Ignore:
Timestamp:
08/13/14 16:55:59 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Fixed issued arising after testing on localhost tomcat (completed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r5551 r5552  
    189189                    "Releasing {} registered components into the world ({} millisecs)",
    190190                    result.size(), (System.currentTimeMillis() - start));
     191           
    191192            return result;
    192193        } catch (AuthenticationFailException e) {
     
    214215
    215216        long start = System.currentTimeMillis();
    216        
     217
    217218        if (!checkRegistrySpaceString(registrySpace)) {
    218219            response.sendError(Status.NOT_FOUND.getStatusCode(), "illegal registry space");
     
    225226                    "Releasing {} registered components into the world ({} millisecs)",
    226227                    result.size(), (System.currentTimeMillis() - start));
     228             
    227229            return result;
    228230        } catch (AuthenticationFailException e) {
     
    418420    public List<Comment> getCommentsFromProfile(
    419421            @PathParam("profileId") String profileId)
    420             throws ComponentRegistryException, IOException {
     422            throws IOException {
    421423        long start = System.currentTimeMillis();
    422424        try {
     
    426428                    comments.size(), (System.currentTimeMillis() - start));
    427429            return comments;
     430        } catch (ComponentRegistryException e) {
     431            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
     432            return new ArrayList<Comment>();
    428433        } catch (ItemNotFoundException e) {
    429             response.sendError(Status.NOT_FOUND.getStatusCode());
     434            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
    430435            return new ArrayList<Comment>();
    431 
    432436        } catch (UserUnauthorizedException e) {
    433             response.sendError(Status.FORBIDDEN.getStatusCode());
     437            response.sendError(Status.FORBIDDEN.getStatusCode(), e.getMessage());
    434438            return new ArrayList<Comment>();
    435439        } catch (AuthenticationFailException e1) {
    436             response.sendError(Status.UNAUTHORIZED.getStatusCode());
     440            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
    437441            return new ArrayList<Comment>();
    438442        }
     
    446450    public List<Comment> getCommentsFromComponent(
    447451            @PathParam("componentId") String componentId)
    448             throws ComponentRegistryException, IOException {
     452            throws IOException {
    449453        long start = System.currentTimeMillis();
    450454        try {
     
    454458                    comments.size(), (System.currentTimeMillis() - start));
    455459            return comments;
     460        } catch (ComponentRegistryException e) {
     461            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
     462            return new ArrayList<Comment>();
    456463        } catch (ItemNotFoundException e) {
    457             response.sendError(Status.NOT_FOUND.getStatusCode());
     464            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
    458465            return new ArrayList<Comment>();
    459466        } catch (UserUnauthorizedException e1) {
    460             response.sendError(Status.FORBIDDEN.getStatusCode());
     467            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
    461468            return new ArrayList<Comment>();
    462469        } catch (AuthenticationFailException e1) {
    463             response.sendError(Status.UNAUTHORIZED.getStatusCode());
     470            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
    464471            return new ArrayList<Comment>();
    465472        }
     
    474481            @PathParam("profileId") String profileId,
    475482            @PathParam("commentId") String commentId)
    476             throws ComponentRegistryException, IOException {
     483            throws IOException {
    477484
    478485        LOG.debug("Comments of profile with id {} are requested.", commentId);
     
    480487
    481488            return this.getBaseRegistry().getSpecifiedCommentInProfile(profileId, commentId);
     489        } catch (ComponentRegistryException e) {
     490            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
     491            return new Comment();
    482492        } catch (ItemNotFoundException e) {
    483             response.sendError(Status.NOT_FOUND.getStatusCode());
     493            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
    484494            return new Comment();
    485495        } catch (UserUnauthorizedException e1) {
    486             response.sendError(Status.FORBIDDEN.getStatusCode());
     496            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
    487497            return new Comment();
    488498        } catch (AuthenticationFailException e1) {
    489             response.sendError(Status.UNAUTHORIZED.getStatusCode());
     499            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
    490500            return new Comment();
    491501        }
     
    500510            @PathParam("componentId") String componentId,
    501511            @PathParam("commentId") String commentId)
    502             throws ComponentRegistryException, IOException {
     512            throws IOException {
    503513        LOG.debug("Comments of component with id {} are requested.", commentId);
    504514        try {
    505515
    506516            return this.getBaseRegistry().getSpecifiedCommentInComponent(componentId, commentId);
     517        } catch (ComponentRegistryException e) {
     518            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
     519            return new Comment();
    507520        } catch (ItemNotFoundException e) {
    508             response.sendError(Status.NOT_FOUND.getStatusCode());
     521            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
    509522            return new Comment();
    510523        } catch (UserUnauthorizedException e1) {
    511             response.sendError(Status.FORBIDDEN.getStatusCode());
     524            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
    512525            return new Comment();
    513526        } catch (AuthenticationFailException e1) {
    514             response.sendError(Status.UNAUTHORIZED.getStatusCode());
     527            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
    515528            return new Comment();
    516529        }
     
    540553    }
    541554
    542     // TODO: test via POSTMAN
     555   
    543556    @Override
    544557    @POST
     
    555568    }
    556569
    557     // TODO: test via POSTMAN
     570   
    558571    @Override
    559572    @POST
     
    848861                    .build();
    849862        } catch (ItemNotFoundException e) {
    850             LOG.warn("Component with id " + componentId + " is not found.",
    851                     e);
     863            LOG.warn("Component with id " + componentId + " is not found.");
    852864            return Response.serverError().status(Status.NOT_FOUND)
    853865                    .build();
     
    869881
    870882        LOG.info("Component with id: {} deleted.", componentId);
    871         return Response.ok().build();
     883        return Response.ok("Component with id" + componentId+" deleted.").build();
    872884    }
    873885
     
    17361748    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML,
    17371749        MediaType.APPLICATION_JSON})
    1738     public String transferItemOwnershipToGroup(@PathParam("itemId") String itemId,
     1750    public Response transferItemOwnershipToGroup(@PathParam("itemId") String itemId,
    17391751            @QueryParam("groupId") long groupId) throws IOException {
    17401752        Principal principal = security.getUserPrincipal();
    17411753        try {
    17421754            groupService.transferItemOwnershipFromUserToGroupId(principal.getName(), groupId, itemId);
    1743             return "No exceptions happen, the item shoul be transferred";
     1755            return Response.ok("Ownership transferred").build();
    17441756        } catch (UserUnauthorizedException e) {
    1745             response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString());
    1746             return e.toString();
     1757            return Response.status(Status.FORBIDDEN).build();
    17471758        }
    17481759    }
     
    17571768        try {
    17581769            ComponentRegistry cr = this.getBaseRegistry();
    1759             try {
    1760                 BaseDescription description = cr.getComponentDescriptionAccessControlled(itemId);
     1770            BaseDescription description;
     1771            if (itemId.startsWith(ComponentDescription.COMPONENT_PREFIX)) {
     1772                description = cr.getComponentDescriptionAccessControlled(itemId);
    17611773                return description;
    1762             } catch (UserUnauthorizedException ex1) {
    1763                 try {
    1764                     BaseDescription description = cr.getProfileDescriptionAccessControlled(itemId);
    1765                     return description;
    1766                 } catch (UserUnauthorizedException ex2) {
    1767                     response.sendError(Status.FORBIDDEN.getStatusCode(), "User \'" + security.getUserPrincipal().getName() + "\' does not have access to the item with the given id or the item with the given id does not exist.");
    1768                     return new BaseDescription();
    1769                 }
    1770             }
     1774            };
     1775            if (itemId.startsWith(ProfileDescription.PROFILE_PREFIX)) {
     1776                description = cr.getProfileDescriptionAccessControlled(itemId);
     1777                return description;
     1778            };
     1779            response.sendError(Status.BAD_REQUEST.getStatusCode());
     1780            return new BaseDescription();
     1781
     1782
     1783        } catch (UserUnauthorizedException ex2) {
     1784            response.sendError(Status.FORBIDDEN.getStatusCode(), ex2.getMessage());
     1785            return new BaseDescription();
    17711786        } catch (ItemNotFoundException e) {
    1772             response.sendError(Status.NOT_FOUND.getStatusCode());
     1787            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
    17731788            return new BaseDescription();
    17741789        } catch (AuthenticationFailException e) {
Note: See TracChangeset for help on using the changeset viewer.