2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.config.oxm;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.LinkedHashMap;
30 import java.util.List;
32 import java.util.Map.Entry;
34 import org.eclipse.persistence.dynamic.DynamicType;
35 import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
36 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
38 public class GeoEntityLookup implements OxmModelProcessor {
40 private Map<String, HashMap<String, String>> geoEntityOxmModel;
42 private Map<String, GeoOxmEntityDescriptor> geoEntityDescriptors;
44 public GeoEntityLookup() {
45 geoEntityOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
46 geoEntityDescriptors = new HashMap<String, GeoOxmEntityDescriptor>();
49 public Map<String, HashMap<String, String>> getGeoEntityOxmModel() {
50 return geoEntityOxmModel;
53 public void setGeoEntityOxmModel(Map<String, HashMap<String, String>> geoEntityOxmModel) {
54 this.geoEntityOxmModel = geoEntityOxmModel;
57 public Map<String, GeoOxmEntityDescriptor> getGeoEntityDescriptors() {
58 return geoEntityDescriptors;
61 public void setGeoEntityDescriptors(Map<String, GeoOxmEntityDescriptor> geoEntityDescriptors) {
62 this.geoEntityDescriptors = geoEntityDescriptors;
66 public void processOxmModel(DynamicJAXBContext jaxbContext) {
68 @SuppressWarnings("rawtypes")
69 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
71 for (@SuppressWarnings("rawtypes")
72 Descriptor desc : descriptorsList) {
74 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
76 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
78 // Not all fields have key attributes
79 if (desc.getPrimaryKeyFields() != null) {
80 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
81 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
84 String entityName = desc.getDefaultRootElement();
87 oxmProperties.put("entityName", entityName);
89 Map<String, String> properties = entity.getDescriptor().getProperties();
91 if (properties != null) {
92 for (Map.Entry<String, String> entry : properties.entrySet()) {
94 if (entry.getKey().equalsIgnoreCase("geoLat")) {
95 if (entry.getValue().length() > 0) {
96 oxmProperties.put("geoLat", entry.getValue());
98 } else if (entry.getKey().equalsIgnoreCase("geoLong")) {
99 if (entry.getValue().length() > 0) {
100 oxmProperties.put("geoLong", entry.getValue());
106 if (oxmProperties.containsKey("geoLat") && oxmProperties.containsKey("geoLong")) {
107 geoEntityOxmModel.put(entityName, oxmProperties);
112 for (Entry<String, HashMap<String, String>> entityModel : geoEntityOxmModel.entrySet()) {
114 HashMap<String, String> attribute = entityModel.getValue();
116 GeoOxmEntityDescriptor entity = new GeoOxmEntityDescriptor();
118 entity.setEntityName(attribute.get("entityName"));
120 if (attribute.containsKey("primaryKeyAttributeNames")) {
122 entity.setPrimaryKeyAttributeNames(
123 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
125 if (attribute.containsKey("geoLat") || attribute.containsKey("geoLong")) {
126 entity.setGeoLatName(attribute.get("geoLat"));
127 entity.setGeoLongName(attribute.get("geoLong"));
130 geoEntityDescriptors.put(attribute.get("entityName"), entity);