Changeset 4493
- Timestamp:
- 02/10/14 17:25:21 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r4429 r4493 20 20 21 21 import eu.dasish.annotation.schema.Permission; 22 import eu.dasish.annotation.schema.ReferenceList;23 22 import eu.dasish.annotation.schema.Notebook; 24 23 import eu.dasish.annotation.schema.NotebookInfo; 25 24 import java.util.List; 26 import java.util.UUID;27 25 28 26 /** … … 48 46 List<Number> getOwnerNotebookIDs(Number userID); 49 47 48 public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission); 49 50 51 50 52 /** 51 53 * … … 55 57 NotebookInfo getNotebookInfo(Number notebookID); 56 58 59 57 60 /** 58 61 * … … 62 65 Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID); 63 66 64 65 // Returns the list of all notebooks owned by the current logged user. 66 //List<Notebook> getUsersNotebooks(UUID userID); 67 67 //? Which type shul be orderedby? 68 /** 69 * 70 * @param maximumAnnotations 71 * @param startannotation 72 * @param orderedBy 73 * @param orederingMode if true then descending, if falset hen ascending 74 * @return 75 */ 76 List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode); 68 77 69 // Returns the list of annotation Id-s for the notebook id. 70 //public List<Number> getAnnotationIDs(Number notebookID); 78 /** 79 * 80 * UPDATERS 81 * 82 * 83 */ 71 84 72 /*Returns the list of annotation info-s for the notebook id.73 /List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); */74 85 75 // Returns the list of annotations Id-s for the notebook id.76 //public List<String> getAnnotationREFsOfNotebook(Number notebookID);77 78 // Returns the Annotations object for the notebook id.79 //public ReferenceList getAnnotations(Number notebookID);80 86 81 87 /** 82 88 * 83 89 * @param notebookID 84 * @return the Notebook information (title, owner (?), time_stamp(?), amount of annotations(?), their headlines (?) // TODO: discuss changing in the schema 85 * user in getting the metadata of a notebook 90 * @return true if updated, false otherwise. Logs the reason if the notebook is not updated. 86 91 */ 87 //NotebookInfo getNotebookInfo(Number notebookID); 88 89 92 boolean updateNotebookMetadata(Number notebookID); 90 93 91 94 /** 92 * @param notebookId 93 * @return returns the externalIds of the annotations contained in the notebookId 95 * 96 * ADDERS 97 * 98 * 94 99 */ 95 //List<UUID> getAnnotationExternalIDs(UUID notebookId); 100 101 Number createNotebook(Notebook notebook); 102 103 boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID); 104 96 105 97 106 98 107 /** 99 108 * 100 * ADDERS 109 * DELETERS (ADDER) 110 * 111 * 101 112 */ 102 113 103 // Creates a new notebook and returns the _nid_ of the created Notebook 104 //UUID addNotebook(UUID userID, String title); 105 106 // Adds an annotation _aid_ to the list of annotations of _nid_. 107 //public int addAnnotation(UUID notebookId, UUID annotationId); 114 boolean deleteannotationFromNotebook(Number notebookID, Number annotationID); 108 115 109 110 111 /** 112 * 113 * DELETE 114 * 115 */ 116 117 // Delete _nid_. Annotations stay, they just lose connection to _nid_.<br> 118 // returns the number of records deleted 119 //public int deleteNotebook(UUID notebookId); 120 /** 121 * 122 * @param annotationID 123 * @return removes the rows with annotationID from notebooks_annotations table 124 */ 125 //int removeAnnotation(Number annotationID); 116 boolean deleteNotebook(Number notebookID); 126 117 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r4429 r4493 39 39 * @author Peter Withers <peter.withers@mpi.nl> 40 40 */ 41 42 41 // TODO: not updated fully yet. 43 44 42 public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao { 45 43 46 44 // @Autowired 47 45 // private AnnotationDao jdbcAnnotationDao; 48 49 46 public JdbcNotebookDao(DataSource dataSource) { 50 setDataSource(dataSource); 47 setDataSource(dataSource); 51 48 internalIdName = notebook_id; 52 49 resourceTableName = notebookTableName; … … 54 51 55 52 /// GETTERS ///////// 56 57 53 //////////////////////////////////////////////// 58 54 @Override 59 public List<Number> getNotebookIDs(Number 55 public List<Number> getNotebookIDs(Number userID, Permission acessMode) { 60 56 Map<String, Object> params = new HashMap<String, Object>(); 61 57 params.put("principalID", userID); 62 58 params.put("accessMode", acessMode.value()); 63 String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";59 String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode"; 64 60 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params); 65 61 } 66 67 62 63 //////////////////////////////////////////////// 68 64 @Override 69 public List<Number> getOwnerNotebookIDs(Number 70 String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?";65 public List<Number> getOwnerNotebookIDs(Number userID) { 66 String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?"; 71 67 return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID); 72 68 } 73 74 75 69 70 71 72 @Override 73 public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) { 74 if (notebookID == null) { 75 return null; 76 } 77 Map<String, Object> params= new HashMap<String, Object>(); 78 params.put("notebookID", notebookID); 79 params.put("permission", permission.value()); 80 81 String sql = "SELECT " + owner_id + " FROM " + notebookPermissionsTableName + " WHERE " + notebook_id +" = :notebookID AND " +this.permission + " = :permission"; 82 return getSimpleJdbcTemplate().query(sql, principalIDRowMapper, params); 83 84 } 85 76 86 @Override 77 87 public NotebookInfo getNotebookInfo(Number notebookID) { … … 80 90 } 81 91 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 82 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID .toString());92 List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID); 83 93 return (!result.isEmpty() ? result.get(0) : null); 84 94 } 85 86 95 private final RowMapper<NotebookInfo> notebookInfoRowMapper = new RowMapper<NotebookInfo>() { 87 96 @Override 88 97 public NotebookInfo mapRow(ResultSet rs, int rowNumber) throws SQLException { 89 98 NotebookInfo notebookInfo = new NotebookInfo(); 90 notebookInfo.setRef(externalIDtoURI(rs.getString(external_id))); 99 notebookInfo.setRef(externalIDtoURI(rs.getString(external_id))); 91 100 notebookInfo.setTitle(rs.getString(title)); 92 101 return notebookInfo; 93 102 } 94 103 }; 95 96 104 97 105 @Override 98 106 public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) { … … 100 108 return null; 101 109 } 102 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";110 String sql = "SELECT " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1"; 103 111 List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID); 104 112 return (!result.isEmpty() ? result.get(0) : null); 105 113 } 106 107 108 109 private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() { 114 private final RowMapper<Notebook> notebookRowMapper = new RowMapper<Notebook>() { 110 115 @Override 111 116 public Notebook mapRow(ResultSet rs, int rowNumber) throws SQLException { … … 124 129 } 125 130 }; 126 127 // @Override128 // public UUID addNotebook(UUID userID, String title) {129 // try {130 // final UUID externalIdentifier = UUID.randomUUID();131 // String sql = "INSERT INTO " + notebookTableName + " (" + external_id + ", " + this.title + "," + notebookOwner_id + ") VALUES (:notebookId, :title, (SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + principalExternal_id + " = :userID))";132 // Map<String, Object> params = new HashMap<String, Object>();133 // params.put("notebookId", externalIdentifier.toString());134 // params.put("userID", userID.toString());135 // params.put("title", title);136 // final int updatedRowCount = getSimpleJdbcTemplate().update(sql, params);137 // return externalIdentifier;138 // } catch (DataAccessException exception) {139 // throw exception;140 // }141 // }142 131 143 144 145 // returns the number of affected annotations 146 // @Override 147 // public int deleteNotebook(UUID notebookId) { 148 // String sql1 = "DELETE FROM " + notebooksAnnotationsTableName + " where " + notebook_id + "= (SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + external_id + " = ?)"; 149 // String sql2 = "DELETE FROM notebook where external_id = ?"; 150 // int affectedAnnotations = getSimpleJdbcTemplate().update(sql1, notebookId.toString()); 151 // int affectedNotebooks = getSimpleJdbcTemplate().update(sql2, notebookId.toString()); 152 // return affectedAnnotations; 153 // } 154 155 // @Override 156 // public int addAnnotation(UUID notebookId, UUID annotationId) { 157 // try { 158 // SimpleJdbcInsert notebookInsert = new SimpleJdbcInsert(getDataSource()).withTableName(notebooksAnnotationsTableName); 159 // Map<String, Object> params = new HashMap<String, Object>(); 160 // params.put(notebook_id, notebookId); 161 // params.put(annotation_id, annotationId); 162 // int rowsAffected = notebookInsert.execute(params); 163 // return rowsAffected; 164 // } catch (DataAccessException exception) { 165 // throw exception; 166 // } 167 // } 168 169 //////////////////////////////////////////////////////////////////////// 132 133 @Override 134 public List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode){ 135 return null; 136 } 137 138 139 /** 140 * 141 * UPDATERS 142 * 143 * 144 */ 145 146 147 170 148 /** 171 * 149 * 172 150 * @param notebookID 173 * @return the list of annotation-ids belonging to the notebook with 174 * notebookId returns null if notebookId is null or is not in the DB TODO: 175 * do we need to return null here? using an additional check. 151 * @return true if updated, false otherwise. Logs the reason if the notebook is not updated. 176 152 */ 177 // @Override 178 // public List<Number> getAnnotationIDs(Number notebookID) { 179 // StringBuilder sql = new StringBuilder("SELECT DISTINCT "); 180 // sql.append(notebooksAnnotationsTableNameAnnotation_id).append(" FROM ").append(notebooksAnnotationsTableName).append(" where ").append(notebook_id).append(" = ?"); 181 // return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID); 182 // } 183 184 ////////////////////////////////////////////////// 153 @Override 154 public boolean updateNotebookMetadata(Number notebookID){ 155 return false; 156 } 157 /** 158 * 159 * ADDERS 160 * 161 * 162 */ 163 164 @Override 165 public Number createNotebook(Notebook notebook){ 166 return null; 167 } 168 169 @Override 170 public boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID){ 171 return false; 172 } 173 174 185 175 /** 186 * 187 * @param notebookID 188 * @return the list of annotation-infos of the annotations from notebookID; 189 * if notebook not in the DB or null returns null if the notebook contains 190 * no annotations returns an empty list 191 * 192 * 193 * @Override public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number 194 * notebookID) { return 195 * jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); } 176 * 177 * DELETERS (ADDER) 178 * 179 * 196 180 */ 197 //////////////////////////////////////////////198 /**199 *200 * @param notebookID201 * @return the list of annotation References from the notebookID returns202 * null if notebookID == null or it does not exists in the DB203 */204 // @Override205 // public List<String> getAnnotationREFsOfNotebook(Number notebookID) {206 // return null; //jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));207 // }208 209 ////////////////////////////////////////////////////////////////////////////210 /**211 *212 * @param notebookID213 * @return the Annotations (as a list of references) from the notebookID *214 * returns null if notebookID == null, or it does not exists in th DB, or215 * the list of annotations is empty, or something wrong happened when216 * extracting annotations from the notebook (according to dasish.xsd if an217 * Annotation is created then its list of annotations must contain at least218 * one element!)219 *220 */221 // @Override222 // public ReferenceList getAnnotations(Number notebookID) {223 // if (notebookID == null) {224 // return null;225 // }226 // ReferenceList result = new ReferenceList();227 // result.getRef().addAll(getAnnotationREFsOfNotebook(notebookID));228 // return result;229 //230 // }231 232 ///////////////////////////////////////////////////233 234 235 181 236 ////////////////////////////////////////////////////////////////// 237 // @Override 238 // public List<UUID> getAnnotationExternalIDs(UUID notebookId) { 239 // List<Number> internalIds = getAnnotationIDs(getInternalID(notebookId)); 240 // if (internalIds == null) { 241 // return null; 242 // } 243 // List<UUID> annotationIds = new ArrayList<UUID>(); 244 //// for (Number internalId : internalIds) { 245 //// annotationIds.add(jdbcAnnotationDao.getExternalID(internalId)); 246 //// } 247 // return annotationIds; 248 // } 249 250 //////////////////////////////////////////////////////////// 251 // @Override 252 // public int removeAnnotation(Number annotationID) { 253 // String sqlNotebooks = "DELETE FROM " + notebooksAnnotationsTableName + " where " + annotation_id + " = ?"; 254 // int affectedNotebooks = getSimpleJdbcTemplate().update(sqlNotebooks, annotationID); 255 // return affectedNotebooks; 256 // } 182 @Override 183 public boolean deleteannotationFromNotebook(Number notebookID, Number annotationID){ 184 return false; 185 } 186 187 @Override 188 public boolean deleteNotebook(Number notebookID){ 189 return false; 190 } 257 191 }
Note: See TracChangeset
for help on using the changeset viewer.