Update license and poms
[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
25 import org.onap.aai.sparky.util.NodeUtils;
26
27 import com.fasterxml.jackson.annotation.JsonIgnore;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29
30
31 /**
32  * The Class IndexableCrossEntityReference.
33  */
34
35 public class IndexableCrossEntityReference extends IndexableEntity implements IndexDocument {
36
37   protected String crossReferenceEntityValues;
38   protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
39
40   /**
41    * Instantiates a new indexable cross entity reference.
42    */
43   public IndexableCrossEntityReference() {
44     super();
45   }
46
47   /**
48    * Adds the cross entity reference value.
49    *
50    * @param crossEntityReferenceValue the cross entity reference value
51    */
52   public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
53     if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
54       crossEntityReferenceCollection.add(crossEntityReferenceValue);
55     }
56   }
57
58   public String getCrossReferenceEntityValues() {
59     return crossReferenceEntityValues;
60   }
61
62   public void setCrossReferenceEntityValues(String crossReferenceEntityValues) {
63     this.crossReferenceEntityValues = crossReferenceEntityValues;
64   }
65
66   /*
67    * (non-Javadoc)
68    * 
69    * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
70    */
71   @Override
72   public void deriveFields() {
73     this.id = NodeUtils.generateUniqueShaDigest(link);
74     this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
75   }
76
77   @JsonIgnore // Since this is a "get" we need to JSON ignore otherwise it will be called when converting to JSON
78   @Override
79   public String getAsJson() throws JsonProcessingException {
80
81     return NodeUtils.convertObjectToJson(this, false);
82
83   }
84
85   @Override
86   public String toString() {
87     return "IndexableCrossEntityReference ["
88         + (crossReferenceEntityValues != null
89             ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
90         + (crossEntityReferenceCollection != null
91             ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "");
92   }
93 }