Fix sync update flow
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / sync / entity / IndexableCrossEntityReference.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sparky.sync.entity;
22
23 import java.util.ArrayList;
24 import java.util.Arrays;
25
26 import org.onap.aai.sparky.util.NodeUtils;
27
28 import com.fasterxml.jackson.annotation.JsonIgnore;
29 import com.fasterxml.jackson.core.JsonProcessingException;
30 import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
31 import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
32 import com.fasterxml.jackson.annotation.JsonInclude;
33 import com.fasterxml.jackson.annotation.JsonInclude.Include;
34
35 /**
36  * The Class IndexableCrossEntityReference.
37  */
38 @JsonInclude(Include.NON_NULL)
39 public class IndexableCrossEntityReference extends IndexableEntity implements IndexDocument {
40
41   protected String crossReferenceEntityValues;
42   protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
43
44   /**
45    * Instantiates a new indexable cross entity reference.
46    */
47   public IndexableCrossEntityReference() {
48     super();
49   }
50
51   /**
52    * Adds the cross entity reference value.
53    *
54    * @param crossEntityReferenceValue the cross entity reference value
55    */
56   public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
57     if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
58       crossEntityReferenceCollection.add(crossEntityReferenceValue);
59     }
60   }
61
62   public String getCrossReferenceEntityValues() {
63     return crossReferenceEntityValues;
64   }
65
66   public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
67     this.crossReferenceEntityValues = crossReferenceEntityValues;
68   }
69
70   /*
71    * (non-Javadoc)
72    * 
73    * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
74    */
75   @Override
76   public void deriveFields() {
77     this.id = NodeUtils.generateUniqueShaDigest(link);
78     this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
79   }
80
81   @JsonIgnore // Since this is a "get" we need to JSON ignore otherwise it will be called when converting to JSON
82   @Override
83   public String getAsJson() throws JsonProcessingException {
84
85     return NodeUtils.convertObjectToJson(this, false);
86
87   }
88
89   @Override
90   public String toString() {
91     return "IndexableCrossEntityReference ["
92         + (crossReferenceEntityValues != null
93             ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
94         + (crossEntityReferenceCollection != null
95             ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "");
96   }
97 }