Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / VfModuleStructure.java
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
21 package org.onap.so.asdc.installer;
22
23
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28 import org.onap.sdc.api.notification.IVfModuleMetadata;
29 import org.onap.so.asdc.client.ASDCConfiguration;
30 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
31 import org.onap.so.db.catalog.beans.VfModule;
32
33 public final class VfModuleStructure {
34
35     private final IVfModuleData vfModuleMetadata;
36
37     private final VfResourceStructure parentVfResource;
38
39     private VfModule catalogVfModule;
40     /**
41      * The list of artifact existing in this resource hashed by artifactType.
42      */
43     private final Map<String, List<VfModuleArtifact>> artifactsMap;
44
45     public VfModuleStructure(VfResourceStructure vfParentResource, IVfModuleData vfmoduleMetadata)
46             throws ArtifactInstallerException {
47
48         vfModuleMetadata = vfmoduleMetadata;
49         parentVfResource = vfParentResource;
50
51         artifactsMap = new HashMap<>();
52
53         for (String artifactUUID : this.vfModuleMetadata.getArtifacts()) {
54             if (vfParentResource.getArtifactsMapByUUID().containsKey(artifactUUID)) {
55                 this.addToStructure(vfParentResource.getArtifactsMapByUUID().get(artifactUUID));
56             } else {
57                 throw new ArtifactInstallerException("Artifact (UUID:" + artifactUUID
58                         + ") referenced in the VFModule UUID list has not been downloaded, cancelling the Resource deployment");
59             }
60         }
61     }
62
63     private void addToStructure(VfModuleArtifact vfModuleArtifact) {
64
65         if (artifactsMap.containsKey(vfModuleArtifact.getArtifactInfo().getArtifactType())) {
66             artifactsMap.get(vfModuleArtifact.getArtifactInfo().getArtifactType()).add(vfModuleArtifact);
67
68         } else {
69             List<VfModuleArtifact> nestedList = new LinkedList<>();
70             nestedList.add(vfModuleArtifact);
71
72             artifactsMap.put(vfModuleArtifact.getArtifactInfo().getArtifactType(), nestedList);
73         }
74     }
75
76     public List<VfModuleArtifact> getOrderedArtifactList() {
77
78         List<VfModuleArtifact> artifactsList = new LinkedList<>();
79
80         artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT));
81         artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_ENV));
82         artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
83
84         artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_NESTED)));
85
86         artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_ARTIFACT)));
87
88         artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
89
90         return null;
91     }
92
93     public IVfModuleData getVfModuleMetadata() {
94         return vfModuleMetadata;
95     }
96
97     public VfResourceStructure getParentVfResource() {
98         return parentVfResource;
99     }
100
101     public Map<String, List<VfModuleArtifact>> getArtifactsMap() {
102         return artifactsMap;
103     }
104
105
106     public VfModule getCatalogVfModule() {
107         return catalogVfModule;
108     }
109
110     public void setCatalogVfModule(VfModule catalogVfModule) {
111         this.catalogVfModule = catalogVfModule;
112     }
113
114
115 }