View Javadoc

1   /**
2    * Copyright 2005-2013 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.service.KRADServiceLocator;
23  import org.kuali.rice.krad.service.SequenceAccessorService;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krms.api.KrmsConstants;
26  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
27  import org.kuali.rice.krms.impl.repository.ContextBo;
28  
29  import java.util.Map;
30  
31  /**
32   * {@link org.kuali.rice.krad.maintenance.Maintainable} for the {@link ContextBo}
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   * */
36  public class ContextMaintainable extends MaintainableImpl {
37  
38      private transient SequenceAccessorService sequenceAccessorService;
39  
40      @Override
41      public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
42          ContextBo newContext = (ContextBo) document.getNewMaintainableObject().getDataObject();
43  
44          String nextId = getSequenceAccessorService().getNextAvailableSequenceNumber(KrmsMaintenanceConstants.Sequences.CONTEXT, ContextBo.class).toString();
45          newContext.setId(nextId);
46  
47          super.processAfterNew(document, requestParameters);    
48      }
49  
50      @Override
51      public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) {
52          ContextBo context = (ContextBo) document.getNewMaintainableObject().getDataObject();
53  
54          String nextId = getSequenceAccessorService().getNextAvailableSequenceNumber(KrmsMaintenanceConstants.Sequences.CONTEXT, ContextBo.class).toString();
55          context.setId(nextId);
56  
57          super.processAfterCopy(document,
58                  requestParameters);
59      }
60  
61      @Override
62      public void saveDataObject() {
63          super.saveDataObject();
64  
65          //flush context cache
66          DistributedCacheManagerDecorator distributedCacheManagerDecorator =
67                  GlobalResourceLoader.getService(KrmsConstants.KRMS_DISTRIBUTED_CACHE);
68          distributedCacheManagerDecorator.getCache(ContextDefinition.Cache.NAME).clear();
69      }
70  
71      @Override
72      public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
73  
74          ContextBo contextBo = (ContextBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
75  
76          if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
77              document.getDocumentHeader().setDocumentDescription("New Context Document");
78  
79              contextBo = contextBo.copyContext(" Copy " + System.currentTimeMillis());
80          }
81  
82          return contextBo;
83      }
84  
85      /**
86       *  Returns the sequenceAssessorService
87       * @return {@link SequenceAccessorService}
88       */
89      private SequenceAccessorService getSequenceAccessorService() {
90          if ( sequenceAccessorService == null ) {
91              sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
92          }
93          return sequenceAccessorService;
94      }
95  
96  }