Search in sources :

Example 1 with KualiBatchInputFileSetForm

use of org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetForm in project cu-kfs by CU-CommunityApps.

the class DisencumbranceKualiBatchInputFileSetAction method save.

/**
 * Override method to create a disencumbrance file for upload
 *
 * @see org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetAction#save(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    DisencumbranceKualiBatchInputFileSetForm batchInputFileSetForm = (DisencumbranceKualiBatchInputFileSetForm) form;
    BatchUpload batchUpload = ((KualiBatchInputFileSetForm) form).getBatchUpload();
    BatchInputFileSetType batchType = retrieveBatchInputFileSetTypeImpl(batchUpload.getBatchInputTypeName());
    boolean requiredValuesForFilesMissing = false;
    boolean errorCreatingDisencFile = false;
    if (StringUtils.isBlank(batchUpload.getFileUserIdentifer())) {
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SET_IDENTIFIER_SELECTED, new String[] {});
        requiredValuesForFilesMissing = true;
    }
    BatchInputFileSetService batchInputFileSetService = SpringContext.getBean(BatchInputFileSetService.class);
    if (!batchInputFileSetService.isFileUserIdentifierProperlyFormatted(batchUpload.getFileUserIdentifer())) {
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SET_IDENTIFIER_BAD_FORMAT);
        requiredValuesForFilesMissing = true;
    }
    Map<String, InputStream> typeToStreamMap = new HashMap<String, InputStream>();
    String path = CUKFSConstants.STAGING_DIR + System.getProperty("file.separator") + CUKFSConstants.LD_DIR + System.getProperty("file.separator") + CUKFSConstants.ENTERPRISE_FEED_DIR;
    String selectedDataFile = batchInputFileSetForm.getSelectedDataFile();
    if (StringUtils.isNotEmpty(selectedDataFile)) {
        String dataFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedDataFile);
        File dataFile = new File(dataFilePath).getAbsoluteFile();
        if (dataFile == null) {
            GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.DATA_FILE_TYPE) });
            requiredValuesForFilesMissing = true;
        } else {
            // call service to create disencumbrance
            LaborLedgerEnterpriseFeedService ldService = SpringContext.getBean(LaborLedgerEnterpriseFeedService.class);
            InputStream disencumFileInputStream = null;
            disencumFileInputStream = ldService.createDisencumbrance(new FileInputStream(dataFile));
            if (disencumFileInputStream == null) {
                GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_ERROR);
                errorCreatingDisencFile = true;
            } else {
                typeToStreamMap.put(KFSConstants.DATA_FILE_TYPE, disencumFileInputStream);
            }
        }
    }
    String selectedReconFile = batchInputFileSetForm.getSelectedReconFile();
    if (StringUtils.isNotEmpty(selectedReconFile)) {
        String reconFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedReconFile);
        File reconFile = new File(reconFilePath).getAbsoluteFile();
        if (reconFile == null) {
            GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.RECON_FILE_TYPE) });
            requiredValuesForFilesMissing = true;
        } else {
            typeToStreamMap.put(KFSConstants.RECON_FILE_TYPE, new FileInputStream(reconFile));
        }
    }
    if (requiredValuesForFilesMissing || errorCreatingDisencFile) {
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }
    try {
        Map<String, String> typeToSavedFileNames = batchInputFileSetService.save(GlobalVariables.getUserSession().getPerson(), batchType, batchUpload.getFileUserIdentifer(), typeToStreamMap);
    } catch (FileStorageException e) {
        LOG.error("Error occured while trying to save file set (probably tried to save a file that already exists).", e);
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SAVE_ERROR, new String[] { e.getMessage() });
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    } catch (ValidationException e) {
        LOG.error("Error occured while trying to validate file set.", e);
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_VALIDATION_ERROR);
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }
    KNSGlobalVariables.getMessageList().add(CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_SUCCESSFUL);
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : BatchInputFileSetType(org.kuali.kfs.sys.batch.BatchInputFileSetType) ValidationException(org.kuali.kfs.krad.exception.ValidationException) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LaborLedgerEnterpriseFeedService(edu.cornell.kfs.module.ld.service.LaborLedgerEnterpriseFeedService) BatchUpload(org.kuali.kfs.sys.businessobject.BatchUpload) FileStorageException(org.kuali.kfs.sys.exception.FileStorageException) KualiBatchInputFileSetForm(org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetForm) FileInputStream(java.io.FileInputStream) File(java.io.File) BatchInputFileSetService(org.kuali.kfs.sys.batch.service.BatchInputFileSetService)

Aggregations

LaborLedgerEnterpriseFeedService (edu.cornell.kfs.module.ld.service.LaborLedgerEnterpriseFeedService)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 BatchInputFileSetType (org.kuali.kfs.sys.batch.BatchInputFileSetType)1 BatchInputFileSetService (org.kuali.kfs.sys.batch.service.BatchInputFileSetService)1 BatchUpload (org.kuali.kfs.sys.businessobject.BatchUpload)1 FileStorageException (org.kuali.kfs.sys.exception.FileStorageException)1 KualiBatchInputFileSetForm (org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetForm)1