Search in sources :

Example 1 with NotFoundException

use of com.sun.jersey.api.NotFoundException in project winery by eclipse.

the class EntityWithoutIdCollectionResource method getEntityResourceFromDecodedId.

/**
 * Method searching the list for an id with the hashcode instead of getId(EntityT)
 */
@Override
protected EntityResourceT getEntityResourceFromDecodedId(String id) {
    Objects.requireNonNull(id);
    int idInt;
    try {
        idInt = Integer.parseInt(id);
    } catch (java.lang.NumberFormatException e) {
        throw new NotFoundException(id + " is not a valid id");
    }
    EntityT entity = null;
    int idx = -1;
    for (EntityT c : this.list) {
        idx++;
        // speed optimization - instead of using getId() we directly use the hash code
        int hash = BackendUtils.getXMLAsString(c).hashCode();
        if (hash == idInt) {
            entity = c;
            break;
        }
    }
    if (entity == null) {
        throw new NotFoundException();
    } else {
        return this.getEntityResourceInstance(entity, idx);
    }
}
Also used : NotFoundException(com.sun.jersey.api.NotFoundException)

Example 2 with NotFoundException

use of com.sun.jersey.api.NotFoundException in project winery by eclipse.

the class RequiredCapabilityTypeResource method putRequiredCapabilityType.

@PUT
@Consumes(MediaType.TEXT_PLAIN)
public Response putRequiredCapabilityType(String type) {
    if (StringUtils.isEmpty(type)) {
        return Response.status(Status.BAD_REQUEST).entity("type must not be empty").build();
    }
    QName qname = QName.valueOf(type);
    CapabilityTypeId id = new CapabilityTypeId(qname);
    if (RepositoryFactory.getRepository().exists(id)) {
        // everything allright. Store new reference
        this.getRequirementType().setRequiredCapabilityType(qname);
        return RestUtils.persist(this.requirementTypeResource);
    } else {
        throw new NotFoundException("Given QName could not be resolved to an existing capability type");
    }
}
Also used : CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) NotFoundException(com.sun.jersey.api.NotFoundException)

Aggregations

NotFoundException (com.sun.jersey.api.NotFoundException)2 QName (javax.xml.namespace.QName)1 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)1