Changeset 4523
- Timestamp:
- 02/14/14 16:16:01 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4495 r4523 240 240 241 241 /// notebooks /// 242 public NotebookInfoList getNotebooks(Number prinipalID, Permission permission); 243 244 public NotebookInfoList getNotebooksOwnedBy(Number principalID); 245 246 public List<UUID> getPrincipals(Number notebookID, Permission permission); 247 248 public NotebookInfo getNotebookInfo(Number notebookID); 249 250 List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc); 242 243 public Number getNotebookInternalIdentifier(UUID externalIdentifier); 244 245 public NotebookInfoList getNotebooks(Number prinipalID, String permission); 246 247 public ReferenceList getNotebooksOwnedBy(Number principalID); 248 249 public ReferenceList getPrincipals(Number notebookID, String permission); 250 251 public Notebook getNotebook(Number notebookID); 252 253 ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc); 251 254 252 255 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4521 r4523 438 438 /// notebooks /// 439 439 @Override 440 public NotebookInfoList getNotebooks(Number prinipalID, Permission permission) { 440 public Number getNotebookInternalIdentifier(UUID externalIdentifier){ 441 return notebookDao.getInternalID(externalIdentifier); 442 } 443 444 445 @Override 446 public NotebookInfoList getNotebooks(Number principalID, String permission) { 441 447 NotebookInfoList result = new NotebookInfoList(); 442 List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission); 448 if (permission.equalsIgnoreCase("reader") || permission.equalsIgnoreCase("writer")) { 449 List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, Permission.fromValue(permission)); 450 for (Number notebookID : notebookIDs) { 451 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 452 Number ownerID = notebookDao.getOwner(notebookID); 453 notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 454 result.getNotebookInfo().add(notebookInfo); 455 } 456 } else { 457 if (permission.equalsIgnoreCase("owner")) { 458 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 459 String ownerRef = userDao.getURIFromInternalID(principalID); 460 for (Number notebookID : notebookIDs) { 461 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 462 notebookInfo.setOwnerRef(ownerRef); 463 result.getNotebookInfo().add(notebookInfo); 464 } 465 } else { 466 return null; 467 } 468 } 469 return result; 470 } 471 472 @Override 473 public ReferenceList getNotebooksOwnedBy(Number principalID) { 474 ReferenceList result = new ReferenceList(); 475 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 443 476 for (Number notebookID : notebookIDs) { 444 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 445 Number ownerID = notebookDao.getOwner(notebookID); 446 notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 447 result.getNotebookInfo().add(notebookInfo); 448 } 449 450 return result; 451 } 452 453 @Override 454 public NotebookInfoList getNotebooksOwnedBy(Number principalID) { 455 NotebookInfoList result = new NotebookInfoList(); 456 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 457 String ownerRef = userDao.getURIFromInternalID(principalID); 458 for (Number notebookID : notebookIDs) { 459 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 460 notebookInfo.setOwnerRef(ownerRef); 461 result.getNotebookInfo().add(notebookInfo); 462 } 463 464 return result; 465 } 466 467 @Override 468 public List<UUID> getPrincipals(Number notebookID, Permission permission) { 469 List<UUID> result = new ArrayList<UUID>(); 470 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission); 477 String reference = notebookDao.getURIFromInternalID(notebookID); 478 result.getRef().add(reference); 479 } 480 return result; 481 } 482 483 @Override 484 public ReferenceList getPrincipals(Number notebookID, String permission) { 485 ReferenceList result = new ReferenceList(); 486 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, Permission.fromValue(permission)); 471 487 for (Number principalID : principalIDs) { 472 UUID uuid = userDao.getExternalID(principalID); 473 result.add(uuid); 474 } 475 return result; 476 } 477 478 @Override 479 public NotebookInfo getNotebookInfo(Number notebookID) { 480 NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID); 488 String reference = userDao.getURIFromInternalID(principalID); 489 result.getRef().add(reference); 490 } 491 return result; 492 } 493 494 @Override 495 public Notebook getNotebook(Number notebookID) { 496 Notebook result = notebookDao.getNotebookWithoutAnnotationsAndPermissionsAndOwner(notebookID); 497 481 498 result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID))); 499 500 ReferenceList annotations = new ReferenceList(); 501 List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); 502 for (Number annotationID : annotationIDs) { 503 annotations.getRef().add(annotationDao.getURIFromInternalID(annotationID)); 504 } 505 result.setAnnotations(annotations); 506 507 UserWithPermissionList ups = new UserWithPermissionList(); 508 List<Permission> permissions = new ArrayList<Permission>(); 509 permissions.add(Permission.READER); 510 permissions.add(Permission.WRITER); 511 for (Permission permission : permissions) { 512 List<Number> users = notebookDao.getPrincipalIDsWithPermission(notebookID, permission); 513 if (users != null) { 514 for (Number user : users) { 515 UserWithPermission up = new UserWithPermission(); 516 up.setRef(userDao.getURIFromInternalID(user)); 517 up.setPermission(permission); 518 ups.getUserWithPermission().add(up); 519 } 520 } 521 } 522 523 result.setPermissions(ups); 482 524 return result; 483 525 } … … 485 527 ///////////////////////////////////////////////////////////// 486 528 @Override 487 public List<UUID>getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) {529 public ReferenceList getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) { 488 530 List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); 489 531 … … 501 543 String direction = desc ? "DESC" : "ASC"; 502 544 List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction); 503 List<UUID> annotationUUIDs = new ArrayList<UUID>();545 ReferenceList references = new ReferenceList(); 504 546 for (Number annotationID : selectedAnnotIDs) { 505 annotationUUIDs.add(annotationDao.getExternalID(annotationID));506 } 507 return annotationUUIDs;547 references.getRef().add(annotationDao.getURIFromInternalID(annotationID)); 548 } 549 return references; 508 550 } 509 551 … … 729 771 730 772 ////////////// HELPERS //////////////////// 731 private Target createFreshTarget(TargetInfo targetInfo) {773 private Target createFreshTarget(TargetInfo targetInfo) { 732 774 Target target = new Target(); 733 775 target.setLink(targetInfo.getLink()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r4207 r4523 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 20 21 import eu.dasish.annotation.backend.dao.DBIntegrityService; 22 import eu.dasish.annotation.schema.Notebook; 23 import eu.dasish.annotation.schema.NotebookInfoList; 24 import eu.dasish.annotation.schema.ObjectFactory; 25 import eu.dasish.annotation.schema.ReferenceList; 21 26 import java.io.IOException; 27 import java.net.URI; 22 28 import java.sql.SQLException; 29 import java.util.UUID; 23 30 import javax.servlet.http.HttpServletRequest; 31 import javax.servlet.http.HttpServletResponse; 32 import javax.ws.rs.GET; 24 33 import javax.ws.rs.Path; 34 import javax.ws.rs.PathParam; 35 import javax.ws.rs.Produces; 36 import javax.ws.rs.QueryParam; 25 37 import javax.ws.rs.core.Context; 38 import javax.ws.rs.core.MediaType; 26 39 import javax.ws.rs.core.UriInfo; 27 40 import javax.ws.rs.ext.Providers; 41 import javax.xml.bind.JAXBElement; 28 42 import javax.xml.parsers.ParserConfigurationException; 43 import org.slf4j.Logger; 44 import org.slf4j.LoggerFactory; 29 45 import org.springframework.beans.factory.annotation.Autowired; 30 46 import org.springframework.stereotype.Component; … … 38 54 @Component 39 55 @Path("/notebooks") 40 @Transactional(rollbackFor ={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})56 @Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class}) 41 57 public class NotebookResource { 42 58 … … 45 61 @Context 46 62 private HttpServletRequest httpServletRequest; 47 63 @Context 64 private HttpServletResponse httpServletResponse; 48 65 @Context 49 66 private UriInfo uriInfo; 50 51 67 @Context 52 68 protected Providers providers; 69 private final Logger logger = LoggerFactory.getLogger(AnnotationResource.class); 70 private final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 53 71 54 // @GET 55 // @Produces(MediaType.TEXT_XML) 56 // @Path("") 57 // // Returns notebook-infos for the notebooks accessible to the current user. 58 // public JAXBElement<NotebookInfoList> getNotebookInfo(@Context HttpServletRequest httpServletRequest) { 59 // final NotebookInfoList notebookInfoList = new NotebookInfoList(); 60 // String remoteUser = httpServletRequest.getRemoteUser(); 61 // UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null; 62 // notebookInfoList.getNotebook().addAll(notebookDao.getNotebookInfos(remoteUserUUID)); 63 // return new ObjectFactory().createNotebookInfoList(notebookInfoList); 64 // } 65 // 66 // @GET 67 // @Produces(MediaType.TEXT_XML) 68 // @Path("test") 69 // // This is not in the standards definition and is only used for testing 70 // public JAXBElement<NotebookInfoList> getNotebookInfo(@QueryParam("userid") String userId) { 71 // final NotebookInfoList notebookInfos = new NotebookInfoList(); 72 // notebookInfos.getNotebook().addAll(notebookDao.getNotebookInfos(UUID.fromString(userId))); 73 // return new ObjectFactory().createNotebookInfoList(notebookInfos); 74 // } 75 // 76 // @GET 77 // @Produces(MediaType.TEXT_XML) 78 // @Path("owned") 79 // // Returns the list of all notebooks owned by the current logged user. 80 // public List<Notebook> getUsersNotebooks(@Context HttpServletRequest httpServletRequest) { 81 // // todo: sort out how the user id is obtained and how it is stored it the db 82 // String remoteUser = httpServletRequest.getRemoteUser(); 83 // UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null; 84 // return notebookDao.getUsersNotebooks(remoteUserUUID); 85 // } 86 // 87 // @GET 88 // @Produces("text/html") 89 // @Path("{notebookid: [a-zA-Z0-9_]*}/readers") 90 // // Returns the list of _uid_ who allowed to read the annotations from notebook. 91 // public String getReaders(@PathParam("notebookid") String notebookId) { 92 // return "readers for " + notebookId; 93 // } 94 // 95 // @GET 96 // @Produces("text/html") 97 // @Path("{notebookid: [a-zA-Z0-9_]*}/writers") 98 // // Returns the list of _uid_ that can add annotations to the notebook. 99 // public String getWriters(@PathParam("notebookid") String notebookId) { 100 // return "writers for " + notebookId; 101 // } 102 // 103 // @GET 104 // @Produces(MediaType.TEXT_XML) 105 // @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}/metadata") 106 // // Get all metadata about a specified notebook _nid_, including the information if it is private or not. 107 // public JAXBElement<NotebookInfo> getMetadata(@PathParam("notebookid") String notebookId) { 108 // NotebookInfo result = notebookDao.getNotebookInfo(notebookDao.getInternalID(UUID.fromString(notebookId))); 109 // // TODO change the name of the create method to createNotebookInfo! 110 // return new ObjectFactory().createNotebookInfo(result); 111 // 112 // } 113 // 114 // @GET 115 // @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}") 116 // /* 117 // * Get the list of all annotations _aid_-s contained within a Notebook with related metadata. 118 // * Parameters: _nid_, 119 // * optional maximumAnnotations specifies the maximum number of annotations to retrieve (default -1, all annotations), 120 // * optional startAnnotation specifies the starting point from which the annotations will be retrieved (default: -1, start from the first annotation), 121 // * optional orderby, specifies the RDF property used to order the annotations (default: dc:created ), 122 // * optional orderingMode specifies if the results should be sorted using a descending order desc=1 or an ascending order desc=0 (default: 0 ). 123 // * */ 124 // @Produces(MediaType.TEXT_XML) 125 // public List<JAXBElement<UUID>> getAllAnnotations(@PathParam("notebookid") String notebookId, @DefaultValue("-1") @QueryParam(value = "maximumAnnotations") final int maximumAnnotations, 126 // @DefaultValue("-1") @QueryParam(value = "startAnnotation") final int startAnnotation, 127 // @DefaultValue("dc:created") @QueryParam(value = "orderby") final String orderby, 128 // @DefaultValue("0") @QueryParam(value = "orderingMode") final int orderingMode) { 129 // UUID notebookUUID = UUID.fromString(notebookId); 130 // List<UUID> annotationIDs = notebookDao.getAnnotationExternalIDs(notebookUUID); 131 // List<JAXBElement<UUID>> result = new ArrayList<JAXBElement<UUID>>(); 132 // for (UUID annotationID : annotationIDs) { 133 // final JAXBElement<UUID> jaxbElement = new JAXBElement<UUID>(new QName("http://www.dasish.eu/ns/addit", "uuid"), UUID.class, null, annotationID); 134 // result.add(jaxbElement); 135 // } 136 // return result; 137 // // TODO implement optional parameters!! 138 // } 139 // 140 // @PUT 141 // @Path("{notebookid: [a-zA-Z0-9_]*}") 142 // @Consumes(MediaType.APPLICATION_XML) 143 // /* 144 // Modify metadata of _nid_. The new notebook?s name must be sent in request?s body. 145 // */ 146 // public String modifyNotebook(@PathParam("notebookid") String notebookId, Notebook notebook) { 147 // return "modifyNotebook " + notebookId + notebook.getTitle(); 148 // } 149 // 150 // @PUT 151 // @Path("{notebookid: [a-zA-Z0-9_]*}/{annotationid: [a-zA-Z0-9_]*}") 152 // /* 153 // Adds an annotation _aid_ to the list of annotations of _nid_. 154 // */ 155 // public String addAnnotation(@PathParam("notebookid") String notebookId, @PathParam("annotationid") String annotationId) { 156 // return "addAnnotation " + notebookId + " : " + annotationId; 157 // } 158 // 159 //// @PUT 160 //// @Path("{notebookid: [a-zA-Z0-9_]*}/setPrivate={isPrivate: true|false}") 161 //// /* 162 //// Sets the specified Notebook as private or not private. 163 //// */ 164 //// public String setPrivate(@PathParam("notebookid") String notebookId, @PathParam("isPrivate") String isPrivate) { 165 //// return "modifyNotebook " + notebookId + " : " + isPrivate; 166 //// } 167 // @POST 168 // @Path("") 169 // /* 170 // * Creates a new notebook. 171 // * This API returns the _nid_ of the created Notebook in response?s payload and the full URL of the notebook adding a Location header into the HTTP response. 172 // * The name of the new notebook can be specified sending a specific payload. 173 // */ 174 // public String createNotebook(@Context HttpServletRequest httpServletRequest) throws URISyntaxException { 175 // String remoteUser = httpServletRequest.getRemoteUser(); 176 // UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null; 177 // UUID notebookId = notebookDao.addNotebook(remoteUserUUID, null); 178 // final URI serverUri = new URI(httpServletRequest.getRequestURL().toString()); 179 // String fullUrlString = "/api/notebooks/" + notebookId.toString(); 180 // return serverUri.resolve(fullUrlString).toString(); 181 // } 182 // 183 // @POST 184 // @Path("{notebookid: [a-zA-Z0-9_]*}") 185 // /* 186 // * Creates a new annotation in _nid_. 187 // * The content of an annotation is given in the request body. In fact this is a short cut of two actions: 188 // */ 189 // public String createAnnotation() { 190 // String notebookId = "_nid_"; 191 // String fullUrlString = "api/notebooks/_nid_"; 192 // return "annotation " + notebookId + " : " + fullUrlString; 193 // } 194 // 195 // @DELETE 196 // @Path("{notebookid: [a-zA-Z0-9_-]*}") 197 // /* 198 // Delete _nid_. Annotations stay, they just lose connection to _nid_.<br> 199 // */ 200 // public String deleteNotebook(@PathParam("notebookid") UUID notebookId) { 201 // // todo: sort out how the id string passsed in here is mapped eg db column for _nid_ 202 // return Integer.toString(notebookDao.deleteNotebook(notebookId)); 203 // } 72 public NotebookResource() { 73 } 74 75 @GET 76 @Produces(MediaType.APPLICATION_XML) 77 @Path("") 78 @Transactional(readOnly = true) 79 public JAXBElement<NotebookInfoList> getNotebookInfos(@QueryParam("permission") String permissionMode) throws IOException { 80 81 URI baseURI = uriInfo.getBaseUri(); 82 String baseURIstr = baseURI.toString(); 83 dbIntegrityService.setServiceURI(baseURIstr); 84 85 String remoteUser = httpServletRequest.getRemoteUser(); 86 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 87 if (userID != null) { 88 if (permissionMode.equalsIgnoreCase("reader") || permissionMode.equalsIgnoreCase("writer") || permissionMode.equalsIgnoreCase("owner")) { 89 NotebookInfoList notebookInfos = dbIntegrityService.getNotebooks(userID, permissionMode); 90 return new ObjectFactory().createNotebookInfoList(notebookInfos); 91 } else { 92 loggerServer.debug(httpServletResponse.SC_BAD_REQUEST + ": '" + permissionMode + "' is an invalid permission value, which must be either owner, or reader, or writer."); 93 httpServletResponse.sendError(httpServletResponse.SC_BAD_REQUEST, permissionMode + "' is an invalid permission value, which must be either owner, or reader, or writer."); 94 return null; 95 } 96 } else { 97 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 98 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 99 return null; 100 } 101 } 102 103 @GET 104 @Produces(MediaType.APPLICATION_XML) 105 @Path("owned") 106 @Transactional(readOnly = true) 107 public JAXBElement<ReferenceList> getOwnedNotebooks() throws IOException { 108 109 URI baseURI = uriInfo.getBaseUri(); 110 String baseURIstr = baseURI.toString(); 111 dbIntegrityService.setServiceURI(baseURIstr); 112 113 String remoteUser = httpServletRequest.getRemoteUser(); 114 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 115 if (userID != null) { 116 ReferenceList references = dbIntegrityService.getNotebooksOwnedBy(userID); 117 return new ObjectFactory().createReferenceList(references); 118 } else { 119 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 120 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 121 return null; 122 } 123 } 124 125 @GET 126 @Produces(MediaType.APPLICATION_XML) 127 @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}/targets") 128 @Transactional(readOnly = true) 129 public JAXBElement<Notebook> getNotebook(@PathParam("notebookid") String externalIdentifier) throws IOException { 130 131 URI baseURI = uriInfo.getBaseUri(); 132 String baseURIstr = baseURI.toString(); 133 dbIntegrityService.setServiceURI(baseURIstr); 134 135 String remoteUser = httpServletRequest.getRemoteUser(); 136 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 137 if (userID != null) { 138 Number notebookID = dbIntegrityService.getNotebookInternalIdentifier(UUID.fromString(externalIdentifier)); 139 if (notebookID != null) { 140 Notebook notebook = dbIntegrityService.getNotebook(notebookID); 141 return new ObjectFactory().createNotebook(notebook); 142 } else { 143 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The notebook with the given id " + externalIdentifier + " is not found in the database"); 144 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The notebook with the given id " + externalIdentifier + " is not found in the database"); 145 return null; 146 } 147 } else { 148 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 149 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 150 return null; 151 } 152 } 204 153 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4521 r4523 50 50 import java.util.UUID; 51 51 import javax.sql.rowset.serial.SerialException; 52 import javax.xml.datatype.DatatypeConfigurationException; 52 53 import javax.xml.datatype.DatatypeFactory; 53 54 import javax.xml.datatype.XMLGregorianCalendar; … … 825 826 * Getters 826 827 */ 827 /// notebooks /// 828 //public NotebookInfoList getNotebooks(Number prinipalID, Permission permission); 829 // NotebookInfoList result = new NotebookInfoList(); 830 // List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission); 831 // for (Number notebookID : notebookIDs) { 832 // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 833 // Number ownerID = notebookDao.getOwner(notebookID); 834 // notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 835 // result.getNotebookInfo().add(notebookInfo); 828 829 // public Number getNotebookInternalIdentifier(UUID externalIdentifier){ 830 // return notebookDao.getInternalID(externalIdentifier); 831 // } 832 833 @Test 834 public void testGetNotebookInternalIdentifier() { 835 836 final UUID mockUUID = UUID.fromString("00000000-0000-0000-0000-000000000021"); 837 838 mockeryDao.checking(new Expectations() { 839 { 840 oneOf(notebookDao).getInternalID(mockUUID); 841 will(returnValue(1)); 842 } 843 }); 844 845 assertEquals(1, dbIntegrityService.getNotebookInternalIdentifier(mockUUID)); 846 847 } 848 849 850 851 // public NotebookInfoList getNotebooks(Number principalID, String permission) { 852 // NotebookInfoList result = new NotebookInfoList(); 853 // if (permission.equalsIgnoreCase("reader") || permission.equalsIgnoreCase("writer")) { 854 // List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, Permission.fromValue(permission)); 855 // for (Number notebookID : notebookIDs) { 856 // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 857 // Number ownerID = notebookDao.getOwner(notebookID); 858 // notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 859 // result.getNotebookInfo().add(notebookInfo); 860 // } 861 // } else { 862 // if (permission.equalsIgnoreCase("owner")) { 863 // List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 864 // String ownerRef = userDao.getURIFromInternalID(principalID); 865 // for (Number notebookID : notebookIDs) { 866 // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 867 // notebookInfo.setOwnerRef(ownerRef); 868 // result.getNotebookInfo().add(notebookInfo); 869 // } 870 // } else { 871 // return null; 872 // } 836 873 // } 837 //838 874 // return result; 839 @Test 840 public void testGetNotebooks() { 875 // } 876 @Test 877 public void testGetNotebooksReaderBranch() { 841 878 842 879 final List<Number> mockNotebookIDs = new ArrayList<Number>(); … … 864 901 }); 865 902 866 NotebookInfoList result = dbIntegrityService.getNotebooks(3, Permission.READER);903 NotebookInfoList result = dbIntegrityService.getNotebooks(3, "reader"); 867 904 assertEquals("00000000-0000-0000-0000-000000000011", result.getNotebookInfo().get(0).getRef()); 868 905 assertEquals("00000000-0000-0000-0000-000000000111", result.getNotebookInfo().get(0).getOwnerRef()); … … 871 908 } 872 909 873 ; 874 875 876 /*public NotebookInfoList getNotebooksOwnedBy(Number principalID){ 877 NotebookInfoList result = new NotebookInfoList(); 878 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 879 String ownerRef = userDao.getURIFromInternalID(principalID); 880 for (Number notebookID : notebookIDs) { 881 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 882 notebookInfo.setOwnerRef(ownerRef); 883 result.getNotebookInfo().add(notebookInfo); 884 } 885 886 return result; 887 }*/ 888 889 @Test 890 public void testGetNotebooksOwnedBy() { 910 @Test 911 public void testGetNotebooksOwnerBranch() { 891 912 892 913 final List<Number> mockNotebookIDs = new ArrayList<Number>(); … … 919 940 }); 920 941 921 NotebookInfoList result = dbIntegrityService.getNotebooks OwnedBy(3);942 NotebookInfoList result = dbIntegrityService.getNotebooks(3, "owner"); 922 943 assertEquals("00000000-0000-0000-0000-000000000013", result.getNotebookInfo().get(0).getRef()); 923 944 assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(0).getOwnerRef()); … … 929 950 } 930 951 931 ; 932 952 // public ReferenceList getNotebooksOwnedBy(Number principalID) { 953 // ReferenceList result = new ReferenceList(); 954 // List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 955 // for (Number notebookID : notebookIDs) { 956 // String reference = notebookDao.getURIFromInternalID(notebookID); 957 // result.getRef().add(reference); 958 // } 959 // return result; 960 // } 961 @Test 962 public void testGetNotebooksOwnedBy() { 963 964 final List<Number> mockNotebookIDs = new ArrayList<Number>(); 965 mockNotebookIDs.add(3); 966 mockNotebookIDs.add(4); 967 968 mockeryDao.checking(new Expectations() { 969 { 970 oneOf(notebookDao).getNotebookIDsOwnedBy(3); 971 will(returnValue(mockNotebookIDs)); 972 973 oneOf(notebookDao).getURIFromInternalID(3); 974 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000013")); 975 976 oneOf(notebookDao).getURIFromInternalID(4); 977 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000014")); 978 979 } 980 }); 981 982 ReferenceList result = dbIntegrityService.getNotebooksOwnedBy(3); 983 assertEquals(2, result.getRef().size()); 984 assertEquals(TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000013", result.getRef().get(0)); 985 assertEquals(TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000014", result.getRef().get(1)); 986 } 933 987 934 988 /* 935 public List<UUID> getPrincipals(Number notebookID, Permissionpermission) {936 List<UUID> result = new ArrayList<UUID>();937 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission);989 public ReferenceList getPrincipals(Number notebookID, String permission) { 990 ReferenceList result = new ReferenceList(); 991 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, Permission.fromValue(permission)); 938 992 for (Number principalID : principalIDs) { 939 UUID uuid = userDao.getExternalID(principalID);940 result. add(uuid);993 String reference = userDao.getURIFromInternalID(principalID); 994 result.getRef().add(reference); 941 995 } 942 996 return result; 943 } */944 997 } 998 }*/ 945 999 @Test 946 1000 public void testGetPrincipals() { … … 948 1002 mockPrincipalIDs.add(2); 949 1003 mockPrincipalIDs.add(4); 950 951 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 952 mockNotebookInfo.setRef("00000000-0000-0000-0000-000000000011"); 953 mockNotebookInfo.setTitle("Notebook 1"); 954 1004 955 1005 mockeryDao.checking(new Expectations() { 956 1006 { … … 958 1008 will(returnValue(mockPrincipalIDs)); 959 1009 960 oneOf(userDao).getExternalID(2); 961 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000112"))); 962 963 oneOf(userDao).getExternalID(4); 964 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000114"))); 965 966 967 } 968 }); 969 970 List<UUID> result = dbIntegrityService.getPrincipals(1, Permission.WRITER); 971 assertEquals("00000000-0000-0000-0000-000000000112", result.get(0).toString()); 972 assertEquals("00000000-0000-0000-0000-000000000114", result.get(1).toString()); 973 974 } 975 976 977 // public NotebookInfo getNotebookInfo(Number notebookID) { 978 // NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID); 1010 oneOf(userDao).getURIFromInternalID(2); 1011 will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000112")); 1012 1013 oneOf(userDao).getURIFromInternalID(4); 1014 will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000114")); 1015 1016 1017 } 1018 }); 1019 1020 ReferenceList result = dbIntegrityService.getPrincipals(1, "writer"); 1021 assertEquals("serviceURI/users/00000000-0000-0000-0000-000000000112", result.getRef().get(0).toString()); 1022 assertEquals("serviceURI/users/00000000-0000-0000-0000-000000000114", result.getRef().get(1).toString()); 1023 1024 } 1025 1026 // @Override 1027 // public Notebook getNotebook(Number notebookID) { 1028 // Notebook result = notebookDao.getNotebookWithoutAnnotationsAndPermissionsAndOwner(notebookID); 1029 // 979 1030 // result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID))); 1031 // 1032 // ReferenceList annotations = new ReferenceList(); 1033 // List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); 1034 // for (Number annotationID : annotationIDs) { 1035 // annotations.getRef().add(annotationDao.getURIFromInternalID(annotationID)); 1036 // } 1037 // result.setAnnotations(annotations); 1038 // 1039 // UserWithPermissionList ups = new UserWithPermissionList(); 1040 // List<Permission> permissions = new ArrayList<Permission>(); 1041 // permissions.add(Permission.READER); 1042 // permissions.add(Permission.WRITER); 1043 // for (Permission permission : permissions) { 1044 // List<Number> users = notebookDao.getPrincipalIDsWithPermission(notebookID, permission); 1045 // if (users != null) { 1046 // for (Number user : users) { 1047 // UserWithPermission up = new UserWithPermission(); 1048 // up.setRef(userDao.getURIFromInternalID(user)); 1049 // up.setPermission(permission); 1050 // ups.getUserWithPermission().add(up); 1051 // } 1052 // } 1053 // } 1054 // 1055 // result.setPermissions(ups); 980 1056 // return result; 981 1057 // } 982 983 984 @Test 985 public void testGetNotebookInfo() { 986 987 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 988 mockNotebookInfo.setRef("00000000-0000-0000-0000-000000000011"); 989 mockNotebookInfo.setTitle("Notebook 1"); 990 991 mockeryDao.checking(new Expectations() { 992 { 993 oneOf(notebookDao).getNotebookInfoWithoutOwner(1); 994 will(returnValue(mockNotebookInfo)); 1058 1059 1060 @Test 1061 public void testGetNotebook() throws DatatypeConfigurationException{ 1062 1063 final Notebook mockNotebook = new Notebook(); 1064 mockNotebook.setURI("serviceURI/notebooks/00000000-0000-0000-0000-000000000012"); 1065 mockNotebook.setTitle("Notebook 2"); 1066 mockNotebook.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2014-02-12T09:25:00.383000Z")); 1067 1068 final List<Number> mockAnnotations = new ArrayList<Number>(); 1069 mockAnnotations.add(3); 1070 1071 final List<Number> mockReaders = new ArrayList<Number>(); 1072 mockReaders.add(1); 1073 1074 final List<Number> mockWriters = new ArrayList<Number>(); 1075 mockWriters.add(3); 1076 1077 mockeryDao.checking(new Expectations() { 1078 { 1079 oneOf(notebookDao).getNotebookWithoutAnnotationsAndPermissionsAndOwner(2); 1080 will(returnValue(mockNotebook)); 1081 1082 oneOf(notebookDao).getOwner(2); 1083 will(returnValue(2)); 1084 1085 oneOf(userDao).getURIFromInternalID(2); 1086 will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000112")); 1087 1088 oneOf(notebookDao).getAnnotations(2); 1089 will(returnValue(mockAnnotations)); 995 1090 996 oneOf(notebookDao).getOwner(1); 997 will(returnValue(1)); 998 1091 oneOf(annotationDao).getURIFromInternalID(3); 1092 will(returnValue("serviceURI/annotations/00000000-0000-0000-0000-000000000023")); 1093 1094 oneOf(notebookDao).getPrincipalIDsWithPermission(2, Permission.READER); 1095 will(returnValue(mockReaders)); 1096 999 1097 oneOf(userDao).getURIFromInternalID(1); 1000 will(returnValue(" 00000000-0000-0000-0000-000000000111"));1098 will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000111")); 1001 1099 1002 1003 } 1004 }); 1005 1006 NotebookInfo result = dbIntegrityService.getNotebookInfo(1); 1007 assertEquals("00000000-0000-0000-0000-000000000011", result.getRef()); 1008 assertEquals("00000000-0000-0000-0000-000000000111", result.getOwnerRef()); 1009 assertEquals("Notebook 1", result.getTitle()); 1010 1011 } 1012 1013 1100 oneOf(notebookDao).getPrincipalIDsWithPermission(2, Permission.WRITER); 1101 will(returnValue(mockWriters)); 1102 1103 oneOf(userDao).getURIFromInternalID(3); 1104 will(returnValue("serviceURI/users/00000000-0000-0000-0000-000000000113")); 1105 1106 1107 1108 } 1109 }); 1110 1111 Notebook result = dbIntegrityService.getNotebook(2); 1112 assertEquals("serviceURI/notebooks/00000000-0000-0000-0000-000000000012", result.getURI()); 1113 assertEquals("serviceURI/users/00000000-0000-0000-0000-000000000112", result.getOwnerRef()); 1114 assertEquals("2014-02-12T09:25:00.383000Z", result.getLastModified().toString()); 1115 assertEquals("Notebook 2", result.getTitle()); 1116 assertEquals(1, result.getAnnotations().getRef().size()); 1117 assertEquals("serviceURI/annotations/00000000-0000-0000-0000-000000000023", result.getAnnotations().getRef().get(0)); 1118 assertEquals(2, result.getPermissions().getUserWithPermission().size()); 1119 assertEquals("serviceURI/users/00000000-0000-0000-0000-000000000111", result.getPermissions().getUserWithPermission().get(0).getRef()); 1120 assertEquals("reader", result.getPermissions().getUserWithPermission().get(0).getPermission().value()); 1121 assertEquals("serviceURI/users/00000000-0000-0000-0000-000000000113", result.getPermissions().getUserWithPermission().get(1).getRef()); 1122 assertEquals("writer", result.getPermissions().getUserWithPermission().get(1).getPermission().value()); 1123 1124 } 1125 1014 1126 // public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) { 1015 1127 // List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); … … 1034 1146 // return annotationUUIDs; 1035 1147 // } 1036 1037 1038 1148 @Test 1039 1149 public void testAnnotationsForNotebook() { … … 1046 1156 oneOf(notebookDao).getAnnotations(1); 1047 1157 will(returnValue(mockAnnotationIDs)); 1048 1158 1049 1159 oneOf(annotationDao).sublistOrderedAnnotationIDs(mockAnnotationIDs, 0, 3, "last_modified", "DESC"); 1050 1160 will(returnValue(mockAnnotationIDs)); 1051 1161 1052 oneOf(annotationDao).get ExternalID(1);1053 will(returnValue( UUID.fromString("00000000-0000-0000-0000-000000000021")));1054 1055 oneOf(annotationDao).get ExternalID(2);1056 will(returnValue( UUID.fromString("00000000-0000-0000-0000-000000000022")));1057 1058 1059 } 1060 });1061 1062 List<UUID> result = dbIntegrityService.getAnnotationsForNotebook(1, -1, 3, "last_modified", true); 1063 assertEquals("00000000-0000-0000-0000-000000000021", result.get(0).toString());1064 assertEquals( "00000000-0000-0000-0000-000000000022", result.get(1).toString());1065 1066 }1067 1068 1069 /** 1070 * Updaters1071 */1072 1162 oneOf(annotationDao).getURIFromInternalID(1); 1163 will(returnValue("serviceURI/annotations/00000000-0000-0000-0000-000000000021")); 1164 1165 oneOf(annotationDao).getURIFromInternalID(2); 1166 will(returnValue("serviceURI/annotations/00000000-0000-0000-0000-000000000022")); 1167 1168 1169 1170 } 1171 }); 1172 1173 ReferenceList result = dbIntegrityService.getAnnotationsForNotebook(1, -1, 3, "last_modified", true); 1174 assertEquals(2, result.getRef().size()); 1175 assertEquals("serviceURI/annotations/00000000-0000-0000-0000-000000000021", result.getRef().get(0).toString()); 1176 assertEquals("serviceURI/annotations/00000000-0000-0000-0000-000000000022", result.getRef().get(1).toString()); 1177 1178 } 1179 1180 /** 1181 * Updaters 1182 */ 1073 1183 // public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) { 1074 1184 // Number ownerID = userDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef()); 1075 1185 // return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID); 1076 1186 // } 1077 1078 1079 @Test 1080 public void testUpdateNotebookMetadata() { 1081 1082 final NotebookInfo mockNotebookInfo= new NotebookInfo(); 1083 mockNotebookInfo.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_users+"00000000-0000-0000-0000-000000000113"); 1187 @Test 1188 public void testUpdateNotebookMetadata() { 1189 1190 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 1191 mockNotebookInfo.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"); 1084 1192 mockNotebookInfo.setTitle("New Title"); 1085 1193 1086 1194 mockeryDao.checking(new Expectations() { 1087 1195 { 1088 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users +"00000000-0000-0000-0000-000000000113");1196 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"); 1089 1197 will(returnValue(3)); 1090 1198 1091 1199 oneOf(notebookDao).updateNotebookMetadata(1, "New Title", 3); 1092 1200 will(returnValue(true)); … … 1096 1204 boolean result = dbIntegrityService.updateNotebookMetadata(1, mockNotebookInfo); 1097 1205 assertTrue(result); 1098 } 1099 1206 } 1100 1207 1101 1208 // … … 1103 1210 // return notebookDao.addAnnotationToNotebook(notebookID, annotationID); 1104 1211 // } 1105 1106 @Test 1107 public void testAddAnnotationToNotebook() { 1108 1109 mockeryDao.checking(new Expectations() { 1110 { 1111 1212 @Test 1213 public void testAddAnnotationToNotebook() { 1214 1215 mockeryDao.checking(new Expectations() { 1216 { 1217 1112 1218 oneOf(notebookDao).addAnnotationToNotebook(1, 3); 1113 1219 will(returnValue(true)); … … 1115 1221 }); 1116 1222 1117 assertTrue(dbIntegrityService.addAnnotationToNotebook(1,3)); 1118 } 1119 1120 1121 /** 1122 * Adders 1123 */ 1124 1223 assertTrue(dbIntegrityService.addAnnotationToNotebook(1, 3)); 1224 } 1225 1226 /** 1227 * Adders 1228 */ 1125 1229 // public Number createNotebook(Notebook notebook, Number ownerID) { 1126 1230 // Number notebookID = notebookDao.createNotebookWithoutPermissionsAndAnnotations(notebook, ownerID); … … 1134 1238 // return notebookID; 1135 1239 // } 1136 1137 1138 1240 @Test 1139 1241 public void testCreateNotebook() { 1140 1242 1141 1243 final Notebook notebook = new Notebook(); 1142 1244 notebook.setOwnerRef("tmpXXX"); 1143 1245 notebook.setTitle("(Almost) Copy of Notebook 1"); 1144 notebook.setURI("tmpYYY"); 1145 1246 notebook.setURI("tmpYYY"); 1247 1146 1248 UserWithPermissionList permissions = new UserWithPermissionList(); 1147 1249 UserWithPermission p1 = new UserWithPermission(); … … 1154 1256 permissions.getUserWithPermission().add(p2); 1155 1257 notebook.setPermissions(permissions); 1156 1258 1157 1259 mockeryDao.checking(new Expectations() { 1158 1260 { 1159 1261 oneOf(notebookDao).createNotebookWithoutPermissionsAndAnnotations(notebook, 1); 1160 1262 will(returnValue(5)); 1161 1263 1162 1264 oneOf(notebookDao).setOwner(5, 1); 1163 1265 will(returnValue(true)); 1164 1266 1165 1267 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000112"); 1166 1268 will(returnValue(2)); 1167 1269 1168 1270 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"); 1169 1271 will(returnValue(3)); 1170 1171 oneOf(notebookDao).addPermissionToNotebook(5, 2, Permission.WRITER);1172 will(returnValue(true));1173 1272 1273 oneOf(notebookDao).addPermissionToNotebook(5, 2, Permission.WRITER); 1274 will(returnValue(true)); 1275 1174 1276 oneOf(notebookDao).addPermissionToNotebook(5, 3, Permission.READER); 1175 will(returnValue(true));1176 1277 will(returnValue(true)); 1278 1177 1279 } 1178 1280 }); … … 1182 1284 1183 1285 } 1184 1185 1186 1187 1286 1188 1287 // public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) { 1189 1288 // Number newAnnotationID = this.addUsersAnnotation(ownerID, annotation); 1190 1289 // return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID); 1191 1290 // } 1192 1193 1291 @Test 1194 1292 public void testCreateAnnotationInNotebook() { 1195 1293 1196 1294 final Annotation testAnnotation = testInstances.getAnnotationToAdd(); 1197 1295 1198 1296 mockeryDao.checking(new Expectations() { 1199 1297 { … … 1212 1310 1213 1311 ///////////////////////// 1214 1312 1215 1313 oneOf(notebookDao).addAnnotationToNotebook(1, 5); 1216 1314 will(returnValue(true)); … … 1220 1318 assertTrue(dbIntegrityService.createAnnotationInNotebook(1, testAnnotation, 3)); 1221 1319 1222 } 1223 1224 /** 1225 * Deleters 1226 */ 1227 1320 } 1321 1322 /** 1323 * Deleters 1324 */ 1228 1325 // public boolean deleteNotebook(Number notebookID) { 1229 1326 // if (notebookDao.deleteAllPermissionsForNotebook(notebookID) || notebookDao.deleteAllAnnotationsFromNotebook(notebookID)) { … … 1234 1331 // 1235 1332 // } 1236 1237 @Test 1238 public void testDeleteNotebook() { 1239 1240 mockeryDao.checking(new Expectations() { 1241 { 1242 1333 @Test 1334 public void testDeleteNotebook() { 1335 1336 mockeryDao.checking(new Expectations() { 1337 { 1338 1243 1339 oneOf(notebookDao).deleteAllPermissionsForNotebook(1); 1244 1340 will(returnValue(true)); 1245 1341 1246 1342 oneOf(notebookDao).deleteAllAnnotationsFromNotebook(1); 1247 1343 will(returnValue(true)); 1248 1344 1249 1345 oneOf(notebookDao).deleteNotebook(1); 1250 1346 will(returnValue(true)); … … 1253 1349 1254 1350 assertTrue(dbIntegrityService.deleteNotebook(1)); 1255 } 1256 1351 } 1257 1352 }
Note: See TracChangeset
for help on using the changeset viewer.