Changeset 4885
- Timestamp:
- 04/02/14 20:59:43 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
r4865 r4885 308 308 Number addPrincipal(Principal principal, String remoteID) throws NotInDataBaseException, PrincipalExists; 309 309 310 int addAnnotationPrincipalAccess(Number annotationID, Number principalID, Access access); 311 /// notebooks //// 310 /// notebooks //// 312 311 Number createNotebook(Notebook notebook, Number ownerID) throws NotInDataBaseException; 313 312 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4865 r4885 180 180 public List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedPrincipalID, String accessMode, String namespace, String after, String before) throws NotInDataBaseException { 181 181 182 if (ownerId != null && accessMode.equals("owner")) { 183 // then UUID of the inlogged principal should be the same as the owner's uuid, 184 // because an annotation cannot have two different owners 185 if (!ownerId.equals(principalDao.getExternalID(inloggedPrincipalID))) { 186 logger.debug("The inlogged principal is demanded to be the owner of the annotations, however the expected owner is different and has the UUID " + ownerId.toString()); 187 return new ArrayList<Number>(); 188 } 189 } 190 191 Number ownerID = (ownerId != null) ? principalDao.getInternalID(ownerId) : null; 182 Number ownerID; 183 184 if (ownerId != null) { 185 if (accessMode.equals("owner")) { 186 if (!ownerId.equals(principalDao.getExternalID(inloggedPrincipalID))) { 187 logger.debug("The inlogged principal is demanded to be the owner of the annotations, however the expected owner is different and has the UUID " + ownerId.toString()); 188 return new ArrayList<Number>(); 189 } else { 190 ownerID = inloggedPrincipalID; 191 } 192 } else { 193 ownerID = principalDao.getInternalID(ownerId); 194 } 195 196 } else { 197 if (accessMode.equals("owner")) { 198 ownerID = inloggedPrincipalID; 199 } else { 200 ownerID = null; 201 } 202 } 203 204 192 205 193 206 List<Number> annotationIDs = annotationDao.getFilteredAnnotationIDs(ownerID, text, namespace, after, before); … … 522 535 @Override 523 536 public int updateAnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) { 524 return annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 537 int result; 538 Access currentAccess = annotationDao.getAccess(annotationID, principalID); 539 if (currentAccess != Access.NONE) { 540 result = annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 541 } else { 542 if (!access.equals(Access.NONE)) { 543 result = annotationDao.deleteAnnotationPrincipalAccess(annotationID, principalID); 544 result = annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); 545 } else { 546 result = 0; 547 } 548 } 549 return result; 525 550 } 526 551 … … 536 561 int result = 0; 537 562 for (Permission permission : permissions) { 538 Number principalID = principalDao.getInternalID (UUID.fromString(principalDao.stringURItoExternalID(permission.getPrincipalRef())));563 Number principalID = principalDao.getInternalIDFromURI(permission.getPrincipalRef()); 539 564 Access access = permission.getLevel(); 540 565 Access currentAccess = annotationDao.getAccess(annotationID, principalID); 541 if (!access.value().equals(currentAccess.value())) { 542 result = result + annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 566 if (!access.equals(currentAccess)) { 567 // then we need to update or psossibly add for none 568 if (!currentAccess.equals(Access.NONE)) { 569 result = result + annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 570 } else { 571 annotationDao.deleteAnnotationPrincipalAccess(annotationID, principalID); 572 result = result + annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); 573 } 543 574 } 544 575 } … … 554 585 int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); 555 586 int deletedPrinsipalsAccesss = annotationDao.deleteAnnotationPermissions(annotationID); 556 int addedTargets = addTargets(annotation, annotationID);557 int addedPrincipalsAccesss = addPermissions(annotation.getPermissions().getPermission(), annotationID);587 int addedTargets = this.addTargets(annotation, annotationID); 588 int addedPrincipalsAccesss = this.addPermissions(annotation.getPermissions().getPermission(), annotationID); 558 589 int updatedPublicAttribute = annotationDao.updatePublicAttribute(annotationID, annotation.getPermissions().getPublic()); 559 590 return updatedAnnotations; … … 634 665 } 635 666 636 @Override 637 public int addAnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) { 638 return annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); 639 } 640 667 641 668 //////////// notebooks ////// 642 669 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4865 r4885 393 393 394 394 String[] body = retrieveBodyComponents(annotation.getBody()); 395 String externalID = stringURItoExternalID(annotation.getURI()); 395 //debug 396 System.out.println(annotation.getURI()); 397 String externalID = this.stringURItoExternalID(annotation.getURI()); 396 398 Map<String, Object> params = new HashMap<String, Object>(); 397 399 params.put("owner", newOwnerID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4865 r4885 274 274 @Override 275 275 public String stringURItoExternalID(String stringURI) { 276 // debug 277 System.out.println("test Input stringURItoExternalID : "+stringURI); 276 278 if (stringURI.length() > _serviceURI.length()) { 277 279 return stringURI.substring(_serviceURI.length()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4834 r4885 286 286 final Number annotationID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString(annotationExternalId), Resource.ANNOTATION); 287 287 if (remotePrincipalID.equals(dbIntegrityService.getAnnotationOwnerID(annotationID)) || dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 288 289 int result = (dbIntegrityService.getAccess(annotationID, principalID) != null) 290 ? dbIntegrityService.updateAnnotationPrincipalAccess(annotationID, principalID, access) 291 : dbIntegrityService.addAnnotationPrincipalAccess(annotationID, principalID, access); 288 int result = dbIntegrityService.updateAnnotationPrincipalAccess(annotationID, principalID, access); 292 289 return result + " rows are updated/added"; 293 294 290 } else { 295 291 verboseOutput.FORBIDDEN_ACCESS_CHANGING(annotationExternalId, dbIntegrityService.getAnnotationOwner(annotationID).getDisplayName(), dbIntegrityService.getAnnotationOwner(annotationID).getEMail()); … … 311 307 @Produces(MediaType.APPLICATION_XML) 312 308 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/accesss/") 313 public JAXBElement<ResponseBody> update Accesss(@PathParam("annotationid") String annotationExternalId, PermissionList accesss) throws IOException {309 public JAXBElement<ResponseBody> updatePermissions(@PathParam("annotationid") String annotationExternalId, PermissionList accesss) throws IOException { 314 310 Number remotePrincipalID = this.getPrincipalID(); 315 311 try { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java
r4865 r4885 45 45 private Annotation makeAnnotationOne(String baseURI) { 46 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");47 result.setURI(baseURI+"annotations/00000000-0000-0000-0000-000000000021"); 48 48 49 49 try { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4865 r4885 215 215 map3.put(3, "read"); 216 216 listMap.add(map3); 217 Map<Number, String> map4 = new HashMap<Number, String>(); 218 map4.put(11, "read"); 219 listMap.add(map4); 217 220 218 221 final String uri1 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000111"; 219 222 final String uri2 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000112"; 220 223 final String uri3 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000113"; 224 final String uri4 = TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000221"; 221 225 222 226 … … 241 245 will(returnValue(mockTargetTwo)); 242 246 243 /// get AccesssForAnnotation247 /// getPermissionsForAnnotation 244 248 245 249 oneOf(annotationDao).getPermissions(1); … … 254 258 oneOf(principalDao).getURIFromInternalID(3); 255 259 will(returnValue(uri3)); 260 261 oneOf(principalDao).getURIFromInternalID(11); 262 will(returnValue(uri4)); 256 263 } 257 264 }); … … 272 279 assertEquals(mockTargetTwo.getVersion(), result.getTargets().getTargetInfo().get(1).getVersion()); 273 280 281 assertEquals(3, result.getPermissions().getPermission().size()); 282 274 283 assertEquals(Access.WRITE, result.getPermissions().getPermission().get(0).getLevel()); 275 284 assertEquals(uri2, result.getPermissions().getPermission().get(0).getPrincipalRef()); … … 277 286 assertEquals(Access.READ, result.getPermissions().getPermission().get(1).getLevel()); 278 287 assertEquals(uri3, result.getPermissions().getPermission().get(1).getPrincipalRef()); 288 289 assertEquals(Access.READ, result.getPermissions().getPermission().get(2).getLevel()); 290 assertEquals(uri4, result.getPermissions().getPermission().get(2).getPrincipalRef()); 279 291 280 292 assertEquals(Access.WRITE, result.getPermissions().getPublic()); … … 356 368 assertEquals(1, result.size()); 357 369 assertEquals(1, result.get(0)); 370 } 371 372 @Test 373 public void testGetFilteredAnnotationIDs2() throws NotInDataBaseException { 374 System.out.println("test getFilteredAnnotationIDs"); 375 376 final List<Number> mockTargetIDs = new ArrayList<Number>(); 377 mockTargetIDs.add(1); 378 mockTargetIDs.add(2); 379 380 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 381 mockAnnotationIDs1.add(1); 382 383 final List<Number> mockAnnotationIDs2 = new ArrayList<Number>(); 384 mockAnnotationIDs2.add(1); 385 mockAnnotationIDs2.add(2); 386 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 394 final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); 395 mockAnnotationIDsWrite.add(2); 396 397 final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); 398 mockAnnotationIDsRead.add(2); 399 400 final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); 401 mockAnnotationIDsWrite.add(1); 402 403 final String after = (new Timestamp(0)).toString(); 404 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 405 406 // final List<Number> mockRetval = new ArrayList<Number>(); 407 // mockRetval.add(1); 408 409 final Number loggedIn = 3; 410 411 mockeryDao.checking(new Expectations() { 412 { 413 oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org"); 414 will(returnValue(mockTargetIDs)); 415 416 oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs); 417 will(returnValue(mockAnnotationIDs2)); 418 419 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 420 will(returnValue(mockAnnotationIDs1)); 421 422 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); 423 will(returnValue(mockAnnotationIDsRead)); 424 425 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); 426 will(returnValue(mockAnnotationIDsPublicRead)); 427 428 oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); 429 will(returnValue(mockAnnotationIDsWrite)); 430 431 oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); 432 will(returnValue(mockAnnotationIDsPublicWrite)); 433 434 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, null, null, null, null); 435 will(returnValue(mockAnnotationIDsOwned)); 436 437 } 438 }); 439 440 441 List result = dbIntegrityService.getFilteredAnnotationIDs(null, "nl.wikipedia.org", "some html 1", 3, "write", null, after, before); 442 assertEquals(1, result.size()); 443 assertEquals(1, result.get(0)); 444 } 445 446 @Test 447 public void testGetFilteredAnnotationIDs3() throws NotInDataBaseException { 448 System.out.println("test getFilteredAnnotationIDs"); 449 450 final List<Number> mockTargetIDs = new ArrayList<Number>(); 451 mockTargetIDs.add(1); 452 mockTargetIDs.add(2); 453 454 final List<Number> mockAnnotationIDs2 = new ArrayList<Number>(); 455 mockAnnotationIDs2.add(1); 456 mockAnnotationIDs2.add(2); 457 458 459 final String after = (new Timestamp(0)).toString(); 460 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 461 462 // final List<Number> mockRetval = new ArrayList<Number>(); 463 // mockRetval.add(1); 464 465 final Number loggedIn = 3; 466 467 mockeryDao.checking(new Expectations() { 468 { 469 oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org"); 470 will(returnValue(mockTargetIDs)); 471 472 oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs); 473 will(returnValue(mockAnnotationIDs2)); 474 475 oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); 476 will(returnValue(new ArrayList<Number>())); 477 478 479 } 480 }); 481 482 483 List result = dbIntegrityService.getFilteredAnnotationIDs(null, "nl.wikipedia.org", "some html 1", 3, "owner", null, after, before); 484 assertEquals(0, result.size()); 485 } 486 487 @Test 488 public void testGetFilteredAnnotationIDs4() throws NotInDataBaseException { 489 System.out.println("test getFilteredAnnotationIDs"); 490 491 final List<Number> mockTargetIDs = new ArrayList<Number>(); 492 mockTargetIDs.add(1); 493 mockTargetIDs.add(2); 494 495 final List<Number> mockAnnotationIDs2 = new ArrayList<Number>(); 496 mockAnnotationIDs2.add(1); 497 mockAnnotationIDs2.add(2); 498 499 500 final String after = (new Timestamp(0)).toString(); 501 final String before = (new Timestamp(System.currentTimeMillis())).toString(); 502 503 // final List<Number> mockRetval = new ArrayList<Number>(); 504 // mockRetval.add(1); 505 506 final Number loggedIn = 3; 507 508 mockeryDao.checking(new Expectations() { 509 { 510 511 oneOf(principalDao).getExternalID(loggedIn); 512 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000113"))); 513 514 515 } 516 }); 517 518 519 List result = dbIntegrityService.getFilteredAnnotationIDs(UUID.fromString("00000000-0000-0000-0000-000000000111"), "nl.wikipedia.org", "some html 1", 3, "owner", null, after, before); 520 assertEquals(0, result.size()); 358 521 } 359 522 … … 1422 1585 assertTrue(dbIntegrityService.deleteNotebook(1)); 1423 1586 } 1587 1588 @Test 1589 public void testGetAccess() { 1590 System.out.println("test getAccess"); 1591 1592 mockeryDao.checking(new Expectations() { 1593 { 1594 1595 oneOf(annotationDao).getAccess(1, 3); 1596 will(returnValue(Access.READ)); 1597 1598 oneOf(annotationDao).getPublicAttribute(1); 1599 will(returnValue(Access.WRITE)); 1600 1601 } 1602 }); 1603 1604 assertEquals(Access.WRITE, dbIntegrityService.getAccess(1, 3)); 1605 1606 ////// 1607 1608 mockeryDao.checking(new Expectations() { 1609 { 1610 oneOf(annotationDao).getAccess(2, 3); 1611 will(returnValue(Access.READ)); 1612 1613 oneOf(annotationDao).getPublicAttribute(2); 1614 will(returnValue(Access.READ)); 1615 1616 } 1617 }); 1618 assertEquals(Access.READ, dbIntegrityService.getAccess(2, 3)); 1619 1620 ////// 1621 1622 mockeryDao.checking(new Expectations() { 1623 { 1624 oneOf(annotationDao).getAccess(3, 3); 1625 will(returnValue(Access.NONE)); 1626 1627 oneOf(annotationDao).getPublicAttribute(3); 1628 will(returnValue(Access.NONE)); 1629 1630 } 1631 }); 1632 assertEquals(Access.NONE, dbIntegrityService.getAccess(3, 3)); 1633 1634 ////// 1635 } 1636 1637 @Test 1638 public void testPublicAttribute() { 1639 1640 System.out.println("test getPublicAttribute"); 1641 mockeryDao.checking(new Expectations() { 1642 { 1643 oneOf(annotationDao).getPublicAttribute(2); 1644 will(returnValue(Access.READ)); 1645 1646 } 1647 }); 1648 assertEquals(Access.READ, dbIntegrityService.getPublicAttribute(2)); 1649 } 1650 1651 // @Override 1652 // public int updateAnnotation(Annotation annotation) throws NotInDataBaseException { 1653 // Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI()); 1654 // int updatedAnnotations = annotationDao.updateAnnotation(annotation, annotationID, principalDao.getInternalIDFromURI(annotation.getOwnerRef())); 1655 // int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); 1656 // int deletedPrinsipalsAccesss = annotationDao.deleteAnnotationPermissions(annotationID); 1657 // int addedTargets = addTargets(annotation, annotationID); 1658 // int addedPrincipalsAccesss = addPermissions(annotation.getPermissions().getPermission(), annotationID); 1659 // int updatedPublicAttribute = annotationDao.updatePublicAttribute(annotationID, annotation.getPermissions().getPublic()); 1660 // return updatedAnnotations; 1661 // } 1662 // for (TargetInfo targetInfo : targets) { 1663 // try { 1664 // Number targetIDRunner = targetDao.getInternalIDFromURI(targetInfo.getRef()); 1665 // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetIDRunner); 1666 // } catch (NotInDataBaseException e) { 1667 // Target newTarget = this.createFreshTarget(targetInfo); 1668 // Number targetID = targetDao.addTarget(newTarget); 1669 // String targetTemporaryID = targetDao.stringURItoExternalID(targetInfo.getRef()); 1670 // result.put(targetTemporaryID, targetDao.getExternalID(targetID).toString()); 1671 // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetID); 1672 // } 1673 // } 1674 @Test 1675 public void testUpdateAnnotation() throws NotInDataBaseException { 1676 1677 System.out.println("test updateAnnotation"); 1678 1679 final Annotation annotation = (new TestInstances(TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne(); 1680 final NotInDataBaseException e = new NotInDataBaseException("00000000-0000-0000-0000-000000000031"); 1681 final String mockTempID = "00000000-0000-0000-0000-000000000031"; 1682 final UUID mockNewID = UUID.randomUUID(); 1683 final PermissionList permissions = annotation.getPermissions(); 1684 1685 1686 System.out.println("test updateAnnotation"); 1687 mockeryDao.checking(new Expectations() { 1688 { 1689 oneOf(annotationDao).getInternalIDFromURI(annotation.getURI()); 1690 will(returnValue(1)); 1691 1692 oneOf(principalDao).getInternalIDFromURI(annotation.getOwnerRef()); 1693 will(returnValue(1)); 1694 1695 oneOf(annotationDao).updateAnnotation(annotation, 1, 1); 1696 will(returnValue(1)); 1697 1698 oneOf(annotationDao).deleteAllAnnotationTarget(1); 1699 will(returnValue(1)); 1700 1701 oneOf(annotationDao).deleteAnnotationPermissions(1); 1702 will(returnValue(3)); 1703 1704 1705 /// adding the first target, nt foind in the DB 1706 1707 oneOf(targetDao).getInternalIDFromURI(annotation.getTargets().getTargetInfo().get(0).getRef()); 1708 will(throwException(e)); 1709 1710 oneOf(targetDao).addTarget(with(aNonNull(Target.class))); 1711 will(returnValue(8)); 1712 1713 oneOf(targetDao).stringURItoExternalID(annotation.getTargets().getTargetInfo().get(0).getRef()); 1714 will(returnValue(mockTempID)); 1715 1716 oneOf(targetDao).getExternalID(8); 1717 will(returnValue(mockNewID)); 1718 1719 oneOf(annotationDao).addAnnotationTarget(1, 8); 1720 will(returnValue(1)); 1721 1722 ///////// 1723 oneOf(targetDao).getInternalIDFromURI(annotation.getTargets().getTargetInfo().get(1).getRef()); 1724 will(returnValue(2)); 1725 1726 oneOf(annotationDao).addAnnotationTarget(1, 2); 1727 will(returnValue(1)); 1728 1729 ///// 1730 oneOf(principalDao).getInternalIDFromURI(permissions.getPermission().get(0).getPrincipalRef()); 1731 will(returnValue(2)); 1732 1733 oneOf(annotationDao).addAnnotationPrincipalAccess(1, 2, Access.WRITE); 1734 will(returnValue(1)); 1735 1736 oneOf(principalDao).getInternalIDFromURI(permissions.getPermission().get(1).getPrincipalRef()); 1737 will(returnValue(3)); 1738 1739 oneOf(annotationDao).addAnnotationPrincipalAccess(1, 3, Access.READ); 1740 will(returnValue(1)); 1741 1742 1743 //// 1744 1745 oneOf(annotationDao).updateAnnotationBody(1, annotation.getBody().getTextBody().getBody(), "text/html", false); 1746 will(returnValue(1)); 1747 1748 /// 1749 1750 oneOf(annotationDao).updatePublicAttribute(1, permissions.getPublic()); 1751 will(returnValue(1)); 1752 1753 1754 } 1755 }); 1756 assertEquals(1, dbIntegrityService.updateAnnotation(annotation)); 1757 } 1758 1759 // public int updateAnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) { 1760 // int result; 1761 // Access currentAccess = annotationDao.getAccess(annotationID, principalID); 1762 // if (currentAccess != Access.NONE) { 1763 // result = annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); 1764 // } else { 1765 // if (!access.equals(Access.NONE)) { 1766 // result = annotationDao.deleteAnnotationPrincipalAccess(annotationID, principalID); 1767 // result = annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); 1768 // } else { 1769 // result = 0; 1770 // } 1771 // } 1772 // return result; 1773 // } 1774 @Test 1775 public void testUpdateAnnotationPrinciaplAccess() { 1776 System.out.println("test updateAnnotationPrincipalAccess"); 1777 mockeryDao.checking(new Expectations() { 1778 { 1779 oneOf(annotationDao).getAccess(1, 2); 1780 will(returnValue(Access.WRITE)); 1781 1782 oneOf(annotationDao).updateAnnotationPrincipalAccess(1, 2, Access.READ); 1783 will(returnValue(1)); 1784 1785 oneOf(annotationDao).getAccess(1, 4); 1786 will(returnValue(Access.NONE)); 1787 1788 oneOf(annotationDao).deleteAnnotationPrincipalAccess(1, 4); 1789 will(returnValue(0)); 1790 1791 oneOf(annotationDao).addAnnotationPrincipalAccess(1, 4, Access.WRITE); 1792 will(returnValue(1)); 1793 1794 } 1795 }); 1796 1797 assertEquals(1, dbIntegrityService.updateAnnotationPrincipalAccess(1, 2, Access.READ)); 1798 assertEquals(1, dbIntegrityService.updateAnnotationPrincipalAccess(1, 4, Access.WRITE)); 1799 } 1800 1801 @Test 1802 public void testUpdatePermissions() throws NotInDataBaseException { 1803 System.out.println("test updatePermissions"); 1804 1805 final Annotation annotation = (new TestInstances(TestBackendConstants._TEST_SERVLET_URI)).getAnnotationOne(); 1806 final PermissionList permissions = annotation.getPermissions(); 1807 1808 1809 mockeryDao.checking(new Expectations() { 1810 { 1811 ///// 1812 oneOf(annotationDao).updatePublicAttribute(1, permissions.getPublic()); 1813 will(returnValue(1)); 1814 1815 oneOf(principalDao).getInternalIDFromURI(permissions.getPermission().get(0).getPrincipalRef()); 1816 will(returnValue(2)); 1817 1818 oneOf(annotationDao).getAccess(1, 2); 1819 will(returnValue(Access.WRITE)); 1820 1821 oneOf(principalDao).getInternalIDFromURI(permissions.getPermission().get(1).getPrincipalRef()); 1822 will(returnValue(3)); 1823 1824 oneOf(annotationDao).getAccess(1, 3); 1825 will(returnValue(Access.WRITE)); 1826 1827 oneOf(annotationDao).updateAnnotationPrincipalAccess(1, 3, Access.READ); 1828 will(returnValue(1)); 1829 1830 } 1831 }); 1832 1833 assertEquals(1, dbIntegrityService.updatePermissions(1, permissions)); 1834 1835 } 1836 1837 @Test 1838 public void testUpdatePermissions2() throws NotInDataBaseException { 1839 System.out.println("test updatePermissions 2"); 1840 1841 final PermissionList permissions = new PermissionList(); 1842 permissions.setPublic(Access.READ); 1843 Permission permission = new Permission(); 1844 permissions.getPermission().add(permission); 1845 permission.setLevel(Access.WRITE); 1846 permission.setPrincipalRef(TestBackendConstants._TEST_SERVLET_URI_principals + "00000000-0000-0000-0000-000000000220"); 1847 1848 mockeryDao.checking(new Expectations() { 1849 { 1850 ///// 1851 oneOf(annotationDao).updatePublicAttribute(1, permissions.getPublic()); 1852 will(returnValue(1)); 1853 1854 oneOf(principalDao).getInternalIDFromURI(permissions.getPermission().get(0).getPrincipalRef()); 1855 will(returnValue(10)); 1856 1857 oneOf(annotationDao).getAccess(1, 10); 1858 will(returnValue(Access.NONE)); 1859 1860 oneOf(annotationDao).deleteAnnotationPrincipalAccess(1, 10); 1861 will(returnValue(0)); 1862 1863 oneOf(annotationDao).addAnnotationPrincipalAccess(1, 10, permissions.getPermission().get(0).getLevel()); 1864 will(returnValue(1)); 1865 1866 } 1867 }); 1868 1869 assertEquals(1, dbIntegrityService.updatePermissions(1, permissions)); 1870 1871 } 1872 1873 @Test 1874 public void testUpdatePublicAttribute(){ 1875 System.out.println("test updatePublicAttribute"); 1876 1877 1878 mockeryDao.checking(new Expectations() { 1879 { 1880 ///// 1881 oneOf(annotationDao).updatePublicAttribute(1, Access.NONE); 1882 will(returnValue(1)); 1883 1884 1885 } 1886 }); 1887 1888 assertEquals(1, dbIntegrityService.updatePublicAttribute(1, Access.NONE)); 1889 1890 } 1424 1891 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r4865 r4885 38 38 import javax.xml.parsers.ParserConfigurationException; 39 39 import static org.junit.Assert.*; 40 import org.junit.Ignore; 40 41 import org.junit.Test; 41 42 import org.junit.runner.RunWith; … … 430 431 431 432 @Test 432 public void testUpdateAnnotationBody() {433 public void testUpdateAnnotationBody() { 433 434 System.out.println("test updateAnnotationbody "); 434 435 int result = jdbcAnnotationDao.updateAnnotationBody(1, "some html 1 updated", "text/plain", false); … … 447 448 assertEquals("application/xml", check2.getBody().getXmlBody().getMimeType()); 448 449 } 449 450 @Test 451 public void testUpdateAnnotation(){ 452 System.out.println("test updateAnntation "); 453 454 Annotation annotation = new TestInstances("http://localhost:8080/annotator-backend/").getAnnotationOne(); 455 annotation.setHeadline("updated headline 1"); 456 annotation.getBody().getTextBody().setBody("updated some html 1"); 457 annotation.getBody().getTextBody().setMimeType("text/plain"); 458 459 int result = jdbcAnnotationDao.updateAnnotation(annotation,1, 1); 460 assertEquals(1, result); 461 Annotation check = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); 462 assertEquals("updated some html 1", check.getBody().getTextBody().getBody()); 463 assertEquals("text/plain", check.getBody().getTextBody().getMimeType()); 464 assertEquals("updated headline 1", check.getHeadline()); 465 466 } 467 468 @Test 469 public void testUpdateAnnotationPrincipalAccess(){ 450 451 @Test 452 public void testUpdateAnnotationPrincipalAccess() { 470 453 System.out.println("test updateAnntationPrincipalAccess "); 471 454 472 455 int result = jdbcAnnotationDao.updateAnnotationPrincipalAccess(1, 2, Access.NONE); 473 456 assertEquals(1, result); 474 457 assertEquals(Access.NONE, jdbcAnnotationDao.getAccess(1, 2)); 475 458 } 476 477 @Test 478 public void testUpdatPublicAttribute() {459 460 @Test 461 public void testUpdatPublicAttribute() { 479 462 System.out.println("test updatePublicAtribute "); 480 463 481 464 int result = jdbcAnnotationDao.updatePublicAttribute(1, Access.NONE); 482 465 assertEquals(1, result); 483 466 assertEquals(Access.NONE, jdbcAnnotationDao.getPublicAttribute(1)); 484 467 } 485 486 @Test 487 public void testRetrieveBodyComponents() throws ParserConfigurationException, IOException, SAXException {488 System.out.println("test retrieveBodyComponents ");489 490 AnnotationBody ab = new TestInstances("http://localhost:8080/annotator-backend/").getAnnotationOne().getBody();491 468 469 @Test 470 public void testRetrieveBodyComponents() throws ParserConfigurationException, IOException, SAXException { 471 System.out.println("test retrieveBodyComponents 1"); 472 473 AnnotationBody ab = testInstances.getAnnotationOne().getBody(); 474 492 475 String[] result = jdbcAnnotationDao.retrieveBodyComponents(ab); 493 476 assertEquals(2, result.length); 494 477 assertEquals("<html><body>some html 1</body></html>", result[0]); 495 478 assertEquals("text/html", result[1]); 496 479 480 497 481 String testXml = "<xhtml:span style=\"background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);\">test</xhtml:span>"; 498 482 AnnotationBody ab2 = new AnnotationBody(); 499 483 XmlBody xb = new XmlBody(); 500 Element el = Helpers.stringToElement(testXml);484 Element el = Helpers.stringToElement(testXml); 501 485 String str = Helpers.elementToString(el); 502 486 xb.setAny(el); 503 487 xb.setMimeType("application/xml"); 504 488 ab2.setXmlBody(xb); 489 System.out.println("test retrieveBodyComponents 2"); 505 490 String[] result2 = jdbcAnnotationDao.retrieveBodyComponents(ab2); 506 491 assertEquals(2, result2.length); … … 508 493 assertEquals("application/xml", result2[1]); 509 494 } 495 496 @Test 497 @Ignore 498 public void testUpdateAnnotation() { 499 System.out.println("KOUKOUK!!!!"); 500 501 Annotation annotation = testInstances.getAnnotationOne(); 502 annotation.setHeadline("updated headline 1"); 503 annotation.getBody().getTextBody().setBody("updated some html 1"); 504 annotation.getBody().getTextBody().setMimeType("text/plain"); 505 506 System.out.println(annotation.getURI()); 507 int result = jdbcAnnotationDao.updateAnnotation(annotation,1, 1); 508 assertEquals(1, result); 509 // Annotation check = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); 510 // assertEquals("updated some html 1", check.getBody().getTextBody().getBody()); 511 // assertEquals("text/plain", check.getBody().getTextBody().getMimeType()); 512 // assertEquals("updated headline 1", check.getHeadline()); 513 514 } 510 515 }
Note: See TracChangeset
for help on using the changeset viewer.