Package org.apache.wink.example.history.legacy

Examples of org.apache.wink.example.history.legacy.DataStore


     */
    @GET
    @Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
    public DefectsAsset getDefects(@Context LinkBuilders linkProcessor, @Context UriInfo uriInfo) {
        // create data object (populated with store data)
        DataStore store = DataStore.getInstance();
        Collection<DefectBean> defects = store.getDefects();
        return new DefectsAsset(defects);
    }
View Full Code Here


                                              new RuntimeException(
                                                                   "The content of the defect is missing"),
                                              Response.Status.BAD_REQUEST);
        }

        DataStore store = DataStore.getInstance();
        if (defect.getId() != null) {
            // undelete operation
            if (!store.isDefectDeleted(defect.getId())) {
                // the defect was already undeleted!
                // it's a conflict!
                return Response.status(Status.CONFLICT).build();
            }
            // this is undelete operation, there is no need to populate new id
        } else {
            // this is a new defect so generate an id
            defect.setId(store.getDefectUniqueId());
        }

        // validate that the user didn't send deleted=true by mistake
        defect.setDeleted(false);

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

        URI location = uriInfo.getAbsolutePathBuilder().segment(defect.getId()).build();
        return Response.created(location).entity(asset).build();
    }
View Full Code Here

        MediaType.APPLICATION_XML})
    public DefectAsset getDefect(@PathParam(DEFECT_VAR) PathSegment segment,
                                 @MatrixParam(REVISION) @DefaultValue("-1") int defectRevision) {

        // create data object (populated with store data)
        DataStore store = DataStore.getInstance();
        String defectId = segment.getPath();
        DefectBean defect = store.getDefect(defectId);
        if (defectRevision != -1) {
            // get specific revision
            // even if the defect was deleted, it is returned
            defect = store.getDefect(defectId, defectRevision);
        }
        if (defect == null) {
            throw new WebApplicationException(new RuntimeException("Defect " + defectId
                + " not found"), Response.Status.NOT_FOUND);
        }

        DefectAsset asset = new DefectAsset(defect);
        asset.setEditable(!store.isDefectDeleted(defectId));
        return asset;
    }
View Full Code Here

    @Path(DEFECT_HISTORY_URL)
    @GET
    @Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
    public DefectsAsset getDefectHistory(@PathParam(DEFECT_VAR) PathSegment segement) {
        // create data object (populated with store data)
        DataStore store = DataStore.getInstance();
        String defectId = segement.getPath();
        // get the history of the defect
        List<DefectBean> defectHistory = store.getDefectHistory(defectId);
        if (defectHistory.isEmpty()) {
            throw new WebApplicationException(new RuntimeException("Defect " + defectId
                + " not found"), Response.Status.NOT_FOUND);
        }
        return new DefectsAsset(defectHistory, true);
View Full Code Here

            throw new WebApplicationException(HttpStatus.METHOD_NOT_ALLOWED.getCode());
        }

        // obtain data object from the memory store
        // if the defect was deleted, it cannot be updated anymore.
        DataStore store = DataStore.getInstance();
        String defectId = segement.getPath();
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            throw new WebApplicationException(new RuntimeException("Defect " + defectId
                + " not found"), Response.Status.NOT_FOUND);
        }

        // validate that user didn't send deleted flag, since it will mark
        // defect as deleted.
        // to delete a defect, DELETE http method should be used
        defect = asset.getDefect();
        defect.setDeleted(false);

        // set Id in the asset for cases that element <id> is missing
        // in the request body
        defect.setId(defectId);

        // update defect legacy bean to the memory store
        store.putDefect(defectId, defect);

        return asset;
    }
View Full Code Here

            throw new WebApplicationException(HttpStatus.METHOD_NOT_ALLOWED.getCode());
        }

        // obtain data object from memory store
        // if the object was already deleted, null will be returned
        DataStore store = DataStore.getInstance();
        String defectId = segement.getPath();
        DefectBean defect = store.getDefect(defectId);
        if (defect == null) {
            throw new WebApplicationException(new RuntimeException("Defect " + defectId
                + " not found"), Response.Status.NOT_FOUND);
        }

        // remove defect legacy bean from memory store
        store.deleteDefect(defectId);

        return new DefectAsset(defect);
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.example.history.legacy.DataStore

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.