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.onap.aai.sparky.config.oxm;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 import java.util.Map.Entry;
32 import org.eclipse.persistence.dynamic.DynamicType;
33 import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
34 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
36 public class GeoEntityLookup implements OxmModelProcessor {
38 private Map<String, HashMap<String, String>> geoEntityOxmModel;
40 private Map<String, GeoOxmEntityDescriptor> geoEntityDescriptors;
42 public GeoEntityLookup() {
43 geoEntityOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
44 geoEntityDescriptors = new HashMap<String, GeoOxmEntityDescriptor>();
47 public Map<String, HashMap<String, String>> getGeoEntityOxmModel() {
48 return geoEntityOxmModel;
51 public void setGeoEntityOxmModel(Map<String, HashMap<String, String>> geoEntityOxmModel) {
52 this.geoEntityOxmModel = geoEntityOxmModel;
55 public Map<String, GeoOxmEntityDescriptor> getGeoEntityDescriptors() {
56 return geoEntityDescriptors;
59 public void setGeoEntityDescriptors(Map<String, GeoOxmEntityDescriptor> geoEntityDescriptors) {
60 this.geoEntityDescriptors = geoEntityDescriptors;
64 public void processOxmModel(DynamicJAXBContext jaxbContext) {
66 @SuppressWarnings("rawtypes")
67 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
69 for (@SuppressWarnings("rawtypes")
70 Descriptor desc : descriptorsList) {
72 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
74 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
76 // Not all fields have key attributes
77 if (desc.getPrimaryKeyFields() != null) {
78 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
79 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
82 String entityName = desc.getDefaultRootElement();
85 oxmProperties.put("entityName", entityName);
87 Map<String, String> properties = entity.getDescriptor().getProperties();
89 if (properties != null) {
90 for (Map.Entry<String, String> entry : properties.entrySet()) {
92 if (entry.getKey().equalsIgnoreCase("geoLat")) {
93 if (entry.getValue().length() > 0) {
94 oxmProperties.put("geoLat", entry.getValue());
96 } else if (entry.getKey().equalsIgnoreCase("geoLong")) {
97 if (entry.getValue().length() > 0) {
98 oxmProperties.put("geoLong", entry.getValue());
104 if (oxmProperties.containsKey("geoLat") && oxmProperties.containsKey("geoLong")) {
105 geoEntityOxmModel.put(entityName, oxmProperties);
110 for (Entry<String, HashMap<String, String>> entityModel : geoEntityOxmModel.entrySet()) {
112 HashMap<String, String> attribute = entityModel.getValue();
114 GeoOxmEntityDescriptor entity = new GeoOxmEntityDescriptor();
116 entity.setEntityName(attribute.get("entityName"));
118 if (attribute.containsKey("primaryKeyAttributeNames")) {
120 entity.setPrimaryKeyAttributeNames(
121 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
123 if (attribute.containsKey("geoLat") || attribute.containsKey("geoLong")) {
124 entity.setGeoLatName(attribute.get("geoLat"));
125 entity.setGeoLongName(attribute.get("geoLong"));
128 geoEntityDescriptors.put(attribute.get("entityName"), entity);