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.financial.batch.pcard;
017:
018: import java.io.File;
019: import java.sql.Timestamp;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.service.DateTimeService;
024: import org.kuali.kfs.KFSConstants;
025: import org.kuali.kfs.KFSKeyConstants;
026: import org.kuali.kfs.batch.BatchInputFileTypeBase;
027:
028: /**
029: * Batch input type for the procurement card job.
030: */
031: public class ProcurementCardInputFileType extends
032: BatchInputFileTypeBase {
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(ProcurementCardInputFileType.class);
035:
036: private DateTimeService dateTimeService;
037:
038: /**
039: * @see org.kuali.kfs.batch.BatchInputFileType#getFileTypeIdentifer()
040: */
041: public String getFileTypeIdentifer() {
042: return KFSConstants.PCDO_FILE_TYPE_INDENTIFIER;
043: }
044:
045: public Class getUploadWorkgroupParameterComponent() {
046: return ProcurementCardLoadStep.class;
047: }
048:
049: /**
050: * No additional information is added to procurment card batch files.
051: *
052: * @see org.kuali.kfs.batch.BatchInputFileType#getFileName(org.kuali.core.bo.user.UniversalUser, java.lang.Object,
053: * java.lang.String)
054: */
055: public String getFileName(UniversalUser user,
056: Object parsedFileContents, String userIdentifier) {
057: Timestamp currentTimestamp = dateTimeService
058: .getCurrentTimestamp();
059:
060: String fileName = "pcdo_"
061: + user.getPersonUserIdentifier().toLowerCase();
062: if (StringUtils.isNotBlank(userIdentifier)) {
063: fileName += "_" + userIdentifier;
064: }
065: fileName += "_"
066: + dateTimeService.toString(currentTimestamp,
067: "yyyyMMdd_HHmmss");
068:
069: // remove spaces in filename
070: fileName = StringUtils.remove(fileName, " ");
071:
072: return fileName;
073: }
074:
075: /**
076: * Builds the file name using the following construction: All pcdo files start with pcdo_ append the username of the user
077: * uploading the file append the supplied user identifier finally append the current timestamp
078: *
079: * @see org.kuali.kfs.batch.BatchInputFileType#checkAuthorization(org.kuali.core.bo.user.UniversalUser, java.io.File)
080: */
081: public boolean checkAuthorization(UniversalUser user, File batchFile) {
082: return true;
083: }
084:
085: /**
086: * @see org.kuali.kfs.batch.BatchInputFileType#validate(java.lang.Object)
087: */
088: public boolean validate(Object parsedFileContents) {
089: return true;
090: }
091:
092: /**
093: * @see org.kuali.kfs.batch.BatchInputFileType#getTitleKey()
094: */
095: public String getTitleKey() {
096: return KFSKeyConstants.MESSAGE_BATCH_UPLOAD_TITLE_PCDO;
097: }
098:
099: /**
100: * Gets the dateTimeService attribute.
101: */
102: public DateTimeService getDateTimeService() {
103: return dateTimeService;
104: }
105:
106: /**
107: * Sets the dateTimeService attribute value.
108: */
109: public void setDateTimeService(DateTimeService dateTimeService) {
110: this.dateTimeService = dateTimeService;
111: }
112:
113: }
|