2 * ============LICENSE_START=======================================================
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
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 package org.onap.aai.sparky.config.oxm;
23 import java.util.Arrays;
24 import java.util.HashMap;
25 import java.util.LinkedHashMap;
26 import java.util.List;
28 import java.util.Map.Entry;
30 import org.eclipse.persistence.dynamic.DynamicType;
31 import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
32 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
34 public class OxmEntityLookup implements OxmModelProcessor {
36 private Map<String, HashMap<String, String>> oxmModel;
38 private Map<String, DynamicType> entityTypeLookup;
40 private Map<String, OxmEntityDescriptor> entityDescriptors;
43 public OxmEntityLookup() {
44 oxmModel = new LinkedHashMap<String, HashMap<String, String>>();
45 entityTypeLookup = new LinkedHashMap<String, DynamicType>();
46 entityDescriptors = new HashMap<String, OxmEntityDescriptor>();
50 public void processOxmModel(DynamicJAXBContext jaxbContext) {
52 @SuppressWarnings("rawtypes")
53 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
55 for (@SuppressWarnings("rawtypes")
56 Descriptor desc : descriptorsList) {
58 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
60 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
62 // Not all fields have key attributes
63 if (desc.getPrimaryKeyFields() != null) {
64 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
65 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
68 String entityName = desc.getDefaultRootElement();
70 entityTypeLookup.put(entityName, entity);
73 oxmProperties.put("entityName", entityName);
75 Map<String, String> properties = entity.getDescriptor().getProperties();
77 oxmModel.put(entityName, oxmProperties);
81 for (Entry<String, HashMap<String, String>> entityModel : oxmModel.entrySet()) {
82 HashMap<String, String> attribute = entityModel.getValue();
83 OxmEntityDescriptor entity = new OxmEntityDescriptor();
85 entity.setEntityName(attribute.get("entityName"));
87 if (attribute.containsKey("primaryKeyAttributeNames")) {
89 entity.setPrimaryKeyAttributeNames(
90 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
92 entityDescriptors.put(attribute.get("entityName"), entity);
98 public Map<String, HashMap<String, String>> getOxmModel() {
102 public void setOxmModel(Map<String, HashMap<String, String>> oxmModel) {
103 this.oxmModel = oxmModel;
106 public Map<String, DynamicType> getEntityTypeLookup() {
107 return entityTypeLookup;
110 public void setEntityTypeLookup(Map<String, DynamicType> entityTypeLookup) {
111 this.entityTypeLookup = entityTypeLookup;
114 public Map<String, OxmEntityDescriptor> getEntityDescriptors() {
115 return entityDescriptors;
118 public void setEntityDescriptors(Map<String, OxmEntityDescriptor> entityDescriptors) {
119 this.entityDescriptors = entityDescriptors;
122 public void addEntityDescriptor(String type, OxmEntityDescriptor descriptor) {
123 if ( this.entityDescriptors != null ) {
124 this.entityDescriptors.put(type, descriptor);