Changeset 3137


Ignore:
Timestamp:
07/15/13 13:14:37 (11 years ago)
Author:
olhsha
Message:

refactored identifiers: user, annotation, notebook

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  
    1818package eu.dasish.annotation.backend.identifiers;
    1919
     20import eu.dasish.annotation.backend.BackendConstants;
    2021import java.util.UUID;
    2122
     
    2526 * @author Peter Withers <peter.withers@mpi.nl>
    2627 */
    27 public class AnnotationIdentifier {
     28public class AnnotationIdentifier extends DasishIdentifier {   
    2829
    29     final private String identifier;
     30   
     31  public AnnotationIdentifier(UUID identifier) {
     32        super(identifier);
     33        setHashParametersAnnotationId();
     34    }
    3035
    3136    public AnnotationIdentifier(String identifier) {
    32         this.identifier = identifier;
     37        super(identifier);
     38        setHashParametersAnnotationId();
    3339    }
    34 
     40 
    3541    public AnnotationIdentifier() {
    36         this.identifier = "aid-" + UUID.randomUUID();
     42        super();
     43        setHashParametersAnnotationId();
    3744    }
    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   
    6550}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/NotebookIdentifier.java

    r3110 r3137  
    1818package eu.dasish.annotation.backend.identifiers;
    1919
     20import eu.dasish.annotation.backend.BackendConstants;
    2021import java.util.UUID;
    2122
     
    2526 * @author Peter Withers <peter.withers@mpi.nl>
    2627 */
    27 public class NotebookIdentifier {
     28public class NotebookIdentifier extends DasishIdentifier{
    2829
    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();
    3339    }
    3440
    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    } 
    3850
    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 
    6852}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/identifiers/UserIdentifier.java

    r3095 r3137  
    1818package eu.dasish.annotation.backend.identifiers;
    1919
     20import eu.dasish.annotation.backend.BackendConstants;
     21import java.util.UUID;
     22
    2023/**
    2124 * Created on : Jun 28, 2013, 2:06:32 PM
     
    2326 * @author Peter Withers <peter.withers@mpi.nl>
    2427 */
    25 public class UserIdentifier {
     28public 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    } */
    2639
    27     final private String identifier;
    28 
    29     public UserIdentifier(String identifier) {
    30         this.identifier = identifier;
     40    public UserIdentifier() {
     41        super();
     42        setHashParametersUserId();
    3143    }
    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   
    5950}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3105 r3137  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.TestBackendConstants;
    2021import eu.dasish.annotation.backend.dao.AnnotationDao;
    2122import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
     
    111112    @Test
    112113    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_));
    114115        assertEquals(2, notebookInfoList.size());
    115116        assertEquals("a notebook", notebookInfoList.get(0).getTitle());
     
    132133            }
    133134        });
    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_));
    135136
    136137
     
    148149            }
    149150        });
    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_));
    151152        assertEquals(0, notebooksEmpty.size());
    152153    }
     
    157158    @Test
    158159    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");
    160161        assertEquals(36, addedNotebookId.getUUID().toString().length());
    161162    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3111 r3137  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.TestBackendConstants;
    2021import eu.dasish.annotation.backend.dao.NotebookDao;
    2122import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
     
    6364        System.out.println("getNotebookInfo");
    6465        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    65         httpServletRequest.setRemoteUser("_test_uid_1_");
     66        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_1_);
     67       
    6668        mockery.checking(new Expectations() {
    6769            {
    68                 oneOf(notebookDao).getNotebookInfos(new UserIdentifier(httpServletRequest.getRemoteUser()));
     70                oneOf(notebookDao).getNotebookInfos(new UserIdentifier(httpServletRequest.getRemoteUser()));               
    6971                will(returnValue(new ArrayList<NotebookInfo>()));
    7072            }
     
    8284        mockery.checking(new Expectations() {
    8385            {
    84                 oneOf(notebookDao).getUsersNotebooks(new UserIdentifier("_test_uid_2_"));
     86                oneOf(notebookDao).getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_2_));
    8587                will(returnValue(new ArrayList<Notebook>()));
    8688            }
    8789        });
    8890        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    89         httpServletRequest.setRemoteUser("_test_uid_2_");
     91        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);
    9092        List result = notebookResource.getUsersNotebooks(httpServletRequest);
    9193        assertEquals(0, result.size());
     
    99101        System.out.println("createNotebook");
    100102        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    101         httpServletRequest.setRemoteUser("_test_uid_2_");
     103        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);
    102104        mockery.checking(new Expectations() {
    103105            {
     
    107109        });
    108110        String expResult = "/api/notebooks/00000000-0000-0000-0000-000000000001";
    109         String result = notebookResource.createNotebook(httpServletRequest);
     111        String result = notebookResource.createNotebook(httpServletRequest); 
    110112        assertEquals(expResult, result.substring(result.length() - expResult.length()));
    111113    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3105 r3137  
    1717--
    1818
    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_');
     19INSERT INTO principal (principal_name, external_id) VALUES ('a user', '00000000-0000-0000-0000-000000000003');
     20INSERT INTO principal (principal_name, external_id) VALUES ('b user', '00000000-0000-0000-0000-000000000004');
    2121
    2222INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, '00000000-0000-0000-0000-000000000001');
    2323-- 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_');
     24INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (1, 'a headline','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000005');
    2525
    2626INSERT 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.