2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.aai.ingestModel;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.Date;
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.LinkedHashMap;
34 import java.util.List;
36 import java.util.Timer;
37 import java.util.TimerTask;
38 import java.util.Vector;
40 import org.eclipse.persistence.descriptors.ClassDescriptor;
41 import org.eclipse.persistence.dynamic.DynamicType;
42 import org.eclipse.persistence.internal.dynamic.DynamicTypeImpl;
43 import org.eclipse.persistence.internal.helper.DatabaseField;
44 import org.eclipse.persistence.jaxb.JAXBContextProperties;
45 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
46 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
47 import org.eclipse.persistence.mappings.DatabaseMapping;
48 import org.eclipse.persistence.oxm.XMLField;
49 import org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping;
50 import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
52 import org.openecomp.aai.domain.model.AAIResource;
53 import org.openecomp.aai.domain.model.AAIResourceKey;
54 import org.openecomp.aai.domain.model.AAIResourceKeys;
55 import org.openecomp.aai.domain.model.AAIResources;
56 import org.openecomp.aai.exceptions.AAIException;
57 import org.openecomp.aai.logging.ErrorLogHelper;
58 import org.openecomp.aai.util.AAIConfig;
59 import org.openecomp.aai.util.AAIConstants;
60 import org.openecomp.aai.util.FileWatcher;
61 import com.att.eelf.configuration.EELFLogger;
62 import com.att.eelf.configuration.EELFManager;
63 import com.google.common.base.CaseFormat;
64 import com.google.common.base.Splitter;
65 import com.google.common.collect.Multimap;
68 * The Class IngestModelMoxyOxm.
70 public class IngestModelMoxyOxm
73 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(IngestModelMoxyOxm.class);
75 public static HashMap<String, AAIResources> aaiResourceContainer;
76 public static HashMap<String, DbMaps> dbMapsContainer;
78 private static HashMap<String, Timer> timers = new HashMap<String,Timer>();
83 * @param args the arguments
84 * @throws Exception the exception
86 public static void main(String[] args) throws Exception {
88 String _apiVersion = AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP);
90 if (args.length > 0) {
91 if (args[0] != null) {
92 _apiVersion = args[0];
95 ArrayList<String> apiVersions = new ArrayList<String>();
96 apiVersions.add(_apiVersion);
97 final IngestModelMoxyOxm m = new IngestModelMoxyOxm();
98 m.init(apiVersions, false);
100 ArrayList<String> endpoints = new ArrayList<String>();
102 for (Map.Entry<String, AAIResources> ent: aaiResourceContainer.entrySet()) {
104 AAIResources aaiResources = ent.getValue();
105 DynamicJAXBContext jaxbContext = aaiResources.getJaxbContext();
106 for (Map.Entry<String, AAIResource> aaiResEnt : aaiResources.getAaiResources().entrySet()) {
107 AAIResource aaiRes = aaiResEnt.getValue();
109 String uri = aaiRes.getUri();
112 DynamicType dt = jaxbContext.getDynamicType(aaiRes.getResourceClassName());
113 if (dt.containsProperty("relationshipList")) {
114 endpoints.add(uri + "/relationship-list/relationship");
118 Collections.sort(endpoints);
119 for (String endpoint : endpoints) {
120 if (!endpoint.contains("/aai-internal/")) {
121 System.out.println(endpoint);
132 * @param apiVersions the api versions
133 * @throws Exception the exception
135 public synchronized void init(ArrayList<String> apiVersions) throws AAIException {
136 final IngestModelMoxyOxm m = new IngestModelMoxyOxm();
137 m.init(apiVersions, true);
143 * @param apiVersions the api versions
144 * @param setTimer the set timer
145 * @throws AAIException If AAIConfig is missing necessary properties
146 * @throws Exception the exception
148 public synchronized void init(ArrayList<String> apiVersions, Boolean setTimer) throws AAIException {
150 aaiResourceContainer = new HashMap<String, AAIResources>();
151 dbMapsContainer = new HashMap<String, DbMaps>();
153 final IngestModelMoxyOxm m = new IngestModelMoxyOxm();
155 for (String apiVersion : apiVersions) {
157 String relationshipUtils = "org.openecomp.aai.dbmap.RelationshipUtils";
158 final String thisRelationshipUtils = relationshipUtils;
160 final String thisApiVersion = apiVersion;
161 final String schemaFile = AAIConstants.AAI_HOME_ETC_OXM + "aai_oxm_" + apiVersion + ".xml";
163 m.loadSchema(apiVersion, schemaFile, relationshipUtils);
165 if (!setTimer) continue;
167 TimerTask task = null;
168 task = new FileWatcher ( new File(schemaFile)) {
169 protected void onChange( File file ) {
170 m.loadSchema(thisApiVersion, schemaFile, thisRelationshipUtils);
174 if (!timers.containsKey(apiVersion)) {
175 Timer timer = new Timer();
176 timer.schedule( task , new Date(), 10000 );
177 timers.put(apiVersion, timer);
181 if (apiVersions.contains(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP))) {
182 m.createPropertyAndNodeVersionInfoMapFromDbMaps();
184 for (Map.Entry<String, AAIResources> ent: aaiResourceContainer.entrySet()) {
185 String apiVersion = ent.getKey();
186 AAIResources aaiResources = ent.getValue();
188 DbMaps dbMap = dbMapsContainer.get(apiVersion);
190 for (Map.Entry<String, AAIResource> aaiResEnt : aaiResources.getAaiResources().entrySet()) {
191 AAIResource aaiRes = aaiResEnt.getValue();
192 aaiRes.setPropertyDataTypeMap(dbMap.PropertyDataTypeMap);
193 aaiRes.setNodeKeyProps(dbMap.NodeKeyProps);
194 aaiRes.setNodeNameProps(dbMap.NodeNameProps);
195 aaiRes.setNodeMapIndexedProps(dbMap.NodeMapIndexedProps);
204 * @param apiVersion the api version
205 * @param schemaFile the schema file
206 * @param relationshipUtils the relationship utils
207 * @return the dynamic JAXB context
209 private DynamicJAXBContext loadSchema(String apiVersion,
211 String relationshipUtils) {
213 AAIResources aaiResources = new AAIResources();
214 DbMaps dbMaps = new DbMaps();
215 DynamicJAXBContext jaxbContext = null;
219 InputStream iStream = new FileInputStream(new File(schemaFile));
221 Map<String, Object> properties = new HashMap<String, Object>();
222 properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream);
225 DynamicJAXBContextFactory.createContextFromOXM(IngestModelMoxyOxm.class.getClassLoader(), properties);
227 aaiResources.setJaxbContext(jaxbContext);
228 String rootClassName = "inventory.aai.openecomp.org." + apiVersion + ".Inventory";
230 if ("v2".equals(apiVersion)) {
231 rootClassName = "inventory.aai.openecomp.org.Inventory";
234 DynamicTypeImpl t = (DynamicTypeImpl)jaxbContext.getDynamicType(rootClassName);
236 lookAtDynamicResource("Inventory",
237 "inventory.aai.openecomp.org." + apiVersion,
240 1, "", "", apiVersion, "/" + apiVersion, false, aaiResources, dbMaps, relationshipUtils);
242 } catch (Exception e) {
243 ErrorLogHelper.logException(new AAIException("AAI_3000", e));
246 LOGGER.info("---> Loading " + apiVersion + " in aaiResourceContainer");
247 aaiResourceContainer.put(apiVersion, aaiResources);
249 createDbMapsfromAAIResources(aaiResources, dbMaps);
251 LOGGER.info("---> Loading " + apiVersion + " in dbMapsContainer");
252 dbMapsContainer.put(apiVersion, dbMaps);
260 public void cleanup() {
261 aaiResourceContainer.clear();
262 dbMapsContainer.clear();
266 * Look at dynamic resource.
268 * @param resource the resource
269 * @param pojoBase the pojo base
270 * @param jaxbContext the jaxb context
272 * @param depth the depth
273 * @param parent the parent
274 * @param namespace the namespace
275 * @param apiVersion the api version
277 * @param container the container
278 * @param aaiResources the aai resources
279 * @param dbMaps the db maps
280 * @param relationshipUtils the relationship utils
281 * @throws ClassNotFoundException the class not found exception
282 * @throws NoSuchFieldException the no such field exception
283 * @throws SecurityException the security exception
284 * @throws IOException Signals that an I/O exception has occurred.
286 private void lookAtDynamicResource(String resource,
288 DynamicJAXBContext jaxbContext,
296 AAIResources aaiResources,
298 String relationshipUtils
300 throws ClassNotFoundException, NoSuchFieldException, SecurityException, IOException {
302 String className = pojoBase + "." + CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL, resource);
304 AAIResource parentResource = aaiResources.getAaiResources().get(parent);
306 AAIResources siblings = null;
308 if (parentResource == null) {
309 String fullName = "/" + resource;
310 AAIResource aaiRes = new AAIResource();
311 aaiRes.setFullName(fullName);
312 aaiRes.setSimpleName(resource);
313 aaiRes.setResourceType("container");
314 aaiRes.setResourceClassName(className);
315 aaiRes.setApiVersion(apiVersion);
317 aaiResources.getAaiResources().put(fullName, aaiRes);
318 parentResource = aaiRes;
321 if (depth >= 50) return;
323 siblings = parentResource.getChildren();
326 namespace = resource;
332 /* if ("Actions".equals(namespace) || "Search".equals(namespace)) {
336 ClassDescriptor cd = t.getDescriptor();
338 createDbMapsfromOXM(cd.getProperties(), resource, dbMaps);
342 Vector<DatabaseMapping> dm = cd.getMappings();
344 for (DatabaseMapping dmInst : dm) {
345 String dmName = dmInst.getAttributeName();
347 ClassDescriptor cd2 = dmInst.getReferenceDescriptor();
350 String newClassName = cd2.getJavaClassName();
352 if (newClassName.contains("RelationshipList")) {
356 DynamicTypeImpl newDt = (DynamicTypeImpl)jaxbContext.getDynamicType(newClassName);
358 if (dmInst instanceof XMLCompositeCollectionMapping) {
359 String simpleName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, dmName);
360 // System.out.println(spaces + "+ List of A&AI Object named " + simpleName);
362 String hypName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, simpleName);
364 String fullName = parent + "/" + simpleName;
366 //Class<?> newClazz = Class.forName(newClassName);
367 AAIResource aaiRes = new AAIResource();
369 if ("cvlan-tag-entry".equals(hypName)) {
372 ClassDescriptor cd3 = newDt.getDescriptor();
374 boolean allowDirectWrite = true;
375 if (cd3.getProperties().containsKey("allowDirectWrite")) {
376 if (cd3.getProperties().get("allowDirectWrite").equals("false")) {
377 allowDirectWrite = false;
382 boolean allowDirectRead = true;
383 if (cd3.getProperties().containsKey("allowDirectRead")) {
384 if (cd3.getProperties().get("allowDirectRead").equals("false")) {
385 allowDirectRead = false;
389 List<DatabaseField> dbfList = cd3.getPrimaryKeyFields();
390 ArrayList<String> keyFields = new ArrayList<String>();
392 if (dbfList != null) {
393 for (DatabaseField dbf : dbfList) {
394 String name = dbf.getName();
395 name = name.substring(0, name.indexOf('/'));
399 Vector<DatabaseMapping> dm2 = cd3.getMappings();
400 for (DatabaseMapping dmInst2 : dm2) {
401 String dmName2= CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmInst2.getAttributeName());
402 DatabaseField xf2 = dmInst2.getField();
403 if (dmInst2.getProperties().containsKey("autoGenerateUuid")) {
404 if (dmInst2.getProperties().get("autoGenerateUuid").equals("true")) {
405 aaiRes.getAutoGenUuidFields().add(dmName2);
408 if (xf2 instanceof XMLField) {
409 XMLField x = (XMLField)xf2;
411 if (x.isRequired()) {
412 aaiRes.getRequiredFields().add(dmName2);
418 Class<?> xf2Clazz = xf2.getType();
419 if (xf2Clazz.getSimpleName().equals("String")) {
420 if (dmInst2 instanceof XMLCompositeDirectCollectionMapping) {
421 aaiRes.getStringListFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
423 aaiRes.getStringFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
425 } else if (xf2Clazz.getSimpleName().toLowerCase().contains("long")) {
426 aaiRes.getLongFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
427 } else if (xf2Clazz.getSimpleName().toLowerCase().contains("int")) {
428 aaiRes.getIntFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
429 } else if (xf2Clazz.getSimpleName().toLowerCase().contains("short")) {
430 aaiRes.getShortFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
431 } else if (xf2Clazz.getSimpleName().toLowerCase().contains("boolean")) {
432 aaiRes.getBooleanFields().add(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmName2));
434 } catch (Exception e) { // this xf2.getType() throws null pointer when I try to get the type and it doesn't have one
439 // get the key(s) from DbRules
441 LinkedHashMap<String, ArrayList<String>> itemKeyList = new LinkedHashMap<String, ArrayList<String>>();
443 aaiRes.setApiVersion(apiVersion);
444 itemKeyList.put(hypName, new ArrayList<String>());
445 for (String thisKey : keyFields) {
446 String pathParamName = hypName + "-" + thisKey;
448 AAIResourceKey aaiResKey = new AAIResourceKey();
449 aaiResKey.setKeyName(thisKey);
450 aaiResKey.setDnCamKeyName(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, pathParamName));
451 aaiResKey.setPathParamName(pathParamName);
453 for (DatabaseMapping dmInst2 : dm2) {
454 String dmName2= CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,dmInst2.getAttributeName());
455 if (dmName2.equals(thisKey)){
456 DatabaseField xf2 = dmInst2.getField();
457 aaiResKey.setKeyType(xf2.getType().getSimpleName());
462 aaiRes.getAaiResourceKeys().getAaiResourceKey().add(aaiResKey);
464 if (siblings != null) {
465 siblings.getAaiResources().put(fullName, aaiRes);
468 uriKey += "/{" + pathParamName + "}";
471 String newUri = url + "/" + hypName + uriKey;
474 if ("v2".equals(apiVersion)) {
475 aaiRes.setResourceClassName("inventory.aai.openecomp.org." + simpleName);
477 aaiRes.setResourceClassName("inventory.aai.openecomp.org." + apiVersion + "." + simpleName);
480 aaiRes.setAllowDirectWrite(allowDirectWrite);
481 aaiRes.setAllowDirectRead(allowDirectRead);
482 aaiRes.setNamespace(namespace);
483 aaiRes.setSimpleName(simpleName);
485 if (!aaiResources.getResourceLookup().containsKey(simpleName)) {
486 aaiResources.getResourceLookup().put(simpleName, aaiRes);
489 aaiRes.setFullName(fullName);
490 aaiRes.setUri(newUri);
491 aaiRes.setResourceType("node");
492 if ("v2".equals(apiVersion)) {
493 aaiRes.setRelationshipListClass("inventory.aai.openecomp.org.RelationshipList");
495 aaiRes.setRelationshipListClass("inventory.aai.openecomp.org." + apiVersion + ".RelationshipList");
497 aaiRes.setRelationshipUtils(relationshipUtils);
499 if (parentResource != null) {
500 aaiRes.setParent(parentResource);
502 aaiRes.setParent(aaiRes);
505 aaiResources.getAaiResources().put(fullName, aaiRes);
507 if (siblings != null) {
508 siblings.getAaiResources().put(fullName, aaiRes);
510 // AAIResource ancestor = parentResource;
512 // boolean recursiveEntity = false;
513 // while (ancestor != null) {
515 // if (ancestor.getSimpleName().equals(aaiRes.getSimpleName())) {
516 // recursiveEntity = true;
517 // // attach it to the container that contains the resource above this one with the same name
518 // if (ancestor.getParent() != null && ancestor.getParent().getResourceType().equals("container")) {
519 // AAIResource recurseHere = ancestor.getParent();
520 // aaiRes.setRecurseToResource(recurseHere);
524 // ancestor = ancestor.getParent();
527 // if (recursiveEntity == false) {
528 lookAtDynamicResource(cd2.getJavaClass().getSimpleName(),
532 (depth + 1), fullName, namespace, apiVersion, newUri, false, aaiResources, dbMaps,
536 String simpleName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, dmName);
537 String fullName = parent + "/" + simpleName;
538 // System.out.println(spaces + "+ Container of A&AI Object named " + simpleName);
540 AAIResource aaiRes = new AAIResource();
541 if (parentResource != null) {
542 aaiRes.setParent(parentResource);
544 aaiRes.setParent(aaiRes);
546 aaiRes.setAllowDirectWrite(true);
547 aaiRes.setAllowDirectRead(true);
548 aaiRes.setFullName(fullName);
549 aaiRes.setSimpleName(simpleName);
550 if (!aaiResources.getResourceLookup().containsKey(simpleName)) {
551 aaiResources.getResourceLookup().put(simpleName, aaiRes);
553 aaiRes.setResourceType("container");
555 if ("v2".equals(apiVersion)) {
556 aaiRes.setResourceClassName("inventory.aai.openecomp.org." + simpleName);
557 aaiRes.setRelationshipListClass("inventory.aai.openecomp.org.RelationshipList");
559 aaiRes.setResourceClassName("inventory.aai.openecomp.org." + apiVersion + "." + simpleName);
560 aaiRes.setRelationshipListClass("inventory.aai.openecomp.org." + apiVersion + ".RelationshipList");
562 aaiRes.setApiVersion(apiVersion);
564 aaiResources.getAaiResources().put(fullName, aaiRes);
565 aaiRes.setRelationshipUtils(relationshipUtils);
567 String hypName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, simpleName);
569 if (siblings != null) {
570 siblings.getAaiResources().put(fullName, aaiRes);
573 lookAtDynamicResource(cd2.getJavaClass().getSimpleName(),
576 (DynamicTypeImpl)jaxbContext.getDynamicType(newClassName),
577 (depth + 1), fullName, namespace, apiVersion, url + "/" + hypName, false, aaiResources, dbMaps,
587 * Creates the db mapsfrom OXM.
589 * @param propMap the prop map
590 * @param resource the resource
591 * @param dbMaps the db maps
593 private void createDbMapsfromOXM(Map<?, ?> propMap, String resource, DbMaps dbMaps) {
594 String nodeType = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, resource);
595 if ("cvlan-tag-entry".equals(nodeType)) {
596 nodeType = "cvlan-tag";
599 // if we have nodes dependent on multiple nodes we might revisit the node again - skip then
600 if (propMap.size() > 1 && !dbMaps.NodeMapIndexedProps.containsKey(nodeType)) {
602 if (propMap.containsKey("nameProps"))
603 dbMaps.NodeNameProps.putAll(nodeType,
604 (Iterable<String>) fromCommaSeparatedString(propMap.get("nameProps").toString()));
606 if (propMap.containsKey("indexedProps"))
607 dbMaps.NodeMapIndexedProps.putAll(nodeType,
608 (Iterable<String>) fromCommaSeparatedString(propMap.get("indexedProps").toString()));
610 if (propMap.containsKey("dependentOn"))
611 dbMaps.NodeDependencies.putAll(nodeType,
612 (Iterable<String>) fromCommaSeparatedString(propMap.get("dependentOn").toString()));
614 if (propMap.containsKey("alternateKeys1"))
615 dbMaps.NodeAltKey1Props.putAll(nodeType,
616 (Iterable<String>) fromCommaSeparatedString(propMap.get("alternateKeys1").toString()));
618 if (propMap.containsKey("uniqueProps"))
619 dbMaps.NodeMapUniqueProps.putAll(nodeType,
620 (Iterable<String>) fromCommaSeparatedString(propMap.get("uniqueProps").toString()));
623 if (propMap.containsKey("edgeInfo")) {
625 Iterable<String> edgeInfoIterable = (Iterable<String>) fromCommaSeparatedString(propMap.get("edgeInfo").toString());
626 Iterator<String> edgeInfoIterator = edgeInfoIterable.iterator();
627 while(edgeInfoIterator.hasNext()) {
628 String propName = edgeInfoIterator.next();
629 dbMaps.EdgeInfoMap.put(i++, propName);
636 * Creates the db mapsfrom AAI resources.
638 * @param aaiResources the aai resources
639 * @param dbMaps the db maps
641 private void createDbMapsfromAAIResources(AAIResources aaiResources, DbMaps dbMaps) {
643 for (String resource: aaiResources.getAaiResources().keySet()) {
645 AAIResource aaiResource = aaiResources.getAaiResources().get(resource);
646 String nodeType = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,aaiResource.getSimpleName());
648 if (nodeType.equals("cvlan-tag-entry"))
649 nodeType = "cvlan-tag";
651 // Build NodeNamespace
652 if (aaiResource.getNamespace() != null && !aaiResource.getNamespace().equalsIgnoreCase("search"))
653 // oamNetworks is also defined under the search namespace - do not want that namespace
654 dbMaps.NodeNamespace.put(nodeType, CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, aaiResource.getNamespace()));
656 // only process one nodetype once
657 if (dbMaps.NodeProps.containsKey(nodeType))
661 if (aaiResource.getPluralName() != null && !aaiResource.getPluralName().equals(aaiResource.getNamespace()))
662 // dont want resources which are namespaces themselves in map
663 dbMaps.NodePlural.put(nodeType, CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, aaiResource.getPluralName()));
666 dbMaps.NodeProps.putAll(nodeType, aaiResource.getAllFields());
668 // build ReservedNames
669 if (nodeType.equalsIgnoreCase("reserved-prop-names")) {
670 for (String propName: aaiResource.getAllFields()) {
671 dbMaps.ReservedPropNames.put(propName, "");
675 // Build NodekeyProps
676 AAIResourceKeys aaiResKeys = aaiResource.getAaiResourceKeys();
677 List<String> keyList = new ArrayList<String>();
678 for (AAIResourceKey rk : aaiResKeys.getAaiResourceKey()) {
679 String keyProp = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,rk.getKeyName());
680 if (!keyList.contains(keyProp))
681 keyList.add(keyProp);
683 dbMaps.NodeKeyProps.putAll(nodeType, (Iterable<String>)keyList);
685 // Build PropertyDataTypeMap
686 for (String propName: aaiResource.getBooleanFields()) {
687 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
688 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
689 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
690 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
691 if (!dbMaps.PropertyDataTypeMap.containsKey(propName))
692 dbMaps.PropertyDataTypeMap.put(propName, "Boolean");
693 else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("Boolean"))
694 System.out.println(propName + "defined with mis-matched types in oxm file");
696 for (String propName: aaiResource.getShortFields()) {
697 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
698 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
699 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
700 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
701 if (!dbMaps.PropertyDataTypeMap.containsKey(propName))
702 dbMaps.PropertyDataTypeMap.put(propName, "Integer");
703 else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("Integer"))
704 System.out.println(propName + "defined with mis-matched types in oxm file");
706 for (String propName: aaiResource.getLongFields()) {
707 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
708 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
709 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
710 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
711 if (!dbMaps.PropertyDataTypeMap.containsKey(propName)) {
712 if (propName.contains("-ts"))
713 dbMaps.PropertyDataTypeMap.put(propName, "Long");
715 dbMaps.PropertyDataTypeMap.put(propName, "Integer");
716 } else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("Integer"))
717 System.out.println(propName + "defined with mis-matched types in oxm file");
719 for (String propName: aaiResource.getIntFields()) {
720 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
721 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
722 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
723 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
724 if (!dbMaps.PropertyDataTypeMap.containsKey(propName))
725 dbMaps.PropertyDataTypeMap.put(propName, "Integer");
726 else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("Integer"))
727 System.out.println(propName + "defined with mis-matched types in oxm file");
729 for (String propName: aaiResource.getStringFields()) {
730 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
731 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
732 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
733 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
734 if (!dbMaps.PropertyDataTypeMap.containsKey(propName))
735 dbMaps.PropertyDataTypeMap.put(propName, "String");
736 else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("String"))
737 System.out.println(propName + "defined with mis-matched types in oxm file");
739 for (String propName: aaiResource.getStringListFields()) {
740 if (nodeType.equalsIgnoreCase("edge-prop-names")) // these properties are in mixed format in DB
741 propName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, propName);
742 if (propName.equals("sVCINFRA")) propName = "SVC-INFRA";
743 if (propName.equals("sVCINFRAREV")) propName = "SVC-INFRA-REV";
744 if (!dbMaps.PropertyDataTypeMap.containsKey(propName))
745 dbMaps.PropertyDataTypeMap.put(propName, "Set<String>");
746 else if (!dbMaps.PropertyDataTypeMap.get(propName).equals("Set<String>"))
747 System.out.println(propName + "defined with mis-matched types in oxm file");
755 * Creates the property and node version info map from db maps.
757 private void createPropertyAndNodeVersionInfoMapFromDbMaps() {
758 DbMaps dbMaps = null;
759 String previousApiVersion = null;
760 List<Integer> apiIntegerKeySet = new ArrayList<Integer>();
761 for ( String vers : dbMapsContainer.keySet()) {
762 apiIntegerKeySet.add(Integer.valueOf(vers.substring(1)));
764 ArrayList<Integer> apiIntegerVersionsList = (ArrayList<Integer>) asSortedList(apiIntegerKeySet);
766 for ( Integer apiIntegerVersion : apiIntegerVersionsList) {
767 apiVersion = "v" + apiIntegerVersion;
768 System.out.println("apiVersion=" + apiVersion);
769 dbMaps = dbMapsContainer.get(apiVersion);
771 if (previousApiVersion != null) { // when running more than one version
772 dbMaps.PropertyVersionInfoMap.putAll(dbMapsContainer.get(previousApiVersion).PropertyVersionInfoMap);
773 dbMaps.NodeVersionInfoMap.putAll(dbMapsContainer.get(previousApiVersion).NodeVersionInfoMap);
776 Iterator<String> nodeTypeIterator = dbMaps.NodeProps.keySet().iterator();
777 while( nodeTypeIterator.hasNext() ){
778 String nType = nodeTypeIterator.next();
779 if (!dbMaps.NodeVersionInfoMap.containsKey(nType)) {
780 dbMaps.NodeVersionInfoMap.put(nType, apiVersion);
782 Collection <String> nodePropsForType = dbMaps.NodeProps.get(nType);
783 Iterator <String> propIter = nodePropsForType.iterator();
784 while( propIter.hasNext() ){
785 String propName = propIter.next();
786 String infoKey = nType + "|" + propName;
787 if( ! dbMaps.PropertyVersionInfoMap.containsKey(infoKey) ){
788 // We haven't seen this one yet -- add it in.
789 dbMaps.PropertyVersionInfoMap.put(infoKey, apiVersion);
793 dbMapsContainer.put(apiVersion, dbMaps);
794 previousApiVersion = apiVersion;
801 * @param <T> the generic type
805 private <T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
806 List<T> list = new ArrayList<T>(c);
807 java.util.Collections.sort(list);
812 * From comma separated string.
814 * @param string the string
815 * @return the iterable
817 public Iterable<String> fromCommaSeparatedString( String string ) {
818 Iterable<String> split = Splitter.on( "," ).omitEmptyStrings().trimResults().split( string );
828 public String prettyPrintMap(Multimap<String, String> map) {
829 StringBuilder sb = new StringBuilder();
831 for (String key:map.keySet()) {
834 sb.append('=').append('"');
835 sb.append(map.get(key));
839 return sb.toString();
848 public String prettyPrintMap(Map<?, String> map) {
849 StringBuilder sb = new StringBuilder();
851 for (Object key:map.keySet()) {
854 sb.append('=').append('"');
855 sb.append(map.get(key));
859 return sb.toString();