Changeset 3909
- Timestamp:
- 10/29/13 15:30:29 (11 years ago)
- 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 133 133 * 134 134 * @param annotationID 135 * @param TargetID135 * @param targetID 136 136 * @return # updated rows in the joint table "annotations_target_Targets". 137 137 * @throws SQLException 138 138 * Connects the annotation to its target Target by adding the pair (annotationID, TargetID) to the joint table. 139 139 */ 140 public int addAnnotationTarget(Number annotationID, Number TargetID) throws SQLException;140 public int addAnnotationTarget(Number annotationID, Number targetID) throws SQLException; 141 141 142 142 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r3904 r3909 143 143 Number getTargetInternalIdentifier(UUID externalID); 144 144 145 String getTargetURI(Number annotationID);145 String getTargetURI(Number targetID); 146 146 147 UUID getTargetExternalIdentifier(Number annotationID); 147 UUID getTargetExternalIdentifier(Number targetID); 148 149 String getUserURI(Number userID); 148 150 149 151 /** … … 174 176 * 175 177 * @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); 179 183 180 184 /** … … 247 251 * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID". 248 252 */ 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; 250 254 251 255 /** … … 255 259 * @return # of rows updated or added in the table annotations_principals_permissions 256 260 */ 257 public int updatePermissions(Number annotationID, UserWithPermissionList permissionList ) throws SQLException;261 public int updatePermissions(Number annotationID, UserWithPermissionList permissionList, Number remoteUser) throws SQLException, Exception; 258 262 259 263 /** … … 299 303 Number addUser(User user, String remoteID) throws SQLException; 300 304 305 int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission, Number remoteUser) throws SQLException, Exception; 306 301 307 /** 302 308 * DELETERS -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r3906 r3909 39 39 import eu.dasish.annotation.schema.UserWithPermission; 40 40 import java.io.InputStream; 41 import java.lang.Number; 41 42 import java.sql.Blob; 42 43 import java.sql.SQLException; … … 97 98 98 99 @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); 106 112 } 107 113 … … 130 136 @Override 131 137 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 } 153 163 } 154 164 … … 157 167 @Override 158 168 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 174 189 } 175 190 … … 204 219 205 220 @Override 206 public List< Number> getTargetsWithNoCachedRepresentation(Number annotationID) {221 public List<String> getTargetsWithNoCachedRepresentation(Number annotationID) { 207 222 if (annotationID == null) { 208 223 return null; 209 224 } 210 List< Number> result = new ArrayList<Number>();225 List<String> result = new ArrayList<String>(); 211 226 List<Number> targetIDs = annotationDao.retrieveTargetIDs(annotationID); 212 227 for (Number targetID : targetIDs) { 213 228 List<Number> versions = targetDao.getCachedRepresentations(targetID); 214 229 if (versions == null) { 215 result.add(target ID);230 result.add(targetDao.getURIFromInternalID(targetID)); 216 231 } else { 217 232 if (versions.isEmpty()) { 218 result.add(target ID);233 result.add(targetDao.getURIFromInternalID(targetID)); 219 234 } 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])); 220 255 221 256 } … … 299 334 ///// UPDATERS ///////////////// 300 335 @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 307 350 List<UserWithPermission> usersWithPermissions = permissionList.getUserWithPermission(); 308 351 int result = 0; … … 372 415 throw new Exception("The current user is not allowed to update this annptation, because (s)he is not its owner"); 373 416 } 374 int updatedAnnotations = annotationDao.updateAnnotation(annotation, userID); 417 int updatedAnnotations = annotationDao.updateAnnotation(annotation, userID); 375 418 Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI()); 376 419 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); … … 388 431 return userDao.addUser(user, remoteID); 389 432 } 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); 390 441 } 391 442 … … 431 482 result[0] = annotationDao.deleteAnnotation(annotationID); 432 483 result[3] = 0; 433 if (targetIDs != null) 484 if (targetIDs != null) { 434 485 for (Number targetID : targetIDs) { 435 486 deleteAllCachedRepresentationsOfTarget(targetID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3906 r3909 97 97 StringBuilder sql = new StringBuilder("SELECT "); 98 98 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 "). 100 100 append(principal_id).append(" = ").append(userID.toString()).append(" LIMIT 1"); 101 101 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 21 21 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 22 import eu.dasish.annotation.schema.Annotation; 23 import eu.dasish.annotation.schema.AnnotationAction;24 import eu.dasish.annotation.schema.AnnotationActionList;25 23 import eu.dasish.annotation.schema.AnnotationActionName; 26 24 import eu.dasish.annotation.schema.AnnotationInfoList; 27 import eu.dasish.annotation.schema.A nnotationResponseBody;28 import eu.dasish.annotation.schema.A nnotationResponseContent;25 import eu.dasish.annotation.schema.Action; 26 import eu.dasish.annotation.schema.ActionList; 29 27 import eu.dasish.annotation.schema.ObjectFactory; 30 28 import eu.dasish.annotation.schema.Permission; 29 import eu.dasish.annotation.schema.PermissionActionName; 31 30 import eu.dasish.annotation.schema.UserWithPermissionList; 32 31 import eu.dasish.annotation.schema.ReferenceList; 33 32 import eu.dasish.annotation.schema.ResponseBody; 34 import eu.dasish.annotation.schema.Target;35 33 import java.sql.SQLException; 36 34 import java.sql.Timestamp; 35 import java.util.ArrayList; 37 36 import java.util.List; 38 37 import java.util.UUID; … … 167 166 public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws SQLException, Exception { 168 167 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)); 170 178 } 171 179 … … 179 187 String path = uriInfo.getBaseUri().toString(); 180 188 dbIntegrityService.setServiceURI(path); 181 182 if (!(path +"annotations/"+externalIdentifier).equals(annotation.getURI())) {189 190 if (!(path + "annotations/" + externalIdentifier).equals(annotation.getURI())) { 183 191 throw new Exception("External annotation id and the annotation id from the request body do not match"); 184 192 } 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)); 186 203 } 187 204 188 205 @PUT 189 206 @Consumes(MediaType.APPLICATION_XML) 190 @Produces(MediaType.TEXT_XML)191 207 @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); 194 215 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId)); 195 216 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId)); 196 217 int result; 197 218 if (dbIntegrityService.getPermission(annotationID, userID) != null) { 198 result = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission );219 result = dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission, remoteUserID); 199 220 } 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())); 202 254 return result; 203 255 } 204 256 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 { 217 259 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>()); 230 274 } 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); 243 281 } 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 } 276 288 } 277 289 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r3901 r3909 76 76 private CachedRepresentationDao cachedRepresentationDao; 77 77 @Autowired 78 private TargetDao TargetDao;78 private TargetDao targetDao; 79 79 @Autowired 80 80 private AnnotationDao annotationDao; … … 233 233 will(returnValue(mockTargetIDs)); 234 234 235 oneOf( TargetDao).getTarget(1);235 oneOf(targetDao).getTarget(1); 236 236 will(returnValue(mockTargetOne)); 237 237 238 oneOf( TargetDao).getTarget(2);238 oneOf(targetDao).getTarget(2); 239 239 will(returnValue(mockTargetTwo)); 240 240 … … 310 310 mockeryDao.checking(new Expectations() { 311 311 { 312 oneOf( TargetDao).getTargetsReferringTo(word);312 oneOf(targetDao).getTargetsReferringTo(word); 313 313 will(returnValue(mockTargetIDs)); 314 314 … … 344 344 will(returnValue(TargetIDs)); 345 345 346 oneOf( TargetDao).getURIFromInternalID(1);346 oneOf(targetDao).getURIFromInternalID(1); 347 347 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets+TestBackendConstants._TEST_Target_1_EXT_ID)); 348 348 349 oneOf( TargetDao).getURIFromInternalID(2);349 oneOf(targetDao).getURIFromInternalID(2); 350 350 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets+TestBackendConstants._TEST_Target_2_EXT_ID)); 351 351 … … 410 410 { 411 411 // getFilteredAnnotationIds 412 oneOf( TargetDao).getTargetsReferringTo(word);412 oneOf(targetDao).getTargetsReferringTo(word); 413 413 will(returnValue(mockTargetIDs)); 414 414 … … 432 432 will(returnValue(TargetIDs)); 433 433 434 oneOf( TargetDao).getURIFromInternalID(1);434 oneOf(targetDao).getURIFromInternalID(1); 435 435 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_1_EXT_ID)); 436 436 437 oneOf( TargetDao).getURIFromInternalID(2);437 oneOf(targetDao).getURIFromInternalID(2); 438 438 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_2_EXT_ID)); 439 439 //// … … 458 458 } 459 459 460 @Test 461 460 @Test 462 461 public void testGetTargetsWithNoCachedRepresentation(){ 463 462 System.out.println("test getTargetsWithNoCachedRepresentation"); … … 478 477 will(returnValue(TargetIDs)); 479 478 480 oneOf( TargetDao).getCachedRepresentations(5);479 oneOf(targetDao).getCachedRepresentations(5); 481 480 will(returnValue(cachedIDs5)); 482 481 483 oneOf( TargetDao).getCachedRepresentations(7);482 oneOf(targetDao).getCachedRepresentations(7); 484 483 will(returnValue(cachedIDs7)); 485 484 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); 490 492 assertEquals(1, result.size()); 491 assertEquals( 7, result.get(0)); // Target number 7 has no cached493 assertEquals("00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached 492 494 } 493 495 … … 497 499 * Test of addCachedForVersion method, of class DBIntegrityServiceImlp. 498 500 */ 499 @Test 500 501 @Test 501 502 public void testAddCachedForVersion() throws SerialException, SQLException { 502 503 System.out.println("addCachedForVersion"); … … 525 526 will(returnValue(newCachedID)); 526 527 527 one( TargetDao).addTargetCachedRepresentation(versionID, newCachedID);528 one(targetDao).addTargetCachedRepresentation(versionID, newCachedID); 528 529 will(returnValue(1)); 529 530 … … 582 583 mockeryDao.checking(new Expectations() { 583 584 { 584 oneOf( TargetDao).getInternalIDFromURI(mockTargetListOne.get(0).getRef());585 oneOf(targetDao).getInternalIDFromURI(mockTargetListOne.get(0).getRef()); 585 586 will(returnValue(1)); 586 587 … … 626 627 mockeryDao.checking(new Expectations() { 627 628 { 628 oneOf( TargetDao).getInternalIDFromURI(mockTargetListTwo.get(0).getRef());629 oneOf(targetDao).getInternalIDFromURI(mockTargetListTwo.get(0).getRef()); 629 630 will(returnValue(null)); 630 631 631 oneOf( TargetDao).addTarget(with(aNonNull(Target.class)));632 oneOf(targetDao).addTarget(with(aNonNull(Target.class))); 632 633 will(returnValue(8)); //# the next new number is 8, we have already 7 Targets 633 634 634 oneOf( TargetDao).stringURItoExternalID(mockTargetListTwo.get(0).getRef());635 oneOf(targetDao).stringURItoExternalID(mockTargetListTwo.get(0).getRef()); 635 636 will(returnValue(tempTargetID)); 636 637 637 oneOf( TargetDao).getExternalID(8);638 oneOf(targetDao).getExternalID(8); 638 639 will(returnValue(mockNewTargetUUID)); 639 640 … … 667 668 668 669 // expectations for addTargetsForannotation 669 oneOf( TargetDao).getInternalIDFromURI(with(aNonNull(String.class)));670 oneOf(targetDao).getInternalIDFromURI(with(aNonNull(String.class))); 670 671 will(returnValue(1)); 671 672 … … 756 757 mockeryDao.checking(new Expectations() { 757 758 { 758 oneOf( TargetDao).deleteTargetCachedRepresentation(5, 7);759 oneOf(targetDao).deleteTargetCachedRepresentation(5, 7); 759 760 will(returnValue(1)); 760 761 … … 782 783 mockeryDao.checking(new Expectations() { 783 784 { 784 oneOf( TargetDao).getCachedRepresentations(1);785 oneOf(targetDao).getCachedRepresentations(1); 785 786 will(returnValue(cachedList)); 786 787 787 oneOf( TargetDao).deleteTargetCachedRepresentation(1, 1);788 oneOf(targetDao).deleteTargetCachedRepresentation(1, 1); 788 789 will(returnValue(1)); 789 790 … … 791 792 will(returnValue(1)); 792 793 793 oneOf( TargetDao).deleteTargetCachedRepresentation(1, 2);794 oneOf(targetDao).deleteTargetCachedRepresentation(1, 2); 794 795 will(returnValue(1)); 795 796 … … 837 838 will(returnValue(1)); 838 839 839 oneOf( TargetDao).getCachedRepresentations(2);840 oneOf(targetDao).getCachedRepresentations(2); 840 841 will(returnValue(mockCachedIDs)); 841 842 842 oneOf( TargetDao).deleteTargetCachedRepresentation(2, 3);843 oneOf(targetDao).deleteTargetCachedRepresentation(2, 3); 843 844 will(returnValue(1)); 844 845 … … 846 847 will(returnValue(1)); 847 848 848 oneOf( TargetDao).deleteTarget(2);849 oneOf(targetDao).deleteTarget(2); 849 850 will(returnValue(1)); 850 851 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3904 r3909 212 212 TargetInfo.setVersion("vandaag"); 213 213 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"); 216 216 217 217 final Annotation addedAnnotation = (new ObjectFactory()).createAnnotation(annotationToAdd).getValue(); … … 247 247 248 248 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 } 254 252 }); 255 253 … … 262 260 263 261 JAXBElement<ResponseBody> result = annotationResource.createAnnotation(annotationToAdd); 264 Annotation newAnnotation = result.getValue().getAnnotation Response().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(); 266 264 assertEquals(addedAnnotation.getOwnerRef(), newAnnotation.getOwnerRef()); 267 265 assertEquals(addedAnnotation.getURI(), newAnnotation.getURI()); … … 270 268 assertEquals(addedAnnotation.getTimeStamp(), newAnnotation.getTimeStamp()); 271 269 assertEquals(addedAnnotation.getBody(), newAnnotation.getBody()); 272 assertEquals(AnnotationActionName.CREATE_CACHED_REPRESENTATION , actionName);270 assertEquals(AnnotationActionName.CREATE_CACHED_REPRESENTATION.value(), actionName); 273 271 } 274 272 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3781 r3909 23 23 import eu.dasish.annotation.backend.TestBackendConstants; 24 24 import eu.dasish.annotation.schema.Annotation; 25 import eu.dasish.annotation.schema.AnnotationResponseBody;26 import eu.dasish.annotation.schema.AnnotationResponseContent;27 25 import eu.dasish.annotation.schema.ObjectFactory; 28 26 import eu.dasish.annotation.schema.ResponseBody; … … 166 164 ResponseBody responseBody = new ResponseBody(); 167 165 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); 174 167 final Annotation addedAnnotation = new Annotation(); 168 responseBody.setAnnotation(addedAnnotation); 169 responseBody.setActionList(null); 170 175 171 TargetInfoList TargetInfoList = new TargetInfoList(); 176 172 addedAnnotation.setTargets(TargetInfoList); … … 220 216 221 217 ResponseBody entity = response.getEntity(ResponseBody.class); 222 Annotation entityA = entity.getAnnotation Response().getContent().getAnnotation();218 Annotation entityA = entity.getAnnotation(); 223 219 assertEquals(addedAnnotation.getBody(), entityA.getBody()); 224 220 assertEquals(addedAnnotation.getHeadline(), entityA.getHeadline());
Note: See TracChangeset
for help on using the changeset viewer.