22package com .github .sfxd .trust .core .instances ;
33
44import java .util .List ;
5- import java .util .Objects ;
65
76import javax .persistence .CascadeType ;
87import javax .persistence .Column ;
9- import javax .persistence .EnumType ;
10- import javax .persistence .Enumerated ;
118import javax .persistence .OneToMany ;
129
13- import com .fasterxml .jackson .annotation .JsonProperty ;
1410import com .github .sfxd .trust .core .Entity ;
1511import com .github .sfxd .trust .core .users .Subscription ;
12+ import io .ebean .annotation .DbEnumType ;
13+ import io .ebean .annotation .DbEnumValue ;
1614import org .apache .commons .lang3 .builder .DiffBuilder ;
1715import org .apache .commons .lang3 .builder .DiffResult ;
1816import org .apache .commons .lang3 .builder .ToStringStyle ;
1917
20- /**
21- * Represents an SFDC instance. Sandbox or Production.
22- * This model maps directly to the model from the api.
23- */
18+ import static java .util .Objects .requireNonNull ;
19+
20+ /// Represents an SFDC instance. Sandbox or Production.
2421@ javax .persistence .Entity
2522public class Instance extends Entity {
26- public static final String STATUS_OK = "OK" ;
27-
28- @ Column (unique = true , nullable = false , length = 255 , name = "\" key\" " )
29- private String key ;
23+ @ Column (unique = true , nullable = false , name = "\" key\" " , columnDefinition = "character varying" )
24+ private final String key ;
3025
31- @ Column (length = 255 )
26+ @ Column (columnDefinition = "character varying" )
3227 private String location ;
3328
34- @ Column (length = 255 )
29+ @ Column (columnDefinition = "character varying" )
3530 private String releaseVersion ;
3631
37- @ Column (length = 255 )
32+ @ Column (columnDefinition = "character varying" )
3833 private String releaseNumber ;
3934
40- @ Column (length = 255 )
35+ @ Column (columnDefinition = "character varying" )
4136 private String status ;
4237
43- @ Enumerated ( EnumType . STRING )
44- private Environment environment ;
38+ @ Column ( nullable = false )
39+ private final Environment environment ;
4540
4641 @ OneToMany (mappedBy = "instance" , cascade = CascadeType .REMOVE )
4742 private List <Subscription > subscriptions ;
4843
49- public Instance () {
50-
44+ public Instance (String key , Environment environment ) {
45+ this .key = requireNonNull (key );
46+ this .environment = requireNonNull (environment );
5147 }
5248
5349 public String key () {
5450 return this .key ;
5551 }
5652
57- public Instance setKey (String key ) {
58- this .key = key ;
59- return this ;
60- }
61-
6253 public String location () {
6354 return this .location ;
6455 }
6556
66- public Instance setLocation (String location ) {
57+ public void setLocation (String location ) {
6758 this .location = location ;
68- return this ;
6959 }
7060
7161 public String releaseVersion () {
7262 return this .releaseVersion ;
7363 }
7464
75- public Instance setReleaseVersion (String releaseVersion ) {
65+ public void setReleaseVersion (String releaseVersion ) {
7666 this .releaseVersion = releaseVersion ;
77- return this ;
7867 }
7968
8069 public String releaseNumber () {
8170 return this .releaseNumber ;
8271 }
8372
84- public Instance setReleaseNumber (String releaseNumber ) {
73+ public void setReleaseNumber (String releaseNumber ) {
8574 this .releaseNumber = releaseNumber ;
86- return this ;
8775 }
8876
8977 public String status () {
9078 return this .status ;
9179 }
9280
93- public Instance setStatus (String status ) {
81+ public void setStatus (String status ) {
9482 this .status = status ;
95- return this ;
9683 }
9784
9885 public Environment environment () {
9986 return this .environment ;
10087 }
10188
102- public Instance setEnvironment (Environment environment ) {
103- this .environment = environment ;
104- return this ;
105- }
106-
10789 public List <Subscription > getSubscriptions () {
10890 return this .subscriptions ;
10991 }
11092
111- public Instance setSubscriptions (List <Subscription > subscriptions ) {
112- this .subscriptions = subscriptions ;
113- return this ;
114- }
115-
11693 public enum Environment {
117- @ JsonProperty ( "sandbox" )
118- SANDBOX ,
94+ SANDBOX ( 1 ),
95+ PRODUCTION ( 2 );
11996
120- @ JsonProperty ("production" )
121- PRODUCTION
97+ private final int id ;
98+ Environment (int id ) {
99+ this .id = id ;
100+ }
101+
102+ @ DbEnumValue (storage = DbEnumType .INTEGER )
103+ public int id () {
104+ return this .id ;
105+ }
122106 }
123107
124108 public DiffResult <Instance > diff (Instance other ) {
@@ -130,18 +114,4 @@ public DiffResult<Instance> diff(Instance other) {
130114 .append ("releaseVersion" , other .releaseVersion , this .releaseVersion )
131115 .build ();
132116 }
133-
134- @ Override
135- public boolean equals (Object other ) {
136- if (other instanceof Instance i ) {
137- return Objects .equals (this .key , i .key );
138- }
139-
140- return false ;
141- }
142-
143- @ Override
144- public int hashCode () {
145- return Objects .hash (this .key );
146- }
147117}
0 commit comments