use of org.eclipse.winery.model.tosca.TOperation 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.TOperation in project winery by eclipse.
the class Generator method generateJavaFile.
private void generateJavaFile(File javaService) throws IOException {
// Generate methods
StringBuilder sb = new StringBuilder();
for (TOperation op : this.tInterface.getOperation()) {
// Annotations
sb.append("\t@WebMethod\n");
sb.append("\t@SOAPBinding\n");
sb.append("\t@Oneway\n");
// Signatur
String operationReturn = "void";
sb.append("\tpublic " + operationReturn + " " + op.getName() + "(\n");
// Parameter
boolean first = true;
if (op.getInputParameters() != null) {
for (TParameter parameter : op.getInputParameters().getInputParameter()) {
String parameterName = parameter.getName();
if (first) {
first = false;
sb.append("\t\t");
} else {
sb.append(",\n\t\t");
}
// Generate @WebParam
sb.append("@WebParam(name=\"" + parameterName + "\", targetNamespace=\"" + this.namespace + "\") ");
// Handle required and optional parameters using @XmlElement
if (parameter.getRequired().equals(TBoolean.YES)) {
sb.append("@XmlElement(required=true)");
} else {
sb.append("@XmlElement(required=false)");
}
sb.append(" String " + parameterName);
}
}
sb.append("\n\t) {\n");
// If there are output parameters we generate the respective HashMap
boolean outputParamsExist = (op.getOutputParameters() != null) && (!op.getOutputParameters().getOutputParameter().isEmpty());
if (outputParamsExist) {
sb.append("\t\t// This HashMap holds the return parameters of this operation.\n");
sb.append("\t\tfinal HashMap<String,String> returnParameters = new HashMap<String, String>();\n\n");
}
sb.append("\t\t// TODO: Implement your operation here.\n");
// Generate code to set output parameters
if (outputParamsExist) {
for (TParameter outputParam : op.getOutputParameters().getOutputParameter()) {
sb.append("\n\n\t\t// Output Parameter '" + outputParam.getName() + "' ");
if (outputParam.getRequired().equals(TBoolean.YES)) {
sb.append("(required)");
} else {
sb.append("(optional)");
}
sb.append("\n\t\t// TODO: Set " + outputParam.getName() + " parameter here.");
sb.append("\n\t\t// Do NOT delete the next line of code. Set \"\" as value if you want to return nothing or an empty result!");
sb.append("\n\t\treturnParameters.put(\"" + outputParam.getName() + "\", \"TODO\");");
}
sb.append("\n\n\t\tsendResponse(returnParameters);\n");
}
sb.append("\t}\n\n");
}
// Read file and replace placeholders
Charset cs = Charset.defaultCharset();
List<String> lines = new ArrayList<>();
for (String line : Files.readAllLines(javaService.toPath(), cs)) {
// Replace web service method
line = line.replaceAll(Generator.PLACEHOLDER_GENERATED_WEBSERVICE_METHODS, sb.toString());
lines.add(line);
}
// Write file
OpenOption[] options = new OpenOption[] { StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING };
Files.write(javaService.toPath(), lines, cs, options);
}
use of org.eclipse.winery.model.tosca.TOperation 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);
}
use of org.eclipse.winery.model.tosca.TOperation in project winery by eclipse.
the class GeneratorTest method testNoParams.
@Test
public void testNoParams() throws Exception {
TInterface tinterface = new TInterface();
tinterface.setName("TestNoParams");
TOperation opIn = new TOperation();
opIn.setName("OpNoParams");
tinterface.getOperation().add(opIn);
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);
}
use of org.eclipse.winery.model.tosca.TOperation in project winery by eclipse.
the class InterfacesResource method onGet.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<?> onGet(@QueryParam("selectData") String selectData) {
if (selectData == null) {
return this.interfaces;
}
List<InterfacesSelectApiData> list = new ArrayList<>();
for (TInterface item : this.interfaces) {
List<String> ops = new ArrayList<>();
for (TOperation op : item.getOperation()) {
ops.add(op.getName());
}
list.add(new InterfacesSelectApiData(item.getName(), ops));
}
return list;
}
Aggregations