Changeset 3395
- Timestamp:
- 08/15/13 17:00:50 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r3364 r3395 18 18 package eu.dasish.annotation.backend; 19 19 20 import eu.dasish.annotation.schema.AnnotationBody; 20 21 import java.sql.Timestamp; 21 22 import java.util.GregorianCalendar; 23 import java.util.Map; 22 24 import javax.xml.datatype.DatatypeConfigurationException; 23 25 import javax.xml.datatype.DatatypeFactory; … … 35 37 return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); 36 38 } 39 40 41 // TODO: change when serialization mechanism for bodies is fixed 42 public static String serializeBody(AnnotationBody body) { 43 return body.getAny().get(0).toString(); 44 } 45 46 // TODO: change when serialization mechanism for bodies is fixed 47 public static AnnotationBody deserializeBody(String bodyXml) { 48 AnnotationBody result = new AnnotationBody(); 49 result.getAny().add(bodyXml); 50 return result; 51 } 52 53 54 public static String replace(String text, Map<String, String> pairs) { 55 String result = (new StringBuilder(text)).toString(); 56 for (String tempSource : pairs.keySet()) { 57 result = result.replaceAll(tempSource, pairs.get(tempSource)); 58 } 59 return result; 60 } 61 37 62 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3380 r3395 24 24 import eu.dasish.annotation.schema.AnnotationInfo; 25 25 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 26 import eu.dasish.annotation.schema.NewSourceInfo; 26 27 import eu.dasish.annotation.schema.ResourceREF; 27 28 import java.sql.SQLException; … … 121 122 * @return the list of annotationdIDs of the annotations that are having target sources from "sourceIDs" list 122 123 */ 123 public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs);124 public List<Number> retrieveAnnotationList(List<Number> sourceIDs); 124 125 125 126 … … 134 135 public List<Number> retrieveSourceIDs(Number annotationID); 135 136 136 /** 137 * 138 * @param body 139 * @return serialized body 140 */ 141 //NOT TESTED, will be changed after serialization is fixed 142 public String serializeBody(AnnotationBody body); 137 143 138 144 /**145 *146 * @param bodyXml147 * @return deserialized body148 */149 // NOT TESTED will be chnaged after serializaion is fixed150 public AnnotationBody deserializeBody(String bodyXml);151 152 /**153 *154 * @param serializedBody155 * @param sourcePairs156 * @return replaces temporary source IDs with persistent ones (after they are added)157 */158 159 //NOT TESTED160 public String updateTargetRefsInBody(String serializedBody, Map<String, String> sourceIDPairs);161 139 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/CachedRepresentationDao.java
r3380 r3395 20 20 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 21 21 import eu.dasish.annotation.schema.CachedRepresentationInfo; 22 import java.util.List;23 22 24 23 /** … … 34 33 */ 35 34 public CachedRepresentationIdentifier getExternalID(Number internalID); 35 36 37 /** 38 * 39 * @param externalID 40 * @return the internal identifier of the resource with the "externalID" 41 */ 42 public Number getInternalID(CachedRepresentationIdentifier externalID); 43 36 44 37 45 /** 38 46 * 39 47 * @param internalID 40 * @return the object "c ached representation info" with the internal id "internalID"48 * @return the object "cCachedRepresentationInfo" with the internal id "internalID" 41 49 */ 42 50 public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); 43 51 44 /** 45 * 46 * @param versionID 47 * @return The list list of cached representation internal id-s of all the cached representations of the version with versionID 48 */ 49 public List<Number> retrieveCachedRepresentationList(Number versionID); 50 51 52 52 53 /** 53 54 * 54 55 * @param internalID 55 * removes the cached representation with internalId from the DB if there is no reference to it in the table "versions_cached_representations" 56 * @return the amount of removed rows in the table "cached_representation" 56 * @return # deleted rows on the table "cached_representation" 57 57 */ 58 public int deleteCachedRepresentationInfo(Number internalID);58 public int deleteCachedRepresentationInfo(Number internalID); 59 59 60 60 /** … … 66 66 67 67 68 /** 69 * 70 * @param versionID 71 * @param cached 72 * @return result[0] = the internalId of the added (if it is not yet in th DB) cached representation 73 * result[1] # added rows to "versions_cached_representations" 74 */ 75 public Number[] addCachedForVersion(Number versionID, CachedRepresentationInfo cached); 68 76 77 78 /** 79 * 80 * @param versionID 81 * @param cachedID 82 * @return result[0] # deleted rows (versionID, cachedID) in the table "versions_cached_representations" 83 * result[1] # deleted rows in the table "cached_representation" 84 */ 85 public int[] deleteCachedForVersion(Number versionID, Number cachedID); 86 69 87 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/SourceDao.java
r3380 r3395 21 21 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 22 22 import eu.dasish.annotation.schema.NewOrExistingSourceInfos; 23 import eu.dasish.annotation.schema.NewSourceInfo; 23 24 import eu.dasish.annotation.schema.Source; 24 25 import eu.dasish.annotation.schema.SourceInfo; … … 49 50 public Source getSource(Number internalID); 50 51 51 /** 52 * 53 * @param internalID 54 * @return the map "colum name" --> vale for the source form the DB 55 */ 56 public Map<String, Object> getRawSource(Number internalID); 52 57 53 58 54 /** … … 62 58 * @return the amount of affected rows in the "source" table 63 59 */ 64 public int deleteSource(Number internalID);60 public int[] deleteSource(Number internalID); 65 61 66 62 /** … … 71 67 * return -1 id the source cannot be added because its version is not in the DB 72 68 */ 73 public Number addSource(Source freshSource) throws SQLException; 74 75 ////////////////////////////////////////////// 69 public Number addSource(Source freshSource) throws SQLException; 76 70 77 /** 71 72 /** 78 73 * 79 * @param annotationID80 * @return the Information about the target sources to which annotationId refers74 * @param sourceID 75 * @return the list of the internal version id-s for the target source with the internal Id "sourceID" 81 76 */ 77 public List<Number> retrieveVersionList(Number sourceID); 78 79 82 80 public List<SourceInfo> getSourceInfos(List<Number> sources); 83 81 84 /** 85 * 86 * @param sourceInfoList 87 * @return the list of NewOrExistingSourceo objects in such a way that an element of the sourceInfoList is injected into an element of the return list 88 */ 89 //TODO: add non-existing sources!! now is implemented only for existing sources 90 public NewOrExistingSourceInfos contructNewOrExistingSourceInfo(List<SourceInfo> sourceInfoList); 91 92 93 94 /** 95 * 96 * @param sourceID 97 * @return delete all the rows in "sources_versions" table with sourceID 98 */ 99 public int deleteSourceVersionRows(Number sourceID); 100 101 102 /** 103 * 104 * @param annotationID 105 * @param sources 106 * @return the mapping of a (temporary source ID onto the corresponding same source persisten ID in the DB. 107 * The side-effect: the joint table "annotations_target_sources" is extended by the pairs (annotationID, addedSoiurceID). 108 * Also: calls "addSource" if the source is not yet in the DB. 109 */ 110 public Map<String, String> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException; 111 82 112 83 /** 113 84 * … … 116 87 */ 117 88 public List<Number> getSourcesForLink(String link); 89 90 91 92 public Map<String, String> addTargetSourcesToAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException; 93 94 118 95 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/VersionDao.java
r3380 r3395 19 19 20 20 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 21 import eu.dasish.annotation.schema.CachedRepresentationInfo; 21 22 import eu.dasish.annotation.schema.Version; 22 23 import java.util.List; … … 36 37 public VersionIdentifier getExternalID(Number internalID); 37 38 39 /** 40 * 41 * @param externalID 42 * @return the internal Id of the Version with the external ID "externalID" 43 */ 44 public Number getInternalID(VersionIdentifier externalID); 45 38 46 39 47 /** 40 48 * 41 49 * @param internalID 42 * @return the instance of Version.class w here the version internal Id is"internalID"50 * @return the instance of Version.class with the internal Id equal to "internalID" 43 51 * 44 52 */ 45 53 public Version getVersion(Number internalID); 46 54 47 /** 48 * 49 * @param sourceID 50 * @return the list of the internal version id-s for the target source with the internal Id "sourceID" 51 */ 52 public List<Number> retrieveVersionList(Number sourceID); 53 55 54 56 55 57 /** @param versionID 56 * removes the row of "version" with the internal ID "internalID" if no references to this version from the tables "sources_versions" and "source" 57 * @return the amount of removed rows 58 * @return result[0] # deleted rows in the joint table "sources_versions" 59 * result[1] # deleted rows in the joit table "versions_cached_representations" 60 * result[2] # deleted rows in "version" table 61 * result[3] # deleted cached representations (which are not referred by other versions) 58 62 */ 59 63 60 public int deleteVersion(Number versionID);64 public int[] deleteVersion(Number versionID); 61 65 62 66 /** … … 68 72 public Number addVersion(Version version); 69 73 70 /** 74 75 76 77 /** 71 78 * 72 79 * @param versionID 73 * @return removes the rows (versionID, some cached representation id) from the joint table "versions_cached_representations"80 * @return The list of the cached representation internal id-s of all the cached representations of the version with "versionID" 74 81 */ 75 public int deleteVersionCachedRepresentationRow(Number versionID);82 public List<Number> retrieveCachedRepresentationList(Number versionID); 76 83 77 78 /**79 *80 * @param sourceID81 * @param cachedRepresentationID82 * @return83 * 1) the amount of rows affected by deleting cached representation "cachedRepresentationID"84 * from the table "versions_cached_representations", if the corresponding version is a sibling-version of the source surceID85 * 2) the amount of rows affected by SAFE removing cachedRepresentationID from cached_representation table,86 * if the first number>087 *88 * used to fulfill DELETE api/sources/<sid>/cached/<cid>89 */90 public int[] deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID);91 92 public Number getInternalID(VersionIdentifier externalID);93 84 } 94 85 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3380 r3395 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.SourceIdentifier; 27 28 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 28 29 import eu.dasish.annotation.schema.Annotation; … … 33 34 import eu.dasish.annotation.schema.NewSourceInfo; 34 35 import eu.dasish.annotation.schema.ResourceREF; 36 import eu.dasish.annotation.schema.Source; 35 37 import eu.dasish.annotation.schema.SourceInfo; 38 import java.lang.String; 36 39 import java.sql.ResultSet; 37 40 import java.sql.SQLException; … … 44 47 import javax.xml.datatype.DatatypeConfigurationException; 45 48 import org.springframework.beans.factory.annotation.Autowired; 46 import org.springframework.dao.DataAccessException;47 49 import org.springframework.jdbc.core.RowMapper; 48 50 … … 72 74 public List<Number> retrieveSourceIDs(Number annotationID) { 73 75 String sql = "SELECT " + source_id + " FROM " + annotationsSourcesTableName + " WHERE " + annotation_id + "= ?"; 74 List<Number> result = getSimpleJdbcTemplate().query(sql, annotationSourceRowMapper, annotationID);75 return result; 76 } 77 private final RowMapper<Number> annotationSourceRowMapper = new RowMapper<Number>() {76 List<Number> result = getSimpleJdbcTemplate().query(sql, sourceIDRowMapper, annotationID); 77 return result; 78 } 79 private final RowMapper<Number> sourceIDRowMapper = new RowMapper<Number>() { 78 80 @Override 79 81 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { … … 83 85 }; 84 86 87 //////////////////////////////////////////////////////////////////////// 85 88 @Override 86 89 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { … … 92 95 if (link != null) { 93 96 List<Number> sourceIDs = jdbcSourceDao.getSourcesForLink(link); 94 List<Number> annotationIDs = getAnnotationIDsForSources(sourceIDs);97 List<Number> annotationIDs = retrieveAnnotationList(sourceIDs); 95 98 if (!annotationIDs.isEmpty()) { 96 99 String values = makeListOfValues(annotationIDs); … … 129 132 ////////////////////////////// 130 133 @Override 131 public List<Number> getAnnotationIDsForSources(List<Number> sourceIDs) {134 public List<Number> retrieveAnnotationList(List<Number> sourceIDs) { 132 135 if (sourceIDs == null) { 133 136 return null; … … 230 233 result.setHeadline(rs.getString(headline)); 231 234 232 result.setBody( deserializeBody(rs.getString(body_xml)));235 result.setBody(Helpers.deserializeBody(rs.getString(body_xml))); 233 236 234 237 List<SourceInfo> sourceInfoList = jdbcSourceDao.getSourceInfos(retrieveSourceIDs(rs.getInt(annotation_id))); 235 NewOrExistingSourceInfos noeSourceInfos = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);238 NewOrExistingSourceInfos noeSourceInfos = contructNewOrExistingSourceInfo(sourceInfoList); 236 239 result.setTargetSources(noeSourceInfos); 237 240 … … 267 270 result[3] = 0; //removed "target_source" rows 268 271 for (Number sourceID : sourceIDs) { 269 result[3] = result[3] + jdbcSourceDao.deleteSource(sourceID); 272 int[] deleteSource = jdbcSourceDao.deleteSource(sourceID); 273 result[3] = result[3] + deleteSource[1]; 270 274 } 271 275 … … 313 317 sql.append(annotationTableName).append(" SET ").append(body_xml).append("= ").append(serializedNewBody).append(" WHERE ").append(annotation_id).append("= ?"); 314 318 return getSimpleJdbcTemplate().update(sql.toString(), annotationID); 315 }316 317 //////////// helpers ///////////////////////318 /////////////////////////////////////////////////319 // TODO: change when serialization mechanism for bodies is fixed320 @Override321 public String serializeBody(AnnotationBody body) {322 return body.getAny().get(0).toString();323 }324 325 // TODO: change when serialization mechanism for bodies is fixed326 @Override327 public AnnotationBody deserializeBody(String bodyXml) {328 AnnotationBody result = new AnnotationBody();329 result.getAny().add(bodyXml);330 return result;331 }332 333 ///////////////////////////////////////334 @Override335 public String updateTargetRefsInBody(String serializedBody, Map<String, String> sourceIDPairs) {336 String result = (new StringBuilder(serializedBody)).toString();337 for (String tempSource : sourceIDPairs.keySet()) {338 result = result.replaceAll(tempSource, sourceIDPairs.get(tempSource));339 }340 return result;341 319 } 342 320 … … 357 335 public Map<String, Object> getRawAnnotation(Number annotationID) throws SQLException { 358 336 359 360 337 if (annotationID == null) { 361 338 return null; … … 385 362 } 386 363 }; 364 365 366 /////////////// helpers ////////////////// 367 368 public NewOrExistingSourceInfos contructNewOrExistingSourceInfo(List<SourceInfo> sourceInfoList) { 369 List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>(); 370 for (SourceInfo sourceInfo : sourceInfoList) { 371 NewOrExistingSourceInfo noeSourceInfo = new NewOrExistingSourceInfo(); 372 noeSourceInfo.setSource(sourceInfo); 373 noeSourceInfoList.add(noeSourceInfo); 374 } 375 NewOrExistingSourceInfos result = new NewOrExistingSourceInfos(); 376 result.getTarget().addAll(noeSourceInfoList); 377 return result; 378 } 379 387 380 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3380 r3395 19 19 20 20 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 21 import eu.dasish.annotation.backend.dao.VersionDao; 21 22 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 22 23 import eu.dasish.annotation.schema.CachedRepresentationInfo; … … 27 28 import java.util.Map; 28 29 import javax.sql.DataSource; 30 import org.springframework.beans.factory.annotation.Autowired; 29 31 import org.springframework.jdbc.core.RowMapper; 30 32 … … 34 36 */ 35 37 public class JdbcCachedRepresentationDao extends JdbcResourceDao implements CachedRepresentationDao { 36 38 39 @Autowired 40 VersionDao jdbcVersionDao; 41 37 42 public JdbcCachedRepresentationDao(DataSource dataSource) { 38 43 setDataSource(dataSource); … … 46 51 return new CachedRepresentationIdentifier(super.getExternalIdentifier(internalID)); 47 52 } 53 54 ////////////////////////////////////////////////////////////////////////////////////////////////////// 55 @Override 56 public Number getInternalID(CachedRepresentationIdentifier externalID) { 57 return super.getInternalID(externalID); 58 } 48 59 60 61 /////////////////////////////////////////////////////////////////////////////////////// 49 62 @Override 50 63 public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID) { … … 65 78 public CachedRepresentationInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 66 79 CachedRepresentationInfo result = new CachedRepresentationInfo(); 67 //external_id, mime_type, tool, type_, where_is_the_file68 80 result.setMimeType(rs.getString(mime_type)); 69 81 result.setRef(rs.getString(external_id)); … … 76 88 77 89 //////////////////////////////////////////////////////////////////////////// 78 @Override79 public List<Number> retrieveCachedRepresentationList(Number versionID) {80 String sql = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ?";81 List<Number> result = getSimpleJdbcTemplate().query(sql, internalIDRowMapper, versionID);82 83 if (result == null) {84 return null;85 }86 if (result.isEmpty()) {87 return null;88 }89 return result;90 }91 92 ;93 94 ////////////////////////////////////////////////////////////////////////////95 90 @Override 96 91 public Number addCachedRepresentationInfo(CachedRepresentationInfo cached) { … … 111 106 @Override 112 107 public int deleteCachedRepresentationInfo(Number internalID) { 113 //check if there are versions referring to the cached with the "internalID" 114 String sqlCheck = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + cached_representation_id + "= ?"; 115 List<Number> result = getSimpleJdbcTemplate().query(sqlCheck, cachedRepresentationCheckerRowMapper, internalID); 108 109 // ask the higher level if it can be deleted 110 if (cachedIsInUse(internalID)){ 111 return 0; 112 } 113 114 String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?"; 115 return getSimpleJdbcTemplate().update(sql, internalID); 116 } 117 118 //////////////////////////////////////////////// 119 @Override 120 public Number[] addCachedForVersion(Number versionID, CachedRepresentationInfo cached){ 121 Number[] result = new Number[2]; 122 result[0] = getInternalID(new CachedRepresentationIdentifier(cached.getRef())); 123 if (result[0] == null) { 124 result[0] = addCachedRepresentationInfo(cached); 125 } 126 Map<String, Object> params = new HashMap<String, Object>(); 127 params.put("versionId", versionID); 128 params.put("cachedId", result[0]); 129 String sql = "INSERT INTO " + versionsCachedRepresentationsTableName + "(" + version_id + "," + cached_representation_id + " ) VALUES (:versionId, :cachedId)"; 130 result[1] = getSimpleJdbcTemplate().update(sql, params); 131 return result; 132 } 133 134 ////////////////////////////// 135 136 @Override 137 public int[] deleteCachedForVersion(Number versionID, Number cachedID){ 138 int[] result = new int[2]; 139 Map<String, Object> params = new HashMap<String, Object>(); 140 params.put("versionId", versionID); 141 params.put("cachedId", cachedID); 142 String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + " = :versionId AND " + cached_representation_id + "= :cachedId"; 143 result[0] = getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, params); 144 145 if (result[0] > 0) { 146 result[1] = deleteCachedRepresentationInfo(cachedID); 147 } 148 else { 149 result[1]=0; 150 151 } 152 return result; 153 } 154 155 ////////////////////////////// 116 156 117 if (result.isEmpty()) { 118 // you can remove the cached representation 119 String sql = "DELETE FROM " + cachedRepresentationTableName + " where " + cached_representation_id + " = ?"; 120 return getSimpleJdbcTemplate().update(sql, internalID); 121 } else { 122 // do not delete, it is in use!! 123 return 0; 157 private boolean cachedIsInUse(Number cachedID) { 158 String sql = "SELECT " + version_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + cached_representation_id + "= ? LIMIT 1"; 159 List<Number> result = getSimpleJdbcTemplate().query(sql, versionIDRowMapper, cachedID); 160 if (result.size() > 0) { 161 return true; 124 162 } 163 return false; 125 164 } 126 private final RowMapper<Number> cachedRepresentationCheckerRowMapper = new RowMapper<Number>() { 165 166 private final RowMapper<Number> versionIDRowMapper = new RowMapper<Number>() { 127 167 @Override 128 168 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 129 Number result = rs.getInt(cached_representation_id); 130 return result; 169 return rs.getInt(version_id); 131 170 } 132 171 }; 133 172 173 134 174 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3380 r3395 134 134 return (sqlResult.get(0)); 135 135 } 136 136 137 protected final RowMapper<String> externalIDRowMapper = new RowMapper<String>() { 137 138 @Override -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3380 r3395 61 61 } 62 62 63 63 /////////////////////////////////////////////////////////////////////////////// 64 64 @Override 65 65 public Source getSource(Number internalID) { … … 77 77 return result; 78 78 } catch (DatatypeConfigurationException e) { 79 // TODO: wh at logger are we going to use80 System.out.println("Cannot construct time stam : probably worng date/time format");79 // TODO: which logger are we going to use? 80 System.out.println("Cannot construct time stamp: probably worng date/time format"); 81 81 return null; 82 82 } 83 83 } 84 84 }; 85 86 /////////////////////////////////////////////////////////////////////////////// 87 @Override 88 public Map<String, Object> getRawSource(Number internalID) { 89 String sql = "SELECT " + sourceStar + "FROM " + sourceTableName + " WHERE " + source_id + " = ?"; 90 List<Map<String, Object>> result = getSimpleJdbcTemplate().query(sql, rawSourceRowMapper, internalID); 91 return result.get(0); 92 } 93 private final RowMapper<Map<String, Object>> rawSourceRowMapper = new RowMapper<Map<String, Object>>() { 94 @Override 95 public Map<String, Object> mapRow(ResultSet rs, int rowNumber) throws SQLException { 96 Map<String, Object> result = new HashMap<String, Object>(); 97 result.put(external_id, rs.getString(external_id)); 98 result.put(link_uri, rs.getString(link_uri)); 99 result.put(version_id, rs.getInt(version_id)); 100 return result; 101 } 102 }; 103 85 86 104 87 /////////////////////////////////////////////////////////////////// 105 88 @Override 106 public int deleteSource(Number internalID) { 107 108 // check if there are annotations referring to the source with "internalID", in the table "annotations_sources" 109 String sqlAnnotationsSources = "SELECT " + annotation_id + " FROM " + annotationsSourcesTableName + " WHERE " + source_id + "= ?"; 110 List<Number> resultAnnotationsSources = getSimpleJdbcTemplate().query(sqlAnnotationsSources, annotationsSourcesRowMapper, internalID); 111 112 if (resultAnnotationsSources.isEmpty()) { 113 114 // You can remove the source! 115 116 // retrieve the list of versions of the source to be deleted 117 List<Number> versions = versionDao.retrieveVersionList(internalID); 118 119 // remove all the pairs (internalID, version_id) from the joint table 120 deleteSourceVersionRows(internalID); 121 // the main action: remove the source with internalID from "source" table 122 String sql = "DELETE FROM " + sourceTableName + " where " + source_id + " = ?"; 123 int affected_source_rows = getSimpleJdbcTemplate().update(sql, internalID); 124 125 // remove the versions of "versions" from the DB unless they are still mentioned in "sources_versions" 126 for (Number versionID : versions) { 127 versionDao.deleteVersion(versionID); 128 } 129 130 return (affected_source_rows); 131 } else { 132 // do not remove 133 return 0; 134 } 135 } 136 private final RowMapper<Number> annotationsSourcesRowMapper = new RowMapper<Number>() { 137 @Override 138 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 139 Number result = rs.getInt(annotation_id); 89 public int[] deleteSource(Number internalID) { 90 91 int[] result = new int[2]; 92 93 if (sourceIsInUse(internalID)){ 94 result[0] =0; 95 result[1] =0; 140 96 return result; 141 97 } 142 }; 98 99 List<Number> versions = retrieveVersionList(internalID); 100 String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?"; 101 result[0] = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID); 102 103 String sql = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ?"; 104 result[1] = getSimpleJdbcTemplate().update(sql, internalID); 105 106 for (Number versionID : versions) { 107 versionDao.deleteVersion(versionID); 108 } 109 110 return result; 111 112 } 143 113 144 114 /////////////////////////////////////////////////////////////////// 145 115 @Override 146 public Number addSource(Source freshSource) throws SQLException {147 116 public Number addSource(Source freshSource) throws SQLException { 117 148 118 SourceIdentifier externalIdentifier = new SourceIdentifier(); 149 119 Number versionID = versionDao.getInternalID(new VersionIdentifier(freshSource.getVersion())); 150 120 151 121 if (versionID == null) { 152 122 System.out.println("Cannot add source because there is no version for it, and no cached representation. Create them and try again."); … … 160 130 String sql = "INSERT INTO " + sourceTableName + "(" + external_id + "," + link_uri + "," + version_id + " ) VALUES (:externalId, :linkUri, :versionId)"; 161 131 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 162 163 132 133 164 134 Map<String, Object> paramsJoint = new HashMap<String, Object>(); 165 135 paramsJoint.put("sourceId", getInternalID(externalIdentifier)); 166 136 paramsJoint.put("versionId", versionID); 167 String sqlJoint = "INSERT INTO " + sourcesVersionsTableName + "(" + source_id + "," + version_id + " ) VALUES (:sourceId, :versionId)";137 String sqlJoint = "INSERT INTO " + sourcesVersionsTableName + "(" + source_id + "," + version_id + " ) VALUES (:sourceId, :versionId)"; 168 138 final int affectedJointRows = getSimpleJdbcTemplate().update(sqlJoint, paramsJoint); 169 170 171 return(getInternalID(externalIdentifier)); 172 } 173 174 //////////////////////////////////////////////////////////////// 139 140 141 return (getInternalID(externalIdentifier)); 142 } 143 144 ///////////////////////////////////////// 145 @Override 146 public List<Number> retrieveVersionList(Number sourceID) { 147 String sql = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?"; 148 List<Number> result = getSimpleJdbcTemplate().query(sql, versionsSourcesRunnerRowMapper, sourceID); 149 return result; 150 } 151 private final RowMapper<Number> versionsSourcesRunnerRowMapper = new RowMapper<Number>() { 152 @Override 153 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 154 Number result = rs.getInt(version_id); 155 return result; 156 } 157 }; 158 175 159 /////////////////////////////////////////////////////////////////// 176 160 @Override … … 182 166 return new ArrayList<SourceInfo>(); 183 167 } 184 168 185 169 String sourceIDs = makeListOfValues(sources); 186 170 String sql = "SELECT " + external_id + "," + link_uri + "," + version_id + " FROM " + sourceTableName + " WHERE " + source_id + " IN " + sourceIDs; … … 195 179 }; 196 180 197 ////////////////////////////////////////// 198 @Override 199 public NewOrExistingSourceInfos contructNewOrExistingSourceInfo(List<SourceInfo> sourceInfoList) { 200 List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>(); 201 for (SourceInfo sourceInfo : sourceInfoList) { 202 NewOrExistingSourceInfo noeSourceInfo = new NewOrExistingSourceInfo(); 203 noeSourceInfo.setSource(sourceInfo); 204 noeSourceInfoList.add(noeSourceInfo); 205 } 206 NewOrExistingSourceInfos result = new NewOrExistingSourceInfos(); 207 result.getTarget().addAll(noeSourceInfoList); 208 return result; 209 } 181 182 ///////////////////////////////////////////////////// 183 @Override 184 public List<Number> getSourcesForLink(String link) { 185 StringBuilder sql = new StringBuilder("SELECT "); 186 sql.append(source_id).append(" FROM ").append(sourceTableName).append(" WHERE ").append(link_uri).append(" LIKE '%").append(link).append("%'"); 187 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper); 188 return result; 189 } 190 191 /////////////////////////////////////////////// 192 @Override 193 public Map<String, String> addTargetSourcesToAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException { 194 Map<String, String> result = new HashMap<String, String>(); 195 for (NewOrExistingSourceInfo noesi : sources) { 196 SourceInfo source = noesi.getSource(); 197 if (source != null) { 198 int affectedRows = addAnnotationSourcePair(annotationID, getInternalID(new SourceIdentifier(source.getRef()))); 199 } else { 200 Number newSourceID = addNewSourceToAnnotation(annotationID, noesi.getNewSource()); 201 if (newSourceID.intValue() == -1) { 202 result.put(noesi.getNewSource().getId(), null); 203 } else { 204 result.put(noesi.getNewSource().getId(), getExternalID(newSourceID).toString()); 205 int affectedRows = addAnnotationSourcePair(annotationID, newSourceID); 206 } 207 } 208 } 209 return result; 210 } 211 212 //////////// helpers /////////////////////// 213 ///////////////////////////////////////////////// 210 214 215 ////////////////////////////// 216 private boolean sourceIsInUse(Number sourceID) { 217 String sql = "SELECT " + annotation_id + " FROM " + annotationsSourcesTableName + " WHERE " + source_id + "= ? LIMIT 1"; 218 List<Number> result = getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, sourceID); 219 if (result.size() > 0) { 220 return true; 221 } 222 return false; 223 } 211 224 225 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 226 @Override 227 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 228 return rs.getInt(annotation_id); 229 } 230 }; 212 231 213 214 ///////////////////////////////////////////////// 215 @Override 216 public int deleteSourceVersionRows(Number sourceID) { 217 // remove all the pairs (internalID, version_id) from the joint table 218 String sqlSourcesVersions = "DELETE FROM " + sourcesVersionsTableName + " where " + source_id + " = ?"; 219 return (getSimpleJdbcTemplate().update(sqlSourcesVersions, sourceID)); 220 221 } 222 223 224 225 226 227 //////////////////////////////////////////////////////////////////////// 228 @Override 229 public Map<String, String> addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException { 230 231 Map<String, String> result = new HashMap<String, String>(); 232 233 for (NewOrExistingSourceInfo noeSourceInfo : sources) { 234 SourceInfo sourceInfo = noeSourceInfo.getSource(); 235 if (sourceInfo != null) { 236 // this is an old source, already exists in the DB 237 addAnnotationSourcePair(annotationID, getInternalID(new SourceIdentifier(sourceInfo.getRef()))); 238 } else { 239 Source newSource = constructNewSource(noeSourceInfo.getNewSource()); 240 Number addedSourceID = addSource(newSource);// adding new source 241 int affectedRows = addAnnotationSourcePair(annotationID, addedSourceID); 242 result.put(noeSourceInfo.getNewSource().getId(), getExternalID(addedSourceID).toString()); 243 } 244 245 } 246 return result; 247 } 248 249 @Override 250 public List<Number> getSourcesForLink(String link){ 251 StringBuilder sql = new StringBuilder("SELECT "); 252 sql.append(source_id).append(" FROM ").append(sourceTableName).append(" WHERE ").append(link_uri).append(" LIKE '%").append(link).append("%'"); 253 List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper); 254 return result; 255 } 256 257 258 //////// HELPERS ////////////////////// 259 //////////////////////////////////////////////////////// 260 261 262 private int addAnnotationSourcePair(Number annotationID, Number sourceID) throws SQLException{ 263 // source is "old" i.e. exists in the DB, onlu the table annotations_target_sources should be updated 232 private int addAnnotationSourcePair(Number annotationID, Number sourceID) throws SQLException { 264 233 Map<String, Object> paramsAnnotationsSources = new HashMap<String, Object>(); 265 234 paramsAnnotationsSources.put("annotationId", annotationID); 266 paramsAnnotationsSources.put("sourceId", 235 paramsAnnotationsSources.put("sourceId", sourceID); 267 236 String sqlAnnotationsSources = "INSERT INTO " + annotationsSourcesTableName + "(" + annotation_id + "," + source_id + " ) VALUES (:annotationId, :sourceId)"; 268 237 int affectedRows = getSimpleJdbcTemplate().update(sqlAnnotationsSources, paramsAnnotationsSources); 269 if (affectedRows != 1) {270 throw (new SQLException("Cannot add annotation properly"));271 272 }273 238 return (affectedRows); 274 239 } 275 276 277 240 ////////////////////////////////////////////////////////////////////////////////// 241 242 private Number addNewSourceToAnnotation(Number annotationID, NewSourceInfo source) throws SQLException { 243 Source newSource = new Source(); 244 newSource.setLink(source.getLink()); 245 newSource.setVersion(source.getVersion()); 246 Number addedSourceID = addSource(newSource);// adding new source 247 if (addedSourceID.intValue() == -1) { 248 return -1; 249 } 250 int affectedRows = addAnnotationSourcePair(annotationID, addedSourceID); 251 return addedSourceID; 252 } 253 278 254 private SourceInfo constructSourceInfo(SourceIdentifier sourceIdentifier, String link, VersionIdentifier versionIdentifier) { 279 255 SourceInfo sourceInfo = new SourceInfo(); … … 284 260 } 285 261 286 ///////////////////287 private Source constructNewSource(NewSourceInfo newSourceInfo) {288 Source result = new Source();289 result.setLink(newSourceInfo.getLink());290 result.setVersion(newSourceInfo.getVersion());291 // source's internalID will be generated by the DB292 // source's time stamp will be generated by the DB293 // source's externalID will be generated by the add-source-dao294 return result;295 }296 297 298 262 private Source constructSource(SourceIdentifier sourceIdentifier, String link, VersionIdentifier version, XMLGregorianCalendar xmlTimeStamp) { 299 263 Source source = new Source(); … … 305 269 return source; 306 270 } 307 308 // TODO: make deep copy for source, otherwise testing will be unfair!!309 private Source makeFreshCopy(Source source) {310 Source result = new Source();311 result.setLink(source.getLink());312 result.setURI(source.getURI());313 result.setVersion(source.getVersion());314 result.setTimeSatmp(source.getTimeSatmp());315 //versions-siblings are mentioned in the table sources_versions316 return result;317 }318 319 320 271 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDao.java
r3380 r3395 20 20 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 21 21 import eu.dasish.annotation.backend.dao.VersionDao; 22 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 22 23 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 24 import eu.dasish.annotation.schema.CachedRepresentationInfo; 23 25 import eu.dasish.annotation.schema.Version; 24 26 import java.sql.ResultSet; … … 51 53 return new VersionIdentifier(super.getExternalIdentifier(internalID)); 52 54 } 53 54 55 56 ////////////////////////////////////////////////////////////////////////////////////////////////////// 55 57 @Override 56 58 public Number getInternalID(VersionIdentifier externalID) { 57 59 return (super.getInternalID(externalID)); 58 60 } 59 61 60 62 /////////////////////////////////////////////////////////////// 61 62 63 @Override 63 64 public Version getVersion(Number internalID) { 64 65 65 String sql = "SELECT " + versionStar + " FROM " + versionTableName + " WHERE " + version_id + "= ? ";66 String sql = "SELECT " + versionStar + " FROM " + versionTableName + " WHERE " + version_id + "= ? LIMIT 1"; 66 67 List<Version> result = getSimpleJdbcTemplate().query(sql, versionRowMapper, internalID); 67 68 … … 86 87 }; 87 88 88 ///////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////// 89 90 @Override 90 public List<Number> retrieveVersionList(Number sourceID) { 91 String sql = "SELECT " + version_id + " FROM " + sourcesVersionsTableName + " WHERE " + source_id + " = ?"; 92 List<Number> result = getSimpleJdbcTemplate().query(sql, versionsSourcesRunnerRowMapper, sourceID); 91 public List<Number> retrieveCachedRepresentationList(Number versionID) { 92 String sql = "SELECT " + cached_representation_id + " FROM " + versionsCachedRepresentationsTableName + " WHERE " + version_id + "= ?"; 93 List<Number> result = getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, versionID); 94 95 if (result == null) { 96 return null; 97 } 98 93 99 return result; 94 100 } 95 private final RowMapper<Number> versionsSourcesRunnerRowMapper = new RowMapper<Number>() { 101 102 private final RowMapper<Number> cachedIDRowMapper = new RowMapper<Number>() { 96 103 @Override 97 104 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 98 Number result = rs.getInt(version_id); 105 return rs.getInt(cached_representation_id); 106 } 107 }; 108 109 ///////////////////////////////////////// 110 @Override 111 public int[] deleteVersion(Number internalID) { 112 113 int[] result = new int[3]; 114 115 if (versionIsInUse(internalID)) { 116 // firs delete sources that refer to it! 117 result[0]=0; 118 result[1]=0; 119 result[2]=0; 99 120 return result; 100 121 } 101 }; 122 123 // retrieve the list of cached representations of the version to be deleted; 124 // they should be deleted if they are not used 125 // you will use it over the next 2 steps 126 List<Number> cachedRepresentations = retrieveCachedRepresentationList(internalID); 102 127 103 ///////////////////////////////////////// 104 @Override 105 public int deleteVersionCachedRepresentationRow(Number versionID) { 106 // remove all the pairs (internalID, cached_representation) from the joint table 128 // remove all the pairs (internalID, cached_representation) from the joint table "versions_cahched_representations" 107 129 String sqlVersionsCachedRepresentations = "DELETE FROM " + versionsCachedRepresentationsTableName + " where " + version_id + " = ?"; 108 return (getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, versionID)); 130 result[0] = getSimpleJdbcTemplate().update(sqlVersionsCachedRepresentations, internalID); 131 132 // the main action: remove the version with internalID from "version" table 133 String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?"; 134 result[1] = getSimpleJdbcTemplate().update(sql, internalID); 135 136 // remove the cached representations of "cachedRepresentations" from the DB unless they are still mentioned in "versions_cached_representations" 137 result[2]=0; 138 for (Number cachedID : cachedRepresentations) { 139 result[2]=result[2]+jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 140 141 } 142 return result; 143 109 144 } 110 111 /////////////////////////////////////////112 //TODO: refactor ???113 @Override114 public int deleteVersion(Number internalID) {115 116 // check if there are sources referring to the version with "internalID", in the table "sources"versions"117 String sqlSourcesVersions = "SELECT " + source_id + " FROM " + sourcesVersionsTableName + " WHERE " + version_id + "= ?";118 List<Number> resultSourcesVersions = getSimpleJdbcTemplate().query(sqlSourcesVersions, sourcesVersionsRowMapper, internalID);119 120 // check if there is a source referring to the version "intrenalID", in the table "source"121 String sqlSource = "SELECT " + source_id + " FROM " + sourceTableName + " WHERE " + version_id + "= ?";122 List<Number> resultSource = getSimpleJdbcTemplate().query(sqlSource, sourceRowMapper, internalID);123 124 125 if (resultSourcesVersions.isEmpty() && resultSource.isEmpty()) {126 127 // You can remove the version safely!!!128 129 // retrieve the list of cached representations of the version to be deleted130 List<Number> cachedRepresentations = jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);131 132 // remove all the pairs (internalID, cached_representation) from the joint table133 deleteVersionCachedRepresentationRow(internalID);134 135 // the main action: remove the version with internalID from "version" table136 String sql = "DELETE FROM " + versionTableName + " where " + version_id + " = ?";137 int affected_version_rows = getSimpleJdbcTemplate().update(sql, internalID);138 139 // remove the cached representations of "cachedRepresentations" from the DB unless they are still mentioned in "versions_cached_representations"140 for (Number cachedID : cachedRepresentations) {141 jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);142 }143 144 return (affected_version_rows);145 } else {146 // do not remove147 return 0;148 }149 }150 private final RowMapper<Number> sourcesVersionsRowMapper = new RowMapper<Number>() {151 @Override152 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {153 Number result = rs.getInt(source_id);154 return result;155 }156 };157 private final RowMapper<Number> sourceRowMapper = new RowMapper<Number>() {158 @Override159 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {160 Number result = rs.getInt(source_id);161 return result;162 }163 };164 145 165 146 ///////////////////////////////////////////////// … … 177 158 return getInternalID(externalIdentifier); 178 159 } 179 180 @Override181 public int[] deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID) {182 List<Number> versions = retrieveVersionList(sourceID);183 int[] result = new int[2];184 185 if (versions == null) {186 result[0] = 0;187 result[1] = 0;188 return result;160 161 162 163 164 ////////////////////////////// 165 private boolean versionIsInUse(Number versionsID) { 166 String sql = "SELECT " + source_id + " FROM " + sourcesVersionsTableName + " WHERE " + version_id + "= ? LIMIT 1"; 167 List<Number> result = getSimpleJdbcTemplate().query(sql, sourceIDRowMapper, versionsID); 168 if (result.size() > 0) { 169 return true; 189 170 } 190 if (versions.isEmpty()) { 191 result[0] = 0; 192 result[1] = 0; 193 return result; 171 return false; 172 } 173 174 private final RowMapper<Number> sourceIDRowMapper = new RowMapper<Number>() { 175 @Override 176 public Number mapRow(ResultSet rs, int rowNumber) throws SQLException { 177 return rs.getInt(source_id); 194 178 } 195 196 String values = makeListOfValues(versions); 197 StringBuilder sql = new StringBuilder("DELETE FROM "); 198 sql.append(versionsCachedRepresentationsTableName).append(" WHERE ").append(version_id).append(" IN ").append(values); 199 sql.append(" AND ").append(cached_representation_id).append(" = ?"); 200 result[0] = getSimpleJdbcTemplate().update(sql.toString(), cachedRepresentationID); 201 202 // safe remove from the DB 203 if (result[0] > 0) { 204 result[1] = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedRepresentationID); 205 } else { 206 result[1] = 0; 207 } 208 return result; 209 } 210 211 179 }; 212 180 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3380 r3395 19 19 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 import eu.dasish.annotation.backend.Helpers; 21 22 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 23 import eu.dasish.annotation.backend.dao.NotebookDao; … … 27 28 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 28 29 import eu.dasish.annotation.schema.Annotation; 30 import eu.dasish.annotation.schema.AnnotationBody; 29 31 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 30 32 import eu.dasish.annotation.schema.ObjectFactory; … … 115 117 } 116 118 119 120 //Add annotation 117 121 Number annotationID = annotationDao.addAnnotation(annotation, userID); 118 122 119 // adding sources to the DB if necessary and updating the joint table annotations_target_sources 120 // also, since the source id-s can bementioned in the body, update the body as well 121 // Note that client provided serialization "NewOrExistingSourceInfo" (of type choice) allows to switch between 122 // new and existing sources 123 //Add the sources to the DB 123 124 List<NewOrExistingSourceInfo> sources = annotation.getTargetSources().getTarget(); 124 Map<String, String> sourcePairs = sourceDao.addTargetSources(annotationID, sources); 125 String body = annotationDao.serializeBody(annotation.getBody()); 126 String newBody = annotationDao.updateTargetRefsInBody(body, sourcePairs); 127 if (!body.equals(newBody)) { 128 annotationDao.updateBody(annotationID, newBody); 129 }; 130 125 Map<String, String> sourceIdPairs= sourceDao.addTargetSourcesToAnnotation(annotationID, sources); 126 127 if (sourceIdPairs.containsValue(null)){ 128 // for one of the soirces there was no version and cached representation 129 // envelope 130 return (new ObjectFactory().createAnnotation(null)); 131 } 132 String body = Helpers.serializeBody(annotation.getBody()); 133 String newBody = Helpers.replace(body, sourceIdPairs); 134 int affectedAnnotRows = annotationDao.updateBody(annotationID, newBody); 135 136 // Add the permission (annotation_id, owner); 131 137 int affectedPermissions = permissionsDao.addAnnotationPrincipalPermission(annotationDao.getExternalID(annotationID), new UserIdentifier(remoteUser), Permission.OWNER); 132 if (affectedPermissions != 1) { 133 System.out.println("Cannot update permission table"); 134 return null; 135 } 138 136 139 Annotation newAnnotation = annotationDao.getAnnotation(annotationID); 137 140 return (new ObjectFactory().createAnnotation(newAnnotation)); 138 141 } 142 143 139 144 }
Note: See TracChangeset
for help on using the changeset viewer.