1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34
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
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
87
88
89 private SequenceAccessorService getSequenceAccessorService() {
90 if ( sequenceAccessorService == null ) {
91 sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
92 }
93 return sequenceAccessorService;
94 }
95
96 }