com.abm.mainet.water.service.PlumberLicenseServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.abm.mainet.water.service.PlumberLicenseServiceImpl.java

Source

/**
 * 
 */
package com.abm.mainet.water.service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.abm.mainet.cfc.challan.dao.IChallanDAO;
import com.abm.mainet.common.constant.CFCConstants;
import com.abm.mainet.common.constant.MainetConstants;
import com.abm.mainet.common.constant.MainetServiceConstant;
import com.abm.mainet.common.domain.CFCApplicationAddressEntity;
import com.abm.mainet.common.dto.ApplicantDetailDTO;
import com.abm.mainet.common.dto.WardZoneBlockDTO;
import com.abm.mainet.common.exception.FrameworkException;
import com.abm.mainet.common.integration.dms.service.IFileUploadService;
import com.abm.mainet.common.integration.dto.ChargeDetailDTO;
import com.abm.mainet.common.integration.dto.DocumentDetailsVO;
import com.abm.mainet.common.integration.dto.RequestDTO;
import com.abm.mainet.common.integration.dto.WSRequestDTO;
import com.abm.mainet.common.integration.dto.WSResponseDTO;
import com.abm.mainet.common.integration.workflow.dto.TaskDefDto;
import com.abm.mainet.common.integration.workflow.service.ITaskManagerService;
import com.abm.mainet.common.master.domain.Organisation;
import com.abm.mainet.common.master.domain.TbCfcApplicationMstEntity;
import com.abm.mainet.common.service.ApplicationService;
import com.abm.mainet.common.service.CommonService;
import com.abm.mainet.common.service.ICFCApplicationAddressService;
import com.abm.mainet.common.service.ICFCApplicationMasterService;
import com.abm.mainet.common.utility.CommonMasterUtility;
import com.abm.mainet.common.utility.LookUp;
import com.abm.mainet.common.utility.RestClient;
import com.abm.mainet.common.utility.Utility;
import com.abm.mainet.common.utility.UtilityService;
import com.abm.mainet.water.constant.WaterConstants;
import com.abm.mainet.water.dao.PlumberLicenseRepository;
import com.abm.mainet.water.datamodel.WaterRateMaster;
import com.abm.mainet.water.domain.PlumberMaster;
import com.abm.mainet.water.domain.TbPlumRenewalScheduler;
import com.abm.mainet.water.domain.TbPlumberExperience;
import com.abm.mainet.water.domain.TbPlumberQualification;
import com.abm.mainet.water.dto.PlumLicenseRenewalSchDTO;
import com.abm.mainet.water.dto.PlumberExperienceDTO;
import com.abm.mainet.water.dto.PlumberLicenseRequestDTO;
import com.abm.mainet.water.dto.PlumberLicenseResponseDTO;
import com.abm.mainet.water.dto.PlumberQualificationDTO;
import com.abm.mainet.water.rest.ui.controller.WaterReconnectionController;

/**
 * @author Arun.Chavda
 *
 */
@Service
public class PlumberLicenseServiceImpl implements PlumberLicenseService {

    private static final Logger LOGGER = LoggerFactory.getLogger(WaterReconnectionController.class);

    @Autowired
    private ApplicationService applicationService;
    @Autowired
    private IFileUploadService fileUploadService;
    @Resource
    PlumberLicenseRepository plumberLicenseRepository;
    @Autowired
    private ICFCApplicationAddressService iCFCApplicationAddressService;
    @Resource
    private MessageSource messageSource;
    @Resource
    CommonService commonService;
    @Autowired
    private ICFCApplicationMasterService cfcService;
    @Autowired
    private ITaskManagerService iTaskManagerService;
    @Resource
    private IChallanDAO iChallanDAO;

    @Override
    @Transactional
    public PlumberLicenseResponseDTO savePlumberLicenseDetails(PlumberLicenseRequestDTO requestDTO) {
        RequestDTO applicantDetailDTO = new RequestDTO();
        applicantDetailDTO.setTitleId(requestDTO.getApplicant().getApplicantTitle());
        applicantDetailDTO.setfName(requestDTO.getApplicant().getApplicantFirstName());
        applicantDetailDTO.setlName(requestDTO.getApplicant().getApplicantLastName());
        applicantDetailDTO.setMobileNo(requestDTO.getApplicant().getMobileNo());
        applicantDetailDTO.setEmail(requestDTO.getApplicant().getEmailId());
        applicantDetailDTO.setAreaName(requestDTO.getApplicant().getAreaName());
        applicantDetailDTO.setPincodeNo(Long.parseLong(requestDTO.getApplicant().getPinCode()));
        applicantDetailDTO.setServiceId(requestDTO.getServiceId());
        applicantDetailDTO.setDeptId(requestDTO.getDeptId());
        applicantDetailDTO.setUserId(requestDTO.getUserId());
        applicantDetailDTO.setOrgId(requestDTO.getOrgId());
        applicantDetailDTO.setLangId((long) requestDTO.getApplicant().getLangId());
        applicantDetailDTO.setBplNo(requestDTO.getApplicant().getBplNo());
        Organisation organisation = new Organisation();
        organisation.setOrgid(requestDTO.getOrgId());
        LookUp lookUp = CommonMasterUtility
                .getNonHierarchicalLookUpObject(Long.valueOf(requestDTO.getApplicant().getGender()), organisation);
        applicantDetailDTO.setGender(lookUp.getLookUpCode());
        applicantDetailDTO.setCityName(requestDTO.getApplicant().getVillageTownSub());
        applicantDetailDTO.setBlockName(requestDTO.getApplicant().getBlockName());
        if (null != requestDTO.getApplicant().getAadharNo()
                && !"".equals(requestDTO.getApplicant().getAadharNo())) {
            Long aadhaarNo = Long.parseLong(requestDTO.getApplicant().getAadharNo());
            applicantDetailDTO.setUid(aadhaarNo);
        }
        if (null != requestDTO.getApplicant().getDwzid1()) {
            applicantDetailDTO.setWardNo(requestDTO.getApplicant().getDwzid1());
        }
        if (null != requestDTO.getApplicant().getDwzid2()) {
            applicantDetailDTO.setZoneNo(requestDTO.getApplicant().getDwzid2());
        }
        if (null != requestDTO.getApplicant().getDwzid3()) {
            applicantDetailDTO.setBlockNo(String.valueOf(requestDTO.getApplicant().getDwzid3()));
        }
        Long applicationId = applicationService.createApplication(applicantDetailDTO);
        PlumberMaster entity = new PlumberMaster();
        entity.setPlumFname(requestDTO.getPlumberFName());
        entity.setPlumMname(requestDTO.getPlumberMName());
        entity.setPlumLname(requestDTO.getPlumberLName());
        entity.setLangId(requestDTO.getLangId());
        entity.setLgIpMac(requestDTO.getLgIpMac());
        entity.setLmoddate(requestDTO.getPlumAppDate());
        entity.setOrgid(requestDTO.getOrgId());
        entity.setUserId(requestDTO.getUserId());
        entity.setApmApplicationId(applicationId);
        final StringBuilder builder = new StringBuilder();
        builder.append(requestDTO.getOrgId()).append(MainetServiceConstant.DOUBLE_BACK_SLACE)
                .append("Plumber_Photo").append(MainetServiceConstant.DOUBLE_BACK_SLACE)
                .append(Utility.getTimestamp());
        String dirPath = builder.toString();
        entity.setPlumImagePath(dirPath);
        entity.setPlumImage(requestDTO.getPlumberImage());
        DocumentDetailsVO documentDetailsVO = new DocumentDetailsVO();
        documentDetailsVO.setDocumentByteCode(requestDTO.getImageByteCode());
        String fileNetPath = messageSource.getMessage("upload.physicalPath", new Object[] {}, StringUtils.EMPTY,
                Locale.ENGLISH);
        fileUploadService.convertAndSaveFile(documentDetailsVO, fileNetPath, dirPath, requestDTO.getPlumberImage());
        try {
            PlumberMaster plumberMaster = plumberLicenseRepository.savePlumberLicenseDetails(entity);
            Long plumberId = null;
            if (null != plumberMaster) {
                plumberId = plumberMaster.getPlumId();
            }
            TbPlumberQualification plumberQualification = null;
            List<TbPlumberQualification> plumberQualificationsList = new ArrayList<TbPlumberQualification>();
            for (PlumberQualificationDTO qualification : requestDTO.getPlumberQualificationDTOList()) {
                plumberQualification = new TbPlumberQualification();
                plumberQualification.setPlumQualification(qualification.getPlumQualification());
                plumberQualification.setPlumInstituteName(qualification.getPlumInstituteName());
                plumberQualification.setPlumInstituteAddress(qualification.getPlumInstituteAddress());
                plumberQualification.setPlumPassYear(qualification.getPlumPassYear());
                plumberQualification.setPlumPassMonth(qualification.getPlumPassMonth());
                plumberQualification.setPlumPercentGrade(qualification.getPlumPercentGrade());
                plumberQualification.setUserId(requestDTO.getUserId());
                plumberQualification.setLangId((int) (long) requestDTO.getLangId());
                plumberQualification.setOrgId(requestDTO.getOrgId());
                plumberQualification.setLgIpMac(requestDTO.getLgIpMac());
                plumberQualification.setLmodDate(requestDTO.getPlumAppDate());
                plumberQualification.setPlumId(plumberId);
                plumberQualification.setIsDeleted("N");
                plumberQualificationsList.add(plumberQualification);
            }
            plumberLicenseRepository.savePlumberLicenseAcademicDetails(plumberQualificationsList);

            TbPlumberExperience plumberExperience = null;
            List<TbPlumberExperience> plumberExperiencesList = new ArrayList<TbPlumberExperience>();
            for (PlumberExperienceDTO experienceDTO : requestDTO.getPlumberExperienceDTOList()) {
                plumberExperience = new TbPlumberExperience();
                plumberExperience.setPlumCompanyName(experienceDTO.getPlumCompanyName());
                plumberExperience.setPlumCompanyAddress(experienceDTO.getPlumCompanyAddress());
                Date frmDate = Utility.stringToDate(experienceDTO.getExpFromDate());
                plumberExperience.setPlumFromDate(frmDate);
                Date toDate = Utility.stringToDate(experienceDTO.getExpToDate());
                plumberExperience.setPlumToDate(toDate);
                String exp = Double.toString(experienceDTO.getExperience());
                String[] string = exp.split("\\.");
                String year = string[0];
                String month = string[1];
                plumberExperience.setPlumExpYear(Long.parseLong(year));
                plumberExperience.setPlumExpMonth(Long.parseLong(month));
                plumberExperience.setPlumCPDFirmType(experienceDTO.getFirmType());
                plumberExperience.setUserId(requestDTO.getUserId());
                plumberExperience.setLangId((int) (long) requestDTO.getLangId());
                plumberExperience.setOrgId(requestDTO.getOrgId());
                plumberExperience.setLgIpMac(requestDTO.getLgIpMac());
                plumberExperience.setLmodDate(requestDTO.getPlumAppDate());
                plumberExperience.setPlumId(plumberId);
                plumberExperience.setIsDeleted("N");
                plumberExperiencesList.add(plumberExperience);
            }
            plumberLicenseRepository.savePlumberLicenseExperienceDetails(plumberExperiencesList);
        } catch (Exception e) {
            LOGGER.error("Exception occured at Plumber License Saving data", e);
        }
        applicantDetailDTO.setApplicationId(applicationId);
        PlumberLicenseResponseDTO responseDTO = new PlumberLicenseResponseDTO();
        responseDTO.setStatus(MainetServiceConstant.Status.SUCCESS);
        if (requestDTO.getDocumentList() != null && !requestDTO.getDocumentList().isEmpty()) {
            boolean isUploaded = fileUploadService.doFileUpload(requestDTO.getDocumentList(), applicantDetailDTO);
            if (!isUploaded) {
                responseDTO.setUploadedDocSize(requestDTO.getDocumentList().size());
                throw new FrameworkException("Problem while saving checklist");
            }
        }
        responseDTO.setApplicationId(applicationId);
        return responseDTO;
    }

    @Override
    @Transactional(readOnly = true)
    public PlumberMaster getPlumberDetailsByAppId(long applicationId, Long orgId) {
        return plumberLicenseRepository.getPlumberDetailsByAppId(applicationId, orgId);
    }

    @Override
    @Transactional
    public ApplicantDetailDTO populateApplicantInfo(ApplicantDetailDTO dto, TbCfcApplicationMstEntity cfcEntity) {
        if (dto == null)
            dto = new ApplicantDetailDTO();
        long applicationId = cfcEntity.getApmApplicationId();
        return initializeApplicantAddressDetail(initializeApplicationDetail(dto, cfcEntity),
                cfcService.getApplicantsDetails(applicationId));
    }

    private ApplicantDetailDTO initializeApplicationDetail(ApplicantDetailDTO dto,
            TbCfcApplicationMstEntity entity) {
        dto.setApplicantTitle(entity.getApmTitle());
        dto.setApplicantFirstName(entity.getApmFname());
        dto.setApplicantMiddleName(entity.getApmMname());
        dto.setApplicantLastName(entity.getApmLname());
        if (entity.getApmBplNo() != null) {
            dto.setBplNo(entity.getApmBplNo());
            dto.setIsBPL(WaterConstants.PlumberLicense.YES);
        } else {
            dto.setIsBPL(WaterConstants.PlumberLicense.NO);
        }
        if (entity.getApmUID() != null)
            dto.setAadharNo(entity.getApmUID().toString());
        return dto;
    }

    private ApplicantDetailDTO initializeApplicantAddressDetail(ApplicantDetailDTO dto,
            CFCApplicationAddressEntity addressEntity) {
        dto.setMobileNo(addressEntity.getApaMobilno());
        dto.setEmailId(addressEntity.getApaEmail());
        dto.setFloorNo(addressEntity.getApaFloor());
        dto.setBuildingName(addressEntity.getApaBldgnm());
        dto.setRoadName(addressEntity.getApaRoadnm());
        dto.setAreaName(addressEntity.getApaAreanm());
        dto.setVillageTownSub(addressEntity.getApaCityName());
        dto.setBlockName(addressEntity.getApaBlockName());
        if (addressEntity.getApaPincode() != null)
            dto.setPinCode(Long.toString(addressEntity.getApaPincode()));
        dto.setDwzid1(addressEntity.getApaZoneNo());
        dto.setDwzid2(addressEntity.getApaWardNo());
        return dto;
    }

    @Override
    @Transactional
    public List<PlumberQualificationDTO> getPlumberQualificationDetails(Long plumberId, Long orgId) {
        List<TbPlumberQualification> list = plumberLicenseRepository.getPlumberQualificationDetails(plumberId,
                orgId);
        List<PlumberQualificationDTO> qualificationDTOs = new ArrayList<PlumberQualificationDTO>();
        PlumberQualificationDTO qualificationDTO = null;
        if (null != list && !list.isEmpty()) {
            for (TbPlumberQualification qualificationEntity : list) {
                qualificationDTO = new PlumberQualificationDTO();
                qualificationDTO.setPlumQualification(qualificationEntity.getPlumQualification());
                qualificationDTO.setPlumInstituteName(qualificationEntity.getPlumInstituteName());
                qualificationDTO.setPlumInstituteAddress(qualificationEntity.getPlumInstituteAddress());
                qualificationDTO.setPlumPassYear(qualificationEntity.getPlumPassYear());
                qualificationDTO.setPlumPassMonth(qualificationEntity.getPlumPassMonth());
                qualificationDTO.setPlumPercentGrade(qualificationEntity.getPlumPercentGrade());
                qualificationDTO.setPlumQualId(qualificationEntity.getPlumQualId());
                qualificationDTOs.add(qualificationDTO);
            }
        }
        return qualificationDTOs;
    }

    @Override
    @Transactional
    public List<PlumberExperienceDTO> getPlumberExperienceDetails(Long plumberId, Long orgId) {
        List<TbPlumberExperience> list = plumberLicenseRepository.getPlumberExperienceDetails(plumberId, orgId);
        List<PlumberExperienceDTO> experienceDTOs = new ArrayList<PlumberExperienceDTO>();
        PlumberExperienceDTO experienceDTO = null;
        if (null != list && !list.isEmpty()) {
            String string = null;
            String frmDate = null;
            String toDate = null;
            for (TbPlumberExperience experienceEntity : list) {
                experienceDTO = new PlumberExperienceDTO();
                experienceDTO.setPlumCompanyName(experienceEntity.getPlumCompanyName());
                experienceDTO.setPlumCompanyAddress(experienceEntity.getPlumCompanyAddress());
                experienceDTO.setPlumExpYear(experienceEntity.getPlumExpYear());
                experienceDTO.setPlumExpMonth(experienceEntity.getPlumExpMonth());
                string = experienceEntity.getPlumExpYear() + "." + experienceEntity.getPlumExpMonth();
                experienceDTO.setExperience(Double.parseDouble(string));
                frmDate = Utility.dateToString(experienceEntity.getPlumFromDate());
                experienceDTO.setExpFromDate(frmDate);
                toDate = Utility.dateToString(experienceEntity.getPlumToDate());
                experienceDTO.setExpToDate(toDate);
                experienceDTO.setFirmType(experienceEntity.getPlumCPDFirmType());
                experienceDTO.setPlumExpId(experienceEntity.getPlumExpId());
                experienceDTOs.add(experienceDTO);
            }
        }
        return experienceDTOs;
    }

    @Override
    @Transactional
    public WardZoneBlockDTO getWordZoneBlockByApplicationId(Long applicationId, Long serviceId, Long orgId) {
        CFCApplicationAddressEntity master = iCFCApplicationAddressService
                .getApplicationAddressByAppId(applicationId, orgId);
        WardZoneBlockDTO wardZoneDTO = null;
        if (master != null) {
            wardZoneDTO = new WardZoneBlockDTO();
            if (master.getApaWardNo() != null)
                wardZoneDTO.setAreaDivision1(master.getApaWardNo());
            if (master.getApaZoneNo() != null)
                wardZoneDTO.setAreaDivision2(master.getApaZoneNo());
            if (null != master.getApaBlockno() && !master.getApaBlockno().isEmpty()) {
                Long blockNo = Long.parseLong(master.getApaBlockno());
                wardZoneDTO.setAreaDivision3(blockNo);
            }
            /*if(master.getCodDwzid4() !=null)
            wardZoneDTO.setAreaDivision4(master.getCodDwzid4());
             if(master.getCodDwzid5() !=null)
            wardZoneDTO.setAreaDivision5(master.getCodDwzid5());*/
        }
        return wardZoneDTO;
    }

    /**
     * This method used for get Scrutiny level LOI charges  
     */
    @Override
    @Transactional
    public Map<Long, Double> getLoiCharges(Long applicationId, Long serviceId, Long orgId) {

        Map<Long, Double> chargeMapData = new HashMap<>();

        //      [START]      BRMS call initialize model
        WSRequestDTO dto = new WSRequestDTO();
        List<ChargeDetailDTO> chargeMap = null;
        dto.setModelName("WaterRateMaster");
        WSResponseDTO response = RestClient.callBRMS(dto, "/BRMS/getInitializedModel");
        if (MainetConstants.WebServiceStatus.SUCCESS.equalsIgnoreCase(response.getWsStatus())) {
            List<Object> waterRateMasterList = RestClient.castResponse(response, WaterRateMaster.class, 0);
            WaterRateMaster WaterRateMaster = (WaterRateMaster) waterRateMasterList.get(0);
            WaterRateMaster.setOrgId(orgId);
            WaterRateMaster.setServiceCode(WaterConstants.ServiceShortCode.PlUMBER_LICENSE);
            WaterRateMaster.setChargeApplicableAt(Long.toString(CommonMasterUtility
                    .getValueFromPrefixLookUp(MainetConstants.NewWaterServiceConstants.SCRUTINY, "CAA")
                    .getLookUpId()));
            dto.setDataModel(WaterRateMaster);
            WSResponseDTO res = RestClient.callBRMS(dto, "/WaterServiceCharge/initializeOtherFieldsForTaxes");
            if (MainetConstants.WebServiceStatus.SUCCESS.equalsIgnoreCase(res.getWsStatus())) {
                if (!res.isFree()) {
                    List<?> rates = RestClient.castResponse(res, WaterRateMaster.class);
                    List<WaterRateMaster> requiredCHarges = new ArrayList<WaterRateMaster>();
                    for (Object rate : rates) {
                        WaterRateMaster master1 = (WaterRateMaster) rate;
                        requiredCHarges.add(master1);
                    }
                    dto.setDataModel(requiredCHarges);
                    WSResponseDTO output = RestClient.callBRMS(dto, "/WaterServiceCharge/serviceCharge");
                    List<ChargeDetailDTO> detailDTOs = output.getCharges();
                    chargeMap = detailDTOs;
                    for (ChargeDetailDTO chargeDTO : detailDTOs) {
                        chargeMapData.put(chargeDTO.getChargeCode(), chargeDTO.getChargeAmount());
                    }

                } else {
                    LOGGER.error(
                            "LOI Charge is not applicable for Change of Ownership, might be not configured in charge master table");
                }
            } else {
                LOGGER.error(
                        "LOI Charge is not applicable for Change of Ownership, might be not configured in charge master table");
            }
        } else {
            LOGGER.error(
                    "LOI Charge is not applicable for Change of Ownership, might be not configured in charge master table");
            //   throw new FrameworkException("LOI Charge is not applicable for Change of Ownership, might be not configured in charge master table");
        }
        //      [END]   
        return chargeMapData;

    }

    @Override
    @Transactional
    public void updatedPlumberLicenseDetailsOnScrutiny(PlumberMaster plumberMaster,
            List<TbPlumberQualification> tbPlumberQualifications, List<TbPlumberExperience> tbPlumberExperiences) {
        plumberLicenseRepository.savePlumberInterviewDetails(plumberMaster);
        plumberLicenseRepository.savePlumberLicenseAcademicDetails(tbPlumberQualifications);
        plumberLicenseRepository.savePlumberLicenseExperienceDetails(tbPlumberExperiences);
    }

    @Override
    @Transactional
    public void updatedQualAndExpIsDeletedFlag(String[] qualRowId, String[] expRowId) {
        if (qualRowId != null && qualRowId.length > 1) {
            for (String string : qualRowId) {
                long qualId = Long.valueOf(string);
                plumberLicenseRepository.updatedQualificationIsDeletedFlag(qualId);
            }
        }
        if (expRowId != null && expRowId.length > 1) {
            for (String string : expRowId) {
                long expId = Long.valueOf(string);
                plumberLicenseRepository.updatedExpIsDeletedFlag(expId);
            }
        }
    }

    @Override
    @Transactional
    public PlumLicenseRenewalSchDTO updatedUserTaskAndPlumberLicenseExecutionDetails(PlumberMaster master,
            TaskDefDto taskDefDto) {
        PlumLicenseRenewalSchDTO renewalSchDTO = new PlumLicenseRenewalSchDTO();
        Long licNo = iChallanDAO.getSequence(WaterConstants.PlumberLicense.PLUM_MASTER_TABLE.MODULE,
                WaterConstants.PlumberLicense.PLUM_MASTER_TABLE.TABLE,
                WaterConstants.PlumberLicense.PLUM_MASTER_TABLE.COLUMN, master.getOrgid(),
                CFCConstants.RECEIPT_MASTER.Reset_Type, null);
        Date sysDate = UtilityService.getSQLDate(new Date());
        String string = sysDate.toString();
        String[] strings = string.split("-");
        String yearPart = strings[0];
        String paddingLicNo = String.format("%04d", Integer.parseInt(licNo.toString()));
        String orgId = master.getOrgid().toString();
        String licNumber = orgId.concat(yearPart).concat(paddingLicNo);
        renewalSchDTO.setLicenseNo(String.valueOf(licNumber));
        Long dependOnId = null;
        List<TbPlumRenewalScheduler> renewalSchedulers = plumberLicenseRepository
                .getPlumRenewalSchedulerDetails(master.getServiceId(), master.getOrgid());
        for (TbPlumRenewalScheduler tbPlumRenewalScheduler : renewalSchedulers) {
            if (tbPlumRenewalScheduler.getTodate() == null) {
                dependOnId = tbPlumRenewalScheduler.getDependon();
                break;
            }
        }

        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        String toDateDependOn = CommonMasterUtility.getNonHierarchicalLookUpObject(dependOnId).getLookUpCode();
        if (WaterConstants.PlumberLicense.TODATE_CALENDER_YEAR_WISE.equals(toDateDependOn)) {
            cal.setTime(date);
            int year = cal.get(Calendar.YEAR);
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.MONTH, 11);
            cal.set(Calendar.DAY_OF_MONTH, 31);
            Date endDate = cal.getTime();
            renewalSchDTO.setLicenseToDate(Utility.dateToString(endDate));
            renewalSchDTO.setLicenseFromDate(Utility.dateToString(date));
        } else if (WaterConstants.PlumberLicense.TODATE_FINANCIAL_YEAR_WISE.equals(toDateDependOn)) {
            cal.setTime(date);
            int year = cal.get(Calendar.YEAR);
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.MONTH, 2);
            cal.set(Calendar.DAY_OF_MONTH, 31);
            Date endDate = cal.getTime();
            renewalSchDTO.setLicenseToDate(Utility.dateToString(endDate));
            renewalSchDTO.setLicenseFromDate(Utility.dateToString(date));
        } else if (WaterConstants.PlumberLicense.TODATE_ON_LICENSE_DATE_WISE.equals(toDateDependOn)) {
            Date today = cal.getTime();
            cal.add(Calendar.YEAR, 1); // to get previous year add -1
            cal.add(Calendar.DAY_OF_MONTH, -1);
            Date nextYear = cal.getTime();
            renewalSchDTO.setLicenseToDate(Utility.dateToString(nextYear));
            renewalSchDTO.setLicenseFromDate(Utility.dateToString(today));
        }
        master.setPlumLicNo(String.valueOf(licNo));
        master.setPlumLicFromDate(Utility.stringToDate(renewalSchDTO.getLicenseFromDate()));
        master.setPlumLicToDate(Utility.stringToDate(renewalSchDTO.getLicenseToDate()));
        plumberLicenseRepository.updatedPlumberLicenseExecutionDetailsByDept(master);
        iTaskManagerService.updateUserTask(taskDefDto);
        return renewalSchDTO;
    }

}