use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final Definitions definitions = createWrapperDefinitions(id);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
for (NodeTypeImplementationId ntiId : allNodeTypeImplementations) {
ids.add(ntiId);
}
final TNodeType nodeType = this.getElement(id);
// add all referenced requirement types
TNodeType.RequirementDefinitions reqDefsContainer = nodeType.getRequirementDefinitions();
if (reqDefsContainer != null) {
List<TRequirementDefinition> reqDefs = reqDefsContainer.getRequirementDefinition();
for (TRequirementDefinition reqDef : reqDefs) {
RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
ids.add(reqTypeId);
}
}
// add all referenced capability types
TNodeType.CapabilityDefinitions capDefsContainer = nodeType.getCapabilityDefinitions();
if (capDefsContainer != null) {
List<TCapabilityDefinition> capDefs = capDefsContainer.getCapabilityDefinition();
for (TCapabilityDefinition capDef : capDefs) {
CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
ids.add(capTypeId);
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TNodeType 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);
}
use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.
the class TOSCAModelHelper method createTNodeType.
public static TNodeType createTNodeType(String id, String namespace) {
TNodeType nodeType = new TNodeType();
nodeType.setName(id);
nodeType.setId(id);
nodeType.setTargetNamespace(namespace);
return nodeType;
}
use of org.eclipse.winery.model.tosca.TNodeType in project winery by eclipse.
the class GeneratorTest method testMultipleOperationsInOrOut.
@Test
public void testMultipleOperationsInOrOut() throws Exception {
TInterface tinterface = new TInterface();
tinterface.setName("TestInOrOut");
TOperation opIn = new TOperation();
opIn.setName("OpIn");
tinterface.getOperation().add(opIn);
TOperation.InputParameters op1InputParameters = new TOperation.InputParameters();
TParameter op1ip1 = new TParameter();
op1ip1.setName("op1ip1");
op1ip1.setType("xs:string");
op1InputParameters.getInputParameter().add(op1ip1);
TParameter op1ip2 = new TParameter();
op1ip2.setName("op1ip2");
op1ip2.setType("xs:string");
op1InputParameters.getInputParameter().add(op1ip2);
opIn.setInputParameters(op1InputParameters);
TOperation opOut = new TOperation();
opOut.setName("OpOut");
tinterface.getOperation().add(opOut);
TOperation.OutputParameters op1OutputParameters = new TOperation.OutputParameters();
TParameter op1op1 = new TParameter();
op1op1.setName("op1op1");
op1op1.setType("xs:string");
op1OutputParameters.getOutputParameter().add(op1op1);
TParameter op1op2 = new TParameter();
op1op2.setName("op1op2");
op1op1.setType("xs:string");
op1OutputParameters.getOutputParameter().add(op1op2);
opOut.setOutputParameters(op1OutputParameters);
TNodeType nodeType = new TNodeType();
nodeType.setName("test");
nodeType.setTargetNamespace("http://asd.com");
Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", WORKING_DIR.toFile());
Path generateProject = gen.generateProject();
System.out.println(generateProject);
}
Aggregations