Changeset 5686
- Timestamp:
- 09/30/14 16:41:32 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBDispatcher.java
r5661 r5686 18 18 package eu.dasish.annotation.backend.dao; 19 19 20 import eu.dasish.annotation.backend.MatchMode; 20 21 import eu.dasish.annotation.backend.NotInDataBaseException; 21 22 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; … … 77 78 * created after time-samp "after and before time-stamp "before". 78 79 */ 79 List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException;80 List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, MatchMode matchMode, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException; 80 81 81 82 AnnotationInfoList getAllAnnotationInfos(); … … 96 97 * created after time-samp "after and before time-stamp "before". 97 98 */ 98 AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String link, String text, Number inloggedPrincipalID, String access, String namespace, String after, String before) throws NotInDataBaseException;99 AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String link, MatchMode matchMode, String text, Number inloggedPrincipalID, String access, String namespace, String after, String before) throws NotInDataBaseException; 99 100 100 101 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherImlp.java
r5661 r5686 21 21 import eu.dasish.annotation.backend.Resource; 22 22 import eu.dasish.annotation.backend.Helpers; 23 import eu.dasish.annotation.backend.MatchMode; 23 24 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; 24 25 import eu.dasish.annotation.backend.PrincipalExists; … … 173 174 174 175 //////////////////////////////////////////////////////////////////////// 175 @Override 176 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link Substring, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException {176 @Override 177 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, MatchMode matchMode, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException { 177 178 178 179 Number ownerID; 179 180 180 181 if (ownerId != null) { 181 if (accessMode.equals("owner")) { 182 if (accessMode.equals("owner")) { // inloggedUser is the owner of the annotations 182 183 if (!ownerId.equals(principalDao.getExternalID(inloggedPrincipalID))) { 183 184 logger.info("The inlogged principal is demanded to be the owner of the annotations, however the expected owner is different and has the UUID " + ownerId.toString()); … … 218 219 219 220 // filtering on reference 220 return this.filterAnnotationIDsOnReference(annotationIDs, link Substring);221 return this.filterAnnotationIDsOnReference(annotationIDs, link, matchMode); 221 222 } 222 223 … … 226 227 227 228 /// helpers /// 228 private List<Number> filterAnnotationIDsOnReference(List<Number> annotationIDs, String link Substring) {229 if (link Substring!= null) {230 if (!link Substring.isEmpty()) {229 private List<Number> filterAnnotationIDsOnReference(List<Number> annotationIDs, String link, MatchMode matchMode) { 230 if (link != null) { 231 if (!link.isEmpty()) { 231 232 if (annotationIDs != null) { 232 String partiallyEncoded = this.encodeURLNoSlashEncoded(link Substring);233 String partiallyEncoded = this.encodeURLNoSlashEncoded(link); 233 234 String urlEncoded = null; 234 235 try { 235 urlEncoded = URLEncoder.encode(link Substring, "UTF-8");236 urlEncoded = URLEncoder.encode(link, "UTF-8"); 236 237 } catch (UnsupportedEncodingException e) { 237 238 logger.debug(e.toString()); … … 243 244 for (Number targetID : targets) { 244 245 if (!result.contains(annotationID)) { 245 String link = targetDao.getLink(targetID);246 if ( link.contains(linkSubstring) || link.contains(partiallyEncoded)) {246 String linkRunner = targetDao.getLink(targetID); 247 if (matchCriterium(linkRunner, link, matchMode) || matchCriterium(linkRunner, partiallyEncoded, matchMode)) { 247 248 result.add(annotationID); 248 249 } else { 249 250 if (urlEncoded != null) { 250 if ( link.contains(urlEncoded)) {251 if (matchCriterium(linkRunner, urlEncoded, matchMode)) { 251 252 result.add(annotationID); 252 253 } … … 261 262 } 262 263 return annotationIDs; 264 } 265 266 private boolean matchCriterium(String currentString, String pattern, MatchMode matchMode){ 267 switch (matchMode) { 268 case EXACT: return currentString.equals(pattern); 269 case STARTS_WITH: return currentString.startsWith(pattern); 270 case ENDS_WITH: return currentString.endsWith(pattern); 271 case CONTAINS: return currentString.contains(pattern); 272 default: return false; 273 } 263 274 } 264 275 … … 339 350 340 351 @Override 341 public AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String link, String text, Number inloggedPrincipalID, String access, String namespace, String after, String before) throws NotInDataBaseException {342 List<Number> annotationIDs = this.getFilteredAnnotationIDs(ownerId, link, text, inloggedPrincipalID, access, namespace, after, before);352 public AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String link, MatchMode matchMode, String text, Number inloggedPrincipalID, String access, String namespace, String after, String before) throws NotInDataBaseException { 353 List<Number> annotationIDs = this.getFilteredAnnotationIDs(ownerId, link, matchMode, text, inloggedPrincipalID, access, namespace, after, before); 343 354 AnnotationInfoList result = new AnnotationInfoList(); 344 355 for (Number annotationID : annotationIDs) { … … 401 412 ReferenceList referenceList = new ReferenceList(); 402 413 for (Number siblingID : targetIDs) { 414 if (!siblingID.equals(targetID)) { 403 415 referenceList.getHref().add(targetDao.getHrefFromInternalID(siblingID)); 416 } 404 417 } 405 418 return referenceList; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5685 r5686 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 21 import eu.dasish.annotation.backend.ForbiddenException; 22 import eu.dasish.annotation.backend.MatchMode; 22 23 import eu.dasish.annotation.backend.NotInDataBaseException; 23 24 import eu.dasish.annotation.backend.Resource; … … 66 67 @Transactional(rollbackFor = {Exception.class}) 67 68 public class AnnotationResource extends ResourceResource { 69 70 final private String defaultMatchMode = "exact"; 71 final private String[] admissibleMatchModes = {"exact", "starts_with", "ends_with", "contains"}; 68 72 69 73 public void setHttpServletResponse(HttpServletResponse httpServletResponse) { … … 81 85 public AnnotationResource() { 82 86 } 87 83 88 84 89 @GET … … 149 154 @Transactional(readOnly = true) 150 155 public JAXBElement<AnnotationInfoList> getFilteredAnnotations(@QueryParam("link") String link, 156 @QueryParam("matchMode") String matchMode, 151 157 @QueryParam("text") String text, 152 158 @QueryParam("access") String access, … … 160 166 return new ObjectFactory().createAnnotationInfoList(new AnnotationInfoList()); 161 167 } 168 169 if (matchMode == null) { 170 matchMode = defaultMatchMode; 171 } 172 if (!Arrays.asList(admissibleMatchModes).contains(matchMode)) { 173 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "ivalide match mode " + matchMode); 174 return new ObjectFactory().createAnnotationInfoList(new AnnotationInfoList()); 175 } 162 176 163 177 UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null; 178 179 164 180 if (access == null) { 165 181 access = defaultAccess; … … 170 186 return new ObjectFactory().createAnnotationInfoList(new AnnotationInfoList()); 171 187 } 172 try { 173 final AnnotationInfoList annotationInfoList = dbDispatcher.getFilteredAnnotationInfos(ownerExternalUUID, link, text, principalID, access, namespace, after, before); 188 189 190 try { 191 final AnnotationInfoList annotationInfoList = dbDispatcher.getFilteredAnnotationInfos(ownerExternalUUID, link, MatchMode.valueOf(matchMode.toUpperCase()), text, principalID, access, namespace, after, before); 174 192 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 175 193 } catch (NotInDataBaseException e) { … … 193 211 194 212 System.out.print("Preparing the data: getting the list of all annotations, picking up "+n+" of them randomly, and initializing threads"); 195 final List<Number> annotationIDs = dbDispatcher.getFilteredAnnotationIDs(null, null, null, remotePrincipalID, "read", null, null, null);213 final List<Number> annotationIDs = dbDispatcher.getFilteredAnnotationIDs(null, null, null, null, remotePrincipalID, "read", null, null, null); 196 214 final int size = annotationIDs.size(); 197 215 List<GetThread> threads = new ArrayList<GetThread>(n); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp
r5685 r5686 57 57 <!-- !Problem: how to ask the servlet if the given user is logged in, may be by some other running somewhere client<br> --> 58 58 GET <a href="api/principals/info?email=Twan.Goosen@mpi.nl">api/principals/info?email=Twan.Goosen@mpi.nl</a> <br> 59 GET <a href="api/annotations?link=Sagrada_Fam%C3%ADlia">api/annotations?link=Sagrada_Fam%C3%ADlia</a> <br> 60 GET <a href="api/annotations?link=Antoni_Gaud%C3%AD">api/annotations?link=Antoni_Gaud%C3%AD</a> <br> 59 GET <a href="api/annotations?link=Sagrada&matchMode=contains">api/annotations?link=Sagrada&matchMode=contains</a> <br> 60 GET <a href="api/annotations?link=http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia&matchMode=exact">api/annotations?link=http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia&matchMode=exact</a> <br> 61 GET <a href="api/annotations?link=http://nl.wikipedia.org/wiki&matchMode=starts_with">api/annotations?link=http://nl.wikipedia.org/wiki&matchMode=starts_with</a> <br> 62 GET <a href="api/annotations?link=_Fam%C3%ADlia&matchMode=ends_with">api/annotations?link=_Fam%C3%ADlia&matchMode=ends_with</a> <br> 63 GET <a href="api/annotations?link=http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia">api/annotations?link=http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia</a> <br> 64 GET <a href="api/annotations?link=http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD">api/annotations?link=http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD</a> <br> 61 65 GET <a href="api/annotations?after=2013-02-04 15:57:58.046908&before=2014-06-25 10:08:16.213186">api/annotations?after=2014-02-04 15:57:58.046908&before=2014-04-06 10:08:16.213186</a><br> 62 66 <!-- !Comment: What is "namespace" query parameter? Must be implemented and tested <br>--> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherTest.java
r5393 r5686 19 19 20 20 import eu.dasish.annotation.backend.Helpers; 21 import eu.dasish.annotation.backend.MatchMode; 21 22 import eu.dasish.annotation.backend.NotInDataBaseException; 22 23 import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; … … 305 306 */ 306 307 @Test 307 public void testGetFilteredAnnotationIDs () throws NotInDataBaseException {308 public void testGetFilteredAnnotationIDsContains() throws NotInDataBaseException { 308 309 System.out.println("test getFilteredAnnotationIDs"); 309 310 … … 366 367 367 368 368 List result = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_Fam%C3%ADlia", "some html 1", 3, "read", null, after, before); 369 assertEquals(1, result.size()); 370 assertEquals(1, result.get(0)); 371 } 372 373 @Test 374 public void testGetFilteredAnnotationIDs2() throws NotInDataBaseException { 369 List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "read", null, after, before); 370 assertEquals(1, resultContains.size()); 371 assertEquals(1, resultContains.get(0)); 372 373 374 375 } 376 377 378 /** 379 * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. 380 */ 381 @Test 382 public void testGetFilteredAnnotationIDsExact() throws NotInDataBaseException { 383 System.out.println("test getFilteredAnnotationIDs"); 384 385 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 386 mockAnnotationIDs1.add(1); 387 388 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 389 //mockAnnotationIDsOwned.add(3); 390 391 final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); 392 mockAnnotationIDsRead.add(1); 393 mockAnnotationIDsRead.add(2); 394 395 396 final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); 397 mockAnnotationIDsPublicRead.add(1); 398 mockAnnotationIDsPublicRead.add(2); 399 400 final List<Number> mockTargets1 = new ArrayList<Number>(); 401 mockTargets1.add(1); 402 mockTargets1.add(2); 403 404 405 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 406 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 407 408 final String after = (new Timestamp(0)).toString(); 409 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 410 411 final Number loggedIn = 3; 412 413 mockeryDao.checking(new Expectations() { 414 { 415 416 417 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 418 will(returnValue(mockAnnotationIDs1)); 419 420 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); 421 will(returnValue(mockAnnotationIDsRead)); 422 423 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); 424 will(returnValue(mockAnnotationIDsPublicRead)); 425 426 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 427 will(returnValue(mockAnnotationIDsOwned)); 428 429 oneOf(targetDao).getTargetIDs(1); 430 will(returnValue(mockTargets1)); 431 432 oneOf(targetDao).getLink(1); 433 will(returnValue(link1)); 434 435 oneOf(targetDao).getLink(2); 436 will(returnValue(link2)); 437 438 439 } 440 }); 441 442 443 444 List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "read", null, after, before); 445 assertEquals(1, resultExact.size()); 446 assertEquals(1, resultExact.get(0)); 447 448 449 } 450 451 /** 452 * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. 453 */ 454 @Test 455 public void testGetFilteredAnnotationIDsStartsWith() throws NotInDataBaseException { 456 System.out.println("test getFilteredAnnotationIDs"); 457 458 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 459 mockAnnotationIDs1.add(1); 460 461 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 462 //mockAnnotationIDsOwned.add(3); 463 464 final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); 465 mockAnnotationIDsRead.add(1); 466 mockAnnotationIDsRead.add(2); 467 468 469 final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); 470 mockAnnotationIDsPublicRead.add(1); 471 mockAnnotationIDsPublicRead.add(2); 472 473 final List<Number> mockTargets1 = new ArrayList<Number>(); 474 mockTargets1.add(1); 475 mockTargets1.add(2); 476 477 478 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 479 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 480 481 final String after = (new Timestamp(0)).toString(); 482 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 483 484 final Number loggedIn = 3; 485 486 mockeryDao.checking(new Expectations() { 487 { 488 489 490 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 491 will(returnValue(mockAnnotationIDs1)); 492 493 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); 494 will(returnValue(mockAnnotationIDsRead)); 495 496 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); 497 will(returnValue(mockAnnotationIDsPublicRead)); 498 499 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 500 will(returnValue(mockAnnotationIDsOwned)); 501 502 oneOf(targetDao).getTargetIDs(1); 503 will(returnValue(mockTargets1)); 504 505 oneOf(targetDao).getLink(1); 506 will(returnValue(link1)); 507 508 oneOf(targetDao).getLink(2); 509 will(returnValue(link2)); 510 511 512 } 513 }); 514 515 516 517 List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "read", null, after, before); 518 assertEquals(1, resultStartsWith.size()); 519 assertEquals(1, resultStartsWith.get(0)); 520 521 522 523 } 524 525 /** 526 * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. 527 */ 528 @Test 529 public void testGetFilteredAnnotationIDsEndsWith() throws NotInDataBaseException { 530 System.out.println("test getFilteredAnnotationIDs"); 531 532 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 533 mockAnnotationIDs1.add(1); 534 535 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 536 //mockAnnotationIDsOwned.add(3); 537 538 final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); 539 mockAnnotationIDsRead.add(1); 540 mockAnnotationIDsRead.add(2); 541 542 543 final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); 544 mockAnnotationIDsPublicRead.add(1); 545 mockAnnotationIDsPublicRead.add(2); 546 547 final List<Number> mockTargets1 = new ArrayList<Number>(); 548 mockTargets1.add(1); 549 mockTargets1.add(2); 550 551 552 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 553 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 554 555 final String after = (new Timestamp(0)).toString(); 556 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 557 558 final Number loggedIn = 3; 559 560 mockeryDao.checking(new Expectations() { 561 { 562 563 564 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 565 will(returnValue(mockAnnotationIDs1)); 566 567 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); 568 will(returnValue(mockAnnotationIDsRead)); 569 570 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); 571 will(returnValue(mockAnnotationIDsPublicRead)); 572 573 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 574 will(returnValue(mockAnnotationIDsOwned)); 575 576 oneOf(targetDao).getTargetIDs(1); 577 will(returnValue(mockTargets1)); 578 579 oneOf(targetDao).getLink(1); 580 will(returnValue(link1)); 581 582 oneOf(targetDao).getLink(2); 583 will(returnValue(link2)); 584 585 586 } 587 }); 588 589 590 List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "read", null, after, before); 591 assertEquals(1, resultEndsWith.size()); 592 assertEquals(1, resultEndsWith.get(0)); 593 594 } 595 596 597 @Test 598 public void testGetFilteredAnnotationIDs2Contains() throws NotInDataBaseException { 375 599 System.out.println("test getFilteredAnnotationIDs"); 376 600 … … 404 628 mockeryDao.checking(new Expectations() { 405 629 { 406 407 408 630 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 409 631 will(returnValue(mockAnnotationIDs1)); … … 426 648 oneOf(targetDao).getLink(2); 427 649 will(returnValue(link2)); 428 429 } 430 }); 431 432 433 List result = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_Fam%C3%ADlia", "some html 1", 3, "write", null, after, before); 434 assertEquals(1, result.size()); 435 assertEquals(1, result.get(0)); 650 651 } 652 }); 653 654 655 656 List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "write", null, after, before); 657 assertEquals(1, resultContains.size()); 658 assertEquals(1, resultContains.get(0)); 659 } 660 661 @Test 662 public void testGetFilteredAnnotationIDs2Exact() throws NotInDataBaseException { 663 System.out.println("test getFilteredAnnotationIDs"); 664 665 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 666 mockAnnotationIDs1.add(1); 667 668 669 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 670 //mockAnnotationIDsOwned.add(3); 671 672 final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); 673 mockAnnotationIDsWrite.add(2); 674 675 676 final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); 677 mockAnnotationIDsPublicWrite.add(1); 678 679 final List<Number> mockTargets1 = new ArrayList<Number>(); 680 mockTargets1.add(1); 681 mockTargets1.add(2); 682 683 684 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 685 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 686 687 final String after = (new Timestamp(0)).toString(); 688 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 689 690 final Number loggedIn = 3; 691 692 mockeryDao.checking(new Expectations() { 693 { 694 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 695 will(returnValue(mockAnnotationIDs1)); 696 697 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); 698 will(returnValue(mockAnnotationIDsWrite)); 699 700 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); 701 will(returnValue(mockAnnotationIDsPublicWrite)); 702 703 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 704 will(returnValue(mockAnnotationIDsOwned)); 705 706 oneOf(targetDao).getTargetIDs(1); 707 will(returnValue(mockTargets1)); 708 709 oneOf(targetDao).getLink(1); 710 will(returnValue(link1)); 711 712 oneOf(targetDao).getLink(2); 713 will(returnValue(link2)); 714 715 } 716 }); 717 718 719 720 List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "write", null, after, before); 721 assertEquals(1, resultExact.size()); 722 assertEquals(1, resultExact.get(0)); 723 724 725 } 726 727 @Test 728 public void testGetFilteredAnnotationIDs2StartsWith() throws NotInDataBaseException { 729 System.out.println("test getFilteredAnnotationIDs"); 730 731 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 732 mockAnnotationIDs1.add(1); 733 734 735 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 736 //mockAnnotationIDsOwned.add(3); 737 738 final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); 739 mockAnnotationIDsWrite.add(2); 740 741 742 final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); 743 mockAnnotationIDsPublicWrite.add(1); 744 745 final List<Number> mockTargets1 = new ArrayList<Number>(); 746 mockTargets1.add(1); 747 mockTargets1.add(2); 748 749 750 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 751 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 752 753 final String after = (new Timestamp(0)).toString(); 754 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 755 756 final Number loggedIn = 3; 757 758 mockeryDao.checking(new Expectations() { 759 { 760 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 761 will(returnValue(mockAnnotationIDs1)); 762 763 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); 764 will(returnValue(mockAnnotationIDsWrite)); 765 766 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); 767 will(returnValue(mockAnnotationIDsPublicWrite)); 768 769 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 770 will(returnValue(mockAnnotationIDsOwned)); 771 772 oneOf(targetDao).getTargetIDs(1); 773 will(returnValue(mockTargets1)); 774 775 oneOf(targetDao).getLink(1); 776 will(returnValue(link1)); 777 778 oneOf(targetDao).getLink(2); 779 will(returnValue(link2)); 780 781 } 782 }); 783 784 785 List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "write", null, after, before); 786 assertEquals(1, resultStartsWith.size()); 787 assertEquals(1, resultStartsWith.get(0)); 788 789 790 } 791 792 @Test 793 public void testGetFilteredAnnotationIDs2EndsWith() throws NotInDataBaseException { 794 System.out.println("test getFilteredAnnotationIDs"); 795 796 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 797 mockAnnotationIDs1.add(1); 798 799 800 final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); 801 //mockAnnotationIDsOwned.add(3); 802 803 final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); 804 mockAnnotationIDsWrite.add(2); 805 806 807 final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); 808 mockAnnotationIDsPublicWrite.add(1); 809 810 final List<Number> mockTargets1 = new ArrayList<Number>(); 811 mockTargets1.add(1); 812 mockTargets1.add(2); 813 814 815 final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; 816 final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 817 818 final String after = (new Timestamp(0)).toString(); 819 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 820 821 final Number loggedIn = 3; 822 823 mockeryDao.checking(new Expectations() { 824 { 825 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 826 will(returnValue(mockAnnotationIDs1)); 827 828 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); 829 will(returnValue(mockAnnotationIDsWrite)); 830 831 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); 832 will(returnValue(mockAnnotationIDsPublicWrite)); 833 834 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 835 will(returnValue(mockAnnotationIDsOwned)); 836 837 oneOf(targetDao).getTargetIDs(1); 838 will(returnValue(mockTargets1)); 839 840 oneOf(targetDao).getLink(1); 841 will(returnValue(link1)); 842 843 oneOf(targetDao).getLink(2); 844 will(returnValue(link2)); 845 846 } 847 }); 848 849 850 851 List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "write", null, after, before); 852 assertEquals(1, resultEndsWith.size()); 853 assertEquals(1, resultEndsWith.get(0)); 436 854 437 855 } … … 452 870 oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); 453 871 will(returnValue(mockAnnotationIDs1)); 454 455 } 456 }); 457 458 459 List result = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_Fam%C3%ADlia", "some html 1", 3, "owner", null, after, before); 460 assertEquals(0, result.size()); 461 } 462 872 873 oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); 874 will(returnValue(mockAnnotationIDs1)); 875 876 oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); 877 will(returnValue(mockAnnotationIDs1)); 878 879 oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); 880 will(returnValue(mockAnnotationIDs1)); 881 882 } 883 }); 884 885 886 List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "owner", null, after, before); 887 assertEquals(0, resultContains.size()); 888 889 List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "owner", null, after, before); 890 assertEquals(0, resultExact.size()); 891 892 List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "owner", null, after, before); 893 assertEquals(0, resultStartsWith.size()); 894 895 List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "owner", null, after, before); 896 assertEquals(0, resultEndsWith.size()); 897 } 898 899 463 900 @Test 464 901 public void testGetFilteredAnnotationIDs4() throws NotInDataBaseException { … … 484 921 485 922 486 List result = dbDispatcher.getFilteredAnnotationIDs(UUID.fromString("00000000-0000-0000-0000-000000000111"), "nl.wikipedia.org", "some html 1", 3, "owner", null, after, before);923 List result = dbDispatcher.getFilteredAnnotationIDs(UUID.fromString("00000000-0000-0000-0000-000000000111"), "nl.wikipedia.org", MatchMode.CONTAINS, "some html 1", 3, "owner", null, after, before); 487 924 assertEquals(0, result.size()); 488 925 } … … 630 1067 631 1068 632 AnnotationInfoList result = dbDispatcher.getFilteredAnnotationInfos(ownerUUID, " nl.wikipedia.org", "some html 1", 3, "read", null, after, before);1069 AnnotationInfoList result = dbDispatcher.getFilteredAnnotationInfos(ownerUUID, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "read", null, after, before); 633 1070 assertEquals(1, result.getAnnotationInfo().size()); 634 1071 AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0);
Note: See TracChangeset
for help on using the changeset viewer.