View Javadoc

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