Changeset 3463


Ignore:
Timestamp:
08/23/13 15:20:13 (11 years ago)
Author:
olhsha
Message:

making URI's in JAXB-generated classes fro resources <serviceURI>_<external_id>. Earlier it was just external Id.

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

Legend:

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

    r3461 r3463  
    5757    @Override
    5858    public List<Number> retrieveSourceIDs(Number annotationID) {
    59         String sql = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ?";
    60         List<Number> result = getSimpleJdbcTemplate().query(sql, sourceIDRowMapper, annotationID);
    61         return result;
     59        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     60        sql.append(source_id).append(" FROM ").append(annotationsSourcesTableName).append(" WHERE ").append(annotation_id).append("= ?");
     61        return getSimpleJdbcTemplate().query(sql.toString(), sourceIDRowMapper, annotationID);
    6262    }
    6363   
     
    102102        }
    103103
    104         List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
    105         return result;
     104        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
    106105    }
    107106
     
    119118        query.append(annotation_id).append(" FROM ").append(annotationsSourcesTableName).append(" WHERE ").append(source_id).append(" IN ");
    120119        query.append(values);
    121         List<Number> result = getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper);
    122         return result;
     120        return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper);
    123121    }
    124122   
     
    137135
    138136        String values = makeListOfValues(annotationIDs);
    139         String sql = "SELECT DISTINCT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
    140         return getSimpleJdbcTemplate().query(sql, annotationInfoRowMapper);
     137        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     138        sql.append(annotationStar).append(" FROM ").append(annotationTableName ).append(" WHERE ").append(annotationAnnotation_id).append("  IN ").append(values);
     139        return getSimpleJdbcTemplate().query(sql.toString(), annotationInfoRowMapper);
    141140    }
    142141    private final RowMapper<AnnotationInfo> annotationInfoRowMapper = new RowMapper<AnnotationInfo>() {
     
    144143        public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
    145144            AnnotationInfo annotationInfo = new AnnotationInfo();
     145            annotationInfo.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    146146            annotationInfo.setOwner(getResourceREF(Integer.toString(rs.getInt(owner_id))));
    147147            annotationInfo.setHeadline(rs.getString(headline));
     
    161161    @Override
    162162    public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) {
    163 
    164163        if (annotationIDs == null) {
    165164            return null;
    166165        }
    167 
    168166        if (annotationIDs.isEmpty()) {
    169167            return (new ArrayList<ResourceREF>());
     
    171169
    172170        String values = makeListOfValues(annotationIDs);
    173         String sql = "SELECT DISTINCT " + annotationAnnotation_id + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "  IN " + values;
    174         return getSimpleJdbcTemplate().query(sql, annotationREFRowMapper);
     171        StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
     172        sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("  IN ").append(values);
     173        return getSimpleJdbcTemplate().query(sql.toString(), annotationREFRowMapper);
    175174    }
    176175    private final RowMapper<ResourceREF> annotationREFRowMapper = new RowMapper<ResourceREF>() {
     
    178177        public ResourceREF mapRow(ResultSet rs, int rowNumber) throws SQLException {
    179178            ResourceREF annotationREF = new ResourceREF();
    180             annotationREF.setRef(Integer.toString(rs.getInt(annotation_id)));
     179            annotationREF.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    181180            return annotationREF;
    182181        }
     
    188187        if (annotationID == null) {
    189188            return null;        }
    190         String sql = "SELECT " + annotationStar + " FROM " + annotationTableName + " WHERE " + annotationAnnotation_id + "= ? LIMIT  1";
    191         List<Annotation> respond = getSimpleJdbcTemplate().query(sql, annotationRowMapper, annotationID);
    192 
    193         if (respond == null) {
    194             return null;
    195         }
    196      
    197         Annotation result = respond.get(0);
    198         String externalId = result.getURI();
    199         result.setURI(extrnalIDtoURI(_serviceURI, externalId));
    200        
    201         return result;
     189        StringBuilder sql = new StringBuilder("SELECT ");
     190        sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("= ? LIMIT  1");
     191        List<Annotation> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID);
     192        return (respond.isEmpty() ? null : respond.get(0));
    202193    }
    203194   
     
    215206            annotation.setBody(Helpers.deserializeBody(rs.getString(body_xml)));
    216207            annotation.setTargetSources(null);
    217             // TODO: fix: rpelace URI in the schema with external id, or make here the conversion:
    218             // from external ID in the DB to the URI for the class
    219             annotation.setURI(rs.getString(external_id));
     208            annotation.setURI(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    220209
    221210            try {
     
    232221   
    233222    private boolean annotationIsInUse(Number sourceID) {
    234         String sqlNotebooks = "SELECT " + notebook_id + " FROM " + notebooksAnnotationsTableName + " WHERE " + annotation_id + "= ? LIMIT 1";
    235         List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks, notebookIDRowMapper, sourceID);
     223        StringBuilder sqlNotebooks = new StringBuilder("SELECT ");
     224        sqlNotebooks.append(notebook_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     225        List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookIDRowMapper, sourceID);
    236226        if (resultNotebooks.size() > 0) {
    237227            return true;
    238228        }
    239         String sqlSources = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ? LIMIT 1";
    240         List<Number> resultSources = getSimpleJdbcTemplate().query(sqlSources, sourceIDRowMapper, sourceID);
     229       
     230        StringBuilder sqlSources = new StringBuilder("SELECT ");
     231        sqlSources.append(source_id).append(" FROM ").append(annotationsSourcesTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     232        List<Number> resultSources = getSimpleJdbcTemplate().query(sqlSources.toString(), sourceIDRowMapper, sourceID);
    241233        if (resultSources.size() > 0) {
    242234            return true;
    243235        }
    244         String sqlPermissions = "SELECT " + principal_id + " FROM " + permissionsTableName + " WHERE " + annotation_id + "= ? LIMIT 1";
    245         List<Number> resultPermissions = getSimpleJdbcTemplate().query(sqlPermissions, principalIDRowMapper, sourceID);
    246         if (resultPermissions.size() > 0) {
    247             return true;
    248         }
    249236       
    250         return false;
     237        StringBuilder sqlPermissions = new StringBuilder("SELECT ");
     238        sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
     239        List<Number> resultPermissions = getSimpleJdbcTemplate().query(sqlPermissions.toString(), principalIDRowMapper, sourceID);
     240        return (resultPermissions.size() > 0);
    251241    }
    252242   
     
    282272        sql.append(",").append(headline).append(",").append(body_xml).append(" ) VALUES (:externalId, :ownerId, :headline, :bodyXml)");
    283273        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
    284         if (affectedRows == 1) {
    285             return getInternalID(externalID);
    286         } else {
    287             return null;
    288         }
    289 
     274        return ((affectedRows > 0) ? getInternalID(externalID) : null);
    290275    }
    291276   
     
    296281        paramsAnnotationsSources.put("annotationId", annotationID);
    297282        paramsAnnotationsSources.put("sourceId", sourceID);
    298         String sqlAnnotationsSources = "INSERT INTO " + annotationsSourcesTableName + "(" + annotation_id + "," + source_id + " ) VALUES (:annotationId, :sourceId)";
    299         int affectedRows = getSimpleJdbcTemplate().update(sqlAnnotationsSources, paramsAnnotationsSources);
    300         return (affectedRows);
     283        StringBuilder  sqlAnnotationsSources = new StringBuilder("INSERT INTO ");
     284        sqlAnnotationsSources.append(annotationsSourcesTableName ).append("(").append(annotation_id).append(",").append(source_id).append(" ) VALUES (:annotationId, :sourceId)");
     285        return getSimpleJdbcTemplate().update(sqlAnnotationsSources.toString(), paramsAnnotationsSources);
    301286    }
    302287    //////////////////////////////////////////////////////////////////////////////////
    303288
    304289   
    305     //////////////////////////////////////////////////////
     290    /////////////////// DELETERS //////////////////////////
    306291    @Override
    307292    public int deleteAnnotation(Number annotationID) throws SQLException {
     
    309294            return 0;
    310295        }
    311        
    312         String sqlAnnotation = "DELETE FROM " + annotationTableName + " where " + annotation_id + " = ?";
    313         return (getSimpleJdbcTemplate().update(sqlAnnotation, annotationID));
     296        StringBuilder sqlAnnotation = new StringBuilder("DELETE FROM ");
     297        sqlAnnotation.append(annotationTableName).append(" where ").append(annotation_id).append(" = ?");
     298        return (getSimpleJdbcTemplate().update(sqlAnnotation.toString(), annotationID));
    314299    }
    315300   
     
    317302    @Override
    318303    public int deleteAllAnnotationSource(Number annotationID) throws SQLException {
    319         String sqlTargetSources = "DELETE FROM " + annotationsSourcesTableName + " where " + annotation_id + " = ?";
    320         return getSimpleJdbcTemplate().update(sqlTargetSources, annotationID); // removed "annotations_target_sources" rows
     304        StringBuilder sqlTargetSources = new StringBuilder("DELETE FROM ");
     305        sqlTargetSources.append(annotationsSourcesTableName).append(" WHERE ").append(annotation_id).append(" = ?");
     306        return getSimpleJdbcTemplate().update(sqlTargetSources.toString(), annotationID); // # removed "annotations_target_sources" rows
    321307       
    322308    }
     
    338324    @Override
    339325    public int deleteAnnotationPrincipalPermissions(Number annotationID) throws SQLException {
    340         String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?";
    341         return getSimpleJdbcTemplate().update(sqlPermissions, annotationID); // removed "permission" rows
     326        StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
     327        sqlPermissions.append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = ?");
     328        return getSimpleJdbcTemplate().update(sqlPermissions.toString(), annotationID); // removed "permission" rows
    342329       
    343330    }
     
    350337        paramsPermissions.put("principalId", userID);
    351338        paramsPermissions.put("status", permission.value());
    352         String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + this.permission + ") VALUES (:annotationId, :principalId, :status)";
    353         final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable, paramsPermissions);
     339        StringBuilder sqlUpdatePermissionTable = new StringBuilder("INSERT INTO ");
     340        sqlUpdatePermissionTable.append(permissionsTableName).append(" (").append(annotation_id).append(",").append(principal_id).append(",").append(this.permission ).append(") VALUES (:annotationId, :principalId, :status)");
     341        final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable.toString(), paramsPermissions);
    354342        return affectedPermissions;
    355343    }
     
    362350            return null;
    363351        }
    364         String sql = "SELECT " + principal_id + "," + permission + " FROM " + permissionsTableName + " WHERE " + annotation_id + "  = ?";
    365         List<Map<Number, String>> result = getSimpleJdbcTemplate().query(sql, principalsPermissionsRowMapper, annotationId.toString());
    366         return result;
     352        StringBuilder sql = new StringBuilder("SELECT ");
     353        sql.append(principal_id).append(",").append(permission).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(annotation_id).append("  = ?");
     354        return getSimpleJdbcTemplate().query(sql.toString(), principalsPermissionsRowMapper, annotationId.toString());
    367355    }
    368356    private final RowMapper<Map<Number, String>> principalsPermissionsRowMapper = new RowMapper<Map<Number, String>>() {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3459 r3463  
    4949    public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID) {
    5050
    51         String sql = "SELECT " + cachedRepresentationStar + " FROM " + cachedRepresentationTableName + " WHERE " + cached_representation_id + "= ?";
     51        String sql = "SELECT " + cachedRepresentationStar + " FROM " + cachedRepresentationTableName + " WHERE " + cached_representation_id + "= ? LIMIT 1";
    5252        List<CachedRepresentationInfo> result = getSimpleJdbcTemplate().query(sql, cachedRepresentationRowMapper, internalID);
    5353
    54         if (result == null) {
    55             return null;
    56         }
    5754        if (result.isEmpty()) {
    5855            return null;
     
    6562            CachedRepresentationInfo result = new CachedRepresentationInfo();
    6663            result.setMimeType(rs.getString(mime_type));
    67             result.setRef(rs.getString(external_id));
     64            result.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    6865            result.setTool(rs.getString(tool));
    6966            result.setType(rs.getString(type_));
     
    7875        String sql = "SELECT " + version_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + cached_representation_id + "= ? LIMIT 1";
    7976        List<Number> result = getSimpleJdbcTemplate().query(sql, versionIDRowMapper, cachedID);
    80         if (result.size() > 0) {
    81             return true;
    82         }
    83         return false;
     77        return (!result.isEmpty());
    8478    }
    8579   
     
    8983    @Override
    9084    public Number addCachedRepresentationInfo(CachedRepresentationInfo cached) {
    91 
    9285        UUID externalIdentifier = UUID.randomUUID();
    9386        Map<String, Object> params = new HashMap<String, Object>();
     
    9891        String sql = "INSERT INTO " + cachedRepresentationTableName + "(" + external_id + "," + mime_type + "," + tool + "," + type_ + " ) VALUES (:externalId, :mime_type,  :tool, :type)";
    9992        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    100         return getInternalID(externalIdentifier);
     93        return (affectedRows > 0 ? getInternalID(externalIdentifier) : null);
    10194    }
    10295
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3455 r3463  
    2424import eu.dasish.annotation.schema.NotebookInfo;
    2525import eu.dasish.annotation.schema.ResourceREF;
     26import eu.dasish.annotation.schema.Version;
    2627import java.sql.ResultSet;
    2728import java.sql.SQLException;
     
    5758    }
    5859
     60    ////////////////////////////////////////////////
    5961    @Override
    6062    public List<NotebookInfo> getNotebookInfos(UUID  userID) {
     
    6264        return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString());
    6365    }
    64 
    65     @Override
    66     public List<Notebook> getUsersNotebooks(UUID userID) {
    67         String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?";
    68         return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString());
    69     }
    70 
    71     @Override
    72     public UUID addNotebook(UUID userID, String title) {
    73         try {
    74             final UUID externalIdentifier = UUID.randomUUID();
    75             String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
    76             Map<String, Object> params = new HashMap<String, Object>();
    77             params.put("notebookId", externalIdentifier.toString());
    78             params.put("userID", userID.toString());
    79             params.put("title", title);
    80             final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);
    81             return externalIdentifier;
    82         } catch (DataAccessException exception) {
    83             throw exception;
    84         }
    85     }
     66   
    8667    private final RowMapper<NotebookInfo> notebookInfoRowMapper = new RowMapper<NotebookInfo>() {
    8768        @Override
    8869        public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
    8970            NotebookInfo notebookInfo = new NotebookInfo();
    90             notebookInfo.setRef(rs.getString(external_id)); // todo: what is ref? should it be the external id? Olha: "yes"
     71            notebookInfo.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    9172            notebookInfo.setTitle(rs.getString(title));
    92 //            notebookInfo.setRef(rs.getString("URI"));
    9373            return notebookInfo;
    9474        }
    9575    };
    96     private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() {
     76   
     77    ////////////////////////////////////////////////
     78
     79    @Override
     80    public List<Notebook> getUsersNotebooks(UUID userID) {
     81        String sql = "SELECT " + notebookStar + " FROM " + notebookTableName + ", " + principalTableName + " where " + principal_id + " = " + owner_id + " and " + principalExternal_id + " = ?";
     82        return getSimpleJdbcTemplate().query(sql, notebookRowMapper, userID.toString());
     83    }
     84   
     85       private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() {
    9786        @Override
    9887        public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException {
     
    10897                throw new SQLException(exception);
    10998            }
    110 //            notebook.setURI(rs.getString("URI_ID"));
     99            notebook.setURI(externalIDtoURI(_serviceURI,rs.getString("external_id")));
    111100            notebook.setAnnotations(getAnnotations(rs.getInt(notebook_id)));
    112101            return notebook;
    113102        }
    114103    };
     104
     105    @Override
     106    public UUID addNotebook(UUID userID, String title) {
     107        try {
     108            final UUID externalIdentifier = UUID.randomUUID();
     109            String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + owner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";
     110            Map<String, Object> params = new HashMap<String, Object>();
     111            params.put("notebookId", externalIdentifier.toString());
     112            params.put("userID", userID.toString());
     113            params.put("title", title);
     114            final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);
     115            return externalIdentifier;
     116        } catch (DataAccessException exception) {
     117            throw exception;
     118        }
     119    }
     120   
     121 
    115122
    116123    // returns the number of affected annotations
     
    152159        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
    153160    }
    154     private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {
    155         @Override
    156         public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
    157             Integer annotationId = rs.getInt("annotation_id");
    158             return annotationId;
    159         }
    160     };
    161 
     161 
    162162    //////////////////////////////////////////////////
    163163    /**
     
    216216            return null;
    217217        }
    218         String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ?";
     218        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
    219219        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID.toString());
    220         if (result == null) {
    221             return null;
    222         }
    223         if (result.isEmpty()) {
    224             return null;
    225         }
    226         return result.get(0);
     220        return (!result.isEmpty() ? result.get(0) : null);
    227221    }
    228222
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3461 r3463  
    203203   
    204204     
    205     protected String extrnalIDtoURI(String serviceURI, String externalID) {
     205    protected String externalIDtoURI(String serviceURI, String externalID) {
    206206        if (_serviceURI != null) {
    207207            return _serviceURI + externalID;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3459 r3463  
    5353        String sql = "SELECT " + sourceStar + "FROM " + sourceTableName + " WHERE " + source_id + " = ?";
    5454        List<Source> result = getSimpleJdbcTemplate().query(sql, sourceRowMapper, internalID);
    55         return result.get(0);
     55        return (!result.isEmpty() ? result.get(0) : null);
    5656    }
    5757    private final RowMapper<Source> sourceRowMapper = new RowMapper<Source>() {
     
    6161                XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp));
    6262                Source result =
    63                         constructSource(UUID.fromString(rs.getString(external_id)), rs.getString(link_uri), rs.getString(version), xmlDate);
     63                        constructSource(rs.getString(external_id), rs.getString(link_uri), rs.getString(version), xmlDate);
    6464                return result;
    6565            } catch (DatatypeConfigurationException e) {
     
    7575    public List<Number> retrieveVersionList(Number sourceID) {
    7676        String sql = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?";
    77         List<Number> result = getSimpleJdbcTemplate().query(sql, versionIDRowMapper, sourceID);
    78         return result;
     77        return getSimpleJdbcTemplate().query(sql, versionIDRowMapper, sourceID);
    7978    }
    8079
     
    9291        String sourceIDs = makeListOfValues(sources);
    9392        String sql = "SELECT " + external_id + "," + link_uri + "," + version + " FROM " + sourceTableName + " WHERE " + source_id + " IN " + sourceIDs;
    94         List<SourceInfo> result = getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper);
    95         return result;
     93        return getSimpleJdbcTemplate().query(sql, SourceInfoRowMapper);
    9694    }
    9795    private final RowMapper<SourceInfo> SourceInfoRowMapper = new RowMapper<SourceInfo>() {
    9896        @Override
    9997        public SourceInfo mapRow(ResultSet rs, int rowNumber) throws SQLException {
    100             return constructSourceInfo(UUID.fromString(rs.getString(external_id)), rs.getString(link_uri), rs.getString(version));
     98            return constructSourceInfo(rs.getString(external_id), rs.getString(link_uri), rs.getString(version));
    10199        }
    102100    };
     
    108106        StringBuilder sql = new StringBuilder("SELECT ");
    109107        sql.append(source_id).append(" FROM ").append(sourceTableName).append(" WHERE ").append(link_uri).append(" LIKE '%").append(link).append("%'");
    110         List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);
    111         return result;
     108        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper);
    112109    }
    113110
     
    123120        String sqlVersions = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + "= ? LIMIT 1";
    124121        List<Number> resultVersions = getSimpleJdbcTemplate().query(sqlVersions, versionIDRowMapper, sourceID);
    125         if (resultVersions.size() > 0) {
    126             return true;
    127         }
    128         return false;
     122        return (resultVersions.size() > 0);
    129123    }
    130124   
     
    135129    @Override
    136130    public Number addSource(Source source) throws SQLException {       
    137         String externalID = source.getURI();       
     131        UUID externalID = UUID.randomUUID();     
    138132        Map<String, Object> params = new HashMap<String, Object>();
    139         params.put("externalId", externalID);
     133        params.put("externalId", externalID.toString());
    140134        params.put("linkUri", source.getLink());
    141135        params.put("version", source.getVersion());
    142136        String sql = "INSERT INTO " + sourceTableName + "(" + external_id + "," + link_uri + "," + version + " ) VALUES (:externalId, :linkUri,  :version)";
    143         final int affectedRows = getSimpleJdbcTemplate().update(sql, params);       
    144         Number internalID = getInternalID(UUID.fromString(externalID));
    145         return internalID;
     137        final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 
     138        return (affectedRows>0 ? getInternalID(UUID.fromString(externalID.toString())) : null);
    146139    }
    147140   
     
    164157        }
    165158        String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? ";
    166         int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    167         return result;
     159        return getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    168160
    169161    }
     
    174166    public int deleteAllSourceVersion(Number internalID) {
    175167        String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?";
    176         int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    177         return result;
     168        return getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
    178169
    179170    }
     
    183174   
    184175
    185     private SourceInfo constructSourceInfo(UUID UUID, String link, String version) {
     176    private SourceInfo constructSourceInfo(String externalID, String link, String version) {
    186177        SourceInfo sourceInfo = new SourceInfo();
    187         sourceInfo.setRef(UUID.toString());
     178        sourceInfo.setRef(externalIDtoURI(_serviceURI,externalID));
    188179        sourceInfo.setLink(link);
    189180        sourceInfo.setVersion(version);
     
    191182    }
    192183
    193     private Source constructSource(UUID UUID, String link, String version, XMLGregorianCalendar xmlTimeStamp) {
     184    private Source constructSource(String externalID, String link, String version, XMLGregorianCalendar xmlTimeStamp) {
    194185        Source source = new Source();
    195         source.setURI(UUID.toString());
     186        source.setURI(externalIDtoURI(_serviceURI, externalID));
    196187        source.setTimeSatmp(xmlTimeStamp);
    197188        source.setLink(link);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java

    r3459 r3463  
    4949        String sql = "SELECT " + versionStar + " FROM " + versionTableName + " WHERE " + version_id + "= ? LIMIT 1";
    5050        List<Version> result = getSimpleJdbcTemplate().query(sql, versionRowMapper, internalID);
    51         if (result.isEmpty()) {
    52             return null;
    53         }
    54         return result.get(0);
     51        return (!result.isEmpty() ? result.get(0) : null);
    5552    }
    5653    private final RowMapper<Version> versionRowMapper = new RowMapper<Version>() {
     
    6158            //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
    6259            // TODO: attribute URI (external-id is missing)
    63             result.setVersion(rs.getString("external_id"));
     60            result.setVersion(externalIDtoURI(_serviceURI, rs.getString(external_id)));
    6461            return result;
    6562        }
     
    6966    @Override
    7067    public List<Number> retrieveCachedRepresentationList(Number versionID) {
    71         String sql = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ?";
    72         List<Number> result = getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, versionID);
    73         return result;
     68        String sql = "SELECT DISTINCT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ?";
     69        return getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, versionID);
    7470    }
    7571
     
    8783        String sqlVersions = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ? LIMIT 1";
    8884        List<Number> resultCached = getSimpleJdbcTemplate().query(sqlVersions, cachedIDRowMapper, versionsID);
    89         if (resultCached.size() > 0) {
    90             return true;
    91         }
    92         return false;
     85        return (resultCached.size() > 0) ;
    9386    }
    9487   
     
    108101        String sql = "INSERT INTO " + versionTableName + "(" + external_id + "," + version + " ) VALUES (:externalId, :version)";
    109102        final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    110         return getInternalID(externalIdentifier);
     103        return (affectedRows>0 ? getInternalID(externalIdentifier) : null);
    111104    }
    112105   
     
    130123        }       
    131124        String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?";
    132         int result = getSimpleJdbcTemplate().update(sql, internalID);     
    133         return result;
     125        return getSimpleJdbcTemplate().update(sql, internalID);
    134126
    135127    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3461 r3463  
    106106        annotIds.add(4);
    107107
     108        jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    108109        final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfos(annotIds);
    109110        assertEquals(3, annotationInfos.size());
     
    111112        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(0).getHeadline());
    112113        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(0).getOwner().getRef());
     114        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_ANNOT_2_EXT,
     115           annotationInfos.get(0).getRef());         
    113116        //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources());
    114117
    115118        assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfos.get(1).getHeadline());
    116119        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfos.get(1).getOwner().getRef());
     120        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_ANNOT_3_EXT,
     121           annotationInfos.get(1).getRef());
    117122        //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources());
    118123
    119124        assertEquals(TestBackendConstants._TEST_ANNOT_4_HEADLINE, annotationInfos.get(2).getHeadline());
    120125        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_4_OWNER), annotationInfos.get(2).getOwner().getRef());
     126        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_ANNOT_4_EXT,
     127           annotationInfos.get(2).getRef());
    121128        //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfos.get(2).getTargetSources());
    122129
     
    142149        annotIds.add(4);
    143150
     151        jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    144152        final List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds);
    145153        assertEquals(3, testList.size());
    146         assertEquals(String.valueOf(2), testList.get(0).getRef());
    147         assertEquals(String.valueOf(3), testList.get(1).getRef());
    148         assertEquals(String.valueOf(4), testList.get(2).getRef());
     154        assertEquals(TestBackendConstants._TEST_SERVLET_URI +TestBackendConstants._TEST_ANNOT_2_EXT, testList.get(0).getRef());
     155        assertEquals(TestBackendConstants._TEST_SERVLET_URI +TestBackendConstants._TEST_ANNOT_3_EXT, testList.get(1).getRef());
     156        assertEquals(TestBackendConstants._TEST_SERVLET_URI + TestBackendConstants._TEST_ANNOT_4_EXT, testList.get(2).getRef());
    149157
    150158        final List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>());
     
    188196        assertEquals(null, annotaionNull);
    189197        ////
    190 
     198             
    191199        final Number testAnnotationID = 2;
    192200        jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3455 r3463  
    8181        System.out.println("getCachedRepresentationInfo");
    8282       
     83        jdbcCachedRepresentationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    8384        CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);       
    84         assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
     85        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
    8586        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType());
    8687        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool());
    8788        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getType());
     89        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
    8890    }
    8991
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3455 r3463  
    8383       
    8484        ResourceREF testRef = new ResourceREF();
    85         testRef.setRef("1");
     85        testRef.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_AID_1_);
    8686        final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRef});
    8787       
    8888        mockery.checking(new Expectations() {
    8989            {
    90                 exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1
     90                exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contain the annotation 1
    9191                will(returnValue(testResult));
     92                // necessary to set annotations reference lists in the notebook
    9293            }
    9394        });
    9495       
     96        jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    9597        final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(UUID.fromString(TestBackendConstants._TEST_UID_2_));
    9698
     
    98100        assertEquals(2, notebooks.size());
    99101        assertEquals("a notebook", notebooks.get(0).getTitle());
    100 //        assertEquals("http://123456", notebooks.get(0).getURI());
     102        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_NOTEBOOK_1_EXT_ID, notebooks.get(0).getURI());
    101103        assertNotNull(notebooks.get(0).getTimeStamp());
    102104        assertEquals(year, notebooks.get(0).getTimeStamp().getYear());
     
    176178        System.out.println("getAnnotationREFsOfNotebook");
    177179       
     180        jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    178181        // test One         
    179         setMockeryNotebookOne();        
     182        setMockeryNotebookOne();
    180183        List<ResourceREF> testList = jdbcNotebookDao.getAnnotationREFsOfNotebook(3);
    181184        assertEquals(2, testList.size());       
    182         assertEquals(String.valueOf(2), testList.get(0).getRef());
    183         assertEquals(String.valueOf(3), testList.get(1).getRef());
     185        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_2_EXT, testList.get(0).getRef());
     186        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_3_EXT, testList.get(1).getRef());
    184187       
    185188        // test Two
     
    187190        List<ResourceREF> testListTwo = jdbcNotebookDao.getAnnotationREFsOfNotebook(4);
    188191        assertEquals(1, testListTwo.size());       
    189         assertEquals(String.valueOf(4), testListTwo.get(0).getRef());
     192        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_4_EXT, testListTwo.get(0).getRef());
    190193       
    191194        // test Three  "empty"
     
    208211        System.out.println("getAnnotations");
    209212       
     213        jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     214       
    210215         // test One
    211216        setMockeryNotebookOne();
    212217        Annotations annotations = jdbcNotebookDao.getAnnotations(3);
    213218        assertEquals(2, annotations.getAnnotation().size());       
    214         assertEquals(String.valueOf(2), annotations.getAnnotation().get(0).getRef());
    215         assertEquals(String.valueOf(3), annotations.getAnnotation().get(1).getRef());
     219        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_2_EXT, annotations.getAnnotation().get(0).getRef());
     220        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_3_EXT, annotations.getAnnotation().get(1).getRef());
    216221       
    217222        // test Two
     
    219224        Annotations annotationsTwo = jdbcNotebookDao.getAnnotations(4);
    220225        assertEquals(1, annotationsTwo.getAnnotation().size());       
    221         assertEquals(String.valueOf(4), annotationsTwo.getAnnotation().get(0).getRef());
     226        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_4_EXT, annotationsTwo.getAnnotation().get(0).getRef());
    222227       
    223228        // test Three  "empty" list of annotations
     
    242247        System.out.println("test getNotebookInfo");
    243248       
     249        jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
     250       
    244251         // test One       
    245252        NotebookInfo info = jdbcNotebookDao.getNotebookInfo(3);
    246         assertEquals(TestBackendConstants._TEST_NOTEBOOK_3_EXT, info.getRef());
     253        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_NOTEBOOK_3_EXT, info.getRef());
    247254        assertEquals(TestBackendConstants._TEST_NOTEBOOK_3_TITLE, info.getTitle());
    248255       
     
    305312    private void setMockeryNotebookOne(){       
    306313        ResourceREF testRefOne = new ResourceREF();
    307         testRefOne.setRef(String.valueOf(2));
     314        testRefOne.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_2_EXT);
    308315        ResourceREF testRefTwo = new ResourceREF();
    309         testRefTwo.setRef(String.valueOf(3));
     316        testRefTwo.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_3_EXT);
    310317        final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRefOne, testRefTwo});
    311318       
     
    320327     private void setMockeryNotebookTwo(){
    321328        ResourceREF testRef = new ResourceREF();
    322         testRef.setRef(String.valueOf(4));
     329        testRef.setRef(String.valueOf(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_4_EXT));
    323330        final List<ResourceREF> testResultTwo = Arrays.asList(new ResourceREF[] {testRef});
    324331       
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3455 r3463  
    7373        System.out.println("getSource");
    7474        Number internalID = 1;
     75        jdbcSourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    7576        Source result = jdbcSourceDao.getSource(internalID);
    76         assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI());
     77        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI());
    7778        assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.getLink());
    7879        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
    79         //TODO: time stamp is not checked: do not know with what to compare
     80        // TODO :add time stamp test
     81       
    8082    }
    8183
     
    128130        freshSource.setLink(link);
    129131        freshSource.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    130         freshSource.setURI((UUID.randomUUID()).toString());
    131132        freshSource.setTimeSatmp(null);
    132133       
     
    137138        assertEquals(link, addedSource.getLink());
    138139        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, addedSource.getVersion());
    139         assertEquals(freshSource.getURI(), addedSource.getURI());
     140        assertTrue(addedSource.getURI().startsWith(TestBackendConstants._TEST_SERVLET_URI));
    140141    }
    141142
     
    145146    @Test
    146147    public void testGetSourceInfos() {
    147         System.out.println("getSourceInfos");
     148        System.out.println("getSourceInfos");       
     149        jdbcSourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    148150        List<Number> test = new ArrayList<Number>();
    149151        test.add(1);
     
    151153        List<SourceInfo> result = jdbcSourceDao.getSourceInfos(test);
    152154        assertEquals(2, result.size());
    153         assertEquals(TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.get(0).getRef());
    154         assertEquals(TestBackendConstants._TEST_SOURCE_2_EXT_ID, result.get(1).getRef());
     155        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.get(0).getRef());
     156        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_SOURCE_2_EXT_ID, result.get(1).getRef());
    155157        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.get(0).getVersion());
    156158        assertEquals(TestBackendConstants._TEST_VERSION_3_EXT_ID, result.get(1).getVersion());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3455 r3463  
    7070    @Test
    7171    public void testGetVersion() {
    72         System.out.println("getVersion");
     72        System.out.println("getVersion");       
     73        jdbcVersionDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI);
    7374        Number internalID = 1;
     75       
    7476        Version result = jdbcVersionDao.getVersion(internalID);
    75         assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
     77        assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
    7678        //TODO: once the schems is fixed, test "version" and "URI/external-id" separately
    7779        // at the moment "version" corresponds "external_id"
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3455 r3463  
    6464        System.out.println("getNotebookInfo");
    6565        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    66         httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_1_);
     66        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_1_);       
     67        httpServletRequest.setServletPath(TestBackendConstants._TEST_SERVLET_URI);
     68       
    6769       
    6870        mockery.checking(new Expectations() {
     
    8991        });
    9092        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    91         httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);
     93        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);               
     94        httpServletRequest.setServletPath(TestBackendConstants._TEST_SERVLET_URI);
    9295        List result = notebookResource.getUsersNotebooks(httpServletRequest);
    9396        assertEquals(0, result.size());
     
    101104        System.out.println("createNotebook");
    102105        final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    103         httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);
     106        httpServletRequest.setRemoteUser(TestBackendConstants._TEST_UID_2_);               
     107        httpServletRequest.setServletPath(TestBackendConstants._TEST_SERVLET_URI);
     108       
    104109        mockery.checking(new Expectations() {
    105110            {
Note: See TracChangeset for help on using the changeset viewer.