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 SearchableEntityLookup implements OxmModelProcessor {
40 private Map<String, HashMap<String, String>> searchableOxmModel;
41 private Map<String, SearchableOxmEntityDescriptor> searchableEntityDescriptors;
43 public SearchableEntityLookup() {
44 searchableOxmModel = new LinkedHashMap<String, HashMap<String, String>>();
45 searchableEntityDescriptors = new HashMap<String, SearchableOxmEntityDescriptor>();
49 public void processOxmModel(DynamicJAXBContext jaxbContext) {
51 @SuppressWarnings("rawtypes")
52 List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
54 for (@SuppressWarnings("rawtypes")
55 Descriptor desc : descriptorsList) {
57 DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
59 LinkedHashMap<String, String> oxmProperties = new LinkedHashMap<String, String>();
61 // Not all fields have key attributes
62 if (desc.getPrimaryKeyFields() != null) {
63 oxmProperties.put("primaryKeyAttributeNames", desc.getPrimaryKeyFields().toString()
64 .replaceAll("/text\\(\\)", "").replaceAll("\\[", "").replaceAll("\\]", ""));
67 String entityName = desc.getDefaultRootElement();
70 oxmProperties.put("entityName", entityName);
72 Map<String, String> properties = entity.getDescriptor().getProperties();
73 if (properties != null) {
74 for (Map.Entry<String, String> entry : properties.entrySet()) {
76 if (entry.getKey().equalsIgnoreCase("searchable")) {
77 oxmProperties.put("searchableAttributes", entry.getValue());
82 // Add all searchable entity types for reserve lookup
83 if (oxmProperties.containsKey("searchableAttributes")) {
84 searchableOxmModel.put(entityName, oxmProperties);
89 for (Entry<String, HashMap<String, String>> searchableModel : searchableOxmModel.entrySet()) {
90 HashMap<String, String> attribute = searchableModel.getValue();
91 SearchableOxmEntityDescriptor entity = new SearchableOxmEntityDescriptor();
92 entity.setEntityName(attribute.get("entityName"));
93 entity.setPrimaryKeyAttributeNames(
94 Arrays.asList(attribute.get("primaryKeyAttributeNames").replace(" ", "").split(",")));
96 .setSearchableAttributes(Arrays.asList(attribute.get("searchableAttributes").split(",")));
97 searchableEntityDescriptors.put(attribute.get("entityName"), entity);
102 public Map<String, HashMap<String, String>> getSearchableOxmModel() {
103 return searchableOxmModel;
106 public void setSearchableOxmModel(Map<String, HashMap<String, String>> searchableOxmModel) {
107 this.searchableOxmModel = searchableOxmModel;
110 public Map<String, SearchableOxmEntityDescriptor> getSearchableEntityDescriptors() {
111 return searchableEntityDescriptors;
114 public void setSearchableEntityDescriptors(
115 Map<String, SearchableOxmEntityDescriptor> searchableEntityDescriptors) {
116 this.searchableEntityDescriptors = searchableEntityDescriptors;