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 OxmEntityLookup implements OxmModelProcessor {
40 private Map<String, HashMap<String, String>> oxmModel;
42 private Map<String, DynamicType> entityTypeLookup;
44 private Map<String, OxmEntityDescriptor> entityDescriptors;
47 public OxmEntityLookup() {
48 oxmModel = new LinkedHashMap<String, HashMap<String, String>>();
49 entityTypeLookup = new LinkedHashMap<String, DynamicType>();
50 entityDescriptors = new HashMap<String, OxmEntityDescriptor>();
54 public void processOxmModel(DynamicJAXBContext jaxbContext) {
56 @SuppressWarnings("rawtypes")
57 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
59 for (@SuppressWarnings("rawtypes")
60 Descriptor desc : descriptorsList) {
62 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
64 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
66 // Not all fields have key attributes
67 if (desc.getPrimaryKeyFields() != null) {
68 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
69 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
72 String entityName = desc.getDefaultRootElement();
74 entityTypeLookup.put(entityName, entity);
77 oxmProperties.put("entityName", entityName);
79 Map<String, String> properties = entity.getDescriptor().getProperties();
81 oxmModel.put(entityName, oxmProperties);
85 for (Entry<String, HashMap<String, String>> entityModel : oxmModel.entrySet()) {
86 HashMap<String, String> attribute = entityModel.getValue();
87 OxmEntityDescriptor entity = new OxmEntityDescriptor();
89 entity.setEntityName(attribute.get("entityName"));
91 if (attribute.containsKey("primaryKeyAttributeNames")) {
93 entity.setPrimaryKeyAttributeNames(
94 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
96 entityDescriptors.put(attribute.get("entityName"), entity);
102 public Map<String, HashMap<String, String>> getOxmModel() {
106 public void setOxmModel(Map<String, HashMap<String, String>> oxmModel) {
107 this.oxmModel = oxmModel;
110 public Map<String, DynamicType> getEntityTypeLookup() {
111 return entityTypeLookup;
114 public void setEntityTypeLookup(Map<String, DynamicType> entityTypeLookup) {
115 this.entityTypeLookup = entityTypeLookup;
118 public Map<String, OxmEntityDescriptor> getEntityDescriptors() {
119 return entityDescriptors;
122 public void setEntityDescriptors(Map<String, OxmEntityDescriptor> entityDescriptors) {
123 this.entityDescriptors = entityDescriptors;
126 public void addEntityDescriptor(String type, OxmEntityDescriptor descriptor) {
127 if ( this.entityDescriptors != null ) {
128 this.entityDescriptors.put(type, descriptor);