Example usage for org.springframework.http HttpHeaders add

List of usage examples for org.springframework.http HttpHeaders add

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders add.

Prototype

@Override
public void add(String headerName, @Nullable String headerValue) 

Source Link

Document

Add the given, single header value under the given name.

Usage

From source file:org.egov.ptis.domain.service.intgdemandbill.IntgDemandBillService.java

public ResponseEntity<byte[]> generateIntgDemandBill(final String assessment) {
    ReportOutput reportOutput;//ww  w.  j a  va  2  s  . c  o  m
    String clientSpecificDmdBill = propertyTaxCommonUtils.getAppConfigValue(APPCONFIG_CLIENT_SPECIFIC_DMD_BILL,
            PTMODULENAME);
    if ("Y".equalsIgnoreCase(clientSpecificDmdBill)) {
        DemandBillService demandBillService = (DemandBillService) beanProvider.getBean("demandBillService");
        reportOutput = demandBillService.generateDemandBill(assessment, INTEGRATED_BILL);
    } else {
        reportOutput = getBill(assessment);
    }
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=" + INTEGRATED_BILL + "_" + assessment + ".pdf");
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.ptis.domain.service.notice.RecoveryNoticeService.java

public ResponseEntity<byte[]> generateNotice(final String assessmentNo, final String noticeType) {
    ReportOutput reportOutput;//from  w ww .  j a va  2s  .  c  om
    final BasicProperty basicProperty = basicPropertyDAO.getBasicPropertyByPropertyID(assessmentNo);
    final PtNotice notice = noticeService.getNoticeByTypeUpicNoAndFinYear(noticeType,
            basicProperty.getUpicNo());
    if (notice == null)
        reportOutput = generateNotice(noticeType, basicProperty);
    else
        reportOutput = getNotice(notice, noticeType);
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition",
            "inline;filename=" + noticeType + "_" + basicProperty.getUpicNo() + ".pdf");
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.ptis.web.controller.transactions.exemption.TaxExemptionController.java

@ResponseBody
@RequestMapping(value = "/printAck/{assessmentNo}", method = RequestMethod.GET)
public ResponseEntity<byte[]> printAck(final HttpServletRequest request, final Model model,
        @PathVariable("assessmentNo") final String assessmentNo) {
    final ReportOutput reportOutput = propertyTaxUtil.generateCitizenCharterAcknowledgement(assessmentNo,
            TAX_EXEMPTION, WFLOW_ACTION_NAME_EXEMPTION, null);
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=CitizenCharterAcknowledgement.pdf");
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.ptis.web.controller.vacancyremission.ApproveAcknowledgementController.java

@RequestMapping(value = { "/generatenotice/preview/{assessmentNo}",
        "/generatenotice/proceedings/{assessmentNo}" }, method = RequestMethod.GET)
@ResponseBody//ww  w. j a  va2  s .c o m
public ResponseEntity<byte[]> generateNotice(final Model model, final HttpServletRequest request,
        @PathVariable final String assessmentNo) {
    ReportOutput noticeOutput = new ReportOutput();
    String fileName;
    String approverName = request.getParameter("approver");
    final VacancyRemission vacancyRemission = vacancyRemissionService
            .getLatestSpecialNoticeGeneratedVacancyRemissionForProperty(assessmentNo);
    final PtNotice notice = noticeService.getNoticeByNoticeTypeAndApplicationNumber(NOTICE_TYPE_VRPROCEEDINGS,
            vacancyRemission.getApplicationNumber());
    if (notice != null) {
        final FileStoreMapper fsm = notice.getFileStore();
        final File file = fileStoreService.fetch(fsm, FILESTORE_MODULE_NAME);
        byte[] bFile;
        try {
            bFile = FileUtils.readFileToByteArray(file);
        } catch (final IOException e) {

            throw new ApplicationRuntimeException("Exception while generating VRSpecial Notcie : " + e);
        }
        noticeOutput.setReportOutputData(bFile);
        noticeOutput.setReportFormat(ReportFormat.PDF);
        fileName = notice.getNoticeNo();
    } else {
        noticeOutput = vacancyRemissionService.generateReport(vacancyRemission, request, approverName, null);
        fileName = SAMPLE_FILE.concat(assessmentNo);
    }
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=" + fileName + ".pdf");
    return new ResponseEntity<>(noticeOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.ptis.web.controller.vacancyremission.VacanyRemissionController.java

@ResponseBody
@RequestMapping(value = "/printAck/{assessmentNo}", method = RequestMethod.GET)
public ResponseEntity<byte[]> printAck(final HttpServletRequest request, final Model model,
        @PathVariable("assessmentNo") final String assessmentNo) {
    final VacancyRemission remission = vacancyRemissionService.getVRUnderWFByUpicNo(assessmentNo);
    ReportOutput reportOutput = propertyTaxUtil.generateCitizenCharterAcknowledgement(assessmentNo,
            VACANCY_REMISSION, NATURE_VACANCY_REMISSION, remission.getApplicationNumber());
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=CitizenCharterAcknowledgement.pdf");
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.stms.web.controller.reports.SewerageGenerateDemandBillController.java

@RequestMapping(value = "/generate-sewerage-demand-bill/{consumernumber}/{assessmentnumber}", method = RequestMethod.GET)
public ResponseEntity<byte[]> generateSewerageDemandBill(@PathVariable final String consumernumber,
        @PathVariable final String assessmentnumber, final HttpServletRequest request) {
    ReportOutput reportOutput = new ReportOutput();
    final HttpHeaders headers = new HttpHeaders();
    SewerageNotice sewerageNotice = null;
    SewerageApplicationDetails sewerageApplicationDetails = null;
    String errorMessage = "";
    if (consumernumber != null)
        sewerageApplicationDetails = sewerageApplicationDetailsService.findByApplicationNumber(consumernumber);

    if (sewerageApplicationDetails != null && sewerageApplicationDetails.getApplicationNumber() != null) {
        sewerageNotice = sewerageNoticeService.findByNoticeTypeAndApplicationNumber(
                NOTICE_TYPE_DEMAND_BILL_NOTICE, sewerageApplicationDetails.getApplicationNumber());
        // GET DEMAND BILL IF ALREADY SAVED
        if (sewerageNotice != null && sewerageNotice.getFileStore() != null) {

            final FileStoreMapper fmp = sewerageNotice.getFileStore();
            if (fmp != null) {
                reportOutput = new ReportOutput();
                final File file = fileStoreService.fetch(fmp, FILESTORE_MODULECODE);
                try {
                    reportOutput.setReportOutputData(FileUtils.readFileToByteArray(file));
                } catch (final IOException e) {
                    LOGGER.error("Error in loading sewerage demand bill" + e.getMessage(), e);
                }// w w  w.  j  a v a  2  s .co  m
                reportOutput.setReportFormat(ReportFormat.PDF);
            }
        } else if (sewerageDemandService
                .checkAnyTaxIsPendingToCollectExcludingAdvance(sewerageApplicationDetails.getCurrentDemand()))
            reportOutput = sewerageDCBReportService.generateAndSaveDemandBillNotice(sewerageApplicationDetails,
                    sewerageThirdPartyServices.getPropertyDetails(assessmentnumber, request));
        else {
            errorMessage = messageSource.getMessage("err.demandbill.demandpaid", new String[] { "" }, null);
            return redirect(errorMessage);
        }
        if (reportOutput != null && reportOutput.getReportOutputData() != null) {
            headers.setContentType(MediaType.parseMediaType("application/pdf"));
            headers.add("content-disposition", "inline;filename=DemandBill.pdf");
        }
    }
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.stms.web.controller.transactions.SewerageCloseUpdateConnectionController.java

@RequestMapping(value = "/viewcloseconnectionnotice/{applicationNumber}", method = RequestMethod.GET)
public ResponseEntity<byte[]> viewCloseConnectionNotice(
        @ModelAttribute final SewerageApplicationDetails sewerageApplicationDetails, final HttpSession session,
        final HttpServletResponse response, final HttpServletRequest request) {
    final ReportOutput reportOutput = new ReportOutput();
    final HttpHeaders headers = new HttpHeaders();
    SewerageNotice sewerageNotice = null;
    File file = null;/*from w  w  w . j av a2 s  . c  o m*/
    FileStoreMapper fmp = null;
    final String closureNoticeNumber = request.getParameter("closureNoticeNumber");
    if (closureNoticeNumber != null)
        sewerageNotice = sewerageNoticeService.findByNoticeNoAndNoticeType(closureNoticeNumber,
                NOTICE_TYPE_CLOSER_NOTICE);
    if (sewerageNotice != null)
        fmp = sewerageNotice.getFileStore();
    if (fmp != null)
        file = fileStoreService.fetch(fmp, SewerageTaxConstants.FILESTORE_MODULECODE);
    try {
        if (file != null)
            reportOutput.setReportOutputData(FileUtils.readFileToByteArray(file));
        reportOutput.setReportFormat(ReportFormat.PDF);
    } catch (final IOException ioe) {
        LOGGER.error("Exception while generating close connection notice", ioe);
        throw new ValidationException(ioe.getMessage());
    }
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=CloseConnectionNotice.pdf");
    return new ResponseEntity<>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.stms.web.controller.transactions.SewerageWorkOrderNoticeController.java

private ResponseEntity<byte[]> generateReport(final SewerageApplicationDetails sewerageApplicationDetails)
        throws IOException {
    final HttpHeaders headers = new HttpHeaders();
    ReportOutput reportOutput = new ReportOutput();
    InputStream generateNoticePDF;
    SewerageNotice sewerageNotice = sewerageNoticeService.findByNoticeNoAndNoticeType(
            sewerageApplicationDetails.getWorkOrderNumber(),
            SewerageTaxConstants.NOTICE_TYPE_WORK_ORDER_NOTICE);
    if (sewerageNotice != null && sewerageNotice.getFileStore() != null) {
        final FileStoreMapper fmp = sewerageNotice.getFileStore();
        final File file = fileStoreService.fetch(fmp, SewerageTaxConstants.FILESTORE_MODULECODE);
        reportOutput.setReportOutputData(FileUtils.readFileToByteArray(file));
        reportOutput.setReportFormat(ReportFormat.PDF);
    } else {//from  w  w w  .  j a v a  2  s . com
        reportOutput = sewerageNoticeService.generateReportOutputForWorkOrder(sewerageApplicationDetails);
        if (reportOutput != null && reportOutput.getReportOutputData() != null) {
            generateNoticePDF = new ByteArrayInputStream(reportOutput.getReportOutputData());
            sewerageNotice = sewerageNoticeService.saveWorkOrderNotice(sewerageApplicationDetails,
                    generateNoticePDF);
            if (sewerageNotice != null) {
                sewerageApplicationDetails.addNotice(sewerageNotice);
                sewerageApplicationDetailsService.save(sewerageApplicationDetails);
            }
        }
    }
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    headers.add("content-disposition", "inline;filename=WorkOrderNotice.pdf");
    return new ResponseEntity<byte[]>(reportOutput.getReportOutputData(), headers, HttpStatus.CREATED);
}

From source file:org.egov.wtms.web.controller.application.UpdateConnectionController.java

@RequestMapping(value = "/update/{applicationNumber}", method = RequestMethod.POST)
public String update(@Valid @ModelAttribute WaterConnectionDetails waterConnectionDetails,
        final BindingResult resultBinder, final RedirectAttributes redirectAttributes,
        final HttpServletRequest request, final Model model,
        @RequestParam("files") final MultipartFile[] files) {

    request.getParameter("currentState");
    request.getParameter("ownerPosition");

    String mode = "";
    String workFlowAction = "";
    Double donationCharges = 0d;/*ww  w .jav a 2 s.c o m*/
    final String sourceChannel = request.getParameter("Source");

    if (request.getParameter(WORKFLOW_ACTION) != null) {
        workFlowAction = request.getParameter(WORKFLOW_ACTION);
        request.getSession().setAttribute(WORKFLOW_ACTION, workFlowAction);
    }

    if (request.getParameter(DONATION_AMOUNT) != null)
        donationCharges = Double.valueOf(request.getParameter(DONATION_AMOUNT));
    if (request.getParameter(MODE) != null)
        mode = request.getParameter(MODE);

    if (PROCEEDWITHOUTDONATION.equalsIgnoreCase(workFlowAction) && APPLICATION_STATUS_ESTIMATENOTICEGEN
            .equalsIgnoreCase(waterConnectionDetails.getStatus().getCode()))
        waterConnectionDetails
                .setStatus(waterTaxUtils.getStatusByCodeAndModuleType(APPLICATION_STATUS_FEEPAID, MODULETYPE));

    // For Submit Button
    if ((APPLICATION_STATUS_CREATED.equalsIgnoreCase(waterConnectionDetails.getStatus().getCode())
            || APPLICATION_STATUS_ESTIMATENOTICEGEN
                    .equalsIgnoreCase(waterConnectionDetails.getStatus().getCode()))
            && (FIELDINSPECTION.equalsIgnoreCase(mode) || EDIT_DEMAND.equalsIgnoreCase(mode)))
        if (SUBMITWORKFLOWACTION.equalsIgnoreCase(workFlowAction)
                || FORWARDWORKFLOWACTION.equalsIgnoreCase(workFlowAction)
                || SAVE.equalsIgnoreCase(workFlowAction)) {
            if (FIELDINSPECTION.equalsIgnoreCase(mode)) {
                final ConnectionCategory connectionCategory = connectionCategoryService
                        .findOne(waterConnectionDetails.getCategory().getId());
                connectionDemandService.generateDemandForApplication(waterConnectionDetails, connectionCategory,
                        donationCharges);
                // Attach any other file during field inspection and estimation
                final Set<FileStoreMapper> fileStoreSet = addToFileStore(files);
                Iterator<FileStoreMapper> fsIterator = null;
                if (fileStoreSet != null && !fileStoreSet.isEmpty())
                    fsIterator = fileStoreSet.iterator();
                while (fsIterator != null && fsIterator.hasNext())
                    waterConnectionDetails.getFieldInspectionDetails().setFileStore(fsIterator.next());

            }
            if (REGULARIZE_CONNECTION.equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode())
                    && (APPLICATION_STATUS_CREATED
                            .equalsIgnoreCase(waterConnectionDetails.getStatus().getCode())
                            || APPLICATION_STATUS_ESTIMATENOTICEGEN
                                    .equalsIgnoreCase(waterConnectionDetails.getStatus().getCode()))) {
                if (!FIELDINSPECTION.equals(mode) && connectionDemandService
                        .getWaterTaxDue(waterConnectionDetails, resultBinder).hasErrors())
                    return loadViewData(model, request, waterConnectionDetails);
                if (waterConnectionDetails.getConnection().getConsumerCode() == null) {
                    connectionDemandService
                            .createDemandDetailForPenaltyAndServiceCharges(waterConnectionDetails);
                    waterConnectionDetails.getConnection()
                            .setConsumerCode(waterTaxNumberGenerator.getNextConsumerNumber());
                }

                waterConnectionDetailsService.save(waterConnectionDetails);
                return loadViewData(model, request, waterConnectionDetails);
            }

            waterConnectionDetailsService.save(waterConnectionDetails);
            waterConnectionDetailsService.getCurrentSession().flush();

        } else if (workFlowAction.equalsIgnoreCase(WFLOW_ACTION_STEP_REJECT)) {
            waterConnectionDetailsService.getCurrentSession().evict(waterConnectionDetails);
            waterConnectionDetails = waterConnectionDetailsService.findBy(waterConnectionDetails.getId());
        }

    Long approvalPosition = 0l;
    String approvalComent = "";

    if (request.getParameter("approvalComent") != null)
        approvalComent = request.getParameter("approvalComent");

    if (workFlowAction != null && workFlowAction.equals(APPROVEWORKFLOWACTION)
            && waterConnectionDetails.getStatus() != null
            && waterConnectionDetails.getStatus().getCode() != null
            && waterConnectionDetails.getStatus().getCode().equals(APPLICATION_STATUS_FEEPAID))
        validateSanctionDetails(waterConnectionDetails, resultBinder);
    if (request.getParameter(APPRIVALPOSITION) != null && !request.getParameter(APPRIVALPOSITION).isEmpty())
        approvalPosition = Long.valueOf(request.getParameter(APPRIVALPOSITION));
    // For Get Configured ApprovalPosition from workflow history
    if (approvalPosition == null || approvalPosition.equals(Long.valueOf(0)))
        if (waterConnectionDetails.getCloseConnectionType() != null)
            approvalPosition = waterConnectionDetailsService.getApprovalPositionByMatrixDesignation(
                    waterConnectionDetails, approvalPosition, request.getParameter(ADDITIONALRULE), mode,
                    workFlowAction);
        else
            approvalPosition = waterConnectionDetailsService.getApprovalPositionByMatrixDesignation(
                    waterConnectionDetails, approvalPosition,
                    waterConnectionDetails.getApplicationType().getCode(), mode, workFlowAction);
    // to get modes to hide and show details in every user inbox

    request.getSession().setAttribute("APPROVAL_POSITION", approvalPosition);

    if (request.getParameter(APPRIVALPOSITION) == null)
        appendModeBasedOnApplicationCreator(model, request, waterConnectionDetails);

    if ((approvalPosition == null || approvalPosition.equals(Long.valueOf(0)))
            && request.getParameter(APPRIVALPOSITION) != null
            && !request.getParameter(APPRIVALPOSITION).isEmpty())
        approvalPosition = Long.valueOf(request.getParameter(APPRIVALPOSITION));
    // For ReConnection and Closure Connection
    if ((workFlowAction.equals(WFLOW_ACTION_STEP_REJECT)
            || workFlowAction.equalsIgnoreCase(WF_RECONNECTIONACKNOWLDGEENT_BUTTON))
            && (waterConnectionDetails.getStatus().getCode().equals(WORKFLOW_RECONNCTIONINITIATED)
                    || waterConnectionDetails.getStatus().getCode()
                            .equals(APPLICATION_STATUS_RECONNCTIONINPROGRESS)
                    || waterConnectionDetails.getStatus().getCode().equals(APPLICATION_STATUS_CLOSERINPROGRESS)
                    || waterConnectionDetails.getStatus().getCode().equals(APPLICATION_STATUS_CLOSERINITIATED)))
        approvalPosition = waterTaxUtils.getApproverPosition(JUNIOR_OR_SENIOR_ASSISTANT_DESIGN,
                waterConnectionDetails);
    if ((approvalPosition == null || approvalPosition.equals(Long.valueOf(0)))
            && (waterConnectionDetails.getStatus().getCode().equals(APPLICATION_STATUS_DIGITALSIGNPENDING)
                    || waterConnectionDetails.getStatus().getCode().equals(APPROVED)))
        throw new ValidationException("err.nouserdefinedforworkflow");
    if (!resultBinder.hasErrors()) {
        try {
            // For Closure Connection
            if (waterConnectionDetails.getCloseConnectionType() != null)
                if (waterConnectionDetails.getCloseConnectionType().equals(PERMENENTCLOSECODE))
                    waterConnectionDetails.setCloseConnectionType(ClosureType.Permanent.getName());
                else
                    waterConnectionDetails.setCloseConnectionType(ClosureType.Temporary.getName());

            if (workFlowAction != null)
                if (APPROVEWORKFLOWACTION.equalsIgnoreCase(workFlowAction)) {

                    if (waterConnectionDetails.getConnection().getConsumerCode() == null)
                        waterConnectionDetails.getConnection()
                                .setConsumerCode(waterTaxNumberGenerator.getNextConsumerNumber());

                    final WorkOrderNumberGenerator workOrderGen = beanResolver
                            .getAutoNumberServiceFor(WorkOrderNumberGenerator.class);
                    if (NEWCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())
                            || ADDNLCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())
                            || CHANGEOFUSE.equals(waterConnectionDetails.getApplicationType().getCode())
                            || REGULARIZE_CONNECTION
                                    .equals(waterConnectionDetails.getApplicationType().getCode())) {
                        waterConnectionDetails.setWorkOrderDate(new Date());
                        waterConnectionDetails.setWorkOrderNumber(workOrderGen.generateWorkOrderNumber());
                    }
                    ReportOutput reportOutput;
                    reportOutput = getReportOutputObject(waterConnectionDetails, workFlowAction);

                    // Setting FileStoreMap object while Commissioner Signs
                    // the document
                    if (reportOutput != null) {
                        String fileName;
                        if (CLOSINGCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())
                                || RECONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())
                                || REGULARIZE_CONNECTION
                                        .equals(waterConnectionDetails.getApplicationType().getCode()))
                            fileName = SIGNED_DOCUMENT_PREFIX + waterConnectionDetails.getApplicationNumber()
                                    + ".pdf";
                        else
                            fileName = SIGNED_DOCUMENT_PREFIX + waterConnectionDetails.getWorkOrderNumber()
                                    + ".pdf";

                        final InputStream fileStream = new ByteArrayInputStream(
                                reportOutput.getReportOutputData());
                        final FileStoreMapper fileStore = fileStoreService.store(fileStream, fileName,
                                "application/pdf", FILESTORE_MODULECODE);
                        if (CLOSINGCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode()))
                            waterConnectionDetails.setClosureFileStore(fileStore);
                        else if (RECONNECTION.equals(waterConnectionDetails.getApplicationType().getCode()))
                            waterConnectionDetails.setReconnectionFileStore(fileStore);
                        else
                            waterConnectionDetails.setFileStore(fileStore);
                        waterConnectionDetailsService
                                .updateWaterConnectionDetailsWithFileStore(waterConnectionDetails);
                    }
                } else if (workFlowAction.equalsIgnoreCase(WF_PREVIEW_BUTTON)
                        && (waterConnectionDetails.getApplicationType().getCode().equals(NEWCONNECTION)
                                || waterConnectionDetails.getApplicationType().getCode().equals(ADDNLCONNECTION)
                                || waterConnectionDetails.getApplicationType().getCode().equals(CHANGEOFUSE)))
                    return "redirect:/application/workorder?pathVar="
                            + waterConnectionDetails.getApplicationNumber();
                else if (workFlowAction.equalsIgnoreCase(WF_PREVIEW_BUTTON)
                        && waterConnectionDetails.getApplicationType().getCode().equals(CLOSINGCONNECTION))
                    return "redirect:/application/acknowlgementNotice?pathVar="
                            + waterConnectionDetails.getApplicationNumber();
                else if (workFlowAction.equalsIgnoreCase(WF_PREVIEW_BUTTON)
                        && waterConnectionDetails.getApplicationType().getCode().equals(RECONNECTION))
                    return "redirect:/application/ReconnacknowlgementNotice?pathVar="
                            + waterConnectionDetails.getApplicationNumber();
                else if (workFlowAction.equals(SIGNWORKFLOWACTION)) { // Sign
                    final WaterConnectionDetails upadtedWaterConnectionDetails = waterConnectionDetailsService
                            .findByApplicationNumber(waterConnectionDetails.getApplicationNumber());

                    final HttpSession session = request.getSession();
                    final Map<String, String> fileStoreIdsApplicationNoMap = new HashMap<>();
                    if (upadtedWaterConnectionDetails != null) {
                        if (CLOSINGCONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())) {
                            model.addAttribute(FILESTOREIDS,
                                    upadtedWaterConnectionDetails.getClosureFileStore().getFileStoreId());
                            fileStoreIdsApplicationNoMap.put(
                                    upadtedWaterConnectionDetails.getClosureFileStore().getFileStoreId(),
                                    upadtedWaterConnectionDetails.getApplicationNumber());
                        } else if (RECONNECTION.equals(waterConnectionDetails.getApplicationType().getCode())) {
                            model.addAttribute(FILESTOREIDS,
                                    upadtedWaterConnectionDetails.getReconnectionFileStore().getFileStoreId());
                            fileStoreIdsApplicationNoMap.put(
                                    upadtedWaterConnectionDetails.getReconnectionFileStore().getFileStoreId(),
                                    upadtedWaterConnectionDetails.getApplicationNumber());
                        } else {
                            model.addAttribute(FILESTOREIDS,
                                    upadtedWaterConnectionDetails.getFileStore().getFileStoreId());
                            fileStoreIdsApplicationNoMap.put(
                                    upadtedWaterConnectionDetails.getFileStore().getFileStoreId(),
                                    upadtedWaterConnectionDetails.getApplicationNumber());
                        }
                        session.setAttribute(APPLICATION_NUMBER,
                                upadtedWaterConnectionDetails.getApplicationNumber());
                    }
                    model.addAttribute("ulbCode", ApplicationThreadLocals.getCityCode());
                    session.setAttribute(MODE, mode);
                    session.setAttribute(APPROVAL_POSITION, approvalPosition);
                    session.setAttribute(APPROVAL_COMMENT, approvalComent);
                    session.setAttribute(FILE_STORE_ID_APPLICATION_NUMBER, fileStoreIdsApplicationNoMap);
                    model.addAttribute("isDigitalSignatureEnabled", waterTaxUtils.isDigitalSignatureEnabled());
                    return "newConnection-digitalSignatureRedirection";
                }
            waterConnectionDetailsService.updateWaterConnection(waterConnectionDetails, approvalPosition,
                    approvalComent, waterConnectionDetails.getApplicationType().getCode(), workFlowAction, mode,
                    null, sourceChannel);
        } catch (final ValidationException e) {
            throw new ValidationException(e.getMessage());
        }
        if (workFlowAction != null && !workFlowAction.isEmpty()
                && workFlowAction.equalsIgnoreCase(WF_STATE_BUTTON_GENERATEESTIMATE)) {

            final EstimationNumberGenerator estimationNoGen = beanResolver
                    .getAutoNumberServiceFor(EstimationNumberGenerator.class);

            waterConnectionDetails.setEstimationNumber(estimationNoGen.generateEstimationNumber());
            waterConnectionDetails.setEstimationNoticeDate(new Date());

            final String cityMunicipalityName = cityService.getMunicipalityName();
            final String districtName = cityService.getDistrictName();
            ReportOutput reportOutput = null;
            reportOutput = reportGenerationService.generateEstimationNoticeReport(waterConnectionDetails,
                    cityMunicipalityName, districtName);
            if (reportOutput != null) {
                final HttpHeaders headers = new HttpHeaders();
                headers.setContentType(MediaType.parseMediaType("application/pdf"));
                headers.add("content-disposition", "inline;filename=EstimationNotice.pdf");
                String fileName;
                fileName = SIGNED_DOCUMENT_PREFIX + waterConnectionDetails.getEstimationNumber() + ".pdf";
                final InputStream fileStream = new ByteArrayInputStream(reportOutput.getReportOutputData());
                final FileStoreMapper fileStore = fileStoreService.store(fileStream, fileName,
                        "application/pdf", FILESTORE_MODULECODE);
                waterConnectionDetails.setEstimationNoticeFileStoreId(fileStore);
                waterConnectionDetailsService.updateWaterConnectionDetailsWithFileStore(waterConnectionDetails);
            }
            return "redirect:/application/estimationNotice?pathVar="
                    + waterConnectionDetails.getApplicationNumber();

        }

        final Assignment currentUserAssignment = assignmentService.getPrimaryAssignmentForGivenRange(
                securityUtils.getCurrentUser().getId(), new Date(), new Date());
        String nextDesign = "";
        Assignment assignObj = null;
        List<Assignment> asignList = null;
        if (approvalPosition != null)
            assignObj = assignmentService.getPrimaryAssignmentForPositon(approvalPosition);
        if (assignObj != null) {
            asignList = new ArrayList<>();
            asignList.add(assignObj);
        } else if (assignObj == null && approvalPosition != null)
            asignList = assignmentService.getAssignmentsForPosition(approvalPosition, new Date());
        nextDesign = asignList == null || asignList.isEmpty() ? ""
                : asignList.get(0).getDesignation().getName();

        final String pathVars = waterConnectionDetails.getApplicationNumber() + ","
                + waterTaxUtils.getApproverName(approvalPosition) + ","
                + (currentUserAssignment != null ? currentUserAssignment.getDesignation().getName() : "") + ","
                + (nextDesign != null ? nextDesign : "");
        return "redirect:/application/application-success?pathVars=" + pathVars;
    } else
        return loadViewData(model, request, waterConnectionDetails);
}

From source file:org.encuestame.mvc.controller.AbstractJsonController.java

/**
 * Build a JSON error response based on the Exception message.
 * @param ex {@link Exception}/* ww  w  . j av  a 2 s  .  c o m*/
 * @return {@link ResponseEntity}
 */
private ResponseEntity<String> errorManage(Exception ex) {
    ex.printStackTrace();
    log.debug("ServletRequestBindingException" + ex.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    final String text_error = ex.getMessage().replace("'", "");
    final String error = "{error : '" + text_error + "', success : null}";
    return new ResponseEntity<String>(error, headers, HttpStatus.BAD_REQUEST);
}