use of org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypeResource in project winery by eclipse.
the class ImplementationArtifactsResource method getInterfacesOfAssociatedType.
/**
* Method to get all interfaces associated to a nodetype or relationshiptype
*
* @return a list of TInterface
*/
@Path("interfaces/")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<?> getInterfacesOfAssociatedType() {
// TODO refactor this that IRepository offers this helper method
boolean isNodeTypeImplementation = this.res instanceof NodeTypeImplementationResource;
QName type = RestUtils.getType(this.res);
List<Object> interfaces = new ArrayList<>();
if (isNodeTypeImplementation) {
NodeTypeResource typeResource = (NodeTypeResource) new NodeTypesResource().getComponentInstaceResource(type);
interfaces.addAll(typeResource.getInterfaces().onGet("true"));
} else {
RelationshipTypeResource typeResource = (RelationshipTypeResource) new RelationshipTypesResource().getComponentInstaceResource(type);
interfaces.addAll(typeResource.getSourceInterfaces().onGet("true"));
interfaces.addAll(typeResource.getTargetInterfaces().onGet("true"));
}
return interfaces;
}
use of org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypeResource in project winery by eclipse.
the class InterfacesResource method onPost.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onPost(List<TInterface> interfaceApiData) {
if (!interfaceApiData.isEmpty()) {
for (TInterface tInt : interfaceApiData) {
if (!tInt.getOperation().isEmpty()) {
for (TOperation tOp : tInt.getOperation()) {
if (tOp.getInputParameters() == null || tOp.getInputParameters().getInputParameter().isEmpty()) {
tOp.setInputParameters(null);
}
if (tOp.getOutputParameters() == null || tOp.getOutputParameters().getOutputParameter().isEmpty()) {
tOp.setOutputParameters(null);
}
}
} else {
return Response.status(Response.Status.BAD_REQUEST).entity("No operation provided!").build();
}
}
} else {
return Response.status(Response.Status.BAD_REQUEST).entity("No interface provided!").build();
}
if (this.res instanceof RelationshipTypeResource) {
TRelationshipType relationshipType = (TRelationshipType) this.res.getElement();
switch(this.interfaceType) {
case "source":
TRelationshipType.SourceInterfaces sourceInterfaces = new TRelationshipType.SourceInterfaces();
sourceInterfaces.getInterface().clear();
sourceInterfaces.getInterface().addAll(interfaceApiData);
relationshipType.setSourceInterfaces(sourceInterfaces);
break;
default:
// it will be target
TRelationshipType.TargetInterfaces targetInterfaces = new TRelationshipType.TargetInterfaces();
targetInterfaces.getInterface().clear();
targetInterfaces.getInterface().addAll(interfaceApiData);
relationshipType.setTargetInterfaces(targetInterfaces);
break;
}
} else if (this.res instanceof NodeTypeResource) {
TNodeType nodeType = (TNodeType) this.res.getElement();
TNodeType.Interfaces interfaces = new TNodeType.Interfaces();
interfaces.getInterface().clear();
interfaces.getInterface().addAll(interfaceApiData);
nodeType.setInterfaces(interfaces);
} else {
throw new IllegalStateException("Interfaces are not supported for this element type!");
}
return RestUtils.persist(this.res);
}
Aggregations