89cb6d91eeb400350f7b60626cfaf8333781fbbe
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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.sdc.be.components.distribution.engine;
22
23 import java.util.List;
24 import java.util.Optional;
25
26 import org.openecomp.sdc.be.model.GroupDefinition;
27 import org.openecomp.sdc.be.model.GroupProperty;
28 import org.openecomp.sdc.common.api.Constants;
29
30 public class VfModuleArtifactPayload {
31         public VfModuleArtifactPayload(GroupDefinition group) {
32                 vfModuleModelName = group.getName();
33                 vfModuleModelInvariantUUID = group.getInvariantUUID();
34                 vfModuleModelVersion = group.getVersion();
35                 vfModuleModelUUID = group.getGroupUUID();
36                 vfModuleModelDescription = group.getDescription();
37
38                 artifacts = group.getArtifactsUuid();
39                 // Base Value is set from properties
40                 setBaseValue(group);
41
42         }
43
44         private void setBaseValue(GroupDefinition group) {
45                 if (group.getProperties() != null) {
46                         Optional<GroupProperty> findBaseProperty = group.getProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
47                         if (findBaseProperty.isPresent()) {
48                                 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
49                         }
50
51                 }
52         }
53
54         private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelDescription;
55         private Boolean isBase;
56         private List<String> artifacts;
57
58         public List<String> getArtifacts() {
59                 return artifacts;
60         }
61
62         public void setArtifacts(List<String> artifacts) {
63                 this.artifacts = artifacts;
64         }
65
66         public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
67                 Integer thisCounter = Integer.parseInt(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1]);
68                 Integer otherCounter = Integer.parseInt(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1]);
69                 return thisCounter.compareTo(otherCounter);
70         }
71 }