diff options
author | Adam Wudzinski <adam.wudzinski@nokia.com> | 2018-07-05 15:05:33 +0200 |
---|---|---|
committer | awudzins <adam.wudzinski@nokia.com> | 2018-07-05 15:05:33 +0200 |
commit | ee8444faf7ad83403b64f9627c442dc7351b21ea (patch) | |
tree | 92edc49c6877f89f6c316fb9c9837e1b84722cf1 /aai-traversal/src/main | |
parent | 393e3083b831358b07e9e5f4170da584c318f451 (diff) |
Fix minor clumsy sonar issues
Change-Id: Ib3c6c469236a635e6f2a1f4314aab67254128c73
Issue-ID: AAI-1366
Signed-off-by: awudzins <adam.wudzinski@nokia.com>
Diffstat (limited to 'aai-traversal/src/main')
7 files changed, 711 insertions, 792 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java index 9d2b934..1f7a75f 100644 --- a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java +++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java @@ -60,9 +60,9 @@ public class ModelBasedProcessing { private Loader loader; private DBSerializer serializer; private DbMethHelper dbMethHelper; - + protected ModelBasedProcessing() { - + } public ModelBasedProcessing(Loader loader, TransactionalGraphEngine engine, DBSerializer serializer) { this.loader = loader; @@ -85,25 +85,25 @@ public class ModelBasedProcessing { * @throws AAIException the AAI exception */ public Map<String,String> getStartNodesAndModVersionIds( String transId, String fromAppId, - String passedModelVersionId, + String passedModelVersionId, String passedModelInvId, String passedModelName, String passedTopNodeType, - List<Map<String,Object>> startNodeFilterArrayOfHashes, - String apiVer ) + List<Map<String,Object>> startNodeFilterArrayOfHashes, + String apiVer ) throws AAIException { // ---------------------------------------------------------------------------------------------------- // Get a hash for all start-nodes (key = vtxId, val = modelVersionId that applies) - // If no start-node-key info is passed, then use either the passed modelVersion or + // If no start-node-key info is passed, then use either the passed modelVersion or // the passed model-invariant-id or model-name to collect them. - // If start-node-key info is given, use it instead to look for start-nodes. - // Note: if ONLY start-node-key info is given, then it would have to map to nodes which + // If start-node-key info is given, use it instead to look for start-nodes. + // Note: if ONLY start-node-key info is given, then it would have to map to nodes which // have persona data. Otherwise we'd have no way to know what model to collect data with. // ---------------------------------------------------------------------------------------------------- Iterator<Vertex> startVerts = null; Map<String, String> startVertInfo = new HashMap<>(); - + if( startNodeFilterArrayOfHashes.isEmpty() ){ // Since they did not give any data to find start instances, we will have to find them // using whatever model-info they provided so we can use it to map to persona-data in the db. @@ -125,7 +125,7 @@ public class ModelBasedProcessing { if( calcModId != null ){ startVerts = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(addDBAliasedSuffix("model-invariant-id"),calcModId).has(addDBAliasedSuffix("model-version-id"),passedModelVersionId); } - } + } else if( passedModelInvId != null && !passedModelInvId.equals("") ){ // They gave us the model-invariant-id startVerts = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(addDBAliasedSuffix("model-invariant-id"),passedModelInvId); @@ -138,11 +138,11 @@ public class ModelBasedProcessing { for( int i = 0; i < modelVerVtxList.size(); i++ ){ String calcModVerId = (modelVerVtxList.get(i)).<String>property("model-version-id").orElse(null); Vertex modVtx = getModelGivenModelVer(modelVerVtxList.get(i),""); - String calcModInvId = modVtx.<String>property("model-invariant-id").orElse(null); + String calcModInvId = modVtx.<String>property("model-invariant-id").orElse(null); // Now we can look up instances that match this model's info Iterator<Vertex> tmpStartIter = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(addDBAliasedSuffix("model-invariant-id"),calcModInvId).has(addDBAliasedSuffix("model-version-id"),calcModVerId); while( tmpStartIter.hasNext() ){ - Vertex tmpStartVert = (Vertex) tmpStartIter.next(); + Vertex tmpStartVert = tmpStartIter.next(); startVtxList.add(tmpStartVert); } } @@ -150,12 +150,12 @@ public class ModelBasedProcessing { if( !startVtxList.isEmpty() ){ startVerts = startVtxList.iterator(); } - } + } } - - if( startVerts != null ){ + + if( startVerts != null ){ while( startVerts.hasNext() ){ - Vertex tmpStartVert = (Vertex) startVerts.next(); + Vertex tmpStartVert = startVerts.next(); String vid = tmpStartVert.id().toString(); String tmpModId = tmpStartVert.<String>property(addDBAliasedSuffix("model-invariant-id")).orElse(null); String tmpModVerId = tmpStartVert.<String>property(addDBAliasedSuffix("model-version-id")).orElse(null); @@ -164,12 +164,12 @@ public class ModelBasedProcessing { } if( startVertInfo.isEmpty() ){ throw new AAIException("AAI_6114", "Start Node(s) could not be found for model data passed. " + - "(modelVersionId = [" + passedModelVersionId + + "(modelVersionId = [" + passedModelVersionId + "], modelInvariantId = [" + passedModelInvId + "], modelName = [" + passedModelName + "])"); } - + return startVertInfo; } else { @@ -179,17 +179,17 @@ public class ModelBasedProcessing { String modInfoStr = ""; if( passedModelVersionId != null && !passedModelVersionId.equals("") ){ modTopNodeType = getModelVerTopWidgetType( transId, fromAppId, passedModelVersionId, "", "" ); - modInfoStr = "modelVersionId = (" + passedModelVersionId + ")"; + modInfoStr = "modelVersionId = (" + passedModelVersionId + ")"; } else if( passedModelInvId != null && !passedModelInvId.equals("") ){ modTopNodeType = getModelVerTopWidgetType( transId, fromAppId,"", passedModelInvId, "" ); - modInfoStr = "modelId = (" + passedModelInvId + ")"; + modInfoStr = "modelId = (" + passedModelInvId + ")"; } else if( passedModelName != null && !passedModelName.equals("") ){ modTopNodeType = getModelVerTopWidgetType( transId, fromAppId,"", "", passedModelName ); - modInfoStr = "modelName = (" + passedModelName + ")"; + modInfoStr = "modelName = (" + passedModelName + ")"; } - + if( modTopNodeType.equals("") ){ if( (passedTopNodeType == null) || passedTopNodeType.equals("") ){ String msg = "Could not determine the top-node nodeType for this request. modelInfo: [" + modInfoStr + "]"; @@ -202,16 +202,16 @@ public class ModelBasedProcessing { } } else { - // we did get a topNode type based on model info - make sure it doesn't contradict + // we did get a topNode type based on model info - make sure it doesn't contradict // the passsed-in one (if there is one) - if( passedTopNodeType != null && !passedTopNodeType.equals("") + if( passedTopNodeType != null && !passedTopNodeType.equals("") && !passedTopNodeType.equals(modTopNodeType) ){ throw new AAIException("AAI_6120", "topNodeType passed in [" + passedTopNodeType + "] does not match nodeType derived for model info passed in: [" - + modTopNodeType + "]"); + + modTopNodeType + "]"); } } - + List<String> modelVersionIds2Check = new ArrayList<>(); if( (passedModelName != null && !passedModelName.equals("")) ){ // They passed a modelName, so find all the model UUIDs (model-version-id's) that map to this @@ -231,7 +231,7 @@ public class ModelBasedProcessing { modelVersionIds2Check.add(passedModelVersionId); } } - + // We should now be OK with our topNodeType for this request, so we can look for the actual startNodes for( int i=0; i < startNodeFilterArrayOfHashes.size(); i++ ){ // Locate the starting node which will be used to look which corresponds to this set of filter data @@ -244,42 +244,42 @@ public class ModelBasedProcessing { startVtx = result.get(); } catch( AAIException e ){ - String msg = "Could not find startNode of type = [" + modTopNodeType + "], given these params: " + String msg = "Could not find startNode of type = [" + modTopNodeType + "], given these params: " + startNodeFilterArrayOfHashes.get(i) + ". msg # from getUniqueNode() = " + e.getMessage(); throw new AAIException("AAI_6114", msg); } - + String vid = startVtx.id().toString(); String personaModInvId = startVtx.<String>property(addDBAliasedSuffix("model-invariant-id")).orElse(null); String personaModVerId = startVtx.<String>property(addDBAliasedSuffix("model-version-id")).orElse(null); - + // Either this start-node has persona info (which should not contradict any passed-in model info) // or they should have passed in the model to use - so we'd just use that. if( personaModVerId != null && !personaModVerId.equals("") ){ // There is persona data in this start-node. So make sure it doesn't contradict any "passed" stuff - if( modelVersionIds2Check.isEmpty() + if( modelVersionIds2Check.isEmpty() && (passedModelInvId == null || passedModelInvId.equals("")) ){ // They didn't pass any model info, so use the persona one. startVertInfo.put(vid, personaModVerId); } - else if( modelVersionIds2Check.isEmpty() + else if( modelVersionIds2Check.isEmpty() && (passedModelInvId != null && !passedModelInvId.equals("")) ){ // They passed in just the modelId - so check it if( passedModelInvId.equals(personaModInvId) ){ startVertInfo.put(vid, personaModVerId); } } - else if( !modelVersionIds2Check.isEmpty() + else if( !modelVersionIds2Check.isEmpty() && (passedModelInvId == null || passedModelInvId.equals("")) ){ // They passed in just modelVersionId - so check if( modelVersionIds2Check.contains(personaModVerId) ){ startVertInfo.put(vid, personaModVerId); } - } - else if( !modelVersionIds2Check.isEmpty() + } + else if( !modelVersionIds2Check.isEmpty() && (passedModelInvId != null && !passedModelInvId.equals("")) ){ - // We have BOTH a modelVersionIds and a modelId to check - if( passedModelInvId.equals(personaModInvId) + // We have BOTH a modelVersionIds and a modelId to check + if( passedModelInvId.equals(personaModInvId) && modelVersionIds2Check.contains(personaModVerId) ){ startVertInfo.put(vid, personaModVerId); } @@ -293,16 +293,14 @@ public class ModelBasedProcessing { } else { throw new AAIException("AAI_6118", "Found startNode but since it does not have persona data, the " + - " model-version-id is required. "); + " model-version-id is required. "); } } } } - return startVertInfo; - - }//end of getStartNodesAndModVersionIds() - + } + /** * Query by model. (really model-ver) @@ -326,16 +324,16 @@ public class ModelBasedProcessing { List<Map<String,Object>> startNodeFilterArrayOfHashes, String apiVer ) throws AAIException { - + final String transId_f = transId; final String fromAppId_f = fromAppId; final String modelVersionId_f = modelVersionId; final String modelInvId_f = modelInvariantId; final String modelName_f = modelName; final String topNodeType_f = topNodeType; - final List<Map<String,Object>> startNodeFilterArrayOfHashes_f = startNodeFilterArrayOfHashes; - final String apiVer_f = apiVer; - + final List<Map<String,Object>> startNodeFilterArrayOfHashes_f = startNodeFilterArrayOfHashes; + final String apiVer_f = apiVer; + // Find out what our time-limit should be int timeLimitSec = 0; String timeLimitString = AAIConfig.get("aai.model.query.timeout.sec"); @@ -347,33 +345,33 @@ public class ModelBasedProcessing { // Don't worry, we will leave the limit as zero - which tells us not to use it. } } - + if( timeLimitSec <= 0 ){ // We will NOT be using a timer return queryByModel_Timed( transId, fromAppId, - modelVersionId, + modelVersionId, modelInvariantId, modelName, topNodeType, - startNodeFilterArrayOfHashes, + startNodeFilterArrayOfHashes, apiVer ); } - + List<ResultSet> resultList = new ArrayList<>(); TimeLimiter limiter = new SimpleTimeLimiter(); try { resultList = limiter.callWithTimeout(new Callable <List<ResultSet>>() { public List<ResultSet> call() throws AAIException { return queryByModel_Timed( transId_f, fromAppId_f, - modelVersionId_f, + modelVersionId_f, modelInvId_f, modelName_f, topNodeType_f, - startNodeFilterArrayOfHashes_f, + startNodeFilterArrayOfHashes_f, apiVer_f ); } }, timeLimitSec, TimeUnit.SECONDS, true); - } + } catch (AAIException ae) { // Re-throw AAIException so we get can tell what happened internally throw ae; @@ -384,11 +382,10 @@ public class ModelBasedProcessing { catch (Exception e) { throw new AAIException("AAI_6128", "Unexpected exception in queryByModel(): " + e.getMessage() ); } - return resultList; } - - + + /** * Query by model (model-ver) timed. * @@ -411,28 +408,28 @@ public class ModelBasedProcessing { List<Map<String,Object>> startNodeFilterArrayOfHashesVal, String apiVer ) throws AAIException { - + List<ResultSet> resultArray = new ArrayList<>(); - + // NOTE: this method can be used for different styles of queries: // a) They could pass neither a modelVersionId or a modelInvariantId but just pass a set of data defining start-nodes. // Note - with no model info, we need them to pass the startNodeType for us to be able to use the - // start-node-filter data. We would look at each start node and ensure that each has persona-model info. + // start-node-filter data. We would look at each start node and ensure that each has persona-model info. // Then use whatever model corresponds to each instance to pull that instance's data. // b) They could pass a modelInvariantId, but no modelVersionId and no startNode info. In this case, we - // Would look in the database for all nodes that have a model-invariant-id-local that matches what was + // Would look in the database for all nodes that have a model-invariant-id-local that matches what was // passed, and then for each of those instances, pull the data based on the corresponding model. - // c) They could pass a model-version-id, but no startNode info. We'd make sure that if a + // c) They could pass a model-version-id, but no startNode info. We'd make sure that if a // model-invariant-id was also passed, that it does not conflict - but it really should be null if they // are passing a full model-version-id. Like case -b-, we'd do a query for all nodes - // that have persona info that corresponds to the model-version-id passed and then + // that have persona info that corresponds to the model-version-id passed and then // collect data for each one. // d) They could pass either modelVersionId or modelInvariantId AND startNodeFilter info. In this case we - // would look at the model info to figure out what the top-node-type is, then look at the + // would look at the model info to figure out what the top-node-type is, then look at the // top-node instances based on the startNodeFilter. We'd only collect data for each instance if // it's persona model info matches what was passed in. - - + + // Sorry to do this, but code that gets called with an empty hash as the first array element was causing errors List<Map<String,Object>> startNodeFilterArrayOfHashes = new ArrayList <Map<String,Object>>(); if( !startNodeFilterArrayOfHashesVal.isEmpty() ){ @@ -443,21 +440,21 @@ public class ModelBasedProcessing { } } } - + // ---------------------------------------------------------------------------------------------------------- - // Get a Hash of all the start-nodes (top instance-data node for a model-ver where we will - // start collecting data) for startNode2ModelVerHash: - // key = vertex-id for the startNode, - // value = model-version-id for the corresponding model-ver + // Get a Hash of all the start-nodes (top instance-data node for a model-ver where we will + // start collecting data) for startNode2ModelVerHash: + // key = vertex-id for the startNode, + // value = model-version-id for the corresponding model-ver // ---------------------------------------------------------------------------------------------------------- Map<String, String> startNode2ModelVerHash = getStartNodesAndModVersionIds( transId, fromAppId, modelVersionId, modelInvariantId, modelName, topNodeType, - startNodeFilterArrayOfHashes, apiVer ); - - //System.out.println("\nDEBUG -- Here's a dump of the startnodes/model-vers: " + startNode2ModelVerHash.toString()); - + startNodeFilterArrayOfHashes, apiVer ); + + //System.out.println("\nDEBUG -- Here's a dump of the startnodes/model-vers: " + startNode2ModelVerHash.toString()); + // -------------------------------------------------------------------------------------------------------- - // Figure out what-all models (model-ver nodes) we will be dealing with + // Figure out what-all models (model-ver nodes) we will be dealing with // Note - Instances must all use the same type of start-node, but do not have to all use the same model-ver. // -------------------------------------------------------------------------------------------------------- Map<String, Vertex> distinctModelVersHash = new HashMap<>(); @@ -472,7 +469,7 @@ public class ModelBasedProcessing { Set <String> snKeySet = startNode2ModelVerHash.keySet(); Iterator<String> startNodeIterator = snKeySet.iterator(); while( startNodeIterator.hasNext() ){ - String modVerIdKey = (String) startNodeIterator.next(); + String modVerIdKey = startNodeIterator.next(); String modVerId = startNode2ModelVerHash.get(modVerIdKey); if( !distinctModelVersHash.containsKey(modVerId) ){ // First time seeing this model-version-id @@ -490,7 +487,7 @@ public class ModelBasedProcessing { System.out.println(">>> WARNING - will not collect model data for this vertex since " + "it uses an inconsistant model-ver model. Model-version-id = " + modVerId ); } - + if( tmpNodeType != null && !tmpNodeType.equals("") ){ if( startNodeType.equals("") ){ startNodeType = tmpNodeType; @@ -504,12 +501,12 @@ public class ModelBasedProcessing { } } } - + //System.out.println("\nDEBUG -- Here's a dump of the DISTINCT model-ver hash: " + distinctModelVersHash.toString() ); - + // ------------------------------------------------------------------------------------------------------ // Get the "valid-next-step" hash for each distinct model-ver - // While we're at it, get a mapping of model-invariant-id|model-version to model-version-id for + // While we're at it, get a mapping of model-invariant-id|model-version to model-version-id for // the model-vers being used // ------------------------------------------------------------------------------------------------------ Map<String, Multimap<String, String>> validNextStepHash = new HashMap<>(); @@ -517,46 +514,46 @@ public class ModelBasedProcessing { Set <String> keySet = distinctModelVersHash.keySet(); Iterator<String> modelVerIterator = keySet.iterator(); while( modelVerIterator.hasNext() ){ - String modVerKey = (String) modelVerIterator.next(); + String modVerKey = modelVerIterator.next(); if( ! skipModelVerIdList.contains(modVerKey) ){ - Vertex modelVerVtx = (Vertex)distinctModelVersHash.get(modVerKey); + Vertex modelVerVtx = distinctModelVersHash.get(modVerKey); Multimap<String, String> tmpTopoMap = genTopoMap4ModelVer( transId, fromAppId, modelVerVtx, modVerKey); validNextStepHash.put(modVerKey, tmpTopoMap); } - } - + } + // ------------------------------------------------------------------------------------------------- - // Figure out what the "start-node" for each instance will be (plus the info we will use to + // Figure out what the "start-node" for each instance will be (plus the info we will use to // represent that in our topology) // ------------------------------------------------------------------------------------------------- List<String> failedPersonaCheckVids = new ArrayList<>(); - Map<String, String> firstStepInfoHash = new HashMap<>(); + Map<String, String> firstStepInfoHash = new HashMap<>(); // For firstStepInfoHash: key = startNodeVtxId, val=topNodeType plus personaData if applicable // ie. the value is what we'd use as the "first-step" for this model. if( !nodeTypeSupportsPersona( startNodeType) ){ - // This node type doesn't have persona info, so we just use startNodeType for the first-step-info + // This node type doesn't have persona info, so we just use startNodeType for the first-step-info snKeySet = startNode2ModelVerHash.keySet(); startNodeIterator = snKeySet.iterator(); while( startNodeIterator.hasNext() ){ - String vtxKey = (String) startNodeIterator.next(); + String vtxKey = startNodeIterator.next(); firstStepInfoHash.put(vtxKey,startNodeType); } } - else { + else { // Need to check that this node's persona data is good and if it is - use it for the first step info snKeySet = startNode2ModelVerHash.keySet(); startNodeIterator = snKeySet.iterator(); while( startNodeIterator.hasNext() ){ - String vtxKey = (String) startNodeIterator.next(); + String vtxKey = startNodeIterator.next(); Iterator<Vertex> vtxIterator = this.engine.asAdmin().getReadOnlyTraversalSource().V(vtxKey); - Vertex tmpVtx = (Vertex)vtxIterator.next(); + Vertex tmpVtx = vtxIterator.next(); String thisVtxModelVerId = startNode2ModelVerHash.get(vtxKey); if( skipModelVerIdList.contains(thisVtxModelVerId) ){ // Skip this vertex because it uses a model-ver that is bad continue; } - Vertex modelVerVtx = (Vertex)distinctModelVersHash.get(thisVtxModelVerId); + Vertex modelVerVtx = distinctModelVersHash.get(thisVtxModelVerId); Vertex modelVtx = getModelGivenModelVer( modelVerVtx, "" ); String modInvId = modelVtx.<String>property("model-invariant-id").orElse(null); String personaModInvId = tmpVtx.<String>property(addDBAliasedSuffix("model-invariant-id")).orElse(null); @@ -565,21 +562,21 @@ public class ModelBasedProcessing { String tmpPersonaInfoStr = startNodeType + "," + personaModInvId + "," + personaModVerId; firstStepInfoHash.put(vtxKey, tmpPersonaInfoStr ); } - else { + else { // we won't use this start node below when we collect data because it should have // had persona data that matched it's model - but it did not. failedPersonaCheckVids.add(vtxKey); } - } - } + } + } //System.out.println("\nDEBUG -- Here's a dump of the firstStepInfoHash hash: " + firstStepInfoHash.toString() ); - + // ------------------------------------------------------------------------------------------------ - // Loop through each start-node, collect it's data using collectInstanceData() and put the + // Loop through each start-node, collect it's data using collectInstanceData() and put the // resultSet onto the resultArray. // ------------------------------------------------------------------------------------------------ - + // Make sure they're not bringing back too much data String maxString = AAIConfig.get("aai.model.query.resultset.maxcount"); if( maxString != null && !maxString.equals("") ){ @@ -590,17 +587,17 @@ public class ModelBasedProcessing { catch ( Exception nfe ){ // Don't worry, we will leave the max as zero - which tells us not to use it. } - + if( maxSets > 0 && (startNode2ModelVerHash.size() > maxSets) ){ String msg = " Query returns " + startNode2ModelVerHash.size() + " resultSets. Max allowed is: " + maxSets; throw new AAIException("AAI_6141", msg); } } - + snKeySet = startNode2ModelVerHash.keySet(); startNodeIterator = snKeySet.iterator(); while( startNodeIterator.hasNext() ){ - String topNodeVtxId = (String) startNodeIterator.next(); + String topNodeVtxId = startNodeIterator.next(); if( failedPersonaCheckVids.contains(topNodeVtxId) ){ // Skip this vertex because it failed it's persona-data check above continue; @@ -609,29 +606,27 @@ public class ModelBasedProcessing { // Skip this vertex because it uses a model-ver that is bad continue; } - + Iterator<Vertex> vtxIterator = this.engine.asAdmin().getReadOnlyTraversalSource().V(topNodeVtxId); - Vertex tmpStartVtx = (Vertex)vtxIterator.next(); - String elementLocationTrail = firstStepInfoHash.get(topNodeVtxId); + Vertex tmpStartVtx = vtxIterator.next(); + String elementLocationTrail = firstStepInfoHash.get(topNodeVtxId); String modelVerId = startNode2ModelVerHash.get(topNodeVtxId); Multimap<String, String> validNextStepMap = validNextStepHash.get(modelVerId); - + List<String> vidsTraversed = new ArrayList<>(); Map<String,String> emptyDelKeyHash = new HashMap<>(); Map<String,String> emptyNQElementHash = new HashMap<>(); // Only applies to Named Queries ResultSet tmpResSet = collectInstanceData( transId, fromAppId, - tmpStartVtx, elementLocationTrail, + tmpStartVtx, elementLocationTrail, validNextStepMap, vidsTraversed, 0, emptyDelKeyHash, emptyNQElementHash, apiVer ); - + resultArray.add(tmpResSet); } - return resultArray; - - }// queryByModel_Timed() - - - + } + + + /** * Run delete by model-ver. * @@ -646,15 +641,15 @@ public class ModelBasedProcessing { * @throws AAIException the AAI exception */ public Map<String,String> runDeleteByModel( String transId, String fromAppId, - String modelVersionId, String topNodeTypeVal, Map<String,Object> startNodeFilterHash, String apiVer, String resVersion ) + String modelVersionId, String topNodeTypeVal, Map<String,Object> startNodeFilterHash, String apiVer, String resVersion ) throws AAIException { - + Map<String,String> retHash = new HashMap<>(); - - // Locate the Model-ver node to be used + + // Locate the Model-ver node to be used Vertex modelVerVtx = null; if( modelVersionId != null && !modelVersionId.equals("") ){ - modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver", + modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver", "model-version-id", modelVersionId); } else { @@ -663,28 +658,28 @@ public class ModelBasedProcessing { if( topNodeTypeVal == null || topNodeTypeVal.equals("") ){ throw new AAIException("AAI_6118", "If no model info is passed, then topNodeType is required. "); } - + Optional<Vertex> result = dbMethHelper.searchVertexByIdentityMap(topNodeTypeVal, startNodeFilterHash); if (!result.isPresent()) { throw new AAIException("AAI_6114", "No Node of type " + topNodeTypeVal + " found for properties"); } Vertex startVtx = result.get(); - + String startVertModVerId = startVtx.<String>property(addDBAliasedSuffix("model-version-id")).orElse(null); - modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver", + modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver", "model-version-id", startVertModVerId); } - + if( modelVerVtx == null ){ throw new AAIException("AAI_6114", "Could not determine the model-ver for the given input parameters. "); } String topNType = "unknown"; String modelType = getModelTypeFromModelVer( modelVerVtx, "" ); - + if( modelType.equals("widget") ){ - // If they want to delete using a widget-level model.. That is just a delete of the one - // instance of one of our nodes. + // If they want to delete using a widget-level model.. That is just a delete of the one + // instance of one of our nodes. String widgModNodeType = modelVerVtx.<String>property("model-name").orElse(null); if( (widgModNodeType == null) || widgModNodeType.equals("") ){ String msg = "Could not find model-name for the widget model [" + modelVersionId + "]."; @@ -700,11 +695,11 @@ public class ModelBasedProcessing { retHash.put(widgId, widgModNodeType); return retHash; } - + // --------------------------------------------------------------------------------- // If we got to here, this must be either a service or resource model. // So, we'll need to get a Hash of which parts of the model to delete. - // NOTE- deleteByModel is deleting data based on one specific version of a model. + // NOTE- deleteByModel is deleting data based on one specific version of a model. // --------------------------------------------------------------------------------- String chkFirstNodePersonaModInvId = ""; String chkFirstNodePersonaModVerId = ""; @@ -721,18 +716,18 @@ public class ModelBasedProcessing { chkFirstNodePersonaModVerId = modelVerVtx.<String>property("model-version-id").orElse(null); personaData = "," + chkFirstNodePersonaModInvId + "," + chkFirstNodePersonaModVerId; } - + // Get the deleteKeyHash for this model String incomingTrail = ""; Map<String, String> currentHash = new HashMap<>(); Map<String, Vertex> modConHash = new HashMap<>(); ArrayList <String> vidsTraversed = new ArrayList<>(); Map<String, String> delKeyHash = collectDeleteKeyHash( transId, fromAppId, - firstModElementVertex, incomingTrail, currentHash, vidsTraversed, - 0, modConHash, - chkFirstNodePersonaModInvId, chkFirstNodePersonaModVerId ); - - + firstModElementVertex, incomingTrail, currentHash, vidsTraversed, + 0, modConHash, + chkFirstNodePersonaModInvId, chkFirstNodePersonaModVerId ); + + System.out.println("\n ----DEBUG -----: Delete Hash for model: [" + modelVersionId + "] looks like: "); for( Map.Entry<String, String> entry : delKeyHash.entrySet() ){ System.out.println("key = [" + entry.getKey() + "], val = [" + entry.getValue() + "]"); @@ -749,7 +744,7 @@ public class ModelBasedProcessing { // we need to make sure that the start node matches the persona values. String startVertPersonaModInvId = startVtx.<String>property(addDBAliasedSuffix("model-invariant-id")).orElse(null); String startVertPersonaModVerId = startVtx.<String>property(addDBAliasedSuffix("model-version-id")).orElse(null); - if( !chkFirstNodePersonaModInvId.equals(startVertPersonaModInvId) + if( !chkFirstNodePersonaModInvId.equals(startVertPersonaModInvId) || !chkFirstNodePersonaModVerId.equals(startVertPersonaModVerId) ){ String msg = "Persona-Model data mismatch for start node (" + topNType + "), " + startNodeFilterHash ; @@ -757,36 +752,34 @@ public class ModelBasedProcessing { } } String topVid = startVtx.id().toString(); - + // Read the model-ver into a Map for processing Multimap<String, String> validNextStepMap = genTopoMap4ModelVer(transId, fromAppId, modelVerVtx, modelVersionId); - + // Collect the data String elementLocationTrail = topNType + personaData; vidsTraversed = new ArrayList<>(); - Map<String,String> emptyHash = new HashMap<>(); - + Map<String,String> emptyHash = new HashMap<>(); + // Pass emptyHash for the NQElement hash since that parameter only applies to Named Queries ResultSet retResSet = collectInstanceData( transId, fromAppId, - startVtx, elementLocationTrail, + startVtx, elementLocationTrail, validNextStepMap, vidsTraversed, 0, delKeyHash, emptyHash, apiVer ); - + // Note: the new ResultSet will have each element tagged with the del flag so we'll know if it - // should be deleted or not - so loop through the results in a try-block since some things + // should be deleted or not - so loop through the results in a try-block since some things // will get auto-deleted by parents before we get to them --- and try to remove each one. String vidToResCheck = topVid; - - retHash = deleteAsNeededFromResultSet( transId, fromAppId, retResSet, + + retHash = deleteAsNeededFromResultSet( transId, fromAppId, retResSet, vidToResCheck, apiVer, resVersion, emptyHash ); //String msgStr = "processed deletes for these vids: (\n"+ retHash.keySet().toString() + ")."; - return retHash; - - }// End of runDeleteByModel() + } + + - - /** * Delete as needed from result set. * @@ -807,26 +800,26 @@ public class ModelBasedProcessing { Map<String,String> retHash = new HashMap<>(); retHash.putAll( hashSoFar ); Boolean deleteIt = false; - + if( resSet.getVert() == null ){ return retHash; } - + Vertex thisVtx = resSet.getVert(); String thisGuyId = ""; String thisNT = ""; String thisGuyStr = ""; - + Boolean gotVtxOK = false; try { if( thisVtx != null ){ thisGuyId = thisVtx.id().toString(); thisNT = thisVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); thisGuyStr = thisGuyId + "[" + thisNT + " found at:" + resSet.getLocationInModelSubGraph() + "]"; - - // NOTE -- will try to set the NodeType to itself to see if the node has been deleted already in - // this transaction. It lets you get properties from nodes being deleted where the - // delete hasn't been committed yet. This check used to be accomplished with a call to + + // NOTE -- will try to set the NodeType to itself to see if the node has been deleted already in + // this transaction. It lets you get properties from nodes being deleted where the + // delete hasn't been committed yet. This check used to be accomplished with a call to // "vtx.isRemoved()" but that was a Titan-only feature and is not available anymore since // we no longer use Titan vertices. // If we don't do this check, we get errors later when we try to delete the node. @@ -838,17 +831,17 @@ public class ModelBasedProcessing { // Sometimes things have already been deleted by the time we get to them - just log it. LOGGER.warn("Exception when trying to delete: " + thisGuyStr + ". msg = " + ex.getMessage(), ex); } - + if( !gotVtxOK ){ // The vertex must have already been removed. Just return. - // Note - We need to catch this because the DB sometimes can still have the vtx + // Note - We need to catch this because the DB sometimes can still have the vtx // and be able to get its ID but it is flagged internally as removed already. return retHash; } else { if( resSet.getNewDataDelFlag() != null && resSet.getNewDataDelFlag().equals("T") ){ LOGGER.info(">> will try to delete this one >> " + thisGuyStr); - + try { Boolean requireResourceVersion = false; if( thisGuyId.equals(vidToResCheck) ){ @@ -866,50 +859,48 @@ public class ModelBasedProcessing { else { String errText = ae.getErrorObject().getErrorText(); String errDetail = ae.getMessage(); - LOGGER.warn("Exception when deleting " + thisGuyStr + ". ErrorCode = " + errorCode + + LOGGER.warn("Exception when deleting " + thisGuyStr + ". ErrorCode = " + errorCode + ", errorText = " + errText + ", details = " + errDetail); } } catch( Exception e ){ - // We'd expect to get a "node not found" here sometimes depending on the order that + // We'd expect to get a "node not found" here sometimes depending on the order that // the model has us finding / deleting nodes. // Ignore the exception - but log it so we can see what happened. LOGGER.warn("Exception when deleting " + thisGuyStr + e.getMessage(), e); } - + // We can't depend on a thrown exception to tell us if a node was deleted since it may - // have been auto=deleted before this removeAaiNode() call. + // have been auto=deleted before this removeAaiNode() call. // --- Not sure if we would want to check anything here -- because the graph.commit() is done outside of this call. - + deleteIt = true; } else { - // --- DEBUG ---- + // --- DEBUG ---- System.out.println(">>>>>>> NOT DELETING THIS ONE >>>> " + thisGuyStr ); List<String> retArr = dbMethHelper.getVertexProperties(thisVtx); for( String info : retArr ){ System.out.println(info); } // --- DEBUG ---- } } - + // Now call this routine for the sub-resultSets List <ResultSet> subResultSetList = resSet.getSubResultSet(); Iterator <ResultSet> subResSetIter = subResultSetList.iterator(); while( subResSetIter.hasNext() ){ ResultSet tmpSubResSet = subResSetIter.next(); - retHash = deleteAsNeededFromResultSet( transId, fromAppId, tmpSubResSet, + retHash = deleteAsNeededFromResultSet( transId, fromAppId, tmpSubResSet, vidToResCheck, apiVer, resVersion, retHash ); } - + if( deleteIt ){ retHash.put(thisGuyId, thisGuyStr); } - return retHash; - - }// deleteAsNeededFromResultSet() - - + } + + /** * Query by named query (old version). @@ -927,18 +918,18 @@ public class ModelBasedProcessing { ArrayList <Map<String,Object>> startNodeFilterArrayOfHashes, String apiVer ) throws AAIException { - + String dummyCutPoint = null; Map<String,Object> dummySecondaryFilterHash = null; - + return queryByNamedQuery( transId, fromAppId, - namedQueryUuid, - startNodeFilterArrayOfHashes, + namedQueryUuid, + startNodeFilterArrayOfHashes, apiVer, dummyCutPoint, - dummySecondaryFilterHash ); + dummySecondaryFilterHash ); } - + /** * Query by named query. @@ -960,15 +951,15 @@ public class ModelBasedProcessing { String secondaryFilterCutPoint, Map<String,Object> secondaryFilterHash ) throws AAIException { - + final String transId_f = transId; final String fromAppId_f = fromAppId; final String namedQueryUuid_f = namedQueryUuid; - final List<Map<String,Object>> startNodeFilterArrayOfHashes_f = startNodeFilterArrayOfHashes; - final String apiVer_f = apiVer; - final String secondaryFilterCutPoint_f = secondaryFilterCutPoint; - final Map<String,Object> secondaryFilterHash_f = secondaryFilterHash; - + final List<Map<String,Object>> startNodeFilterArrayOfHashes_f = startNodeFilterArrayOfHashes; + final String apiVer_f = apiVer; + final String secondaryFilterCutPoint_f = secondaryFilterCutPoint; + final Map<String,Object> secondaryFilterHash_f = secondaryFilterHash; + // Find out what our time-limit should be int timeLimitSec = 0; String timeLimitString = AAIConfig.get("aai.model.query.timeout.sec"); @@ -985,12 +976,12 @@ public class ModelBasedProcessing { // We will NOT be using a timer return queryByNamedQuery_Timed( transId, fromAppId, namedQueryUuid, - startNodeFilterArrayOfHashes, + startNodeFilterArrayOfHashes, apiVer, secondaryFilterCutPoint_f, secondaryFilterHash_f ); } - + List<ResultSet> resultList = new ArrayList<>(); TimeLimiter limiter = new SimpleTimeLimiter(); try { @@ -998,14 +989,14 @@ public class ModelBasedProcessing { public List<ResultSet> call() throws AAIException { return queryByNamedQuery_Timed( transId_f, fromAppId_f, namedQueryUuid_f, - startNodeFilterArrayOfHashes_f, + startNodeFilterArrayOfHashes_f, apiVer_f, secondaryFilterCutPoint_f, secondaryFilterHash_f ); } }, timeLimitSec, TimeUnit.SECONDS, true); - - } + + } catch (AAIException ae) { // Re-throw AAIException so we get can tell what happened internally throw ae; @@ -1016,21 +1007,20 @@ public class ModelBasedProcessing { catch (Exception e) { throw new AAIException("AAI_6128", "Unexpected exception in queryByNamedQuery(): " + e.getMessage() ); } - return resultList; } - - + + /** * Query by named query timed. * * @param transId the trans id * @param fromAppId the from app id * @param namedQueryUuid the named query uuid - * @param startNodeFilterArrayOfHashes the start node filter array of hashes --used to locate the first nodes of instance data + * @param startNodeFilterArrayOfHashes the start node filter array of hashes --used to locate the first nodes of instance data * @param apiVer the api ver * @param secondaryFilterCutPoint the nodeType where we will parse for the secondary Filter - * @param secondaryFilterHash the secondary filter hash + * @param secondaryFilterHash the secondary filter hash * @return resultSet * @throws AAIException the AAI exception */ @@ -1040,13 +1030,13 @@ public class ModelBasedProcessing { String apiVer, String secondaryFilterCutPoint, Map<String,Object> secondaryFilterHash - ) + ) throws AAIException { - + // Locate the Query to be used Vertex queryVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query", "named-query-uuid", namedQueryUuid); - + // Get the first/top named-query-element used by this query Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, queryVtx, "named-query-element"); Vertex firstNqElementVert = null; @@ -1057,7 +1047,7 @@ public class ModelBasedProcessing { count++; topNType = getNqElementWidgetType( transId, fromAppId, firstNqElementVert, "" ); } - + if( count < 1 ){ // A named query must start with a single top element throw new AAIException("AAI_6133", "No top-node defined for named-query-uuid = [" + namedQueryUuid + "]"); @@ -1070,7 +1060,7 @@ public class ModelBasedProcessing { String msg = "Could not determine the top-node nodeType for Named Query: [" + namedQueryUuid + "]"; throw new AAIException("AAI_6133", msg); } - + // Read the topology into a hash for processing Multimap<String, String> validNextStepMap = genTopoMap4NamedQ(transId, fromAppId, queryVtx, namedQueryUuid); @@ -1087,7 +1077,7 @@ public class ModelBasedProcessing { boolean foundIndexedField = false; int propertiesSet = 0; while( propIter.hasNext() ){ - String oldVtxKey = (String) propIter.next(); + String oldVtxKey = propIter.next(); String newKey = oldVtxKey; String [] parts = oldVtxKey.split("\\."); if( parts.length == 2 ){ @@ -1131,7 +1121,7 @@ public class ModelBasedProcessing { } } } - + if (startVertList.isEmpty()) { throw new AAIException("AAI_6114", "No Node of type " + topNType + " found for properties"); } @@ -1144,7 +1134,7 @@ public class ModelBasedProcessing { throw new AAIException("AAI_6141", msg); } } - + // Loop through each start node and get its data List<ResultSet> resSetList = new ArrayList<>(); for( int i = 0; i < startVertList.size(); i++ ){ @@ -1153,21 +1143,21 @@ public class ModelBasedProcessing { String elementLocationTrail = topNType; ArrayList <String> vidsTraversed = new ArrayList<>(); Map<String,String> emptyDelKeyHash = new HashMap<>(); // Does not apply to Named Queries - + // Get the mapping of namedQuery elements to our widget topology for this namedQuery String incomingTrail = ""; Map<String, String> currentHash = new HashMap<>(); - + Map<String,String> namedQueryElementHash = collectNQElementHash( transId, fromAppId, firstNqElementVert, incomingTrail, currentHash, vidsTraversed, 0 ); - + vidsTraversed = new ArrayList<>(); ResultSet tmpResSet = collectInstanceData( transId, fromAppId, - startVtx, elementLocationTrail, + startVtx, elementLocationTrail, validNextStepMap, vidsTraversed, 0, emptyDelKeyHash, namedQueryElementHash, apiVer ); resSetList.add(tmpResSet); } - + // If a secondary filter was defined, we will prune the collected instance data result set(s) based on it. List<ResultSet> prunedResSetList = new ArrayList<>(); if( resSetList != null && !resSetList.isEmpty() ){ @@ -1184,8 +1174,8 @@ public class ModelBasedProcessing { } } } - - // Since a NamedQuery can mark some nodes as "do-not-display", we need to collapse our resultSet so + + // Since a NamedQuery can mark some nodes as "do-not-display", we need to collapse our resultSet so // does not display those nodes. List<ResultSet> collapsedResSetList = new ArrayList<>(); if( prunedResSetList != null && !prunedResSetList.isEmpty() ){ @@ -1194,7 +1184,7 @@ public class ModelBasedProcessing { // marked all the "top" node-elements as do-not-output. Ie. the query may // have had a top-node of "generic-vnf" which joins down to different l-interfaces. // If they only want to see the l-interfaces, then a single result set - // would be "collapsed" into many separate resultSets - each of which is + // would be "collapsed" into many separate resultSets - each of which is // just a single l-interface. List<ResultSet> tmpResSetList = collapseForDoNotOutput(prunedResSetList.get(i)); if( tmpResSetList != null && !tmpResSetList.isEmpty() ){ @@ -1205,12 +1195,11 @@ public class ModelBasedProcessing { } } } - + return collapsedResSetList; - - }// End of queryByNamedQuery() + } + - /** * Prune a result set as per a secondary filter. * @@ -1222,13 +1211,13 @@ public class ModelBasedProcessing { */ public ResultSet pruneResultSet(ResultSet resSetVal, String cutPointType, Map<String,Object> secFilterHash ) throws AAIException { - - // Given a ResultSet and some secondary filter info, do pruning as needed + + // Given a ResultSet and some secondary filter info, do pruning as needed ResultSet pResSet = new ResultSet(); - - // For this ResultSet, we will see if we are on a node of the type that is our cutPoint; + + // For this ResultSet, we will see if we are on a node of the type that is our cutPoint; // then only keep it if we peek "below" and see a match for our filter. - + String nt = resSetVal.getVert().<String>property(AAIProperties.NODE_TYPE).orElse(null); if( nt != null && nt.equals(cutPointType) ){ // We are on the type of node that may need to be "pruned" along with it's sub-results @@ -1237,8 +1226,8 @@ public class ModelBasedProcessing { return pResSet; } } - - // If we made it to here, we will not be pruning at this level, so we will + + // If we made it to here, we will not be pruning at this level, so we will // be returning a copy of this resultSet that has it's subResults pruned (as needed). pResSet.setVert(resSetVal.getVert()); pResSet.setDoNotOutputFlag(resSetVal.getDoNotOutputFlag()); @@ -1247,7 +1236,7 @@ public class ModelBasedProcessing { pResSet.setNewDataDelFlag(resSetVal.getNewDataDelFlag()); pResSet.setPropertyLimitDesc(resSetVal.getPropertyLimitDesc()); pResSet.setPropertyOverRideHash(resSetVal.getPropertyOverRideHash()); - + if( !resSetVal.getSubResultSet().isEmpty() ){ ListIterator<ResultSet> listItr = resSetVal.getSubResultSet().listIterator(); List<ResultSet> newSubSetList = new ArrayList<>(); @@ -1259,13 +1248,11 @@ public class ModelBasedProcessing { } } pResSet.setSubResultSet(newSubSetList); - } - + } return pResSet; - - }// End pruneResultSet() - - + } + + /** * Satisfies hash of filters. * @@ -1276,18 +1263,18 @@ public class ModelBasedProcessing { */ public boolean satisfiesFilters(ResultSet resSet, Map<String,Object> filterHash ) throws AAIException { - + if( filterHash.isEmpty() ){ // Nothing to look for, so no, we didn't find it. return false; } - + Iterator <?> it = filterHash.entrySet().iterator(); while( it.hasNext() ){ Map.Entry<?,?> filtEntry = (Map.Entry<?,?>) it.next(); String propNodeTypeDotName = (filtEntry.getKey()).toString(); String fpv = (filtEntry.getValue()).toString(); - + int periodLoc = propNodeTypeDotName.indexOf("."); if( periodLoc <= 0 ){ String emsg = "Bad filter param key passed in: [" + propNodeTypeDotName + "]. Expected format = [nodeName.paramName]\n"; @@ -1305,13 +1292,11 @@ public class ModelBasedProcessing { } } } - // Made it through all the filters -- it found what we were looking for. return true; - - }// end of satisfiesFilters() - - + } + + /** * Filter met by this set. * @@ -1324,7 +1309,7 @@ public class ModelBasedProcessing { public boolean filterMetByThisSet(ResultSet resSet, String filtNodeType, String filtPropName, String filtPropVal ) { // Note - we are just looking for a positive match for one filter for this resultSet // NOTE: we're expecting the filter to have a format like this: "nodeType.parameterName:parameterValue" - + Vertex vert = resSet.getVert(); if( vert == null ){ return false; @@ -1350,7 +1335,7 @@ public class ModelBasedProcessing { } } } - + // Didn't find a match at the this level, so check the sets below it meet the criteria if( resSet.getSubResultSet() != null ){ ListIterator<ResultSet> listItr = resSet.getSubResultSet().listIterator(); @@ -1360,13 +1345,11 @@ public class ModelBasedProcessing { } } } - return false; - - }// end of filterMetByThisSet() - + } + + - /** * Collapse for do not output. * @@ -1376,14 +1359,14 @@ public class ModelBasedProcessing { */ public List<ResultSet> collapseForDoNotOutput(ResultSet resSetVal ) throws AAIException { - - // Given a ResultSet -- if it is tagged to NOT be output, then replace it with - // it's sub-ResultSets if it has any. + + // Given a ResultSet -- if it is tagged to NOT be output, then replace it with + // it's sub-ResultSets if it has any. List<ResultSet> colResultSet = new ArrayList<>(); - + if( resSetVal.getDoNotOutputFlag().equals("true") ){ // This ResultSet isn't to be displayed, so replace it with it's sub-ResultSets - List<ResultSet> subResList = (ArrayList<ResultSet>) resSetVal.getSubResultSet(); + List<ResultSet> subResList = resSetVal.getSubResultSet(); for( int k = 0; k < subResList.size(); k++ ){ List<ResultSet> newSubResList = collapseForDoNotOutput(subResList.get(k)); colResultSet.addAll(newSubResList); @@ -1393,11 +1376,11 @@ public class ModelBasedProcessing { // This set will be displayed colResultSet.add(resSetVal); } - + // For each result set now at this level, call this same routine to collapse their sub-resultSets for( int i = 0; i < colResultSet.size(); i++ ){ List<ResultSet> newSubSet = new ArrayList<>(); - List<ResultSet> subResList = (ArrayList<ResultSet>) colResultSet.get(i).getSubResultSet(); + List<ResultSet> subResList = colResultSet.get(i).getSubResultSet(); for( int n = 0; n < subResList.size(); n++ ){ List<ResultSet> newSubResList = collapseForDoNotOutput(subResList.get(n)); newSubSet.addAll(newSubResList); @@ -1405,19 +1388,18 @@ public class ModelBasedProcessing { // Replace the old subResultSet with the collapsed set colResultSet.get(i).setSubResultSet(newSubSet); } - + return colResultSet; - - }// End collapseForDoNotOutput() - - - + } + + + /** * Collect instance data. * * @param transId the trans id * @param fromAppId the from app id - * @param thisLevelElemVtx the element vtx at this level + * @param thisLevelElemVtx the element vtx at this level * @param thisVertsTrail the this verts trail * @param elementLocationTrail -- trail of nodeTypes that got us here (this element vertex) from the top * @param validNextStepMap the valid next step map -- hash of valid next steps (node types) for this model @@ -1439,33 +1421,33 @@ public class ModelBasedProcessing { Map<String,String> namedQueryElementHash, // only applies to named-query data collecting String apiVer ) throws AAIException { - + levelCounter++; - + String thisElemVid = thisLevelElemVtx.id().toString(); - + if( levelCounter > MAX_LEVELS ) { throw new AAIException("AAI_6125", "collectInstanceData() has looped across more levels than allowed: " + MAX_LEVELS + ". "); } - + ResultSet rs = new ResultSet(); if( namedQueryElementHash.containsKey(thisVertsTrail) ){ // We're collecting data for a named-query, so need to see if we need to do anything special String nqElUuid = namedQueryElementHash.get(thisVertsTrail); Vertex nqElementVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query-element", "named-query-element-uuid", nqElUuid); - + String tmpDoNotShow = nqElementVtx.<String>property("do-not-output").orElse(null); if( tmpDoNotShow != null && tmpDoNotShow.equals("true") ){ rs.setDoNotOutputFlag("true"); } - + if( namedQueryConstraintSaysStop(transId, fromAppId, nqElementVtx, thisLevelElemVtx, apiVer) ){ - // There was a property constraint which says they do not want to collect this vertex or whatever + // There was a property constraint which says they do not want to collect this vertex or whatever // might be below it. Just return the empty rs here. return rs; } - + String propLimDesc = nqElementVtx.<String>property("property-limit-desc").orElse(null); if( (propLimDesc != null) && !propLimDesc.equals("") ){ if (propLimDesc.equalsIgnoreCase("show-all")) { @@ -1481,13 +1463,13 @@ public class ModelBasedProcessing { Map<String,Object> tmpPropertyOverRideHash = getNamedQueryPropOverRide(transId, fromAppId, nqElementVtx, thisLevelElemVtx, apiVer); //System.out.println(" DEBUG --- USING this propertyOverride data set on ResSet [" + tmpPropertyOverRideHash.toString() + "]"); rs.setPropertyOverRideHash(tmpPropertyOverRideHash); - + // See if we need to look up any "unconnected" data that needs to be associated with this result set Map<String,Object> tmpExtraPropHash = getNamedQueryExtraDataLookup(transId, fromAppId, nqElementVtx, thisLevelElemVtx, apiVer); //System.out.println(" DEBUG --- ADDING this EXTRA Lookup data to the ResSet [" + tmpExtraPropHash.toString() + "]"); rs.setExtraPropertyHash(tmpExtraPropHash); } - + rs.setVert(thisLevelElemVtx); rs.setLocationInModelSubGraph(thisVertsTrail); if( delKeyHash.containsKey(thisVertsTrail) && delKeyHash.get(thisVertsTrail).equals("T") ){ @@ -1496,10 +1478,10 @@ public class ModelBasedProcessing { else { rs.setNewDataDelFlag("F"); } - + // Use Gremlin-pipeline to just look for edges that go to a valid "next-steps" Collection <String> validNextStepColl = validNextStepMap.get(thisVertsTrail); - + // Because of how we process linkage-points, we may have duplicate node-types in our next-stepMap (for one step) // So, to keep from looking (and bringing back) the same data twice, we need to make sure our next-steps are unique Set<String> validNextStepHashSet = new HashSet<>(); @@ -1508,20 +1490,20 @@ public class ModelBasedProcessing { String targetStepStr = ntcItr.next(); validNextStepHashSet.add(targetStepStr); } - + List<String> tmpVidsTraversedList = new ArrayList<>(); tmpVidsTraversedList.addAll(vidsTraversed); tmpVidsTraversedList.add(thisElemVid); - + Iterator <String> ntItr = validNextStepHashSet.iterator(); while( ntItr.hasNext() ){ String targetStep = ntItr.next(); // NOTE: NextSteps can either be just a nodeType, or can be a nodeType plus - // model-invariant-id-local and model-version-id-local (the two persona properties) + // model-invariant-id-local and model-version-id-local (the two persona properties) // if those need to be checked also. // When the persona stuff is part of the step, it is a comma separated string. // Ie. "nodeType,model-inv-id-local,model-version-id-local" (the two "persona" props) - // + // String targetNodeType = ""; String pmid = ""; String pmv = ""; @@ -1543,7 +1525,7 @@ public class ModelBasedProcessing { // It's just the nodeType with no other info targetNodeType = targetStep; } - + GraphTraversal<Vertex, Vertex> modPipe = null; if( stepIsJustNT ){ modPipe = this.engine.asAdmin().getReadOnlyTraversalSource().V(thisLevelElemVtx).both().has(AAIProperties.NODE_TYPE, targetNodeType); @@ -1551,31 +1533,29 @@ public class ModelBasedProcessing { else { modPipe = this.engine.asAdmin().getReadOnlyTraversalSource().V(thisLevelElemVtx).both().has(AAIProperties.NODE_TYPE, targetNodeType).has(addDBAliasedSuffix("model-invariant-id"),pmid).has(addDBAliasedSuffix("model-version-id"),pmv); } - + if( modPipe == null || !modPipe.hasNext() ){ //System.out.println("DEBUG - didn't find any [" + targetStep + "] connected to this guy (which is ok)"); } else { while( modPipe.hasNext() ){ - Vertex tmpVert = (Vertex) modPipe.next(); + Vertex tmpVert = modPipe.next(); String tmpVid = tmpVert.id().toString(); String tmpTrail = thisVertsTrail + "|" + targetStep; if( !vidsTraversed.contains(tmpVid) ){ - // This is one we would like to use - so we'll include the result set we get for it + // This is one we would like to use - so we'll include the result set we get for it ResultSet tmpResSet = collectInstanceData( transId, fromAppId, - tmpVert, tmpTrail, - validNextStepMap, tmpVidsTraversedList, + tmpVert, tmpTrail, + validNextStepMap, tmpVidsTraversedList, levelCounter, delKeyHash, namedQueryElementHash, apiVer ); - + rs.getSubResultSet().add(tmpResSet); } } } } - return rs; - - } // End of collectInstanceData() + } /** @@ -1592,17 +1572,17 @@ public class ModelBasedProcessing { public Multimap<String, String> genTopoMap4ModelVer(String transId, String fromAppId, Vertex modelVerVertex, String modelVerId) throws AAIException { - + if( modelVerVertex == null ){ throw new AAIException("AAI_6114", "null modelVerVertex passed to genTopoMap4ModelVer()"); } - + Multimap<String, String> initialEmptyMap = ArrayListMultimap.create(); List<String> vidsTraversed = new ArrayList<>(); String modelType = getModelTypeFromModelVer( modelVerVertex, "" ); if( modelType.equals("widget") ){ // A widget model by itself does not have a topoplogy. That is - it has no "model-elements" which - // define how it is connected to other things. All it has is a name which ties it to + // define how it is connected to other things. All it has is a name which ties it to // an aai-node-type Iterator<Vertex> vertI= this.traverseIncidentEdges(EdgeType.TREE, modelVerVertex, "model-element"); if( vertI != null && vertI.hasNext() ){ @@ -1613,42 +1593,39 @@ public class ModelBasedProcessing { return initialEmptyMap; } } - + String firstModelVerId = modelVerVertex.<String>property("model-version-id").orElse(null); String firstModelVersion = modelVerVertex.<String>property("model-version").orElse(null); if( firstModelVerId == null || firstModelVerId.equals("") || firstModelVersion == null || firstModelVersion.equals("") ){ throw new AAIException("AAI_6132", "Bad Model Definition: Bad model-version-id or model-version. model-version-id = " + modelVerId); } - + Vertex firstElementVertex = getTopElementForSvcOrResModelVer( modelVerVertex, "" ); Vertex firstEleModVerVtx = getModelVerThatElementRepresents( firstElementVertex, "" ); - String firstElemModelType = getModelTypeFromModelVer( firstEleModVerVtx, "" ); + String firstElemModelType = getModelTypeFromModelVer( firstEleModVerVtx, "" ); if( ! firstElemModelType.equals("widget") ){ throw new AAIException("AAI_6132", "Bad Model Definition: First element must correspond to a widget type model. Model UUID = " + modelVerId); } - + Vertex firstModVtx = getModelGivenModelVer( modelVerVertex, "" ); String firstModelInvId = firstModVtx.<String>property("model-invariant-id").orElse(null); if( firstModelInvId == null || firstModelInvId.equals("") ){ throw new AAIException("AAI_6132", "Bad Model Definition: Could not find model.model-invariant-id given model-ver.model-version-id = " + modelVerId); } - - Multimap<String, String> collectedMap = collectTopology4ModelVer( transId, fromAppId, + + return collectTopology4ModelVer( transId, fromAppId, firstElementVertex, "", initialEmptyMap, vidsTraversed, 0, null, firstModelInvId, firstModelVersion ); - - return collectedMap; - - } // End of genTopoMap4ModelVer() + } public List<String> makeSureItsAnArrayList( String listStringVal ){ // We're sometimes getting a String back on db properties that should be ArrayList<String> // Seems to be how they're defined in OXM - whether they use a "xml-wrapper" or not // Need to translate them into ArrayLists sometimes... - + List<String> retArrList = new ArrayList<String>(); String listString = listStringVal; listString = listString.replace(" ", ""); @@ -1661,7 +1638,6 @@ public class ModelBasedProcessing { retArrList.add(pieces[i]); } } - return retArrList; } @@ -1676,33 +1652,33 @@ public class ModelBasedProcessing { */ public Map<String, Vertex> getModConstraintHash(Vertex modelElementVtx, Map<String, Vertex> currentHash ) throws AAIException { - - // For a given model-element vertex, look to see if there are any "model-constraint" elements that is has + + // For a given model-element vertex, look to see if there are any "model-constraint" elements that is has // an OUT "uses" edge to. If it does, then get any "constrained-element-set" nodes that are pointed to // by the "model-constraint". That will be the replacement "constrained-element-set". The UUID of the // "constrained-element-set" that it is supposed to replace is found in the property: - // model-constraint.constrained-element-set-uuid-to-replace + // model-constraint.constrained-element-set-uuid-to-replace // - // For now, that is the only type of model-constraint allowed, so that is all we will look for. - // Pass back any of these "constrained-element-set" nodes along with any that were passed in by + // For now, that is the only type of model-constraint allowed, so that is all we will look for. + // Pass back any of these "constrained-element-set" nodes along with any that were passed in by // the "currentHash" parameter. - + if( modelElementVtx == null ){ String msg = " null modelElementVtx passed to getModConstraintHash() "; throw new AAIException("AAI_6114", msg); } - + String modelType = modelElementVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( modelType == null || (!modelType.equals("model-element")) ){ String msg = " getModConstraintHash() called with wrong type model: [" + modelType + "]. "; throw new AAIException("AAI_6114", msg); } - + Map<String, Vertex> thisHash = new HashMap<>(); if( currentHash != null ){ thisHash.putAll(currentHash); } - + int count = 0; List<Vertex> modelConstraintArray = new ArrayList<>(); Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, modelElementVtx, "model-constraint"); @@ -1715,7 +1691,7 @@ public class ModelBasedProcessing { count++; } } - + if( count > 0 ) { for( int i = 0; i < count; i++ ){ Vertex vtxOfModelConstraint = modelConstraintArray.get(i); @@ -1724,7 +1700,7 @@ public class ModelBasedProcessing { // constrained-element-set to use in its place Iterator<Vertex> mvertI = this.traverseIncidentEdges(EdgeType.TREE, vtxOfModelConstraint, "constrained-element-set"); while( mvertI != null && mvertI.hasNext() ){ - // There better only be one... + // There better only be one... Vertex tmpVert = mvertI.next(); String connectToType = tmpVert.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( (connectToType != null) && connectToType.equals("constrained-element-set") ){ @@ -1739,10 +1715,9 @@ public class ModelBasedProcessing { // Didn't find anything to add, so just return what they passed in. return currentHash; } - - } // End of getModConstraintHash() - - + } + + /** * Gets the top element vertex for service or resource model. * @@ -1752,50 +1727,48 @@ public class ModelBasedProcessing { */ public Vertex getTopElementForSvcOrResModelVer(Vertex modelVerVtx, String trail ) throws AAIException { - + // For a "resource" or "service" type model, return the "top" element in that model if( modelVerVtx == null ){ String msg = " null modelVertex passed to getTopoElementForSvcOrResModelVer() at [" + trail + "]. "; throw new AAIException("AAI_6114", msg); } - + String modelVerId = modelVerVtx.<String>property("model-version-id").orElse(null); if( modelVerId == null ){ String nt = modelVerVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( nt != null && !nt.equals("model-ver") ){ - String msg = "Illegal model defined: model element pointing to nodeType: [" + String msg = "Illegal model defined: model element pointing to nodeType: [" + nt + "], should be pointing to: [model-ver] at [" + trail + "]. "; throw new AAIException("AAI_6132", msg); } } - + Vertex firstElementVertex = null; - + Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, modelVerVtx, "model-element"); int elCount = 0; while( vertI != null && vertI.hasNext() ){ elCount++; firstElementVertex = vertI.next(); } - + if( elCount > 1 ){ - String msg = "Illegal model defined: More than one first element defined for model-ver-id = " + + String msg = "Illegal model defined: More than one first element defined for model-ver-id = " + modelVerId + " at [" + trail + "]. "; throw new AAIException("AAI_6132", msg); } - + if( firstElementVertex == null ){ - String msg = "Could not find first model element for model-ver-id = " + String msg = "Could not find first model element for model-ver-id = " + modelVerId + " at [" + trail + "]. "; throw new AAIException("AAI_6132", msg); } - return firstElementVertex; - - } // End of getTopElementForSvcOrResModelVer() + } + + - - /** * Gets the named query prop over ride. * @@ -1810,34 +1783,32 @@ public class ModelBasedProcessing { public Map<String,Object> getNamedQueryPropOverRide(String transId, String fromAppId, Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer ) throws AAIException { - + // If this model-element says that they want an alternative set of properties returned, then pull that // data out of the instance vertex. - + Map<String,Object> altPropHash = new HashMap<>(); - + if( namedQueryElementVertex == null ){ String msg = " null namedQueryElementVertex passed to getNamedQueryPropOverRide() "; throw new AAIException("AAI_6114", msg); } - + List<String> propCollectList = new ArrayList<>(); Iterator <VertexProperty<Object>> vpI = namedQueryElementVertex.properties("property-collect-list"); while( vpI.hasNext() ){ propCollectList.add((String)vpI.next().value()); } - + for( int i = 0; i < propCollectList.size(); i++ ){ String thisPropName = propCollectList.get(i); Object instanceVal = instanceVertex.<Object>property(thisPropName).orElse(null); altPropHash.put(thisPropName, instanceVal); } - return altPropHash; - - } // End of getNamedQueryPropOverRide() + } + - /** * Named query constraint says stop. * @@ -1852,11 +1823,11 @@ public class ModelBasedProcessing { public Boolean namedQueryConstraintSaysStop(String transId, String fromAppId, Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer ) throws AAIException { - + // For each (if any) property-constraint defined for this named-query-element, we will evaluate if // the constraint is met or not-met. if there are constraints and any are not-met, then // we return "true". - + if( namedQueryElementVertex == null ){ String msg = " null namedQueryElementVertex passed to namedQueryConstraintSaysStop() "; throw new AAIException("AAI_6114", msg); @@ -1865,15 +1836,15 @@ public class ModelBasedProcessing { String msg = " null instanceVertex passed to namedQueryConstraintSaysStop() "; throw new AAIException("AAI_6114", msg); } - + Iterator<Vertex> constrPipe = this.traverseIncidentEdges(EdgeType.TREE, namedQueryElementVertex, "property-constraint"); if( constrPipe == null || !constrPipe.hasNext() ){ // There's no "property-constraint" defined for this named-query-element. No problem. return false; } - + while( constrPipe.hasNext() ){ - Vertex constrVtx = (Vertex) constrPipe.next(); + Vertex constrVtx = constrPipe.next(); // We found a property constraint that we will need to check String conType = constrVtx.<String>property("constraint-type").orElse(null); if( (conType == null) || conType.equals("")){ @@ -1890,13 +1861,13 @@ public class ModelBasedProcessing { String msg = " Bad property-constraint (propVal) found in Named Query definition. "; throw new AAIException("AAI_6133", msg); } - + // See if that constraint is met or not String val = instanceVertex.<String>property(propName).orElse(null); if( val == null ){ val = ""; } - + if( conType.equals("EQUALS") ){ if( !val.equals(propVal) ){ // This constraint was not met @@ -1914,12 +1885,10 @@ public class ModelBasedProcessing { throw new AAIException("AAI_6133", msg); } } - - return false; - - } // End of namedQueryConstraintSaysStop() + return false; + } + - /** * Gets the named query extra data lookup. * @@ -1934,10 +1903,10 @@ public class ModelBasedProcessing { public Map<String,Object> getNamedQueryExtraDataLookup(String transId, String fromAppId, Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer ) throws AAIException { - + // For each (if any) related-lookup defined for this named-query-element, we will go and // and try to find it. All the related-lookup data will get put in a hash and returned. - + if( namedQueryElementVertex == null ){ String msg = " null namedQueryElementVertex passed to getNamedQueryExtraDataLookup() "; throw new AAIException("AAI_6114", msg); @@ -1946,22 +1915,22 @@ public class ModelBasedProcessing { String msg = " null instanceVertex passed to getNamedQueryExtraDataLookup() "; throw new AAIException("AAI_6114", msg); } - + Map<String,Object> retHash = new HashMap<>(); - + Iterator<Vertex> lookPipe = this.traverseIncidentEdges(EdgeType.TREE, namedQueryElementVertex, "related-lookup"); if( lookPipe == null || !lookPipe.hasNext() ){ // There's no "related-lookup" defined for this named-query-element. No problem. return retHash; } - + while( lookPipe.hasNext() ){ - Vertex relLookupVtx = (Vertex) lookPipe.next(); + Vertex relLookupVtx = lookPipe.next(); // We found a related-lookup record to try and use String srcProp = relLookupVtx.<String>property("source-node-property").orElse(null); String srcNodeType = relLookupVtx.<String>property("source-node-type").orElse(null); srcProp = getPropNameWithAliasIfNeeded(srcNodeType, srcProp); - + if( (srcProp == null) || srcProp.equals("")){ String msg = " Bad related-lookup (source-node-property) found in Named Query definition. "; throw new AAIException("AAI_6133", msg); @@ -1973,38 +1942,38 @@ public class ModelBasedProcessing { } String targetProp = relLookupVtx.<String>property("target-node-property").orElse(null); targetProp = getPropNameWithAliasIfNeeded(targetNodeType, targetProp); - + if( (targetProp == null) || targetProp.equals("")){ String msg = " Bad related-lookup (target-node-property) found in Named Query definition. "; throw new AAIException("AAI_6133", msg); } - + List<String> propCollectList = new ArrayList<>(); Iterator <VertexProperty<Object>> vpI = relLookupVtx.properties("property-collect-list"); while( vpI.hasNext() ){ propCollectList.add((String)vpI.next().value()); } - // Use the value from the source to see if we can find ONE target record using the + // Use the value from the source to see if we can find ONE target record using the // value from the source String valFromInstance = instanceVertex.<String>property(srcProp).orElse(null); if( valFromInstance == null ){ // if there is no key to use to go look up something, we should end it here and just - // note what happened - no need to try to look something up by an empty key - LOGGER.debug("WARNING - the instance data node of type [" + srcNodeType - + "] did not have a value for property [" + srcProp + // note what happened - no need to try to look something up by an empty key + LOGGER.debug("WARNING - the instance data node of type [" + srcNodeType + + "] did not have a value for property [" + srcProp + "], so related-lookup is being abandoned."); return retHash; } - + Map<String,Object> propHash = new HashMap<String,Object>(); propHash.put(targetProp, valFromInstance); - + Optional<Vertex> result = dbMethHelper.locateUniqueVertex(targetNodeType, propHash); if (!result.isPresent()) { // If it can't find the lookup node, don't fail, just log that it couldn't be found --- - LOGGER.debug("WARNING - Could not find lookup node that corresponds to nodeType [" - + targetNodeType + "] propertyName = [" + srcProp + LOGGER.debug("WARNING - Could not find lookup node that corresponds to nodeType [" + + targetNodeType + "] propertyName = [" + srcProp + "], propVal = [" + valFromInstance + "] so related-lookup is being abandoned."); return retHash; @@ -2018,21 +1987,20 @@ public class ModelBasedProcessing { Object valObj = tmpVtx.<Object>property(tmpPropName).orElse(null); String lookupKey = targetNodeType + "." + tmpPropName; retHash.put(lookupKey, valObj); - + } } } - + return retHash; - - } // End of getNamedQueryExtraDataLookup() + } /** * Collect NQ element hash. * * @param transId the trans id * @param fromAppId the from app id - * @param thisLevelElemVtx the element verrtx for this level + * @param thisLevelElemVtx the element verrtx for this level * @param incomingTrail the incoming trail -- trail of nodeTypes that got us here (this nq-element vertex) from the top * @param currentHash the current hash * @param Map that got us to this point (that we will use as the base of the map we will return) @@ -2045,21 +2013,21 @@ public class ModelBasedProcessing { Vertex thisLevelElemVtx, String incomingTrail, Map<String,String> currentHash, ArrayList <String> vidsTraversed, int levelCounter ) throws AAIException { - + levelCounter++; Map<String, String> thisHash = new HashMap<>(); thisHash.putAll(currentHash); - + if( levelCounter > MAX_LEVELS ) { throw new AAIException("AAI_6125", "collectNQElementHash() has looped across more levels than allowed: " + MAX_LEVELS + ". "); } String thisGuysTrail = ""; String thisElemVid = thisLevelElemVtx.id().toString(); - + // Find out what widget (and thereby what aai-node-type) this element represents. String thisElementNodeType = getNqElementWidgetType( transId, fromAppId, thisLevelElemVtx, incomingTrail ); - + if( incomingTrail == null || incomingTrail.equals("") ){ // This is the first one thisGuysTrail = thisElementNodeType; @@ -2068,28 +2036,28 @@ public class ModelBasedProcessing { thisGuysTrail = incomingTrail + "|" + thisElementNodeType; } vidsTraversed.add(thisElemVid); - + String nqElementUuid = thisLevelElemVtx.<String>property("named-query-element-uuid").orElse(null); if( nqElementUuid == null || nqElementUuid.equals("") ){ String msg = " named-query element UUID not found at trail = [" + incomingTrail + "]."; throw new AAIException("AAI_6133", msg); } - thisHash.put(thisGuysTrail, nqElementUuid ); - + thisHash.put(thisGuysTrail, nqElementUuid ); + // Now go "down" and look at the sub-elements pointed to so we can get their data. Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, thisLevelElemVtx, "named-query-element"); while( vertI != null && vertI.hasNext() ){ Vertex tmpVert = vertI.next(); String vid = tmpVert.id().toString(); Map<String,Object> elementHash = new HashMap<String, Object>(); - + String connectToType = tmpVert.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( connectToType != null && connectToType.equals("named-query-element") ){ // This is what we would expect elementHash.put(vid, tmpVert); } else { - String msg = " named query element has [connectedTo] edge to improper nodeType= [" + String msg = " named query element has [connectedTo] edge to improper nodeType= [" + connectToType + "] trail = [" + incomingTrail + "]."; throw new AAIException("AAI_6133", msg); } @@ -2098,16 +2066,15 @@ public class ModelBasedProcessing { String tmpElVid = elVert.id().toString(); if( !vidsTraversed.contains(tmpElVid) ){ // This is one we would like to use - so we'll recursively get it's result set to add to ours - Map<String, String> tmpHash = collectNQElementHash( transId, fromAppId, + Map<String, String> tmpHash = collectNQElementHash( transId, fromAppId, elVert, thisGuysTrail, currentHash, vidsTraversed, levelCounter); thisHash.putAll(tmpHash); } - } + } } return thisHash; - - } // End of collectNQElementHash() - + } + /** * Collect delete key hash. @@ -2133,47 +2100,47 @@ public class ModelBasedProcessing { int levelCounter, Map<String, Vertex> modConstraintHash, String overRideModelId, String overRideModelVersionId ) throws AAIException { - + levelCounter++; Map<String, String> thisHash = new HashMap<>(); thisHash.putAll(currentHash); - + if( levelCounter > MAX_LEVELS ) { throw new AAIException("AAI_6125", "collectDeleteKeyHash() has looped across more levels than allowed: " + MAX_LEVELS + ". "); } String thisGuysTrail = ""; String thisElemVid = thisLevelElemVtx.id().toString(); Map<String, Vertex> modConstraintHash2Use = null; - - // If this element represents a resource or service model, then we will replace this element with + + // If this element represents a resource or service model, then we will replace this element with // the "top" element of that resource or service model. That model-element already points to its - // topology, so it will graft in that model's topology. + // topology, so it will graft in that model's topology. // EXCEPT - if this element has "linkage-points" defined, then we need to do some extra // processing for how we join to that model and will not try to go any "deeper". List<String> linkagePtList = new ArrayList<>(); Iterator <VertexProperty<Object>> vpI = thisLevelElemVtx.properties("linkage-points"); - // I am not sure why, but since "linkage-points" is an xml-element-wrapper in the OXM definition, + // I am not sure why, but since "linkage-points" is an xml-element-wrapper in the OXM definition, // we get back the whole array of Strings in one String - but still use the "vtx.properties()" to // get it - but only look at the first thing returned by the iterator. if( vpI.hasNext() ){ String tmpLinkageThing = (String)vpI.next().value(); linkagePtList = makeSureItsAnArrayList( tmpLinkageThing ); - } - + } + if( linkagePtList != null && !linkagePtList.isEmpty() ){ // Whatever this element is - we are connecting to it via a linkage-point // We will figure out what to do and then return without going any deeper String elemFlag = thisLevelElemVtx.<String>property("new-data-del-flag").orElse(null); - + Set<String> linkageConnectNodeTypes = getLinkageConnectNodeTypes( linkagePtList ); Iterator <?> linkNtIter = linkageConnectNodeTypes.iterator(); String incTrail = ""; if( incomingTrail != null && !incomingTrail.equals("") ){ incTrail = incomingTrail + "|"; } - + while( linkNtIter.hasNext() ){ // The 'trail' (or trails) for this element should just be the to the first-contact on the linkage point String linkTrail = incTrail + linkNtIter.next(); @@ -2194,14 +2161,14 @@ public class ModelBasedProcessing { } return thisHash; } - + // ---------------------------------------------------------------------------- - // If we got to here, then this was not an element that used a linkage-point + // If we got to here, then this was not an element that used a linkage-point // ---------------------------------------------------------------------------- - + // Find out what widget-model (and thereby what aai-node-type) this element represents. // Even if this element is pointing to a service or resource model, it must have a - // first element which is a single widget-type model. + // first element which is a single widget-type model. String thisElementNodeType = getModElementWidgetType( thisLevelElemVtx, incomingTrail ); String firstElementModelInfo = ""; @@ -2219,11 +2186,11 @@ public class ModelBasedProcessing { // could be a resource or service model. firstElementModelInfo = "," + overRideModelId + "," + overRideModelVersionId; } - } + } else if( nodeTypeSupportsPersona(thisElementNodeType) ){ firstElementModelInfo = "," + subModelFirstModInvId + "," + subModelFirstVerId; } - + if( incomingTrail.equals("") ){ // This is the first one thisGuysTrail = thisElementNodeType + firstElementModelInfo; @@ -2231,27 +2198,27 @@ public class ModelBasedProcessing { else { thisGuysTrail = incomingTrail + "|" + thisElementNodeType + firstElementModelInfo; } - + String tmpFlag = "F"; Boolean stoppedByASvcOrResourceModelElement = false; if( modType.equals("widget") ){ elementVtxForThisLevel = thisLevelElemVtx; - // For the element-model for the widget at this level, record it's delete flag + // For the element-model for the widget at this level, record it's delete flag tmpFlag = elementVtxForThisLevel.<String>property("new-data-del-flag").orElse(null); } else { - // For an element that is referring to a resource or service model, we replace + // For an element that is referring to a resource or service model, we replace // this element with the "top" element for that resource/service model so that the // topology of that resource/service model will be included in this topology. String modelVerId = thisElementsModelVerVtx.<String>property("model-version-id").orElse(null); - if( subModelFirstModInvId == null || subModelFirstModInvId.equals("") + if( subModelFirstModInvId == null || subModelFirstModInvId.equals("") || subModelFirstVerId == null || subModelFirstVerId.equals("") ){ throw new AAIException("AAI_6132", "Bad Model Definition: Bad model-invariant-id or model-version-id. Model-version-id = " + modelVerId + ", at [" + incomingTrail + "]"); } - - // BUT -- if the model-element HERE at the resource/service level does NOT have - // it's new-data-del-flag set to "T", then we do not need to go down into the + + // BUT -- if the model-element HERE at the resource/service level does NOT have + // it's new-data-del-flag set to "T", then we do not need to go down into the // sub-model looking for delete-able things. tmpFlag = thisLevelElemVtx.<String>property("new-data-del-flag").orElse(null); @@ -2262,10 +2229,10 @@ public class ModelBasedProcessing { else { stoppedByASvcOrResourceModelElement = true; } - // For the element-model for the widget at this level, record it's delete flag + // For the element-model for the widget at this level, record it's delete flag tmpFlag = elementVtxForThisLevel.<String>property("new-data-del-flag").orElse(null); } - + String flag2Use = "F"; // by default we'll use "F" for the delete flag if( ! stoppedByASvcOrResourceModelElement ){ // Since we haven't been stopped by a resource/service level "F", we can look at the lower level flag @@ -2287,8 +2254,8 @@ public class ModelBasedProcessing { flag2Use = "T"; } } - - thisHash.put(thisGuysTrail, flag2Use); + + thisHash.put(thisGuysTrail, flag2Use); if( ! stoppedByASvcOrResourceModelElement ){ // Since we haven't been stopped by a resource/service level "F", we will continue to // go "down" and look at the elements pointed to so we can get their data. @@ -2297,7 +2264,7 @@ public class ModelBasedProcessing { Vertex tmpVert = vertI.next(); String vid = tmpVert.id().toString(); Map<String,Object> elementHash = new HashMap<String, Object>(); - + String connectToType = tmpVert.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( connectToType != null && connectToType.equals("model-element") ){ // A nice, regular old model-element @@ -2314,15 +2281,15 @@ public class ModelBasedProcessing { modConstraintHash.remove(constrainedElementSetUuid); } else { - elementHash = getNextStepElementsFromSet( tmpVert ); + elementHash = getNextStepElementsFromSet( tmpVert ); } } else { - String msg = " model-element has [connectedTo] edge to improper nodeType= [" + String msg = " model-element has [connectedTo] edge to improper nodeType= [" + connectToType + "] trail = [" + incomingTrail + "]."; throw new AAIException("AAI_6132", msg); } - + for( Map.Entry<String, Object> entry : elementHash.entrySet() ){ Vertex elVert = (Vertex)(entry.getValue()); String tmpElVid = elVert.id().toString(); @@ -2330,20 +2297,19 @@ public class ModelBasedProcessing { check4EdgeRule(tmpElNT, thisElementNodeType); if( !vidsTraversed.contains(tmpElVid) ){ // This is one we would like to use - so we'll recursively get it's result set to add to ours - Map<String, String> tmpHash = collectDeleteKeyHash( transId, fromAppId, - elVert, thisGuysTrail, + Map<String, String> tmpHash = collectDeleteKeyHash( transId, fromAppId, + elVert, thisGuysTrail, currentHash, vidsTraversed, levelCounter, modConstraintHash2Use, "", "" ); thisHash.putAll(tmpHash); } - } + } } } return thisHash; - - } // End of collectDeleteKeyHash() - - + } + + /** * Gets the linkage connect node types. * @@ -2353,18 +2319,18 @@ public class ModelBasedProcessing { */ public Set<String> getLinkageConnectNodeTypes(List<String> linkagePtList ) throws AAIException { - // linkage points are a path from the top of a model to where we link in. - // This method wants to just bring back a list of distinct last items. + // linkage points are a path from the top of a model to where we link in. + // This method wants to just bring back a list of distinct last items. // Ie: for the input with these two: "pserver|lag-link|l-interface" and "pserver|p-interface|l-interface" // it would just return a single item, "l-interface" since both linkage points end in that same node-type. - + Set<String> linkPtSet = new HashSet<>(); - + if( linkagePtList == null ){ String detail = " Bad (null) linkagePtList passed to getLinkageConnectNodeTypes() "; throw new AAIException("AAI_6125", detail); } - + for( int i = 0; i < linkagePtList.size(); i++ ){ String [] trailSteps = linkagePtList.get(i).split("\\|"); if( trailSteps == null || trailSteps.length == 0 ){ @@ -2374,12 +2340,11 @@ public class ModelBasedProcessing { String lastStepNT = trailSteps[trailSteps.length - 1]; linkPtSet.add(lastStepNT); } - + return linkPtSet; - - }// End getLinkageConnectNodeTypes() - - + } + + /** * Collect topology for model-ver. * @@ -2403,34 +2368,34 @@ public class ModelBasedProcessing { int levelCounter, Map<String, Vertex> modConstraintHash, String overRideModelInvId, String overRideModelVersionId ) throws AAIException { - + levelCounter++; Multimap<String, String> thisMap = ArrayListMultimap.create(); thisMap.putAll(currentMap); - + if( levelCounter > MAX_LEVELS ) { throw new AAIException("AAI_6125", "collectTopology4ModelVer() has looped across more levels than allowed: " + MAX_LEVELS + ". "); } String thisGuysTrail = ""; String thisElemVid = thisLevelElemVtx.id().toString(); Map<String, Vertex> modConstraintHash2Use = null; - - // If this element represents a resource or service model, then we will replace this element with + + // If this element represents a resource or service model, then we will replace this element with // the "top" element of that resource or service model. That model-element already points to its - // topology, so it will graft in that model's topology. + // topology, so it will graft in that model's topology. // EXCEPT - if this element defines "linkage-points" defined, then we need to do some extra // processing for how we join to that model. - + // Find out what widget-model (and thereby what aai-node-type) this element represents. // Even if this element is pointing to a service or resource model, it must have a - // first element which is a single widget-type model. + // first element which is a single widget-type model. String firstElementModelInfo = ""; String thisElementNodeType = getModElementWidgetType( thisLevelElemVtx, incomingTrail ); if( nodeTypeSupportsPersona(thisElementNodeType) && overRideModelInvId != null && !overRideModelInvId.equals("") ){ firstElementModelInfo = "," + overRideModelInvId + "," + overRideModelVersionId; } - + Vertex elementVtxForThisLevel = null; Vertex thisElementsModelVerVtx = getModelVerThatElementRepresents( thisLevelElemVtx, incomingTrail ); String subModelFirstModInvId = ""; @@ -2441,12 +2406,12 @@ public class ModelBasedProcessing { // For an element that is referring to a resource or service model, we replace this // this element with the "top" element for that resource/service model so that the // topology of that resource/service model gets included in this topology. - // -- Note - since that top element of a service or resource model will point to a widget model, + // -- Note - since that top element of a service or resource model will point to a widget model, // we have to track what modelId/version it really maps so we can make our recursive call Vertex thisElementsModelVtx = getModelGivenModelVer(thisElementsModelVerVtx, incomingTrail); subModelFirstModInvId = thisElementsModelVtx.<String>property("model-invariant-id").orElse(null); subModelFirstModVerId = thisElementsModelVerVtx.<String>property("model-version-id").orElse(null); - + if( nodeTypeSupportsPersona(thisElementNodeType) ){ modInfo4Trail = "," + subModelFirstModInvId + "," + subModelFirstModVerId; } @@ -2455,13 +2420,13 @@ public class ModelBasedProcessing { throw new AAIException("AAI_6132", "Bad Model Definition: Bad model-invariant-id or model-version-id. Model-ver-id = " + modelVerId); } - elementVtxForThisLevel = getTopElementForSvcOrResModelVer(thisElementsModelVerVtx, incomingTrail); + elementVtxForThisLevel = getTopElementForSvcOrResModelVer(thisElementsModelVerVtx, incomingTrail); modConstraintHash2Use = getModConstraintHash( thisLevelElemVtx, modConstraintHash ); } else { elementVtxForThisLevel = thisLevelElemVtx; } - + if( incomingTrail.equals("") ){ // This is the first one thisGuysTrail = thisElementNodeType + firstElementModelInfo; @@ -2469,7 +2434,7 @@ public class ModelBasedProcessing { else { thisGuysTrail = incomingTrail + "|" + thisElementNodeType + modInfo4Trail; } - + // We only want to ensure that a particular element does not repeat on a single "branch". // It could show up on other branches in the case where it is a sub-model which is being // used in more than one place. @@ -2477,7 +2442,7 @@ public class ModelBasedProcessing { List<String> thisTrailsVidsTraversed = new ArrayList <String>(); thisTrailsVidsTraversed.addAll(vidsTraversed); thisTrailsVidsTraversed.add(thisElemVid); - + // Look at the elements pointed to at this level and add on their data Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, elementVtxForThisLevel, "model-element", "constrained-element-set"); @@ -2501,35 +2466,35 @@ public class ModelBasedProcessing { modConstraintHash.remove(constrainedElementSetUuid); } else { - elementHash = getNextStepElementsFromSet( tmpVert ); + elementHash = getNextStepElementsFromSet( tmpVert ); } } else { - String msg = " model element has [connectedTo] edge to improper nodeType= [" + String msg = " model element has [connectedTo] edge to improper nodeType= [" + connectToType + "] trail = [" + incomingTrail + "]."; throw new AAIException("AAI_6132", msg); } - + for( Map.Entry<String, Object> entry : elementHash.entrySet() ){ Vertex elVert = (Vertex)(entry.getValue()); String tmpElVid = elVert.id().toString(); String tmpElNT = getModElementWidgetType( elVert, thisGuysTrail ); String tmpElStepName = getModelElementStepName( elVert, thisGuysTrail); - + List<String> linkagePtList = new ArrayList <String>(); Iterator <VertexProperty<Object>> vpI = elVert.properties("linkage-points"); - - // I am not sure why, but since "linkage-points" is an xml-element-wrapper in the OXM definition, + + // I am not sure why, but since "linkage-points" is an xml-element-wrapper in the OXM definition, // we get back the whole array of Strings in one String - but still use the "vtx.properties()" to // get it - but only look at the first thing returned by the iterator. if( vpI.hasNext() ){ String tmpLinkageThing = (String)vpI.next().value(); linkagePtList = makeSureItsAnArrayList( tmpLinkageThing ); - } - + } + if( linkagePtList != null && !linkagePtList.isEmpty() ){ - // This is as far as we can go, we will use the linkage point info to define the - // rest of this "trail" + // This is as far as we can go, we will use the linkage point info to define the + // rest of this "trail" for( int i = 0; i < linkagePtList.size(); i++ ){ Multimap<String, String> tmpMap = collectTopology4LinkagePoint( transId, fromAppId, linkagePtList.get(i), thisGuysTrail, currentMap); @@ -2542,8 +2507,8 @@ public class ModelBasedProcessing { if( !thisTrailsVidsTraversed.contains(tmpElVid) ){ // This is one we would like to use - so we'll recursively get it's result set to add to ours Multimap<String, String> tmpMap = collectTopology4ModelVer( transId, fromAppId, - elVert, thisGuysTrail, - currentMap, thisTrailsVidsTraversed, levelCounter, + elVert, thisGuysTrail, + currentMap, thisTrailsVidsTraversed, levelCounter, modConstraintHash2Use, subModelFirstModInvId, subModelFirstModVerId ); thisMap.putAll(tmpMap); } @@ -2554,16 +2519,14 @@ public class ModelBasedProcessing { " on trail = [" + thisGuysTrail + "]. "; System.out.println( msg ); throw new AAIException("AAI_6132", msg); - } - } - } + } + } + } } - return thisMap; - - } // End of collectTopology4ModelVer() - - + } + + /** * Check 4 edge rule. * @@ -2574,10 +2537,10 @@ public class ModelBasedProcessing { */ public void check4EdgeRule( String nodeTypeA, String nodeTypeB) throws AAIException { // Throw an exception if there is no defined edge rule for this combination of nodeTypes in DbEdgeRules. - + final EdgeRules edgeRules = EdgeRules.getInstance(); - - if( !edgeRules.hasEdgeRule(nodeTypeA, nodeTypeB) + + if( !edgeRules.hasEdgeRule(nodeTypeA, nodeTypeB) && !edgeRules.hasEdgeRule(nodeTypeB, nodeTypeA) ){ // There's no EdgeRule for this -- find out if one of the nodeTypes is invalid or if // they are valid, but there's just no edgeRule for them. @@ -2593,16 +2556,14 @@ public class ModelBasedProcessing { String emsg = " Unrecognized nodeType bb [" + nodeTypeB + "]\n"; throw new AAIException("AAI_6115", emsg); } - - String msg = " No Edge Rule found for this pair of nodeTypes (order does not matter) [" + + String msg = " No Edge Rule found for this pair of nodeTypes (order does not matter) [" + nodeTypeA + "], [" + nodeTypeB + "]."; throw new AAIException("AAI_6120", msg); } - - } - - + + /** * Collect topology 4 linkage point. * @@ -2622,11 +2583,11 @@ public class ModelBasedProcessing { Multimap<String, String> thisMap = ArrayListMultimap.create(); thisMap.putAll(currentMap); String thisGuysTrail = incomingTrail; - + // NOTE - "trails" can have multiple parts now since we track persona info for some. // We just want to look at the node type info - which would be the piece // before any commas (if there are any). - + String [] trailSteps = thisGuysTrail.split("\\|"); if( trailSteps == null || trailSteps.length == 0 ){ throw new AAIException("AAI_6125", "Bad incomingTrail passed to collectTopology4LinkagePoint(): [" + incomingTrail + "] "); @@ -2634,23 +2595,23 @@ public class ModelBasedProcessing { String lastStepString = trailSteps[trailSteps.length - 1]; String [] stepPieces = lastStepString.split(","); String lastStepNT = stepPieces[0]; - + // It is assumed that the linkagePoint string will be a pipe-delimited string where each // piece is an AAIProperties.NODE_TYPE. For now, the first thing to connect to is what is on the farthest right. // Example: linkagePoint = "pserver|p-interface|l-interface" would mean that we're connecting to the l-interface // but that after that, we connect to a p-interface followed by a pserver. // It might have been more clear to define it in the other direction, but for now, that is it. (16-07) String linkagePointStr = linkagePointStrVal; - - // We are getting these with more than linkage thing in one string. + + // We are getting these with more than linkage thing in one string. // Ie. "pserver|lag-interface|l-interface, pserver|p-interface|l-interface, vlan|l-interface" linkagePointStr = linkagePointStr.replace("[", ""); linkagePointStr = linkagePointStr.replace("]", ""); linkagePointStr = linkagePointStr.replace(" ", ""); - + String [] linkage = linkagePointStr.split("\\,"); for( int x = 0; x < linkage.length; x++ ){ - lastStepNT = stepPieces[0]; + lastStepNT = stepPieces[0]; String thisStepNT = ""; String [] linkageSteps = linkage[x].split("\\|"); if( linkageSteps == null || linkageSteps.length == 0 ){ @@ -2665,10 +2626,10 @@ public class ModelBasedProcessing { } } return thisMap; - - } // End of collectTopology4LinkagePoint() - - + + } + + /** * Gets the next step elements from set. * @@ -2680,21 +2641,21 @@ public class ModelBasedProcessing { throws AAIException { // Take a constrained-element-set and figure out the total set of all the possible elements that it // represents and return them as a Hash. - + Map<String,Object> retElementHash = new HashMap<String, Object>(); - + if( constrElemSetVtx == null ){ String msg = " getNextStepElementsFromSet() called with null constrElemSetVtx "; throw new AAIException("AAI_6125", msg); } - + String constrNodeType = constrElemSetVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); String constrElemSetUuid = constrElemSetVtx.<String>property("constrained-element-set-uuid").orElse(null); if( constrNodeType == null || !constrNodeType.equals("constrained-element-set") ){ String msg = " getNextStepElementsFromSet() called with wrong type model: [" + constrNodeType + "]. "; throw new AAIException("AAI_6125", msg); } - + ArrayList <Vertex> choiceSetVertArray = new ArrayList<Vertex>(); Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, constrElemSetVtx, "element-choice-set"); int setCount = 0; @@ -2706,12 +2667,12 @@ public class ModelBasedProcessing { setCount++; } } - + if( setCount == 0 ){ String msg = "No element-choice-set found under constrained-element-set-uuid = " + constrElemSetUuid; throw new AAIException("AAI_6132", msg); } - + // Loop through each choice-set and grab the model-elements for( int i = 0; i < setCount; i++ ){ Vertex choiceSetVert = choiceSetVertArray.get(i); @@ -2727,24 +2688,24 @@ public class ModelBasedProcessing { } else { // unsupported node type found for this choice-set - String msg = "Unsupported nodeType (" + elNodeType + String msg = "Unsupported nodeType (" + elNodeType + ") found under choice-set under constrained-element-set-uuid = " + constrElemSetUuid; throw new AAIException("AAI_6132", msg); } } - + if( elCount == 0 ){ String msg = "No model-elements found in choice-set under constrained-element-set-uuid = " + constrElemSetUuid; throw new AAIException("AAI_6132", msg); } - + } return retElementHash; - - } // End of getNextStepElementsFromSet() - - - + + } + + + /** * Gen topo map 4 named Q. * @@ -2758,14 +2719,14 @@ public class ModelBasedProcessing { public Multimap<String, String> genTopoMap4NamedQ(String transId, String fromAppId, Vertex queryVertex, String namedQueryUuid ) throws AAIException { - + if( queryVertex == null ){ throw new AAIException("AAI_6125", "null queryVertex passed to genTopoMap4NamedQ()"); } - + Multimap<String, String> initialEmptyMap = ArrayListMultimap.create(); List<String> vidsTraversed = new ArrayList<>(); - + Vertex firstElementVertex = null; Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, queryVertex, "named-query-element"); int elCount = 0; @@ -2773,32 +2734,29 @@ public class ModelBasedProcessing { elCount++; firstElementVertex = vertI.next(); } - + if( elCount > 1 ){ throw new AAIException("AAI_6133", "Illegal query defined: More than one first element defined for = " + namedQueryUuid); } - + if( firstElementVertex == null ){ throw new AAIException("AAI_6114", "Could not find first query element = " + namedQueryUuid); } - + Vertex modVtx = getModelThatNqElementRepresents( firstElementVertex, "" ); - String modelType = getModelTypeFromModel( modVtx, "" ); + String modelType = getModelTypeFromModel( modVtx, "" ); if( ! modelType.equals("widget") ){ throw new AAIException("AAI_6133", "Bad Named Query Definition: First element must correspond to a widget type model. Named Query UUID = " + namedQueryUuid); } - - Multimap<String, String> collectedMap = collectTopology4NamedQ( transId, fromAppId, - firstElementVertex, "", + + return collectTopology4NamedQ( transId, fromAppId, + firstElementVertex, "", initialEmptyMap, vidsTraversed, 0); - - return collectedMap; - - } // End of genTopoMap4NamedQ() + } + + - - /** * Collect topology 4 named Q. * @@ -2813,21 +2771,21 @@ public class ModelBasedProcessing { Vertex thisLevelElemVtx, String incomingTrail, Multimap<String,String> currentMap, List<String> vidsTraversed, int levelCounter ) throws AAIException { - + levelCounter++; Multimap<String, String> thisMap = ArrayListMultimap.create(); thisMap.putAll(currentMap); - + String thisElemVid = thisLevelElemVtx.id().toString(); if( levelCounter > MAX_LEVELS ) { throw new AAIException("AAI_6125", "collectModelStructure() has looped across more levels than allowed: " + MAX_LEVELS + ". "); } String thisGuysTrail = ""; - + // find out what widget (and thereby what aai-node-type) this element represents String thisElementNodeType = getNqElementWidgetType( transId, fromAppId, thisLevelElemVtx, incomingTrail ); - + if( incomingTrail.equals("") ){ // This is the first one thisGuysTrail = thisElementNodeType; @@ -2835,9 +2793,9 @@ public class ModelBasedProcessing { else { thisGuysTrail = incomingTrail + "|" + thisElementNodeType; } - + vidsTraversed.add(thisElemVid); - + // Look at the elements pointed to at this level and add on their data Iterator<Vertex> vertI = this.traverseIncidentEdges(EdgeType.TREE, thisLevelElemVtx, "named-query-element"); while( vertI != null && vertI.hasNext() ){ @@ -2848,15 +2806,15 @@ public class ModelBasedProcessing { if( !vidsTraversed.contains(tmpVid) ){ // This is one we would like to use - so we'll recursively get it's result set to add to ours Multimap<String, String> tmpMap = collectTopology4NamedQ( transId, fromAppId, - tmpVert, thisGuysTrail, + tmpVert, thisGuysTrail, currentMap, vidsTraversed, levelCounter); thisMap.putAll(tmpMap); } } - + return thisMap; - - } // End of collectTopology4NamedQ() + + } /** @@ -2869,7 +2827,7 @@ public class ModelBasedProcessing { */ public Vertex getModelThatNqElementRepresents(Vertex elementVtx, String elementTrail ) throws AAIException { - + // Get the model that a named-query element represents Vertex modVtx = null; Iterator<Vertex> mvertI = this.traverseIncidentEdges(EdgeType.COUSIN, elementVtx, "model"); @@ -2878,13 +2836,13 @@ public class ModelBasedProcessing { modCount++; modVtx = mvertI.next(); } - + if( modCount > 1 ){ String msg = "Illegal element defined: More than one model pointed to by a single named-query-element at [" + elementTrail + "]."; throw new AAIException("AAI_6125", msg); } - + if( modVtx == null ){ String msg = "Bad named-query definition: Could not find model for element. "; if( !elementTrail.equals("") ){ @@ -2892,20 +2850,20 @@ public class ModelBasedProcessing { } throw new AAIException("AAI_6132", msg); } - + String nodeType = modVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( (nodeType != null) && nodeType.equals("model") ){ return modVtx; } else { - String msg = "Illegal Named Query element defined: expecting a 'model', but found 'isA' edge pointing to nodeType = " + + String msg = "Illegal Named Query element defined: expecting a 'model', but found 'isA' edge pointing to nodeType = " + nodeType + "] at [" + elementTrail + "]."; throw new AAIException("AAI_6125", msg); - } - - }// getModelThatNqElementRepresents() - - + } + + } + + /** * Gets the model-ver that element represents. * @@ -2916,7 +2874,7 @@ public class ModelBasedProcessing { */ public Vertex getModelVerThatElementRepresents(Vertex elementVtx, String elementTrail ) throws AAIException { - + // Get the model-ver that an element represents Vertex modVerVtx = null; Iterator<Vertex> mvertI = this.traverseIncidentEdges(EdgeType.COUSIN, elementVtx, "model-ver"); @@ -2925,13 +2883,13 @@ public class ModelBasedProcessing { modCount++; modVerVtx = mvertI.next(); } - + if( modCount > 1 ){ String msg = "Illegal element defined: More than one model pointed to by a single element at [" + elementTrail + "]."; throw new AAIException("AAI_6125", msg); } - + if( modVerVtx == null ){ String msg = "Bad model definition: Could not find model-ver for model-element. "; if( !elementTrail.equals("") ){ @@ -2939,21 +2897,21 @@ public class ModelBasedProcessing { } throw new AAIException("AAI_6132", msg); } - + String nodeType = modVerVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); if( (nodeType != null) && nodeType.equals("model-ver") ){ return modVerVtx; } else { - String msg = "Illegal model-element defined: expecting a 'model-ver', but found 'isA' edge pointing to nodeType = " + + String msg = "Illegal model-element defined: expecting a 'model-ver', but found 'isA' edge pointing to nodeType = " + nodeType + "] at [" + elementTrail + "]."; throw new AAIException("AAI_6125", msg); } - - }// getModelVerThatElementRepresents() - - - + + } + + + /** * Gets the model that is parent to model-ver node. * @@ -2964,7 +2922,7 @@ public class ModelBasedProcessing { */ public Vertex getModelGivenModelVer(Vertex modVerVtx, String elementTrail ) throws AAIException { - + // Get the parent model for this "model-ver" node Vertex modVtx = null; Iterator<Vertex> mvertI = this.traverseIncidentEdges(EdgeType.TREE, modVerVtx, "model"); @@ -2973,13 +2931,13 @@ public class ModelBasedProcessing { modCount++; modVtx = mvertI.next(); } - + if( modCount > 1 ){ String msg = "Illegal model-ver node defined: More than one model points to it with a 'has' edge [" + elementTrail + "]."; throw new AAIException("AAI_6125", msg); } - + if( modVtx == null ){ String msg = "Bad model-ver node: Could not find parent model. "; if( !elementTrail.equals("") ){ @@ -2987,7 +2945,7 @@ public class ModelBasedProcessing { } throw new AAIException("AAI_6132", msg); } - + String nodeType = modVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null);; if( (nodeType != null) && nodeType.equals("model") ){ // Found what we were looking for. @@ -2999,12 +2957,12 @@ public class ModelBasedProcessing { elementTrail + "]."; throw new AAIException("AAI_6125", msg); } - - - }// getModelGivenModelVer() - - - + + + } + + + /** * Gets the model type. * @@ -3015,30 +2973,30 @@ public class ModelBasedProcessing { */ public String getModelTypeFromModel(Vertex modelVtx, String elementTrail ) throws AAIException { - + // Get the model-type from a model vertex if( modelVtx == null ){ String msg = " null modelVtx passed to getModelTypeFromModel() "; throw new AAIException("AAI_6114", msg); - } - + } + String modelType = modelVtx.<String>property("model-type").orElse(null); if( (modelType == null) || modelType.equals("") ){ String msg = "Could not find model-type for model encountered at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + if( !modelType.equals("widget") && !modelType.equals("resource") && !modelType.equals("service") ){ String msg = "Unrecognized model-type, [" + modelType + "] for model pointed to by element at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - - return modelType; - - }// getModelTypeFromModel() - - - + + return modelType; + + } + + + /** * Gets the model type given model-ver * @@ -3049,30 +3007,29 @@ public class ModelBasedProcessing { */ public String getModelTypeFromModelVer(Vertex modelVerVtx, String elementTrail ) throws AAIException { - + // Get the model-type given a model-ver vertex if( modelVerVtx == null ){ String msg = " null modelVerVtx passed to getModelTypeFromModelVer() "; throw new AAIException("AAI_6114", msg); - } - + } + Vertex modVtx = getModelGivenModelVer( modelVerVtx, elementTrail ); String modelType = modVtx.<String>property("model-type").orElse(null); if( (modelType == null) || modelType.equals("") ){ String msg = "Could not find model-type for model encountered at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + if( !modelType.equals("widget") && !modelType.equals("resource") && !modelType.equals("service") ){ String msg = "Unrecognized model-type, [" + modelType + "] for model pointed to by element at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - - return modelType; - - }// getModelTypeFromModelVer() - - + + return modelType; + } + + /** * Gets the model-element step name. @@ -3085,8 +3042,8 @@ public class ModelBasedProcessing { */ public String getModelElementStepName(Vertex elementVtx, String elementTrail) throws AAIException { - - // Get the "step name" for a model-element + + // Get the "step name" for a model-element // Step names look like this for widget-models: AAIProperties.NODE_TYPE // Step names look like this for resource/service models: "aai-node-type,model-invariant-id,model-version-id" // NOTE -- if the element points to a resource or service model, then we'll return the @@ -3094,14 +3051,14 @@ public class ModelBasedProcessing { String thisElementNodeType = "?"; Vertex modVerVtx = getModelVerThatElementRepresents( elementVtx, elementTrail ); String modelType = getModelTypeFromModelVer( modVerVtx, elementTrail ); - + if( modelType == null ){ String msg = " could not determine modelType in getModelElementStepName(). elementTrail = [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + if( modelType.equals("widget") ){ - // NOTE: for models that have model-type = "widget", their "model-name" maps directly to aai-node-type + // NOTE: for models that have model-type = "widget", their "model-name" maps directly to aai-node-type thisElementNodeType = modVerVtx.<String>property("model-name").orElse(null); if( (thisElementNodeType == null) || thisElementNodeType.equals("") ){ String msg = "Could not find model-name for the widget model pointed to by element at [" + elementTrail + "]."; @@ -3111,17 +3068,17 @@ public class ModelBasedProcessing { } else if( modelType.equals("resource") || modelType.equals("service") ){ Vertex modVtx = getModelGivenModelVer( modVerVtx, elementTrail ); - String modInvId = modVtx.<String>property("model-invariant-id").orElse(null); + String modInvId = modVtx.<String>property("model-invariant-id").orElse(null); String modVerId = modVerVtx.<String>property("model-version-id").orElse(null); Vertex relatedTopElementModelVtx = getTopElementForSvcOrResModelVer( modVerVtx, elementTrail ); Vertex relatedModelVtx = getModelVerThatElementRepresents( relatedTopElementModelVtx, elementTrail ); thisElementNodeType = relatedModelVtx.<String>property("model-name").orElse(null); - + if( (thisElementNodeType == null) || thisElementNodeType.equals("") ){ String msg = "Could not find model-name for the widget model pointed to by element at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + String stepName = ""; if( nodeTypeSupportsPersona(thisElementNodeType) ){ // This nodeType that this resource or service model refers to does support persona-related fields, so @@ -3137,11 +3094,10 @@ public class ModelBasedProcessing { String msg = " Unrecognized model-type = [" + modelType + "] pointed to by element at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - - }// getModelElementStepName() - - - + } + + + /** * Node type supports persona. * @@ -3152,7 +3108,7 @@ public class ModelBasedProcessing { */ public Boolean nodeTypeSupportsPersona(String nodeType) throws AAIException { - + if( nodeType == null || nodeType.equals("") ){ return false; } @@ -3163,18 +3119,13 @@ public class ModelBasedProcessing { String emsg = " Unrecognized nodeType [" + nodeType + "]\n"; throw new AAIException("AAI_6115", emsg); } - + Collection <String> props4ThisNT = loader.introspectorFromName(nodeType).getProperties(); - if( !props4ThisNT.contains(addDBAliasedSuffix("model-invariant-id")) || !props4ThisNT.contains(addDBAliasedSuffix("model-version-id")) ){ - return false; - } - else { - return true; - } - - }// nodeTypeSupportsPersona() - - + return props4ThisNT.contains(addDBAliasedSuffix("model-invariant-id")) && + props4ThisNT.contains(addDBAliasedSuffix("model-version-id")); + } + + /** * Gets a Named Query element's widget type. * @@ -3186,16 +3137,16 @@ public class ModelBasedProcessing { public String getNqElementWidgetType(String transId, String fromAppId, Vertex elementVtx, String elementTrail ) throws AAIException { - + String thisNqElementWidgetType = ""; // Get the associated node-type for the model pointed to by a named-query-element. // NOTE -- if the element points to a resource or service model, then we'll return the // widget-type of the first element (crown widget) for that model. Vertex modVtx = getModelThatNqElementRepresents( elementVtx, elementTrail ); String modelType = getModelTypeFromModel( modVtx, elementTrail ); - + if( modelType == null || !modelType.equals("widget") ){ - String emsg = " Model Type must be 'widget' for NamedQuery elements. Found [" + modelType + "] at [" + + String emsg = " Model Type must be 'widget' for NamedQuery elements. Found [" + modelType + "] at [" + elementTrail + "]\n"; throw new AAIException("AAI_6132", emsg); } @@ -3213,11 +3164,9 @@ public class ModelBasedProcessing { return thisNqElementWidgetType; } } - - - }// End getNqElementWidgetType() - - + } + + /** * Gets a model-element's top widget type. * @@ -3228,23 +3177,21 @@ public class ModelBasedProcessing { */ public String getModElementWidgetType(Vertex elementVtx, String elementTrail ) throws AAIException { - + // Get the associated node-type for the model-ver pointed to by a model-element. // NOTE -- if the element points to a resource or service model, then we'll return the // widget-type of the first element (crown widget) for that model. Vertex modVerVtx = getModelVerThatElementRepresents( elementVtx, elementTrail ); - String thisElementNodeType = getModelVerTopWidgetType( modVerVtx, elementTrail ); - return thisElementNodeType; - - }// End getModElementWidgetType() - - + return getModelVerTopWidgetType( modVerVtx, elementTrail ); + } + + /** * Gets the node using unique identifier * * @param transId the trans id * @param fromAppId the from app id - * @param nodeType the nodeType + * @param nodeType the nodeType * @param idPropertyName the property name of the unique identifier * @param uniqueIdVal the UUID value * @return unique vertex found using UUID @@ -3253,41 +3200,41 @@ public class ModelBasedProcessing { public Vertex getNodeUsingUniqueId(String transId, String fromAppId, String nodeType, String idPropertyName, String uniqueIdVal ) throws AAIException { - - // Given a unique identifier, get the Vertex + + // Given a unique identifier, get the Vertex if( uniqueIdVal == null || uniqueIdVal.equals("") ){ - String emsg = " Bad uniqueIdVal passed to getNodeUsingUniqueId(): [" + String emsg = " Bad uniqueIdVal passed to getNodeUsingUniqueId(): [" + uniqueIdVal + "]\n"; throw new AAIException("AAI_6118", emsg); } - + if( idPropertyName == null || idPropertyName.equals("") ){ - String emsg = " Bad idPropertyName passed to getNodeUsingUniqueId(): [" + String emsg = " Bad idPropertyName passed to getNodeUsingUniqueId(): [" + idPropertyName + "]\n"; throw new AAIException("AAI_6118", emsg); - } - + } + if( nodeType == null || nodeType.equals("") ){ - String emsg = " Bad nodeType passed to getNodeUsingUniqueId(): [" + String emsg = " Bad nodeType passed to getNodeUsingUniqueId(): [" + nodeType + "]\n"; throw new AAIException("AAI_6118", emsg); - } - + } + Vertex uniqVtx = null; Iterable <?> uniqVerts = null; uniqVerts = engine.asAdmin().getReadOnlyTraversalSource().V().has(AAIProperties.NODE_TYPE,nodeType).has(idPropertyName,uniqueIdVal).toList(); if( uniqVerts == null ){ - String emsg = "Node could not be found for nodeType = [" + nodeType - + "], propertyName = [" + idPropertyName + String emsg = "Node could not be found for nodeType = [" + nodeType + + "], propertyName = [" + idPropertyName + "], propertyValue = [" + uniqueIdVal + "]\n"; throw new AAIException("AAI_6114", emsg); } - else { + else { int count = 0; Iterator <?> uniqVertsIter = uniqVerts.iterator(); if( !uniqVertsIter.hasNext() ){ - String emsg = "Node could not be found for nodeType = [" + nodeType - + "], propertyName = [" + idPropertyName + String emsg = "Node could not be found for nodeType = [" + nodeType + + "], propertyName = [" + idPropertyName + "], propertyValue = [" + uniqueIdVal + "]\n"; throw new AAIException("AAI_6114", emsg); } @@ -3296,19 +3243,18 @@ public class ModelBasedProcessing { count++; uniqVtx = (Vertex) uniqVertsIter.next(); if( count > 1 ){ - String emsg = "More than one node found for nodeType = [" + nodeType - + "], propertyName = [" + idPropertyName + String emsg = "More than one node found for nodeType = [" + nodeType + + "], propertyName = [" + idPropertyName + "], propertyValue = [" + uniqueIdVal + "]\n"; throw new AAIException("AAI_6132", emsg); } } } } - return uniqVtx; - }// End getNodeUsingUniqueId() - - + } + + /** * Gets the model-ver nodes using name. * @@ -3321,102 +3267,97 @@ public class ModelBasedProcessing { public List<Vertex> getModelVersUsingName(String transId, String fromAppId, String modelName ) throws AAIException { - + // Given a "model-name", find the model-ver vertices that this maps to if( modelName == null || modelName.equals("") ){ - String emsg = " Bad modelName passed to getModelVersUsingName(): [" + String emsg = " Bad modelName passed to getModelVersUsingName(): [" + modelName + "]\n"; throw new AAIException("AAI_6118", emsg); } - + List<Vertex> retVtxArr = new ArrayList<>(); Iterator<Vertex> modVertsIter = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(AAIProperties.NODE_TYPE,"model-ver").has("model-name",modelName); if( !modVertsIter.hasNext() ){ - String emsg = "Model-ver record(s) could not be found for model-ver data passed. model-name = [" + + String emsg = "Model-ver record(s) could not be found for model-ver data passed. model-name = [" + modelName + "]\n"; throw new AAIException("AAI_6132", emsg); } - else { + else { while( modVertsIter.hasNext() ){ - Vertex tmpModelVerVtx = (Vertex) modVertsIter.next(); + Vertex tmpModelVerVtx = modVertsIter.next(); retVtxArr.add(tmpModelVerVtx); } } - return retVtxArr; - - }// End getModelVersUsingName() - - + } + + /** * Gets the model-ver nodes using model-invariant-id. * * @param transId the trans id * @param fromAppId the from app id * @param model-invariant-id (uniquely identifies a model) - * @return the model-ver's defined for the corresponding model + * @return the model-ver's defined for the corresponding model * @throws AAIException the AAI exception */ public Iterator<Vertex> getModVersUsingModelInvId(String transId, String fromAppId, String modelInvId ) throws AAIException { - + // Given a "model-invariant-id", find the model-ver nodes that this maps to if( modelInvId == null || modelInvId.equals("") ){ - String emsg = " Bad model-invariant-id passed to getModVersUsingModelInvId(): [" + String emsg = " Bad model-invariant-id passed to getModVersUsingModelInvId(): [" + modelInvId + "]\n"; throw new AAIException("AAI_6118", emsg); } - + Vertex modVtx = getNodeUsingUniqueId(transId, fromAppId, "model", "model-invariant-id", modelInvId); List<Vertex> retVtxArr = getModVersUsingModel(transId, fromAppId, modVtx); if( retVtxArr == null || retVtxArr.isEmpty() ){ - String emsg = " Model-ver record(s) could not be found attached to model with model-invariant-id = [" + + String emsg = " Model-ver record(s) could not be found attached to model with model-invariant-id = [" + modelInvId + "]\n"; throw new AAIException("AAI_6132", emsg); } - return retVtxArr.iterator(); - }// End getModVersUsingModelInvId() - - + } + + /** * Gets the model-ver nodes using a model node. * * @param transId the trans id * @param fromAppId the from app id * @param model vertex - * @return the model-ver's defined for the corresponding model + * @return the model-ver's defined for the corresponding model * @throws AAIException the AAI exception */ public List<Vertex> getModVersUsingModel(String transId, String fromAppId, Vertex modVtx ) throws AAIException { - + if( modVtx == null ){ String emsg = " Null model vertex passed to getModVersUsingModel(): "; throw new AAIException("AAI_6118", emsg); } - + List<Vertex> retVtxArr = new ArrayList<>(); Iterator<Vertex> modVerVertsIter = this.traverseIncidentEdges(EdgeType.TREE, modVtx, "model-ver"); if(!modVerVertsIter.hasNext()){ String modelInvId = modVtx.<String>property("model-invariant-id").orElse(null); - String emsg = "Model-ver record(s) could not be found attached to model with model-invariant-id = [" + + String emsg = "Model-ver record(s) could not be found attached to model with model-invariant-id = [" + modelInvId + "]\n"; throw new AAIException("AAI_6132", emsg); } - else { + else { while( modVerVertsIter.hasNext() ){ - Vertex tmpModelVtx = (Vertex) modVerVertsIter.next(); + Vertex tmpModelVtx = modVerVertsIter.next(); retVtxArr.add(tmpModelVtx); } } - return retVtxArr; - - }// End getModVersUsingModel() - + } + /** * Gets the model-version-ids using model-name. * @@ -3429,41 +3370,40 @@ public class ModelBasedProcessing { public List<String> getModelVerIdsUsingName( String transId, String fromAppId, String modelName ) throws AAIException { - + // Given a model-name find the model-ver nodes that it maps to if( modelName == null || modelName.equals("") ){ - String emsg = " Bad modelName passed to getModelVerIdsUsingName(): [" + String emsg = " Bad modelName passed to getModelVerIdsUsingName(): [" + modelName + "]\n"; throw new AAIException("AAI_6118", emsg); } - + List<String> retArr = new ArrayList<>(); Iterator<Vertex> modVerVertsIter = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(AAIProperties.NODE_TYPE,"model-ver").has("model-name",modelName); if( !modVerVertsIter.hasNext() ){ - String emsg = " model-ver record(s) could not be found for model data passed. model-name = [" + + String emsg = " model-ver record(s) could not be found for model data passed. model-name = [" + modelName + "]\n"; throw new AAIException("AAI_6114", emsg); } - else { + else { while( modVerVertsIter.hasNext() ){ - Vertex modelVerVtx = (Vertex) modVerVertsIter.next(); + Vertex modelVerVtx = modVerVertsIter.next(); String tmpUuid = modelVerVtx.<String>property("model-version-id").orElse(null); if( (tmpUuid != null) && !tmpUuid.equals("") && !retArr.contains(tmpUuid) ){ retArr.add(tmpUuid); } } } - + if( retArr.isEmpty() ){ - String emsg = "No model-ver record found for model-name = [" + String emsg = "No model-ver record found for model-name = [" + modelName + "]\n"; throw new AAIException("AAI_6132", emsg); } - return retArr; - }// End getModelVerIdsUsingName() - - + } + + /** * Gets the model top widget type. * @@ -3478,14 +3418,14 @@ public class ModelBasedProcessing { public String getModelVerTopWidgetType( String transId, String fromAppId, String modelVersionId, String modelInvId, String modelName ) throws AAIException { - + // Could be given a model-ver's key info (model-version-id), OR, just a (non-unique) model-name, // Or just a model-invariant-id (which could have multiple model-ver records under it). - // In any case, they should only map to one single "top" node-type for the first element. - + // In any case, they should only map to one single "top" node-type for the first element. + String nodeType = "?"; Iterator<Vertex> modVerVertsIter; - + if( modelVersionId != null && !modelVersionId.equals("") ){ // this would be the best - we can just look up the model-ver records directly modVerVertsIter = this.engine.asAdmin().getReadOnlyTraversalSource().V().has(AAIProperties.NODE_TYPE,"model-ver").has("model-version-id",modelVersionId); @@ -3500,13 +3440,13 @@ public class ModelBasedProcessing { String msg = "Neither modelVersionId, modelInvariantId, nor modelName passed to: getModelVerTopWidgetType() "; throw new AAIException("AAI_6120", msg); } - + if( !modVerVertsIter.hasNext() ){ String emsg = "model-ver record(s) could not be found for model data passed: modelInvariantId = [" + modelInvId + "], modeVersionId = [" + modelVersionId + "], modelName = [" + modelName + "]\n"; throw new AAIException("AAI_6114", emsg); } - else { + else { String lastNT = ""; if( !modVerVertsIter.hasNext() ){ String emsg = "model-ver record(s) could not be found for model data passed: modelInvariantId = [" + modelInvId + @@ -3514,13 +3454,13 @@ public class ModelBasedProcessing { throw new AAIException("AAI_6114", emsg); } while( modVerVertsIter.hasNext() ){ - Vertex tmpModVerVtx = (Vertex) modVerVertsIter.next(); + Vertex tmpModVerVtx = modVerVertsIter.next(); String tmpNT = getModelVerTopWidgetType( tmpModVerVtx, "" ); if( lastNT != null && !lastNT.equals("") ){ if( !lastNT.equals(tmpNT) ){ - String emsg = "Different top-node-types (" + tmpNT + ", " + lastNT + String emsg = "Different top-node-types (" + tmpNT + ", " + lastNT + ") found for model data passed. (" + - " modelVersionId = [" + modelVersionId + + " modelVersionId = [" + modelVersionId + "], modelId = [" + modelInvId + "], modelName = [" + modelName + "])\n"; @@ -3531,12 +3471,10 @@ public class ModelBasedProcessing { nodeType = tmpNT; } } - return nodeType; - - }// End getModelVerTopWidgetType() - - + } + + /** * Gets the widget type that this model-ver starts with. * @@ -3555,7 +3493,7 @@ public class ModelBasedProcessing { String msg = " Could not determine modelType in getModelVerTopWidgetType(). elementTrail = [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + String thisElementNodeType = "?"; if( modelType.equals("widget") ){ // NOTE: for models that have model-type = "widget", their child model-ver nodes will @@ -3580,12 +3518,11 @@ public class ModelBasedProcessing { String msg = " Unrecognized model-type = [" + modelType + "] pointed to by element at [" + elementTrail + "]."; throw new AAIException("AAI_6132", msg); } - + return thisElementNodeType; - - }// getModelVerTopWidgetType() - - + } + + /** * Validate model. * @@ -3595,10 +3532,10 @@ public class ModelBasedProcessing { * @param apiVersion the api version * @throws AAIException the AAI exception */ - public void validateModel(String transId, String fromAppId, String modelVersionIdVal, String apiVersion ) + public void validateModel(String transId, String fromAppId, String modelVersionIdVal, String apiVersion ) throws AAIException { - - // Note - this will throw an exception if the model either can't be found, or if + + // Note - this will throw an exception if the model either can't be found, or if // we can't figure out its topology map. Vertex modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver", "model-version-id", modelVersionIdVal); @@ -3613,10 +3550,9 @@ public class ModelBasedProcessing { System.out.println("INFO -- " + msg ); } return; - - }// End validateModel() - - + } + + /** * Validate named query. * @@ -3626,29 +3562,28 @@ public class ModelBasedProcessing { * @param apiVersion the api version * @throws AAIException the AAI exception */ - public void validateNamedQuery(String transId, String fromAppId, String namedQueryUuid, String apiVersion ) + public void validateNamedQuery(String transId, String fromAppId, String namedQueryUuid, String apiVersion ) throws AAIException { - - // Note - this will throw an exception if the named query either can't be found, or if + + // Note - this will throw an exception if the named query either can't be found, or if // we can't figure out its topology map. Vertex nqVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query", "named-query-uuid", namedQueryUuid); - + if( nqVtx == null ){ String msg = " Could not find named-query with namedQueryUuid = [" + namedQueryUuid + "]."; throw new AAIException("AAI_6114", msg); } else { - //Multimap<String, String> topoMap = genTopoMap4NamedQ( "junkTransId", "junkFromAppId", + //Multimap<String, String> topoMap = genTopoMap4NamedQ( "junkTransId", "junkFromAppId", // graph, nqVtx, namedQueryUuid ); //System.out.println("DEBUG -- for test only : --- "); //System.out.println("DEBUG -- topomap = [" + topoMap + "]"); } return; - - }// End validateNamedQuery() - - + } + + /** * Show result set. * @@ -3656,7 +3591,7 @@ public class ModelBasedProcessing { * @param levelCount the level count */ public void showResultSet(ResultSet resSet, int levelCount ) { - + levelCount++; String propsStr = ""; for( int i= 1; i <= levelCount; i++ ){ @@ -3667,11 +3602,11 @@ public class ModelBasedProcessing { } String nt = resSet.getVert().<String>property(AAIProperties.NODE_TYPE).orElse(null); propsStr = propsStr + "[" + nt + "] "; - + //propsStr = propsStr + " newDataDelFlag = " + resSet.getNewDataDelFlag() + ", trail = " + resSet.getLocationInModelSubGraph(); //propsStr = propsStr + "limitDesc = [" + resSet.getPropertyLimitDesc() + "]"; propsStr = propsStr + " trail = " + resSet.getLocationInModelSubGraph(); - + Map<String,Object> overrideHash = resSet.getPropertyOverRideHash(); if( overrideHash != null && !overrideHash.isEmpty() ){ for( Map.Entry<String, Object> entry : overrideHash.entrySet() ){ @@ -3684,7 +3619,7 @@ public class ModelBasedProcessing { Iterator<VertexProperty<Object>> pI = resSet.getVert().properties(); while( pI.hasNext() ){ VertexProperty<Object> tp = pI.next(); - if( ! tp.key().startsWith("aai") + if( ! tp.key().startsWith("aai") && ! tp.key().equals("source-of-truth") //&& ! tp.key().equals("resource-version") && ! tp.key().startsWith("last-mod") @@ -3703,45 +3638,42 @@ public class ModelBasedProcessing { propsStr = propsStr + " [" + propName + " = " + propVal.toString() + "]"; } } - + System.out.println( propsStr ); LOGGER.info(propsStr); - + if( !resSet.getSubResultSet().isEmpty() ){ ListIterator<ResultSet> listItr = resSet.getSubResultSet().listIterator(); while( listItr.hasNext() ){ showResultSet( listItr.next(), levelCount ); } } - - }// end of showResultSet() - - private Iterator<Vertex> traverseIncidentEdges(EdgeType treeType, Vertex startV, String connectedNodeType) throws AAIUnknownObjectException, AAIException { - QueryBuilder builder = this.engine.getQueryBuilder(startV).createEdgeTraversal(treeType, startV, loader.introspectorFromName(connectedNodeType)); - return builder; + } + + private Iterator<Vertex> traverseIncidentEdges(EdgeType treeType, Vertex startV, String connectedNodeType) throws AAIException { + return this.engine.getQueryBuilder(startV).createEdgeTraversal(treeType, startV, loader.introspectorFromName(connectedNodeType)); } - - private Iterator<Vertex> traverseIncidentEdges(EdgeType treeType, Vertex startV, String... connectedNodeType) throws AAIUnknownObjectException, AAIException { + + private Iterator<Vertex> traverseIncidentEdges(EdgeType treeType, Vertex startV, String... connectedNodeType) throws AAIException { QueryBuilder[] builders = new QueryBuilder[connectedNodeType.length]; for (int i = 0; i < connectedNodeType.length; i++) { builders[i] = this.engine.getQueryBuilder(startV).createEdgeTraversal(EdgeType.TREE, startV, loader.introspectorFromName(connectedNodeType[i])); } - QueryBuilder builder = this.engine.getQueryBuilder(startV).union(builders); - return builder; + return this.engine.getQueryBuilder(startV).union(builders); } private String addDBAliasedSuffix(String propName) { return propName + AAIProperties.DB_ALIAS_SUFFIX; } - + protected String getPropNameWithAliasIfNeeded(String nodeType, String propName) throws AAIUnknownObjectException { - + String retPropName = propName; if( loader.introspectorFromName(nodeType).getPropertyMetadata(propName, PropertyMetadata.DB_ALIAS).isPresent() ){ return propName + AAIProperties.DB_ALIAS_SUFFIX; } return retPropName; } - + } diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java index 419743b..40d3027 100644 --- a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java +++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java @@ -227,7 +227,7 @@ public class SearchGraph { return response; } - private URI craftUriFromQueryParams(Loader loader, String startNodeType, List<String> startNodeKeyParams) throws UnsupportedEncodingException, IllegalArgumentException, UriBuilderException, AAIException { + private URI craftUriFromQueryParams(Loader loader, String startNodeType, List<String> startNodeKeyParams) throws UnsupportedEncodingException, AAIException { Introspector relationship = loader.introspectorFromName("relationship"); relationship.setValue("related-to", startNodeType); @@ -492,10 +492,9 @@ public class SearchGraph { * @return the edge label * @throws AAIException the AAI exception */ - public static String[] getEdgeLabel(String targetNodeType, String nodeType) throws AAIException{ + public static String[] getEdgeLabel(String targetNodeType, String nodeType) { Map<String, EdgeRule> rules = EdgeRules.getInstance().getEdgeRules(targetNodeType, nodeType); - String[] results = rules.keySet().toArray(new String[0]); - return results; + return rules.keySet().toArray(new String[0]); } @@ -512,7 +511,7 @@ public class SearchGraph { */ public Response runNamedQuery(String fromAppId, String transId, String queryParameters, DBConnectionType connectionType, - AAIExtensionMap aaiExtMap) throws JAXBException, AAIException { + AAIExtensionMap aaiExtMap) throws AAIException { Introspector inventoryItems; boolean success = true; @@ -548,7 +547,7 @@ public class SearchGraph { DynamicEntity qp = modelAndNamedQuerySearch.get("queryParameters"); String namedQueryUuid = null; if ((qp != null) && qp.isSet("namedQuery")) { - DynamicEntity namedQuery = (DynamicEntity) qp.get("namedQuery"); + DynamicEntity namedQuery = qp.get("namedQuery"); if (namedQuery.isSet("namedQueryUuid")) { namedQueryUuid = namedQuery.get("namedQueryUuid"); @@ -633,7 +632,7 @@ public class SearchGraph { public Response executeModelOperation(String fromAppId, String transId, String queryParameters, DBConnectionType connectionType, boolean isDelete, - AAIExtensionMap aaiExtMap) throws JAXBException, AAIException, DynamicException, UnsupportedEncodingException { + AAIExtensionMap aaiExtMap) throws AAIException, UnsupportedEncodingException { Response response; boolean success = true; TransactionalGraphEngine dbEngine = null; @@ -689,7 +688,7 @@ public class SearchGraph { DynamicEntity qp = modelAndNamedQuerySearch.get("queryParameters"); if (qp.isSet("model")) { - DynamicEntity model = (DynamicEntity) qp.get("model"); + DynamicEntity model = qp.get("model"); // on an old-style model object, the following 4 attrs were all present if (model.isSet("modelNameVersionId")) { @@ -714,7 +713,7 @@ public class SearchGraph { if (model.isSet("modelVers")) { // we know that this is new style, because modelVers was not an option // before v9 - DynamicEntity modelVers = (DynamicEntity) model.get("modelVers"); + DynamicEntity modelVers = model.get("modelVers"); if (modelVers.isSet("modelVer")) { List<DynamicEntity> modelVerList = modelVers.get("modelVer"); // if they send more than one, too bad, they get the first one @@ -735,7 +734,7 @@ public class SearchGraph { List<Map<String,Object>> startNodeFilterHash = new ArrayList<>(); - String resourceVersion = mapInstanceFilters((DynamicEntity)modelAndNamedQuerySearch.get("instanceFilters"), + String resourceVersion = mapInstanceFilters(modelAndNamedQuerySearch.get("instanceFilters"), startNodeFilterHash, jaxbContext); if (isDelete) { @@ -837,7 +836,7 @@ public class SearchGraph { return null; } @SuppressWarnings("unchecked") - List<DynamicEntity> instanceFilter = (ArrayList<DynamicEntity>)instanceFilters.get("instanceFilter"); + List<DynamicEntity> instanceFilter = instanceFilters.get("instanceFilter"); String resourceVersion = null; for (DynamicEntity instFilt : instanceFilter) { @@ -856,7 +855,7 @@ public class SearchGraph { if (anyEnt.isSet(propName)) { thisNodeFilterHash.put(nodeType + "." + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, propName), anyEnt.get(propName)); if (propName.equals("resourceVersion") && resourceVersion == null) { - resourceVersion = (String)anyEnt.get(propName); + resourceVersion = anyEnt.get(propName); } } } @@ -880,7 +879,7 @@ public class SearchGraph { return; } @SuppressWarnings("unchecked") - List<DynamicEntity> secondaryFilter = (ArrayList<DynamicEntity>)secondaryFilts.get("secondaryFilt"); + List<DynamicEntity> secondaryFilter = secondaryFilts.get("secondaryFilt"); for (DynamicEntity secondaryFilt : secondaryFilter) { List<DynamicEntity> any = secondaryFilt.get("any"); @@ -1062,8 +1061,8 @@ public class SearchGraph { String modelName = null; try { // Try to get the modelName if we can. Otherwise, do not fail, just return what we have already. - String modelInvariantIdLocal = (String)vert.<String>property("model-invariant-id-local").orElse(null); // this one points at a model - String modelVersionIdLocal = (String)vert.<String>property("model-version-id-local").orElse(null); // this one points at a model-ver + String modelInvariantIdLocal = vert.<String>property("model-invariant-id-local").orElse(null); // this one points at a model + String modelVersionIdLocal = vert.<String>property("model-version-id-local").orElse(null); // this one points at a model-ver if ( (modelInvariantIdLocal != null && modelVersionIdLocal != null) && (modelInvariantIdLocal.length() > 0 && modelVersionIdLocal.length() > 0) ) { diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java index 8ee0659..4139907 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java @@ -303,13 +303,11 @@ public class QueryConsumer extends RESTAPI { templateVars.add(missingRequiredQueryParams.toString()); } - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)).build(); - - return response; - } + } private Response createMessageInvalidQuerySection(String invalidQuery, HttpHeaders headers, UriInfo info, HttpServletRequest req) { AAIException e = new AAIException("AAI_3014"); @@ -320,13 +318,11 @@ public class QueryConsumer extends RESTAPI { templateVars.add(invalidQuery); } - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)).build(); - - return response; - } + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/retired/RetiredConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/retired/RetiredConsumer.java index fb97a63..aea9083 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/retired/RetiredConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/retired/RetiredConsumer.java @@ -132,11 +132,9 @@ public abstract class RetiredConsumer extends RESTAPI { templateVars.add(AAIConfig.get("aai.default.api.version", "")); } - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)).build(); - - return response; } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java index d102097..6831fb8 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java @@ -95,7 +95,7 @@ public abstract class GenericQueryProcessor { return resultVertices; } - public List<Object> execute(SubGraphStyle style) throws FileNotFoundException { + public List<Object> execute(SubGraphStyle style) { final List<Object> resultVertices; Pair<String, Map<String, Object>> tuple = this.createQuery(); diff --git a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java index eb0ad91..136b610 100644 --- a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java +++ b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java @@ -102,7 +102,7 @@ public class MakeNamedQuery { String modelInvariantId = meObject.getValue("model-invariant-id"); if (meObject.hasProperty("model-vers")) { Introspector modelVers = meObject.getWrappedValue("model-vers"); - List<Introspector> modelVerList = (List<Introspector>) modelVers.getWrappedListValue("model-ver"); + List<Introspector> modelVerList = modelVers.getWrappedListValue("model-ver"); for (Introspector modelVer : modelVerList) { List<Introspector> relList = new ArrayList<Introspector>(); @@ -175,7 +175,7 @@ public class MakeNamedQuery { } else { newNQElements = nqeObj.newIntrospectorInstanceOfProperty("named-query-elements"); nqeObj.setValue("named-query-elements", newNQElements.getUnderlyingObject()); - nqElementList = (List<Object>)newNQElements.getValue("named-query-element"); + nqElementList = newNQElements.getValue("named-query-element"); } newNQElement = loadNQElement(newNQElements, listOfRelationships); nqElementList.add(newNQElement.getUnderlyingObject()); @@ -200,7 +200,7 @@ public class MakeNamedQuery { Introspector newRelationshipList = newNqElement.getLoader().introspectorFromName("relationship-list"); newNqElement.setValue("relationship-list", newRelationshipList.getUnderlyingObject()); - List<Object> newRelationshipListList = (List<Object>)newRelationshipList.getValue("relationship"); + List<Object> newRelationshipListList = newRelationshipList.getValue("relationship"); for (Introspector rel : listOfRelationships) { newRelationshipListList.add(rel.getUnderlyingObject()); @@ -222,7 +222,7 @@ public class MakeNamedQuery { try { newRelationship = loader.introspectorFromName("relationship"); - List<Object> newRelationshipData = (List<Object>)newRelationship.getValue("relationship-data"); + List<Object> newRelationshipData = newRelationship.getValue("relationship-data"); newRelationship.setValue("related-to", "model"); diff --git a/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java index 3a11668..b979fb8 100644 --- a/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java +++ b/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java @@ -8,7 +8,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -83,28 +83,25 @@ public class JerseyConfiguration extends ResourceConfig { // Filter them based on the clazz that was passed in Set<Class<? extends ContainerRequestFilter>> filters = reflections.getSubTypesOf(ContainerRequestFilter.class); - // Check to ensure that each of the filter has the @Priority annotation and if not throw exception for (Class filterClass : filters) { if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); + throw new RuntimeException( + "Container filter " + filterClass.getName() + " does not have @Priority annotation"); } } // Turn the set back into a list List<Class<? extends ContainerRequestFilter>> filtersList = filters - .stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); + .stream() + .filter(f -> !(f.isAnnotationPresent(Profile.class) + && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) + ) + .collect(Collectors.toList()); // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); + filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()) + .compareTo(c2.getAnnotation(Priority.class).value())); // Then register this to the jersey application filtersList.forEach(this::register); @@ -115,29 +112,26 @@ public class JerseyConfiguration extends ResourceConfig { // Find all the classes within the interceptors package Reflections reflections = new Reflections("org.onap.aai.interceptors"); // Filter them based on the clazz that was passed in - Set<Class<? extends ContainerResponseFilter>> filters = reflections.getSubTypesOf(ContainerResponseFilter.class); - + Set<Class<? extends ContainerResponseFilter>> filters = reflections + .getSubTypesOf(ContainerResponseFilter.class); // Check to ensure that each of the filter has the @Priority annotation and if not throw exception for (Class filterClass : filters) { if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); + throw new RuntimeException( + "Container filter " + filterClass.getName() + " does not have @Priority annotation"); } } // Turn the set back into a list List<Class<? extends ContainerResponseFilter>> filtersList = filters.stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); + .filter(f -> !(f.isAnnotationPresent(Profile.class) + && !env.acceptsProfiles(f.getAnnotation(Profile.class).value()))) + .collect(Collectors.toList()); // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); + filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()) + .compareTo(c2.getAnnotation(Priority.class).value())); // Then register this to the jersey application filtersList.forEach(this::register); |