001: /*
002: * Copyright 2006-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.routingform.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.module.kra.KraPropertyConstants;
028: import org.kuali.module.kra.routingform.bo.ResearchRiskType;
029: import org.kuali.module.kra.routingform.bo.RoutingFormResearchRisk;
030: import org.kuali.module.kra.routingform.document.RoutingFormDocument;
031: import org.kuali.module.kra.routingform.service.RoutingFormResearchRiskService;
032: import org.springframework.transaction.annotation.Transactional;
033:
034: @Transactional
035: public class RoutingFormResearchRiskServiceImpl implements
036: RoutingFormResearchRiskService {
037:
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(RoutingFormResearchRiskServiceImpl.class);
040:
041: private BusinessObjectService businessObjectService;
042:
043: /**
044: * @see org.kuali.module.kra.routingform.service.RoutingFormResearchRiskService#setupResearchRisks(RoutingFormDocument
045: * routingFormDocument)
046: */
047: public void setupResearchRisks(
048: RoutingFormDocument routingFormDocument) {
049: List<ResearchRiskType> researchRiskTypes = getAllResearchRiskTypes();
050: List<RoutingFormResearchRisk> researchRisks = new ArrayList<RoutingFormResearchRisk>();
051: for (ResearchRiskType researchRiskType : researchRiskTypes) {
052: researchRisks.add(new RoutingFormResearchRisk(
053: routingFormDocument.getDocumentNumber(),
054: researchRiskType));
055: }
056: routingFormDocument.setRoutingFormResearchRisks(researchRisks);
057: }
058:
059: /**
060: * Get the list of all active research risk types from the database.
061: *
062: * @return List<ResearchRiskType>
063: */
064: private List<ResearchRiskType> getAllResearchRiskTypes() {
065: return getResearchRiskTypes(new String[0]);
066: }
067:
068: /**
069: * @see org.kuali.module.kra.routingform.service.RoutingFormResearchRiskService#getResearchRiskTypes(String[])
070: */
071: public List<ResearchRiskType> getResearchRiskTypes(
072: String[] exceptCodes) {
073: Map criteria = new HashMap();
074: criteria
075: .put(
076: KFSPropertyConstants.DATA_OBJECT_MAINTENANCE_CODE_ACTIVE_INDICATOR,
077: true);
078: List<ResearchRiskType> allActiveResearchRiskTypes = (List<ResearchRiskType>) this .businessObjectService
079: .findMatchingOrderBy(
080: ResearchRiskType.class,
081: criteria,
082: KraPropertyConstants.RESEARCH_RISK_TYPE_SORT_NUMBER,
083: true);
084:
085: List<String> exceptCodesList = Arrays.asList(exceptCodes);
086: List<ResearchRiskType> result = new ArrayList<ResearchRiskType>();
087: for (ResearchRiskType type : allActiveResearchRiskTypes) {
088: if (!exceptCodesList.contains(type
089: .getResearchRiskTypeCode())) {
090: result.add(type);
091: }
092: }
093: return result;
094: }
095:
096: public List<String> getNotificationWorkgroups(String documentNumber) {
097: Map fieldValues = new HashMap();
098: fieldValues.put("documentNumber", documentNumber);
099: List<RoutingFormResearchRisk> researchRisks = new ArrayList<RoutingFormResearchRisk>(
100: businessObjectService.findMatching(
101: RoutingFormResearchRisk.class, fieldValues));
102: List<String> workgroups = new ArrayList<String>();
103: for (RoutingFormResearchRisk researchRisk : researchRisks) {
104: if (!StringUtils.isBlank(researchRisk
105: .getResearchRiskDescription())
106: || !researchRisk.getResearchRiskStudies().isEmpty()) {
107: if (researchRisk.getResearchRiskType()
108: .getResearchRiskTypeNotificationGroupText() != null) {
109: workgroups
110: .add(researchRisk
111: .getResearchRiskType()
112: .getResearchRiskTypeNotificationGroupText());
113: }
114: }
115: }
116: return workgroups;
117: }
118:
119: /**
120: * Setter for BusinessObjectService property.
121: *
122: * @param businessObjectService businessObjectService
123: */
124: public void setBusinessObjectService(
125: BusinessObjectService businessObjectService) {
126: this.businessObjectService = businessObjectService;
127: }
128: }
|