Changeset 5684 for DASISH


Ignore:
Timestamp:
09/26/14 14:04:57 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Refixing the previous bug, because update public access mode id not work properly.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r5679 r5684  
    247247        Map params = new HashMap();
    248248        params.put("annotation", annotation);
    249         ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation());
    250         if (result != null) {
    251             return (new ObjectFactory()).createResponseBody(result);
    252         } else {
     249        try {
     250            ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation());
     251            if (result != null) {
     252                return (new ObjectFactory()).createResponseBody(result);
     253            } else {
     254                return (new ObjectFactory()).createResponseBody(new ResponseBody());
     255            }
     256        } catch (NotInDataBaseException e) {
     257            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
    253258            return (new ObjectFactory()).createResponseBody(new ResponseBody());
    254259        }
     
    399404        }
    400405
    401         Access accessTyped = Access.fromValue(access);
    402         int updatedAnnotations = 0;
    403 
    404         if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) {
    405             List<Number> annotationIDs = dbDispatcher.getAnnotationInternalIDsFromHeadline(annotationHeadline);
    406             if (annotationIDs == null || annotationIDs.isEmpty()) {
    407                 return "No annotations with this headline have been found";
    408             };
    409             int count = 0;
    410             for (Number annotationID : annotationIDs) {
    411                 count = dbDispatcher.updatePublicAttribute(annotationID, accessTyped);;
    412                 updatedAnnotations = updatedAnnotations + count;
    413             }
    414             return (updatedAnnotations + " row(s) are updated");
    415         } else {
    416             try {
    417                 Number annotationID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(annotationDatabaseId), Resource.ANNOTATION);
    418                 updatedAnnotations = dbDispatcher.updatePublicAttribute(annotationID, accessTyped);
    419             } catch (NotInDataBaseException e) {
    420                 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString());
    421             }
    422         }
    423         return (updatedAnnotations + " annotation(s) are updated.");
     406        try {
     407
     408            Access accessTyped = Access.fromValue(access);
     409            if (annotationDatabaseId == null || annotationDatabaseId.trim().equals("")) {
     410                List<UUID> annotationIds = dbDispatcher.getAnnotationExternalIdsFromHeadline(annotationHeadline);
     411                if (annotationIds == null || annotationIds.isEmpty()) {
     412                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "No annotations with this headline have been found");
     413                    return "No annotations with this headline have been found";
     414                };
     415                int updatedAnnotations = 0;           
     416                for (UUID annotationId : annotationIds) {
     417                    Map params = new HashMap();
     418                    params.put("access", accessTyped);
     419                    Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId.toString());
     420                    updatedAnnotations = (result != null) ? updatedAnnotations + result.intValue() : updatedAnnotations;
     421                }
     422                return (updatedAnnotations + " row(s) are updated");
     423            } else {
     424                Map params = new HashMap();
     425                params.put("access", accessTyped);
     426                Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePublicAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationDatabaseId);
     427                if (result != null) {
     428                    return result + " row(s) is(are) updated.";
     429                } else {
     430                    return "0 rows are updated.";
     431                }
     432            }
     433        } catch (NotInDataBaseException e1) {
     434            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.toString());
     435            return "0 rows are updated.";
     436        } catch (ForbiddenException e2) {
     437            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.toString());
     438            return "0 rows are updated.";
     439        }
     440    }
     441
     442    private class UpdatePublicAccess implements ILambda<Map, Integer> {
     443
     444        @Override
     445        public Integer apply(Map params) throws NotInDataBaseException {
     446            Number annotationID = (Number) params.get("internalID");
     447            Access access = (Access) params.get("access");
     448            return dbDispatcher.updatePublicAttribute(annotationID, access);
     449        }
    424450    }
    425451
     
    512538            return "0 rows are updated.";
    513539        }
    514 
    515 
    516540    }
    517541
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java

    r5679 r5684  
    7777        Map params = new HashMap<String, String>();
    7878        params.put("externalId", externalIdentifier);
    79         Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipal());
    80         return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
     79        try {
     80            Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipal());
     81            return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
     82        } catch (NotInDataBaseException e) {
     83            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
     84            return new ObjectFactory().createPrincipal(new Principal());
     85        }
    8186    }
    8287
     
    111116        Map params = new HashMap<String, String>();
    112117        params.put("email", email);
    113         Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipalByInfo());
    114         return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
     118        try {
     119            Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new GetPrincipalByInfo());
     120            return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
     121        } catch (NotInDataBaseException e) {
     122            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
     123            return new ObjectFactory().createPrincipal(new Principal());
     124        }
    115125    }
    116126
     
    131141        Map params = new HashMap<String, String>();
    132142        params.put("externalId", externalIdentifier);
    133         CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCurrentPrincipalInfo());
    134         return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo()));
     143        try {
     144            CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCurrentPrincipalInfo());
     145            return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo()));
     146        } catch (NotInDataBaseException e) {
     147            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
     148            return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo());
     149        }
    135150    }
    136151
     
    309324            Map params = new HashMap<String, Object>();
    310325            params.put("newPrincipal", principal);
    311             Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipal());
    312             return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
    313 
     326            try {
     327                Principal result = (Principal) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipal());
     328                return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal()));
     329            } catch (NotInDataBaseException e) {
     330                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
     331                return new ObjectFactory().createPrincipal(new Principal());
     332            }
    314333        } else {
    315334            this.ADMIN_RIGHTS_EXPECTED();
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java

    r5679 r5684  
    5353    }
    5454
    55     public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor) throws IOException {
     55    public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor) throws IOException, NotInDataBaseException {
    5656        Number remotePrincipalID = resourceResource.getPrincipalID();
    5757        if (remotePrincipalID == null) {
     
    5959        }
    6060        params.put(_principalID, remotePrincipalID);
    61         try {
    62             return dbRequestor.apply(params);
    63         } catch (NotInDataBaseException e1) {
    64             resourceResource.loggerServer.debug(e1.toString());
    65             resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
    66             return null;
    67         }
     61        return dbRequestor.apply(params);
    6862    }
    6963
     
    8579
    8680    }
     81   
     82   
    8783
    8884    public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException, NotInDataBaseException, PrincipalExists {
Note: See TracChangeset for help on using the changeset viewer.