- Timestamp:
- 06/24/14 17:43:30 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 3 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBDispatcher.java
r5186 r5385 51 51 public interface DBDispatcher { 52 52 53 void set ServiceURI(String serviceURI);53 void setResourcesPaths(String relServiceURI); 54 54 55 55 /** … … 59 59 Number getResourceInternalIdentifier(UUID externalID, Resource resource) throws NotInDataBaseException; 60 60 61 Number getResourceInternalIdentifierFromURI(String uri, Resource resource) throws NotInDataBaseException;62 63 61 UUID getResourceExternalIdentifier(Number resourceID, Resource resource); 64 65 String getResourceURI(Number resourceID, Resource resource);66 62 67 63 PermissionList getPermissions(Number resourceID, Resource resource); … … 179 175 180 176 Number getPrincipalInternalIDFromRemoteID(String remoteID) throws NotInDataBaseException; 177 178 UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException; 181 179 182 180 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/PrincipalDao.java
r5186 r5385 51 51 public Number getPrincipalInternalIDFromRemoteID(String remoteID) throws NotInDataBaseException; 52 52 53 public UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException; 54 55 53 56 public List<Number> getPrincipalIDsWithAccessForNotebook(Number notebookID, Access access); 54 57 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ResourceDao.java
r5086 r5385 30 30 public interface ResourceDao { 31 31 32 void set ServiceURI(String serviceURI);32 void setResourcePath(String relResourcePath); 33 33 34 34 Number getInternalID(UUID externalId) throws NotInDataBaseException; 35 35 36 Number getInternalIDFromURI(String uri) throws NotInDataBaseException;37 38 36 UUID getExternalID(Number internalId); 39 37 40 String externalIDtoURI(String externalID); 41 42 /** 43 * 44 * @param stringURI 45 * @return returns the extranlID which is a suffix of stringURI 46 */ 47 String stringURItoExternalID(String stringURI); 48 38 39 49 40 /** 50 41 * … … 53 44 * with internalID 54 45 */ 55 String getURIFromInternalID(Number internalID); 46 String getHrefFromInternalID(Number internalID); 47 48 Number getInternalIDFromHref(String href) throws NotInDataBaseException; 56 49 57 50 List<Map<Number, String>> getPermissions(Number resourceID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/TargetDao.java
r5138 r5385 118 118 /** 119 119 * 120 * @param TargetID120 * @param targetID 121 121 * @return # deleted rows in the table "Targets_cached_representation" when 122 122 * deleting the pair (TargetID, chachedID) -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherImlp.java
r5203 r5385 106 106 107 107 @Override 108 public void set ServiceURI(String serviceURI) {109 principalDao.set ServiceURI(serviceURI + "principals/");110 cachedRepresentationDao.set ServiceURI(serviceURI + "cached/");111 targetDao.set ServiceURI(serviceURI + "targets/");112 annotationDao.set ServiceURI(serviceURI + "annotations/");113 notebookDao.set ServiceURI(serviceURI + "notebooks/");108 public void setResourcesPaths(String relServiceURI) { 109 principalDao.setResourcePath(relServiceURI + "/principals/"); 110 cachedRepresentationDao.setResourcePath(relServiceURI + "/cached/"); 111 targetDao.setResourcePath(relServiceURI + "/targets/"); 112 annotationDao.setResourcePath(relServiceURI + "/annotations/"); 113 notebookDao.setResourcePath(relServiceURI + "/notebooks/"); 114 114 } 115 115 … … 120 120 } 121 121 122 @Override 123 public Number getResourceInternalIdentifierFromURI(String uri, Resource resource) throws NotInDataBaseException { 124 return this.getDao(resource).getInternalIDFromURI(uri); 125 } 126 122 127 123 @Override 128 124 public UUID getResourceExternalIdentifier(Number resourceID, Resource resource) { … … 130 126 } 131 127 132 @Override 133 public String getResourceURI(Number resourceID, Resource resource) { 134 return this.getDao(resource).getURIFromInternalID(resourceID); 135 } 136 128 137 129 @Override 138 130 public Annotation getAnnotation(Number annotationID) { 139 131 Annotation result = annotationDao.getAnnotationWithoutTargetsAndPemissions(annotationID); 140 result.setOwner Ref(principalDao.getURIFromInternalID(annotationDao.getOwner(annotationID)));132 result.setOwnerHref(principalDao.getHrefFromInternalID(annotationDao.getOwner(annotationID))); 141 133 List<Number> targetIDs = targetDao.getTargetIDs(annotationID); 142 134 TargetInfoList sis = new TargetInfoList(); 143 135 for (Number targetID : targetIDs) { 144 TargetInfo targetInfo = getTargetInfoFromTarget(targetDao.getTarget(targetID));136 TargetInfo targetInfo = this.getTargetInfoFromTarget(targetDao.getTarget(targetID)); 145 137 sis.getTargetInfo().add(targetInfo); 146 138 } … … 173 165 principalAccess.keySet().toArray(principal); 174 166 Permission permission = new Permission(); 175 permission.setPrincipal Ref(principalDao.getURIFromInternalID(principal[0]));167 permission.setPrincipalHref(principalDao.getHrefFromInternalID(principal[0])); 176 168 permission.setLevel(Access.fromValue(principalAccess.get(principal[0]))); 177 169 list.add(permission); … … 311 303 List<Number> targetIDs = targetDao.getTargetIDs(annotationID); 312 304 for (Number targetID : targetIDs) { 313 result.get Ref().add(targetDao.getURIFromInternalID(targetID));305 result.getHref().add(targetDao.getHrefFromInternalID(targetID)); 314 306 } 315 307 return result; … … 324 316 List<Number> versions = cachedRepresentationDao.getCachedRepresentationsForTarget(targetID); 325 317 if (versions.isEmpty()) { 326 result.add(targetDao.get URIFromInternalID(targetID));318 result.add(targetDao.getHrefFromInternalID(targetID)); 327 319 } 328 320 } … … 339 331 Principal principal = principalDao.getPrincipal(principalID[0]); 340 332 if (principal.getDisplayName() == null || principal.getDisplayName().trim().isEmpty() || principal.getEMail() == null || principal.getEMail().trim().isEmpty()) { 341 result.add(principalDao.get URIFromInternalID(principalID[0]));333 result.add(principalDao.getHrefFromInternalID(principalID[0])); 342 334 343 335 } … … 353 345 AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargetsAndOwner(annotationID); 354 346 annotationInfo.setTargets(this.getAnnotationTargets(annotationID)); 355 annotationInfo.setOwner Ref(principalDao.getURIFromInternalID(annotationDao.getOwner(annotationID)));347 annotationInfo.setOwnerHref(principalDao.getHrefFromInternalID(annotationDao.getOwner(annotationID))); 356 348 result.getAnnotationInfo().add(annotationInfo); 357 349 } … … 365 357 for (Number annotationID : annotationIDs) { 366 358 Number ownerID = annotationDao.getOwner(annotationID); 367 ReferenceList targets = getAnnotationTargets(annotationID);359 ReferenceList targets = this.getAnnotationTargets(annotationID); 368 360 AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargetsAndOwner(annotationID); 369 361 annotationInfo.setTargets(targets); 370 annotationInfo.setOwner Ref(principalDao.getURIFromInternalID(ownerID));362 annotationInfo.setOwnerHref(principalDao.getHrefFromInternalID(ownerID)); 371 363 result.getAnnotationInfo().add(annotationInfo); 372 364 } … … 384 376 for (Number key : cachedIDsFragments.keySet()) { 385 377 CachedRepresentationFragment cachedRepresentationFragment = new CachedRepresentationFragment(); 386 cachedRepresentationFragment.set Ref(cachedRepresentationDao.getURIFromInternalID(key));378 cachedRepresentationFragment.setHref(cachedRepresentationDao.getHrefFromInternalID(key)); 387 379 cachedRepresentationFragment.setFragmentString(cachedIDsFragments.get(key)); 388 380 cachedRepresentationFragmentList.getCached().add(cachedRepresentationFragment); … … 409 401 ReferenceList referenceList = new ReferenceList(); 410 402 for (Number siblingID : targetIDs) { 411 referenceList.get Ref().add(targetDao.externalIDtoURI(targetDao.getExternalID(siblingID).toString()));403 referenceList.getHref().add(targetDao.getHrefFromInternalID(siblingID)); 412 404 } 413 405 return referenceList; … … 461 453 return principalDao.getPrincipalInternalIDFromRemoteID(remoteID); 462 454 } 455 456 @Override 457 public UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException { 458 return principalDao.getPrincipalExternalIDFromRemoteID(remoteID); 459 } 463 460 464 461 @Override … … 519 516 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 520 517 Number ownerID = notebookDao.getOwner(notebookID); 521 notebookInfo.setOwner Ref(principalDao.getURIFromInternalID(ownerID));518 notebookInfo.setOwnerHref(principalDao.getHrefFromInternalID(ownerID)); 522 519 result.getNotebookInfo().add(notebookInfo); 523 520 } … … 537 534 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 538 535 for (Number notebookID : notebookIDs) { 539 String reference = notebookDao.get URIFromInternalID(notebookID);540 result.get Ref().add(reference);536 String reference = notebookDao.getHrefFromInternalID(notebookID); 537 result.getHref().add(reference); 541 538 } 542 539 return result; … … 548 545 List<Number> principalIDs = principalDao.getPrincipalIDsWithAccessForNotebook(notebookID, Access.fromValue(access)); 549 546 for (Number principalID : principalIDs) { 550 String reference = principalDao.get URIFromInternalID(principalID);551 result.get Ref().add(reference);547 String reference = principalDao.getHrefFromInternalID(principalID); 548 result.getHref().add(reference); 552 549 } 553 550 return result; … … 558 555 Notebook result = notebookDao.getNotebookWithoutAnnotationsAndAccesssAndOwner(notebookID); 559 556 560 result.setOwnerRef(principalDao.get URIFromInternalID(notebookDao.getOwner(notebookID)));557 result.setOwnerRef(principalDao.getHrefFromInternalID(notebookDao.getOwner(notebookID))); 561 558 562 559 ReferenceList annotations = new ReferenceList(); 563 560 List<Number> annotationIDs = annotationDao.getAnnotations(notebookID); 564 561 for (Number annotationID : annotationIDs) { 565 annotations.get Ref().add(annotationDao.getURIFromInternalID(annotationID));562 annotations.getHref().add(annotationDao.getHrefFromInternalID(annotationID)); 566 563 } 567 564 result.setAnnotations(annotations); … … 576 573 for (Number principal : principals) { 577 574 Permission up = new Permission(); 578 up.setPrincipal Ref(principalDao.getURIFromInternalID(principal));575 up.setPrincipalHref(principalDao.getHrefFromInternalID(principal)); 579 576 up.setLevel(access); 580 577 ups.getPermission().add(up); … … 611 608 ReferenceList references = new ReferenceList(); 612 609 for (Number annotationID : selectedAnnotIDs) { 613 references.get Ref().add(annotationDao.getURIFromInternalID(annotationID));610 references.getHref().add(annotationDao.getHrefFromInternalID(annotationID)); 614 611 } 615 612 return references; … … 649 646 int result = 0; 650 647 for (Permission permission : permissions) { 651 Number principalID = principalDao.getInternalIDFrom URI(permission.getPrincipalRef());648 Number principalID = principalDao.getInternalIDFromHref(permission.getPrincipalHref()); 652 649 Access access = permission.getLevel(); 653 650 Access currentAccess = annotationDao.getAccess(annotationID, principalID); … … 670 667 @Override 671 668 public int updateAnnotation(Annotation annotation) throws NotInDataBaseException { 672 Number annotationID = annotationDao.getInternalID FromURI(annotation.getURI());673 int updatedAnnotations = annotationDao.updateAnnotation(annotation, annotationID, principalDao.getInternalIDFrom URI(annotation.getOwnerRef()));669 Number annotationID = annotationDao.getInternalID(UUID.fromString(annotation.getId())); 670 int updatedAnnotations = annotationDao.updateAnnotation(annotation, annotationID, principalDao.getInternalIDFromHref(annotation.getOwnerHref())); 674 671 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); 675 672 int deletedPrinsipalsAccesss = annotationDao.deleteAnnotationPermissions(annotationID); … … 688 685 689 686 @Override 690 public int updateAnnotationHeadline(Number internalID, String newHeader) 687 public int updateAnnotationHeadline(Number internalID, String newHeader){ 691 688 return annotationDao.updateAnnotationHeadline(internalID, newHeader); 692 689 } … … 704 701 @Override 705 702 public int updateCachedMetada(CachedRepresentationInfo cachedInfo) throws NotInDataBaseException { 706 Number internalID = cachedRepresentationDao.getInternalID FromURI(cachedInfo.getURI());703 Number internalID = cachedRepresentationDao.getInternalID(UUID.fromString(cachedInfo.getId())); 707 704 return cachedRepresentationDao.updateCachedRepresentationMetadata(internalID, cachedInfo); 708 705 } … … 716 713 @Override 717 714 public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) throws NotInDataBaseException { 718 Number ownerID = principalDao.getInternalIDFrom URI(upToDateNotebookInfo.getOwnerRef());715 Number ownerID = principalDao.getInternalIDFromHref(upToDateNotebookInfo.getOwnerHref()); 719 716 return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID); 720 717 } … … 741 738 } 742 739 740 743 741 @Override 744 742 public Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets) throws NotInDataBaseException { … … 746 744 for (TargetInfo targetInfo : targets) { 747 745 try { 748 Number targetIDRunner = targetDao.getInternalIDFrom URI(targetInfo.getRef());746 Number targetIDRunner = targetDao.getInternalIDFromHref(targetInfo.getHref()); 749 747 int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetIDRunner); 750 748 } catch (NotInDataBaseException e) { 751 749 Target newTarget = this.createFreshTarget(targetInfo); 752 750 Number targetID = targetDao.addTarget(newTarget); 753 String targetTemporaryI D = targetDao.stringURItoExternalID(targetInfo.getRef());754 result.put(targetTemporaryI D, targetDao.getExternalID(targetID).toString());751 String targetTemporaryId = targetInfo.getHref(); 752 result.put(targetTemporaryId, targetDao.getHrefFromInternalID(targetID)); 755 753 int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetID); 756 754 } … … 784 782 List<Permission> permissions = notebook.getPermissions().getPermission(); 785 783 for (Permission permission : permissions) { 786 Number principalID = principalDao.getInternalIDFrom URI(permission.getPrincipalRef());784 Number principalID = principalDao.getInternalIDFromHref(permission.getPrincipalHref()); 787 785 Access access = permission.getLevel(); 788 786 boolean updateAccesss = notebookDao.addAccessToNotebook(notebookID, principalID, access); … … 947 945 } 948 946 949 //// privee e///947 //// privee /// 950 948 private Target createFreshTarget(TargetInfo targetInfo) { 951 949 Target target = new Target(); … … 982 980 int addedPermissions = 0; 983 981 for (Permission permission : permissions) { 984 addedPermissions = addedPermissions + annotationDao.addAnnotationPrincipalAccess(annotationID, principalDao.getInternalIDFrom URI(permission.getPrincipalRef()), permission.getLevel());982 addedPermissions = addedPermissions + annotationDao.addAnnotationPrincipalAccess(annotationID, principalDao.getInternalIDFromHref(permission.getPrincipalHref()), permission.getLevel()); 985 983 } 986 984 return addedPermissions; … … 992 990 private TargetInfo getTargetInfoFromTarget(Target target) { 993 991 TargetInfo targetInfo = new TargetInfo(); 994 targetInfo.set Ref(target.getURI());992 targetInfo.setHref(target.getHref()); 995 993 targetInfo.setLink(target.getLink()); 996 994 targetInfo.setVersion(target.getVersion()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r5186 r5385 61 61 62 62 @Override 63 public void set ServiceURI(String serviceURI) {64 _ serviceURI = serviceURI;63 public void setResourcePath(String relResourcePath) { 64 _relResourcePath = relResourcePath; 65 65 } 66 66 … … 218 218 public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 219 219 AnnotationInfo annotationInfo = new AnnotationInfo(); 220 annotationInfo.setRef(externalIDtoURI(rs.getString(external_id))); 220 String externalId = rs.getString(external_id); 221 annotationInfo.setHref(externalIDtoHref(externalId)); 221 222 annotationInfo.setHeadline(rs.getString(headline)); 222 223 annotationInfo.setLastModified(timeStampToXMLGregorianCalendar(rs.getString(last_modified))); … … 249 250 @Override 250 251 public String mapRow(ResultSet rs, int rowNumber) throws SQLException { 251 return externalIDto URI(rs.getString(external_id));252 return externalIDtoHref(rs.getString(external_id)); 252 253 } 253 254 }; … … 300 301 301 302 annotation.setTargets(null); 302 annotation.setURI(externalIDtoURI(rs.getString(external_id))); 303 String externalId = rs.getString(external_id); 304 annotation.setId(externalId); 305 annotation.setHref(externalIDtoHref(externalId)); 303 306 annotation.setLastModified(timeStampToXMLGregorianCalendar(rs.getString(last_modified))); 304 307 return annotation; … … 398 401 399 402 String[] body = retrieveBodyComponents(annotation.getBody()); 400 401 String externalID = this.stringURItoExternalID(annotation.getURI()); 403 402 404 Map<String, Object> params = new HashMap<String, Object>(); 403 405 params.put("owner", newOwnerID); … … 406 408 params.put("headline", annotation.getHeadline()); 407 409 params.put("isXml", annotation.getBody().getXmlBody() != null); 408 params.put("externalId", externalID);410 params.put("externalId", annotation.getId()); 409 411 params.put("annotationId", annotationID); 410 412 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r4941 r5385 51 51 52 52 @Override 53 public void set ServiceURI(String serviceURI) {54 _ serviceURI = serviceURI;53 public void setResourcePath(String relResourcePath) { 54 _relResourcePath = relResourcePath; 55 55 } 56 56 … … 68 68 CachedRepresentationInfo result = new CachedRepresentationInfo(); 69 69 result.setMimeType(rs.getString(mime_type)); 70 result.setURI(externalIDtoURI(rs.getString(external_id))); 70 String externalId = rs.getString(external_id); 71 result.setId(externalId); 72 result.setHref(externalIDtoHref(externalId)); 71 73 result.setTool(rs.getString(tool)); 72 74 result.setType(rs.getString(type_)); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4903 r5385 107 107 public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 108 108 NotebookInfo notebookInfo = new NotebookInfo(); 109 notebookInfo.setRef(externalIDtoURI(rs.getString(external_id))); 109 String externalId = rs.getString(external_id); 110 notebookInfo.setHref(externalIDtoHref(externalId)); 110 111 notebookInfo.setTitle(rs.getString(title)); 111 112 return notebookInfo; … … 128 129 notebook.setTitle(rs.getString(title)); 129 130 notebook.setLastModified(timeStampToXMLGregorianCalendar(rs.getString(last_modified))); 130 notebook.setURI(externalIDtoURI(rs.getString(external_id))); 131 String externalId = rs.getString(external_id); 132 notebook.setId(externalId); 133 notebook.setHref(externalIDtoHref(externalId)); 131 134 return notebook; 132 135 } … … 247 250 append(" ) VALUES (:externalId, :owner, :title)"); 248 251 int affectedRows = this.loggedUpdate(sql.toString(), params); 249 return getInternalID(externalID);252 return this.getInternalID(externalID); 250 253 } 251 254 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcPrincipalDao.java
r5186 r5385 50 50 51 51 @Override 52 public void set ServiceURI(String serviceURI) {53 _ serviceURI = serviceURI;52 public void setResourcePath(String relResourcePath) { 53 _relResourcePath = relResourcePath; 54 54 } 55 55 … … 66 66 public Principal mapRow(ResultSet rs, int rowNumber) throws SQLException { 67 67 Principal result = new Principal(); 68 result.setURI(externalIDtoURI(rs.getString(external_id))); 68 String externalId = rs.getString(external_id); 69 result.setId(externalId); 70 result.setHref(externalIDtoHref(externalId)); 69 71 result.setDisplayName(rs.getString(principal_name)); 70 72 result.setEMail(rs.getString(e_mail)); … … 142 144 } 143 145 146 @Override 147 public UUID getPrincipalExternalIDFromRemoteID(String remoteID) throws NotInDataBaseException { 148 149 StringBuilder requestDB = new StringBuilder("SELECT "); 150 requestDB.append(external_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(remote_id).append("= ? LIMIT 1"); 151 List<UUID> result = this.loggedQuery(requestDB.toString(), externalIDRowMapper, remoteID); 152 if (result.isEmpty()) { 153 throw new NotInDataBaseException("principal", "remote ID", remoteID); 154 } 155 return result.get(0); 156 } 157 144 158 @Override 145 159 public String getTypeOfPrincipalAccount(Number internalID) { … … 244 258 @Override 245 259 public Number updatePrincipal(Principal principal) throws NotInDataBaseException { 246 Number principalID = this.getInternalID FromURI(principal.getURI());260 Number principalID = this.getInternalID(UUID.fromString(principal.getId())); 247 261 StringBuilder sql = new StringBuilder("UPDATE "); 248 262 sql.append(principalTableName).append(" SET "). … … 262 276 263 277 if (principalIsInUse(internalID)) { 264 throw new PrincipalCannotBeDeleted(this.get URIFromInternalID(internalID));278 throw new PrincipalCannotBeDeleted(this.getHrefFromInternalID(internalID)); 265 279 } 266 280 StringBuilder sql = new StringBuilder("DELETE FROM "); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r5174 r5385 28 28 import java.util.List; 29 29 import java.util.Map; 30 import java.util.Set;31 30 import java.util.UUID; 32 31 import javax.xml.datatype.DatatypeConfigurationException; … … 103 102 protected String internalIdName = null; 104 103 protected String resourceTableName = null; 105 protected String _ serviceURI;104 protected String _relResourcePath; 106 105 private final Logger _logger = LoggerFactory.getLogger(JdbcResourceDao.class); 107 106 protected String nullArgument = "Null argument is given to the method."; … … 149 148 /////////////////// Class field SETTERS ///////////// 150 149 @Override 151 public void set ServiceURI(String serviceURI) {152 _ serviceURI = serviceURI;150 public void setResourcePath(String relResourcePath) { 151 _relResourcePath = relResourcePath; 153 152 } 154 153 … … 176 175 } 177 176 177 178 178 179 ////////////////////////////////////////////// 179 180 @Override 180 public Number getInternalIDFromURI(String uri) throws NotInDataBaseException { 181 String externalID = this.stringURItoExternalID(uri); 182 try { 183 UUID externalUUID = UUID.fromString(externalID); 184 return this.getInternalID(externalUUID); 185 } catch (IllegalArgumentException e) { 186 _logger.info(externalID + " is not a valid <uuid>. Therefore, I expect that it is a temporary idendifier of a new resource that is not yet."); 187 throw new NotInDataBaseException(resourceTableName, "external ID", externalID); 188 } 189 } 190 191 ////////////////////////////////////////////// 192 @Override 193 public String getURIFromInternalID(Number internalID) { 194 return externalIDtoURI(getExternalID(internalID).toString()); 181 public String getHrefFromInternalID(Number internalID) { 182 return this.externalIDtoHref(getExternalID(internalID).toString()); 183 } 184 185 ////////////////////////////////////////////// 186 @Override 187 public Number getInternalIDFromHref(String href) throws NotInDataBaseException{ 188 try{ 189 return this.getInternalID(UUID.fromString(this.hrefToExternalID(href))); 190 } catch (IllegalArgumentException e){ 191 throw new NotInDataBaseException("resource", "identifier", href); 192 } 195 193 } 196 194 … … 257 255 258 256 ////// END ROW MAPPERS ///// 259 @Override260 p ublic String externalIDtoURI(String externalID) {261 if (_ serviceURI!= null) {262 return _ serviceURI+ externalID;257 258 protected String externalIDtoHref(String externalID) { 259 if (_relResourcePath != null) { 260 return _relResourcePath + externalID; 263 261 } else { 264 262 return externalID; … … 266 264 } 267 265 268 @Override269 p ublic String stringURItoExternalID(String stringURI) {270 if (stringURI.length() > _ serviceURI.length()) {271 return stringURI.substring(_ serviceURI.length());266 267 protected String hrefToExternalID(String stringURI) { 268 if (stringURI.length() > _relResourcePath.length()) { 269 return stringURI.substring(_relResourcePath.length()); 272 270 } else { 273 logger.debug(stringURI + " does not have the form < serviceurl>/<isentifier>, therefore I return the input value.");271 logger.debug(stringURI + " does not have the form <rel url>/<isentifier>, therefore I return the input value."); 274 272 return stringURI; 275 273 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDao.java
r5203 r5385 50 50 51 51 @Override 52 public void set ServiceURI(String serviceURI) {53 _ serviceURI = serviceURI;52 public void setResourcePath(String relResourcePath) { 53 _relResourcePath = relResourcePath; 54 54 } 55 55 … … 240 240 private TargetInfo constructTargetInfo(String externalID, String link, String version, String fragment) { 241 241 TargetInfo targetInfo = new TargetInfo(); 242 targetInfo.set Ref(externalIDtoURI(externalID));242 targetInfo.setHref(externalIDtoHref(externalID)); 243 243 targetInfo.setLink(((new StringBuilder(link)).append("#").append(fragment)).toString()); 244 244 targetInfo.setVersion(version); … … 248 248 private Target constructTarget(String externalID, String link, String version, XMLGregorianCalendar xmlTimeStamp, String fragment) { 249 249 Target target = new Target(); 250 target.setURI(externalIDtoURI(externalID)); 250 target.setId(externalID); 251 target.setHref(externalIDtoHref(externalID)); 251 252 target.setLastModified(xmlTimeStamp); 252 253 if (fragment != null) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5174 r5385 48 48 import javax.ws.rs.QueryParam; 49 49 import javax.ws.rs.core.MediaType; 50 import javax.ws.rs.core.UriInfo;51 50 import javax.ws.rs.ext.Providers; 52 51 import javax.xml.bind.JAXBElement; … … 62 61 @Transactional(rollbackFor = {Exception.class}) 63 62 public class AnnotationResource extends ResourceResource { 64 65 public void setUriInfo(UriInfo uriInfo) { 66 this.uriInfo = uriInfo; 67 } 68 63 69 64 public void setHttpServletResponse(HttpServletResponse httpServletResponse) { 70 65 this.httpServletResponse = httpServletResponse; … … 88 83 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 89 84 Map params = new HashMap(); 90 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier , false);85 Annotation result = (Annotation) (new RequestWrappers(this)).wrapRequestResource(params, new GetAnnotation(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 91 86 if (result != null) { 92 87 return (new ObjectFactory()).createAnnotation(result); … … 111 106 public JAXBElement<ReferenceList> getAnnotationTargets(@PathParam("annotationid") String externalIdentifier) throws IOException { 112 107 Map params = new HashMap(); 113 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier , false);108 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetTargetList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 114 109 if (result != null) { 115 110 return (new ObjectFactory()).createTargetList(result); … … 171 166 public JAXBElement<PermissionList> getAnnotationPermissions(@PathParam("annotationid") String externalIdentifier) throws IOException { 172 167 Map params = new HashMap(); 173 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier , false);168 PermissionList result = (PermissionList) (new RequestWrappers(this)).wrapRequestResource(params, new GetPermissionList(), Resource.ANNOTATION, ResourceAction.READ, externalIdentifier); 174 169 if (result != null) { 175 170 return (new ObjectFactory()).createPermissionList(result); … … 192 187 public String deleteAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 193 188 Map params = new HashMap(); 194 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, ResourceAction.DELETE, externalIdentifier , false);189 int[] result = (int[]) (new RequestWrappers(this)).wrapRequestResource(params, new DeleteAnnotation(), Resource.ANNOTATION, ResourceAction.DELETE, externalIdentifier); 195 190 if (result != null) { 196 191 return result[0] + " annotation(s) is(are) deleted."; … … 246 241 public JAXBElement<ResponseBody> updateAnnotation(@PathParam("annotationid") String externalId, Annotation annotation) throws IOException { 247 242 248 String annotationURI = annotation.getURI(); 249 String path = uriInfo.getBaseUri().toString(); 250 if (!(path + "annotations/" + externalId).equals(annotationURI)) { 251 loggerServer.debug("Wrong request: the annotation (notebook) identifier " + externalId + " and the annotation (notebook) ID from the request body do not match."); 243 String annotationExtId = annotation.getId(); 244 if (!(externalId).equals(annotationExtId)) { 245 loggerServer.debug("Wrong request: the annotation identifier " + externalId + " and the annotation (notebook) ID from the request body do not match."); 252 246 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST); 253 247 return null; … … 255 249 Map params = new HashMap(); 256 250 params.put("annotation", annotation); 257 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, externalId , false);251 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotation(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, externalId); 258 252 if (result != null) { 259 253 return (new ObjectFactory()).createResponseBody(result); … … 285 279 Map params = new HashMap(); 286 280 params.put("annotationBody", annotationBody); 287 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier , false);281 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationBody(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 288 282 if (result != null) { 289 283 return (new ObjectFactory()).createResponseBody(result); … … 313 307 Map params = new HashMap(); 314 308 params.put("headline", newHeadline); 315 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier , false);309 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateAnnotationHeadline(), Resource.ANNOTATION, ResourceAction.WRITE, externalIdentifier); 316 310 if (result != null) { 317 311 return (new ObjectFactory()).createResponseBody(result); … … 341 335 public String updateAccess(@PathParam("annotationid") String annotationExternalId, 342 336 @PathParam("principalid") String principalExternalId, Access access) throws IOException { 343 return genericUpdateDeleteAccess(annotationExternalId, principalExternalId, access);337 return this.genericUpdateDeleteAccess(annotationExternalId, principalExternalId, access); 344 338 } 345 339 //////////////////////////////////////////// … … 351 345 final Number inputPrincipalID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString(principalId), Resource.PRINCIPAL); 352 346 params.put("inputPrincipalID", inputPrincipalID); 353 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipalAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId , false);347 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePrincipalAccess(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationId); 354 348 if (result != null) { 355 349 return result + " row(s) is(are) updated."; … … 386 380 params.put("permissions", permissions); 387 381 388 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationExternalId , false);382 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new UpdatePermissions(), Resource.ANNOTATION, ResourceAction.WRITE_W_METAINFO, annotationExternalId); 389 383 if (result != null) { 390 384 return new ObjectFactory().createResponseBody(result); … … 414 408 public String deletePrincipalsAccess(@PathParam("annotationId") String annotationId, 415 409 @PathParam("principalId") String principalId) throws IOException { 416 return genericUpdateDeleteAccess(annotationId, principalId, null);410 return this.genericUpdateDeleteAccess(annotationId, principalId, null); 417 411 } 418 412 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AutheticationResource.java
r5275 r5385 19 19 20 20 import eu.dasish.annotation.backend.Helpers; 21 import eu.dasish.annotation.backend.NotInDataBaseException;22 21 import eu.dasish.annotation.schema.ObjectFactory; 23 22 import eu.dasish.annotation.schema.Principal; … … 27 26 import javax.ws.rs.Path; 28 27 import javax.ws.rs.Produces; 28 import javax.ws.rs.core.Context; 29 29 import javax.ws.rs.core.MediaType; 30 import javax.ws.rs.core.UriInfo; 30 31 import javax.xml.bind.JAXBElement; 31 32 import javax.xml.parsers.ParserConfigurationException; … … 41 42 @Transactional(rollbackFor = {Exception.class, IOException.class, ParserConfigurationException.class}) 42 43 public class AutheticationResource extends ResourceResource { 43 44 45 44 46 @GET 45 47 @Produces(MediaType.TEXT_XML) … … 66 68 Number principalID = this.getPrincipalID(); 67 69 String remoteID = dbDispatcher.getPrincipalRemoteID(principalID); 68 return Helpers.welcomeString( uriInfo.getBaseUri().toString() + "..", remoteID);70 return Helpers.welcomeString(httpServletRequest.getContextPath(), remoteID); 69 71 } catch (IOException e) { 70 72 return e.getMessage(); … … 80 82 boolean isShibboleth = Boolean.parseBoolean(context.getInitParameter("eu.dasish.annotation.backend.isShibbolethSession")); 81 83 String redirect = isShibboleth ? context.getInitParameter("eu.dasish.annotation.backend.logout") : 82 uriInfo.getBaseUri().toString() + ".."+context.getInitParameter("eu.dasish.annotation.backend.logout");84 httpServletRequest.getContextPath() + context.getInitParameter("eu.dasish.annotation.backend.logout"); 83 85 httpServletResponse.sendRedirect(redirect); 84 86 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r5186 r5385 66 66 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws IOException { 67 67 Map params = new HashMap(); 68 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId , false);68 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInfo(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 69 69 if (result != null) { 70 70 return (new ObjectFactory()).createCashedRepresentationInfo(result); … … 90 90 public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws IOException { 91 91 Map params = new HashMap(); 92 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId , false);92 InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 93 93 if (result != null) { 94 94 ImageIO.setUseCache(false); … … 114 114 public InputStream getCachedRepresentationContentStream(@PathParam("cachedid") String externalId) throws IOException { 115 115 Map params = new HashMap(); 116 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId , false);116 return (InputStream) (new RequestWrappers(this)).wrapRequestResource(params, new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, ResourceAction.READ, externalId); 117 117 } 118 118 … … 136 136 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(0).getEntity(); 137 137 params.put("stream", bpe.getInputStream()); 138 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier , false);138 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedBlob(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE, cachedIdentifier); 139 139 if (result != null) { 140 140 return result + "rows are updated"; … … 168 168 Map params = new HashMap(); 169 169 params.put("info", cachedInfo); 170 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.get URI(), true);170 Integer result = (Integer) (new RequestWrappers(this)).wrapRequestResource(params, new UpdateCachedMetadata(), Resource.CACHED_REPRESENTATION, ResourceAction.WRITE_W_METAINFO, cachedInfo.getId()); 171 171 if (result != null) { 172 172 return result + "rows are updated"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java
r5088 r5385 65 65 @Transactional(readOnly = true) 66 66 public JAXBElement<NotebookInfoList> getNotebookInfos(@QueryParam("access") String accessMode) throws IOException { 67 dbDispatcher.set ServiceURI(uriInfo.getBaseUri().toString());67 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 68 68 Number remotePrincipalID = this.getPrincipalID(); 69 69 if (accessMode.equalsIgnoreCase("read") || accessMode.equalsIgnoreCase("write")) { … … 188 188 return new ObjectFactory().createResponseBody(new ResponseBody()); 189 189 } 190 String path = uriInfo.getBaseUri().toString();191 String notebookURI = notebookInfo.get Ref();192 if (!(path + " notebook/" + externalIdentifier).equals(notebookURI)) {190 String path = this.getRelativeServiceURI(); 191 String notebookURI = notebookInfo.getHref(); 192 if (!(path + "/notebooks/" + externalIdentifier).equals(notebookURI)) { 193 193 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST); 194 194 return new ObjectFactory().createResponseBody(new ResponseBody()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java
r5266 r5385 130 130 Map params = new HashMap<String, String>(); 131 131 params.put("externalId", externalIdentifier); 132 params.put("resource", this);133 132 CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(this)).wrapRequestResource(params, new GetCurrentPrincipalInfo()); 134 133 return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo())); … … 139 138 @Override 140 139 public CurrentPrincipalInfo apply(Map params) throws NotInDataBaseException { 141 final Number principalID = dbDispatcher.getResourceInternalIdentifier(UUID.fromString((String) params.get("externalId")), Resource.PRINCIPAL); 140 String externalId = (String) params.get("externalId"); 141 String loggedInExternalId = (dbDispatcher.getPrincipalExternalIDFromRemoteID(httpServletRequest.getRemoteUser())).toString(); 142 142 final CurrentPrincipalInfo principalInfo = new CurrentPrincipalInfo(); 143 principalInfo.set Ref(dbDispatcher.getResourceURI(principalID, Resource.PRINCIPAL));144 principalInfo.setCurrentPrincipal( ((PrincipalResource) params.get("resource")).ifLoggedIn(principalID));143 principalInfo.setHref(getRelativeServiceURI() + "/principals/" + externalId); 144 principalInfo.setCurrentPrincipal(externalId.equals(loggedInExternalId)); 145 145 return principalInfo; 146 146 } … … 148 148 ////////////////////////////// 149 149 150 @POST 151 @Produces(MediaType.TEXT_PLAIN) 152 @Path("create/{remoteId}/{password}") 153 public String createSpringAuthenticationRecord(@PathParam("remoteId") String remoteId, @PathParam("password") String password) throws IOException { 154 Number remotePrincipalID = this.getPrincipalID(); 155 if (remotePrincipalID == null) { 156 return "Logged in principal is null or anonymous."; 157 } 158 159 if (dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 160 try { 161 int result = dbDispatcher.addSpringUser(remoteId, password, shaStrength, remoteId); 162 return result + " record(s) has been added. Must be 2: 1 record for the principal, another for the authorities table."; 163 } catch (DuplicateKeyException e) { 164 loggerServer.error(e.toString()); 165 httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST); 166 return e.toString(); 167 } 168 } else { 169 this.ADMIN_RIGHTS_EXPECTED(); 170 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 171 return "Nothing is added."; 172 } 173 174 } 175 150 // @POST 151 // @Produces(MediaType.TEXT_PLAIN) 152 // @Path("create/{remoteId}/{password}") 153 // public String createSpringAuthenticationRecord(@PathParam("remoteId") String remoteId, @PathParam("password") String password) throws IOException { 154 // Number remotePrincipalID = this.getPrincipalID(); 155 // if (remotePrincipalID == null) { 156 // return "Logged in principal is null or anonymous."; 157 // } 158 // 159 // if (dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 160 // try { 161 // int result = dbDispatcher.addSpringUser(remoteId, password, shaStrength, remoteId); 162 // return result + " record(s) has been added. Must be 2: 1 record for the principal, another for the authorities table."; 163 // } catch (DuplicateKeyException e) { 164 // loggerServer.error(e.toString()); 165 // httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST); 166 // return e.toString(); 167 // } 168 // } else { 169 // this.ADMIN_RIGHTS_EXPECTED(); 170 // httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 171 // return "Nothing is added."; 172 // } 173 // 174 // } 176 175 /////////////////////////////////////// 177 @POST 178 @Consumes(MediaType.APPLICATION_XML) 179 @Produces(MediaType.APPLICATION_XML) 180 @Path("{remoteId}") 181 public JAXBElement<Principal> addPrincipal(@PathParam("remoteId") String remoteId, Principal principal) throws IOException { 182 183 Number remotePrincipalID = this.getPrincipalID(); 184 if (remotePrincipalID == null) { 185 return new ObjectFactory().createPrincipal(new Principal()); 186 } 187 188 Map params = new HashMap<String, Object>(); 189 params.put("remoteId", remoteId); 190 params.put("newPrincipal", principal); 191 192 if (dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 193 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new AddPrincipal()); 194 } else { 195 this.ADMIN_RIGHTS_EXPECTED(); 196 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 197 return new ObjectFactory().createPrincipal(new Principal()); 198 } 199 200 } 201 202 private class AddPrincipal implements ILambdaPrincipal<Map, Principal> { 203 204 @Override 205 public Principal apply(Map params) throws NotInDataBaseException, PrincipalExists { 206 final Number principalID = dbDispatcher.addPrincipal((Principal) params.get("newPrincipal"), (String) params.get("remoteId")); 207 return dbDispatcher.getPrincipal(principalID); 208 } 209 } 210 176 // @POST 177 // @Consumes(MediaType.APPLICATION_XML) 178 // @Produces(MediaType.APPLICATION_XML) 179 // @Path("{remoteId}") 180 // public JAXBElement<Principal> addPrincipal(@PathParam("remoteId") String remoteId, Principal principal) throws IOException { 181 // 182 // Number remotePrincipalID = this.getPrincipalID(); 183 // if (remotePrincipalID == null) { 184 // return new ObjectFactory().createPrincipal(new Principal()); 185 // } 186 // 187 // Map params = new HashMap<String, Object>(); 188 // params.put("remoteId", remoteId); 189 // params.put("newPrincipal", principal); 190 // 191 // if (dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 192 // return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new AddPrincipal()); 193 // } else { 194 // this.ADMIN_RIGHTS_EXPECTED(); 195 // httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 196 // return new ObjectFactory().createPrincipal(new Principal()); 197 // } 198 // 199 // } 211 200 ///////////////////////////////////// 212 201 @POST … … 227 216 params.put("newPrincipal", newPrincipal); 228 217 229 dbDispatcher.set ServiceURI(uriInfo.getBaseUri().toString());218 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 230 219 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 231 220 } … … 253 242 @FormParam("remoteId") String remoteId, @FormParam("email") String email) 254 243 throws IOException { 255 dbDispatcher.set ServiceURI(uriInfo.getBaseUri().toString());244 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 256 245 Principal newPrincipal = new Principal(); 257 246 newPrincipal.setDisplayName(name); … … 261 250 params.put("newPrincipal", newPrincipal); 262 251 263 dbDispatcher.setServiceURI(uriInfo.getBaseUri().toString()); 264 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new AddPrincipal()); 252 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 253 return (new RequestWrappers(this)).wrapAddPrincipalRequest(params, new RegisterShibbolizedPrincipal()); 254 } 255 256 private class RegisterShibbolizedPrincipal implements ILambdaPrincipal<Map, Principal> { 257 258 @Override 259 public Principal apply(Map params) throws NotInDataBaseException, PrincipalExists { 260 final Number principalID = dbDispatcher.addPrincipal((Principal) params.get("newPrincipal"), (String) params.get("remoteId")); 261 return dbDispatcher.getPrincipal(principalID); 262 } 265 263 } 266 264 … … 303 301 } 304 302 } 305 /////////////////////////////////// 306 303 ///////////////////////////////// 304 305 // logged in user can update his/her account 306 // or account can be updated by the admin in a separate request, see above 307 307 @POST 308 308 @Consumes(MediaType.APPLICATION_FORM_URLENCODED) … … 310 310 @Path("updateme") 311 311 public JAXBElement<Principal> updatePrincipalFromForm(@FormParam("name") String name, @FormParam("email") String email) 312 throws IOException {313 312 throws IOException, NotInDataBaseException { 313 314 314 Principal newPrincipal = new Principal(); 315 315 newPrincipal.setDisplayName(name); 316 316 newPrincipal.setEMail(email); 317 String remoteId = httpServletRequest.getRemoteUser(); 318 String externalId = (dbDispatcher.getPrincipalExternalIDFromRemoteID(remoteId)).toString(); 319 String href = this.getRelativeServiceURI() + "/principals/" + externalId; 320 newPrincipal.setId(externalId); 321 newPrincipal.setHref(href); 317 322 Map params = new HashMap<String, Object>(); 318 323 params.put("newPrincipal", newPrincipal); … … 326 331 public Principal apply(Map params) throws NotInDataBaseException { 327 332 Principal principal = (Principal) params.get("newPrincipal"); 328 Number principalID = (Number) params.get("principalID"); 329 String principalURI = dbDispatcher.getResourceURI(principalID, Resource.PRINCIPAL); 330 principal.setURI(principalURI); 331 Number principalIDupd = dbDispatcher.updatePrincipal(principal); 333 Number principalIDupd = dbDispatcher.updatePrincipal(principal); 332 334 return dbDispatcher.getPrincipal(principalIDupd); 333 335 } … … 354 356 } 355 357 } catch (NotInDataBaseException e) { 356 loggerServer.debug(e.toString()); ;358 loggerServer.debug(e.toString()); 357 359 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); 358 360 return "Account is updated."; … … 385 387 } 386 388 } catch (NotInDataBaseException e) { 387 loggerServer.debug(e.toString()); ;389 loggerServer.debug(e.toString()); 388 390 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString()); 389 391 return "Nothing is deleted."; … … 392 394 this.ADMIN_RIGHTS_EXPECTED(); 393 395 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 394 return "Account is not updated."; 395 } 396 397 } 398 399 // silly because it is trivial. harvest all logged in users via shibboleth!! 400 private boolean ifLoggedIn(Number principalID) { 401 return (httpServletRequest.getRemoteUser()).equals(dbDispatcher.getPrincipalRemoteID(principalID)); 396 return "Principal is not deleted."; 397 } 398 402 399 } 403 400 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java
r5122 r5385 38 38 public class RequestWrappers<T> { 39 39 40 41 40 private ResourceResource resourceResource; 42 41 private String _internalID = "internalID"; … … 68 67 } 69 68 70 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId , boolean isUri) throws IOException {69 public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId) throws IOException { 71 70 Number principalID = resourceResource.getPrincipalID(); 72 71 if (principalID == null) { … … 75 74 params.put(_principalID, principalID); 76 75 try { 77 final Number resourceID; 78 if (isUri) { 79 resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifierFromURI(externalId, resource); 80 params.put(_externalId, resourceResource.dbDispatcher.getResourceExternalIdentifier(resourceID, resource).toString()); 81 } else { 82 resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource); 83 params.put(_externalId, externalId); 84 } 76 final Number resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource); 85 77 if (resourceResource.dbDispatcher.canDo(action, principalID, resourceID, resource)) { 78 params.put(_externalId, externalId); 86 79 params.put(_internalID, resourceID); 87 80 params.put(_resourceType, resource); … … 89 82 } else { 90 83 this.FORBIDDEN_RESOURCE_ACTION(externalId, resource.name(), action.name()); 91 resourceResource.loggerServer.debug("Principal " +resourceResource.dbDispatcher.getResourceExternalIdentifier(principalID, Resource.PRINCIPAL)+" cannot "+action.name()+" "+resource.name()+" with the id "+externalId);84 resourceResource.loggerServer.debug("Principal " + resourceResource.dbDispatcher.getResourceExternalIdentifier(principalID, Resource.PRINCIPAL) + " cannot " + action.name() + " " + resource.name() + " with the id " + externalId); 92 85 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); 93 86 return null; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/ResourceResource.java
r5266 r5385 28 28 import javax.servlet.http.HttpServletResponse; 29 29 import javax.ws.rs.core.Context; 30 import javax.ws.rs.core.UriInfo;31 30 import javax.ws.rs.ext.Providers; 32 31 import org.slf4j.Logger; … … 45 44 protected HttpServletRequest httpServletRequest; 46 45 @Context 47 protected HttpServletResponse httpServletResponse; 48 @Context 49 protected UriInfo uriInfo; 46 protected HttpServletResponse httpServletResponse; 50 47 @Context 51 48 protected Providers providers; … … 59 56 60 57 public Number getPrincipalID() throws IOException { 61 dbDispatcher.setServiceURI(uriInfo.getBaseUri().toString()); 58 59 dbDispatcher.setResourcesPaths(this.getRelativeServiceURI()); 62 60 String remotePrincipal = httpServletRequest.getRemoteUser(); 63 61 if (remotePrincipal != null) { … … 102 100 loggerServer.debug(accessMode + " is an invalid access value, which must be either owner, or read, or write."); 103 101 } 102 103 protected String getRelativeServiceURI(){ 104 return httpServletRequest.getContextPath()+httpServletRequest.getServletPath(); 105 } 104 106 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r5088 r5385 79 79 public JAXBElement<Target> getTarget(@PathParam("targetid") String externalIdentifier) throws IOException { 80 80 Map params = new HashMap(); 81 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier , false);81 Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 82 82 if (result != null) { 83 83 return new ObjectFactory().createTarget(result); … … 103 103 public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String externalIdentifier) throws HTTPException, IOException { 104 104 Map params = new HashMap(); 105 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier , false);105 ReferenceList result = (ReferenceList) (new RequestWrappers(this)).wrapRequestResource(params, new GetSiblingTargets(), Resource.TARGET, ResourceAction.READ, externalIdentifier); 106 106 if (result != null) { 107 107 return new ObjectFactory().createReferenceList(result); … … 135 135 params.put("fragmentDescriptor", fragmentDescriptor); 136 136 137 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier , false);137 CachedRepresentationInfo result = (CachedRepresentationInfo) (new RequestWrappers(this)).wrapRequestResource(params, new PostCached(), Resource.TARGET, ResourceAction.WRITE_W_METAINFO, targetIdentifier); 138 138 if (result != null) { 139 139 return new ObjectFactory().createCashedRepresentationInfo(result); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/WelcomeResource.java
r5266 r5385 22 22 import javax.ws.rs.Path; 23 23 import javax.ws.rs.Produces; 24 import javax.ws.rs.core.Context; 24 25 import javax.ws.rs.core.MediaType; 26 import javax.ws.rs.core.UriInfo; 25 27 import org.springframework.stereotype.Component; 26 28 … … 39 41 String remotePrincipal= httpServletRequest.getRemoteUser(); 40 42 if (remotePrincipal != null) { 41 return Helpers.welcomeString( uriInfo.getBaseUri().toString() + "..",remotePrincipal);43 return Helpers.welcomeString(httpServletRequest.getContextPath(),remotePrincipal); 42 44 } 43 45 else { 44 return Helpers.welcomeString( uriInfo.getBaseUri().toString() + "..", "null-principal");46 return Helpers.welcomeString(httpServletRequest.getContextPath(), "null-principal"); 45 47 } 46 48 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web-basic.xml
r5275 r5385 19 19 20 20 --> 21 22 21 23 <!-- This web.xml file is not required when using Servlet 3.0 container, 22 24 see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 --> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web-shibboleth.xml
r5275 r5385 19 19 20 20 --> 21 21 22 <!-- This web.xml file is not required when using Servlet 3.0 container, 22 23 see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 --> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml
r5275 r5385 26 26 <param-value>/WEB-INF/shhaa.xml</param-value> 27 27 </context-param> 28 29 30 28 <context-param> 31 29 <param-name>contextConfigLocation</param-name> … … 34 32 <context-param> 35 33 <param-name>eu.dasish.annotation.backend.schemaLocation</param-name> 36 <param-value> http://lux17.mpi.nl/schemacat/schemas/s15/files/dwan.xsd</param-value>34 <param-value>/Users/olhsha/repositories/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd</param-value> 37 35 </context-param> 38 36 <context-param> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/MockObjectsFactoryRest.java
r5088 r5385 21 21 import javax.servlet.http.HttpServletRequest; 22 22 import javax.servlet.http.HttpServletResponse; 23 import javax.ws.rs.core.UriInfo;24 23 import javax.ws.rs.ext.Providers; 25 24 import org.jmock.Mockery; … … 38 37 } 39 38 40 41 39 public DBDispatcher newDBDispatcher() { 42 40 return context.mock(DBDispatcher.class); 43 41 } 44 45 public UriInfo newUriInfo() { 46 return context.mock(UriInfo.class); 47 } 48 49 50 public Providers newProviders() { 42 43 public Providers newProviders() { 51 44 return context.mock(Providers.class); 52 45 } 53 46 54 47 public HttpServletRequest newHttpServletRequest() { 55 48 return context.mock(HttpServletRequest.class); 56 49 } 57 50 58 51 public HttpServletResponse newHttpServletResponce() { 59 52 return context.mock(HttpServletResponse.class); 60 53 } 61 62 54 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java
r4903 r5385 26 26 import eu.dasish.annotation.schema.Permission; 27 27 import eu.dasish.annotation.schema.PermissionList; 28 import java.util.UUID; 28 29 import javax.xml.datatype.DatatypeConfigurationException; 29 30 import javax.xml.datatype.DatatypeFactory; … … 38 39 final private Annotation _annotationToAdd; 39 40 40 public TestInstances(String baseURI) {41 _annotationOne = makeAnnotationOne( baseURI);42 _annotationToAdd = makeAnnotationToAdd( baseURI);41 public TestInstances(String relativePath) { 42 _annotationOne = makeAnnotationOne(relativePath); 43 _annotationToAdd = makeAnnotationToAdd(relativePath); 43 44 } 44 45 45 private Annotation makeAnnotationOne(String baseURI) { 46 Annotation result = makeAnnotation(baseURI, "<html><body>some html 1</body></html>", "text/html", "Sagrada Famiglia", "00000000-0000-0000-0000-000000000111"); 47 result.setURI(baseURI+"annotations/00000000-0000-0000-0000-000000000021"); 48 46 private Annotation makeAnnotationOne(String relativePath) { 47 Annotation result = makeAnnotation(relativePath, "<html><body>some html 1</body></html>", "text/html", "Sagrada Famiglia", "00000000-0000-0000-0000-000000000111", "00000000-0000-0000-0000-000000000021"); 48 49 49 try { 50 50 result.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z")); … … 59 59 60 60 Permission up1 = new Permission(); 61 up1.setPrincipal Ref(baseURI + "principals/00000000-0000-0000-0000-000000000112");61 up1.setPrincipalHref(relativePath + "/principals/00000000-0000-0000-0000-000000000112"); 62 62 up1.setLevel(Access.WRITE); 63 63 64 64 Permission up2 = new Permission(); 65 up2.setPrincipal Ref(baseURI + "principals/00000000-0000-0000-0000-000000000113");65 up2.setPrincipalHref(relativePath + "/principals/00000000-0000-0000-0000-000000000113"); 66 66 up2.setLevel(Access.READ); 67 67 … … 72 72 TargetInfo target1 = new TargetInfo(); 73 73 target1.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); 74 target1.set Ref(baseURI + "targets/00000000-0000-0000-0000-000000000031");74 target1.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000031"); 75 75 target1.setVersion("version 1.0"); 76 76 77 77 TargetInfo target2 = new TargetInfo(); 78 78 target2.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); 79 target2.set Ref(baseURI + "targets/00000000-0000-0000-0000-000000000032");79 target2.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000032"); 80 80 target2.setVersion("version 1.1"); 81 81 … … 86 86 } 87 87 88 private Annotation makeAnnotationToAdd(String baseURI) {89 Annotation result = makeAnnotation( baseURI, "<html><body>some html 3</body></html>", "text/plain", "Annotation to add to test DAO", "00000000-0000-0000-0000-000000000113");88 private Annotation makeAnnotationToAdd(String relativePath) { 89 Annotation result = makeAnnotation(relativePath, "<html><body>some html 3</body></html>", "text/plain", "Annotation to add to test DAO", "00000000-0000-0000-0000-000000000113", UUID.randomUUID().toString()); 90 90 91 91 TargetInfo TargetInfo = new TargetInfo(); 92 92 TargetInfo.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht"); 93 TargetInfo.set Ref(baseURI+ "targets/00000000-0000-0000-0000-000000000031");93 TargetInfo.setHref(relativePath + "/targets/00000000-0000-0000-0000-000000000031"); 94 94 TargetInfo.setVersion("version 1.0"); 95 95 … … 97 97 targetInfos.getTargetInfo().add(TargetInfo); 98 98 result.setTargets(targetInfos); 99 99 100 100 PermissionList permissions = new PermissionList(); 101 101 permissions.setPublic(Access.WRITE); 102 102 result.setPermissions(permissions); 103 103 104 104 return result; 105 105 } 106 106 107 private Annotation makeAnnotation(String baseURI, String bodyTxt, String bodyMimeType, String headline, String ownerExternalId) {107 private Annotation makeAnnotation(String relativePath, String bodyTxt, String bodyMimeType, String headline, String ownerExternalId, String externalId) { 108 108 Annotation result = new Annotation(); 109 109 110 AnnotationBody body = new AnnotationBody(); 110 111 result.setBody(body); … … 113 114 textBody.setMimeType(bodyMimeType); 114 115 textBody.setBody(bodyTxt); 115 116 116 117 result.setHeadline(headline); 117 118 if (baseURI != null) { 119 result.setOwnerRef(baseURI + "principals/" + ownerExternalId); 120 } else { 121 result.setOwnerRef("principals/" + ownerExternalId); 122 } 123 118 result.setOwnerHref(relativePath + "/principals/" + ownerExternalId); 124 119 result.setLastModified(null); 125 result.setURI(null); 120 result.setId(externalId); 121 result.setHref(relativePath + "/annotations/"+externalId); 126 122 result.setTargets(null); 127 result.setURI(null);128 129 123 return result; 130 124 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherTest.java
r5203 r5385 22 22 import eu.dasish.annotation.backend.PrincipalExists; 23 23 import eu.dasish.annotation.backend.Resource; 24 import eu.dasish.annotation.backend.TestBackendConstants;25 24 import eu.dasish.annotation.backend.TestInstances; 26 25 import eu.dasish.annotation.backend.dao.AnnotationDao; … … 93 92 @Autowired 94 93 private NotebookDao notebookDao; 95 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 96 97 public DBDispatcherTest() { 98 } 94 TestInstances testInstances = new TestInstances("/api"); 95 96 public DBDispatcherTest() { 97 } 98 99 99 100 100 101 ///////// GETTERS ///////////// … … 103 104 * DBIntegrityServiceImlp. 104 105 */ 106 105 107 @Test 106 108 public void testGetAnnotationInternalIdentifier() throws NotInDataBaseException { 107 109 System.out.println("getAnnotationInternalIdentifier"); 110 108 111 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); 109 //dbIntegrityService.setResourceList();110 112 mockeryDao.checking(new Expectations() { 111 113 { … … 125 127 System.out.println("getAnnotationExternalIdentifier"); 126 128 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); 127 129 128 130 mockeryDao.checking(new Expectations() { 129 131 { … … 142 144 public void testGetPrincipalInternalIdentifier() throws NotInDataBaseException { 143 145 System.out.println("getPrincipalInternalIdentifier"); 144 146 145 147 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000111"); 146 148 … … 162 164 System.out.println("getPrincipalExternalIdentifier"); 163 165 final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000111"); 164 166 165 167 mockeryDao.checking(new Expectations() { 166 168 { … … 178 180 public void testGetAnnotation() throws Exception { 179 181 System.out.println("test getAnnotation"); 180 182 181 183 final Annotation mockAnnotation = new Annotation();// corresponds to the annotation # 1 182 mockAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021"); 184 mockAnnotation.setHref("/api/annotations/00000000-0000-0000-0000-000000000021"); 185 mockAnnotation.setId("00000000-0000-0000-0000-000000000021"); 183 186 mockAnnotation.setHeadline("Sagrada Famiglia"); 184 187 XMLGregorianCalendar mockTimeStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"); 185 188 mockAnnotation.setLastModified(mockTimeStamp); 186 mockAnnotation.setOwner Ref(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000111");189 mockAnnotation.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000111"); 187 190 188 191 AnnotationBody mockBody = new AnnotationBody(); … … 201 204 final Target mockTargetOne = new Target(); 202 205 mockTargetOne.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); 203 mockTargetOne.setURI(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031"); 206 mockTargetOne.setId("00000000-0000-0000-0000-000000000031"); 207 mockTargetOne.setHref("/api/targets/00000000-0000-0000-0000-000000000031"); 204 208 mockTargetOne.setVersion("version 1.0"); 205 209 206 210 final Target mockTargetTwo = new Target(); 207 211 mockTargetTwo.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); 208 mockTargetTwo.setURI(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032"); 212 mockTargetTwo.setId("00000000-0000-0000-0000-000000000032"); 213 mockTargetTwo.setHref("/api/targets/00000000-0000-0000-0000-000000000032"); 209 214 mockTargetTwo.setVersion("version 1.1"); 210 215 … … 220 225 listMap.add(map4); 221 226 222 final String uri1 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000111";223 final String uri2 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000112";224 final String uri3 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113";225 final String uri4 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000221";227 final String uri1 = "/api/principals/00000000-0000-0000-0000-000000000111"; 228 final String uri2 = "/api/principals/00000000-0000-0000-0000-000000000112"; 229 final String uri3 = "/api/principals/00000000-0000-0000-0000-000000000113"; 230 final String uri4 = "/api/principals/00000000-0000-0000-0000-000000000221"; 226 231 227 232 … … 234 239 will(returnValue(1)); 235 240 236 oneOf(principalDao).get URIFromInternalID(1);241 oneOf(principalDao).getHrefFromInternalID(1); 237 242 will(returnValue(uri1)); 238 243 … … 254 259 will(returnValue(Access.WRITE)); 255 260 256 oneOf(principalDao).get URIFromInternalID(2);261 oneOf(principalDao).getHrefFromInternalID(2); 257 262 will(returnValue(uri2)); 258 263 259 oneOf(principalDao).get URIFromInternalID(3);264 oneOf(principalDao).getHrefFromInternalID(3); 260 265 will(returnValue(uri3)); 261 266 262 oneOf(principalDao).get URIFromInternalID(11);267 oneOf(principalDao).getHrefFromInternalID(11); 263 268 will(returnValue(uri4)); 264 269 } … … 266 271 267 272 Annotation result = dbDispatcher.getAnnotation(1); 268 assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021", result.getURI()); 273 assertEquals("00000000-0000-0000-0000-000000000021", result.getId()); 274 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); 269 275 assertEquals("text/plain", result.getBody().getTextBody().getMimeType()); 270 276 assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); 271 277 assertEquals("Sagrada Famiglia", result.getHeadline()); 272 278 assertEquals("2013-08-12T09:25:00.383000Z", result.getLastModified().toString()); 273 assertEquals( TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000111", result.getOwnerRef());279 assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getOwnerHref()); 274 280 275 281 assertEquals(mockTargetOne.getLink(), result.getTargets().getTargetInfo().get(0).getLink()); 276 assertEquals(mockTargetOne.get URI(), result.getTargets().getTargetInfo().get(0).getRef());282 assertEquals(mockTargetOne.getHref(), result.getTargets().getTargetInfo().get(0).getHref()); 277 283 assertEquals(mockTargetOne.getVersion(), result.getTargets().getTargetInfo().get(0).getVersion()); 278 284 assertEquals(mockTargetTwo.getLink(), result.getTargets().getTargetInfo().get(1).getLink()); 279 assertEquals(mockTargetTwo.get URI(), result.getTargets().getTargetInfo().get(1).getRef());285 assertEquals(mockTargetTwo.getHref(), result.getTargets().getTargetInfo().get(1).getHref()); 280 286 assertEquals(mockTargetTwo.getVersion(), result.getTargets().getTargetInfo().get(1).getVersion()); 281 287 … … 283 289 284 290 assertEquals(Access.WRITE, result.getPermissions().getPermission().get(0).getLevel()); 285 assertEquals(uri2, result.getPermissions().getPermission().get(0).getPrincipal Ref());291 assertEquals(uri2, result.getPermissions().getPermission().get(0).getPrincipalHref()); 286 292 287 293 assertEquals(Access.READ, result.getPermissions().getPermission().get(1).getLevel()); 288 assertEquals(uri3, result.getPermissions().getPermission().get(1).getPrincipal Ref());294 assertEquals(uri3, result.getPermissions().getPermission().get(1).getPrincipalHref()); 289 295 290 296 assertEquals(Access.READ, result.getPermissions().getPermission().get(2).getLevel()); 291 assertEquals(uri4, result.getPermissions().getPermission().get(2).getPrincipal Ref());297 assertEquals(uri4, result.getPermissions().getPermission().get(2).getPrincipalHref()); 292 298 293 299 assertEquals(Access.WRITE, result.getPermissions().getPublic()); … … 300 306 public void testGetFilteredAnnotationIDs() throws NotInDataBaseException { 301 307 System.out.println("test getFilteredAnnotationIDs"); 302 308 303 309 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 304 310 mockAnnotationIDs1.add(1); … … 367 373 public void testGetFilteredAnnotationIDs2() throws NotInDataBaseException { 368 374 System.out.println("test getFilteredAnnotationIDs"); 369 370 375 371 376 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 372 377 mockAnnotationIDs1.add(1); … … 434 439 public void testGetFilteredAnnotationIDs3() throws NotInDataBaseException { 435 440 System.out.println("test getFilteredAnnotationIDs"); 436 437 441 438 442 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); … … 459 463 public void testGetFilteredAnnotationIDs4() throws NotInDataBaseException { 460 464 System.out.println("test getFilteredAnnotationIDs"); 461 462 463 465 464 466 final String after = (new Timestamp(0)).toString(); 465 467 final String before = (new Timestamp(System.currentTimeMillis())).toString(); … … 488 490 public void testGetAnnotationTargets() throws SQLException { 489 491 System.out.println("test getAnnotationTargets"); 490 final List<Number> TargetIDs = new ArrayList<Number>(); 491 TargetIDs.add(1); 492 TargetIDs.add(2); 492 493 final List<Number> targetIDs = new ArrayList<Number>(); 494 targetIDs.add(1); 495 targetIDs.add(2); 493 496 mockeryDao.checking(new Expectations() { 494 497 { 495 498 oneOf(targetDao).getTargetIDs(1); 496 will(returnValue( TargetIDs));497 498 oneOf(targetDao).get URIFromInternalID(1);499 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031"));500 501 oneOf(targetDao).get URIFromInternalID(2);502 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032"));499 will(returnValue(targetIDs)); 500 501 oneOf(targetDao).getHrefFromInternalID(1); 502 will(returnValue("/api/targets/00000000-0000-0000-0000-000000000031")); 503 504 oneOf(targetDao).getHrefFromInternalID(2); 505 will(returnValue("/api/targets/00000000-0000-0000-0000-000000000032")); 503 506 504 507 } … … 506 509 507 510 ReferenceList result = dbDispatcher.getAnnotationTargets(1); 508 assertEquals(2, result.get Ref().size());509 assertEquals( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031", result.getRef().get(0));510 assertEquals( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032", result.getRef().get(1));511 assertEquals(2, result.getHref().size()); 512 assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", result.getHref().get(0)); 513 assertEquals("/api/targets/00000000-0000-0000-0000-000000000032", result.getHref().get(1)); 511 514 512 515 } … … 524 527 public void testGetFilteredAnnotationInfos() throws NotInDataBaseException { 525 528 System.out.println("test getetFilteredAnnotationInfos"); 526 527 529 528 530 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 529 531 mockAnnotationIDs1.add(1); … … 563 565 564 566 mockAnnotInfo.setHeadline("Sagrada Famiglia"); 565 mockAnnotInfo.set Ref(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021");566 mockAnnotInfo.setOwner Ref(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000111");567 mockAnnotInfo.setHref("/api/annotations/00000000-0000-0000-0000-000000000021"); 568 mockAnnotInfo.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000111"); 567 569 568 570 final List<Number> targetIDs = new ArrayList<Number>(); … … 608 610 will(returnValue(1)); 609 611 610 oneOf(principalDao).get URIFromInternalID(1);611 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000111"));612 oneOf(principalDao).getHrefFromInternalID(1); 613 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); 612 614 613 615 //// … … 615 617 will(returnValue(targetIDs)); 616 618 617 oneOf(targetDao).get URIFromInternalID(1);618 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031"));619 620 621 oneOf(targetDao).get URIFromInternalID(2);622 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032"));619 oneOf(targetDao).getHrefFromInternalID(1); 620 will(returnValue("/api/targets/00000000-0000-0000-0000-000000000031")); 621 622 623 oneOf(targetDao).getHrefFromInternalID(2); 624 will(returnValue("/api/targets/00000000-0000-0000-0000-000000000032")); 623 625 624 626 … … 630 632 assertEquals(1, result.getAnnotationInfo().size()); 631 633 AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0); 632 assertEquals(mockAnnotInfo.getHeadline(), resultAnnotInfo.getHeadline()); 633 assertEquals(mockAnnotInfo.getRef(), resultAnnotInfo.getRef()); 634 assertEquals(mockAnnotInfo.getOwnerRef(), resultAnnotInfo.getOwnerRef()); 635 assertEquals(mockAnnotInfo.getRef(), result.getAnnotationInfo().get(0).getRef()); 636 assertEquals(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031", resultAnnotInfo.getTargets().getRef().get(0)); 637 assertEquals(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032", resultAnnotInfo.getTargets().getRef().get(1)); 634 assertEquals("Sagrada Famiglia", resultAnnotInfo.getHeadline()); 635 assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", resultAnnotInfo.getOwnerHref()); 636 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getAnnotationInfo().get(0).getHref()); 637 assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", resultAnnotInfo.getTargets().getHref().get(0)); 638 assertEquals("/api/targets/00000000-0000-0000-0000-000000000032", resultAnnotInfo.getTargets().getHref().get(1)); 638 639 639 640 } … … 642 643 public void testGetTargetsWithNoCachedRepresentation() { 643 644 System.out.println("test getTargetsWithNoCachedRepresentation"); 645 644 646 final List<Number> targetIDs = new ArrayList<Number>(); 645 647 targetIDs.add(5); … … 663 665 will(returnValue(cachedIDs7)); 664 666 665 oneOf(targetDao).get URIFromInternalID(7);666 will(returnValue(" 00000000-0000-0000-0000-000000000037"));667 oneOf(targetDao).getHrefFromInternalID(7); 668 will(returnValue("/api/targets/00000000-0000-0000-0000-000000000037")); 667 669 668 670 } … … 671 673 List<String> result = dbDispatcher.getTargetsWithNoCachedRepresentation(3); 672 674 assertEquals(1, result.size()); 673 assertEquals(" 00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached675 assertEquals("/api/targets/00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached 674 676 } 675 677 … … 680 682 @Test 681 683 public void testAddCached() throws SerialException, IOException, NotInDataBaseException { 682 System.out.println("addCached"); 684 System.out.println("test addCached"); 685 683 686 String mime = "text/html"; 684 687 String type = "text"; … … 689 692 newCachedInfo.setType(type); 690 693 newCachedInfo.setTool(tool); 691 newCachedInfo.setURI(TestBackendConstants._TEST_SERVLET_URI_cached + externalID); 692 694 newCachedInfo.setHref("/api/cached/" + externalID); 695 newCachedInfo.setId(externalID); 696 693 697 String blobString = "aaa"; 694 698 byte[] blobBytes = blobString.getBytes(); … … 697 701 mockeryDao.checking(new Expectations() { 698 702 { 699 700 oneOf(cachedRepresentationDao).getInternalIDFromURI(newCachedInfo.getURI());701 will(returnValue(null));702 703 703 704 oneOf(cachedRepresentationDao).addCachedRepresentation(newCachedInfo, newCachedBlob); … … 729 730 public void testAddTargetsForAnnotation() throws Exception { 730 731 System.out.println("test addTargetsForAnnotation"); 731 732 732 733 // test 1: adding an existing target 733 734 TargetInfo testTargetOne = new TargetInfo(); 734 735 testTargetOne.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); 735 testTargetOne.set Ref(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031");736 testTargetOne.setHref("/api/targets/00000000-0000-0000-0000-000000000031"); 736 737 testTargetOne.setVersion("version 1.0"); 737 738 final List<TargetInfo> mockTargetListOne = new ArrayList<TargetInfo>(); … … 740 741 mockeryDao.checking(new Expectations() { 741 742 { 742 oneOf(targetDao).getInternalIDFrom URI(mockTargetListOne.get(0).getRef());743 oneOf(targetDao).getInternalIDFromHref(mockTargetListOne.get(0).getHref()); 743 744 will(returnValue(1)); 744 745 … … 753 754 // test 2: adding a new Target 754 755 TargetInfo testTargetTwo = new TargetInfo(); 755 final String tempTargetID = UUID.randomUUID().toString();756 testTargetTwo.set Ref(TestBackendConstants._TEST_SERVLET_URI_targets +tempTargetID);756 final String tempTargetID = "/api/targets/"+UUID.randomUUID().toString(); 757 testTargetTwo.setHref(tempTargetID); 757 758 testTargetTwo.setLink("http://www.sagradafamilia.cat/docs_instit/historia.php"); 758 759 testTargetTwo.setVersion("version 1.0"); … … 763 764 final NotInDataBaseException e = new NotInDataBaseException("target", "external ID", tempTargetID); 764 765 765 mockeryDao.checking(new Expectations() { 766 { 767 oneOf(targetDao).getInternalIDFromURI(mockTargetListTwo.get(0).getRef()); 766 // Target newTarget = this.createFreshTarget(targetInfo); 767 // Number targetID = targetDao.addTarget(newTarget); 768 // String targetTemporaryId = targetInfo.getHref(); 769 // result.put(targetTemporaryId, targetDao.getExternalID(targetID).toString()); 770 // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetID); 771 // 772 mockeryDao.checking(new Expectations() { 773 { 774 oneOf(targetDao).getInternalIDFromHref(mockTargetListTwo.get(0).getHref()); 768 775 will(throwException(e)); 769 776 … … 771 778 will(returnValue(8)); //# the next new number is 8, we have already 7 Targets 772 779 773 oneOf(targetDao).stringURItoExternalID(mockTargetListTwo.get(0).getRef()); 774 will(returnValue(tempTargetID)); 775 776 oneOf(targetDao).getExternalID(8); 777 will(returnValue(mockNewTargetUUID)); 780 oneOf(targetDao).getHrefFromInternalID(8); 781 will(returnValue("/api/targets/"+mockNewTargetUUID.toString())); 778 782 779 783 oneOf(annotationDao).addAnnotationTarget(1, 8); … … 785 789 Map<String, String> resultTwo = dbDispatcher.addTargetsForAnnotation(1, mockTargetListTwo); 786 790 assertEquals(1, resultTwo.size()); 787 assertEquals( mockNewTargetUUID.toString(), resultTwo.get(tempTargetID));791 assertEquals("/api/targets/"+mockNewTargetUUID.toString(), resultTwo.get(tempTargetID)); 788 792 789 793 } … … 805 809 806 810 // expectations for addTargetsForannotation 807 oneOf(targetDao).getInternalIDFrom URI(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031");811 oneOf(targetDao).getInternalIDFromHref("/api/targets/00000000-0000-0000-0000-000000000031"); 808 812 will(returnValue(1)); 809 813 … … 824 828 assertEquals(5, result); 825 829 826 // Annotation newAnnotation = db IntegrityService.getAnnotation(5);827 // assertEquals( TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113", newAnnotation.getOwnerRef());830 // Annotation newAnnotation = dbDispatcher.getAnnotation(5); 831 // assertEquals("/api/principals/00000000-0000-0000-0000-000000000113", newAnnotation.getOwnerHref()); 828 832 // assertEquals(testAnnotation.getHeadline(), newAnnotation.getHeadline()); 829 833 // assertEquals(testAnnotation.getBody().getTextBody().getBody(), newAnnotation.getBody().getTextBody().getBody()); … … 1071 1075 1072 1076 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 1073 mockNotebookInfo.set Ref("00000000-0000-0000-0000-000000000011");1077 mockNotebookInfo.setHref("/api/notebooks/00000000-0000-0000-0000-000000000011"); 1074 1078 mockNotebookInfo.setTitle("Notebook 1"); 1075 1079 … … 1085 1089 will(returnValue(1)); 1086 1090 1087 oneOf(principalDao).get URIFromInternalID(1);1088 will(returnValue(" 00000000-0000-0000-0000-000000000111"));1091 oneOf(principalDao).getHrefFromInternalID(1); 1092 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); 1089 1093 1090 1094 } … … 1092 1096 1093 1097 NotebookInfoList result = dbDispatcher.getNotebooks(3, Access.READ); 1094 assertEquals(" 00000000-0000-0000-0000-000000000011", result.getNotebookInfo().get(0).getRef());1095 assertEquals(" 00000000-0000-0000-0000-000000000111", result.getNotebookInfo().get(0).getOwnerRef());1098 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000011", result.getNotebookInfo().get(0).getHref()); 1099 assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getNotebookInfo().get(0).getOwnerHref()); 1096 1100 assertEquals("Notebook 1", result.getNotebookInfo().get(0).getTitle()); 1097 1101 … … 1107 1111 1108 1112 final NotebookInfo mockNotebookInfo1 = new NotebookInfo(); 1109 mockNotebookInfo1.set Ref("00000000-0000-0000-0000-000000000013");1113 mockNotebookInfo1.setHref("/api/notebooks/00000000-0000-0000-0000-000000000013"); 1110 1114 mockNotebookInfo1.setTitle("Notebook 3"); 1111 1115 1112 1116 final NotebookInfo mockNotebookInfo2 = new NotebookInfo(); 1113 mockNotebookInfo2.set Ref("00000000-0000-0000-0000-000000000014");1117 mockNotebookInfo2.setHref("/api/notebooks/00000000-0000-0000-0000-000000000014"); 1114 1118 mockNotebookInfo2.setTitle("Notebook 4"); 1115 1119 … … 1119 1123 will(returnValue(mockNotebookIDs)); 1120 1124 1121 oneOf(principalDao).get URIFromInternalID(3);1122 will(returnValue(" 00000000-0000-0000-0000-000000000113"));1125 oneOf(principalDao).getHrefFromInternalID(3); 1126 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113")); 1123 1127 1124 1128 oneOf(notebookDao).getNotebookInfoWithoutOwner(3); … … 1131 1135 }); 1132 1136 1133 // NotebookInfoList result = dbIntegrityService.getNotebooks(3, "owner"); 1134 // assertEquals("00000000-0000-0000-0000-000000000013", result.getNotebookInfo().get(0).getRef());// assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(0).getOwnerRef()); 1137 //?? 1138 // NotebookInfoList result = dbDispatcher.getNotebooks(3, "owner"); 1139 // assertEquals("00000000-0000-0000-0000-000000000013", result.getNotebookInfo().get(0).getRef());// assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(0).getOwnerRef()); 1135 1140 // assertEquals("Notebook 3", result.getNotebookInfo().get(0).getTitle()); 1136 1141 // assertEquals("00000000-0000-0000-0000-000000000014", result.getNotebookInfo().get(1).getRef()); … … 1161 1166 will(returnValue(mockNotebookIDs)); 1162 1167 1163 oneOf(notebookDao).get URIFromInternalID(3);1164 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000013"));1165 1166 oneOf(notebookDao).get URIFromInternalID(4);1167 will(returnValue( TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000014"));1168 oneOf(notebookDao).getHrefFromInternalID(3); 1169 will(returnValue("/api/notebooks/00000000-0000-0000-0000-000000000013")); 1170 1171 oneOf(notebookDao).getHrefFromInternalID(4); 1172 will(returnValue("/api/notebooks/00000000-0000-0000-0000-000000000014")); 1168 1173 1169 1174 } … … 1171 1176 1172 1177 ReferenceList result = dbDispatcher.getNotebooksOwnedBy(3); 1173 assertEquals(2, result.get Ref().size());1174 assertEquals( TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000013", result.getRef().get(0));1175 assertEquals( TestBackendConstants._TEST_SERVLET_URI_notebooks + "00000000-0000-0000-0000-000000000014", result.getRef().get(1));1178 assertEquals(2, result.getHref().size()); 1179 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000013", result.getHref().get(0)); 1180 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000014", result.getHref().get(1)); 1176 1181 } 1177 1182 … … 1229 1234 will(returnValue(mockPrincipalIDs)); 1230 1235 1231 oneOf(principalDao).get URIFromInternalID(2);1232 will(returnValue(" serviceURI/principals/00000000-0000-0000-0000-000000000112"));1233 1234 oneOf(principalDao).get URIFromInternalID(4);1235 will(returnValue(" serviceURI/principals/00000000-0000-0000-0000-000000000114"));1236 oneOf(principalDao).getHrefFromInternalID(2); 1237 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000112")); 1238 1239 oneOf(principalDao).getHrefFromInternalID(4); 1240 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000114")); 1236 1241 1237 1242 … … 1240 1245 1241 1246 ReferenceList result = dbDispatcher.getPrincipals(1, "write"); 1242 assertEquals(" serviceURI/principals/00000000-0000-0000-0000-000000000112", result.getRef().get(0).toString());1243 assertEquals(" serviceURI/principals/00000000-0000-0000-0000-000000000114", result.getRef().get(1).toString());1247 assertEquals("/api/principals/00000000-0000-0000-0000-000000000112", result.getHref().get(0).toString()); 1248 assertEquals("/api/principals/00000000-0000-0000-0000-000000000114", result.getHref().get(1).toString()); 1244 1249 1245 1250 } … … 1281 1286 1282 1287 final Notebook mockNotebook = new Notebook(); 1283 mockNotebook.setURI("serviceURI/notebooks/00000000-0000-0000-0000-000000000012"); 1288 mockNotebook.setHref("/api/notebooks/00000000-0000-0000-0000-000000000012"); 1289 mockNotebook.setId("00000000-0000-0000-0000-000000000012"); 1284 1290 mockNotebook.setTitle("Notebook 2"); 1285 1291 mockNotebook.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2014-02-12T09:25:00.383000Z")); … … 1302 1308 will(returnValue(2)); 1303 1309 1304 oneOf(principalDao).get URIFromInternalID(2);1305 will(returnValue(" serviceURI/principals/00000000-0000-0000-0000-000000000112"));1310 oneOf(principalDao).getHrefFromInternalID(2); 1311 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000112")); 1306 1312 1307 1313 oneOf(annotationDao).getAnnotations(2); 1308 1314 will(returnValue(mockAnnotations)); 1309 1315 1310 oneOf(annotationDao).get URIFromInternalID(3);1311 will(returnValue(" serviceURI/annotations/00000000-0000-0000-0000-000000000023"));1316 oneOf(annotationDao).getHrefFromInternalID(3); 1317 will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000023")); 1312 1318 1313 1319 oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.READ); 1314 1320 will(returnValue(mockREADs)); 1315 1321 1316 oneOf(principalDao).get URIFromInternalID(1);1317 will(returnValue(" serviceURI/principals/00000000-0000-0000-0000-000000000111"));1322 oneOf(principalDao).getHrefFromInternalID(1); 1323 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); 1318 1324 1319 1325 oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.WRITE); 1320 1326 will(returnValue(mockWRITEs)); 1321 1327 1322 oneOf(principalDao).get URIFromInternalID(3);1323 will(returnValue(" serviceURI/principals/00000000-0000-0000-0000-000000000113"));1328 oneOf(principalDao).getHrefFromInternalID(3); 1329 will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113")); 1324 1330 1325 1331 … … 1329 1335 1330 1336 Notebook result = dbDispatcher.getNotebook(2); 1331 assertEquals("serviceURI/notebooks/00000000-0000-0000-0000-000000000012", result.getURI()); 1332 assertEquals("serviceURI/principals/00000000-0000-0000-0000-000000000112", result.getOwnerRef()); 1337 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000012", result.getHref()); 1338 assertEquals("00000000-0000-0000-0000-000000000012", result.getId()); 1339 assertEquals("/api/principals/00000000-0000-0000-0000-000000000112", result.getOwnerRef()); 1333 1340 assertEquals("2014-02-12T09:25:00.383000Z", result.getLastModified().toString()); 1334 1341 assertEquals("Notebook 2", result.getTitle()); 1335 assertEquals(1, result.getAnnotations().get Ref().size());1336 assertEquals(" serviceURI/annotations/00000000-0000-0000-0000-000000000023", result.getAnnotations().getRef().get(0));1342 assertEquals(1, result.getAnnotations().getHref().size()); 1343 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000023", result.getAnnotations().getHref().get(0)); 1337 1344 assertEquals(2, result.getPermissions().getPermission().size()); 1338 assertEquals(" serviceURI/principals/00000000-0000-0000-0000-000000000111", result.getPermissions().getPermission().get(0).getPrincipalRef());1345 assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getPermissions().getPermission().get(0).getPrincipalHref()); 1339 1346 assertEquals("read", result.getPermissions().getPermission().get(0).getLevel().value()); 1340 assertEquals(" serviceURI/principals/00000000-0000-0000-0000-000000000113", result.getPermissions().getPermission().get(1).getPrincipalRef());1347 assertEquals("/api/principals/00000000-0000-0000-0000-000000000113", result.getPermissions().getPermission().get(1).getPrincipalHref()); 1341 1348 assertEquals("write", result.getPermissions().getPermission().get(1).getLevel().value()); 1342 1349 … … 1357 1364 will(returnValue(mockAnnotationIDs)); 1358 1365 1359 oneOf(annotationDao).get URIFromInternalID(1);1360 will(returnValue(" serviceURI/annotations/00000000-0000-0000-0000-000000000021"));1361 1362 oneOf(annotationDao).get URIFromInternalID(2);1363 will(returnValue(" serviceURI/annotations/00000000-0000-0000-0000-000000000022"));1366 oneOf(annotationDao).getHrefFromInternalID(1); 1367 will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000021")); 1368 1369 oneOf(annotationDao).getHrefFromInternalID(2); 1370 will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000022")); 1364 1371 1365 1372 … … 1369 1376 1370 1377 ReferenceList result = dbDispatcher.getAnnotationsForNotebook(1, -1, 3, "last_modified", true); 1371 assertEquals(2, result.get Ref().size());1372 assertEquals(" serviceURI/annotations/00000000-0000-0000-0000-000000000021", result.getRef().get(0).toString());1373 assertEquals(" serviceURI/annotations/00000000-0000-0000-0000-000000000022", result.getRef().get(1).toString());1378 assertEquals(2, result.getHref().size()); 1379 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref().get(0).toString()); 1380 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000022", result.getHref().get(1).toString()); 1374 1381 1375 1382 } … … 1386 1393 1387 1394 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 1388 mockNotebookInfo.setOwner Ref(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113");1395 mockNotebookInfo.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000113"); 1389 1396 mockNotebookInfo.setTitle("New Title"); 1390 1397 1391 1398 mockeryDao.checking(new Expectations() { 1392 1399 { 1393 oneOf(principalDao).getInternalIDFrom URI(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113");1400 oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000113"); 1394 1401 will(returnValue(3)); 1395 1402 … … 1441 1448 notebook.setOwnerRef("tmpXXX"); 1442 1449 notebook.setTitle("(Almost) Copy of Notebook 1"); 1443 notebook.setURI("tmpYYY"); 1450 notebook.setId("tmpYYY"); 1451 notebook.setHref("whatever"); 1444 1452 1445 1453 PermissionList accesss = new PermissionList(); 1446 1454 Permission p1 = new Permission(); 1447 1455 p1.setLevel(Access.WRITE); 1448 p1.setPrincipal Ref(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000112");1456 p1.setPrincipalHref("/api/principals/00000000-0000-0000-0000-000000000112"); 1449 1457 accesss.getPermission().add(p1); 1450 1458 Permission p2 = new Permission(); 1451 1459 p2.setLevel(Access.READ); 1452 p2.setPrincipal Ref(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113");1460 p2.setPrincipalHref("/api/principals/00000000-0000-0000-0000-000000000113"); 1453 1461 accesss.getPermission().add(p2); 1454 1462 notebook.setPermissions(accesss); … … 1462 1470 will(returnValue(true)); 1463 1471 1464 oneOf(principalDao).getInternalIDFrom URI(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000112");1472 oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000112"); 1465 1473 will(returnValue(2)); 1466 1474 1467 oneOf(principalDao).getInternalIDFrom URI(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113");1475 oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000113"); 1468 1476 will(returnValue(3)); 1469 1477 … … 1497 1505 1498 1506 // expectations for addTargetsForannotation 1499 oneOf(targetDao).getInternalIDFrom URI(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031");1507 oneOf(targetDao).getInternalIDFromHref("/api/targets/00000000-0000-0000-0000-000000000031"); 1500 1508 will(returnValue(1)); 1501 1509 … … 1642 1650 System.out.println("test updateAnnotation"); 1643 1651 1644 final Annotation annotation = (new TestInstances( TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne();1652 final Annotation annotation = (new TestInstances("/api")).getAnnotationOne(); 1645 1653 final NotInDataBaseException e = new NotInDataBaseException("annotation", "external ID", "00000000-0000-0000-0000-000000000031"); 1646 1654 final String mockTempID = "00000000-0000-0000-0000-000000000031"; … … 1652 1660 mockeryDao.checking(new Expectations() { 1653 1661 { 1654 oneOf(annotationDao).getInternalID FromURI(annotation.getURI());1655 will(returnValue(1)); 1656 1657 oneOf(principalDao).getInternalIDFrom URI(annotation.getOwnerRef());1662 oneOf(annotationDao).getInternalID(UUID.fromString(annotation.getId())); 1663 will(returnValue(1)); 1664 1665 oneOf(principalDao).getInternalIDFromHref(annotation.getOwnerHref()); 1658 1666 will(returnValue(1)); 1659 1667 … … 1670 1678 /// adding the first target, nt foind in the DB 1671 1679 1672 oneOf(targetDao).getInternalIDFrom URI(annotation.getTargets().getTargetInfo().get(0).getRef());1680 oneOf(targetDao).getInternalIDFromHref(annotation.getTargets().getTargetInfo().get(0).getHref()); 1673 1681 will(throwException(e)); 1674 1682 … … 1676 1684 will(returnValue(8)); 1677 1685 1678 oneOf(targetDao).stringURItoExternalID(annotation.getTargets().getTargetInfo().get(0).getRef()); 1679 will(returnValue(mockTempID)); 1680 1681 oneOf(targetDao).getExternalID(8); 1682 will(returnValue(mockNewID)); 1686 oneOf(targetDao).getHrefFromInternalID(8); 1687 will(returnValue("/api/targets/"+mockNewID.toString())); 1683 1688 1684 1689 oneOf(annotationDao).addAnnotationTarget(1, 8); … … 1686 1691 1687 1692 ///////// 1688 oneOf(targetDao).getInternalIDFrom URI(annotation.getTargets().getTargetInfo().get(1).getRef());1693 oneOf(targetDao).getInternalIDFromHref(annotation.getTargets().getTargetInfo().get(1).getHref()); 1689 1694 will(returnValue(2)); 1690 1695 … … 1693 1698 1694 1699 ///// 1695 oneOf(principalDao).getInternalIDFrom URI(permissions.getPermission().get(0).getPrincipalRef());1700 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(0).getPrincipalHref()); 1696 1701 will(returnValue(2)); 1697 1702 … … 1699 1704 will(returnValue(1)); 1700 1705 1701 oneOf(principalDao).getInternalIDFrom URI(permissions.getPermission().get(1).getPrincipalRef());1706 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(1).getPrincipalHref()); 1702 1707 will(returnValue(3)); 1703 1708 … … 1725 1730 public void testUpdateHeadline() throws NotInDataBaseException { 1726 1731 1727 System.out.println("test updateAnnotation"); 1728 1729 final Annotation annotation = (new TestInstances(TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne(); 1730 1731 1732 System.out.println("test updateAnnotation"); 1733 mockeryDao.checking(new Expectations() { 1734 { 1735 oneOf(annotationDao).getInternalIDFromURI(annotation.getURI()); 1736 will(returnValue(1)); 1737 1738 oneOf(principalDao).getInternalIDFromURI(annotation.getOwnerRef()); 1739 will(returnValue(1)); 1740 1741 oneOf(annotationDao).updateAnnotationHeadline(1, "new Headline"); 1732 System.out.println("test updateAnnotationHeadline "); 1733 mockeryDao.checking(new Expectations() { 1734 { oneOf(annotationDao).updateAnnotationHeadline(1, "new Headline"); 1742 1735 will(returnValue(1)); 1743 1736 … … 1794 1787 1795 1788 Permission permission2 = new Permission(); 1796 permission2.setPrincipal Ref("ref2");1789 permission2.setPrincipalHref("/api/principals/ref2"); 1797 1790 permission2.setLevel(Access.WRITE); 1798 1791 1799 1792 Permission permission3 = new Permission(); 1800 permission3.setPrincipal Ref("ref3");1793 permission3.setPrincipalHref("/api/principals/ref3"); 1801 1794 permission3.setLevel(Access.READ); 1802 1795 1803 1796 Permission permission4 = new Permission(); 1804 1797 permission4.setLevel(Access.READ); 1805 permission4.setPrincipal Ref("ref4");1798 permission4.setPrincipalHref("/api/principals/ref4"); 1806 1799 1807 1800 permissions.getPermission().add(permission2); … … 1816 1809 will(returnValue(1)); 1817 1810 1818 oneOf(principalDao).getInternalIDFrom URI(permissions.getPermission().get(0).getPrincipalRef());1811 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(0).getPrincipalHref()); 1819 1812 will(returnValue(2)); 1820 1813 … … 1822 1815 will(returnValue(Access.WRITE)); 1823 1816 1824 oneOf(principalDao).getInternalIDFrom URI(permissions.getPermission().get(1).getPrincipalRef());1817 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(1).getPrincipalHref()); 1825 1818 will(returnValue(3)); 1826 1819 … … 1828 1821 will(returnValue(Access.WRITE)); 1829 1822 1830 oneOf(principalDao).getInternalIDFrom URI(permissions.getPermission().get(2).getPrincipalRef());1823 oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(2).getPrincipalHref()); 1831 1824 will(returnValue(4)); 1832 1825 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r5186 r5385 20 20 import eu.dasish.annotation.backend.Helpers; 21 21 import eu.dasish.annotation.backend.NotInDataBaseException; 22 import eu.dasish.annotation.backend.TestBackendConstants;23 22 import eu.dasish.annotation.backend.TestInstances; 24 23 import eu.dasish.annotation.schema.Annotation; … … 57 56 @Autowired 58 57 JdbcAnnotationDao jdbcAnnotationDao; 59 TestInstances testInstances = new TestInstances( TestBackendConstants._TEST_SERVLET_URI);58 TestInstances testInstances = new TestInstances("/api"); 60 59 61 60 /** … … 64 63 */ 65 64 @Test 66 public void test StringURItoExternalID() {65 public void testHrefToExternalID() { 67 66 System.out.println("test stringURItoExternalID"); 68 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);67 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 69 68 String randomUUID = UUID.randomUUID().toString(); 70 String uri = TestBackendConstants._TEST_SERVLET_URI_annotations+ randomUUID;71 String externalID = jdbcAnnotationDao.stringURItoExternalID(uri);72 assertEquals(randomUUID, externalID);69 String uri = "/api/annotations/" + randomUUID; 70 String uuid = jdbcAnnotationDao.hrefToExternalID(uri); 71 assertEquals(randomUUID, uuid); 73 72 } 74 73 … … 78 77 */ 79 78 @Test 80 public void testExternalIDto URI() {81 System.out.println("test stringURItoExternalID");82 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);79 public void testExternalIDtoHref() { 80 System.out.println("test externalIDtoHref"); 81 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 83 82 String randomUUID = UUID.randomUUID().toString(); 84 String uri = TestBackendConstants._TEST_SERVLET_URI_annotations+ randomUUID;85 String uriResult = jdbcAnnotationDao.externalIDto URI(randomUUID);83 String uri = "/api/annotations/" + randomUUID; 84 String uriResult = jdbcAnnotationDao.externalIDtoHref(randomUUID); 86 85 assertEquals(uri, uriResult); 87 86 } … … 147 146 annotIds.add(3); 148 147 149 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);148 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 150 149 final List<String> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds); 151 150 assertEquals(3, testList.size()); 152 assertEquals( TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021", testList.get(0));153 assertEquals( TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000022", testList.get(1));154 assertEquals( TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000023", testList.get(2));151 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", testList.get(0)); 152 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000022", testList.get(1)); 153 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000023", testList.get(2)); 155 154 156 155 final List<String> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>()); … … 185 184 */ 186 185 @Test 187 public void testGetInternalIDFRom URI() throws NotInDataBaseException {188 System.out.println("test getInternalIDFrom URI");189 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);190 String uri = TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021";191 Number result = jdbcAnnotationDao.getInternalIDFrom URI(uri);186 public void testGetInternalIDFRomHref() throws NotInDataBaseException { 187 System.out.println("test getInternalIDFromHref"); 188 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 189 String uri = "/api/annotations/00000000-0000-0000-0000-000000000021"; 190 Number result = jdbcAnnotationDao.getInternalIDFromHref(uri); 192 191 assertEquals(1, result.intValue()); 192 assertEquals(1, result); 193 193 } 194 194 … … 201 201 public void getAnnotationWithoutTargetsAndPermisions() throws DatatypeConfigurationException { 202 202 System.out.println("test getAnnotationWithoutTargetsAndPermissions"); 203 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);203 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 204 204 final Annotation result = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); 205 205 … … 207 207 assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); 208 208 assertEquals("text/html", result.getBody().getTextBody().getMimeType()); 209 assertEquals( TestBackendConstants._TEST_SERVLET_URI_annotations210 + "00000000-0000-0000-0000-000000000021", result.getURI());209 assertEquals("00000000-0000-0000-0000-000000000021", result.getId()); 210 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); 211 211 assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"), result.getLastModified()); 212 212 } … … 238 238 public void testAddAnnotation() throws SQLException, Exception { 239 239 System.out.println("test_addAnnotation "); 240 240 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 241 241 final Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing Targets 242 assertEquals(null, annotationToAdd.getURI()); 243 assertEquals(null, annotationToAdd.getLastModified()); 244 242 245 243 Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd, 3); 246 244 assertEquals(5, newAnnotationID); … … 248 246 // checking 249 247 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(5); 250 assert False(null == addedAnnotation.getURI());248 assertEquals(addedAnnotation.getHref(), "/api/annotations/"+addedAnnotation.getId()); 251 249 assertFalse(null == addedAnnotation.getLastModified()); 252 250 assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), addedAnnotation.getBody().getTextBody().getMimeType()); … … 393 391 public void testGetAnnotationInfoWithoutTargetsAndOwner() throws DatatypeConfigurationException { 394 392 System.out.println("test getAnnotationInfoWithoutTargets"); 395 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);393 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 396 394 final AnnotationInfo result = jdbcAnnotationDao.getAnnotationInfoWithoutTargetsAndOwner(1); 397 395 398 396 assertEquals("Sagrada Famiglia", result.getHeadline()); 399 assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations 400 + "00000000-0000-0000-0000-000000000021", result.getRef()); 397 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); 401 398 assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"), result.getLastModified()); 402 399 } … … 496 493 public void testUpdateAnnotation() { 497 494 System.out.println("test UpdateAnnotation"); 498 jdbcAnnotationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_annotations);495 jdbcAnnotationDao.setResourcePath("/api/annotations/"); 499 496 500 497 Annotation annotation = testInstances.getAnnotationOne(); … … 503 500 annotation.getBody().getTextBody().setMimeType("text/plain"); 504 501 505 System.out.println(annotation.getURI());502 506 503 int result = jdbcAnnotationDao.updateAnnotation(annotation,1, 1); 507 504 assertEquals(1, result); … … 511 508 assertEquals("text/plain", check.getBody().getTextBody().getMimeType()); 512 509 assertEquals("updated headline 1", check.getHeadline()); 513 510 assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", check.getHref()); 511 assertEquals("00000000-0000-0000-0000-000000000021", check.getId()); 514 512 } 515 513 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java
r4941 r5385 19 19 20 20 import eu.dasish.annotation.backend.NotInDataBaseException; 21 import eu.dasish.annotation.backend.TestBackendConstants;22 21 import eu.dasish.annotation.schema.CachedRepresentationInfo; 23 22 import java.io.ByteArrayInputStream; … … 49 48 */ 50 49 @Test 51 public void test StringURItoExternalID() {52 System.out.println("test stringURItoExternalID");53 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);50 public void testHrefToExternalID() { 51 System.out.println("test hrefToExternalID"); 52 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 54 53 String randomUUID = UUID.randomUUID().toString(); 55 String uri = TestBackendConstants._TEST_SERVLET_URI_cached+ randomUUID;56 String externalID = jdbcCachedRepresentationDao.stringURItoExternalID(uri);57 assertEquals(randomUUID, externalID);54 String uri = "/api/cached/" + randomUUID; 55 String check = jdbcCachedRepresentationDao.hrefToExternalID(uri); 56 assertEquals(randomUUID, check); 58 57 } 59 58 … … 63 62 */ 64 63 @Test 65 public void testExternalI DtoURI() {64 public void testExternalIdToHref() { 66 65 System.out.println("test stringURItoExternalID"); 67 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);66 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 68 67 String randomUUID = UUID.randomUUID().toString(); 69 String uri = TestBackendConstants._TEST_SERVLET_URI_cached+randomUUID;70 String uriResult = jdbcCachedRepresentationDao.externalIDto URI(randomUUID);68 String uri = "/api/cached/"+randomUUID; 69 String uriResult = jdbcCachedRepresentationDao.externalIDtoHref(randomUUID); 71 70 assertEquals(uri, uriResult); 72 71 } … … 84 83 public void testGetExternalId() { 85 84 System.out.println("getExternalId"); 86 Number internalID = 1;87 85 UUID expResult = UUID.fromString("00000000-0000-0000-0000-000000000051"); 88 UUID result = jdbcCachedRepresentationDao.getExternalID( internalID);86 UUID result = jdbcCachedRepresentationDao.getExternalID(1); 89 87 assertEquals(expResult, result); 90 88 } … … 110 108 public void testGetInternalIDFRomURI() throws NotInDataBaseException{ 111 109 System.out.println("test getInternalIDFromURI"); 112 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);113 String uri = TestBackendConstants._TEST_SERVLET_URI_cached +"00000000-0000-0000-0000-000000000051";114 Number result = jdbcCachedRepresentationDao.getInternalIDFrom URI(uri);110 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 111 String uri = "/api/cached/00000000-0000-0000-0000-000000000051"; 112 Number result = jdbcCachedRepresentationDao.getInternalIDFromHref(uri); 115 113 assertEquals(1, result.intValue()); 116 114 } … … 125 123 System.out.println("getCachedRepresentationInfo"); 126 124 127 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);125 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 128 126 CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1); 129 assertEquals(TestBackendConstants._TEST_SERVLET_URI_cached + "00000000-0000-0000-0000-000000000051", result.getURI()); 127 assertEquals("/api/cached/00000000-0000-0000-0000-000000000051", result.getHref()); 128 assertEquals("00000000-0000-0000-0000-000000000051", result.getId()); 130 129 assertEquals("image/png", result.getMimeType()); 131 130 assertEquals("screen-shot", result.getTool()); … … 140 139 public void testGetCachedRepresentations() { 141 140 System.out.println("test getCachedRepresentationsForTarget"); 142 Number TargetID = 1; 143 List<Number> result = jdbcCachedRepresentationDao.getCachedRepresentationsForTarget(TargetID); 141 List<Number> result = jdbcCachedRepresentationDao.getCachedRepresentationsForTarget(1); 144 142 assertEquals(1, result.get(0)); 145 143 assertEquals(2, result.get(1)); … … 154 152 public void testDeleteCachedRepresentation() { 155 153 System.out.println("deleteCachedRepresentationInfo"); 156 Number internalID = 6;/// deleted because no version refers to it157 int result = jdbcCachedRepresentationDao.deleteCachedRepresentation( internalID);154 /// deleted because no version refers to it 155 int result = jdbcCachedRepresentationDao.deleteCachedRepresentation(6); 158 156 assertEquals(1, result); 159 157 … … 163 161 public void testUpdateCachedRepresentationMetadata(){ 164 162 System.out.println("test updateCachedRepresentationInfo"); 165 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);163 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 166 164 CachedRepresentationInfo cachedInfo = new CachedRepresentationInfo(); 167 165 cachedInfo.setMimeType("update mime type 1"); 168 166 cachedInfo.setType("update type 1"); 169 167 cachedInfo.setTool("update tool 1"); 170 cachedInfo.setURI(TestBackendConstants._TEST_SERVLET_URI_cached + "00000000-0000-0000-0000-00000000005c");171 168 172 169 int result = jdbcCachedRepresentationDao.updateCachedRepresentationMetadata(1, cachedInfo); … … 174 171 175 172 CachedRepresentationInfo newCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1); 176 assertEquals(TestBackendConstants._TEST_SERVLET_URI_cached + "00000000-0000-0000-0000-000000000051", newCached.getURI()); 173 assertEquals("/api/cached/00000000-0000-0000-0000-000000000051", newCached.getHref()); 174 assertEquals("00000000-0000-0000-0000-000000000051", newCached.getId()); 177 175 assertEquals("update mime type 1", newCached.getMimeType()); 178 176 assertEquals("update tool 1", newCached.getTool()); … … 184 182 public void testUpdateCachedRepresentationBlob() throws IOException{ 185 183 System.out.println("test updateCachedRepresentationBlob"); 186 jdbcCachedRepresentationDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);184 jdbcCachedRepresentationDao.setResourcePath("/api/cached/"); 187 185 String blobString = " test blobbie "; 188 186 byte[] blobBytes = blobString.getBytes(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r4834 r5385 85 85 public void testGetNotebookInfoWithoutOwner() { 86 86 System.out.println("test getNotebookInfoWithoutOwner"); 87 jdbcNotebookDao.setResourcePath("/api/notebooks/"); 87 88 NotebookInfo result = jdbcNotebookDao.getNotebookInfoWithoutOwner(1); 88 assertEquals(" 00000000-0000-0000-0000-000000000011", result.getRef());89 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000011", result.getHref()); 89 90 assertEquals("Notebook 1", result.getTitle()); 90 assertEquals(null, result.getOwner Ref());91 assertEquals(null, result.getOwnerHref()); 91 92 } 92 93 … … 98 99 public void testGetNotebookWithoutAnnotationsAndAccesssAndOwner() { 99 100 System.out.println("test getNotebookWithoutAnnotationsAndAccesssAndOwner"); 101 jdbcNotebookDao.setResourcePath("/api/notebooks/"); 100 102 Notebook result = jdbcNotebookDao.getNotebookWithoutAnnotationsAndAccesssAndOwner(1); 101 assertEquals("00000000-0000-0000-0000-000000000011", result.getURI()); 103 assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000011", result.getHref()); 104 assertEquals("00000000-0000-0000-0000-000000000011", result.getId()); 102 105 assertEquals("Notebook 1", result.getTitle()); 103 106 assertEquals("2013-08-12T09:25:00.383000Z", result.getLastModified().toString()); … … 149 152 public void testCreateNotebookWithoutAccesssAndAnnotations() throws NotInDataBaseException, DatatypeConfigurationException { 150 153 System.out.println("test createNotebookWithoutAccesssAndAnnotations"); 154 jdbcNotebookDao.setResourcePath("/api/notebooks/"); 151 155 Notebook notebook = new Notebook(); 152 156 notebook.setTitle("New test notebook"); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcPrincipalDaoTest.java
r4995 r5385 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers; 20 21 21 import eu.dasish.annotation.backend.NotInDataBaseException; 22 22 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; 23 import eu.dasish.annotation.backend.TestBackendConstants;24 23 import eu.dasish.annotation.backend.TestInstances; 25 24 import eu.dasish.annotation.schema.Access; … … 45 44 @Autowired 46 45 JdbcPrincipalDao jdbcPrincipalDao; 47 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI);48 46 49 47 /** … … 52 50 */ 53 51 @Test 54 public void test StringURItoExternalID() {55 System.out.println("test stringURItoExternalID");56 jdbcPrincipalDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals);52 public void testHrefToExternalID() { 53 System.out.println("test hrefToExternalID"); 54 jdbcPrincipalDao.setResourcePath("/api/principals/"); 57 55 String randomUUID = UUID.randomUUID().toString(); 58 String uri = TestBackendConstants._TEST_SERVLET_URI_principals+ randomUUID;59 String externalID = jdbcPrincipalDao. stringURItoExternalID(uri);56 String uri = "/api/principals/" + randomUUID; 57 String externalID = jdbcPrincipalDao.hrefToExternalID(uri).toString(); 60 58 assertEquals(randomUUID, externalID); 61 59 } … … 68 66 public void testExternalIDtoURI() { 69 67 System.out.println("test stringURItoExternalID"); 70 jdbcPrincipalDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals);68 jdbcPrincipalDao.setResourcePath("/api/principals/"); 71 69 String randomUUID = UUID.randomUUID().toString(); 72 String uri = TestBackendConstants._TEST_SERVLET_URI_principals+randomUUID;73 String uriResult = jdbcPrincipalDao.externalIDto URI(randomUUID);70 String uri = "/api/principals/"+randomUUID; 71 String uriResult = jdbcPrincipalDao.externalIDtoHref(randomUUID); 74 72 assertEquals(uri, uriResult); 75 73 } … … 98 96 @Test 99 97 public void testGetExternalID() { 100 UUID testOne = jdbcPrincipalDao.getExternalID(3); 101 assertEquals("00000000-0000-0000-0000-000000000113", testOne.toString()); 98 assertEquals("00000000-0000-0000-0000-000000000113", jdbcPrincipalDao.getExternalID(3).toString()); 102 99 103 100 } … … 106 103 public void testGetPrincipal() { 107 104 System.out.println("test getPrincipal"); 108 jdbcPrincipalDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals);105 jdbcPrincipalDao.setResourcePath("/api/principals/"); 109 106 Principal result = jdbcPrincipalDao.getPrincipal(1); 110 107 assertEquals("Twan", result.getDisplayName()); 111 108 assertEquals("Twan.Goosen@mpi.nl", result.getEMail()); 112 assertEquals(TestBackendConstants._TEST_SERVLET_URI_principals+"00000000-0000-0000-0000-000000000111", result.getURI()); 109 assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getHref()); 110 assertEquals("00000000-0000-0000-0000-000000000111", result.getId()); 113 111 } 114 112 … … 116 114 public void testAddPrincipal() throws NotInDataBaseException{ 117 115 System.out.println("test addPrincipal"); 118 jdbcPrincipalDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals);116 jdbcPrincipalDao.setResourcePath("/api/principals/"); 119 117 String freshPrincipalName = "Guilherme"; 120 118 String freshPrincipalEmail = "guisil@mpi.nl"; … … 129 127 assertEquals(freshPrincipalName, addedPrincipal.getDisplayName()); 130 128 assertEquals(freshPrincipalEmail, addedPrincipal.getEMail()); 131 assertFalse(null == jdbcPrincipalDao.stringURItoExternalID(addedPrincipal.getURI())); 129 assertEquals(addedPrincipal.getHref(), "/api/principals/"+addedPrincipal.getId()); 130 132 131 } 133 132 … … 135 134 public void testDeletePrincipal() throws PrincipalCannotBeDeleted{ 136 135 System.out.println("test deletePrincipal"); 137 jdbcPrincipalDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals);136 jdbcPrincipalDao.setResourcePath("/api/principals/"); 138 137 139 138 int result = jdbcPrincipalDao.deletePrincipal(10); … … 152 151 @Test 153 152 public void tesPrincipalExists() { 154 System.out.println("test principalExists"); 155 //jdbcPrincipalDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_principals); 153 System.out.println("test principalExists"); 156 154 assertEquals(false,jdbcPrincipalDao.principalExists("guisil@mpi.nl")); 157 155 assertTrue(jdbcPrincipalDao.principalExists("olhsha@mpi.nl")); … … 170 168 assertEquals(expResult, result); 171 169 } 172 173 @Test174 public void generateHashes() {175 System.out.println("*****");176 System.out.println("generate hashes");177 System.out.println(Helpers.hashPswd("1234", 512, "olhsha@mpi.nl"));178 System.out.println(Helpers.hashPswd("5678", 512, "olasei@mpi.nl"));179 System.out.println("*****");180 181 }170 // 171 // @Test 172 // public void generateHashes() { 173 // System.out.println("*****"); 174 // System.out.println("generate hashes"); 175 // System.out.println(Helpers.hashPswd("1234", 512, "olhsha@mpi.nl")); 176 // System.out.println(Helpers.hashPswd("5678", 512, "olasei@mpi.nl")); 177 // System.out.println("*****"); 178 // 179 // } 182 180 183 181 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDaoTest.java
r5138 r5385 19 19 20 20 import eu.dasish.annotation.backend.NotInDataBaseException; 21 import eu.dasish.annotation.backend.TestBackendConstants;22 21 import eu.dasish.annotation.schema.Target; 23 22 import eu.dasish.annotation.schema.TargetInfo; … … 50 49 */ 51 50 @Test 52 public void test StringURItoExternalID() {53 System.out.println("test stringURItoExternalID");54 jdbcTargetDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_targets);51 public void testHrefToExternalID() { 52 System.out.println("test hrefToExternalID"); 53 jdbcTargetDao.setResourcePath("/api/targets/"); 55 54 String randomUUID = UUID.randomUUID().toString(); 56 String uri = TestBackendConstants._TEST_SERVLET_URI_targets+ randomUUID;57 String externalID = jdbcTargetDao.stringURItoExternalID(uri);55 String uri = "/api/targets/" + randomUUID; 56 String externalID = (jdbcTargetDao.hrefToExternalID(uri)).toString(); 58 57 assertEquals(randomUUID, externalID); 59 58 } … … 66 65 public void testExternalIDtoURI() { 67 66 System.out.println("test stringURItoExternalID"); 68 jdbcTargetDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_targets);67 jdbcTargetDao.setResourcePath("/api/targets/"); 69 68 String randomUUID = UUID.randomUUID().toString(); 70 String uri = TestBackendConstants._TEST_SERVLET_URI_targets+ randomUUID;71 String uriResult = jdbcTargetDao.externalIDto URI(randomUUID);69 String uri = "/api/targets/" + randomUUID; 70 String uriResult = jdbcTargetDao.externalIDtoHref(randomUUID); 72 71 assertEquals(uri, uriResult); 73 72 } … … 79 78 public void testGetExternalID() { 80 79 System.out.println("getExternalID"); 81 Number internalID = 1; 82 UUID result = jdbcTargetDao.getExternalID(internalID); 80 UUID result = jdbcTargetDao.getExternalID(1); 83 81 assertEquals("00000000-0000-0000-0000-000000000031", result.toString()); 84 82 } … … 91 89 System.out.println("getInternalId"); 92 90 UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000031"); 93 Number expResult = 1;94 91 Number result = jdbcTargetDao.getInternalID(externalID); 95 assertEquals( expResult, result);92 assertEquals(1, result); 96 93 } 97 94 … … 103 100 public void testGetInternalIDFRomURI() throws NotInDataBaseException{ 104 101 System.out.println("test getInternalIDFromURI"); 105 jdbcTargetDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_targets);106 String uri = TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031";107 Number result = jdbcTargetDao.getInternalIDFrom URI(uri);102 jdbcTargetDao.setResourcePath("/api/targets/"); 103 String uri = "/api/targets/00000000-0000-0000-0000-000000000031"; 104 Number result = jdbcTargetDao.getInternalIDFromHref(uri); 108 105 assertEquals(1, result.intValue()); 109 106 } … … 115 112 public void testGetTarget() { 116 113 System.out.println("getTarget"); 117 jdbcTargetDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_targets);114 jdbcTargetDao.setResourcePath("/api/targets/"); 118 115 Target result = jdbcTargetDao.getTarget(1); 119 assertEquals(TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031", result.getURI()); 116 assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", result.getHref()); 117 assertEquals("00000000-0000-0000-0000-000000000031", result.getId()); 120 118 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#" + "de_Opdracht", result.getLink()); 121 119 assertEquals("version 1.0", result.getVersion()); … … 167 165 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia" + "#Het_ontwerp", addedTarget.getLink()); 168 166 assertEquals("version 1.0", addedTarget.getVersion()); 169 assertTrue(addedTarget.get URI().startsWith(TestBackendConstants._TEST_SERVLET_URI_targets));167 assertTrue(addedTarget.getHref().startsWith("/api/targets/")); 170 168 } 171 169 … … 176 174 public void testGetTargetInfos() { 177 175 System.out.println("getTargetInfos"); 178 jdbcTargetDao.set ServiceURI(TestBackendConstants._TEST_SERVLET_URI_targets);176 jdbcTargetDao.setResourcePath("/api/targets/"); 179 177 List<Number> test = new ArrayList<Number>(); 180 178 test.add(1); … … 182 180 List<TargetInfo> result = jdbcTargetDao.getTargetInfos(test); 183 181 assertEquals(2, result.size()); 184 assertEquals( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000031", result.get(0).getRef());185 assertEquals( TestBackendConstants._TEST_SERVLET_URI_targets + "00000000-0000-0000-0000-000000000032", result.get(1).getRef());182 assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", result.get(0).getHref()); 183 assertEquals("/api/targets/00000000-0000-0000-0000-000000000032", result.get(1).getHref()); 186 184 assertEquals("version 1.0", result.get(0).getVersion()); 187 185 assertEquals("version 1.1", result.get(1).getVersion()); … … 196 194 public void testRetrieveTargetIDs() { 197 195 System.out.println("retrieveTargetIDs"); 198 Number annotationID = 1; 199 List<Number> result = jdbcTargetDao.getTargetIDs(annotationID); 196 List<Number> result = jdbcTargetDao.getTargetIDs(1); 200 197 assertEquals(2, result.size()); 201 198 assertEquals(1, result.get(0)); … … 206 203 public void testUpdateTargetCachedRepresentationFragment(){ 207 204 System.out.println("test updateTargetCachedRepresentationFragment"); 208 jdbcTargetDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_cached);209 205 int result = jdbcTargetDao.updateTargetCachedRepresentationFragment(1, 1, "updated fragment"); 210 206 assertEquals(1, result); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r5145 r5385 22 22 import eu.dasish.annotation.backend.ResourceAction; 23 23 import eu.dasish.annotation.backend.dao.DBDispatcher; 24 import eu.dasish.annotation.backend.TestBackendConstants;25 24 import eu.dasish.annotation.backend.TestInstances; 26 25 import eu.dasish.annotation.schema.Access; … … 45 44 import java.net.URI; 46 45 import java.util.UUID; 47 import javax.ws.rs.core.UriInfo;48 46 import org.springframework.mock.web.MockHttpServletRequest; 49 47 … … 54 52 @RunWith(value = SpringJUnit4ClassRunner.class) 55 53 @ContextConfiguration(locations = {"/spring-test-config/mockeryRest.xml", "/spring-test-config/mockDBDispatcher.xml", 56 "/spring-test-config/mockUriInfo.xml",57 54 "/spring-config/jaxbMarshallerFactory.xml", "/spring-config/jaxbUnmarshallerFactory.xml"}) 58 55 public class AnnotationResourceTest { … … 61 58 private Mockery mockeryRest; 62 59 @Autowired 63 private DBDispatcher mockDbDispatcher; 64 @Autowired 65 UriInfo mockUriInfo; 60 private DBDispatcher mockDbDispatcher; 66 61 @Autowired 67 62 private AnnotationResource annotationResource; … … 73 68 74 69 // public Number getPrincipalID() throws IOException { 75 // dbIntegrityService.setServiceURI( uriInfo.getBaseUri().toString());70 // dbIntegrityService.setServiceURI(this.getRelativeServiceURI()); 76 71 // verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); 77 72 // String remotePrincipal = httpServletRequest.getRemotePrincipal(); … … 95 90 System.out.println("getAnnotation"); 96 91 final String externalIDstring = "00000000-0000-0000-0000-000000000021"; 97 final Annotation expectedAnnotation = (new TestInstances(null)).getAnnotationOne(); 98 annotationResource.setHttpServletRequest(mockRequest); 99 annotationResource.setUriInfo(mockUriInfo); 92 final Annotation expectedAnnotation = (new TestInstances("/api")).getAnnotationOne(); 93 annotationResource.setHttpServletRequest(mockRequest); 100 94 mockRequest.setRemoteUser("olhsha@mpi.nl"); 101 102 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI); 103 104 mockeryRest.checking(new Expectations() { 105 { 106 oneOf(mockUriInfo).getBaseUri(); 107 will(returnValue(baseUri)); 108 109 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 95 mockRequest.setContextPath("/backend"); 96 mockRequest.setServletPath("/api"); 97 mockeryRest.checking(new Expectations() { 98 { 99 100 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 110 101 111 102 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("olhsha@mpi.nl"); … … 143 134 144 135 annotationResource.setHttpServletRequest(mockRequest); 145 annotationResource.setUriInfo(mockUriInfo);146 136 mockRequest.setRemoteUser("olhsha@mpi.nl"); 147 148 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI); 149 150 151 mockeryRest.checking(new Expectations() { 152 { 153 oneOf(mockUriInfo).getBaseUri(); 154 will(returnValue(baseUri)); 155 156 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 137 mockRequest.setContextPath("/backend"); 138 mockRequest.setServletPath("/api"); 139 140 mockeryRest.checking(new Expectations() { 141 { 142 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 157 143 158 144 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("olhsha@mpi.nl"); … … 186 172 System.out.println("test createAnnotation"); 187 173 188 final Annotation annotationToAdd = (new TestInstances( TestBackendConstants._TEST_SERVLET_URI)).getAnnotationToAdd();174 final Annotation annotationToAdd = (new TestInstances("/api")).getAnnotationToAdd(); 189 175 final Number newAnnotationID = 5; 190 176 191 177 192 178 final Annotation addedAnnotation = (new ObjectFactory()).createAnnotation(annotationToAdd).getValue(); 193 addedAnnotation.setURI("http://localhost:8080/annotator-backend/api/annotations/" + UUID.randomUUID().toString()); 194 addedAnnotation.setOwnerRef("http://localhost:8080/annotator-backend/api/principals/" + "00000000-0000-0000-0000-000000000113"); 179 String externalId = UUID.randomUUID().toString(); 180 addedAnnotation.setId(externalId); 181 addedAnnotation.setHref("/backend/api/annotations/" + externalId); 182 addedAnnotation.setOwnerHref("/backend/api/principals/00000000-0000-0000-0000-000000000113"); 195 183 196 184 final ResponseBody mockEnvelope = new ResponseBody(); … … 201 189 actionList.getAction().add(action); 202 190 action.setMessage(AnnotationActionName.CREATE_CACHED_REPRESENTATION.value()); 203 action.setObject("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036"); 204 205 annotationResource.setHttpServletRequest(mockRequest); 206 annotationResource.setUriInfo(mockUriInfo); 191 action.setObject("/backend/api/targets/00000000-0000-0000-0000-000000000036"); 192 193 annotationResource.setHttpServletRequest(mockRequest); 207 194 mockRequest.setRemoteUser("olhsha@mpi.nl"); 208 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI); 209 210 // final List<String> targets = new ArrayList<String>(); 211 // targets.add("http://localhost:8080/annotator-backend/api/targets/00000000-0000-0000-0000-000000000036"); 212 213 mockeryRest.checking(new Expectations() { 214 { 215 oneOf(mockUriInfo).getBaseUri(); 216 will(returnValue(baseUri)); 217 218 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 195 mockRequest.setContextPath("/backend"); 196 mockRequest.setServletPath("/api"); 197 mockeryRest.checking(new Expectations() { 198 { 199 200 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 219 201 220 202 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("olhsha@mpi.nl"); … … 238 220 Annotation newAnnotation = result.getValue().getAnnotation(); 239 221 String actionName = result.getValue().getActionList().getAction().get(0).getMessage(); 240 assertEquals(addedAnnotation.getOwnerRef(), newAnnotation.getOwnerRef()); 241 assertEquals(addedAnnotation.getURI(), newAnnotation.getURI()); 222 assertEquals(addedAnnotation.getOwnerHref(), newAnnotation.getOwnerHref()); 223 assertEquals(addedAnnotation.getId(), newAnnotation.getId()); 224 assertEquals(addedAnnotation.getHref(), newAnnotation.getHref()); 242 225 assertEquals(addedAnnotation.getHeadline(), newAnnotation.getHeadline()); 243 226 assertEquals(addedAnnotation.getTargets(), newAnnotation.getTargets()); … … 252 235 System.out.println("test updateAnnotation"); 253 236 254 final Annotation annotation = (new TestInstances( TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne();237 final Annotation annotation = (new TestInstances("/backend/api")).getAnnotationOne(); 255 238 annotation.getPermissions().setPublic(Access.READ); 256 239 annotation.setHeadline("updated annotation 1"); … … 269 252 270 253 annotationResource.setHttpServletRequest(mockRequest); 271 annotationResource.setUriInfo(mockUriInfo);272 254 mockRequest.setRemoteUser("twagoo@mpi.nl"); 273 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI);274 255 mockRequest.setContextPath("/backend"); 256 mockRequest.setServletPath("/api"); 275 257 final UUID externalId = UUID.fromString("00000000-0000-0000-0000-000000000021"); 276 258 … … 283 265 mockeryRest.checking(new Expectations() { 284 266 { 285 oneOf(mockUriInfo).getBaseUri(); 286 will(returnValue(baseUri)); 287 288 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 267 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 289 268 290 269 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("twagoo@mpi.nl"); 291 will(returnValue(1)); 292 293 oneOf(mockUriInfo).getBaseUri(); 294 will(returnValue(baseUri)); 295 270 will(returnValue(1)); 271 296 272 oneOf(mockDbDispatcher).getResourceInternalIdentifier(externalId, Resource.ANNOTATION); 297 273 will(returnValue(1)); … … 316 292 JAXBElement<ResponseBody> result = annotationResource.updateAnnotation("00000000-0000-0000-0000-000000000021", annotation); 317 293 Annotation newAnnotation = result.getValue().getAnnotation(); 318 assertEquals(annotation.getOwnerRef(), newAnnotation.getOwnerRef()); 319 assertEquals(annotation.getURI(), newAnnotation.getURI()); 294 assertEquals(annotation.getOwnerHref(), newAnnotation.getOwnerHref()); 295 assertEquals(annotation.getId(), newAnnotation.getId()); 296 assertEquals(annotation.getHref(), newAnnotation.getHref()); 320 297 assertEquals("updated annotation 1", newAnnotation.getHeadline()); 321 298 assertEquals("text/plain", newAnnotation.getBody().getTextBody().getMimeType()); … … 329 306 System.out.println("test updateAnnotationBody"); 330 307 331 Annotation annotation = (new TestInstances( TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne();308 Annotation annotation = (new TestInstances("/backend/api")).getAnnotationOne(); 332 309 333 310 final AnnotationBody ab = new AnnotationBody(); … … 344 321 345 322 annotationResource.setHttpServletRequest(mockRequest); 346 annotationResource.setUriInfo(mockUriInfo);347 323 mockRequest.setRemoteUser("twagoo@mpi.nl"); 348 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI);349 324 mockRequest.setContextPath("/backend"); 325 mockRequest.setServletPath("/api"); 350 326 final UUID externalId = UUID.fromString("00000000-0000-0000-0000-000000000021"); 351 327 … … 358 334 mockeryRest.checking(new Expectations() { 359 335 { 360 oneOf(mockUriInfo).getBaseUri(); 361 will(returnValue(baseUri)); 362 363 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 336 337 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 364 338 365 339 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("twagoo@mpi.nl"); … … 395 369 System.out.println("test updateAnnotationHeadline"); 396 370 397 Annotation annotation = (new TestInstances( TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne();371 Annotation annotation = (new TestInstances("/api")).getAnnotationOne(); 398 372 399 373 final String newHeadline = "new Headline"; … … 406 380 407 381 annotationResource.setHttpServletRequest(mockRequest); 408 annotationResource.setUriInfo(mockUriInfo);409 382 mockRequest.setRemoteUser("twagoo@mpi.nl"); 410 final URI baseUri = URI.create(TestBackendConstants._TEST_SERVLET_URI);411 383 mockRequest.setContextPath("/backend"); 384 mockRequest.setServletPath("/api"); 412 385 final UUID externalId = UUID.fromString("00000000-0000-0000-0000-000000000021"); 413 386 … … 415 388 mockeryRest.checking(new Expectations() { 416 389 { 417 oneOf(mockUriInfo).getBaseUri(); 418 will(returnValue(baseUri)); 419 420 oneOf(mockDbDispatcher).setServiceURI(baseUri.toString()); 390 oneOf(mockDbDispatcher).setResourcesPaths("/backend/api"); 421 391 422 392 oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("twagoo@mpi.nl"); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r5203 r5385 70 70 private JdbcTemplate jdbcTemplate; 71 71 72 72 String _relativePath = "/backend/api"; 73 73 74 74 … … 81 81 .requestListenerClass(RequestContextListener.class) 82 82 .contextListenerClass(ContextLoaderListener.class) 83 .contextPath("/backend").servletPath("/api") 83 84 .build(); 84 85 … … 101 102 jdbcTemplate.execute(JdbcResourceDaoTest.getNormalisedSql()); 102 103 jdbcTemplate.execute(JdbcResourceDaoTest.getTestDataInsertSql()); 104 103 105 } 104 106 … … 122 124 // Getting annotation 123 125 System.out.println("testGetAnnotation"); 124 final String externalIDstring = "00000000-0000-0000-0000-000000000021"; 125 final Annotation testAnnotation = (new TestInstances(resource().getURI().toString())).getAnnotationOne(); 126 127 final String requestUrl = "annotations/" + externalIDstring; 128 System.out.println("requestUrl: " + requestUrl); 129 130 Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML); 126 final Annotation testAnnotation = (new TestInstances(_relativePath)).getAnnotationOne(); 127 128 Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/00000000-0000-0000-0000-000000000021")).accept(MediaType.TEXT_XML); 131 129 ClientResponse response = responseBuilder.get(ClientResponse.class); 132 130 … … 136 134 assertEquals(testAnnotation.getBody().getTextBody().getBody(), entity.getBody().getTextBody().getBody()); 137 135 assertEquals(testAnnotation.getHeadline(), entity.getHeadline()); 138 assertEquals(testAnnotation.getOwner Ref(), entity.getOwnerRef());136 assertEquals(testAnnotation.getOwnerHref(), entity.getOwnerHref()); 139 137 assertEquals(Access.WRITE, entity.getPermissions().getPublic()); 140 138 assertEquals(3, entity.getPermissions().getPermission().size()); 141 139 assertEquals("write", entity.getPermissions().getPermission().get(0).getLevel().value()); 142 assertEquals( resource().getURI()+"principals/"+"00000000-0000-0000-0000-000000000112", entity.getPermissions().getPermission().get(0).getPrincipalRef());140 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000112", entity.getPermissions().getPermission().get(0).getPrincipalHref()); 143 141 assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 144 assertEquals( resource().getURI()+"principals/"+"00000000-0000-0000-0000-000000000113", entity.getPermissions().getPermission().get(1).getPrincipalRef());142 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000113", entity.getPermissions().getPermission().get(1).getPrincipalHref()); 145 143 assertEquals("read", entity.getPermissions().getPermission().get(1).getLevel().value()); 146 assertEquals( resource().getURI()+"principals/"+"00000000-0000-0000-0000-000000000221", entity.getPermissions().getPermission().get(2).getPrincipalRef());144 assertEquals(_relativePath+"/principals/00000000-0000-0000-0000-000000000221", entity.getPermissions().getPermission().get(2).getPrincipalHref()); 147 145 assertEquals(2, entity.getTargets().getTargetInfo().size()); 148 assertEquals( resource().getURI().toString()+"targets/"+"00000000-0000-0000-0000-000000000031", entity.getTargets().getTargetInfo().get(0).getRef());149 assertEquals( resource().getURI().toString()+"targets/"+"00000000-0000-0000-0000-000000000032", entity.getTargets().getTargetInfo().get(1).getRef());146 assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000031", entity.getTargets().getTargetInfo().get(0).getHref()); 147 assertEquals(_relativePath+"/targets/00000000-0000-0000-0000-000000000032", entity.getTargets().getTargetInfo().get(1).getHref()); 150 148 assertEquals(testAnnotation.getLastModified(), entity.getLastModified()); 151 assertEquals( resource().getURI()+requestUrl, entity.getURI());149 assertEquals(_relativePath+"/annotations/00000000-0000-0000-0000-000000000021", entity.getHref()); 152 150 } 153 151 … … 194 192 System.out.println("test createAnnotation"); 195 193 System.out.println("POST "+resource().getURI().toString()+"annotations/"); 196 final Annotation annotationToAdd = (new TestInstances(this.getBaseURI().toString())).getAnnotationToAdd(); 194 195 final Annotation annotationToAdd = (new TestInstances(_relativePath)).getAnnotationToAdd(); 197 196 final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotationToAdd); 198 197 … … 208 207 assertEquals(0, entityA.getPermissions().getPermission().size()); 209 208 assertEquals(Access.WRITE, entityA.getPermissions().getPublic()); 210 assertEquals( this.getBaseURI() + "principals/00000000-0000-0000-0000-000000000113", entityA.getOwnerRef());209 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000113", entityA.getOwnerHref()); 211 210 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 212 assertEquals( this.getBaseURI()+ "targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getRef());211 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 213 212 assertEquals("version 1.0", entityA.getTargets().getTargetInfo().get(0).getVersion()); 214 213 … … 231 230 System.out.println("test updateAnnotation"); 232 231 System.out.println("PUT "+resource().getURI().toString()+"annotations/00000000-0000-0000-0000-000000000021"); 233 Annotation annotation = (new TestInstances(this.getBaseURI().toString())).getAnnotationOne(); 232 233 Annotation annotation = (new TestInstances(_relativePath)).getAnnotationOne(); 234 234 annotation.getPermissions().setPublic(Access.READ); 235 235 annotation.setHeadline("updated annotation 1"); … … 254 254 assertEquals(2, entityA.getPermissions().getPermission().size()); 255 255 assertEquals(Access.READ, entityA.getPermissions().getPublic()); 256 assertEquals( this.getBaseURI() + "principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerRef());256 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref()); 257 257 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 258 assertEquals( this.getBaseURI()+ "targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getRef());258 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 259 259 260 260 } … … 297 297 assertEquals(3, entityA.getPermissions().getPermission().size()); 298 298 assertEquals(Access.WRITE , entityA.getPermissions().getPublic()); 299 assertEquals(this.getBaseURI() + "principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerRef()); 299 300 301 assertEquals(_relativePath + "/principals/00000000-0000-0000-0000-000000000111", entityA.getOwnerHref()); 300 302 assertEquals("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia#de_Opdracht", entityA.getTargets().getTargetInfo().get(0).getLink()); 301 assertEquals( this.getBaseURI()+ "targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getRef());303 assertEquals(_relativePath+ "/targets/00000000-0000-0000-0000-000000000031", entityA.getTargets().getTargetInfo().get(0).getHref()); 302 304 303 305 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r5145 r5385 32 32 @RunWith(value = SpringJUnit4ClassRunner.class) 33 33 @ContextConfiguration(locations = {"/spring-test-config/mockeryRest.xml", "/spring-test-config/mockDBDispatcher.xml", "/spring-config/jaxbMarshallerFactory.xml", 34 "/spring-config/jaxbUnmarshallerFactory.xml" ,"/spring-test-config/mockUriInfo.xml"})34 "/spring-config/jaxbUnmarshallerFactory.xml"}) 35 35 public class NotebookResourceTest { 36 36
Note: See TracChangeset
for help on using the changeset viewer.