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 SearchableEntityLookup implements OxmModelProcessor {
36 private Map<String, HashMap<String, String>> searchableOxmModel;
37 private Map<String, SearchableOxmEntityDescriptor> searchableEntityDescriptors;
39 public SearchableEntityLookup() {
40 searchableOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
41 searchableEntityDescriptors = new HashMap<String, SearchableOxmEntityDescriptor>();
45 public void processOxmModel(DynamicJAXBContext jaxbContext) {
47 @SuppressWarnings("rawtypes")
48 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
50 for (@SuppressWarnings("rawtypes")
51 Descriptor desc : descriptorsList) {
53 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
55 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
57 // Not all fields have key attributes
58 if (desc.getPrimaryKeyFields() != null) {
59 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
60 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
63 String entityName = desc.getDefaultRootElement();
66 oxmProperties.put("entityName", entityName);
68 Map<String, String> properties = entity.getDescriptor().getProperties();
69 if (properties != null) {
70 for (Map.Entry<String, String> entry : properties.entrySet()) {
72 if (entry.getKey().equalsIgnoreCase("searchable")) {
73 oxmProperties.put("searchableAttributes", entry.getValue());
78 // Add all searchable entity types for reserve lookup
79 if (oxmProperties.containsKey("searchableAttributes")) {
80 searchableOxmModel.put(entityName, oxmProperties);
85 for (Entry<String, HashMap<String, String>> searchableModel : searchableOxmModel.entrySet()) {
86 HashMap<String, String> attribute = searchableModel.getValue();
87 SearchableOxmEntityDescriptor entity = new SearchableOxmEntityDescriptor();
88 entity.setEntityName(attribute.get("entityName"));
89 entity.setPrimaryKeyAttributeNames(
90 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
92 .setSearchableAttributes(Arrays.asList(attribute.get("searchableAttributes").split(",")));
93 searchableEntityDescriptors.put(attribute.get("entityName"), entity);
98 public Map<String, HashMap<String, String>> getSearchableOxmModel() {
99 return searchableOxmModel;
102 public void setSearchableOxmModel(Map<String, HashMap<String, String>> searchableOxmModel) {
103 this.searchableOxmModel = searchableOxmModel;
106 public Map<String, SearchableOxmEntityDescriptor> getSearchableEntityDescriptors() {
107 return searchableEntityDescriptors;
110 public void setSearchableEntityDescriptors(
111 Map<String, SearchableOxmEntityDescriptor> searchableEntityDescriptors) {
112 this.searchableEntityDescriptors = searchableEntityDescriptors;