6c573a559c8c701ddb4ffa395daf4b04f44d602f
[vfc/nfvo/wfengine.git] /
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.entitytypes.nodetypes;
13
14 import javax.ws.rs.Path;
15
16 import org.eclipse.winery.model.tosca.TExtensibleElements;
17 import org.eclipse.winery.model.tosca.TNodeType;
18 import org.eclipse.winery.model.tosca.TNodeType.CapabilityDefinitions;
19 import org.eclipse.winery.model.tosca.TNodeType.Interfaces;
20 import org.eclipse.winery.model.tosca.TNodeType.RequirementDefinitions;
21 import org.eclipse.winery.model.tosca.TTopologyElementInstanceStates;
22 import org.eclipse.winery.common.ids.definitions.NodeTypeId;
23 import org.eclipse.winery.repository.resources.entitytypes.InstanceStatesResource;
24 import org.eclipse.winery.repository.resources.entitytypes.TopologyGraphElementEntityTypeResource;
25 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs.CapabilityDefinitionsResource;
26 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.reqandcapdefs.RequirementDefinitionsResource;
27 import org.eclipse.winery.repository.resources.interfaces.InterfacesResource;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class NodeTypeResource extends TopologyGraphElementEntityTypeResource {
32         
33         private static final Logger logger = LoggerFactory.getLogger(NodeTypeResource.class);
34         
35         
36         public NodeTypeResource(NodeTypeId id) {
37                 super(id);
38         }
39         
40         /**
41          * Convenience method to avoid casting at the caller's side.
42          */
43         public TNodeType getNodeType() {
44                 return (TNodeType) this.getElement();
45         }
46         
47         /** sub-resources **/
48         
49         @Path("implementations/")
50         public ImplementationsOfOneNodeTypeResource getImplementations() {
51                 return new ImplementationsOfOneNodeTypeResource((NodeTypeId) this.id);
52         }
53         
54         @Path("instancestates/")
55         public InstanceStatesResource getInstanceStatesResource() {
56                 TTopologyElementInstanceStates instanceStates = this.getNodeType().getInstanceStates();
57                 if (instanceStates == null) {
58                         // if an explicit (empty) list does not exist, create it
59                         instanceStates = new TTopologyElementInstanceStates();
60                         this.getNodeType().setInstanceStates(instanceStates);
61                 }
62                 return new InstanceStatesResource(instanceStates, this);
63         }
64         
65         @Path("interfaces/")
66         public InterfacesResource getInterfaces() {
67                 Interfaces interfaces = this.getNodeType().getInterfaces();
68                 if (interfaces == null) {
69                         interfaces = new Interfaces();
70                         this.getNodeType().setInterfaces(interfaces);
71                 }
72                 return new InterfacesResource(null, interfaces.getInterface(), this);
73         }
74         
75         @Path("requirementdefinitions/")
76         public RequirementDefinitionsResource getRequirementDefinitions() {
77                 RequirementDefinitions definitions = this.getNodeType().getRequirementDefinitions();
78                 if (definitions == null) {
79                         definitions = new RequirementDefinitions();
80                         this.getNodeType().setRequirementDefinitions(definitions);
81                 }
82                 return new RequirementDefinitionsResource(this, definitions.getRequirementDefinition());
83         }
84         
85         @Path("capabilitydefinitions/")
86         public CapabilityDefinitionsResource getCapabilityDefinitions() {
87                 CapabilityDefinitions definitions = this.getNodeType().getCapabilityDefinitions();
88                 if (definitions == null) {
89                         definitions = new CapabilityDefinitions();
90                         this.getNodeType().setCapabilityDefinitions(definitions);
91                 }
92                 return new CapabilityDefinitionsResource(this, definitions.getCapabilityDefinition());
93         }
94         
95         @Path("visualappearance/")
96         public VisualAppearanceResource getVisualAppearanceResource() {
97                 return new VisualAppearanceResource(this, this.getElement().getOtherAttributes(), (NodeTypeId) this.id);
98         }
99         
100         @Override
101         protected TExtensibleElements createNewElement() {
102                 return new TNodeType();
103         }
104         
105 }