use of org.eclipse.winery.model.tosca.TPropertyConstraint in project winery by eclipse.
the class PropertyConstraintsResource method onGet.
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<PropertyConstraintsApiData> onGet() {
List<PropertyConstraintsApiData> apiDatas = new ArrayList<>();
Iterator<TPropertyConstraint> iterator = this.propertyConstraints.getPropertyConstraint().iterator();
for (TPropertyConstraint propertyConstraint : this.propertyConstraints.getPropertyConstraint()) {
apiDatas.add(new PropertyConstraintsApiData(propertyConstraint));
}
return apiDatas;
}
use of org.eclipse.winery.model.tosca.TPropertyConstraint in project winery by eclipse.
the class PropertyConstraintsResource method onPost.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onPost(PropertyConstraintsApiData constraintsApiData) {
if (StringUtils.isEmpty(constraintsApiData.getProperty())) {
return Response.status(Status.BAD_REQUEST).entity("Property must not be empty").build();
}
if (StringUtils.isEmpty(constraintsApiData.getConstraintType())) {
return Response.status(Status.BAD_REQUEST).entity("Constraint Type must not be empty").build();
}
TPropertyConstraint propertyConstraint = new TPropertyConstraint();
propertyConstraint.setProperty(constraintsApiData.getProperty());
// Patching Any from String to XML
try {
propertyConstraint.setAny(ModelUtilities.patchAnyItem(constraintsApiData.getFragments()));
} catch (IOException e) {
LOGGER.info("Could not parse the given Fragments as XML elements");
return Response.notAcceptable(null).build();
}
propertyConstraint.setConstraintType(constraintsApiData.getConstraintType());
this.propertyConstraints.add(propertyConstraint);
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.model.tosca.TPropertyConstraint in project winery by eclipse.
the class PropertyConstraintsResource method onDelete.
@Path("{id}")
@DELETE
public Response onDelete(@PathParam("id") String id) {
id = EncodingUtil.URLdecode(id);
Iterator<TPropertyConstraint> iterator = this.propertyConstraints.iterator();
while (iterator.hasNext()) {
TPropertyConstraint propertyConstraint = iterator.next();
if (propertyConstraint.getProperty().equals(id)) {
iterator.remove();
return RestUtils.persist(this.res);
}
}
// otherwise "iterator.remove()" has called and the resource persisted
return Response.status(Status.NOT_FOUND).build();
}
Aggregations