FormValidatorWorkOrder

mail@pastecode.io avatar
unknown
java
a month ago
12 kB
0
Indexable
Never
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eksad.dam.ddms.h2.workspace.validation.workorder;

import com.eksad.dam.ddms.h2.workspace.validation.CommonFormValidator;
import com.eksad.dam.ui.common.ui.CommonViewModel;
import com.eksad.dam.ui.common.util.StringUtil;
import com.eksad.ddms.common.h2.dto.customerattendee.CustomerAttendeeDTO;
import com.eksad.ddms.common.h2.dto.unitcustomer.UnitCustomerDTO;
import com.eksad.ddms.common.h2.dto.workorder.WorkOrderDTO;
import com.eksad.ddms.common.h2.dto.workorder.WorkOrderSparepartDTO;
import com.eksad.ddms.common.type.WoStatus;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.zkoss.bind.ValidationContext;

/**
 *
 * @author hello world
 */
public class FormValidatorWorkOrder extends CommonFormValidator{

    @Override
    public void validate(ValidationContext vc) {
        WorkOrderDTO workOrder = (WorkOrderDTO) vc.getValidatorArg("wo");
        UnitCustomerDTO unitCustomer = (UnitCustomerDTO) vc.getValidatorArg("unitCustomer");
        CustomerAttendeeDTO customerAttendee = (CustomerAttendeeDTO) vc.getValidatorArg("custAtendee");
        Boolean noBukuC2null = Boolean.FALSE;
        Boolean isVisit = (Boolean) vc.getValidatorArg("isVisit");
        Boolean isPUD = (Boolean) vc.getValidatorArg("isPUD");
        Boolean isUnitEV = (Boolean) vc.getValidatorArg("isUnitEV");
        Boolean kesediaanCheckShown = (Boolean) vc.getValidatorArg("kesediaanCheckShown");
        Boolean showErrMsgFromLCR = Boolean.FALSE;
        try {
            System.out.println(new ObjectMapper().writeValueAsString(workOrder)+" "+new ObjectMapper().writeValueAsString(unitCustomer));
        } catch (JsonProcessingException ex) {
            Logger.getLogger(FormValidatorWorkOrder.class.getName()).log(Level.SEVERE, null, ex);
        }

        validateNullString(vc, workOrder.getNoPolisi(), "nopol", "Nomor polisi tidak boleh kosong");
        validateNullString(vc, unitCustomer.getMachineNumber(), "nomesin", "Nomor mesin tidak boleh kosong");
        validateNullString(vc, workOrder.getTipeKPB(), "tipeKPB", "Harap pilih tipe KPB");
//        if(workOrder.getIsLCR()) {
//            validateNullString(vc, workOrder.getHistoryLCRDTO().getKesediaan(), "kesediaan", "Harap Pilih Kesediaan");
//        }

//        String machineNumberPattern = "[\\w]{5}[\\s]{1}[\\w]+"; // format nomor mesin 5 digit alpahnumeric, 1 digit spasi, alphanumeric
        String machineNumberPattern = "^(?=.{0,5}[a-zA-Z])(?=.{0,5}[0-9])[A-Za-z0-9]{5}[\\s]{0,1}[0-9]{7}$"; // format nomor mesin 5 digit alpahnumeric, 0 atau 1 digit spasi, 7 digit numeric

        if(StringUtil.hasValue(unitCustomer.getMachineNumber())){
            if(!Pattern.matches(machineNumberPattern, unitCustomer.getMachineNumber())){
                this.addInvalidMessage(vc, "nomesin", "Input no mesin tidak valid! contoh no mesin : XX12X 1234567");
                CommonViewModel.showErrorMessagebox( "Input no mesin tidak valid! \nContoh no mesin : \nXX12X 1234567");
            }
        }

//        String chasisNumberPattern = "[\\w]{11}[\\s]{0,1}[0-9]{6}$"; // format nomor rangka 11 digit alphanumeric, 0 atau 1 digit spasi, 6 digit numeric
        String chasisNumberPattern = "^(?=.{0,11}[a-zA-Z])(?=.{0,11}[0-9])[A-Za-z0-9]{11}[\\s]{0,1}[0-9]{6}$"; // format nomor rangka 11 digit alphanumeric, 0 atau 1 digit spasi, 6 digit numeric
        String chasisNumberPatternForLen14 = "^(?=.{0,8}[a-zA-Z])(?=.{0,8}[0-9])[A-Za-z0-9]{8}[\\s]{0,1}[0-9]{6}$"; // format nomor rangka 8 digit alphanumeric, 0 atau 1 digit spasi, 6 digit numeric

        if(StringUtil.hasValue(unitCustomer.getChasisNumber())){
            if(unitCustomer.getChasisNumber().length()>=17){
                if(!Pattern.matches(chasisNumberPattern, unitCustomer.getChasisNumber())){
                    this.addInvalidMessage(vc, "norangka", "Input no rangka tidak valid! contoh no rangka : XX123X4X56X 123456");
                    CommonViewModel.showErrorMessagebox( "Input no rangka tidak valid! \nContoh no rangka : \nXX123X4X56X 123456");
                }
            } else {
                if(!Pattern.matches(chasisNumberPatternForLen14, unitCustomer.getChasisNumber())){
                    this.addInvalidMessage(vc, "norangka", "Input no rangka tidak valid! contoh no rangka : XX123X4X56X 123456");
                    CommonViewModel.showErrorMessagebox( "Input no rangka tidak valid! \nContoh no rangka : \nXX123X4X56X 123456");
                }
            }
        }

        validateNullString(vc, workOrder.getUnitTypeID(), "utp", "Tipe unit tidak boleh kosong");
        validateNullWoDisclaimerType(vc, workOrder.getWoDisclaimerType(), "woDisclaimerType", "Harap pilih salah satu");
        validateNegativeNumber(vc, workOrder.getKmMotor(), "km", "Km motor tidak boleh kosong atau bernilai negatif");

        validateNullString(vc, unitCustomer.getPhone(),"notlp","No telepon tidak boleh kosong");
        validatePhoneIsNumber(vc, unitCustomer.getPhone(),"notlp","No telepon tidak boleh huruf atau simbol");
        validateNullString(vc, unitCustomer.getCustomerName(),"name","Nama tidak boleh kosong");

        List<WorkOrderSparepartDTO> woSparepartC2 = workOrder.getListPart()
                                                           .stream()
                                                           .filter(p-> p.getC2())
                                                           .collect(Collectors.toList());
        if (woSparepartC2.size()>0) {
            validateNullString(vc, workOrder.getNoBukuC2(),"bukuC2","No Buku C2 tidak boleh kosong");
            noBukuC2null = !StringUtil.hasValue(workOrder.getNoBukuC2());
        }


        if(workOrder.getListJasa() == null){
            this.addInvalidMessage(vc, "jasa", "Jasa harus diisi");
        }else if(workOrder.getListJasa().isEmpty()){
            this.addInvalidMessage(vc, "jasa", "Jasa harus diisi");
        }
        validateNullString(vc, workOrder.getUnitEntrySource(), "unitentrysource", "Asal unit entry tidak boleh kosong");


        if (isVisit == true) {
            validateNullString(vc, workOrder.getMechanicID(), "mechanicid", "Nama Mekanik tidak boleh kosong");
        }

        if (workOrder.getProsesServicePUD()!=null) {
            isPUD = Boolean.TRUE;
             if(workOrder.getProsesServicePUD().equalsIgnoreCase("isi")){
                this.addInvalidMessage(vc, "processervicepud", "Proses Service PUD tidak boleh kosong");
            }
            validateNullString(vc, workOrder.getProsesServicePUD(), "processervicepud", "Proses Service PUD tidak boleh kosong");
        }else{
             isPUD = Boolean.FALSE;
        }
        if (isUnitEV){
            if(unitCustomer.getChasisNumber().length() != 17){
                this.addInvalidMessage(vc, "norangka", "No rangka EV harus 17 digit.");
            }
        }

        if (workOrder.getIsLCR() && (workOrder.getWoLastKnownStatus().equals(WoStatus.REGISTERED)) || workOrder.getWoLastKnownStatus().equals(WoStatus.IN_PIT)){
            if (workOrder.getHistoryLCRDTO() != null){
                if (workOrder.getHistoryLCRDTO().getKesediaan() != null){
                    if (workOrder.getHistoryLCRDTO().getKesediaan().contains("03")){
                        if (workOrder.getHistoryLCRDTO().getReason() == null){
                            this.addInvalidMessage(vc, "alasanlcr", "Alasan Harus Dipilih.");
                            showErrMsgFromLCR = Boolean.TRUE;
                        }
                    } else if (workOrder.getHistoryLCRDTO().getKesediaan().contains("02")){
                        validateNullDate(vc, workOrder.getHistoryLCRDTO().getBookingDate(), "lcr_booking", "Harap Pilih Tanggal Booking.");
                        if(workOrder.getHistoryLCRDTO().getBookingDate() == null) {
                        	showErrMsgFromLCR = Boolean.TRUE;
                        }
                    } else if (workOrder.getHistoryLCRDTO().getKesediaan().contains("01") && StringUtil.hasValue(workOrder.getHistoryLCRDTO().getCheckingResult())
                    		&& StringUtil.hasValue(workOrder.getHistoryLCRDTO().getWillingnessToDoWork())
                    		&& workOrder.getHistoryLCRDTO().getWillingnessToDoWork().contains("02")){
                    	validateNullDate(vc, workOrder.getHistoryLCRDTO().getBookingDate(), "lcr_booking_aftercheck", "Harap Pilih Tanggal Booking.");
                    	if(workOrder.getHistoryLCRDTO().getBookingDate() == null) {
                    		showErrMsgFromLCR = Boolean.TRUE;
                    	}
                    } else if (workOrder.getHistoryLCRDTO().getKesediaan().contains("01") && workOrder.getWoLastKnownStatus().equals(WoStatus.IN_PIT)
                    		&& StringUtil.isNullStr(workOrder.getHistoryLCRDTO().getCheckingResult())){
                    	this.addInvalidMessage(vc, "hasilpengecekanlcr", "Hasil Pengecekan wajib diisi jika pilih Bersedia Langsung Dilakukan Pengecekan.");
                    } else if (kesediaanCheckShown && StringUtil.hasValue(workOrder.getHistoryLCRDTO().getCheckingResult()) && StringUtil.isNullStr(workOrder.getHistoryLCRDTO().getWillingnessToDoWork()) &&
                            !workOrder.getHistoryLCRDTO().getCheckingResult().startsWith("02")) {
                    	this.addInvalidMessage(vc, "kesediaanpengerjaanlcr", "Kesediaan Customer Dilakukan Pengerjaan Harus Dipilih Jika Hasil Pengecekan Dipilih.");
                    	showErrMsgFromLCR = Boolean.TRUE;
                    }
                } else {
                	if(kesediaanCheckShown) {
                		this.addInvalidMessage(vc, "kesediaanlcr", "Kesediaan Customer Harus Dipilih.");
                		showErrMsgFromLCR = Boolean.TRUE;
                	}
                }
            } else {
                if (kesediaanCheckShown) {
                    this.addInvalidMessage(vc, "kesediaanlcr", "Kesediaan Customer Harus Dipilih.");
                    showErrMsgFromLCR = Boolean.TRUE;
                }
            }
        }

        if(!StringUtil.hasValue(workOrder.getNoPolisi())
                || !StringUtil.hasValue(unitCustomer.getMachineNumber())
                || !StringUtil.hasValue(unitCustomer.getCustomerName())
                || !StringUtil.hasValue(workOrder.getUnitTypeID())
                || !StringUtil.hasValue(workOrder.getKmMotor())
                || !StringUtil.hasValue(unitCustomer.getPhone())
                || !StringUtil.hasValue(workOrder.getTipeKPB())
                || workOrder.getMechanicID() == null && isVisit == true
                || workOrder.getWoDisclaimerType() == null
                || !StringUtil.hasValue(unitCustomer.getPhone())
                || workOrder.getUnitEntrySource()==null
                || ((workOrder.getProsesServicePUD() == null || workOrder.getProsesServicePUD().equalsIgnoreCase("isi")) && isPUD == true)
                || noBukuC2null
                || showErrMsgFromLCR) {
            CommonViewModel.showErrorMessagebox("Data belum lengkap mohon periksa kembali");
        }
    }

}
Leave a Comment