Changeset 3137
- Timestamp:
- 07/15/13 13:14:37 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/AnnotationIdentifier.java
r3096 r3137 18 18 package eu.dasish.annotation.backend.identifiers; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 20 21 import java.util.UUID; 21 22 … … 25 26 * @author Peter Withers <peter.withers@mpi.nl> 26 27 */ 27 public class AnnotationIdentifier {28 public class AnnotationIdentifier extends DasishIdentifier { 28 29 29 final private String identifier; 30 31 public AnnotationIdentifier(UUID identifier) { 32 super(identifier); 33 setHashParametersAnnotationId(); 34 } 30 35 31 36 public AnnotationIdentifier(String identifier) { 32 this.identifier = identifier; 37 super(identifier); 38 setHashParametersAnnotationId(); 33 39 } 34 40 35 41 public AnnotationIdentifier() { 36 this.identifier = "aid-" + UUID.randomUUID(); 42 super(); 43 setHashParametersAnnotationId(); 37 44 } 38 39 @Override 40 public String toString() { 41 return identifier; 42 } 43 44 @Override 45 public int hashCode() { 46 int hash = 5; 47 hash = 23 * hash + (this.identifier != null ? this.identifier.hashCode() : 0); 48 return hash; 49 } 50 51 @Override 52 public boolean equals(Object obj) { 53 if (obj == null) { 54 return false; 55 } 56 if (getClass() != obj.getClass()) { 57 return false; 58 } 59 final AnnotationIdentifier other = (AnnotationIdentifier) obj; 60 if ((this.identifier == null) ? (other.identifier != null) : !this.identifier.equals(other.identifier)) { 61 return false; 62 } 63 return true; 64 } 45 46 private void setHashParametersAnnotationId(){ 47 setHashParameters(BackendConstants.ANNOTATION_HASH_PARAM_1, BackendConstants.ANNOTATION_HASH_PARAM_2); 48 } 49 65 50 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/NotebookIdentifier.java
r3110 r3137 18 18 package eu.dasish.annotation.backend.identifiers; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 20 21 import java.util.UUID; 21 22 … … 25 26 * @author Peter Withers <peter.withers@mpi.nl> 26 27 */ 27 public class NotebookIdentifier {28 public class NotebookIdentifier extends DasishIdentifier{ 28 29 29 final private UUID identifier; 30 31 public NotebookIdentifier(String identifier) { 32 this.identifier = UUID.fromString(identifier); 30 public NotebookIdentifier(String identifier) { 31 super(identifier); 32 setHashParametersNotebookId(); 33 } 34 35 36 public NotebookIdentifier(UUID identifier) { 37 super(identifier); 38 setHashParametersNotebookId(); 33 39 } 34 40 35 public NotebookIdentifier(UUID identifier) { 36 this.identifier = identifier; 37 } 41 42 public NotebookIdentifier() { 43 super(); 44 setHashParametersNotebookId(); 45 } 46 47 private void setHashParametersNotebookId(){ 48 setHashParameters(BackendConstants.NOTEBOOK_HASH_PARAM_1, BackendConstants.NOTEBOOK_HASH_PARAM_2); 49 } 38 50 39 public NotebookIdentifier() { 40 this.identifier = UUID.randomUUID(); 41 } 42 43 public UUID getUUID() { 44 return identifier; 45 } 46 47 @Override 48 public int hashCode() { 49 int hash = 7; 50 hash = 29 * hash + (this.identifier != null ? this.identifier.hashCode() : 0); 51 return hash; 52 } 53 54 @Override 55 public boolean equals(Object obj) { 56 if (obj == null) { 57 return false; 58 } 59 if (getClass() != obj.getClass()) { 60 return false; 61 } 62 final NotebookIdentifier other = (NotebookIdentifier) obj; 63 if ((this.identifier == null) ? (other.identifier != null) : !this.identifier.equals(other.identifier)) { 64 return false; 65 } 66 return true; 67 } 51 68 52 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/UserIdentifier.java
r3095 r3137 18 18 package eu.dasish.annotation.backend.identifiers; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 21 import java.util.UUID; 22 20 23 /** 21 24 * Created on : Jun 28, 2013, 2:06:32 PM … … 23 26 * @author Peter Withers <peter.withers@mpi.nl> 24 27 */ 25 public class UserIdentifier { 28 public class UserIdentifier extends DasishIdentifier { 29 30 public UserIdentifier(String identifier) { 31 super(identifier); 32 setHashParametersUserId(); 33 } 34 35 /* public UserIdentifier(UUID identifier) { 36 super(identifier); 37 setHashParametersUserId(); 38 } */ 26 39 27 final private String identifier; 28 29 public UserIdentifier(String identifier) { 30 this.identifier = identifier; 40 public UserIdentifier() { 41 super(); 42 setHashParametersUserId(); 31 43 } 32 33 @Override 34 public String toString() { 35 return identifier; 36 } 37 38 @Override 39 public int hashCode() { 40 int hash = 5; 41 hash = 19 * hash + (this.identifier != null ? this.identifier.hashCode() : 0); 42 return hash; 43 } 44 45 @Override 46 public boolean equals(Object obj) { 47 if (obj == null) { 48 return false; 49 } 50 if (getClass() != obj.getClass()) { 51 return false; 52 } 53 final UserIdentifier other = (UserIdentifier) obj; 54 if ((this.identifier == null) ? (other.identifier != null) : !this.identifier.equals(other.identifier)) { 55 return false; 56 } 57 return true; 58 } 44 45 private void setHashParametersUserId(){ 46 setHashParameters(BackendConstants.USER_HASH_PARAM_1, BackendConstants.USER_HASH_PARAM_2); 47 } 48 49 59 50 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3105 r3137 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.TestBackendConstants; 20 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; … … 111 112 @Test 112 113 public void testGetNotebookInfos() { 113 final List<NotebookInfo> notebookInfoList = jdbcNotebookDao.getNotebookInfos(new UserIdentifier( "_test_uid_2_"));114 final List<NotebookInfo> notebookInfoList = jdbcNotebookDao.getNotebookInfos(new UserIdentifier(TestBackendConstants._TEST_UID_2_)); 114 115 assertEquals(2, notebookInfoList.size()); 115 116 assertEquals("a notebook", notebookInfoList.get(0).getTitle()); … … 132 133 } 133 134 }); 134 final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier( "_test_uid_2_"));135 final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_2_)); 135 136 136 137 … … 148 149 } 149 150 }); 150 final List<Notebook> notebooksEmpty = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier( "_test_uid_1_"));151 final List<Notebook> notebooksEmpty = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_1_)); 151 152 assertEquals(0, notebooksEmpty.size()); 152 153 } … … 157 158 @Test 158 159 public void testAddNotebook() throws URISyntaxException { 159 final NotebookIdentifier addedNotebookId = jdbcNotebookDao.addNotebook(new UserIdentifier( "_test_uid_2_"), "a title");160 final NotebookIdentifier addedNotebookId = jdbcNotebookDao.addNotebook(new UserIdentifier(TestBackendConstants._TEST_UID_2_), "a title"); 160 161 assertEquals(36, addedNotebookId.getUUID().toString().length()); 161 162 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3111 r3137 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.TestBackendConstants; 20 21 import eu.dasish.annotation.backend.dao.NotebookDao; 21 22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; … … 63 64 System.out.println("getNotebookInfo"); 64 65 final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 65 httpServletRequest.setRemoteUser("_test_uid_1_"); 66 httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_1_); 67 66 68 mockery.checking(new Expectations() { 67 69 { 68 oneOf(notebookDao).getNotebookInfos(new UserIdentifier(httpServletRequest.getRemoteUser())); 70 oneOf(notebookDao).getNotebookInfos(new UserIdentifier(httpServletRequest.getRemoteUser())); 69 71 will(returnValue(new ArrayList<NotebookInfo>())); 70 72 } … … 82 84 mockery.checking(new Expectations() { 83 85 { 84 oneOf(notebookDao).getUsersNotebooks(new UserIdentifier( "_test_uid_2_"));86 oneOf(notebookDao).getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_2_)); 85 87 will(returnValue(new ArrayList<Notebook>())); 86 88 } 87 89 }); 88 90 final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 89 httpServletRequest.setRemoteUser( "_test_uid_2_");91 httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_); 90 92 List result = notebookResource.getUsersNotebooks(httpServletRequest); 91 93 assertEquals(0, result.size()); … … 99 101 System.out.println("createNotebook"); 100 102 final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 101 httpServletRequest.setRemoteUser( "_test_uid_2_");103 httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_); 102 104 mockery.checking(new Expectations() { 103 105 { … … 107 109 }); 108 110 String expResult = "/api/notebooks/00000000-0000-0000-0000-000000000001"; 109 String result = notebookResource.createNotebook(httpServletRequest); 111 String result = notebookResource.createNotebook(httpServletRequest); 110 112 assertEquals(expResult, result.substring(result.length() - expResult.length())); 111 113 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3105 r3137 17 17 -- 18 18 19 INSERT INTO principal (principal_name, external_id) VALUES ('a user', ' _test_uid_1_');20 INSERT INTO principal (principal_name, external_id) VALUES ('b user', ' _test_uid_2_');19 INSERT INTO principal (principal_name, external_id) VALUES ('a user', '00000000-0000-0000-0000-000000000003'); 20 INSERT INTO principal (principal_name, external_id) VALUES ('b user', '00000000-0000-0000-0000-000000000004'); 21 21 22 22 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, '00000000-0000-0000-0000-000000000001'); 23 23 -- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1); 24 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (1, 'a headline','<html><body>some html</body></html>', ' _test_aid_1_');24 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (1, 'a headline','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000005'); 25 25 26 26 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 1, '00000000-0000-0000-0000-000000000002');
Note: See TracChangeset
for help on using the changeset viewer.