com.fpt.mic.micweb.model.dto.form.CreateCompensationDto.java Source code

Java tutorial

Introduction

Here is the source code for com.fpt.mic.micweb.model.dto.form.CreateCompensationDto.java

Source

package com.fpt.mic.micweb.model.dto.form;

import com.fpt.mic.micweb.model.dao.ContractDao;
import com.fpt.mic.micweb.model.entity.ContractEntity;
import com.fpt.mic.micweb.utils.ConfigUtils;
import com.fpt.mic.micweb.utils.Constants;
import com.fpt.mic.micweb.utils.DateUtils;
import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.Days;
import org.joda.time.LocalDate;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.sql.Timestamp;

/**
 * Created by Kha on 03/07/2015.
 */
public class CreateCompensationDto {
    @NotEmpty(message = "M hp ng khng c  trng")
    @Pattern(regexp = "^HD([0-9A-Z]{4,8})$", message = "M hp ng khng hp l")
    // M hp ng khng tn ti: @see {@link isNotExisted}
    private String contractCode;
    @NotNull(message = "Ngy gi yu cu khng c  trng")
    private Timestamp createdDate;
    @NotEmpty(message = "Vui lng ch?n phng thc nhp")
    private String inputMethod;
    @NotEmpty(message = "H? tn li xe khng c  trng")
    @Pattern(regexp = "^([^0-9`~!@#$%^&*,.<>;':/|{}()=_+-]+)$", message = "H? tn li xe khng hp l")
    @Size(min = 3, max = 80, message = "H? tn li xe phi t {min} n {max} k t")
    private String driverName;
    @NotEmpty(message = "Giy php li xe khng c  trng")
    @Size(min = 10, max = 15, message = "Giy php li xe phi t {min} n {max} k t")
    private String licenseNumber;
    @NotEmpty(message = "Hng GPLX khng c  trng")
    @Size(min = 1, max = 15, message = "Hng GPLX phi t {min} n {max} k t")
    private String licenseType;
    @NotEmpty(message = "?a ch lin h khng c  trng")
    @Size(min = 3, max = 250, message = "?a ch lin h phi t {min} n {max} k t")
    private String driverAddress;
    @NotEmpty(message = "S in thoi khng c  trng")
    @Pattern(regexp = "[0-9]+", message = "S in thoi khng hp l")
    @Size(min = 8, max = 15, message = "S in thoi phi t {min} n {max} k t")
    private String driverPhone;
    @NotEmpty(message = "Bin s xe gy tai nn khng c  trng")
    @Size(min = 4, max = 15, message = "Bin s xe gy tai nn phi c t {min} n {max} k t")
    private String plate;
    @NotEmpty(message = "Tr?ng ti/s ch ngi khng c  trng")
    @Size(min = 1, max = 20, message = "Tr?ng ti/s ch ngi phi c t {min} n {max} k t")
    private String vehicleCapacity;
    @NotNull(message = "Ngy xy ra tai nn khng c  trng")
    private Timestamp accidentDate;
    @NotEmpty(message = "Ni xy ra tai nn khng c  trng")
    @Size(min = 3, max = 250, message = "Ni xy ra tai nn phi t {min} n {max} k t")
    private String accidentPlace;
    @NotEmpty(message = "C quan cng an gii quyt tai nn khng c  trng")
    @Size(min = 3, max = 250, message = "C quan cng an gii quyt tai nn phi t {min} n {max} k t")
    private String controlDepartment;
    @NotEmpty(message = "Din bin v nguyn nhn tai nn khng c  trng")
    @Size(min = 1, max = 2000, message = "Din bin v nguyn nhn tai nn phi t {min} n {max} k t")
    private String description;
    @NotEmpty(message = "Tnh hnh thit hi v? ng?i khng c  trng")
    @Size(min = 1, max = 2000, message = "Tnh hnh thit hi v? ng?i phi t {min} n {max} k t")
    private String humanDamage;
    @NotEmpty(message = "Tnh hnh thit hi v? ti sn khng c  trng")
    @Size(min = 1, max = 2000, message = "Tnh hnh thit hi v? ti sn phi t {min} n {max} k t")
    private String assetDamage;
    @NotEmpty(message = "Ng?i lm chng khng c  trng")
    @Pattern(regexp = "^([^0-9`~!@#$%^&*,.<>;':/|{}()=_+-]+)$", message = "Ng?i lm chng khng hp l")
    @Size(min = 3, max = 80, message = "Ng?i lm chng phi t {min} n {max} k t")
    private String observer;
    @NotEmpty(message = "?a ch ng?i lm chng khng c  trng")
    @Size(min = 3, max = 250, message = "?a ch ng?i lm chng phi t {min} n {max} k t")
    private String observerAddress;
    private String compensationNote;
    private String attachment;

    @AssertTrue(message = "M hp ng khng tn ti")
    private boolean isNotExisted() {
        ContractDao contractDao = new ContractDao();
        return contractCode != null && contractDao.read(contractCode) != null;
    }

    @AssertTrue(message = "Ngy gi yu cu khng c sau ngy hin ti")
    private boolean isValidCreatedDate() {
        if (createdDate != null) {
            return !createdDate.after(DateUtils.currentDateWithoutTime());
        }
        return false;
    }

    @AssertTrue(message = "Th?i im xy ra tai nn khng c sau ngy gi yu cu")
    private boolean isValidAccidentDate() {
        if (accidentDate != null) {
            return !accidentDate.after(createdDate);
        }
        return false;
    }

    @AssertTrue(message = "Yu cu bi th?ng phi c  di t 1 n 2000 k t")
    private boolean isCompensationNoteValid() {
        if (compensationNote == null || compensationNote.isEmpty()) {
            return true; // Vn chp nhn null hoc rng
        } else {
            // Nu c gi tr th phi c  di ng requirement
            return compensationNote.length() >= 1 && compensationNote.length() <= 2000;
        }
    }

    @AssertTrue(message = "??ng dn ti bin bn ca c quan CA phi c  di t 1 n 255 k t")
    private boolean isAttachmentValid() {
        if (attachment == null || attachment.isEmpty()) {
            return true; // Vn chp nhn null hoc rng
        } else {
            // Nu c gi tr th phi c  di ng requirement
            return attachment.length() >= 1 && attachment.length() <= 255;
        }
    }

    @AssertTrue(message = "Khng th gi yu cu bi th?ng cho hp ng  b hy qu th?i hn cp nht thng tin")
    private boolean isValidUpdateDueDate() {
        ContractDao contractDao = new ContractDao();
        ContractEntity contractEntity = contractDao.read(contractCode);
        if (contractEntity != null
                && contractEntity.getStatus().equalsIgnoreCase(Constants.ContractStatus.CANCELLED)) {
            LocalDate cancelDate = new LocalDate(contractEntity.getCancelDate());
            int durationFromCurrentToCancel = Days.daysBetween(cancelDate, new LocalDate()).getDays();
            ConfigUtils configUtils = new ConfigUtils();
            return durationFromCurrentToCancel <= configUtils.getUpdateContractDueDate();
        } else {
            return true;
        }
    }

    public CreateCompensationDto() {
    }

    public CreateCompensationDto(String contractCode, Timestamp createdDate, String inputMethod, String driverName,
            String licenseNumber, String licenseType, String driverAddress, String driverPhone, String plate,
            String vehicleCapacity, Timestamp accidentDate, String accidentPlace, String controlDepartment,
            String description, String humanDamage, String assetDamage, String observer, String observerAddress,
            String compensationNote, String attachment) {
        this.contractCode = contractCode;
        this.createdDate = createdDate;
        this.inputMethod = inputMethod;
        this.driverName = driverName;
        this.licenseNumber = licenseNumber;
        this.licenseType = licenseType;
        this.driverAddress = driverAddress;
        this.driverPhone = driverPhone;
        this.plate = plate;
        this.vehicleCapacity = vehicleCapacity;
        this.accidentDate = accidentDate;
        this.accidentPlace = accidentPlace;
        this.controlDepartment = controlDepartment;
        this.description = description;
        this.humanDamage = humanDamage;
        this.assetDamage = assetDamage;
        this.observer = observer;
        this.observerAddress = observerAddress;
        this.compensationNote = compensationNote;
        this.attachment = attachment;
    }

    public String getContractCode() {
        return contractCode;
    }

    public void setContractCode(String contractCode) {
        this.contractCode = contractCode;
    }

    public Timestamp getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Timestamp createdDate) {
        this.createdDate = createdDate;
    }

    public String getInputMethod() {
        return inputMethod;
    }

    public void setInputMethod(String inputMethod) {
        this.inputMethod = inputMethod;
    }

    public String getDriverName() {
        return driverName;
    }

    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    public String getLicenseNumber() {
        return licenseNumber;
    }

    public void setLicenseNumber(String licenseNumber) {
        this.licenseNumber = licenseNumber;
    }

    public String getLicenseType() {
        return licenseType;
    }

    public void setLicenseType(String licenseType) {
        this.licenseType = licenseType;
    }

    public String getDriverAddress() {
        return driverAddress;
    }

    public void setDriverAddress(String driverAddress) {
        this.driverAddress = driverAddress;
    }

    public String getDriverPhone() {
        return driverPhone;
    }

    public void setDriverPhone(String driverPhone) {
        this.driverPhone = driverPhone;
    }

    public String getPlate() {
        return plate;
    }

    public void setPlate(String plate) {
        this.plate = plate;
    }

    public String getVehicleCapacity() {
        return vehicleCapacity;
    }

    public void setVehicleCapacity(String vehicleCapacity) {
        this.vehicleCapacity = vehicleCapacity;
    }

    public Timestamp getAccidentDate() {
        return accidentDate;
    }

    public void setAccidentDate(Timestamp accidentDate) {
        this.accidentDate = accidentDate;
    }

    public String getAccidentPlace() {
        return accidentPlace;
    }

    public void setAccidentPlace(String accidentPlace) {
        this.accidentPlace = accidentPlace;
    }

    public String getControlDepartment() {
        return controlDepartment;
    }

    public void setControlDepartment(String controlDepartment) {
        this.controlDepartment = controlDepartment;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getHumanDamage() {
        return humanDamage;
    }

    public void setHumanDamage(String humanDamage) {
        this.humanDamage = humanDamage;
    }

    public String getAssetDamage() {
        return assetDamage;
    }

    public void setAssetDamage(String assetDamage) {
        this.assetDamage = assetDamage;
    }

    public String getObserver() {
        return observer;
    }

    public void setObserver(String observer) {
        this.observer = observer;
    }

    public String getObserverAddress() {
        return observerAddress;
    }

    public void setObserverAddress(String observerAddress) {
        this.observerAddress = observerAddress;
    }

    public String getCompensationNote() {
        return compensationNote;
    }

    public void setCompensationNote(String compensationNote) {
        this.compensationNote = compensationNote;
    }

    public String getAttachment() {
        return attachment;
    }

    public void setAttachment(String attachment) {
        this.attachment = attachment;
    }
}