1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.document; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
import java.util.HashSet; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
import java.util.Set; |
23 | |
|
24 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
25 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
26 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
27 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
28 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
29 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
30 | |
import org.kuali.rice.kew.util.KEWPropertyConstants; |
31 | |
import org.kuali.rice.kew.xml.DocumentTypeXmlParser; |
32 | |
import org.kuali.rice.kns.bo.DocumentHeader; |
33 | |
import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition; |
34 | |
import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition; |
35 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
36 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
37 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
38 | |
import org.kuali.rice.kns.util.ObjectUtils; |
39 | |
import org.kuali.rice.kns.web.ui.Field; |
40 | |
import org.kuali.rice.kns.web.ui.Row; |
41 | |
import org.kuali.rice.kns.web.ui.Section; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class DocumentTypeMaintainable extends KualiMaintainableImpl { |
50 | |
|
51 | |
private static final long serialVersionUID = -5920808902137192662L; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Override |
58 | |
public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
59 | 0 | List<Section> sections = super.getSections(document, oldMaintainable); |
60 | |
|
61 | 0 | if (!document.isNew()) { |
62 | 0 | sectionLoop: for (Section section : sections) { |
63 | 0 | for (Row row : section.getRows()) { |
64 | 0 | for (Field field : row.getFields()) { |
65 | 0 | if (KEWPropertyConstants.NAME.equals(field.getPropertyName())) { |
66 | 0 | field.setReadOnly(true); |
67 | 0 | break sectionLoop; |
68 | |
} |
69 | |
} |
70 | |
} |
71 | |
} |
72 | |
} |
73 | 0 | return sections; |
74 | |
} |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) { |
83 | 0 | super.processAfterCopy(document, parameters); |
84 | 0 | DocumentType docType = ((DocumentType)getBusinessObject()); |
85 | 0 | docType.setDocumentTypeId(null); |
86 | 0 | docType.setName(""); |
87 | 0 | docType.setPreviousVersionId(null); |
88 | 0 | } |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
@Override |
94 | |
public void doRouteStatusChange(DocumentHeader documentHeader) { |
95 | 0 | super.doRouteStatusChange(documentHeader); |
96 | 0 | } |
97 | |
|
98 | |
private Set<String> constructUserInterfaceEditablePropertyNamesList() { |
99 | 0 | Set<String> propertyNames = new HashSet<String>(); |
100 | 0 | List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
101 | 0 | for (MaintainableSectionDefinition maintainableSectionDefinition : sectionDefinitions) { |
102 | 0 | for (MaintainableItemDefinition maintainableItemDefinition : maintainableSectionDefinition.getMaintainableItems()) { |
103 | 0 | propertyNames.add(maintainableItemDefinition.getName()); |
104 | |
} |
105 | |
} |
106 | 0 | return propertyNames; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
@Override |
117 | |
public void saveBusinessObject() { |
118 | 0 | DocumentTypeService docTypeService = KEWServiceLocator.getDocumentTypeService(); |
119 | 0 | DocumentType newDocumentType = (DocumentType) getBusinessObject(); |
120 | 0 | String documentTypeName = newDocumentType.getName(); |
121 | 0 | DocumentType docTypeFromDatabase = docTypeService.findByName(documentTypeName); |
122 | 0 | if (ObjectUtils.isNull(docTypeFromDatabase)) { |
123 | 0 | docTypeService.versionAndSave(newDocumentType); |
124 | |
} |
125 | |
else { |
126 | 0 | Boolean applyRetroactively = newDocumentType.getApplyRetroactively(); |
127 | |
DocumentType newDocumentTypeFromDatabase; |
128 | 0 | DocumentTypeXmlParser parser = new DocumentTypeXmlParser(); |
129 | |
try { |
130 | 0 | newDocumentTypeFromDatabase = parser.generateNewDocumentTypeFromExisting(documentTypeName); |
131 | 0 | } catch (Exception e) { |
132 | 0 | throw new WorkflowRuntimeException("Error while attempting to generate new document type from existing " + |
133 | |
"database document type with name '" + documentTypeName + "'", e); |
134 | 0 | } |
135 | 0 | newDocumentTypeFromDatabase.populateDataDictionaryEditableFields(constructUserInterfaceEditablePropertyNamesList(), newDocumentType); |
136 | 0 | docTypeService.versionAndSave(newDocumentTypeFromDatabase); |
137 | 0 | if (ObjectUtils.isNotNull(applyRetroactively) && applyRetroactively.booleanValue()) { |
138 | |
|
139 | |
|
140 | 0 | List<DocumentType> previousDocTypeInstances = docTypeService.findPreviousInstances(documentTypeName); |
141 | 0 | for (DocumentType prevDocType : previousDocTypeInstances) { |
142 | |
|
143 | 0 | prevDocType.setLabel(newDocumentType.getLabel()); |
144 | 0 | prevDocType.setDescription(newDocumentType.getDescription()); |
145 | 0 | prevDocType.setUnresolvedHelpDefinitionUrl(newDocumentType.getUnresolvedHelpDefinitionUrl()); |
146 | 0 | prevDocType.setUnresolvedDocSearchHelpUrl(newDocumentType.getUnresolvedDocSearchHelpUrl()); |
147 | 0 | docTypeService.save(prevDocType, false); |
148 | |
} |
149 | |
|
150 | 0 | docTypeService.flushCache(); |
151 | |
|
152 | |
|
153 | 0 | ActionListService actionListService = KEWServiceLocator.getActionListService(); |
154 | 0 | Collection<ActionItem> items = actionListService.findByDocumentTypeName(documentTypeName); |
155 | 0 | for (ActionItem actionItem : items) { |
156 | 0 | actionItem.setDocLabel(newDocumentType.getLabel()); |
157 | 0 | actionListService.saveActionItem(actionItem); |
158 | |
} |
159 | |
|
160 | |
|
161 | 0 | Collection<ActionItem> outboxItems = actionListService.getOutboxItemsByDocumentType(documentTypeName); |
162 | 0 | for (ActionItem outboxItem : outboxItems) { |
163 | 0 | outboxItem.setDocLabel(newDocumentType.getLabel()); |
164 | 0 | actionListService.saveActionItem(outboxItem); |
165 | |
} |
166 | |
} |
167 | |
} |
168 | 0 | } |
169 | |
|
170 | |
} |