use of org.eclipse.winery.model.tosca.TParameter in project winery by eclipse.
the class ParametersResource method createParamter.
/**
* TODO: This method possibly is never called from the Angular UI
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
public // @formatter:off
Response createParamter(@FormParam("name") String name, @FormParam("type") String type, // @ApiParam(value = "type tYesNo, not Boolean. For convenience, on/off is also supported. In case this parameter is not provided, 'off' is assumed. This is in contrast to the specification, but it eases implementing the UI")
@FormParam("required") String required) {
// @formatter:on
if (StringUtils.isEmpty(name)) {
return Response.status(Status.BAD_REQUEST).entity("name must not be null").build();
}
if (StringUtils.isEmpty(type)) {
return Response.status(Status.BAD_REQUEST).entity("type must not be null").build();
}
TParameter param = new TParameter();
param.setName(name);
param.setType(type);
TBoolean tb;
if (required == null) {
// The specification states that the default value is "yes"
// We assume "no", because Chrome does not send the checkbox data if a checkbox is not checked
tb = TBoolean.NO;
} else {
if (required.equalsIgnoreCase("on")) {
tb = TBoolean.YES;
} else if (required.equalsIgnoreCase("off")) {
tb = TBoolean.NO;
} else {
try {
tb = TBoolean.valueOf(required);
} catch (java.lang.IllegalArgumentException e) {
return Response.status(Status.BAD_REQUEST).entity("Wrong format of required").build();
}
}
}
param.setRequired(tb);
this.list.add(param);
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.model.tosca.TParameter 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.TParameter 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.TParameter in project winery by eclipse.
the class GeneratorTest method testInOut.
@Test
public void testInOut() throws Exception {
TInterface tinterface = new TInterface();
tinterface.setName("http://www.example.org/interfaces/lifecycle");
TOperation op1 = new TOperation();
op1.setName("Op1InOut");
tinterface.getOperation().add(op1);
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);
op1.setInputParameters(op1InputParameters);
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);
op1.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