001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.kra.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.service.BusinessObjectService;
024: import org.kuali.kfs.KFSConstants;
025: import org.kuali.kfs.KFSPropertyConstants;
026: import org.kuali.module.kra.KraConstants;
027: import org.kuali.module.kra.bo.AdhocOrg;
028: import org.kuali.module.kra.bo.AdhocPerson;
029: import org.kuali.module.kra.bo.AdhocWorkgroup;
030: import org.kuali.module.kra.bo.ResearchAdhocPermissionType;
031: import org.kuali.module.kra.service.ResearchDocumentPermissionsService;
032: import org.springframework.transaction.annotation.Transactional;
033:
034: import edu.iu.uis.eden.clientapp.WorkflowInfo;
035: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
036: import edu.iu.uis.eden.clientapp.vo.DocumentDetailVO;
037: import edu.iu.uis.eden.clientapp.vo.ReportCriteriaVO;
038: import edu.iu.uis.eden.exception.WorkflowException;
039:
040: @Transactional
041: public class ResearchDocumentPermissionsServiceImpl implements
042: ResearchDocumentPermissionsService {
043:
044: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(ResearchDocumentPermissionsServiceImpl.class);
046:
047: private BusinessObjectService businessObjectService;
048:
049: /**
050: * @see org.kuali.module.kra.budget.service.BudgetPermissionsService#getAdHocPermission(String documentNumber, String
051: * personUniversalIdentifier)
052: */
053: public AdhocPerson getAdHocPerson(String documentNumber,
054: String personUniversalIdentifier) {
055: return (AdhocPerson) businessObjectService
056: .retrieve(new AdhocPerson(documentNumber,
057: personUniversalIdentifier));
058: }
059:
060: /**
061: * @see org.kuali.module.kra.budget.service.BudgetPermissionsService#getAdHocWorkgroup(String documentNumber, String
062: * workgroupName)
063: */
064: public AdhocWorkgroup getAdHocWorkgroup(String documentNumber,
065: String workgroupName) {
066: return (AdhocWorkgroup) businessObjectService
067: .retrieve(new AdhocWorkgroup(documentNumber,
068: workgroupName));
069: }
070:
071: /**
072: * @see org.kuali.module.kra.budget.service.BudgetPermissionsService#getAssAdHocWorkgroups(String documentNumber)
073: */
074: public List<AdhocWorkgroup> getAllAdHocWorkgroups(
075: String documentNumber) {
076: Map fieldValues = new HashMap();
077: fieldValues.put(KFSPropertyConstants.DOCUMENT_NUMBER,
078: documentNumber);
079: return new ArrayList(businessObjectService.findMatching(
080: AdhocWorkgroup.class, fieldValues));
081: }
082:
083: /**
084: * @see org.kuali.module.kra.budget.service.PermissionsService#getAdHocOrgs(String documentNumber, String budgetPermissionCode)
085: */
086: public List<AdhocOrg> getAdHocOrgs(String documentNumber,
087: String permissionCode) {
088: Map fieldValues = new HashMap();
089: fieldValues.put(KFSPropertyConstants.DOCUMENT_NUMBER,
090: documentNumber);
091: fieldValues.put("permissionCode", permissionCode);
092: return new ArrayList(businessObjectService.findMatching(
093: AdhocOrg.class, fieldValues));
094: }
095:
096: /**
097: * @see org.kuali.module.kra.budget.service.PermissionsService#getPermissionType()
098: */
099: public List<ResearchAdhocPermissionType> getPermissionTypes() {
100: List<ResearchAdhocPermissionType> permissionTypeList = new ArrayList<ResearchAdhocPermissionType>();
101: permissionTypeList.add(new ResearchAdhocPermissionType(
102: KFSConstants.PERMISSION_READ_CODE,
103: KFSConstants.PERMISSION_READ_DESCRIPTION));
104: permissionTypeList.add(new ResearchAdhocPermissionType(
105: KFSConstants.PERMISSION_MOD_CODE,
106: KFSConstants.PERMISSION_MOD_DESCRIPTION));
107: return permissionTypeList;
108: }
109:
110: /**
111: * @see org.kuali.module.kra.budget.service.BudgetPermissionsService#getBudgetPermissionType(String orgXml, String documentType,
112: * String uuid)
113: */
114: public boolean isUserInOrgHierarchy(String orgXml,
115: String documentType, String uuid) {
116: ReportCriteriaVO criteria = new ReportCriteriaVO();
117: criteria.setDocumentTypeName(documentType);
118: criteria
119: .setNodeNames(new String[] { KraConstants.ORG_REVIEW_NODE_NAME });
120: criteria
121: .setRuleTemplateNames(new String[] { KraConstants.ORG_REVIEW_TEMPLATE_NAME });
122: criteria.setXmlContent(orgXml);
123: WorkflowInfo info = new WorkflowInfo();
124: try {
125: DocumentDetailVO detail = info.routingReport(criteria);
126: return isUserInRequests(detail.getActionRequests(), uuid);
127: } catch (WorkflowException e) {
128: throw new RuntimeException(
129: "Exception generating routing report: " + e);
130: }
131: }
132:
133: /**
134: * Check whether given user is in the given action requests.
135: *
136: * @param ActionRequestVO[] requests
137: * @param String uuid
138: * @return boolean
139: */
140: private boolean isUserInRequests(ActionRequestVO[] requests,
141: String uuid) {
142: for (int i = 0; i < requests.length; i++) {
143: ActionRequestVO request = (ActionRequestVO) requests[i];
144: if (request.getUserVO().getUuId().equals(uuid)) {
145: return true;
146: }
147: if (isUserInRequests(request.getChildrenRequests(), uuid)) {
148: return true;
149: }
150: }
151: return false;
152: }
153:
154: /**
155: * Setter for BusinessObjectService property.
156: *
157: * @param BusinessObjectService businessObjectService
158: */
159: public void setBusinessObjectService(
160: BusinessObjectService businessObjectService) {
161: this.businessObjectService = businessObjectService;
162: }
163: }
|