1 /*******************************************************************************
2 * Copyright (c) 2012-2013 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
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.artifacts;
14 import java.util.List;
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.TImplementationArtifacts.ImplementationArtifact;
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;
23 public class ImplementationArtifactResource extends GenericArtifactResource<ImplementationArtifact> {
25 private ImplementationArtifact a;
29 * Converts the given artifactId to an ImplementArtifact.
31 * <em>SIDE EFFECT</em> Adds it to the implementationArtifacts list if it
34 private static ImplementationArtifact getImplementationArtifact(String artifactId, List<ImplementationArtifact> implementationArtifacts) {
35 if (artifactId == null) {
36 throw new IllegalArgumentException("artifactId must not be null");
38 if (implementationArtifacts == null) {
39 throw new IllegalArgumentException("implementationArtifacts must not be null");
41 for (ImplementationArtifact ia : implementationArtifacts) {
42 // ia.getName() might be null as TOSCA COS01 does not forsee a name on the implementation artifact
43 // Therefore, we begin the test with "artifactId"
44 if (artifactId.equals(ia.getName())) {
48 // IA does not exist in list
49 ImplementationArtifact ia = new ImplementationArtifact();
50 ia.setName(artifactId);
51 implementationArtifacts.add(ia);
55 public ImplementationArtifactResource(String artifactId, List<ImplementationArtifact> implementationArtifacts, IPersistable res) {
56 this(ImplementationArtifactResource.getImplementationArtifact(artifactId, implementationArtifacts), implementationArtifacts, res);
59 public ImplementationArtifactResource(IIdDetermination<ImplementationArtifact> idDetermination, ImplementationArtifact o, int idx, List<ImplementationArtifact> list, IPersistable res) {
60 super(idDetermination, o, idx, list, res);
64 public ImplementationArtifactResource(ImplementationArtifact a, List<ImplementationArtifact> implementationArtifacts, IPersistable res) {
65 this(new IIdDetermination<ImplementationArtifact>() {
68 public String getId(ImplementationArtifact e) {
71 }, a, implementationArtifacts.indexOf(a), implementationArtifacts, res);
74 public ImplementationArtifact getImplementationArtifact() {
79 public void setArtifactType(ArtifactTypeId artifactTypeId) {
80 this.getImplementationArtifact().setArtifactType(artifactTypeId.getQName());
81 BackendUtils.persist(this.res);
85 public void setArtifactTemplate(ArtifactTemplateId artifactTemplateId) {
86 this.getImplementationArtifact().setArtifactRef(artifactTemplateId.getQName());
87 BackendUtils.persist(this.res);
91 public ImplementationArtifact getA() {