Changeset 3463
- Timestamp:
- 08/23/13 15:20:13 (11 years ago)
- 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 57 57 @Override 58 58 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); 62 62 } 63 63 … … 102 102 } 103 103 104 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params); 105 return result; 104 return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params); 106 105 } 107 106 … … 119 118 query.append(annotation_id).append(" FROM ").append(annotationsSourcesTableName).append(" WHERE ").append(source_id).append(" IN "); 120 119 query.append(values); 121 List<Number> result = getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper); 122 return result; 120 return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper); 123 121 } 124 122 … … 137 135 138 136 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); 141 140 } 142 141 private final RowMapper<AnnotationInfo> annotationInfoRowMapper = new RowMapper<AnnotationInfo>() { … … 144 143 public AnnotationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 145 144 AnnotationInfo annotationInfo = new AnnotationInfo(); 145 annotationInfo.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id))); 146 146 annotationInfo.setOwner(getResourceREF(Integer.toString(rs.getInt(owner_id)))); 147 147 annotationInfo.setHeadline(rs.getString(headline)); … … 161 161 @Override 162 162 public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) { 163 164 163 if (annotationIDs == null) { 165 164 return null; 166 165 } 167 168 166 if (annotationIDs.isEmpty()) { 169 167 return (new ArrayList<ResourceREF>()); … … 171 169 172 170 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); 175 174 } 176 175 private final RowMapper<ResourceREF> annotationREFRowMapper = new RowMapper<ResourceREF>() { … … 178 177 public ResourceREF mapRow(ResultSet rs, int rowNumber) throws SQLException { 179 178 ResourceREF annotationREF = new ResourceREF(); 180 annotationREF.setRef( Integer.toString(rs.getInt(annotation_id)));179 annotationREF.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id))); 181 180 return annotationREF; 182 181 } … … 188 187 if (annotationID == null) { 189 188 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)); 202 193 } 203 194 … … 215 206 annotation.setBody(Helpers.deserializeBody(rs.getString(body_xml))); 216 207 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))); 220 209 221 210 try { … … 232 221 233 222 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); 236 226 if (resultNotebooks.size() > 0) { 237 227 return true; 238 228 } 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); 241 233 if (resultSources.size() > 0) { 242 234 return true; 243 235 } 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 }249 236 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); 251 241 } 252 242 … … 282 272 sql.append(",").append(headline).append(",").append(body_xml).append(" ) VALUES (:externalId, :ownerId, :headline, :bodyXml)"); 283 273 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); 290 275 } 291 276 … … 296 281 paramsAnnotationsSources.put("annotationId", annotationID); 297 282 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); 301 286 } 302 287 ////////////////////////////////////////////////////////////////////////////////// 303 288 304 289 305 /////////////////// ///////////////////////////////////290 /////////////////// DELETERS ////////////////////////// 306 291 @Override 307 292 public int deleteAnnotation(Number annotationID) throws SQLException { … … 309 294 return 0; 310 295 } 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)); 314 299 } 315 300 … … 317 302 @Override 318 303 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 321 307 322 308 } … … 338 324 @Override 339 325 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 342 329 343 330 } … … 350 337 paramsPermissions.put("principalId", userID); 351 338 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); 354 342 return affectedPermissions; 355 343 } … … 362 350 return null; 363 351 } 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()); 367 355 } 368 356 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 49 49 public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID) { 50 50 51 String sql = "SELECT " + cachedRepresentationStar + " FROM " + cachedRepresentationTableName + " WHERE " + cached_representation_id + "= ? ";51 String sql = "SELECT " + cachedRepresentationStar + " FROM " + cachedRepresentationTableName + " WHERE " + cached_representation_id + "= ? LIMIT 1"; 52 52 List<CachedRepresentationInfo> result = getSimpleJdbcTemplate().query(sql, cachedRepresentationRowMapper, internalID); 53 53 54 if (result == null) {55 return null;56 }57 54 if (result.isEmpty()) { 58 55 return null; … … 65 62 CachedRepresentationInfo result = new CachedRepresentationInfo(); 66 63 result.setMimeType(rs.getString(mime_type)); 67 result.setRef( rs.getString(external_id));64 result.setRef(externalIDtoURI(_serviceURI, rs.getString(external_id))); 68 65 result.setTool(rs.getString(tool)); 69 66 result.setType(rs.getString(type_)); … … 78 75 String sql = "SELECT " + version_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + cached_representation_id + "= ? LIMIT 1"; 79 76 List<Number> result = getSimpleJdbcTemplate().query(sql, versionIDRowMapper, cachedID); 80 if (result.size() > 0) { 81 return true; 82 } 83 return false; 77 return (!result.isEmpty()); 84 78 } 85 79 … … 89 83 @Override 90 84 public Number addCachedRepresentationInfo(CachedRepresentationInfo cached) { 91 92 85 UUID externalIdentifier = UUID.randomUUID(); 93 86 Map<String, Object> params = new HashMap<String, Object>(); … … 98 91 String sql = "INSERT INTO " + cachedRepresentationTableName + "(" + external_id + "," + mime_type + "," + tool + "," + type_ + " ) VALUES (:externalId, :mime_type, :tool, :type)"; 99 92 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 100 return getInternalID(externalIdentifier);93 return (affectedRows > 0 ? getInternalID(externalIdentifier) : null); 101 94 } 102 95 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3455 r3463 24 24 import eu.dasish.annotation.schema.NotebookInfo; 25 25 import eu.dasish.annotation.schema.ResourceREF; 26 import eu.dasish.annotation.schema.Version; 26 27 import java.sql.ResultSet; 27 28 import java.sql.SQLException; … … 57 58 } 58 59 60 //////////////////////////////////////////////// 59 61 @Override 60 62 public List<NotebookInfo> getNotebookInfos(UUID userID) { … … 62 64 return getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, userID.toString()); 63 65 } 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 86 67 private final RowMapper<NotebookInfo> notebookInfoRowMapper = new RowMapper<NotebookInfo>() { 87 68 @Override 88 69 public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 89 70 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))); 91 72 notebookInfo.setTitle(rs.getString(title)); 92 // notebookInfo.setRef(rs.getString("URI"));93 73 return notebookInfo; 94 74 } 95 75 }; 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>() { 97 86 @Override 98 87 public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException { … … 108 97 throw new SQLException(exception); 109 98 } 110 // notebook.setURI(rs.getString("URI_ID"));99 notebook.setURI(externalIDtoURI(_serviceURI,rs.getString("external_id"))); 111 100 notebook.setAnnotations(getAnnotations(rs.getInt(notebook_id))); 112 101 return notebook; 113 102 } 114 103 }; 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 115 122 116 123 // returns the number of affected annotations … … 152 159 return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID); 153 160 } 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 162 162 ////////////////////////////////////////////////// 163 163 /** … … 216 216 return null; 217 217 } 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"; 219 219 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); 227 221 } 228 222 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3461 r3463 203 203 204 204 205 protected String ext rnalIDtoURI(String serviceURI, String externalID) {205 protected String externalIDtoURI(String serviceURI, String externalID) { 206 206 if (_serviceURI != null) { 207 207 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 53 53 String sql = "SELECT " + sourceStar + "FROM " + sourceTableName + " WHERE " + source_id + " = ?"; 54 54 List<Source> result = getSimpleJdbcTemplate().query(sql, sourceRowMapper, internalID); 55 return result.get(0);55 return (!result.isEmpty() ? result.get(0) : null); 56 56 } 57 57 private final RowMapper<Source> sourceRowMapper = new RowMapper<Source>() { … … 61 61 XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp)); 62 62 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); 64 64 return result; 65 65 } catch (DatatypeConfigurationException e) { … … 75 75 public List<Number> retrieveVersionList(Number sourceID) { 76 76 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); 79 78 } 80 79 … … 92 91 String sourceIDs = makeListOfValues(sources); 93 92 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); 96 94 } 97 95 private final RowMapper<SourceInfo> SourceInfoRowMapper = new RowMapper<SourceInfo>() { 98 96 @Override 99 97 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)); 101 99 } 102 100 }; … … 108 106 StringBuilder sql = new StringBuilder("SELECT "); 109 107 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); 112 109 } 113 110 … … 123 120 String sqlVersions = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + "= ? LIMIT 1"; 124 121 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); 129 123 } 130 124 … … 135 129 @Override 136 130 public Number addSource(Source source) throws SQLException { 137 String externalID = source.getURI();131 UUID externalID = UUID.randomUUID(); 138 132 Map<String, Object> params = new HashMap<String, Object>(); 139 params.put("externalId", externalID );133 params.put("externalId", externalID.toString()); 140 134 params.put("linkUri", source.getLink()); 141 135 params.put("version", source.getVersion()); 142 136 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); 146 139 } 147 140 … … 164 157 } 165 158 String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? "; 166 int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 167 return result; 159 return getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 168 160 169 161 } … … 174 166 public int deleteAllSourceVersion(Number internalID) { 175 167 String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?"; 176 int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 177 return result; 168 return getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 178 169 179 170 } … … 183 174 184 175 185 private SourceInfo constructSourceInfo( UUID UUID, String link, String version) {176 private SourceInfo constructSourceInfo(String externalID, String link, String version) { 186 177 SourceInfo sourceInfo = new SourceInfo(); 187 sourceInfo.setRef( UUID.toString());178 sourceInfo.setRef(externalIDtoURI(_serviceURI,externalID)); 188 179 sourceInfo.setLink(link); 189 180 sourceInfo.setVersion(version); … … 191 182 } 192 183 193 private Source constructSource( UUID UUID, String link, String version, XMLGregorianCalendar xmlTimeStamp) {184 private Source constructSource(String externalID, String link, String version, XMLGregorianCalendar xmlTimeStamp) { 194 185 Source source = new Source(); 195 source.setURI( UUID.toString());186 source.setURI(externalIDtoURI(_serviceURI, externalID)); 196 187 source.setTimeSatmp(xmlTimeStamp); 197 188 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 49 49 String sql = "SELECT " + versionStar + " FROM " + versionTableName + " WHERE " + version_id + "= ? LIMIT 1"; 50 50 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); 55 52 } 56 53 private final RowMapper<Version> versionRowMapper = new RowMapper<Version>() { … … 61 58 //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 62 59 // TODO: attribute URI (external-id is missing) 63 result.setVersion( rs.getString("external_id"));60 result.setVersion(externalIDtoURI(_serviceURI, rs.getString(external_id))); 64 61 return result; 65 62 } … … 69 66 @Override 70 67 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); 74 70 } 75 71 … … 87 83 String sqlVersions = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ? LIMIT 1"; 88 84 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) ; 93 86 } 94 87 … … 108 101 String sql = "INSERT INTO " + versionTableName + "(" + external_id + "," + version + " ) VALUES (:externalId, :version)"; 109 102 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 110 return getInternalID(externalIdentifier);103 return (affectedRows>0 ? getInternalID(externalIdentifier) : null); 111 104 } 112 105 … … 130 123 } 131 124 String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?"; 132 int result = getSimpleJdbcTemplate().update(sql, internalID); 133 return result; 125 return getSimpleJdbcTemplate().update(sql, internalID); 134 126 135 127 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3461 r3463 106 106 annotIds.add(4); 107 107 108 jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 108 109 final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfos(annotIds); 109 110 assertEquals(3, annotationInfos.size()); … … 111 112 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(0).getHeadline()); 112 113 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()); 113 116 //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources()); 114 117 115 118 assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfos.get(1).getHeadline()); 116 119 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()); 117 122 //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources()); 118 123 119 124 assertEquals(TestBackendConstants._TEST_ANNOT_4_HEADLINE, annotationInfos.get(2).getHeadline()); 120 125 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()); 121 128 //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfos.get(2).getTargetSources()); 122 129 … … 142 149 annotIds.add(4); 143 150 151 jdbcAnnotationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 144 152 final List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds); 145 153 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()); 149 157 150 158 final List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>()); … … 188 196 assertEquals(null, annotaionNull); 189 197 //// 190 198 191 199 final Number testAnnotationID = 2; 192 200 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 81 81 System.out.println("getCachedRepresentationInfo"); 82 82 83 jdbcCachedRepresentationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 83 84 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()); 85 86 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType()); 86 87 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool()); 87 88 assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getType()); 89 assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef()); 88 90 } 89 91 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3455 r3463 83 83 84 84 ResourceREF testRef = new ResourceREF(); 85 testRef.setRef( "1");85 testRef.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_AID_1_); 86 86 final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRef}); 87 87 88 88 mockery.checking(new Expectations() { 89 89 { 90 exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contain sthe annotation 190 exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contain the annotation 1 91 91 will(returnValue(testResult)); 92 // necessary to set annotations reference lists in the notebook 92 93 } 93 94 }); 94 95 96 jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 95 97 final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(UUID.fromString(TestBackendConstants._TEST_UID_2_)); 96 98 … … 98 100 assertEquals(2, notebooks.size()); 99 101 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()); 101 103 assertNotNull(notebooks.get(0).getTimeStamp()); 102 104 assertEquals(year, notebooks.get(0).getTimeStamp().getYear()); … … 176 178 System.out.println("getAnnotationREFsOfNotebook"); 177 179 180 jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 178 181 // test One 179 setMockeryNotebookOne(); 182 setMockeryNotebookOne(); 180 183 List<ResourceREF> testList = jdbcNotebookDao.getAnnotationREFsOfNotebook(3); 181 184 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()); 184 187 185 188 // test Two … … 187 190 List<ResourceREF> testListTwo = jdbcNotebookDao.getAnnotationREFsOfNotebook(4); 188 191 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()); 190 193 191 194 // test Three "empty" … … 208 211 System.out.println("getAnnotations"); 209 212 213 jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 214 210 215 // test One 211 216 setMockeryNotebookOne(); 212 217 Annotations annotations = jdbcNotebookDao.getAnnotations(3); 213 218 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()); 216 221 217 222 // test Two … … 219 224 Annotations annotationsTwo = jdbcNotebookDao.getAnnotations(4); 220 225 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()); 222 227 223 228 // test Three "empty" list of annotations … … 242 247 System.out.println("test getNotebookInfo"); 243 248 249 jdbcNotebookDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 250 244 251 // test One 245 252 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()); 247 254 assertEquals(TestBackendConstants._TEST_NOTEBOOK_3_TITLE, info.getTitle()); 248 255 … … 305 312 private void setMockeryNotebookOne(){ 306 313 ResourceREF testRefOne = new ResourceREF(); 307 testRefOne.setRef( String.valueOf(2));314 testRefOne.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_2_EXT); 308 315 ResourceREF testRefTwo = new ResourceREF(); 309 testRefTwo.setRef( String.valueOf(3));316 testRefTwo.setRef(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_3_EXT); 310 317 final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRefOne, testRefTwo}); 311 318 … … 320 327 private void setMockeryNotebookTwo(){ 321 328 ResourceREF testRef = new ResourceREF(); 322 testRef.setRef(String.valueOf( 4));329 testRef.setRef(String.valueOf(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_ANNOT_4_EXT)); 323 330 final List<ResourceREF> testResultTwo = Arrays.asList(new ResourceREF[] {testRef}); 324 331 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java
r3455 r3463 73 73 System.out.println("getSource"); 74 74 Number internalID = 1; 75 jdbcSourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 75 76 Source result = jdbcSourceDao.getSource(internalID); 76 assertEquals(TestBackendConstants._TEST_S OURCE_1_EXT_ID, result.getURI());77 assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_SOURCE_1_EXT_ID, result.getURI()); 77 78 assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.getLink()); 78 79 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 80 82 } 81 83 … … 128 130 freshSource.setLink(link); 129 131 freshSource.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 130 freshSource.setURI((UUID.randomUUID()).toString());131 132 freshSource.setTimeSatmp(null); 132 133 … … 137 138 assertEquals(link, addedSource.getLink()); 138 139 assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, addedSource.getVersion()); 139 assert Equals(freshSource.getURI(), addedSource.getURI());140 assertTrue(addedSource.getURI().startsWith(TestBackendConstants._TEST_SERVLET_URI)); 140 141 } 141 142 … … 145 146 @Test 146 147 public void testGetSourceInfos() { 147 System.out.println("getSourceInfos"); 148 System.out.println("getSourceInfos"); 149 jdbcSourceDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 148 150 List<Number> test = new ArrayList<Number>(); 149 151 test.add(1); … … 151 153 List<SourceInfo> result = jdbcSourceDao.getSourceInfos(test); 152 154 assertEquals(2, result.size()); 153 assertEquals(TestBackendConstants._TEST_S OURCE_1_EXT_ID, result.get(0).getRef());154 assertEquals(TestBackendConstants._TEST_S OURCE_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()); 155 157 assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.get(0).getVersion()); 156 158 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 70 70 @Test 71 71 public void testGetVersion() { 72 System.out.println("getVersion"); 72 System.out.println("getVersion"); 73 jdbcVersionDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); 73 74 Number internalID = 1; 75 74 76 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()); 76 78 //TODO: once the schems is fixed, test "version" and "URI/external-id" separately 77 79 // 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 64 64 System.out.println("getNotebookInfo"); 65 65 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 67 69 68 70 mockery.checking(new Expectations() { … … 89 91 }); 90 92 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); 92 95 List result = notebookResource.getUsersNotebooks(httpServletRequest); 93 96 assertEquals(0, result.size()); … … 101 104 System.out.println("createNotebook"); 102 105 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 104 109 mockery.checking(new Expectations() { 105 110 {
Note: See TracChangeset
for help on using the changeset viewer.