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.kfs.lookup;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020: import java.util.Map;
021: import java.util.regex.Pattern;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.kuali.core.bo.BusinessObject;
025: import org.kuali.core.lookup.KualiLookupableHelperServiceImpl;
026: import org.kuali.core.service.KualiConfigurationService;
027: import org.kuali.core.util.GlobalVariables;
028: import org.kuali.core.util.UrlFactory;
029: import org.kuali.kfs.KFSConstants;
030: import org.kuali.kfs.batch.BatchJobStatus;
031: import org.kuali.kfs.service.ParameterService;
032: import org.kuali.kfs.service.SchedulerService;
033: import org.kuali.kfs.service.impl.ParameterConstants;
034:
035: public class BatchJobStatusLookupableHelperServiceImpl extends
036: KualiLookupableHelperServiceImpl {
037:
038: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(BatchJobStatusLookupableHelperServiceImpl.class);
040:
041: private SchedulerService schedulerService;
042: private KualiConfigurationService configurationService;
043: private ParameterService parameterService;
044:
045: @Override
046: public List<? extends BusinessObject> getSearchResults(
047: Map<String, String> fieldValues) {
048: super .setBackLocation((String) fieldValues
049: .get(KFSConstants.BACK_LOCATION));
050: super .setDocFormKey((String) fieldValues
051: .get(KFSConstants.DOC_FORM_KEY));
052: List<BatchJobStatus> allJobs = schedulerService.getJobs();
053: List<BatchJobStatus> jobs = new ArrayList<BatchJobStatus>();
054: String nameValue = fieldValues.get("name");
055: Pattern namePattern = null;
056: if (!StringUtils.isEmpty(nameValue)) {
057: namePattern = Pattern.compile(nameValue.replace("*", ".*"),
058: Pattern.CASE_INSENSITIVE);
059: }
060: String schedulerGroup = fieldValues.get("group");
061: String jobStatus = fieldValues.get("status");
062: for (BatchJobStatus job : allJobs) {
063: if (namePattern != null
064: && !namePattern.matcher(job.getName()).matches()) {
065: continue; // match failed, skip this entry
066: }
067: if (!StringUtils.isEmpty(schedulerGroup)
068: && !schedulerGroup.equalsIgnoreCase(job.getGroup())) {
069: continue;
070: }
071: if (!StringUtils.isEmpty(jobStatus)
072: && !jobStatus.equalsIgnoreCase(job.getStatus())) {
073: continue;
074: }
075: jobs.add(job);
076: }
077:
078: return jobs;
079: }
080:
081: @Override
082: public String getActionUrls(BusinessObject businessObject) {
083: if (businessObject instanceof BatchJobStatus) {
084: BatchJobStatus job = (BatchJobStatus) businessObject;
085: String linkText = "Modify";
086: StringBuffer sb = new StringBuffer();
087: if (parameterService
088: .parameterExists(
089: ParameterConstants.FINANCIAL_SYSTEM_BATCH.class,
090: KFSConstants.SystemGroupParameterNames.JOB_ADMIN_WORKGROUP)) {
091: String adminWorkgroup = parameterService
092: .getParameterValue(
093: ParameterConstants.FINANCIAL_SYSTEM_BATCH.class,
094: KFSConstants.SystemGroupParameterNames.JOB_ADMIN_WORKGROUP);
095: if (!GlobalVariables.getUserSession()
096: .getUniversalUser().isMember(adminWorkgroup)) {
097: linkText = "View";
098: }
099: }
100: sb
101: .append(
102: "<a href=\""
103: + configurationService
104: .getPropertyString(KFSConstants.APPLICATION_URL_KEY)
105: + "/batchModify.do?methodToCall=start&name=")
106: .append(UrlFactory.encode(job.getName())).append(
107: "&group=").append(
108: UrlFactory.encode(job.getGroup())).append(
109: "\">").append(linkText).append("</a>");
110:
111: return sb.toString();
112: }
113: return " ";
114: }
115:
116: public void setSchedulerService(SchedulerService schedulerService) {
117: this .schedulerService = schedulerService;
118: }
119:
120: public void setParameterService(ParameterService parameterService) {
121: this .parameterService = parameterService;
122: }
123:
124: public void setConfigurationService(
125: KualiConfigurationService configurationService) {
126: this.configurationService = configurationService;
127: }
128:
129: }
|