Changeset 4263


Ignore:
Timestamp:
01/14/14 18:06:27 (10 years ago)
Author:
olhsha
Message:

Put annotation is fixed. But AnnotationResourse? definitely needs refactoring.

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

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4262 r4263  
    386386        int addedTargets = addTargets(annotation, annotationID);
    387387        int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID);
    388         int addedOwner = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);
    389388        return updatedAnnotations;
    390389    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4262 r4263  
    101101    public AnnotationResource() {
    102102    }
    103    
    104    
    105103
    106104    @GET
     
    167165// TODO Unit test
    168166
    169    
    170    
    171    
    172167    @GET
    173168    @Produces(MediaType.TEXT_XML)
     
    255250        }
    256251    }
    257    
     252
    258253    // TODO: how to return the status code?
    259 
    260    
    261254///////////////////////////////////////////////////////
    262 
    263255    @POST
    264256    @Consumes(MediaType.APPLICATION_XML)
     
    288280        dbIntegrityService.setServiceURI(path);
    289281        String annotationURI = annotation.getURI();
    290        
     282
    291283        if (!(path + "annotations/" + externalIdentifier).equals(annotationURI)) {
    292284            httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request: the external annotation ID and the annotation ID from the request body do not match. Correct the request and resend.");
    293285            return null;
    294286        }
    295        
     287
    296288        List<UserWithPermission> permissions = annotation.getPermissions().getUserWithPermission();
    297        
    298        
     289        String ownerURI = annotation.getOwnerRef();
     290        if (!ownerIsListed(ownerURI, permissions)) {
     291            httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request body: the  owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend.");
     292            return null;
     293        }
     294
     295
    299296        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    300297        if (annotationID != null) {
     
    518515        }
    519516    }
    520    
    521    
     517
     518    private boolean ownerIsListed(String uri, List<UserWithPermission> permissions) {
     519        for (UserWithPermission permissionPair : permissions) {
     520            if (permissionPair.getRef().equals(uri) && permissionPair.getPermission().equals(Permission.OWNER)) {
     521                return true;
     522            }
     523        }
     524        return false;
     525    }
    522526}
Note: See TracChangeset for help on using the changeset viewer.