01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.pdp.document.maintenance;
17:
18: import java.security.GeneralSecurityException;
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.apache.commons.lang.StringUtils;
24: import org.kuali.RiceConstants;
25: import org.kuali.core.bo.PersistableBusinessObject;
26: import org.kuali.core.document.MaintenanceLock;
27: import org.kuali.core.maintenance.KualiMaintainableImpl;
28: import org.kuali.core.util.Guid;
29: import org.kuali.core.util.ObjectUtils;
30: import org.kuali.rice.KNSServiceLocator;
31:
32: public class PayeeAchAccountMaintainable extends KualiMaintainableImpl {
33:
34: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
35: .getLogger(PayeeAchAccountMaintainable.class);
36:
37: @Override
38: public List<MaintenanceLock> generateMaintenanceLocks() {
39:
40: List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>();
41: StringBuffer lockRepresentation = new StringBuffer(boClass
42: .getName());
43: lockRepresentation
44: .append(RiceConstants.Maintenance.AFTER_CLASS_DELIM);
45:
46: PersistableBusinessObject bo = getBusinessObject();
47: List keyFieldNames = KNSServiceLocator
48: .getMaintenanceDocumentDictionaryService()
49: .getLockingKeys(
50: KNSServiceLocator
51: .getMaintenanceDocumentDictionaryService()
52: .getDocumentTypeName(boClass));
53:
54: for (Iterator i = keyFieldNames.iterator(); i.hasNext();) {
55: String fieldName = (String) i.next();
56: Object fieldValue = ObjectUtils.getPropertyValue(bo,
57: fieldName);
58: if (fieldValue == null) {
59: fieldValue = new Guid().toString();
60: }
61:
62: // check if field is a secure
63: String displayWorkgroup = KNSServiceLocator
64: .getDataDictionaryService()
65: .getAttributeDisplayWorkgroup(getBoClass(),
66: fieldName);
67: if (StringUtils.isNotBlank(displayWorkgroup)) {
68: try {
69: fieldValue = KNSServiceLocator
70: .getEncryptionService().encrypt(fieldValue);
71: } catch (GeneralSecurityException e) {
72: LOG
73: .error("Unable to encrypt secure field for locking representation "
74: + e.getMessage());
75: throw new RuntimeException(
76: "Unable to encrypt secure field for locking representation "
77: + e.getMessage());
78: }
79: }
80:
81: lockRepresentation.append(fieldName);
82: lockRepresentation
83: .append(RiceConstants.Maintenance.AFTER_FIELDNAME_DELIM);
84: lockRepresentation.append(String.valueOf(fieldValue));
85: if (i.hasNext()) {
86: lockRepresentation
87: .append(RiceConstants.Maintenance.AFTER_VALUE_DELIM);
88: }
89: }
90:
91: MaintenanceLock maintenanceLock = new MaintenanceLock();
92: maintenanceLock.setDocumentNumber(documentNumber);
93: maintenanceLock.setLockingRepresentation(lockRepresentation
94: .toString());
95: maintenanceLocks.add(maintenanceLock);
96: return maintenanceLocks;
97: }
98:
99: }
|