Kenmegne
7 days ago 494d349fb67be74da49caae2794fda702f595fb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.fdxgenerator.annotations;
 
import com.megatim.fdxgenerator.enums.TypeDonnee;
import com.megatim.fdxgenerator.model.StructureLigne;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
 
/**
 *
 * @author STEPHANIE
 */
public class FormatDateValidator implements  ConstraintValidator<FormatDateConstraint, StructureLigne> {
    @Override
    public void initialize(FormatDateConstraint cons) {
    }
    
    @Override
    public boolean isValid(StructureLigne structLigne, ConstraintValidatorContext cxt) {
         if(structLigne.getTypeDonnee().getValue().equals(TypeDonnee.DATE.getValue())){
             return structLigne.getFormatDate().matches(
                     "y{4}((M{2}){0,1})((d{2}){0,1})((H{2}){0,1})((m{2}){0,1})((s{2}){0,1})|"
            + "y{4}((d{2}){0,1})((M{2}){0,1})((H{2}){0,1})((m{2}){0,1})((s{2}){0,1})|"
            + "M{2}((y{4}){0,1})((d{2}){0,1})((H{2}){0,1})((m{2}){0,1})((s{2}){0,1})|"
            + "M{2}((d{2}){0,1})((y{4}){0,1})((H{2}){0,1})((m{2}){0,1})((s{2}){0,1})");
         } else return true;
    }
}