Changeset 3909


Ignore:
Timestamp:
10/29/13 15:30:29 (11 years ago)
Author:
olhsha
Message:

Refactoring + debugging updating permission lists for an annotation. Works (PUT)

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
8 edited

Legend:

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

    r3901 r3909  
    133133     *
    134134     * @param annotationID
    135      * @param TargetID
     135     * @param targetID
    136136     * @return # updated rows in the joint table "annotations_target_Targets".
    137137     * @throws SQLException
    138138     * Connects the annotation to its target Target by adding the pair (annotationID, TargetID) to the joint table.
    139139     */
    140     public int addAnnotationTarget(Number annotationID, Number TargetID) throws SQLException;
     140    public int addAnnotationTarget(Number annotationID, Number targetID) throws SQLException;
    141141   
    142142   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java

    r3904 r3909  
    143143    Number getTargetInternalIdentifier(UUID externalID);
    144144
    145     String getTargetURI(Number annotationID);
     145    String getTargetURI(Number targetID);
    146146   
    147      UUID getTargetExternalIdentifier(Number annotationID);
     147     UUID getTargetExternalIdentifier(Number targetID);
     148     
     149    String getUserURI(Number userID);
    148150   
    149151    /**
     
    174176     *
    175177     * @param annotationID
    176      * @return the list of TargetID's for which there is no cached representation
    177      */
    178     List<Number> getTargetsWithNoCachedRepresentation(Number annotationID);
     178     * @return the list of targetURI's for which there is no cached representation
     179     */
     180    List<String> getTargetsWithNoCachedRepresentation(Number annotationID);
     181   
     182    List<String> getUsersWithNoInfo(Number annotationID);
    179183   
    180184    /**
     
    247251     * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID".
    248252     */
    249     public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException;
     253    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission, Number remoteUser) throws SQLException, Exception;
    250254   
    251255   /**
     
    255259     * @return # of rows updated or added in the table annotations_principals_permissions
    256260     */
    257     public int updatePermissions(Number annotationID, UserWithPermissionList permissionList) throws SQLException;
     261    public int updatePermissions(Number annotationID, UserWithPermissionList permissionList, Number remoteUser) throws SQLException, Exception;
    258262   
    259263   /**
     
    299303    Number addUser(User user, String remoteID) throws SQLException;
    300304
     305    int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission, Number remoteUser) throws SQLException, Exception;
     306   
    301307    /**
    302308     * DELETERS
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r3906 r3909  
    3939import eu.dasish.annotation.schema.UserWithPermission;
    4040import java.io.InputStream;
     41import java.lang.Number;
    4142import java.sql.Blob;
    4243import java.sql.SQLException;
     
    9798
    9899    @Override
    99     public UUID getTargetExternalIdentifier(Number annotationID) {
    100         return targetDao.getExternalID(annotationID);
    101     }
    102 
    103     @Override
    104     public String getTargetURI(Number annotationID) {
    105         return targetDao.getURIFromInternalID(annotationID);
     100    public UUID getTargetExternalIdentifier(Number targetID) {
     101        return targetDao.getExternalID(targetID);
     102    }
     103
     104    @Override
     105    public String getTargetURI(Number targetID) {
     106        return targetDao.getURIFromInternalID(targetID);
     107    }
     108   
     109    @Override
     110    public String getUserURI(Number userID) {
     111        return userDao.getURIFromInternalID(userID);
    106112    }
    107113
     
    130136    @Override
    131137    public Annotation getAnnotation(Number annotationID) throws SQLException {
    132         Map<Annotation, Number> annotationOwner = annotationDao.getAnnotationWithoutTargetsAndPermissions(annotationID);
    133 
    134         Annotation[] annotations = new Annotation[1];
    135         annotationOwner.keySet().toArray(annotations);
    136         Annotation result = annotations[0];
    137         result.setOwnerRef(userDao.getURIFromInternalID(annotationOwner.get(result)));
    138 
    139         List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
    140         TargetInfoList sis = new TargetInfoList();
    141         for (Number targetID : targetIDs) {
    142             Target target = targetDao.getTarget(targetID);
    143             TargetInfo targetInfo = new TargetInfo();
    144             targetInfo.setLink(target.getLink());
    145             targetInfo.setRef(target.getURI());
    146             targetInfo.setVersion(target.getVersion());
    147             sis.getTargetInfo().add(targetInfo);
    148         }
    149         result.setTargets(sis);
    150 
    151         result.setPermissions(getPermissionsForAnnotation(annotationID));
    152         return result;
     138        if (annotationID != null) {
     139            Map<Annotation, Number> annotationOwner = annotationDao.getAnnotationWithoutTargetsAndPermissions(annotationID);
     140
     141            Annotation[] annotations = new Annotation[1];
     142            annotationOwner.keySet().toArray(annotations);
     143            Annotation result = annotations[0];
     144            result.setOwnerRef(userDao.getURIFromInternalID(annotationOwner.get(result)));
     145
     146            List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
     147            TargetInfoList sis = new TargetInfoList();
     148            for (Number targetID : targetIDs) {
     149                Target target = targetDao.getTarget(targetID);
     150                TargetInfo targetInfo = new TargetInfo();
     151                targetInfo.setLink(target.getLink());
     152                targetInfo.setRef(target.getURI());
     153                targetInfo.setVersion(target.getVersion());
     154                sis.getTargetInfo().add(targetInfo);
     155            }
     156            result.setTargets(sis);
     157
     158            result.setPermissions(getPermissionsForAnnotation(annotationID));
     159            return result;
     160        } else {
     161            return null;
     162        }
    153163    }
    154164
     
    157167    @Override
    158168    public UserWithPermissionList getPermissionsForAnnotation(Number annotationID) throws SQLException {
    159         List<Map<Number, String>> principalsPermissions = annotationDao.getPermissions(annotationID);
    160         UserWithPermissionList result = new UserWithPermissionList();
    161         List<UserWithPermission> list = result.getUserWithPermission();
    162         for (Map<Number, String> principalPermission : principalsPermissions) {
    163 
    164             Number[] principal = new Number[1];
    165             principalPermission.keySet().toArray(principal);
    166 
    167             UserWithPermission userWithPermission = new UserWithPermission();
    168             userWithPermission.setRef(userDao.getURIFromInternalID(principal[0]));
    169             userWithPermission.setPermission(Permission.fromValue(principalPermission.get(principal[0])));
    170 
    171             list.add(userWithPermission);
    172         }
    173         return result;
     169        if (annotationID != null) {
     170            List<Map<Number, String>> principalsPermissions = annotationDao.getPermissions(annotationID);
     171            UserWithPermissionList result = new UserWithPermissionList();
     172            List<UserWithPermission> list = result.getUserWithPermission();
     173            for (Map<Number, String> principalPermission : principalsPermissions) {
     174
     175                Number[] principal = new Number[1];
     176                principalPermission.keySet().toArray(principal);
     177
     178                UserWithPermission userWithPermission = new UserWithPermission();
     179                userWithPermission.setRef(userDao.getURIFromInternalID(principal[0]));
     180                userWithPermission.setPermission(Permission.fromValue(principalPermission.get(principal[0])));
     181
     182                list.add(userWithPermission);
     183            }
     184            return result;
     185        } else {
     186            return null;
     187        }
     188
    174189    }
    175190
     
    204219
    205220    @Override
    206     public List<Number> getTargetsWithNoCachedRepresentation(Number annotationID) {
     221    public List<String> getTargetsWithNoCachedRepresentation(Number annotationID) {
    207222        if (annotationID == null) {
    208223            return null;
    209224        }
    210         List<Number> result = new ArrayList<Number>();
     225        List<String> result = new ArrayList<String>();
    211226        List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID);
    212227        for (Number targetID : targetIDs) {
    213228            List<Number> versions = targetDao.getCachedRepresentations(targetID);
    214229            if (versions == null) {
    215                 result.add(targetID);
     230                result.add(targetDao.getURIFromInternalID(targetID));
    216231            } else {
    217232                if (versions.isEmpty()) {
    218                     result.add(targetID);
     233                    result.add(targetDao.getURIFromInternalID(targetID));
    219234                }
     235
     236            }
     237        }
     238        return result;
     239    }
     240
     241    @Override
     242    public List<String> getUsersWithNoInfo(Number annotationID) {
     243        if (annotationID == null) {
     244            return null;
     245        }
     246        List<String> result = new ArrayList<String>();
     247        List<Map<Number, String>> usersWithPermissions = annotationDao.getPermissions(annotationID);
     248        for (Map<Number, String> userWithPermission : usersWithPermissions) {
     249            Number[] userID = new Number[1];
     250            userWithPermission.keySet().toArray(userID);
     251            User user = userDao.getUser(userID[0]);
     252
     253            if (user.getDisplayName() == null || user.getEMail() == null) {
     254                result.add(userDao.getURIFromInternalID(userID[0]));
    220255
    221256            }
     
    299334    ///// UPDATERS /////////////////
    300335    @Override
    301     public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) throws SQLException {
    302         return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
    303     }
    304 
    305     @Override
    306     public int updatePermissions(Number annotationID, UserWithPermissionList permissionList) throws SQLException {
     336    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission, Number remoteUser) throws SQLException, Exception {
     337        if (annotationDao.getPermission(annotationID, remoteUser) != Permission.OWNER) {
     338            throw new Exception("The curent user cannot update the annotation because (s)he is not its owner");
     339        }
     340        return annotationDao.updateAnnotationPrincipalPermission(annotationID, userID, permission);
     341    }
     342
     343    @Override
     344    public int updatePermissions(Number annotationID, UserWithPermissionList permissionList, Number remoteUser) throws SQLException, Exception {
     345
     346        if (annotationDao.getPermission(annotationID, remoteUser) != Permission.OWNER) {
     347            throw new Exception("The curent user cannot update the annotation because (s)he is not its owner");
     348        }
     349
    307350        List<UserWithPermission> usersWithPermissions = permissionList.getUserWithPermission();
    308351        int result = 0;
     
    372415            throw new Exception("The current user is not allowed to update this annptation, because (s)he is not its owner");
    373416        }
    374         int updatedAnnotations = annotationDao.updateAnnotation(annotation, userID);       
     417        int updatedAnnotations = annotationDao.updateAnnotation(annotation, userID);
    375418        Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI());
    376419        int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID);
     
    388431            return userDao.addUser(user, remoteID);
    389432        }
     433    }
     434
     435    @Override
     436    public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission, Number remoteUser) throws SQLException, Exception {
     437        if (annotationDao.getPermission(annotationID, remoteUser) != Permission.OWNER) {
     438            throw new Exception("The curent user cannot update the annotation because (s)he is not its owner");
     439        }
     440        return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
    390441    }
    391442
     
    431482        result[0] = annotationDao.deleteAnnotation(annotationID);
    432483        result[3] = 0;
    433         if (targetIDs != null)  {
     484        if (targetIDs != null) {
    434485            for (Number targetID : targetIDs) {
    435486                deleteAllCachedRepresentationsOfTarget(targetID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3906 r3909  
    9797        StringBuilder sql = new StringBuilder("SELECT ");
    9898        sql.append(permission).append(" FROM ").append(permissionsTableName).append(" WHERE ").
    99                 append(annotation_id).append("  = ").append(annotationID.toString()).
     99                append(annotation_id).append("  = ").append(annotationID.toString()).append(" AND ").
    100100                append(principal_id).append("  = ").append(userID.toString()).append(" LIMIT 1");
    101101        List<Permission> result = getSimpleJdbcTemplate().query(sql.toString(), permissionRowMapper);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3906 r3909  
    2121import eu.dasish.annotation.backend.dao.DBIntegrityService;
    2222import eu.dasish.annotation.schema.Annotation;
    23 import eu.dasish.annotation.schema.AnnotationAction;
    24 import eu.dasish.annotation.schema.AnnotationActionList;
    2523import eu.dasish.annotation.schema.AnnotationActionName;
    2624import eu.dasish.annotation.schema.AnnotationInfoList;
    27 import eu.dasish.annotation.schema.AnnotationResponseBody;
    28 import eu.dasish.annotation.schema.AnnotationResponseContent;
     25import eu.dasish.annotation.schema.Action;
     26import eu.dasish.annotation.schema.ActionList;
    2927import eu.dasish.annotation.schema.ObjectFactory;
    3028import eu.dasish.annotation.schema.Permission;
     29import eu.dasish.annotation.schema.PermissionActionName;
    3130import eu.dasish.annotation.schema.UserWithPermissionList;
    3231import eu.dasish.annotation.schema.ReferenceList;
    3332import eu.dasish.annotation.schema.ResponseBody;
    34 import eu.dasish.annotation.schema.Target;
    3533import java.sql.SQLException;
    3634import java.sql.Timestamp;
     35import java.util.ArrayList;
    3736import java.util.List;
    3837import java.util.UUID;
     
    167166    public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws SQLException, Exception {
    168167        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    169         return new ObjectFactory().createResponseBody(addAnnotation(annotation));
     168
     169        //testing mode
     170        //String remoteUser = httpServletRequest.getRemoteUser();
     171        // if (remoteUser == null) { throw new Exception();}
     172        //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
     173        UUID userExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
     174
     175        Number userID = dbIntegrityService.getUserInternalIdentifier(userExternalID);
     176        Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation);
     177        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    170178    }
    171179
     
    179187        String path = uriInfo.getBaseUri().toString();
    180188        dbIntegrityService.setServiceURI(path);
    181        
    182         if (!(path+"annotations/"+externalIdentifier).equals(annotation.getURI())) {
     189
     190        if (!(path + "annotations/" + externalIdentifier).equals(annotation.getURI())) {
    183191            throw new Exception("External annotation id and the annotation id from the request body do not match");
    184192        }
    185         return new ObjectFactory().createResponseBody(updateAnnotation(annotation));
     193
     194        //testing mode
     195        //String remoteUser = httpServletRequest.getRemoteUser();
     196        // if (remoteUser == null) { throw new Exception();}
     197        //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
     198        UUID userExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
     199
     200        Number userID = dbIntegrityService.getUserInternalIdentifier(userExternalID);
     201        Number annotationID = dbIntegrityService.updateUsersAnnotation(userID, annotation);
     202        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    186203    }
    187204
    188205    @PUT
    189206    @Consumes(MediaType.APPLICATION_XML)
    190     @Produces(MediaType.TEXT_XML)
    191207    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions/{userid: " + BackendConstants.regExpIdentifier + "}")
    192     public int updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws SQLException, Exception {
    193         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     208    public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws SQLException, Exception {
     209        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     210        //String remoteUser = httpServletRequest.getRemoteUser();
     211        //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
     212        //testing mode
     213        UUID remoteUserExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
     214        Number remoteUserID = dbIntegrityService.getUserInternalIdentifier(remoteUserExternalID);
    194215        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    195216        final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
    196217        int result;
    197218        if (dbIntegrityService.getPermission(annotationID, userID) != null) {
    198             result = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission);
     219            result = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission, remoteUserID);
    199220        } else {
    200             result = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission);
    201         }
     221            result = dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission, remoteUserID);
     222        }
     223
     224        return (result + " rows are updated");
     225    }
     226
     227    @PUT
     228    @Consumes(MediaType.APPLICATION_XML)
     229    @Produces(MediaType.APPLICATION_XML)
     230    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions/")
     231    public JAXBElement<ResponseBody> updatePermissions(@PathParam("annotationid") String annotationExternalId, UserWithPermissionList permissions) throws SQLException, Exception {
     232        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     233        //String remoteUser = httpServletRequest.getRemoteUser();
     234        //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
     235        //testing mode
     236        UUID remoteUserExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
     237        Number remoteUserID = dbIntegrityService.getUserInternalIdentifier(remoteUserExternalID);
     238        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     239        int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions, remoteUserID);
     240        return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
     241    }
     242
     243    /////////////////////////////////////////
     244   
     245    private ResponseBody makeAnnotationResponseEnvelope(Number annotationID) throws SQLException {
     246        ResponseBody result = new ResponseBody();
     247        result.setPermissions(null);       
     248        Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
     249        result.setAnnotation(annotation);
     250        List<String> targetsNoCached = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID);
     251        ActionList actionList = new ActionList();
     252        result.setActionList(actionList);
     253        actionList.getAction().addAll(makeActionList(targetsNoCached,  AnnotationActionName.CREATE_CACHED_REPRESENTATION.value()));       
    202254        return result;
    203255    }
    204256
    205     @PUT
    206     @Consumes(MediaType.APPLICATION_XML)
    207     @Produces(MediaType.TEXT_XML)
    208     @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions/")
    209     public int updatePermissions(@PathParam("annotationid") String annotationExternalId, UserWithPermissionList permissions) throws SQLException, Exception {
    210         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    211 
    212         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    213         return dbIntegrityService.updatePermissions(annotationID, permissions);
    214     }
    215 
    216     private ResponseBody makeResponseEnvelope(Number annotationID) throws SQLException {
     257    /////////////////////////////////////////
     258    private ResponseBody makePermissionResponseEnvelope(Number annotationID) throws SQLException {
    217259        ResponseBody result = new ResponseBody();
    218         result.setPermissionResponse(null);
    219         AnnotationResponseBody subresult = new AnnotationResponseBody();
    220         result.setAnnotationResponse(subresult);
    221         AnnotationResponseContent content = new AnnotationResponseContent();
    222         subresult.setContent(content);
    223 
    224         if (annotationID != null) {
    225             Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
    226             content.setAnnotation(annotation);
    227             List<Number> targetsNoCached = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID);
    228             if (targetsNoCached == null) {
    229                 subresult.setActions(null);
     260        result.setAnnotation(null);       
     261        UserWithPermissionList permissions = dbIntegrityService.getPermissionsForAnnotation(annotationID);
     262        result.setPermissions(permissions);
     263        List<String> usersWithNoInfo = dbIntegrityService.getUsersWithNoInfo(annotationID);
     264        ActionList actionList = new ActionList();
     265        result.setActionList(actionList);
     266        actionList.getAction().addAll(makeActionList(usersWithNoInfo, PermissionActionName.PROVIDE_USER_INFO.value()));
     267        return result;
     268    }
     269   
     270    private List<Action>  makeActionList(List<String> resourceURIs, String message){
     271        if (resourceURIs!=null){
     272          if (resourceURIs.isEmpty()) {
     273                return (new ArrayList<Action>());
    230274            } else {
    231                 if (targetsNoCached.isEmpty()) {
    232                     subresult.setActions(new AnnotationActionList());
    233                 } else {
    234 
    235                     AnnotationActionList actions = new AnnotationActionList();
    236                     subresult.setActions(actions);
    237                     for (Number target : targetsNoCached) {
    238                         AnnotationAction action = new AnnotationAction();
    239                         actions.getAction().add(action);
    240                         action.setAction(AnnotationActionName.CREATE_CACHED_REPRESENTATION);
    241                         action.setObject(dbIntegrityService.getTargetURI(target));
    242                     }
     275                List<Action> result = new ArrayList<Action>();               
     276                for (String resourceURI : resourceURIs) {
     277                    Action action = new Action();
     278                    result.add(action);
     279                    action.setMessage(message);
     280                    action.setObject(resourceURI);
    243281                }
    244             }
    245 
    246         } else {
    247             content.setAnnotation(null);
    248         }
    249         return result;
    250     }
    251 
    252     private ResponseBody addAnnotation(Annotation annotation) throws SQLException, Exception {
    253         // Where the map remoteUSer-->externalID is saved and how to get it?
    254         String remoteUser = httpServletRequest.getRemoteUser();
    255         // if (remoteUser == null) { throw new Exception();}
    256         //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
    257         //testing mode
    258         UUID userExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
    259         Number userID = dbIntegrityService.getUserInternalIdentifier(userExternalID);
    260         Number annotationID= dbIntegrityService.addUsersAnnotation(userID, annotation);
    261         return makeResponseEnvelope(annotationID);
    262     }
    263    
    264    
    265     private ResponseBody updateAnnotation(Annotation annotation) throws SQLException, Exception {
    266         // Where the map remoteUSer-->externalID is saved and how to get it?
    267         String remoteUser = httpServletRequest.getRemoteUser();
    268         // if (remoteUser == null) { throw new Exception();}
    269         //UUID externalID = getExternalIDforREmoteUSer(remoteUser);
    270         //testing mode
    271         UUID userExternalID = UUID.fromString("00000000-0000-0000-0000-0000000000111");
    272         Number userID = dbIntegrityService.getUserInternalIdentifier(userExternalID);
    273         dbIntegrityService.updateUsersAnnotation(userID, annotation);
    274         Number annotationID = dbIntegrityService.getAnnotationInternalIdentifierFromURI(annotation.getURI());
    275         return makeResponseEnvelope(annotationID);
     282                return result;
     283            } 
     284        }
     285        else {
     286            return null;
     287        }
    276288    }
    277289}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java

    r3901 r3909  
    7676    private CachedRepresentationDao cachedRepresentationDao;   
    7777    @Autowired
    78     private TargetDao TargetDao;
     78    private TargetDao targetDao;
    7979    @Autowired
    8080    private AnnotationDao annotationDao;
     
    233233                will(returnValue(mockTargetIDs));
    234234
    235                 oneOf(TargetDao).getTarget(1);
     235                oneOf(targetDao).getTarget(1);
    236236                will(returnValue(mockTargetOne));
    237237
    238                 oneOf(TargetDao).getTarget(2);
     238                oneOf(targetDao).getTarget(2);
    239239                will(returnValue(mockTargetTwo));
    240240
     
    310310        mockeryDao.checking(new Expectations() {
    311311            {
    312                 oneOf(TargetDao).getTargetsReferringTo(word);
     312                oneOf(targetDao).getTargetsReferringTo(word);
    313313                will(returnValue(mockTargetIDs));
    314314
     
    344344                will(returnValue(TargetIDs));
    345345
    346                 oneOf(TargetDao).getURIFromInternalID(1);
     346                oneOf(targetDao).getURIFromInternalID(1);
    347347                will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets+TestBackendConstants._TEST_Target_1_EXT_ID));
    348348
    349                 oneOf(TargetDao).getURIFromInternalID(2);
     349                oneOf(targetDao).getURIFromInternalID(2);
    350350                will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets+TestBackendConstants._TEST_Target_2_EXT_ID));
    351351
     
    410410            {
    411411                // getFilteredAnnotationIds
    412                 oneOf(TargetDao).getTargetsReferringTo(word);
     412                oneOf(targetDao).getTargetsReferringTo(word);
    413413                will(returnValue(mockTargetIDs));
    414414               
     
    432432                will(returnValue(TargetIDs));
    433433               
    434                 oneOf(TargetDao).getURIFromInternalID(1);
     434                oneOf(targetDao).getURIFromInternalID(1);
    435435                will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_1_EXT_ID));
    436436               
    437                 oneOf(TargetDao).getURIFromInternalID(2);
     437                oneOf(targetDao).getURIFromInternalID(2);
    438438                will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_2_EXT_ID));
    439439                ////
     
    458458    }
    459459   
    460     @Test
    461    
     460    @Test   
    462461    public void testGetTargetsWithNoCachedRepresentation(){
    463462        System.out.println("test getTargetsWithNoCachedRepresentation");
     
    478477                will(returnValue(TargetIDs));
    479478
    480                 oneOf(TargetDao).getCachedRepresentations(5);
     479                oneOf(targetDao).getCachedRepresentations(5);
    481480                will(returnValue(cachedIDs5));
    482481               
    483                 oneOf(TargetDao).getCachedRepresentations(7);
     482                oneOf(targetDao).getCachedRepresentations(7);
    484483                will(returnValue(cachedIDs7));
    485484               
    486             }
    487         });
    488        
    489         List<Number> result = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID);
     485                oneOf(targetDao).getURIFromInternalID(7);
     486                will(returnValue("00000000-0000-0000-0000-000000000037"));
     487               
     488            }
     489        });
     490       
     491        List<String> result = dbIntegrityService.getTargetsWithNoCachedRepresentation(annotationID);
    490492        assertEquals(1, result.size());
    491         assertEquals(7, result.get(0)); // Target number 7 has no cached
     493        assertEquals("00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached
    492494    }
    493495   
     
    497499     * Test of addCachedForVersion method, of class DBIntegrityServiceImlp.
    498500     */
    499     @Test
    500    
     501    @Test   
    501502    public void testAddCachedForVersion() throws SerialException, SQLException {
    502503        System.out.println("addCachedForVersion");
     
    525526                will(returnValue(newCachedID));
    526527
    527                 one(TargetDao).addTargetCachedRepresentation(versionID, newCachedID);
     528                one(targetDao).addTargetCachedRepresentation(versionID, newCachedID);
    528529                will(returnValue(1));
    529530
     
    582583        mockeryDao.checking(new Expectations() {
    583584            {
    584                 oneOf(TargetDao).getInternalIDFromURI(mockTargetListOne.get(0).getRef());
     585                oneOf(targetDao).getInternalIDFromURI(mockTargetListOne.get(0).getRef());
    585586                will(returnValue(1));
    586587
     
    626627        mockeryDao.checking(new Expectations() {
    627628            {
    628                 oneOf(TargetDao).getInternalIDFromURI(mockTargetListTwo.get(0).getRef());
     629                oneOf(targetDao).getInternalIDFromURI(mockTargetListTwo.get(0).getRef());
    629630                will(returnValue(null));
    630631
    631                 oneOf(TargetDao).addTarget(with(aNonNull(Target.class)));
     632                oneOf(targetDao).addTarget(with(aNonNull(Target.class)));
    632633                will(returnValue(8)); //# the next new number is 8, we have already 7 Targets
    633634
    634                 oneOf(TargetDao).stringURItoExternalID(mockTargetListTwo.get(0).getRef());
     635                oneOf(targetDao).stringURItoExternalID(mockTargetListTwo.get(0).getRef());
    635636                will(returnValue(tempTargetID));
    636637
    637                 oneOf(TargetDao).getExternalID(8);
     638                oneOf(targetDao).getExternalID(8);
    638639                will(returnValue(mockNewTargetUUID));
    639640
     
    667668
    668669                //  expectations for addTargetsForannotation
    669                 oneOf(TargetDao).getInternalIDFromURI(with(aNonNull(String.class)));
     670                oneOf(targetDao).getInternalIDFromURI(with(aNonNull(String.class)));
    670671                will(returnValue(1));
    671672
     
    756757        mockeryDao.checking(new Expectations() {
    757758            {
    758                 oneOf(TargetDao).deleteTargetCachedRepresentation(5, 7);
     759                oneOf(targetDao).deleteTargetCachedRepresentation(5, 7);
    759760                will(returnValue(1));
    760761
     
    782783        mockeryDao.checking(new Expectations() {
    783784            {
    784                 oneOf(TargetDao).getCachedRepresentations(1);
     785                oneOf(targetDao).getCachedRepresentations(1);
    785786                will(returnValue(cachedList));
    786787               
    787                 oneOf(TargetDao).deleteTargetCachedRepresentation(1, 1);
     788                oneOf(targetDao).deleteTargetCachedRepresentation(1, 1);
    788789                will(returnValue(1));
    789790               
     
    791792                will(returnValue(1));
    792793               
    793                 oneOf(TargetDao).deleteTargetCachedRepresentation(1, 2);
     794                oneOf(targetDao).deleteTargetCachedRepresentation(1, 2);
    794795                will(returnValue(1));
    795796               
     
    837838                will(returnValue(1));
    838839               
    839                 oneOf(TargetDao).getCachedRepresentations(2);
     840                oneOf(targetDao).getCachedRepresentations(2);
    840841                will(returnValue(mockCachedIDs));
    841842               
    842                 oneOf(TargetDao).deleteTargetCachedRepresentation(2, 3);
     843                oneOf(targetDao).deleteTargetCachedRepresentation(2, 3);
    843844                will(returnValue(1));
    844845               
     
    846847                will(returnValue(1));
    847848               
    848                 oneOf(TargetDao).deleteTarget(2);
     849                oneOf(targetDao).deleteTarget(2);
    849850                will(returnValue(1));
    850851
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3904 r3909  
    212212        TargetInfo.setVersion("vandaag");
    213213       
    214         final List<Number> Targets = new ArrayList<Number>();
    215         Targets.add(6);
     214        final List<String> targets = new ArrayList<String>();
     215        targets.add("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036");
    216216       
    217217        final Annotation addedAnnotation = (new ObjectFactory()).createAnnotation(annotationToAdd).getValue();
     
    247247               
    248248                oneOf(daoDispatcher).getTargetsWithNoCachedRepresentation(newAnnotationID);
    249                 will(returnValue(Targets));
    250                
    251                 oneOf(daoDispatcher).getTargetURI(6);
    252                 will(returnValue("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036"));
    253             }
     249                will(returnValue(targets));
     250               
     251          }
    254252        });
    255253       
     
    262260       
    263261        JAXBElement<ResponseBody> result = annotationResource.createAnnotation(annotationToAdd);
    264         Annotation newAnnotation = result.getValue().getAnnotationResponse().getContent().getAnnotation();
    265         AnnotationActionName actionName = result.getValue().getAnnotationResponse().getActions().getAction().get(0).getAction();
     262        Annotation newAnnotation = result.getValue().getAnnotation();
     263        String actionName = result.getValue().getActionList().getAction().get(0).getMessage();
    266264        assertEquals(addedAnnotation.getOwnerRef(), newAnnotation.getOwnerRef());
    267265        assertEquals(addedAnnotation.getURI(), newAnnotation.getURI());
     
    270268        assertEquals(addedAnnotation.getTimeStamp(), newAnnotation.getTimeStamp());
    271269        assertEquals(addedAnnotation.getBody(), newAnnotation.getBody());
    272         assertEquals(AnnotationActionName.CREATE_CACHED_REPRESENTATION, actionName);
     270        assertEquals(AnnotationActionName.CREATE_CACHED_REPRESENTATION.value(), actionName);
    273271    }
    274272}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3781 r3909  
    2323import eu.dasish.annotation.backend.TestBackendConstants;
    2424import eu.dasish.annotation.schema.Annotation;
    25 import eu.dasish.annotation.schema.AnnotationResponseBody;
    26 import eu.dasish.annotation.schema.AnnotationResponseContent;
    2725import eu.dasish.annotation.schema.ObjectFactory;
    2826import eu.dasish.annotation.schema.ResponseBody;
     
    166164        ResponseBody responseBody = new ResponseBody();
    167165        final JAXBElement<ResponseBody> jaxbElement = (new ObjectFactory()).createResponseBody(responseBody);
    168         responseBody.setPermissionResponse(null);
    169         AnnotationResponseBody arb =new AnnotationResponseBody();
    170         responseBody.setAnnotationResponse(arb);
    171         arb.setActions(null);
    172         AnnotationResponseContent content = new AnnotationResponseContent();
    173         arb.setContent(content);       
     166        responseBody.setPermissions(null);
    174167        final Annotation addedAnnotation = new Annotation();
     168        responseBody.setAnnotation(addedAnnotation);
     169        responseBody.setActionList(null);
     170       
    175171        TargetInfoList TargetInfoList = new TargetInfoList();
    176172        addedAnnotation.setTargets(TargetInfoList);
     
    220216       
    221217        ResponseBody entity = response.getEntity(ResponseBody.class);
    222         Annotation entityA = entity.getAnnotationResponse().getContent().getAnnotation();
     218        Annotation entityA = entity.getAnnotation();
    223219        assertEquals(addedAnnotation.getBody(), entityA.getBody());
    224220        assertEquals(addedAnnotation.getHeadline(), entityA.getHeadline());
Note: See TracChangeset for help on using the changeset viewer.