Change the way of fetching data from datastore and write user's intents into datastor...
[nemo.git] / nemo-impl / src / main / java / org / opendaylight / nemo / user / vnspacemanager / structurestyle / deleteintent / DeleteFlow.java
1 /*\r
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;\r
9 \r
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
11 import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
12 import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;\r
16 \r
17 /**\r
18  * Created by z00293636 on 2015/9/2.\r
19  */\r
20 public class DeleteFlow {\r
21     private TenantManage tenantManage;\r
22 \r
23     public DeleteFlow(DataBroker dataBroker, TenantManage tenantManage){\r
24         this.tenantManage = tenantManage;\r
25     }\r
26 \r
27     public String DeleteFlowHandling(UserId userId, FlowId flowId){\r
28         Boolean flowExist = false;\r
29 \r
30         if (tenantManage.getFlow(userId)!=null){\r
31             if (tenantManage.getFlow(userId).containsKey(flowId)){\r
32                 flowExist = true;\r
33                 tenantManage.getFlow(userId).remove(flowId);\r
34                 tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,flowId.getValue()));\r
35             }\r
36         }\r
37         if (tenantManage.getFlowDataStore(userId)!=null){\r
38             if (tenantManage.getFlowDataStore(userId).containsKey(flowId)){\r
39                 flowExist = true;\r
40                 tenantManage.setUserDeleteIntent(userId, NEMOConstants.flow, flowId.getValue());\r
41                 tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,flowId.getValue()));\r
42             }\r
43         }\r
44 \r
45         if (!flowExist){\r
46             return "The flow instance " +flowId.getValue()+" is not exist.";\r
47         }\r
48         else {\r
49             if (tenantManage.getOperation(userId)!=null){\r
50                 for (Operation operation : tenantManage.getOperation(userId).values()){\r
51                     if (operation.getTargetObject().getValue().equals(flowId.getValue())){\r
52                         tenantManage.getOperation(userId).remove(operation.getOperationId());\r
53                         tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,operation.getOperationId().getValue()));\r
54                     }\r
55                 }\r
56             }\r
57             if (tenantManage.getOperationDataStore(userId)!=null){\r
58                 for (Operation operation : tenantManage.getOperationDataStore(userId).values()){\r
59                     if (operation.getTargetObject().getValue().equals(flowId.getValue())){\r
60                         tenantManage.setUserDeleteIntent(userId, NEMOConstants.operation, operation.getOperationId().getValue());\r
61                         tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,operation.getOperationId().getValue()));\r
62                     }\r
63                 }\r
64             }\r
65         }\r
66         return null;\r
67     }\r
68 }\r