Changeset 3236


Ignore:
Timestamp:
08/05/13 13:32:17 (11 years ago)
Author:
olhsha
Message:

get, retrieve list for versions, add and delete cached representations DAO are implemented and tested

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
3 added
8 edited

Legend:

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

    r3222 r3236  
    4141     * @return internal identifier of the resource with externalID
    4242     */
    43     public  Number getExternalId(CachedRepresentationIdentifier externalID);
     43    public  Number getInternalId(CachedRepresentationIdentifier externalID);
    4444   
    4545    /**
    4646     *
    4747     * @param internalID
    48      * @return the object which fields have the corresponding column values of the row internalID
     48     * @return the object "cached representation info"  with the internal id "internalID"
    4949     */
    5050    public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
     
    5353     *
    5454     * @param versionID
    55      * @return List of cached_representation_id-s of all the cached representations of the version with versionID
     55     * @return The list list of cached representation internal id-s of all the cached representations of the version with versionID
    5656     */
    5757    public List<Number> retrieveCachedRepresentationList(Number versionID);
     
    5959    /**
    6060     *
    61      * @param versionID
    62      * @return List of cached_representation_id-s of all the cached representations of the version with versionID
     61     * @param internalID
     62     * @return the amount of rows affected by removing from the DB the cached representation with the id "intenalID"
     63     * should be "1" (or 0 with  a non-existing id on the input)
    6364     */
    64     public CachedRepresentations retrieveCachedRepresentations(Number versionID);
     65    public int deleteCachedRepresentationInfo(Number internalID);
    6566   
     67    /**
     68     *
     69     * @param cached
     70     * @return copy of "cached" after "cached" is added to the DB; the internal id is set in the return copy
     71     */
     72    public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached);
    6673   
    6774}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3221 r3236  
    333333   
    334334   
    335    
    336    
    337     //TODO: update when target sources and permissions are added
     335 ////////////////////////////////////////// 
     336   
    338337    private  Annotation makeFreshCopy(Annotation annotation){
    339338       
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3222 r3236  
    2121import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2222import eu.dasish.annotation.schema.CachedRepresentationInfo;
    23 import eu.dasish.annotation.schema.CachedRepresentations;
    24 import eu.dasish.annotation.schema.ResourceREF;
    2523import java.sql.ResultSet;
    2624import java.sql.SQLException;
    27 import java.util.ArrayList;
     25import java.util.HashMap;
    2826import java.util.List;
     27import java.util.Map;
    2928import javax.sql.DataSource;
    3029import org.springframework.jdbc.core.RowMapper;
     
    6968      //////////////////////////////////////////////////////////////////////////////////////////////////////
    7069     @Override
    71      public Number getExternalId(CachedRepresentationIdentifier externalID){
     70     public Number getInternalId(CachedRepresentationIdentifier externalID){
    7271       if (externalID == null) {
    7372            return null;
    7473        }
    7574       String sql = "SELECT "+cached_representation_id+" FROM "+cachedRepresentationTableName+" WHERE "+external_id  +"= ?";
    76        List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID);
     75       List<Number> sqlResult= getSimpleJdbcTemplate().query(sql, internalIDRowMapper, externalID.toString());
    7776       
    7877       if (sqlResult == null) {
     
    9089        @Override
    9190        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    92             return(rs.getInt(cached_representation_id));
     91            int result = rs.getInt(cached_representation_id);
     92            Number resultNumber =  result;
     93            return resultNumber;
    9394        }
    9495     };
     
    140141      };
    141142     
     143      ////////////////////////////////////////////////////////////////////////////
     144      @Override
     145      public int deleteCachedRepresentationInfo(Number internalID){
     146        String sql = "DELETE FROM " + cachedRepresentationTableName + " where "+cached_representation_id + " = ?";
     147        String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where "+cached_representation_id + " = ?";       
     148        getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID);
     149        return (getSimpleJdbcTemplate().update(sql, internalID));
     150      };
     151     
     152      ////////////////////////////////////////////////////////////////////////////
     153      @Override
     154      public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached){
     155         
     156          CachedRepresentationIdentifier externalIdentifier = new CachedRepresentationIdentifier();
     157         
     158          Map<String, Object> params = new HashMap<String, Object>();
     159          params.put("externalId", externalIdentifier.toString());
     160          params.put("mime_type", cached.getMimeType());
     161          params.put("tool", cached.getTool());
     162          params.put("type", cached.getType());
     163          String sql = "INSERT INTO "+cachedRepresentationTableName + "("+external_id+","+ mime_type+"," + tool+","+type_+" ) VALUES (:externalId, :mime_type,  :tool, :type)";
     164          final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
     165          CachedRepresentationInfo cachedNew = makeFreshCopy(cached);         
     166          return cachedNew;
     167      }
    142168     
    143       /////////////////////////////////////////////////////
     169      ////////// Helpers ///////////////////
    144170     
    145       @Override
    146       public CachedRepresentations retrieveCachedRepresentations(Number versionID){
    147        CachedRepresentations result = new CachedRepresentations();
    148        
    149        List<Number> cachedRepresenationIDs = retrieveCachedRepresentationList(versionID);
    150        List<ResourceREF> cachedRepresenationIdentifierList = new ArrayList<ResourceREF>();
    151        
    152        for (Number cachedRepresentationID :  cachedRepresenationIDs){
    153            ResourceREF resourceREF = new ResourceREF();
    154            resourceREF.setRef(getExternalId(cachedRepresentationID).toString());
    155            cachedRepresenationIdentifierList.add(resourceREF);
    156        }
    157        
    158        result.getCachedRepresentation().addAll(cachedRepresenationIdentifierList);
    159        return result;
    160       };
    161      
     171      private CachedRepresentationInfo makeFreshCopy(CachedRepresentationInfo cached){
     172          CachedRepresentationInfo result = new CachedRepresentationInfo();
     173          result.setMimeType(cached.getMimeType());
     174          result.setRef(cached.getRef());
     175          result.setTool(cached.getTool());
     176          result.setType(cached.getType());
     177          return result;
     178      }
    162179}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3222 r3236  
    4545    final static protected String permissionsTableName = "annotations_principals_permissions";
    4646    final static protected String annotationsSourcesTableName = "annotations_target_sources";
    47     final static protected String versionsCachedRepresentationsTableName = "versions+cached_representations";
     47    final static protected String versionsCachedRepresentationsTableName = "versions_cached_representations";
    4848   
    4949   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3222 r3236  
    113113        public Version mapRow(ResultSet rs, int rowNumber) throws SQLException {
    114114            Version result = new Version();
    115             //external_id, mime_type, tool, type_, where_is_the_file
    116            // result.setCachedRepresentations((rs.get)
    117           //  result.setRef(rs.getString(external_id));
    118           //  result.setTool(rs.getString(tool));
    119            // result.setType(rs.getString(type_));
    120             // TODO add where is the file when the schem is updated!!!!s
     115            // TODO: clarify situation with the attribute cached representation
     116            //result.setCachedRepresentations!!! The same situation as with permissions lists: we cannot refer from a filed to a list of smth, we have a separate joint table
     117            // TODO: attribute URI (external-id is missing)
     118            result.setVersion(rs.getString("external_id"));
    121119            return result;
    122120        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3220 r3236  
    8181    public static final int _TEST_SOURCE_1_VERSION_ID = 1;
    8282    public static final int _TEST_SOURCE_2_VERSION_ID = 3;
     83   
     84    public static final String _TEST_CACHED_REPRESENTATION_1_EXT_ID_ = "00000000-0000-0000-0000-000000000051";
     85    // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --1
     86    public static final String _TEST_CACHED_REPRESENTATION_1_MIME_TYPE_ =  "text/html";
     87    public static final String _TEST_CACHED_REPRESENTATION_1_TOOL_ =  "latex";
     88    public static final String _TEST_CACHED_REPRESENTATION_1_TYPE_ =  "text";
     89   
     90   
    8391}
    8492
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java

    r3220 r3236  
    6666   
    6767    // so far tests only adding annot with existing sources!!!
    68     // TOD: add non-existing sources
     68    // TODO: add non-existing sources
    6969    private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){
    7070        Annotation result = new Annotation();
     
    9191        return _annotationToAdd;
    9292    }
     93   
     94   
    9395}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3217 r3236  
    123123INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000053', 'image/png', 'screenshooter', 'image', 'corpus1'); -- 3
    124124INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000054', 'text/html', 'oxygen', 'text', 'corpus1'); --4
     125INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000055', 'image/jpg', 'photomaster', 'image', 'TLAscratch'); --5
    125126
    126127--------------------------------------------------------------
     
    138139INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (3, 2);
    139140INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (4, 4);
    140 
     141INSERT INTO versions_cached_representations (version_id, cached_representation_id) VALUES (1, 5);
    141142
    142143---- PERMISSIONS --------------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.