7c9e000a444e6295ac3016b90e48a06374739a57
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21
22 import org.onap.so.bpmn.common.BuildingBlockExecution;
23 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
24 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
25 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
26 import org.onap.so.db.catalog.beans.OrchestrationStatus;
27 import org.onap.so.logger.MsoLogger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public class AssignNetwork {
33
34         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
35                         AssignNetwork.class);
36
37         @Autowired
38         private ExtractPojosForBB extractPojosForBB;
39         
40         /**
41          * Check if network was found by name
42          * @param execution
43          * @return
44          */
45         public boolean networkFoundByName(BuildingBlockExecution execution) {
46                 boolean networkFound = false;
47                 try {
48                         L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,
49                                         execution.getLookupMap().get(ResourceKey.NETWORK_ID));
50
51                         if (!OrchestrationStatus.PRECREATED.equals(l3network.getOrchestrationStatus())){
52                                 networkFound = true;
53                                 msoLogger.debug("network found in NOT PRECREATED status");
54                         }
55                 } catch (Exception ex) {
56                         // return false if no network present
57                 }
58                 return networkFound;
59         }
60 }