View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krms.impl.ui;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.core.impl.cache.DistributedCacheManagerDecorator;
20  import org.kuali.rice.krad.maintenance.MaintainableImpl;
21  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krms.api.KrmsConstants;
24  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
25  import org.kuali.rice.krms.impl.repository.ContextBo;
26  import org.kuali.rice.krms.impl.repository.RepositoryBoIncrementer;
27  
28  import java.util.Map;
29  
30  /**
31   * {@link org.kuali.rice.krad.maintenance.Maintainable} for the {@link ContextBo}
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   * */
35  public class ContextMaintainable extends MaintainableImpl {
36  
37      private static final RepositoryBoIncrementer contextIdIncrementer = new RepositoryBoIncrementer(ContextBo.CONTEXT_SEQ_NAME);
38  
39      @Override
40      public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
41          ContextBo newContext = (ContextBo) document.getNewMaintainableObject().getDataObject();
42  
43          newContext.setId(contextIdIncrementer.getNewId());
44  
45          super.processAfterNew(document, requestParameters);    
46      }
47  
48      @Override
49      public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
50          ContextBo context = (ContextBo) document.getNewMaintainableObject().getDataObject();
51  
52          context.setId(contextIdIncrementer.getNewId());
53  
54          super.processAfterCopy(document,
55                  requestParameters);
56      }
57  
58      @Override
59      public void saveDataObject() {
60          super.saveDataObject();
61  
62          //flush context cache
63          DistributedCacheManagerDecorator distributedCacheManagerDecorator =
64                  GlobalResourceLoader.getService(KrmsConstants.KRMS_DISTRIBUTED_CACHE);
65          distributedCacheManagerDecorator.getCache(ContextDefinition.Cache.NAME).clear();
66      }
67  
68      @Override
69      public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
70  
71          ContextBo contextBo = (ContextBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
72  
73          if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
74              document.getDocumentHeader().setDocumentDescription("New Context Document");
75  
76              contextBo = contextBo.copyContext(" Copy " + System.currentTimeMillis());
77          }
78  
79          return contextBo;
80      }
81  }