aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/resources/entitytemplates/TEntityTemplateResource.java
blob: ee9064b56437ef4f589daa2d8bf50a2934579a5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2012-2014 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     Oliver Kopp - initial API and implementation
 *******************************************************************************/
package org.eclipse.winery.repository.resources.entitytemplates;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.xml.namespace.QName;

import org.eclipse.winery.model.tosca.TEntityTemplate;
import org.eclipse.winery.repository.backend.BackendUtils;
import org.eclipse.winery.repository.resources.AbstractComponentInstanceResource;
import org.eclipse.winery.repository.resources.IHasTypeReference;
import org.eclipse.winery.repository.resources._support.IPersistable;
import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
import org.eclipse.winery.repository.resources._support.collections.withid.EntityWithIdResource;

public class TEntityTemplateResource<E extends TEntityTemplate> extends EntityWithIdResource<E> implements IEntityTemplateResource<E>, IHasTypeReference {
	
	/**
	 * This constructor is used for both entity templates nested in an component
	 * instance as well as for entity templates being component instances
	 * itself.
	 * 
	 * As Java does not support multi-inheritance, we implemented a quick hack
	 * to re-use this class as inner implementation at templates extending
	 * AbstractComponentInstanceResourceDefinitionsBacked
	 */
	public TEntityTemplateResource(IIdDetermination<E> idDetermination, E o, int idx, List<E> list, IPersistable res) {
		super(idDetermination, o, idx, list, res);
	}
	
	//	public String getId() {
	//		return this.template.getId();
	//	}
	//
	//	public void setId(String id) {
	//		// TODO: There is no check for uniqueness of the given id
	//		this.template.setId(id);
	//	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public QName getType() {
		return this.o.getType();
	}
	
	@Path("type")
	@GET
	public String getTypeAsQNameString() {
		return this.getType().toString();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public Response setType(QName type) {
		this.o.setType(type);
		return BackendUtils.persist(this.res);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public Response setType(String typeStr) {
		return this.setType(QName.valueOf(typeStr));
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public PropertiesResource getPropertiesResource() {
		return new PropertiesResource(this.o, (AbstractComponentInstanceResource) this.res);
	}
	
}