Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / artifacts / DeploymentArtifactsResource.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2013,2015 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.artifacts;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17
18 import org.eclipse.winery.model.tosca.TDeploymentArtifact;
19 import org.eclipse.winery.model.tosca.TDeploymentArtifacts;
20 import org.eclipse.winery.model.tosca.TNodeTemplate;
21 import org.eclipse.winery.repository.resources.INodeTemplateResourceOrNodeTypeImplementationResource;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class DeploymentArtifactsResource extends GenericArtifactsResource<DeploymentArtifactResource, TDeploymentArtifact> {
26         
27         private static final Logger logger = LoggerFactory.getLogger(DeploymentArtifactsResource.class);
28         
29         private List<TDeploymentArtifact> deploymentArtifacts;
30         
31         
32         public DeploymentArtifactsResource(List<TDeploymentArtifact> deploymentArtifact, INodeTemplateResourceOrNodeTypeImplementationResource res) {
33                 super(DeploymentArtifactResource.class, TDeploymentArtifact.class, deploymentArtifact, res);
34                 this.deploymentArtifacts = deploymentArtifact;
35         }
36         
37         /**
38          * Determines the list of DAs belonging to the given node template.
39          * 
40          * If no DAs are existing, an empty list is created in the model for the
41          * node template
42          */
43         private static List<TDeploymentArtifact> getDeploymentArtifacts(TNodeTemplate nodeTemplate) {
44                 TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
45                 final List<TDeploymentArtifact> res;
46                 if (deploymentArtifacts == null) {
47                         deploymentArtifacts = new TDeploymentArtifacts();
48                         nodeTemplate.setDeploymentArtifacts(deploymentArtifacts);
49                 }
50                 res = deploymentArtifacts.getDeploymentArtifact();
51                 return res;
52         }
53         
54         public DeploymentArtifactsResource(TNodeTemplate nodeTemplate, INodeTemplateResourceOrNodeTypeImplementationResource res) {
55                 this(DeploymentArtifactsResource.getDeploymentArtifacts(nodeTemplate), res);
56         }
57         
58         @Override
59         public Collection<DeploymentArtifactResource> getAllArtifactResources() {
60                 Collection<DeploymentArtifactResource> res = new ArrayList<DeploymentArtifactResource>(this.deploymentArtifacts.size());
61                 for (TDeploymentArtifact da : this.deploymentArtifacts) {
62                         DeploymentArtifactResource r = new DeploymentArtifactResource(da, this.deploymentArtifacts, this.res);
63                         res.add(r);
64                 }
65                 return res;
66         }
67         
68         @Override
69         public String getId(TDeploymentArtifact entity) {
70                 return entity.getName();
71         }
72         
73 }