1 /*******************************************************************************
2 * Copyright (c) 2012-2013,2015 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.entitytypes.relationshiptypes;
14 import java.io.StringWriter;
15 import java.util.ArrayList;
16 import java.util.Collection;
18 import javax.ws.rs.core.Response;
19 import javax.xml.namespace.QName;
21 import org.eclipse.winery.common.ids.definitions.RelationshipTypeId;
22 import org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId;
23 import org.eclipse.winery.repository.backend.BackendUtils;
24 import org.eclipse.winery.repository.resources.entitytypes.ImplementationsOfOneType;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.fasterxml.jackson.core.JsonFactory;
29 import com.fasterxml.jackson.core.JsonGenerator;
31 public class ImplementationsOfOneRelationshipTypeResource extends ImplementationsOfOneType {
33 public ImplementationsOfOneRelationshipTypeResource(RelationshipTypeId typeId) {
38 private static final Logger logger = LoggerFactory.getLogger(ImplementationsOfOneRelationshipTypeResource.class);
42 * required by implementations.jsp
44 * Method similar top the one of ImplementationsOfOneNodeTypeResource
46 * @return for each node type implementation implementing the associated
50 public String getImplementationsTableData() {
52 JsonFactory jsonFactory = new JsonFactory();
53 StringWriter tableDataSW = new StringWriter();
55 JsonGenerator jGenerator = jsonFactory.createGenerator(tableDataSW);
56 jGenerator.writeStartArray();
58 Collection<RelationshipTypeImplementationId> allNTIids = BackendUtils.getAllElementsRelatedWithATypeAttribute(RelationshipTypeImplementationId.class, this.getTypeId().getQName());
59 for (RelationshipTypeImplementationId ntiID : allNTIids) {
60 jGenerator.writeStartArray();
61 jGenerator.writeString(ntiID.getNamespace().getDecoded());
62 jGenerator.writeString(ntiID.getXmlId().getDecoded());
63 jGenerator.writeEndArray();
65 jGenerator.writeEndArray();
68 res = tableDataSW.toString();
69 } catch (Exception e) {
70 ImplementationsOfOneRelationshipTypeResource.logger.error(e.getMessage(), e);
77 public String getType() {
78 return "relationshiptype";
82 public String getTypeStr() {
83 return "Relationship Type";
87 public Response getJSON() {
88 Collection<RelationshipTypeImplementationId> allImplementations = BackendUtils.getAllElementsRelatedWithATypeAttribute(RelationshipTypeImplementationId.class, this.getTypeId().getQName());
89 ArrayList<QName> res = new ArrayList<QName>(allImplementations.size());
90 for (RelationshipTypeImplementationId id : allImplementations) {
91 res.add(id.getQName());
93 return Response.ok().entity(res).build();