1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document;
17
18 import org.kuali.ole.select.OleSelectConstant;
19 import org.kuali.ole.select.businessobject.OleDefaultTableColumn;
20 import org.kuali.ole.select.businessobject.OleDefaultValue;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.core.api.mo.common.active.Inactivatable;
23 import org.kuali.rice.kew.api.exception.WorkflowException;
24 import org.kuali.rice.kew.doctype.bo.DocumentType;
25 import org.kuali.rice.kns.document.MaintenanceDocument;
26 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
27 import org.kuali.rice.krad.document.TransactionalDocumentBase;
28 import org.kuali.rice.krad.service.BusinessObjectService;
29 import org.kuali.rice.krad.service.DocumentService;
30
31 import java.math.BigDecimal;
32 import java.sql.Timestamp;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.LinkedHashMap;
36
37 public class OleDefaultTableColumnValueDocument extends TransactionalDocumentBase implements Inactivatable {
38 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDefaultTableColumnValueDocument.class);
39
40 protected String documentNumber;
41 protected BigDecimal defaultTableColumnId;
42 protected String documentTypeId;
43 protected String documentColumn;
44 protected DocumentType documentTypes;
45 protected boolean active;
46 protected Timestamp createdDate;
47 protected Timestamp modifiedDate;
48 protected String defaultValue;
49
50 public String getDefaultValue() {
51 return defaultValue;
52 }
53
54 public void setDefaultValue(String defaultValue) {
55 this.defaultValue = defaultValue;
56 }
57
58 public String getDocumentNumber() {
59 return documentNumber;
60 }
61
62 public void setDocumentNumber(String documentNumber) {
63 this.documentNumber = documentNumber;
64 }
65
66 public Timestamp getCreatedDate() {
67 return createdDate;
68 }
69
70 public void setCreatedDate(Timestamp createdDate) {
71 this.createdDate = createdDate;
72 }
73
74 public Timestamp getModifiedDate() {
75 return modifiedDate;
76 }
77
78 public void setModifiedDate(Timestamp modifiedDate) {
79 this.modifiedDate = modifiedDate;
80 }
81
82 public BigDecimal getDefaultTableColumnId() {
83 return defaultTableColumnId;
84 }
85
86 public void setDefaultTableColumnId(BigDecimal defaultTableColumnId) {
87 this.defaultTableColumnId = defaultTableColumnId;
88 }
89
90 public String getDocumentTypeId() {
91 return documentTypeId;
92 }
93
94 public void setDocumentTypeId(String documentTypeId) {
95 this.documentTypeId = documentTypeId;
96 }
97
98 public String getDocumentColumn() {
99 return documentColumn;
100 }
101
102 public void setDocumentColumn(String documentColumn) {
103 this.documentColumn = documentColumn;
104 }
105
106 public boolean isActive() {
107 return active;
108 }
109
110 public void setActive(boolean active) {
111 this.active = active;
112 }
113
114 public DocumentType getDocumentTypes() {
115 return documentTypes;
116 }
117
118 public void setDocumentTypes(DocumentType documentTypes) {
119 this.documentTypes = documentTypes;
120 }
121
122
123
124
125 @SuppressWarnings("rawtypes")
126
127 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
128 LinkedHashMap m = new LinkedHashMap();
129 return m;
130 }
131
132 public void valueSubmit() {
133 try {
134 boolean flag = true;
135 boolean flag1 = true;
136 if (!(this.getDocumentTypeId() == null) || !(this.getDocumentColumn() == null)) {
137 if (LOG.isDebugEnabled())
138 LOG.debug(" this.getDocumentTypeId() --------------------------> " + this.getDocumentTypeId());
139 Collection<OleDefaultTableColumn> defaultTableColumnList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleDefaultTableColumn.class, Collections.singletonMap("documentTypeId", getDocumentTypeId()));
140 for (OleDefaultTableColumn col : defaultTableColumnList) {
141 if (col.getDocumentColumn().equalsIgnoreCase(this.getDocumentColumn())) {
142 this.setDefaultTableColumnId(col.getDefaultTableColumnId());
143 flag = false;
144 }
145 }
146 if (flag) {
147 MaintenanceDocument document = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getNewDocument(SpringContext.getBean(MaintenanceDocumentDictionaryService.class).getDocumentTypeName(OleDefaultTableColumn.class));
148 OleDefaultTableColumn oleDefaultTableColumn = (OleDefaultTableColumn) document.getNewMaintainableObject().getBusinessObject();
149 oleDefaultTableColumn.setDocumentTypeId(this.getDocumentTypeId());
150 oleDefaultTableColumn.setDocumentColumn(this.getDocumentColumn());
151 oleDefaultTableColumn.setActive(this.isActive());
152 SpringContext.getBean(BusinessObjectService.class).save(oleDefaultTableColumn);
153 this.setDefaultTableColumnId(oleDefaultTableColumn.getDefaultTableColumnId());
154 }
155 }
156
157 Collection<OleDefaultValue> defaultValueList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleDefaultValue.class, Collections.singletonMap("defaultTableColumnId", this.getDefaultTableColumnId()));
158 for (OleDefaultValue def : defaultValueList) {
159 if (def.getDefaultValueFor().equalsIgnoreCase(OleSelectConstant.DEFAULT_VALUE_SYSTEM)) {
160 flag1 = false;
161 }
162 }
163 if (flag1) {
164 if (!(this.getDefaultValue() == null) && !(this.getDefaultTableColumnId() == null)) {
165 MaintenanceDocument document = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getNewDocument(SpringContext.getBean(MaintenanceDocumentDictionaryService.class).getDocumentTypeName(OleDefaultValue.class));
166 OleDefaultValue oleDefaultValue = (OleDefaultValue) document.getNewMaintainableObject().getBusinessObject();
167 oleDefaultValue.setDefaultValue(this.getDefaultValue());
168 oleDefaultValue.setDefaultTableColumnId(this.getDefaultTableColumnId());
169 oleDefaultValue.setActive(this.isActive());
170 oleDefaultValue.setDefaultValueFor("System");
171 SpringContext.getBean(BusinessObjectService.class).save(oleDefaultValue);
172
173 }
174 }
175 } catch (WorkflowException e) {
176 LOG.error("Received WorkflowException trying to get route header id from workflow document", e);
177 throw new RuntimeException(e);
178 }
179 }
180
181 }