Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / InheritanceResource.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;
13
14 import java.util.SortedSet;
15 import java.util.TreeSet;
16
17 import javax.ws.rs.GET;
18 import javax.ws.rs.Produces;
19 import javax.ws.rs.core.MediaType;
20
21 import org.eclipse.winery.common.ids.definitions.TOSCAComponentId;
22 import org.eclipse.winery.repository.backend.Repository;
23
24 import com.sun.jersey.api.view.Viewable;
25
26 /**
27  * Class for managing inheritance properties: abstract, final, derivedFromn
28  * 
29  * The linking in the resources tree is different than the others. Here, there
30  * is no additional Id generated.
31  * 
32  * We separated the code here to have the collection of valid super types in a
33  * separate class. We think, this is less confusing than including this
34  * functionality in
35  * AbstractComponentInstanceResourceWithNameDerivedFromAbstractFinalDefinitionsBacked
36  */
37 public class InheritanceResource {
38         
39         private AbstractComponentInstanceResourceWithNameDerivedFromAbstractFinal managedResource;
40         
41         
42         public InheritanceResource(AbstractComponentInstanceResourceWithNameDerivedFromAbstractFinal res) {
43                 this.managedResource = res;
44         }
45         
46         @GET
47         @Produces(MediaType.TEXT_HTML)
48         public Viewable getHTML() {
49                 return new Viewable("/jsp/inheritance.jsp", this);
50         }
51         
52         public String getIsAbstract() {
53                 return this.managedResource.getIsAbstract();
54         }
55         
56         public String getIsFinal() {
57                 return this.managedResource.getIsAbstract();
58         }
59         
60         public String getDerivedFrom() {
61                 return this.managedResource.getDerivedFrom();
62         }
63         
64         /** JSP Data **/
65         
66         public SortedSet<? extends TOSCAComponentId> getPossibleSuperTypes() {
67                 // sorted by Name, not by namespace
68                 SortedSet<? extends TOSCAComponentId> allTOSCAcomponentIds = Repository.INSTANCE.getAllTOSCAComponentIds(this.managedResource.getId().getClass());
69                 SortedSet<? extends TOSCAComponentId> res = new TreeSet<>(allTOSCAcomponentIds);
70                 res.remove(this.managedResource.getId());
71                 // FEATURE: Possibly exclude all subtypes to avoid circles. However, this could be disappointing for users who know what they are doing
72                 return res;
73         }
74 }