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.cg.maintenance;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.kuali.core.bo.BusinessObject;
024: import org.kuali.core.bo.user.UniversalUser;
025: import org.kuali.core.datadictionary.InquirySectionDefinition;
026: import org.kuali.core.service.BusinessObjectDictionaryService;
027: import org.kuali.core.util.GlobalVariables;
028: import org.kuali.core.web.ui.Section;
029: import org.kuali.core.web.ui.SectionBridge;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.kfs.inquiry.KfsInquirableImpl;
032: import org.kuali.kfs.service.ParameterService;
033: import org.kuali.kfs.service.impl.ParameterConstants;
034: import org.kuali.module.cg.CGConstants;
035:
036: /**
037: * Used for wiring up {@link Proposal} for inquiries.
038: */
039: public class ProposalInquirable extends KfsInquirableImpl {
040: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(ProposalInquirable.class);
042:
043: private transient static String centralPreAwardWorkgroupName;
044: private transient static String centralPostAwardWorkgroupName;
045: private transient static String centralReviewWorkgroupName;
046:
047: /**
048: * @see org.kuali.core.inquiry.KualiInquirableImpl#getSections(org.kuali.core.bo.BusinessObject)
049: */
050: public List<Section> getSections(BusinessObject bo) {
051:
052: initStatics();
053:
054: List<Section> sections = new ArrayList<Section>();
055: if (getBusinessObjectClass() == null) {
056: LOG.error("Business object class not set in inquirable.");
057: throw new RuntimeException(
058: "Business object class not set in inquirable.");
059: }
060:
061: Collection inquirySections = SpringContext.getBean(
062: BusinessObjectDictionaryService.class)
063: .getInquirySections(getBusinessObjectClass());
064: for (Iterator iter = inquirySections.iterator(); iter.hasNext();) {
065:
066: UniversalUser user = GlobalVariables.getUserSession()
067: .getUniversalUser();
068: InquirySectionDefinition inquirySection = (InquirySectionDefinition) iter
069: .next();
070: Section section = SectionBridge.toSection(this ,
071: inquirySection, bo);
072: if (inquirySection.getTitle().equals("Research Risks")) {
073: if (user.isMember(centralPreAwardWorkgroupName)
074: || user.isMember(centralPostAwardWorkgroupName)) {
075: sections.add(section);
076: }
077: } else {
078: sections.add(section);
079: }
080: }
081:
082: return sections;
083: }
084:
085: /**
086: * A non-static way to initialize the static attributes. Doing it statically would cause problems with the {@link SpringContext}.
087: * So doing it non-statically helps by allowing the {@link SpringContext} time to load.
088: */
089: private void initStatics() {
090: // get the group name that we need here
091: if (centralPreAwardWorkgroupName == null) {
092: centralPreAwardWorkgroupName = SpringContext
093: .getBean(ParameterService.class)
094: .getParameterValue(
095: ParameterConstants.CONTRACTS_AND_GRANTS_DOCUMENT.class,
096: CGConstants.PRE_AWARD_GROUP);
097: }
098: if (centralPostAwardWorkgroupName == null) {
099: centralPostAwardWorkgroupName = SpringContext
100: .getBean(ParameterService.class)
101: .getParameterValue(
102: ParameterConstants.CONTRACTS_AND_GRANTS_DOCUMENT.class,
103: CGConstants.POST_AWARD_GROUP);
104: }
105: }
106:
107: }
|