Search in sources :

Example 1 with TPropertyConstraint

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;
}
Also used : PropertyConstraintsApiData(org.eclipse.winery.repository.rest.resources.apiData.boundarydefinitions.PropertyConstraintsApiData) ArrayList(java.util.ArrayList) TPropertyConstraint(org.eclipse.winery.model.tosca.TPropertyConstraint)

Example 2 with TPropertyConstraint

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);
}
Also used : IOException(java.io.IOException) TPropertyConstraint(org.eclipse.winery.model.tosca.TPropertyConstraint) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 3 with TPropertyConstraint

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();
}
Also used : TPropertyConstraint(org.eclipse.winery.model.tosca.TPropertyConstraint) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

TPropertyConstraint (org.eclipse.winery.model.tosca.TPropertyConstraint)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PropertyConstraintsApiData (org.eclipse.winery.repository.rest.resources.apiData.boundarydefinitions.PropertyConstraintsApiData)1