Changeset 3206


Ignore:
Timestamp:
07/30/13 09:08:46 (11 years ago)
Author:
olhsha
Message:

getting user for AnnotationResource? not as a parameter for the REST-method bi via injection from the context, using an annotation @Context HttpServletRequest? httpServletRequest

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3189 r3206  
    7474     * @return annotationIdentifier of the newly added annotation; returns null if something went wrong and annotation was not added or more than one row in the annotation table was affected
    7575     */
    76     public AnnotationIdentifier addAnnotation(Annotation annotation);
     76    public Annotation addAnnotation(Annotation annotation, Number ownerID);
    7777 
    7878    /**
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3189 r3206  
    227227    }
    228228     
    229      
    230    //////////////////////////////////////////////
    231    /* CREATE TABLE annotation (
    232     annotation_id SERIAL UNIQUE NOT NULL,
    233     external_id UUID UNIQUE NOT NULL,
    234     time_stamp timestamp with time zone default now(),
    235     owner_id integer,
    236     headline text,
    237     body_xml xml */
    238 
    239    
     229 
     230   
     231   // TODO: so far URI in the xml is the same as the external_id in the DB!!
     232   // Chnage it when the decision is taken!!!
    240233    @Override
    241     public AnnotationIdentifier addAnnotation(Annotation annotation) {
     234    public Annotation addAnnotation(Annotation annotation, Number ownerID) {
     235       
     236        if (annotation == null) {
     237            return null;
     238        }
     239       
    242240        try {
     241            Annotation result = makeFreshCopy(annotation);
     242           
     243            ResourceREF ownerRef = new ResourceREF();
     244            ownerRef.setRef(String.valueOf(ownerID));
     245            result.setOwner(ownerRef);
     246           
    243247            AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier();
     248            result.setURI(annotationIdentifier.toString());
     249           
    244250            Map<String, Object> params = new HashMap<String, Object>();
    245251            params.put("externalId", annotationIdentifier.toString());
    246             params.put("timeStamp", annotation.getTimeStamp());
    247             params.put("ownerId", annotation.getOwner().getRef());
     252            params.put("timeStamp", annotation.getTimeStamp());           
     253            params.put("ownerId", ownerID);
    248254            params.put("headline", annotation.getHeadline());
    249255            // may be changed once we elaborate the body
     
    252258            final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    253259            if (affectedRows == 1) {
    254                 return annotationIdentifier;
     260                return result;
    255261            }
    256262            else {
     
    327333    }
    328334   
     335    //TODO: update when target sources and permissions are added
     336    private  Annotation makeFreshCopy(Annotation annotation){
     337       
     338        if (annotation == null) {
     339            return null;
     340        }
     341       
     342        Annotation result = new Annotation();
     343        result.setBody(annotation.getBody());
     344        result.setHeadline(annotation.getHeadline());
     345        result.setOwner(annotation.getOwner());
     346        result.setPermissions(annotation.getPermissions());
     347        result.setTargetSources(annotation.getTargetSources());
     348        result.setTimeStamp(annotation.getTimeStamp());
     349        result.setURI(annotation.getURI());
     350       
     351        return result;
     352    }
    329353   
    330354}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r3205 r3206  
    2020import eu.dasish.annotation.backend.dao.UserDao;
    2121import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    22 import eu.dasish.annotation.schema.Annotation;
    2322import java.sql.ResultSet;
    2423import java.sql.SQLException;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3192 r3206  
    2020import eu.dasish.annotation.backend.BackendConstants;
    2121import eu.dasish.annotation.backend.dao.AnnotationDao;
     22import eu.dasish.annotation.backend.dao.UserDao;
    2223import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     24import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2325import eu.dasish.annotation.schema.Annotation;
    2426import eu.dasish.annotation.schema.ObjectFactory;
    2527import java.sql.SQLException;
     28import javax.servlet.ServletContext;
     29import javax.servlet.http.HttpServletRequest;
    2630import javax.ws.rs.Consumes;
    2731import javax.ws.rs.DELETE;
     
    3135import javax.ws.rs.PathParam;
    3236import javax.ws.rs.Produces;
     37import javax.ws.rs.core.Context;
    3338import javax.ws.rs.core.MediaType;
    3439import javax.xml.bind.JAXBElement;
     
    4651    @Autowired
    4752    private AnnotationDao annotationDao;
    48    
     53    @Autowired
     54    private UserDao userDao;
     55   
     56    //for Peter, see also http://stackoverflow.com/questions/6140697/jersey-the-context-annotation-for-injection-how-does-it-work
     57    @Context
     58    private HttpServletRequest httpServletRequest;
     59   
     60    @Context
     61    private ServletContext servletContext;
     62   
     63   
     64    public void setHttpRequest(HttpServletRequest request){
     65       this.httpServletRequest =  request;
     66    }
     67   
     68    public AnnotationResource(){
     69    }
     70   
     71    /*public AnnotationResource(@Context HttpServletRequest request){
     72        this.httpServletRequest =  request;
     73    }*/
     74           
     75           
    4976    @GET
    5077    @Produces(MediaType.TEXT_XML)
     
    6592   
    6693    // TODO: should be returning the envelope!!!
    67     @POST
     94    @POST   
    6895    @Consumes(MediaType.APPLICATION_XML)
    6996    @Produces(MediaType.APPLICATION_XML)
    7097    @Path("")
    7198    public JAXBElement<Annotation> createAnnotation(Annotation annotation) {
    72         AnnotationIdentifier newAnnotationIdentifier = annotationDao.addAnnotation(annotation);
    73         //return newAnnotationIdentifier.toString();
    74         if (newAnnotationIdentifier == null) {
     99       
     100        String remoteUser = httpServletRequest.getRemoteUser();
     101        Number userID;
     102       
     103        if (remoteUser == null) {
     104            // happens in client testing
     105            userID = null;
     106        }
     107        else {
     108           userID= userDao.getInternalID(new UserIdentifier(remoteUser));
     109        }
     110       
     111        Annotation newAnnotation = annotationDao.addAnnotation(annotation, userID);
     112        if (newAnnotation == null) {
    75113            return null;
    76114        } else {
    77             return (new ObjectFactory().createAnnotation(annotation));
     115            return (new ObjectFactory().createAnnotation(newAnnotation));
    78116        }
    79117    }
     118   
    80119   
    81  
     120   
    82121}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/sql/DashishAnnotatorCreate.sql

    r3100 r3206  
    3636SET default_with_oids = false;
    3737
     38
     39---------- BASE TABLES ----------------------------------------------
     40
     41--<xs:complexType name="User">
     42--        <xs:sequence>
     43--            <xs:element name="additionalInfo">
     44--                <xs:complexType>
     45--                    <xs:sequence>
     46--                        <xs:any processContents="lax" maxOccurs="unbounded"/>
     47--                    </xs:sequence>
     48--                    <xs:anyAttribute processContents="lax"/>
     49--                </xs:complexType>
     50--            </xs:element>
     51--       </xs:sequence>
     52--        <xs:attribute name="URI" type="xs:anyURI" use="required"/>
     53--        <xs:attribute name="displayName" type="xs:string" use="required"/>
     54--        <xs:attribute name="eMail" type="xs:string" use="required"/>
     55--   </xs:complexType>
     56
     57
     58CREATE TABLE principal (
     59    principal_id SERIAL UNIQUE NOT NULL,
     60    external_id UUID UNIQUE NOT NULL,
     61    principal_name text,
     62    e_mail text,
     63    additional_info text
     64);
     65
     66
     67------------------------------------------------------------------------
     68-- <xs:complexType name="Annotation">
     69--        <xs:sequence>
     70--            <xs:element name="owner" type="ResourceREF" minOccurs="1"/>
     71--            <xs:element name="headline" type="xs:string" minOccurs="1"/>
     72--            <!-- schematron checks the length <== 100 -->
     73--            <xs:element name="body" type="AnnotationBody" minOccurs="1"/>
     74--            <xs:element name="targetSources" type="NewOrExistingSourceInfos" minOccurs="1"/>
     75--            <xs:element name="permissions" type="ResourceREF"/>
     76--        </xs:sequence>
     77--        <xs:attribute name="URI" type="xs:anyURI" use="required"/>
     78--        <xs:attribute name="timeStamp" type="xs:dateTime" use="required"/>
     79--    </xs:complexType>
     80
     81
    3882CREATE TABLE annotation (
    39     annotation_id SERIAL UNIQUE NOT NULL,
     83    annotation_id SERIAL UNIQUE NOT NULL, 
    4084    external_id UUID UNIQUE NOT NULL,
    4185    time_stamp timestamp with time zone default now(),
    42     owner_id integer,
     86    owner_id integer REFERENCES principal(principal_id),
     87    --  there must be exactly one owner ++
     88     -- and this owner must be in the table "permissions" as owner!!
    4389    headline text,
    4490    body_xml xml
    4591);
     92
     93-----------------------------------------------------------------------
     94-- <xs:complexType name="CachedRepresentationInfo">
     95--        <xs:attribute name="ref" type="xs:anyURI" use="required"/>
     96--        <xs:attribute name="mimeType" type="xs:string" use="required"/>
     97--        <xs:attribute name="tool" type="xs:string" use="required"/>
     98--        <xs:attribute name="type" type="xs:string" use="required"/>
     99--    </xs:complexType>
     100
     101CREATE TABLE cached_representation_info (
     102    cached_representation_id SERIAL UNIQUE NOT NULL,
     103    external_id UUID UNIQUE NOT NULL,
     104    mime_type text,
     105    tool text,
     106    type_ text,
     107    where_is_the_file text -- DIFFERS FROM the schema
     108);
     109
     110-- soundness there must be at least one version referring to this cahced representation
     111
     112
     113----------------------------------------------------------------------
     114-- <xs:complexType name="Version">
     115--        <xs:sequence>
     116--            <xs:element name="version" type="xs:string"/>
     117--            <xs:element name="cachedRepresentations" type="CachedRepresentations"/>
     118--        </xs:sequence>
     119--    </xs:complexType>
     120
     121CREATE TABLE version (
     122    version_id SERIAL UNIQUE NOT NULL,
     123    external_id UUID UNIQUE NOT NULL,
     124    version text,
     125    --  SOUNDNESS: there must be at least one row with this version_id in the verions_cached_representations table
     126);
     127
     128----------------------------------------------------------------
     129
     130 -- <xs:complexType name="Source">
     131 --       <xs:sequence>
     132 --           <xs:element name="versions-siblings" type="ResourceREF" minOccurs="1"/>
     133 --       </xs:sequence>
     134 --       <xs:attribute name="URI" type="xs:anyURI" use="required"/>
     135 --       <xs:attribute name="timeSatmp" type="xs:dateTime" use="required"/>
     136 --       <xs:attribute name="link" type="xs:anyURI" use="required"/>
     137 --       <xs:attribute name="version" type="xs:string" use="required"/>
     138 --   </xs:complexType>
     139
     140CREATE TABLE target_source (
     141    source_id SERIAL UNIQUE NOT NULL,
     142    external_id UUID UNIQUE NOT NULL,
     143    time_stamp timestamp with time zone default now(),
     144    link_uri text,
     145    version_id integer REFERENCES version(version_id), ---- DIFFERS from the xml structure,
     146    -- SOUNDNESS: there must be exactly version at the version table  ++   
     147    -- soundness: there must be at least one annotation referring to this source
     148);
     149
     150
     151-----------------------------------------------------------------------------------
    46152
    47153CREATE TABLE notebook (
     
    51157    title text,
    52158    owner_id integer NOT NULL
    53 );
     159-- soundness:  there must be at least one target source in the annotations_target_sources table
     160);
     161
     162
     163
     164-----------------------------------------------------------------------
     165--------------------- JOINT TABLES ------------------------------------
     166
     167CREATE TABLE annotations_target_sources (
     168   annotation_id integer REFERENCES annotation(annotation_id), -- defining a foreign key: there must be a uniquely defined row in "annotation", that is defined by "annotation_id"
     169   source_id integer REFERENCES target_source(source_id),
     170   unique(annotation_id, source_id),
     171);
     172
     173
    54174
    55175CREATE TABLE notebooks_annotations (
    56176    notebook_id integer REFERENCES notebook(notebook_id),
    57     annotation_id integer REFERENCES annotation(annotation_id)
    58 );
    59 
    60 CREATE TABLE principal (
    61     principal_id SERIAL NOT NULL,
    62     external_id UUID UNIQUE NOT NULL,
    63     principal_name text
    64 );
    65 
     177    annotation_id integer REFERENCES annotation(annotation_id),
     178    unique(notebook_id, annotation_id),
     179);
     180
     181CREATE TABLE sources_versions (
     182    source_id integer REFERENCES target_source(source_id),
     183    version_id integer REFERENCES version(version_id),
     184    unique(source_id, version_id),
     185);
     186
     187CREATE TABLE versions_cached_representations (
     188    version_id integer REFERENCES version(version_id),
     189    cached_representation_id integer REFERENCES cached_representation_info(cached_representation_id),
     190    unique(version_id, cached_representation_id),
     191);
     192
     193
     194---------------------------------------------------------------------------------------------
    66195ALTER TABLE ONLY annotation
    67196    ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id);
     
    92221-- PostgreSQL database dump complete
    93222--
    94 
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3188 r3206  
    6363    public static final String _TEST_ANNOT_TO_ADD_HEADLINE = "Annotation to add to test DAO";
    6464   
    65     public static final int _TEST_ANNOT_1_OWNER = 111;
    66     public static final int _TEST_ANNOT_2_OWNER = 112;
    67     public static final int _TEST_ANNOT_3_OWNER = 113;
    68     public static final int _TEST_ANNOT_TO_ADD_OWNER = 117;
     65    public static final int _TEST_ANNOT_1_OWNER = 3;
     66    public static final int _TEST_ANNOT_2_OWNER = 4;
     67    public static final int _TEST_ANNOT_3_OWNER = 5;
     68    public static final int _TEST_ANNOT_TO_ADD_OWNER = 5;
    6969   
    7070    public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>";
     
    7373    public static final String annotaiontoDeleteInDB="INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');";
    7474   
     75    public static final String _TEST_OWNER_3_EXT_ID = "00000000-0000-0000-0000-000000000111";
     76    public static final String _TEST_OWNER_4_EXT_ID = "00000000-0000-0000-0000-000000000112"; 
     77    public static final String _TEST_OWNER_5_EXT_ID = "00000000-0000-0000-0000-000000000113"; 
     78   
    7579}
    7680
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3189 r3206  
    180180        System.out.println("test_addAnnotation");
    181181        Annotation annotationToAdd = testInstances.getAnnotationToAdd();
    182         AnnotationIdentifier result = jdbcAnnotationDao.addAnnotation(annotationToAdd);
     182        Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER);
    183183        assertFalse(result == null);
    184184       
    185         Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(result));       
     185        AnnotationIdentifier generatedAnnotationExternalID  = new AnnotationIdentifier(result.getURI());
     186       
     187        Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(generatedAnnotationExternalID));       
    186188        assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0));
    187189        assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline());
    188         assertEquals(annotationToAdd.getOwner().getRef(), addedAnnotation.getOwner().getRef());
     190        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER), addedAnnotation.getOwner().getRef());
     191        assertEquals(annotationToAdd.getPermissions(), addedAnnotation.getPermissions());
     192        assertEquals(annotationToAdd.getTargetSources(), addedAnnotation.getTargetSources());
     193        assertEquals(annotationToAdd.getTimeStamp(), addedAnnotation.getTimeStamp());
    189194       
    190195        // try to add an already existing annptation, should produce null
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3189 r3206  
    4949 */
    5050@RunWith(SpringJUnit4ClassRunner.class)
    51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
     51@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml",
    5252    "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    5353public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3192 r3206  
    2222import eu.dasish.annotation.backend.TestInstances;
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
     24import eu.dasish.annotation.backend.dao.UserDao;
    2425import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     26import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2527import eu.dasish.annotation.schema.Annotation;
    26 import eu.dasish.annotation.schema.ObjectFactory;
     28import eu.dasish.annotation.schema.ResourceREF;
    2729import java.sql.SQLException;
    2830import javax.xml.bind.JAXBElement;
     
    3638import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    3739import java.lang.InstantiationException;
     40import javax.servlet.ServletException;
     41import org.springframework.mock.web.MockHttpServletRequest;
     42import org.springframework.web.context.ContextLoaderListener;
     43import org.springframework.web.context.WebApplicationContext;
    3844/**
    3945 *
     
    4248
    4349@RunWith(value = SpringJUnit4ClassRunner.class)
    44 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     50@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    4551public class AnnotationResourceTest {
    4652   
     
    5056    private AnnotationDao annotationDao;
    5157    @Autowired
    52     private AnnotationResource annotationResource; 
     58    private UserDao userDao;
     59   
     60    @Autowired
     61    private AnnotationResource annotationResource;
    5362   
    5463    public AnnotationResourceTest() {
     
    119128     */
    120129    @Test
    121     public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException {
     130    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, ServletException {
    122131        System.out.println("test createAnnotation");
    123132        final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
    124         final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
    125133       
     134        final Annotation addedAnnotation = annotationToAdd;
     135        AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     136        addedAnnotation.setURI(annotationIdentifier.toString());
     137        ResourceREF ownerRef = new ResourceREF();
     138        ownerRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER));
     139        addedAnnotation.setOwner(ownerRef);
     140       
     141     
    126142        mockery.checking(new Expectations() {
    127143            {
    128                 oneOf(annotationDao).addAnnotation(annotationToAdd);
    129                 will(returnValue(newAnnotationID));
     144                oneOf(userDao).getInternalID(new UserIdentifier(TestBackendConstants._TEST_OWNER_5_EXT_ID));
     145                will(returnValue(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER));
     146               
     147                oneOf(annotationDao).addAnnotation(annotationToAdd, TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER);
     148                will(returnValue(addedAnnotation));
    130149            }
    131150        });
    132151       
    133152       
     153       
     154        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
     155        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_OWNER_5_EXT_ID);       
     156        annotationResource.setHttpRequest(httpServletRequest);
     157       
    134158        JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd);
    135         assertTrue(annotationToAdd.equals(result.getValue()));
     159        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER), result.getValue().getOwner().getRef());
     160        assertEquals(annotationIdentifier.toString(), result.getValue().getURI());
     161       
     162       
    136163    }
    137164}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3192 r3206  
    2222import eu.dasish.annotation.backend.TestBackendConstants;
    2323import eu.dasish.annotation.backend.dao.AnnotationDao;
     24import eu.dasish.annotation.backend.dao.UserDao;
    2425import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     26import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2527import eu.dasish.annotation.schema.Annotation;
    26 import eu.dasish.annotation.schema.Notebook;
    2728import eu.dasish.annotation.schema.ObjectFactory;
     29import eu.dasish.annotation.schema.ResourceREF;
    2830import java.sql.SQLException;
    29 import javax.ws.rs.core.GenericEntity;
     31import javax.servlet.http.HttpServletRequest;
    3032import javax.ws.rs.core.MediaType;
    3133import javax.xml.bind.JAXBElement;
     
    4143   
    4244    private AnnotationDao annotationDao;
     45    private UserDao userDao;
    4346   
    4447    public AnnotationsTest() {
    4548        super(AnnotationResource.class.getPackage().getName());
    4649        annotationDao = webAppContext.getBean(AnnotationDao.class);
     50        userDao = webAppContext.getBean(UserDao.class);
    4751    }
    4852   
     
    132136    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException{
    133137        System.out.println("test createAnnotation");
    134         //final Annotation annotationToAdd = new ObjectFactory().createAnnotation();
    135        final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
    136        final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     138        final Annotation annotationToAdd = new ObjectFactory().createAnnotation();
     139       
     140         // Peter's workaround on absence of "ObjectFactory.create... for annotations       
     141        final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd);
     142       
     143       
     144        final Annotation addedAnnotation = annotationToAdd;
     145        AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     146        addedAnnotation.setURI(annotationIdentifier.toString());
    137147       
    138148        mockery.checking(new Expectations() {
    139             {
    140                 oneOf(annotationDao).addAnnotation(with(aNonNull(Annotation.class)));
    141                 will(returnValue(newAnnotationID));
     149            {   
     150                oneOf(annotationDao).addAnnotation(with(any(Annotation.class)), with(any(Number.class)));
     151                will(returnValue(addedAnnotation));
    142152            }
    143153        });
     154       
     155     
    144156       
    145        
    146        
    147         final String requestUrl = "annotations/";
     157        final String requestUrl = "annotations";
    148158        System.out.println("requestUrl: " + requestUrl);
    149159       
    150         // Peter's workaround on absence of "PnjectFactory.create... for annotations
    151         final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd);
    152                
    153         ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);
     160        // Peter's workaround on absence of "ObjectFactory.create... for annotations
     161       
     162        ClientResponse response = resource().path(requestUrl).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);
    154163        assertEquals(200, response.getStatus());
    155164       
     
    160169        assertEquals(annotationToAdd.getTargetSources(), entity.getTargetSources());
    161170        assertEquals(annotationToAdd.getTimeStamp(), entity.getTimeStamp());
    162         assertEquals(annotationToAdd.getURI(), entity.getURI());
    163171    }
    164172}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3190 r3206  
    4747 */
    4848@RunWith(value = SpringJUnit4ClassRunner.class)
    49 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     49@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
    5050public class NotebookResourceTest {
    5151
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/ResourcesTest.java

    r3205 r3206  
    4949
    5050        // Get the context and mock objects from the context by their type
    51         mockery = webAppContext.getBean(Mockery.class); 
     51        mockery = webAppContext.getBean(Mockery.class);
    5252    }
    5353
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3168 r3206  
    1717--
    1818
    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');
     19INSERT INTO principal (principal_name, external_id) VALUES ('a user', '00000000-0000-0000-0000-000000000003'); -- 1
     20INSERT INTO principal (principal_name, external_id) VALUES ('b user', '00000000-0000-0000-0000-000000000004');-- 2
    2121
    22 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, '00000000-0000-0000-0000-000000000001');
     22INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 2, '00000000-0000-0000-0000-000000000001');
    2323-- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1);
    2424INSERT 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
    26 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 1, '00000000-0000-0000-0000-000000000002');
     26INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 2, '00000000-0000-0000-0000-000000000002');
    2727-- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 1, 2);
    2828INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (1,1);
     
    3232-- Test data for jdbcAnnotationDao --
    3333
    34 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 111, '00000000-0000-0000-0000-000000000011');
    35 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 112, '00000000-0000-0000-0000-000000000012');
    36 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 113, '00000000-0000-0000-0000-000000000013');
     34INSERT INTO principal (principal_name, external_id) VALUES ('Twan', '00000000-0000-0000-0000-000000000111'); --3
     35INSERT INTO principal (principal_name, external_id) VALUES ('Peter', '00000000-0000-0000-0000-000000000112'); -- 4
     36INSERT INTO principal (principal_name, external_id) VALUES ('Olha', '00000000-0000-0000-0000-000000000113'); -- 5
    3737
    38 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 111, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021');
    39 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 112, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022');
    40 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 113, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023');
    41 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');
     38INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 3, '00000000-0000-0000-0000-000000000011');
     39INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 4, '00000000-0000-0000-0000-000000000012');
     40INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 5, '00000000-0000-0000-0000-000000000013');
     41
     42INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021');
     43INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 4, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022');
     44INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 5, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023');
     45INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 3, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');
    4246
    4347
     
    4852
    4953
     54
     55
Note: See TracChangeset for help on using the changeset viewer.