Package org.apache.wink.example.simpledefects.legacy

Examples of org.apache.wink.example.simpledefects.legacy.DefectBean


    @Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON,
        MediaType.APPLICATION_XML})
    public Response createDefect(DefectAsset asset, @Context UriInfo uriInfo) {
        // if content was not sent => there is no meaning for the defect, throw
        // exception.
        DefectBean defect = asset.getDefect();
        if (defect == null) {
            logger.error("The content of the defect is missing");
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        // set unique Id in the new defect bean:
        // - Id in the input data is ignored, actually there should be no Id
        // there,
        // - resource collection always decides about the unique Id of its own
        // entries,
        // - in our case we use a helper method to generate a unique Id
        defect.setId(DataStore.getInstance().getDefectUniqueId());

        // add defect legacy bean to the memory store
        DataStore store = DataStore.getInstance();
        store.putDefect(defect.getId(), defect);

        // return status code 201 (created) with the created defect
        URI location = uriInfo.getAbsolutePathBuilder().segment(defect.getId()).build();
        return Response.status(Response.Status.CREATED).entity(asset).location(location)
            .tag(new EntityTag(String.valueOf(defect.hashCode()))).build();
    }
View Full Code Here


        MediaType.APPLICATION_JSON})
    public DefectAsset getDefect(@PathParam(DEFECT) String defectId) {
        // initialize memory store
        DataStore store = DataStore.getInstance();
        // create data object (populated with store data)
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        // create a new instance of a defect asset
View Full Code Here

        // initialize the memory store
        DataStore store = DataStore.getInstance();

        // verify the defect exists in the store
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }

        // set Id in the resources data for cases that element <id> is missing
        // in the request body
        defect = asset.getDefect();
        defect.setId(defectId);
        // update defect legacy bean to the memory store
        store.putDefect(defect.getId(), defect);
        return asset;
    }
View Full Code Here

        // initialize the memory store
        DataStore store = DataStore.getInstance();

        // obtain data object from memory store
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }

        // remove defect legacy bean from memory store
        store.removeDefect(defect.getId());

        // create new asset and set defect bean that is being deleted as its
        // data object
        DefectAsset asset = new DefectAsset(defect);
        return asset;
View Full Code Here

    @Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON,
        MediaType.APPLICATION_XML})
    public Response createDefect(DefectAsset asset, @Context UriInfo uriInfo) {
        // if content was not sent => there is no meaning for the defect, throw
        // exception.
        DefectBean defect = asset.getDefect();
        if (defect == null) {
            logger.error("The content of the defect is missing");
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        // set unique Id in the new defect bean:
        // - Id in the input data is ignored, actually there should be no Id
        // there,
        // - resource collection always decides about the unique Id of its own
        // entries,
        // - in our case we use a helper method to generate a unique Id
        defect.setId(DataStore.getInstance().getDefectUniqueId());

        // add defect legacy bean to the memory store
        DataStore store = DataStore.getInstance();
        store.putDefect(defect.getId(), defect);

        // return status code 201 (created) with the created defect
        URI location = uriInfo.getAbsolutePathBuilder().segment(defect.getId()).build();
        return Response.status(Response.Status.CREATED).entity(asset).location(location)
            .tag(new EntityTag(String.valueOf(defect.hashCode()))).build();
    }
View Full Code Here

        MediaType.APPLICATION_JSON})
    public DefectAsset getDefect(@PathParam(DEFECT) String defectId) {
        // initialize memory store
        DataStore store = DataStore.getInstance();
        // create data object (populated with store data)
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        // create a new instance of a defect asset
View Full Code Here

        // initialize the memory store
        DataStore store = DataStore.getInstance();

        // verify the defect exists in the store
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }

        // set Id in the resources data for cases that element <id> is missing
        // in the request body
        defect = asset.getDefect();
        defect.setId(defectId);
        // update defect legacy bean to the memory store
        store.putDefect(defect.getId(), defect);
        return asset;
    }
View Full Code Here

        // initialize the memory store
        DataStore store = DataStore.getInstance();

        // obtain data object from memory store
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            logger.error("Defect {} was not found", defectId);
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }

        // remove defect legacy bean from memory store
        store.removeDefect(defect.getId());

        // create new asset and set defect bean that is being deleted as its
        // data object
        DefectAsset asset = new DefectAsset(defect);
        return asset;
View Full Code Here

TOP

Related Classes of org.apache.wink.example.simpledefects.legacy.DefectBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.