2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sparky.synchronizer.entity;
25 import java.util.ArrayList;
27 import org.openecomp.sparky.config.oxm.OxmModelLoader;
28 import org.openecomp.sparky.util.NodeUtils;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.node.ObjectNode;
35 * The Class IndexableCrossEntityReference.
38 public class IndexableCrossEntityReference extends IndexableEntity implements IndexDocument {
40 protected String crossReferenceEntityValues;
41 protected ArrayList<String> crossEntityReferenceCollection = new ArrayList<String>();
42 protected ObjectMapper mapper = new ObjectMapper();
45 * Instantiates a new indexable cross entity reference.
47 public IndexableCrossEntityReference() {
52 * Instantiates a new indexable cross entity reference.
54 * @param loader the loader
56 public IndexableCrossEntityReference(OxmModelLoader loader) {
61 * Adds the cross entity reference value.
63 * @param crossEntityReferenceValue the cross entity reference value
65 public void addCrossEntityReferenceValue(String crossEntityReferenceValue) {
66 if (!crossEntityReferenceCollection.contains(crossEntityReferenceValue)) {
67 crossEntityReferenceCollection.add(crossEntityReferenceValue);
72 * @see org.openecomp.sparky.synchronizer.entity.IndexDocument#deriveFields()
75 public void deriveFields() {
76 this.id = NodeUtils.generateUniqueShaDigest(link);
77 this.crossReferenceEntityValues = NodeUtils.concatArray(crossEntityReferenceCollection, ";");
81 public String getIndexDocumentJson() {
82 ObjectNode rootNode = mapper.createObjectNode();
83 rootNode.put("entityType", this.getEntityType());
84 rootNode.put("entityPrimaryKeyValue", this.getEntityPrimaryKeyValue());
85 rootNode.put("crossEntityReferenceValues", crossReferenceEntityValues);
86 rootNode.put("link", link);
87 rootNode.put("lastmodTimestamp", this.getEntityTimeStamp());
88 return rootNode.toString();
92 public ObjectNode getBulkImportEntity() {
93 // TODO Auto-generated method stub
98 * @see java.lang.Object#toString()
101 public String toString() {
102 return "IndexableCrossEntityReference ["
103 + (crossReferenceEntityValues != null
104 ? "crossReferenceEntityValues=" + crossReferenceEntityValues + ", " : "")
105 + (crossEntityReferenceCollection != null
106 ? "crossEntityReferenceCollection=" + crossEntityReferenceCollection + ", " : "")
107 + (mapper != null ? "mapper=" + mapper + ", " : "") + (id != null ? "id=" + id + ", " : "")
108 + (entityType != null ? "entityType=" + entityType + ", " : "")
109 + (entityPrimaryKeyValue != null ? "entityPrimaryKeyValue=" + entityPrimaryKeyValue + ", "
111 + (lastmodTimestamp != null ? "lastmodTimestamp=" + lastmodTimestamp + ", " : "")
112 + (link != null ? "link=" + link + ", " : "") + (loader != null ? "loader=" + loader : "")