Changeset 3180


Ignore:
Timestamp:
07/23/13 11:31:04 (11 years ago)
Author:
olhsha
Message:

fixing redundant imports

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

Legend:

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

    r3168 r3180  
    1919
    2020import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     21import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
     22import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2123import eu.dasish.annotation.schema.Annotation;
    2224import eu.dasish.annotation.schema.AnnotationInfo;
     
    6769   
    6870    public int deleteAnnotation(Number annotationId) throws SQLException;
    69 
     71   
     72   
     73    /**
     74     *
     75     * @param annotation added to the table with annotations
     76     * @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
     77     */
     78    public AnnotationIdentifier addAnnotation(Annotation annotation);
     79 
     80   
    7081}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3168 r3180  
    2828import java.sql.SQLException;
    2929import java.util.ArrayList;
     30import java.util.HashMap;
    3031import java.util.List;
     32import java.util.Map;
    3133import javax.sql.DataSource;
     34import org.springframework.dao.DataAccessException;
    3235import org.springframework.jdbc.core.RowMapper;
    3336
     
    122125        }
    123126    };
    124    
    125    //////////////////////////////////////////////
    126    /* CREATE TABLE annotation (
    127     annotation_id SERIAL UNIQUE NOT NULL,
    128     external_id UUID UNIQUE NOT NULL,
    129     time_stamp timestamp with time zone default now(),
    130     owner_id integer,
    131     headline text,
    132     body_xml xml */
    133 
     127 
    134128   @Override
    135129    public Annotation getAnnotation(Number annotationID) throws SQLException{
     
    222216    };
    223217     
    224       
     218   @Override   
    225219     public int deleteAnnotation(Number annotationId) throws SQLException{
    226220        String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?";
    227         //String sqSources = "DELETE FROM " + sourceTableName + " where "+ notebook_id +"= ?";
    228221        int affectedAnnotations = getSimpleJdbcTemplate().update(sqlAnnotation, annotationId);
    229222        if (affectedAnnotations>1) {
     
    234227    }
    235228     
     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   
     240    @Override
     241    public AnnotationIdentifier addAnnotation(Annotation annotation) {
     242        try {
     243            AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier();
     244            Map<String, Object> params = new HashMap<String, Object>();
     245            params.put("externalId", annotationIdentifier.toString());
     246            params.put("timeStamp", annotation.getTimeStamp());
     247            params.put("ownerId", annotation.getOwner().getRef());
     248            params.put("headline", annotation.getHeadline());
     249            // may be changed once we elaborate the body
     250            params.put("bodyXml", annotation.getBody().getAny().get(0).toString());
     251            String sql = "INSERT INTO "+annotationTableName + "("+external_id+","+ time_stamp+"," + owner_id+","+headline+","+body_xml+" ) VALUES (:externalId, :timeStamp,  :ownerId, :headline, :bodyXml)";
     252            final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
     253            if (affectedRows == 1) {
     254                return annotationIdentifier;
     255            }
     256            else {
     257                // something went wrong
     258                return null;
     259            }
     260        } catch (DataAccessException exception) {
     261            throw exception;
     262        }
     263    }
     264     
     265   
    236266   
    237267    //////////// helpers ///////////////////////
     268   
    238269   
    239270    /////////////////////////////////////////////////
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3168 r3180  
    2424import eu.dasish.annotation.schema.ObjectFactory;
    2525import java.sql.SQLException;
     26import java.util.ArrayList;
     27import javax.ws.rs.Consumes;
    2628import javax.ws.rs.DELETE;
    2729import javax.ws.rs.GET;
     30import javax.ws.rs.POST;
    2831import javax.ws.rs.Path;
    2932import javax.ws.rs.PathParam;
     
    4447    @Autowired
    4548    private AnnotationDao annotationDao;
     49   
     50    final private int charBufferSize = 128;
    4651   
    4752    @GET
     
    6166        return Integer.toString(annotationDao.deleteAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier))));
    6267    }
     68   
     69    // TODO: should be returning the envelope!!!
     70    @POST
     71    @Consumes(MediaType.APPLICATION_XML)
     72    @Produces(MediaType.APPLICATION_XML)
     73    @Path("")
     74    public String createAnnotation(ArrayList<Annotation> annotation) {
     75        return "OK";
     76        /*AnnotationIdentifier newAnnotationIdentifier = annotationDao.addAnnotation(annotation);
     77        if (newAnnotationIdentifier == null) {
     78            return null;
     79        } else {
     80            return Response.status(Status.OK).entity(new ObjectFactory().createAnnotation(annotation)).build();
     81        }*/
     82    }
     83   
     84   
     85    /* helper: stolen from StackOverflow
     86    private String getBody(HttpServletRequest request) throws IOException{
     87        String body = null;
     88        StringBuilder stringBuilder = new StringBuilder();
     89        BufferedReader bufferedReader = null;
     90
     91        try {
     92            InputStream inputStream = request.getInputStream();
     93            if (inputStream != null) {
     94                bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
     95                char[] charBuffer = new char[charBufferSize];
     96                int bytesRead = -1;
     97                while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
     98                    stringBuilder.append(charBuffer, 0, bytesRead);
     99                }
     100            } else {
     101                stringBuilder.append("");
     102            }
     103        } catch (IOException ex) {
     104            throw ex;
     105        } finally {
     106            if (bufferedReader != null) {
     107                try {
     108                    bufferedReader.close();
     109                } catch (IOException ex) {
     110                    throw ex;
     111                }
     112            }
     113        }
     114
     115        body = stringBuilder.toString();
     116        return body;
     117
     118    }*/
     119
     120   
    63121}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml

    r3034 r3180  
    6363        <url-pattern>/webresources/*</url-pattern>
    6464    </servlet-mapping>-->
     65   
     66   
    6567    </web-app>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3168 r3180  
    4747    public static final String _TEST_ANNOT_5_EXT_TO_BE_DELETED = "00000000-0000-0000-0000-000000000025";
    4848   
     49   
    4950    public static final int _TEST_ANNOT_1_INT = 21;
    5051    public static final int _TEST_ANNOT_2_INT = 22;
     
    5657    public static final String _TEST_ANNOT_2_HEADLINE = "Gaudi";
    5758    public static final String _TEST_ANNOT_3_HEADLINE = "Art Nuveau";
     59    public static final String _TEST_ANNOT_TO_ADD_HEADLINE = "Annotation to add to test DAO";
    5860   
    5961    public static final int _TEST_ANNOT_1_OWNER = 111;
    6062    public static final int _TEST_ANNOT_2_OWNER = 112;
    6163    public static final int _TEST_ANNOT_3_OWNER = 113;
     64    public static final int _TEST_ANNOT_TO_ADD_OWNER = 117;
    6265   
    6366    public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>";
     67    public static final String _TEST_ANNOT_TO_ADD_BODY = "<html><body>the stuff to be added</body></html>";
    6468   
    6569    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');";
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java

    r3154 r3180  
    3030   
    3131    final private Annotation _annotationOne;
     32    final private Annotation _annotationToAdd;
    3233   
    3334    public TestInstances(){
    3435        _annotationOne = makeAnnotationOne();
     36        _annotationToAdd = makeAnnotationToAdd();
     37       
    3538    }
    3639   
    3740   
    3841    private Annotation makeAnnotationOne(){
    39         // add the other fields whengetAnnotation is completed
     42        Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_1_BODY, TestBackendConstants._TEST_ANNOT_1_HEADLINE, TestBackendConstants._TEST_ANNOT_1_OWNER);
     43        return result;
     44    }
     45   
     46    private Annotation makeAnnotationToAdd(){
     47        Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_TO_ADD_BODY, TestBackendConstants._TEST_ANNOT_TO_ADD_HEADLINE, TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER);
     48        return result;
     49    }
     50   
     51    // add the other fields whengetAnnotation is completed
     52    private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){
    4053        Annotation result = new Annotation();
    4154        AnnotationBody body = new AnnotationBody();
    4255        List<Object> bodyContent = body.getAny();
    43         bodyContent.add(TestBackendConstants._TEST_ANNOT_1_BODY);       
     56        bodyContent.add(bodyTxt);       
    4457        result.setBody(body);
    45         result.setHeadline(TestBackendConstants._TEST_ANNOT_1_HEADLINE);
     58        result.setHeadline(headline);
    4659        ResourceREF owner = new ResourceREF();
    47         owner.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER));
    48         result.setOwner(owner);
     60        owner.setRef(String.valueOf(ownerId));
     61        result.setOwner(owner); 
    4962        return result;
    5063    }
     64   
    5165   
    5266    public Annotation getAnnotationOne(){
    5367        return _annotationOne;
    5468    }
     69   
     70    public Annotation getAnnotationToAdd(){
     71        return _annotationToAdd;
     72    }
    5573}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3168 r3180  
    1919
    2020import eu.dasish.annotation.backend.TestBackendConstants;
     21import eu.dasish.annotation.backend.TestInstances;
    2122import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2323import eu.dasish.annotation.schema.Annotation;
    2424import eu.dasish.annotation.schema.AnnotationInfo;
     
    2727import java.util.ArrayList;
    2828import java.util.List;
    29 import java.util.UUID;
    3029import static org.junit.Assert.*;
    3130import org.junit.Test;
     
    4544   
    4645    @Autowired
    47     JdbcAnnotationDao jdbcAnnotationDao;   
     46    JdbcAnnotationDao jdbcAnnotationDao;
     47   
     48    TestInstances testInstances = new TestInstances();
    4849   
    4950    @Test
     
    171172    }
    172173   
     174   
     175    /**
     176     * Test of addAnnotation method, of class JdbcAnnotationDao.
     177     */
     178    @Test
     179    public void testAddAnnotation() throws SQLException{
     180        System.out.println("test_addAnnotation");
     181        Annotation annotationToAdd = testInstances.getAnnotationToAdd();
     182        AnnotationIdentifier result = jdbcAnnotationDao.addAnnotation(annotationToAdd);
     183        assertFalse(result == null);
     184       
     185        Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(result));       
     186        assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0));
     187        assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline());
     188        assertEquals(annotationToAdd.getOwner().getRef(), addedAnnotation.getOwner().getRef());
     189       
     190        // try to add an already existing annptation, should produce null
     191        //Annotation annotationOne = testInstances.getAnnotationOne();
     192        //AnnotationIdentifier resultOne = jdbcAnnotationDao.addAnnotation(annotationOne);
     193        // TODO: why it doesp produce an annotation, it already exists!!
     194        //assertTrue(resultOne == null);
     195       
     196    }
    173197}
    174198
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3168 r3180  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import com.sun.jersey.api.client.GenericType;
    2021import eu.dasish.annotation.backend.TestBackendConstants;
    2122import eu.dasish.annotation.backend.TestInstances;
     
    2425import eu.dasish.annotation.schema.Annotation;
    2526import java.sql.SQLException;
     27import javax.ws.rs.core.Response;
    2628import javax.xml.bind.JAXBElement;
    2729import org.jmock.Expectations;
     
    3335import org.springframework.test.context.ContextConfiguration;
    3436import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    35 
     37import java.lang.InstantiationException;
     38import java.util.ArrayList;
     39import java.util.List;
    3640/**
    3741 *
     
    4852    private AnnotationDao annotationDao;
    4953    @Autowired
    50     private AnnotationResource annotationResource;
     54    private AnnotationResource annotationResource; 
    5155   
    5256    public AnnotationResourceTest() {
     
    112116        assertEquals("0", result);
    113117    }
     118   
     119    /**
     120     * Test of createAnnotation method, of class AnnotationResource.
     121     */
     122    @Test
     123    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException {
     124        System.out.println("test createAnnotation");
     125        final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
     126        final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     127       
     128        mockery.checking(new Expectations() {
     129            {
     130                oneOf(annotationDao).addAnnotation(annotationToAdd);
     131                will(returnValue(newAnnotationID));
     132            }
     133        });
     134       
     135        ArrayList<Annotation> parameter = new ArrayList<Annotation>();
     136        parameter.add(annotationToAdd);
     137       
     138        String result = annotationResource.createAnnotation(parameter);       
     139        assertTrue(result=="OK");
     140        //assertEquals(200, result.getStatus());
     141        //assertTrue(annotationToAdd.equals(result.getEntity()));
     142    }
    114143}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3169 r3180  
    2525import eu.dasish.annotation.schema.ObjectFactory;
    2626import java.sql.SQLException;
     27import java.util.ArrayList;
     28import java.util.List;
    2729import javax.ws.rs.core.MediaType;
    2830import org.jmock.Expectations;
    2931import org.junit.Test;
    3032import static org.junit.Assert.*;
     33import org.junit.Ignore;
    3134/**
    3235 *
     
    119122        assertEquals("0", response.getEntity(String.class));
    120123    }
     124    /**
     125     * Test of createAnnotation method, of class AnnotationResource.
     126     * POST api/annotations/
     127     */
     128    @Test
     129    @Ignore
     130    public void testAddAnnotation() throws SQLException, InstantiationException, IllegalAccessException{
     131        System.out.println("testDeleteAnnotation");
     132        System.out.println("test createAnnotation");
     133        //final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
     134        final Annotation annotationToAdd = new ObjectFactory().createAnnotation();
     135        ///final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
     136       
     137//        mockery.checking(new Expectations() {
     138//            {
     139//                oneOf(annotationDao).addAnnotation(annotationToAdd);
     140//                will(returnValue(newAnnotationID));
     141//            }
     142//        });
     143       
     144       
     145        final String requestUrl = "annotations/";
     146        System.out.println("requestUrl: " + requestUrl);
     147       
     148        List<Annotation> parameter = new ArrayList<Annotation>();
     149        parameter.add(annotationToAdd);
     150       
     151        String response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).post(String.class, parameter);
     152        //assertEquals(200, response.getStatus());
     153        //assertEquals(annotationToAdd, response.getEntity(Annotation.class));
     154       
     155         
     156    }
    121157}
Note: See TracChangeset for help on using the changeset viewer.