@Test public void testCheckTemplateDefinition() throws Exception { field = class1.getDeclaredField("getDefinitions"); field.setAccessible(true); UserId userId = mock(UserId.class); NodeId nodeId = mock(NodeId.class); SubNode subNode = mock(SubNode.class); EndNode endNode = mock(EndNode.class); MatchItem matchItem = mock(MatchItem.class); ObjectId objectId = mock(ObjectId.class); AbstractFlow abstractFlow = mock(AbstractFlow.class); TemplateName templateName = mock(TemplateName.class); ParameterName parameterName = mock(ParameterName.class); AbstractOperation abstractOperation = mock(AbstractOperation.class); TemplateParameter templateParameter = mock(TemplateParameter.class); TemplateDefinition templateDefinition = mock(TemplateDefinition.class); AbstractNode abstractNode = mock(AbstractNode.class); AbstractIntents abstractIntents = mock(AbstractIntents.class); AbstractObjects abstractObjects = mock(AbstractObjects.class); AbstractOperations abstractOperations = mock(AbstractOperations.class); AbstractConnection abstractConnection = mock(AbstractConnection.class); GetDefinitions getDefinitions = mock(GetDefinitions.class); List<TemplateParameter> list = new ArrayList<TemplateParameter>(); List<AbstractNode> nodeList = new ArrayList<AbstractNode>(); List<SubNode> subNodeList = new ArrayList<SubNode>(); List<AbstractConnection> connectionList = new ArrayList<AbstractConnection>(); List<EndNode> endNodeList = new ArrayList<EndNode>(); List<AbstractFlow> flowList = new ArrayList<AbstractFlow>(); List<MatchItem> matchItemList = new ArrayList<MatchItem>(); List<AbstractOperation> operationList = new ArrayList<AbstractOperation>(); Map<TemplateName, TemplateDefinition> map = mock(Map.class); Map<NodeType, NodeDefinition> nodeDefinitions = mock(Map.class); Map<MatchItemName, MatchItemDefinition> matchItemDefinitionMap = mock(Map.class); list.add(templateParameter); nodeList.add(abstractNode); subNodeList.add(subNode); endNodeList.add(endNode); connectionList.add(abstractConnection); flowList.add(abstractFlow); matchItemList.add(matchItem); operationList.add(abstractOperation); when(tenantManage.getTempalteDefinition(userId)) .thenReturn(map) .thenReturn(map) .thenReturn(null); when(templateDefinition.getTemplateName()).thenReturn(templateName); when(map.containsKey(templateDefinition.getTemplateName())).thenReturn(true); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The template " + templateDefinition.getTemplateName().getValue() + " has been defined.")); verify(tenantManage, times(2)).getTempalteDefinition(userId); when(templateDefinition.getTemplateParameter()).thenReturn(list); when(templateParameter.getParameterName()).thenReturn(parameterName); when(templateParameter.getParameterValueType()).thenReturn(TemplateParameter.ParameterValueType.Int); when(templateDefinition.getAbstractIntents()).thenReturn(abstractIntents); when(abstractIntents.getAbstractObjects()).thenReturn(abstractObjects); when(abstractObjects.getAbstractNode()) .thenReturn(nodeList) .thenReturn(nodeList) .thenReturn(nodeList) .thenReturn(nodeList) .thenReturn(null) .thenReturn(nodeList) .thenReturn(nodeList) .thenReturn(null) .thenReturn(null) .thenReturn(null) .thenReturn(null) .thenReturn(nodeList) .thenReturn(nodeList); when(abstractNode.getNodeId()).thenReturn(nodeId); when(abstractNode.getSubNode()) .thenReturn(subNodeList) .thenReturn(subNodeList) .thenReturn(null); when(subNode.getNodeId()).thenReturn(null); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The sub node is not defined.")); verify(abstractNode,times(2)).getSubNode(); verify(abstractObjects,times(2)).getAbstractNode(); field.set(updateTemplateDefinition, getDefinitions); when(abstractNode.getNodeType()).thenReturn(mock(NodeType.class)); when(getDefinitions.getNodeDefinition()).thenReturn(nodeDefinitions); when(nodeDefinitions.containsKey(any(NodeType.class))).thenReturn(false); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The node type " + abstractNode.getNodeType().getValue() + " is not defined.")); verify(abstractNode,times(3)).getSubNode(); verify(abstractObjects, times(4)).getAbstractNode(); when(abstractObjects.getAbstractConnection()) .thenReturn(connectionList) .thenReturn(connectionList) .thenReturn(connectionList) .thenReturn(connectionList) .thenReturn(null) .thenReturn(null) .thenReturn(connectionList) .thenReturn(connectionList); when(abstractConnection.getEndNode()).thenReturn(endNodeList); when(endNode.getNodeId()).thenReturn(null); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The end node is not exist.")); verify(abstractObjects,times(7)).getAbstractNode(); verify(abstractObjects,times(2)).getAbstractConnection(); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("There are no end nodes exist.")); verify(abstractObjects, times(9)).getAbstractNode(); verify(abstractObjects, times(4)).getAbstractConnection(); when(abstractObjects.getAbstractFlow()) .thenReturn(flowList) .thenReturn(flowList) .thenReturn(null) .thenReturn(flowList) .thenReturn(flowList); when(getDefinitions.getMatchItemDefinition()).thenReturn(matchItemDefinitionMap); when(abstractFlow.getMatchItem()).thenReturn(matchItemList); when(matchItem.getMatchItemName()).thenReturn(mock(MatchItemName.class)); when(matchItemDefinitionMap.containsKey(any(MatchItemName.class))).thenReturn(false); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The match item " + matchItem.getMatchItemName().getValue() + " is not defined.")); verify(abstractObjects, times(10)).getAbstractNode(); verify(abstractObjects, times(5)).getAbstractConnection(); verify(abstractObjects, times(2)).getAbstractFlow(); when(abstractIntents.getAbstractOperations()).thenReturn(abstractOperations); when(abstractOperations.getAbstractOperation()) .thenReturn(operationList) .thenReturn(operationList) .thenReturn(null); when(abstractOperation.getTargetObject()).thenReturn(objectId); Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The target is not exist.")); verify(abstractObjects, times(13)).getAbstractNode(); verify(abstractObjects, times(8)).getAbstractConnection(); verify(abstractObjects, times(5)).getAbstractFlow(); }
public String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition){ String errorInfo = null; Boolean templateDefined = false; if (tenantManage.getTempalteDefinition(userId)!=null){ if (tenantManage.getTempalteDefinition(userId).containsKey(templateDefinition.getTemplateName())){ templateDefined = true; } } if (templateDefined){ return "The template " + templateDefinition.getTemplateName().getValue() + " has been defined."; } else { List<TemplateParameter> list = templateDefinition.getTemplateParameter(); HashMap<ParameterName, TemplateParameter.ParameterValueType> map = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); for (TemplateParameter templateParameter : list){ map.put(templateParameter.getParameterName(), templateParameter.getParameterValueType()); } AbstractIntents abstractIntents = templateDefinition.getAbstractIntents(); if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (AbstractNode node : nodeMap.values()){ if (node.getSubNode()!=null){ for (SubNode subNode : node.getSubNode()){ if (!nodeMap.containsKey(subNode.getNodeId())){ return "The sub node is not defined."; } } } errorInfo = checkNodeTemplate(node,map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); for (AbstractConnection connection : connectionList){ List<EndNode> endNodeList = connection.getEndNode(); if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (EndNode endNode : endNodeList){ if (!nodeMap.containsKey(endNode.getNodeId())){ return "The end node is not exist."; } } } else { return "There are no end nodes exist."; } errorInfo = checkConnectionTemplate(connection, map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null){ List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); for (AbstractFlow flow : flowList){ errorInfo = checkFlowTemplate(flow,map); if (errorInfo!=null){ return errorInfo; } } } } if (abstractIntents.getAbstractOperations()!=null){ if (abstractIntents.getAbstractOperations().getAbstractOperation()!=null){ List<AbstractOperation> operationList = abstractIntents.getAbstractOperations().getAbstractOperation(); for (AbstractOperation operation : operationList){ ObjectId objectId = operation.getTargetObject(); Boolean targetExist = false; if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null) { List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId, AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList) { nodeMap.put(node.getNodeId(), node); } if (nodeMap.containsKey(new NodeId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); Map<ConnectionId, AbstractConnection> connectionMap = new HashMap<ConnectionId, AbstractConnection>(); for (AbstractConnection connection : connectionList){ connectionMap.put(connection.getConnectionId(),connection); } if (connectionMap.containsKey(new ConnectionId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null) { List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); Map<FlowId, AbstractFlow> flowMap = new HashMap<FlowId, AbstractFlow>(); for (AbstractFlow flow : flowList){ flowMap.put(flow.getFlowId(),flow); } if (flowMap.containsKey(new FlowId(objectId))){ targetExist = true; } } } else { return "The target is not exist."; } if (!targetExist){ return "The target is not exist."; } errorInfo = checkOperationTemplate(operation, map); if (errorInfo!=null){ return errorInfo; } } } } if (errorInfo == null){ tenantManage.setTemplateDefinition(userId,templateDefinition.getTemplateName(),templateDefinition); } } return errorInfo; }
UpdateTemplateDefinition { public String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition){ String errorInfo = null; Boolean templateDefined = false; if (tenantManage.getTempalteDefinition(userId)!=null){ if (tenantManage.getTempalteDefinition(userId).containsKey(templateDefinition.getTemplateName())){ templateDefined = true; } } if (templateDefined){ return "The template " + templateDefinition.getTemplateName().getValue() + " has been defined."; } else { List<TemplateParameter> list = templateDefinition.getTemplateParameter(); HashMap<ParameterName, TemplateParameter.ParameterValueType> map = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); for (TemplateParameter templateParameter : list){ map.put(templateParameter.getParameterName(), templateParameter.getParameterValueType()); } AbstractIntents abstractIntents = templateDefinition.getAbstractIntents(); if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (AbstractNode node : nodeMap.values()){ if (node.getSubNode()!=null){ for (SubNode subNode : node.getSubNode()){ if (!nodeMap.containsKey(subNode.getNodeId())){ return "The sub node is not defined."; } } } errorInfo = checkNodeTemplate(node,map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); for (AbstractConnection connection : connectionList){ List<EndNode> endNodeList = connection.getEndNode(); if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (EndNode endNode : endNodeList){ if (!nodeMap.containsKey(endNode.getNodeId())){ return "The end node is not exist."; } } } else { return "There are no end nodes exist."; } errorInfo = checkConnectionTemplate(connection, map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null){ List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); for (AbstractFlow flow : flowList){ errorInfo = checkFlowTemplate(flow,map); if (errorInfo!=null){ return errorInfo; } } } } if (abstractIntents.getAbstractOperations()!=null){ if (abstractIntents.getAbstractOperations().getAbstractOperation()!=null){ List<AbstractOperation> operationList = abstractIntents.getAbstractOperations().getAbstractOperation(); for (AbstractOperation operation : operationList){ ObjectId objectId = operation.getTargetObject(); Boolean targetExist = false; if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null) { List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId, AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList) { nodeMap.put(node.getNodeId(), node); } if (nodeMap.containsKey(new NodeId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); Map<ConnectionId, AbstractConnection> connectionMap = new HashMap<ConnectionId, AbstractConnection>(); for (AbstractConnection connection : connectionList){ connectionMap.put(connection.getConnectionId(),connection); } if (connectionMap.containsKey(new ConnectionId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null) { List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); Map<FlowId, AbstractFlow> flowMap = new HashMap<FlowId, AbstractFlow>(); for (AbstractFlow flow : flowList){ flowMap.put(flow.getFlowId(),flow); } if (flowMap.containsKey(new FlowId(objectId))){ targetExist = true; } } } else { return "The target is not exist."; } if (!targetExist){ return "The target is not exist."; } errorInfo = checkOperationTemplate(operation, map); if (errorInfo!=null){ return errorInfo; } } } } if (errorInfo == null){ tenantManage.setTemplateDefinition(userId,templateDefinition.getTemplateName(),templateDefinition); } } return errorInfo; } }
UpdateTemplateDefinition { public String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition){ String errorInfo = null; Boolean templateDefined = false; if (tenantManage.getTempalteDefinition(userId)!=null){ if (tenantManage.getTempalteDefinition(userId).containsKey(templateDefinition.getTemplateName())){ templateDefined = true; } } if (templateDefined){ return "The template " + templateDefinition.getTemplateName().getValue() + " has been defined."; } else { List<TemplateParameter> list = templateDefinition.getTemplateParameter(); HashMap<ParameterName, TemplateParameter.ParameterValueType> map = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); for (TemplateParameter templateParameter : list){ map.put(templateParameter.getParameterName(), templateParameter.getParameterValueType()); } AbstractIntents abstractIntents = templateDefinition.getAbstractIntents(); if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (AbstractNode node : nodeMap.values()){ if (node.getSubNode()!=null){ for (SubNode subNode : node.getSubNode()){ if (!nodeMap.containsKey(subNode.getNodeId())){ return "The sub node is not defined."; } } } errorInfo = checkNodeTemplate(node,map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); for (AbstractConnection connection : connectionList){ List<EndNode> endNodeList = connection.getEndNode(); if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (EndNode endNode : endNodeList){ if (!nodeMap.containsKey(endNode.getNodeId())){ return "The end node is not exist."; } } } else { return "There are no end nodes exist."; } errorInfo = checkConnectionTemplate(connection, map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null){ List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); for (AbstractFlow flow : flowList){ errorInfo = checkFlowTemplate(flow,map); if (errorInfo!=null){ return errorInfo; } } } } if (abstractIntents.getAbstractOperations()!=null){ if (abstractIntents.getAbstractOperations().getAbstractOperation()!=null){ List<AbstractOperation> operationList = abstractIntents.getAbstractOperations().getAbstractOperation(); for (AbstractOperation operation : operationList){ ObjectId objectId = operation.getTargetObject(); Boolean targetExist = false; if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null) { List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId, AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList) { nodeMap.put(node.getNodeId(), node); } if (nodeMap.containsKey(new NodeId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); Map<ConnectionId, AbstractConnection> connectionMap = new HashMap<ConnectionId, AbstractConnection>(); for (AbstractConnection connection : connectionList){ connectionMap.put(connection.getConnectionId(),connection); } if (connectionMap.containsKey(new ConnectionId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null) { List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); Map<FlowId, AbstractFlow> flowMap = new HashMap<FlowId, AbstractFlow>(); for (AbstractFlow flow : flowList){ flowMap.put(flow.getFlowId(),flow); } if (flowMap.containsKey(new FlowId(objectId))){ targetExist = true; } } } else { return "The target is not exist."; } if (!targetExist){ return "The target is not exist."; } errorInfo = checkOperationTemplate(operation, map); if (errorInfo!=null){ return errorInfo; } } } } if (errorInfo == null){ tenantManage.setTemplateDefinition(userId,templateDefinition.getTemplateName(),templateDefinition); } } return errorInfo; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); }
UpdateTemplateDefinition { public String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition){ String errorInfo = null; Boolean templateDefined = false; if (tenantManage.getTempalteDefinition(userId)!=null){ if (tenantManage.getTempalteDefinition(userId).containsKey(templateDefinition.getTemplateName())){ templateDefined = true; } } if (templateDefined){ return "The template " + templateDefinition.getTemplateName().getValue() + " has been defined."; } else { List<TemplateParameter> list = templateDefinition.getTemplateParameter(); HashMap<ParameterName, TemplateParameter.ParameterValueType> map = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); for (TemplateParameter templateParameter : list){ map.put(templateParameter.getParameterName(), templateParameter.getParameterValueType()); } AbstractIntents abstractIntents = templateDefinition.getAbstractIntents(); if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (AbstractNode node : nodeMap.values()){ if (node.getSubNode()!=null){ for (SubNode subNode : node.getSubNode()){ if (!nodeMap.containsKey(subNode.getNodeId())){ return "The sub node is not defined."; } } } errorInfo = checkNodeTemplate(node,map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); for (AbstractConnection connection : connectionList){ List<EndNode> endNodeList = connection.getEndNode(); if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (EndNode endNode : endNodeList){ if (!nodeMap.containsKey(endNode.getNodeId())){ return "The end node is not exist."; } } } else { return "There are no end nodes exist."; } errorInfo = checkConnectionTemplate(connection, map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null){ List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); for (AbstractFlow flow : flowList){ errorInfo = checkFlowTemplate(flow,map); if (errorInfo!=null){ return errorInfo; } } } } if (abstractIntents.getAbstractOperations()!=null){ if (abstractIntents.getAbstractOperations().getAbstractOperation()!=null){ List<AbstractOperation> operationList = abstractIntents.getAbstractOperations().getAbstractOperation(); for (AbstractOperation operation : operationList){ ObjectId objectId = operation.getTargetObject(); Boolean targetExist = false; if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null) { List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId, AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList) { nodeMap.put(node.getNodeId(), node); } if (nodeMap.containsKey(new NodeId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); Map<ConnectionId, AbstractConnection> connectionMap = new HashMap<ConnectionId, AbstractConnection>(); for (AbstractConnection connection : connectionList){ connectionMap.put(connection.getConnectionId(),connection); } if (connectionMap.containsKey(new ConnectionId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null) { List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); Map<FlowId, AbstractFlow> flowMap = new HashMap<FlowId, AbstractFlow>(); for (AbstractFlow flow : flowList){ flowMap.put(flow.getFlowId(),flow); } if (flowMap.containsKey(new FlowId(objectId))){ targetExist = true; } } } else { return "The target is not exist."; } if (!targetExist){ return "The target is not exist."; } errorInfo = checkOperationTemplate(operation, map); if (errorInfo!=null){ return errorInfo; } } } } if (errorInfo == null){ tenantManage.setTemplateDefinition(userId,templateDefinition.getTemplateName(),templateDefinition); } } return errorInfo; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition); }
UpdateTemplateDefinition { public String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition){ String errorInfo = null; Boolean templateDefined = false; if (tenantManage.getTempalteDefinition(userId)!=null){ if (tenantManage.getTempalteDefinition(userId).containsKey(templateDefinition.getTemplateName())){ templateDefined = true; } } if (templateDefined){ return "The template " + templateDefinition.getTemplateName().getValue() + " has been defined."; } else { List<TemplateParameter> list = templateDefinition.getTemplateParameter(); HashMap<ParameterName, TemplateParameter.ParameterValueType> map = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); for (TemplateParameter templateParameter : list){ map.put(templateParameter.getParameterName(), templateParameter.getParameterValueType()); } AbstractIntents abstractIntents = templateDefinition.getAbstractIntents(); if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (AbstractNode node : nodeMap.values()){ if (node.getSubNode()!=null){ for (SubNode subNode : node.getSubNode()){ if (!nodeMap.containsKey(subNode.getNodeId())){ return "The sub node is not defined."; } } } errorInfo = checkNodeTemplate(node,map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); for (AbstractConnection connection : connectionList){ List<EndNode> endNodeList = connection.getEndNode(); if (abstractIntents.getAbstractObjects().getAbstractNode()!=null){ List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId,AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList){ nodeMap.put(node.getNodeId(),node); } for (EndNode endNode : endNodeList){ if (!nodeMap.containsKey(endNode.getNodeId())){ return "The end node is not exist."; } } } else { return "There are no end nodes exist."; } errorInfo = checkConnectionTemplate(connection, map); if (errorInfo!=null){ return errorInfo; } } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null){ List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); for (AbstractFlow flow : flowList){ errorInfo = checkFlowTemplate(flow,map); if (errorInfo!=null){ return errorInfo; } } } } if (abstractIntents.getAbstractOperations()!=null){ if (abstractIntents.getAbstractOperations().getAbstractOperation()!=null){ List<AbstractOperation> operationList = abstractIntents.getAbstractOperations().getAbstractOperation(); for (AbstractOperation operation : operationList){ ObjectId objectId = operation.getTargetObject(); Boolean targetExist = false; if (abstractIntents.getAbstractObjects()!=null){ if (abstractIntents.getAbstractObjects().getAbstractNode()!=null) { List<AbstractNode> nodeList = abstractIntents.getAbstractObjects().getAbstractNode(); Map<NodeId, AbstractNode> nodeMap = new HashMap<NodeId, AbstractNode>(); for (AbstractNode node : nodeList) { nodeMap.put(node.getNodeId(), node); } if (nodeMap.containsKey(new NodeId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractConnection()!=null){ List<AbstractConnection> connectionList = abstractIntents.getAbstractObjects().getAbstractConnection(); Map<ConnectionId, AbstractConnection> connectionMap = new HashMap<ConnectionId, AbstractConnection>(); for (AbstractConnection connection : connectionList){ connectionMap.put(connection.getConnectionId(),connection); } if (connectionMap.containsKey(new ConnectionId(objectId))){ targetExist = true; } } if (abstractIntents.getAbstractObjects().getAbstractFlow()!=null) { List<AbstractFlow> flowList = abstractIntents.getAbstractObjects().getAbstractFlow(); Map<FlowId, AbstractFlow> flowMap = new HashMap<FlowId, AbstractFlow>(); for (AbstractFlow flow : flowList){ flowMap.put(flow.getFlowId(),flow); } if (flowMap.containsKey(new FlowId(objectId))){ targetExist = true; } } } else { return "The target is not exist."; } if (!targetExist){ return "The target is not exist."; } errorInfo = checkOperationTemplate(operation, map); if (errorInfo!=null){ return errorInfo; } } } } if (errorInfo == null){ tenantManage.setTemplateDefinition(userId,templateDefinition.getTemplateName(),templateDefinition); } } return errorInfo; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition);  }