Changeset 3365
- Timestamp:
- 08/12/13 16:25:10 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/BackendConstants.java
r3221 r3365 31 31 public static final int USER_HASH_PARAM_1 = 5; 32 32 public static final int USER_HASH_PARAM_2 = 19; 33 34 33 // peter, is it okay? 35 34 public static final int SOURCE_HASH_PARAM_1 = 7; … … 41 40 42 41 public static final String regExpIdentifier = "[a-zA-Z0-9_-]*"; 42 43 43 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3345 r3365 19 19 20 20 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 21 import eu.dasish.annotation.backend.identifiers. SourceIdentifier;21 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 22 import eu.dasish.annotation.schema.Annotation; 23 23 import eu.dasish.annotation.schema.AnnotationInfo; 24 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;25 24 import eu.dasish.annotation.schema.ResourceREF; 26 25 import java.sql.SQLException; 26 import java.sql.Timestamp; 27 27 import java.util.List; 28 28 … … 73 73 public Annotation addAnnotation(Annotation annotation, Number ownerID) throws SQLException; 74 74 75 76 /** 77 * 78 * @param link optional 79 * @param text optional 80 * @param access optional 81 * @param namespace optional TODO: do not know what to do with it 82 * @param owner optional 83 * @param after optional 84 * @param before optional 85 * @return the list of internal annotation identifiers for annotations 86 * -- referring to the "link", 87 * -- bodies of which contain the "text", 88 * -- to which inlogged user has "access", 89 * -- owned by "owner", 90 * -- added to the database between "before" and "after" time-dates. 91 */ 92 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before); 93 75 94 76 77 95 /** 96 * 97 * @param annotationIDs 98 * @return the list of annotationInfos (owner, headline, target sources, external_id) for the internal Ids from the input list 99 * used on the second step for for GET api/annotations?<filters> 100 */ 78 101 public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs); 79 102 80 103 81 104 82 public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); 105 public List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); 106 107 108 83 109 84 110 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3348 r3365 108 108 public Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException; 109 109 110 110 /** 111 * 112 * @param link 113 * @return the list source ID's which link-fields contain "link" as a substring 114 */ 115 public List<Number> getSourcesForLink(String link); 111 116 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3364 r3365 25 25 import eu.dasish.annotation.backend.dao.UserDao; 26 26 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 27 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 27 28 import eu.dasish.annotation.schema.Annotation; 28 29 import eu.dasish.annotation.schema.AnnotationBody; … … 35 36 import java.sql.ResultSet; 36 37 import java.sql.SQLException; 38 import java.sql.Timestamp; 37 39 import java.util.ArrayList; 38 40 import java.util.HashMap; … … 67 69 } 68 70 69 //////////////////////////////////////////////////////////////////////////// 70 /** 71 * 72 * @param annotationIDs is a list of internal annotation identifiers 73 * @return the list of the corresponding annotation-infos for the annotation 74 * identifiers from the list; if the input list is null return null if the 75 * input list is empty (zero elements) returns an empty list 76 */ 71 @Override 72 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 73 74 String sql = "SELECT " + annotation_id + " FROM " + annotationTableName; 75 boolean firstClauseIsBuild = false; 76 //TODO: optimize List<Object> params = new ArrayList<Object>(); 77 //TODO: optimizie String builder 78 79 80 81 if (owner != null) { 82 sql = sql + " WHERE " + principal_id + "=:owner" + jdbcUserDao.getInternalID(owner); 83 firstClauseIsBuild = true; 84 } 85 86 87 88 if (after != null) { 89 if (firstClauseIsBuild) { 90 sql = sql + " AND " + time_stamp + " > " + after.toString(); 91 } else { 92 sql = sql + " WHERE " + time_stamp + " > " + after.toString(); 93 firstClauseIsBuild = true; 94 } 95 } 96 97 if (before != null) { 98 if (firstClauseIsBuild) { 99 sql = sql + " AND " + time_stamp + " < " + before.toString(); 100 } else { 101 sql = sql + " WHERE " + time_stamp + " < " + before.toString(); 102 firstClauseIsBuild = true; 103 } 104 } 105 106 if (text != null) { 107 if (firstClauseIsBuild) { 108 sql = sql + " AND " + body_xml + " LIKE '%" + text + "%'"; 109 } else { 110 sql = sql + " WHERE " + body_xml + " LIKE '%" + text + "%'"; 111 firstClauseIsBuild = true; 112 } 113 } 114 115 if (link != null) { 116 List<Number> sourceIDs = jdbcSourceDao.getSourcesForLink(link); 117 if (!sourceIDs.isEmpty()) { 118 String values = makeListOfValues(sourceIDs); 119 if (firstClauseIsBuild) { 120 sql = sql + " AND " + source_id + " IN " + values; 121 } 122 else { 123 sql = sql + " WHERE " + source_id + " IN " + values; 124 firstClauseIsBuild = true; 125 } 126 } 127 } 128 129 130 List<Number> result = getSimpleJdbcTemplate().query(sql, internalIDRowMapper); 131 return result; 132 } 133 77 134 @Override 78 135 public List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) { … … 197 254 int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationId); 198 255 199 256 String sqlPermissions = "DELETE FROM " + permissionsTableName + " where " + annotation_id + " = ?"; 200 257 int affectedPermissions = getSimpleJdbcTemplate().update(sqlPermissions, annotationId); 201 258 202 259 // safe removing sources 203 260 List<Number> sourceIDs = jdbcSourceDao.retrieveSourceIDs(annotationId); … … 205 262 int affectedAnnotationsSources = getSimpleJdbcTemplate().update(sqlTargetSources, annotationId); 206 263 int affectedSources; 207 for (Number sourceID : sourceIDs) { 208 // call the method in sources DAO that handles removal of a source which is not refered by other annotations264 for (Number sourceID : sourceIDs) { 265 // call the method in sources DAO that handles removal of a source which is not refered by other annotations 209 266 affectedSources = jdbcSourceDao.deleteSource(sourceID); 210 267 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3364 r3365 223 223 224 224 225 225 226 226 227 227 … … 258 258 } 259 259 260 261 260 @Override 261 public List<Number> getSourcesForLink(String link){ 262 String sql = "SELECT "+source_id+" FROM "+sourceTableName+ "WHERE "+link_uri+" LIKE '%"+link+"%'"; 263 List<Number> result = getSimpleJdbcTemplate().query(sql, internalIDRowMapper); 264 return result; 265 } 262 266 263 267 //////// HELPERS //////////////////////
Note: See TracChangeset
for help on using the changeset viewer.