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 / DeploymentArtifactResource.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.List;
15
16 import org.eclipse.winery.common.ids.definitions.ArtifactTemplateId;
17 import org.eclipse.winery.common.ids.definitions.ArtifactTypeId;
18 import org.eclipse.winery.model.tosca.TDeploymentArtifact;
19 import org.eclipse.winery.repository.backend.BackendUtils;
20 import org.eclipse.winery.repository.resources._support.IPersistable;
21 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
22
23 public class DeploymentArtifactResource extends GenericArtifactResource<TDeploymentArtifact> {
24         
25         private final TDeploymentArtifact a;
26         
27         
28         /**
29          * Converts the given artifactId to an DeploymentArtifact.
30          * 
31          * <em>SIDE EFFECT</em> Adds it to the DeploymentArtifacts list if it does
32          * not yet exist.
33          */
34         private static TDeploymentArtifact getDeploymentArtifact(String artifactId, List<TDeploymentArtifact> deploymentArtifacts) {
35                 for (TDeploymentArtifact ia : deploymentArtifacts) {
36                         if (ia.getName().equals(artifactId)) {
37                                 return ia;
38                         }
39                 }
40                 // DA does not exist in list
41                 TDeploymentArtifact ia = new TDeploymentArtifact();
42                 ia.setName(artifactId);
43                 deploymentArtifacts.add(ia);
44                 return ia;
45         }
46         
47         public DeploymentArtifactResource(String artifactId, List<TDeploymentArtifact> deploymentArtifacts, IPersistable res) {
48                 this(DeploymentArtifactResource.getDeploymentArtifact(artifactId, deploymentArtifacts), deploymentArtifacts, res);
49         }
50         
51         public DeploymentArtifactResource(IIdDetermination<TDeploymentArtifact> idDetermination, TDeploymentArtifact o, int idx, List<TDeploymentArtifact> list, IPersistable res) {
52                 super(idDetermination, o, idx, list, res);
53                 this.a = o;
54         }
55         
56         public DeploymentArtifactResource(TDeploymentArtifact deploymentArtifact, List<TDeploymentArtifact> deploymentArtifacts, IPersistable res) {
57                 this(new IIdDetermination<TDeploymentArtifact>() {
58                         
59                         @Override
60                         public String getId(TDeploymentArtifact e) {
61                                 return e.getName();
62                         }
63                 }, deploymentArtifact, deploymentArtifacts.indexOf(deploymentArtifact), deploymentArtifacts, res);
64         }
65         
66         public TDeploymentArtifact getDeploymentArtifact() {
67                 return this.a;
68         }
69         
70         @Override
71         public void setArtifactType(ArtifactTypeId artifactTypeId) {
72                 this.getDeploymentArtifact().setArtifactType(artifactTypeId.getQName());
73                 BackendUtils.persist(this.res);
74         }
75         
76         @Override
77         public void setArtifactTemplate(ArtifactTemplateId artifactTemplateId) {
78                 this.getDeploymentArtifact().setArtifactRef(artifactTemplateId.getQName());
79                 BackendUtils.persist(this.res);
80         }
81         
82         @Override
83         public TDeploymentArtifact getA() {
84                 return this.a;
85         }
86         
87 }