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.kfs.rules;
17:
18: import java.util.HashMap;
19: import java.util.List;
20: import java.util.Map;
21:
22: import org.kuali.core.bo.Parameter;
23: import org.kuali.core.bo.ParameterDetailType;
24: import org.kuali.core.datadictionary.DataDictionaryException;
25: import org.kuali.core.document.MaintenanceDocument;
26: import org.kuali.core.util.ObjectUtils;
27: import org.kuali.kfs.context.SpringContext;
28: import org.kuali.kfs.service.ParameterService;
29:
30: public class ParameterRule extends org.kuali.core.rules.ParameterRule {
31:
32: @Override
33: protected boolean processCustomRouteDocumentBusinessRules(
34: MaintenanceDocument document) {
35: boolean result = super
36: .processCustomRouteDocumentBusinessRules(document);
37:
38: result &= checkComponent((Parameter) getNewBo());
39:
40: return result;
41: }
42:
43: public boolean checkComponent(Parameter param) {
44: String component = param.getParameterDetailTypeCode();
45: String namespace = param.getParameterNamespaceCode();
46: boolean result = false;
47:
48: try {
49: List<ParameterDetailType> dataDictionaryAndSpringComponents = SpringContext
50: .getBean(ParameterService.class)
51: .getNonDatabaseDetailTypes();
52: for (ParameterDetailType pdt : dataDictionaryAndSpringComponents) {
53: if (pdt.getParameterNamespaceCode().equals(namespace)
54: && pdt.getParameterDetailTypeCode().equals(
55: component)) {
56: result = true;
57: break;
58: }
59: }
60:
61: if (!result) {
62: Map<String, String> primaryKeys = new HashMap<String, String>(
63: 2);
64: primaryKeys.put("parameterNamespaceCode", namespace);
65: primaryKeys.put("parameterDetailTypeCode", component);
66: result = ObjectUtils.isNotNull(getBoService()
67: .findByPrimaryKey(ParameterDetailType.class,
68: primaryKeys));
69: }
70:
71: if (!result) {
72: putFieldError("parameterDetailTypeCode",
73: "error.document.parameter.detailType.invalid",
74: component);
75: }
76:
77: return result;
78: } catch (DataDictionaryException ex) {
79: throw new RuntimeException(
80: "Problem parsing data dictionary during full load required for rule validation: "
81: + ex.getMessage(), ex);
82: }
83: }
84:
85: }
|