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
32
33
34 package fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common;
35
36 import com.fasterxml.jackson.annotation.JsonCreator;
37 import com.fasterxml.jackson.annotation.JsonFormat;
38 import com.fasterxml.jackson.annotation.JsonIgnore;
39 import com.fasterxml.jackson.annotation.JsonInclude;
40 import com.fasterxml.jackson.annotation.JsonProperty;
41
42 import java.util.Arrays;
43 import java.util.List;
44 import java.util.Objects;
45 import java.util.stream.Collectors;
46
47 import static fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.AttributeChangeStatusType.ERROR;
48 import static fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.AttributeChangeStatusType.SUCCESS;
49 import static fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.AttributeChangeStatusType.WARNING;
50
51 @JsonInclude( JsonInclude.Include.NON_NULL )
52 @JsonFormat( shape = JsonFormat.Shape.OBJECT )
53 public enum AttributeChangeStatus
54 {
55 CREATED( "created", null, SUCCESS ),
56 NOT_CREATED( "not_created", "This attribute was not created because of an invalid provided value.", ERROR ),
57 UPDATED( "updated", null, SUCCESS ),
58 REMOVED( "removed", null, SUCCESS ),
59 NOT_REMOVED( "not_removed", "This mandatory attribute cannot be removed.", ERROR ),
60 NOT_UPDATED( "not_updated", "This attribute already exists with the same value and certificate.", WARNING ),
61 NOT_FOUND( "not_found", "This attribute does not exist in the repository.", ERROR ),
62 INSUFFICIENT_CERTIFICATION_LEVEL( "insufficient_certification_level",
63 "This attribute cannot be updated because the existing certification level is higher than the level of the process provided in the request.",
64 ERROR ),
65 INSUFFICIENT_RIGHTS( "insufficient_rights",
66 "This attribute cannot be written because the associated process in the request does not match the contract definition.", ERROR ),
67 UNAUTHORIZED( "unauthorized", "This attribute is not writable in service contract definition", ERROR ),
68 UNKNOWN_GEOCODES_CODE( "unknown_geocodes_code", "The provided code was not found in the Geocodes repository.", ERROR ),
69 UNKNOWN_GEOCODES_LABEL( "unknown_geocodes_label", "The provided label was not found in the Geocodes repository.", ERROR ),
70 MULTIPLE_GEOCODES_RESULTS_FOR_LABEL( "multiple_geocodes_results_for_label",
71 "The provided label correspond to multiple results in Geocodes. Please specify by providing the code.", ERROR ),
72 OVERRIDDEN_GEOCODES_LABEL( "overridden_geocodes_label",
73 "The provided label was not corresponding to the provided code, and has been overridden with the correct Geocodes label.", SUCCESS ),
74 INVALID_VALUE( "invalid_value", "This attribute value doesn't match its validation pattern.", ERROR ),
75 FORMATTED_VALUE( "formatted_value", "This attribute value has been formatted before treatment.", WARNING ),
76 UNCERTIFIED( "uncertified", null, SUCCESS );
77
78 @JsonIgnore
79 private static final List<AttributeChangeStatus> SUCCESS_STATUSES = Arrays.stream( values( ) ).filter( s -> s.type == SUCCESS )
80 .collect( Collectors.toList( ) );
81
82 @JsonProperty( "code" )
83 private String code;
84
85 @JsonProperty( "message" )
86 private String message;
87
88 @JsonProperty( "type" )
89 private AttributeChangeStatusType type;
90
91 AttributeChangeStatus( final String status, final String message, final AttributeChangeStatusType type )
92 {
93 this.code = status;
94 this.message = message;
95 this.type = type;
96 }
97
98 @JsonCreator
99 public static AttributeChangeStatus forValues( @JsonProperty( "code" ) String code, @JsonProperty( "message" ) String message )
100 {
101 return Arrays.stream( AttributeChangeStatus.values( ) ).filter( attributeChangeStatus -> Objects.equals( code, attributeChangeStatus.getCode( ) )
102 && Objects.equals( message, attributeChangeStatus.getMessage( ) ) ).findFirst( ).orElse( null );
103 }
104
105 public String getCode( )
106 {
107 return code;
108 }
109
110 public void setCode( String code )
111 {
112 this.code = code;
113 }
114
115 public String getMessage( )
116 {
117 return message;
118 }
119
120 public void setMessage( String message )
121 {
122 this.message = message;
123 }
124
125 public AttributeChangeStatusType getType( )
126 {
127 return type;
128 }
129
130 public void setType( final AttributeChangeStatusType type )
131 {
132 this.type = type;
133 }
134
135 @JsonIgnore
136 public static List<AttributeChangeStatus> getSuccessStatuses( )
137 {
138 return SUCCESS_STATUSES;
139 }
140
141 }