001: /*
002: * Copyright 2007 The Kuali Foundation Licensed under the Educational Community License, Version 1.0 (the "License"); you may
003: * not use this file except in compliance with the License. You may obtain a copy of the License at
004: * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law or agreed to in writing, software
005: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
006: * express or implied. See the License for the specific language governing permissions and limitations under the License.
007: */
008: package org.kuali.core.rules;
009:
010: import org.apache.commons.lang.StringUtils;
011: import org.kuali.core.bo.Parameter;
012: import org.kuali.core.bo.user.UniversalUser;
013: import org.kuali.core.document.MaintenanceDocument;
014: import org.kuali.core.exceptions.UserNotFoundException;
015: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
016: import org.kuali.core.util.GlobalVariables;
017: import org.kuali.rice.KNSServiceLocator;
018:
019: /**
020: * This is a description of what this class does - kellerj don't forget to fill
021: * this in.
022: *
023: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
024: */
025: public class ParameterRule extends MaintenanceDocumentRuleBase {
026:
027: /**
028: * This overridden method ...
029: *
030: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
031: */
032: @Override
033: protected boolean processCustomRouteDocumentBusinessRules(
034: MaintenanceDocument document) {
035: boolean result = super
036: .processCustomRouteDocumentBusinessRules(document);
037:
038: result &= checkWorkgroup(document.getDocumentHeader()
039: .getWorkflowDocument().getInitiatorNetworkId(),
040: (Parameter) getOldBo(), (Parameter) getNewBo());
041:
042: return result;
043: }
044:
045: protected boolean checkWorkgroup(String initiatorUserId,
046: Parameter oldBO, Parameter newBO) {
047: boolean result = true;
048: // don't check if workgroup is blank
049: if (StringUtils.isNotBlank(newBO.getParameterWorkgroupName())) {
050: // check that the workgroup exists
051: result = KNSServiceLocator.getKualiGroupService()
052: .groupExists(newBO.getParameterWorkgroupName());
053: if (result) {
054: // get the initiator user record
055: UniversalUser user = null;
056: try {
057: user = KNSServiceLocator.getUniversalUserService()
058: .getUniversalUserByAuthenticationUserId(
059: initiatorUserId);
060: } catch (UserNotFoundException ex) {
061: LOG.error("Unable to find initiator user: "
062: + initiatorUserId + " via user service");
063: throw new RuntimeException(
064: "Unable to find initiator user: "
065: + initiatorUserId
066: + " via user service", ex);
067: }
068: if (oldBO == null
069: || StringUtils.isBlank(oldBO
070: .getParameterWorkgroupName())) { // creating
071: // a
072: // new
073: // parameter
074: result = user.isMember(newBO
075: .getParameterWorkgroupName());
076: if (!result) {
077: putFieldError(
078: "parameterWorkgroupName",
079: "error.document.parameter.workgroupName.notinnew",
080: newBO.getParameterWorkgroupName());
081: }
082: } else { // editing an existing parameter
083: result = user.isMember(oldBO
084: .getParameterWorkgroupName())
085: && user.isMember(newBO
086: .getParameterWorkgroupName());
087: if (!result) {
088: putFieldError("parameterWorkgroupName",
089: "error.document.parameter.workgroupName.notinboth");
090: }
091: }
092: } else {
093: putFieldError(
094: "parameterWorkgroupName",
095: "error.document.parameter.workgroupName.invalid",
096: newBO.getParameterWorkgroupName());
097: }
098: }
099: return result;
100: }
101:
102: }
|