1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.cam.document.validation.impl;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase;
25 import org.kuali.kfs.module.cam.CamsConstants;
26 import org.kuali.kfs.module.cam.CamsKeyConstants;
27 import org.kuali.kfs.module.cam.CamsPropertyConstants;
28 import org.kuali.kfs.module.cam.businessobject.AssetGlobal;
29 import org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail;
30 import org.kuali.kfs.module.cam.document.service.AssetService;
31 import org.kuali.kfs.sys.KFSConstants;
32 import org.kuali.kfs.sys.context.SpringContext;
33 import org.kuali.rice.core.api.config.property.ConfigurationService;
34 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35 import org.kuali.rice.kns.document.MaintenanceDocument;
36 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
37 import org.kuali.rice.krad.util.ObjectUtils;
38
39 public class AssetGlobalPreRules extends MaintenancePreRulesBase {
40 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AssetGlobalPreRules.class);
41
42
43
44
45
46
47 @Override
48 protected boolean doCustomPreRules(MaintenanceDocument document) {
49 if (hasDifferentObjectSubTypes(document)) {
50 if (!isOkHavingDifferentObjectSubTypes()) {
51 event.setActionForwardName(KFSConstants.MAPPING_BASIC);
52 return false;
53 }
54 }
55 return true;
56 }
57
58
59
60
61
62
63
64
65
66 public boolean hasDifferentObjectSubTypes(MaintenanceDocument document) {
67 AssetGlobal assetGlobal = (AssetGlobal) document.getNewMaintainableObject().getBusinessObject();
68
69 boolean invalid = false;
70 List<String> objectSubTypeList = new ArrayList<String>();
71
72 for (AssetPaymentDetail assetPaymentDetail : assetGlobal.getAssetPaymentDetails()) {
73 assetPaymentDetail.refreshReferenceObject(CamsPropertyConstants.AssetPaymentDetail.OBJECT_CODE);
74 if (ObjectUtils.isNotNull(assetPaymentDetail.getObjectCode())) {
75 objectSubTypeList.add(assetPaymentDetail.getObjectCode().getFinancialObjectSubTypeCode());
76 }
77 }
78 if (!getAssetService().isObjectSubTypeCompatible(objectSubTypeList)) {
79 invalid = true;
80 }
81 return invalid;
82 }
83
84
85 protected boolean isOkHavingDifferentObjectSubTypes() {
86 String parameterDetail = "(module:" + KRADServiceLocatorWeb.getKualiModuleService().getNamespaceCode(AssetGlobal.class) + "/component:" + AssetGlobal.class.getSimpleName() + ")";
87 ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class);
88
89 String continueQuestion = kualiConfiguration.getPropertyValueAsString(CamsKeyConstants.CONTINUE_QUESTION);
90 String warningMessage = kualiConfiguration.getPropertyValueAsString(CamsKeyConstants.Payment.WARNING_NOT_SAME_OBJECT_SUB_TYPES) + " " + CamsConstants.Parameters.OBJECT_SUB_TYPE_GROUPS + " " + parameterDetail + ". " + continueQuestion;
91 return super.askOrAnalyzeYesNoQuestion(CamsConstants.AssetPayment.ASSET_PAYMENT_DIFFERENT_OBJECT_SUB_TYPE_CONFIRMATION_QUESTION, warningMessage);
92 }
93
94 protected AssetService getAssetService() {
95 return SpringContext.getBean(AssetService.class);
96 }
97
98 protected ParameterService getParameterService() {
99 return SpringContext.getBean(ParameterService.class);
100 }
101 }