001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016// Generated File -- DO NOT EDIT BY HAND
017// --------------------------------------------------------------------------------
018
019/**
020 * EntityEncryptionKeyValue.java
021 */
022
023package com.echothree.model.data.core.server.value;
024
025import com.echothree.model.data.core.common.pk.EntityEncryptionKeyPK;
026
027import com.echothree.model.data.core.server.factory.EntityEncryptionKeyFactory;
028
029import com.echothree.util.common.exception.PersistenceCloneException;
030import com.echothree.util.common.exception.PersistenceNotNullException;
031
032import com.echothree.util.server.persistence.BaseValue;
033
034import java.io.Serializable;
035
036public class EntityEncryptionKeyValue
037        extends BaseValue<EntityEncryptionKeyPK>
038        implements Cloneable, Serializable {
039    
040    private String entityEncryptionKeyName;
041    private boolean entityEncryptionKeyNameHasBeenModified = false;
042    private Boolean isExternal;
043    private boolean isExternalHasBeenModified = false;
044    private String secretKey;
045    private boolean secretKeyHasBeenModified = false;
046    private String initializationVector;
047    private boolean initializationVectorHasBeenModified = false;
048    
049    private transient Integer _hashCode = null;
050    private transient String _stringValue = null;
051    
052    private void constructFields(String entityEncryptionKeyName, Boolean isExternal, String secretKey, String initializationVector)
053            throws PersistenceNotNullException {
054        checkForNull(entityEncryptionKeyName);
055        this.entityEncryptionKeyName = entityEncryptionKeyName;
056        checkForNull(isExternal);
057        this.isExternal = isExternal;
058        checkForNull(secretKey);
059        this.secretKey = secretKey;
060        checkForNull(initializationVector);
061        this.initializationVector = initializationVector;
062    }
063    
064    /** Creates a new instance of EntityEncryptionKeyValue */
065    public EntityEncryptionKeyValue(EntityEncryptionKeyPK entityEncryptionKeyPK, String entityEncryptionKeyName, Boolean isExternal, String secretKey, String initializationVector)
066            throws PersistenceNotNullException {
067        super(entityEncryptionKeyPK);
068        constructFields(entityEncryptionKeyName, isExternal, secretKey, initializationVector);
069    }
070    
071    /** Creates a new instance of EntityEncryptionKeyValue */
072    public EntityEncryptionKeyValue(String entityEncryptionKeyName, Boolean isExternal, String secretKey, String initializationVector)
073            throws PersistenceNotNullException {
074        super();
075        constructFields(entityEncryptionKeyName, isExternal, secretKey, initializationVector);
076    }
077    
078   @Override
079   public EntityEncryptionKeyFactory getBaseFactoryInstance() {
080        return EntityEncryptionKeyFactory.getInstance();
081    }
082    
083    @Override
084    public EntityEncryptionKeyValue clone() {
085        Object result;
086        
087        try {
088            result = super.clone();
089        } catch (CloneNotSupportedException cnse) {
090            // This shouldn't happen, fail when it does.
091            throw new PersistenceCloneException(cnse);
092        }
093        
094        return (EntityEncryptionKeyValue)result;
095    }
096    
097   @Override
098    public EntityEncryptionKeyPK getPrimaryKey() {
099        if(_primaryKey == null) {
100            _primaryKey = new EntityEncryptionKeyPK(entityId);
101        }
102        
103        return _primaryKey;
104    }
105    
106    private void clearHashAndString() {
107        _hashCode = null;
108        _stringValue = null;
109    }
110    
111    @Override
112    public int hashCode() {
113        if(_hashCode == null) {
114            int hashCode = 17;
115            
116            hashCode = 37 * hashCode + ((entityId != null) ? entityId.hashCode() : 0);
117            
118            hashCode = 37 * hashCode + ((entityEncryptionKeyName != null) ? entityEncryptionKeyName.hashCode() : 0);
119            hashCode = 37 * hashCode + ((isExternal != null) ? isExternal.hashCode() : 0);
120            hashCode = 37 * hashCode + ((secretKey != null) ? secretKey.hashCode() : 0);
121            hashCode = 37 * hashCode + ((initializationVector != null) ? initializationVector.hashCode() : 0);
122            
123            _hashCode = hashCode;
124        }
125        
126        return _hashCode;
127    }
128    
129    @Override
130    public String toString() {
131        if(_stringValue == null) {
132            _stringValue = "{" + 
133                    "entityId=" + getEntityId() +
134                    ", entityEncryptionKeyName=" + getEntityEncryptionKeyName() +
135                    ", isExternal=" + getIsExternal() +
136                    ", secretKey=" + getSecretKey() +
137                    ", initializationVector=" + getInitializationVector() +
138                    "}";
139        }
140        return _stringValue;
141    }
142    
143    @Override
144    public boolean equals(Object other) {
145        if(this == other)
146            return true;
147        
148        if(!hasIdentity())
149            return false;
150        
151        if(other instanceof  EntityEncryptionKeyValue that) {
152            if(!that.hasIdentity())
153                return false;
154            
155            Long thisEntityId = getEntityId();
156            Long thatEntityId = that.getEntityId();
157            
158            boolean objectsEqual = thisEntityId.equals(thatEntityId);
159            if(objectsEqual)
160                objectsEqual = isIdentical(that);
161            
162            return objectsEqual;
163        } else {
164            return false;
165        }
166    }
167    
168    public boolean isIdentical(Object other) {
169        if(other instanceof EntityEncryptionKeyValue that) {
170            boolean objectsEqual = true;
171            
172            
173            if(objectsEqual) {
174                String thisEntityEncryptionKeyName = getEntityEncryptionKeyName();
175                String thatEntityEncryptionKeyName = that.getEntityEncryptionKeyName();
176                
177                if(thisEntityEncryptionKeyName == null) {
178                    objectsEqual = objectsEqual && (thatEntityEncryptionKeyName == null);
179                } else {
180                    objectsEqual = objectsEqual && thisEntityEncryptionKeyName.equals(thatEntityEncryptionKeyName);
181                }
182            }
183            
184            if(objectsEqual) {
185                Boolean thisIsExternal = getIsExternal();
186                Boolean thatIsExternal = that.getIsExternal();
187                
188                if(thisIsExternal == null) {
189                    objectsEqual = objectsEqual && (thatIsExternal == null);
190                } else {
191                    objectsEqual = objectsEqual && thisIsExternal.equals(thatIsExternal);
192                }
193            }
194            
195            if(objectsEqual) {
196                String thisSecretKey = getSecretKey();
197                String thatSecretKey = that.getSecretKey();
198                
199                if(thisSecretKey == null) {
200                    objectsEqual = objectsEqual && (thatSecretKey == null);
201                } else {
202                    objectsEqual = objectsEqual && thisSecretKey.equals(thatSecretKey);
203                }
204            }
205            
206            if(objectsEqual) {
207                String thisInitializationVector = getInitializationVector();
208                String thatInitializationVector = that.getInitializationVector();
209                
210                if(thisInitializationVector == null) {
211                    objectsEqual = objectsEqual && (thatInitializationVector == null);
212                } else {
213                    objectsEqual = objectsEqual && thisInitializationVector.equals(thatInitializationVector);
214                }
215            }
216            
217            return objectsEqual;
218        } else {
219            return false;
220        }
221    }
222    
223    @Override
224    public boolean hasBeenModified() {
225        return entityEncryptionKeyNameHasBeenModified || isExternalHasBeenModified || secretKeyHasBeenModified || initializationVectorHasBeenModified;
226    }
227    
228    @Override
229    public void clearHasBeenModified() {
230        entityEncryptionKeyNameHasBeenModified = false;
231        isExternalHasBeenModified = false;
232        secretKeyHasBeenModified = false;
233        initializationVectorHasBeenModified = false;
234    }
235    
236    public String getEntityEncryptionKeyName() {
237        return entityEncryptionKeyName;
238    }
239    
240    public void setEntityEncryptionKeyName(String entityEncryptionKeyName)
241            throws PersistenceNotNullException {
242        checkForNull(entityEncryptionKeyName);
243        
244        boolean update = true;
245        
246        if(this.entityEncryptionKeyName != null) {
247            if(this.entityEncryptionKeyName.equals(entityEncryptionKeyName)) {
248                update = false;
249            }
250        } else if(entityEncryptionKeyName == null) {
251            update = false;
252        }
253        
254        if(update) {
255            this.entityEncryptionKeyName = entityEncryptionKeyName;
256            entityEncryptionKeyNameHasBeenModified = true;
257            clearHashAndString();
258        }
259    }
260    
261    public boolean getEntityEncryptionKeyNameHasBeenModified() {
262        return entityEncryptionKeyNameHasBeenModified;
263    }
264    
265    public Boolean getIsExternal() {
266        return isExternal;
267    }
268    
269    public void setIsExternal(Boolean isExternal)
270            throws PersistenceNotNullException {
271        checkForNull(isExternal);
272        
273        boolean update = true;
274        
275        if(this.isExternal != null) {
276            if(this.isExternal.equals(isExternal)) {
277                update = false;
278            }
279        } else if(isExternal == null) {
280            update = false;
281        }
282        
283        if(update) {
284            this.isExternal = isExternal;
285            isExternalHasBeenModified = true;
286            clearHashAndString();
287        }
288    }
289    
290    public boolean getIsExternalHasBeenModified() {
291        return isExternalHasBeenModified;
292    }
293    
294    public String getSecretKey() {
295        return secretKey;
296    }
297    
298    public void setSecretKey(String secretKey)
299            throws PersistenceNotNullException {
300        checkForNull(secretKey);
301        
302        boolean update = true;
303        
304        if(this.secretKey != null) {
305            if(this.secretKey.equals(secretKey)) {
306                update = false;
307            }
308        } else if(secretKey == null) {
309            update = false;
310        }
311        
312        if(update) {
313            this.secretKey = secretKey;
314            secretKeyHasBeenModified = true;
315            clearHashAndString();
316        }
317    }
318    
319    public boolean getSecretKeyHasBeenModified() {
320        return secretKeyHasBeenModified;
321    }
322    
323    public String getInitializationVector() {
324        return initializationVector;
325    }
326    
327    public void setInitializationVector(String initializationVector)
328            throws PersistenceNotNullException {
329        checkForNull(initializationVector);
330        
331        boolean update = true;
332        
333        if(this.initializationVector != null) {
334            if(this.initializationVector.equals(initializationVector)) {
335                update = false;
336            }
337        } else if(initializationVector == null) {
338            update = false;
339        }
340        
341        if(update) {
342            this.initializationVector = initializationVector;
343            initializationVectorHasBeenModified = true;
344            clearHashAndString();
345        }
346    }
347    
348    public boolean getInitializationVectorHasBeenModified() {
349        return initializationVectorHasBeenModified;
350    }
351    
352}