Merge "Reorder modifiers"
[so.git] / asdc-controller / src / main / java / org / openecomp / mso / 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.openecomp.mso.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.openecomp.mso.asdc.client.ASDCConfiguration;
30 import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException;
31 import org.openecomp.mso.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) throws ArtifactInstallerException {
46
47                 vfModuleMetadata = vfmoduleMetadata;
48                 parentVfResource = vfParentResource;
49
50                 artifactsMap = new HashMap<>();
51
52                 for (String artifactUUID:this.vfModuleMetadata.getArtifacts()) {
53                         if (vfParentResource.getArtifactsMapByUUID().containsKey(artifactUUID)) {
54                                 this.addToStructure(vfParentResource.getArtifactsMapByUUID().get(artifactUUID));
55                         } else {
56                                 throw new ArtifactInstallerException("Artifact (UUID:"+artifactUUID+ ") referenced in the VFModule UUID list has not been downloaded, cancelling the Resource deployment");
57                         }
58                 }
59         }
60
61         private void addToStructure(VfModuleArtifact vfModuleArtifact) {
62
63                 if (artifactsMap.containsKey(vfModuleArtifact.getArtifactInfo().getArtifactType())) {
64                         artifactsMap.get(vfModuleArtifact.getArtifactInfo().getArtifactType()).add(vfModuleArtifact);
65
66                 } else {
67                         List<VfModuleArtifact> nestedList = new LinkedList<>();
68                         nestedList.add(vfModuleArtifact);
69
70                         artifactsMap.put(vfModuleArtifact.getArtifactInfo().getArtifactType(), nestedList);
71                 }
72         }
73
74         public List<VfModuleArtifact> getOrderedArtifactList() {
75
76                 List <VfModuleArtifact> artifactsList = new LinkedList<>();
77
78                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT));
79                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_ENV));
80                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
81
82                 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_NESTED)));
83
84                 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_ARTIFACT)));
85
86                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
87
88                 return null;
89         }
90
91         public IVfModuleData getVfModuleMetadata() {
92                 return vfModuleMetadata;
93         }
94
95         public VfResourceStructure getParentVfResource() {
96                 return parentVfResource;
97         }
98
99         public Map<String, List<VfModuleArtifact>> getArtifactsMap() {
100                 return artifactsMap;
101         }
102
103
104         public VfModule getCatalogVfModule() {
105                 return catalogVfModule;
106         }
107
108         public void setCatalogVfModule(VfModule catalogVfModule) {
109                 this.catalogVfModule = catalogVfModule;
110         }
111
112
113 }