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 / entitytypeimplementations / relationshiptypeimplementations / RelationshipTypeImplementationResource.java
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
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypeimplementations.relationshiptypeimplementations;
13
14 import javax.ws.rs.Path;
15 import javax.ws.rs.core.Response;
16 import javax.xml.namespace.QName;
17
18 import org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId;
19 import org.eclipse.winery.model.tosca.TExtensibleElements;
20 import org.eclipse.winery.model.tosca.TImplementationArtifacts;
21 import org.eclipse.winery.model.tosca.TRelationshipTypeImplementation;
22 import org.eclipse.winery.repository.backend.BackendUtils;
23 import org.eclipse.winery.repository.resources.INodeTypeImplementationResourceOrRelationshipTypeImplementationResource;
24 import org.eclipse.winery.repository.resources.artifacts.ImplementationArtifactsResource;
25 import org.eclipse.winery.repository.resources.entitytypeimplementations.EntityTypeImplementationResource;
26
27 public class RelationshipTypeImplementationResource extends EntityTypeImplementationResource implements INodeTypeImplementationResourceOrRelationshipTypeImplementationResource {
28         
29         public RelationshipTypeImplementationResource(RelationshipTypeImplementationId id) {
30                 super(id);
31         }
32         
33         public TRelationshipTypeImplementation getRTI() {
34                 return (TRelationshipTypeImplementation) this.getElement();
35         }
36         
37         /**
38          * Even if both node type implementations and relationship type
39          * implementations have implementation artifacts, there is no common
40          * supertype. To avoid endless casts, we just implement the method here
41          */
42         @Path("implementationartifacts/")
43         public ImplementationArtifactsResource getImplementationArtifacts() {
44                 TImplementationArtifacts implementationArtifacts;
45                 implementationArtifacts = this.getRTI().getImplementationArtifacts();
46                 if (implementationArtifacts == null) {
47                         implementationArtifacts = new TImplementationArtifacts();
48                         this.getRTI().setImplementationArtifacts(implementationArtifacts);
49                 }
50                 return new ImplementationArtifactsResource(implementationArtifacts.getImplementationArtifact(), this);
51         }
52         
53         @Override
54         protected TExtensibleElements createNewElement() {
55                 return new TRelationshipTypeImplementation();
56         }
57         
58         @Override
59         protected void copyIdToFields() {
60                 this.getRTI().setTargetNamespace(this.getId().getNamespace().getDecoded());
61                 this.getRTI().setName(this.getId().getXmlId().getDecoded());
62         }
63         
64         @Override
65         public QName getType() {
66                 return this.getRTI().getRelationshipType();
67         }
68         
69         @Override
70         public Response setType(QName type) {
71                 this.getRTI().setRelationshipType(type);
72                 return BackendUtils.persist(this);
73         }
74         
75         @Override
76         public Response setType(String typeStr) {
77                 QName qname = QName.valueOf(typeStr);
78                 return this.setType(qname);
79         }
80         
81 }