Changeset 4281
- Timestamp:
- 01/17/14 18:46:22 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/TargetDao.java
r4181 r4281 112 112 public int addTargetCachedRepresentation(Number TargetID, Number cachedID, String fragmentDescription); 113 113 114 /** 115 * 116 * @param TargetID 117 * @param classID 118 * @return # of updated rows (should be 1) when updating the row for TargetID by class classID 119 * @throws SQLException 120 */ 121 public int updateSiblingClass(Number TargetID, int classID); 114 122 115 123 116 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4276 r4281 283 283 AnnotationInfoList result = new AnnotationInfoList(); 284 284 for (Number annotationID : annotationIDs) { 285 Number ownerID = annotationDao.getOwner(annotationID); 285 Number ownerID = annotationDao.getOwner(annotationID); 286 286 ReferenceList targets = getAnnotationTargets(annotationID); 287 287 AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID); 288 288 annotationInfo.setTargets(targets); 289 if (ownerID != null) {290 annotationInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID));}291 else {292 annotationInfo.setOwnerRef("ACHTUNG: This annotation does not have an owner in the DB!!!!");289 if (ownerID != null) { 290 annotationInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 291 } else { 292 annotationInfo.setOwnerRef("ACHTUNG: This annotation does not have an owner in the DB!!!!"); 293 293 } 294 294 result.getAnnotationInfo().add(annotationInfo); … … 371 371 372 372 ///// UPDATERS ///////////////// 373 374 373 @Override 375 374 public boolean updateAccount(UUID userExternalID, String account) { 376 375 return userDao.updateAccount(userExternalID, account); 377 376 } 378 377 379 378 @Override 380 379 public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) { … … 462 461 Number annotationID = annotationDao.addAnnotation(annotation); 463 462 int affectedAnnotRows = addTargets(annotation, annotationID); 464 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID); 463 if (annotation.getPermissions() != null) { 464 if (annotation.getPermissions().getUserWithPermission() != null) { 465 int addedPrincipalsPermissions = addPrincipalsPermissions(annotation.getPermissions().getUserWithPermission(), annotationID); 466 } 467 } 465 468 int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER); 466 469 return annotationID; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4276 r4281 36 36 import java.util.UUID; 37 37 import javax.sql.DataSource; 38 import org.slf4j.Logger; 39 import org.slf4j.LoggerFactory; 38 40 import org.springframework.jdbc.core.RowMapper; 39 41 … … 45 47 public class JdbcAnnotationDao extends JdbcResourceDao implements AnnotationDao { 46 48 49 private final Logger loggerAnnotationDao = LoggerFactory.getLogger(JdbcAnnotationDao.class); 50 47 51 public JdbcAnnotationDao(DataSource dataSource) { 48 52 setDataSource(dataSource); … … 65 69 return getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, annotationID); 66 70 } else { 71 loggerAnnotationDao.debug(nullArgument); 67 72 return null; 68 73 } … … 73 78 public List<Map<Number, String>> getPermissions(Number annotationID) { 74 79 if (annotationID == null) { 80 loggerAnnotationDao.debug(nullArgument); 75 81 return null; 76 82 } … … 90 96 @Override 91 97 public Permission getPermission(Number annotationID, Number userID) { 92 if (annotationID == null || userID == null) { 93 return null; 94 } 98 if (annotationID == null) { 99 loggerAnnotationDao.debug("annotationID: "+nullArgument); 100 return null; 101 } 102 103 if (userID == null) { 104 loggerAnnotationDao.debug("userID: "+nullArgument); 105 return null; 106 } 107 95 108 StringBuilder sql = new StringBuilder("SELECT "); 96 109 sql.append(permission).append(" FROM ").append(permissionsTableName).append(" WHERE "). … … 115 128 @Override 116 129 public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String[] permissionStrings) { 117 if (userID == null || permissionStrings == null) { 130 if (permissionStrings == null) { 131 loggerAnnotationDao.debug("premissionStrings: "+nullArgument); 132 return null; 133 } 134 135 if (userID == null) { 136 loggerAnnotationDao.debug("userID: "+nullArgument); 118 137 return null; 119 138 } … … 154 173 155 174 if (annotationIDs == null) { 175 loggerAnnotationDao.debug("annotationIDs: "+nullArgument); 156 176 return null; 157 177 } else { … … 193 213 ////////////////////////////// 194 214 @Override 195 public List<Number> retrieveAnnotationList(List<Number> TargetIDs) { 196 if (TargetIDs == null) { 197 return null; 198 } 199 if (TargetIDs.isEmpty()) { 215 public List<Number> retrieveAnnotationList(List<Number> targetIDs) { 216 if (targetIDs == null) { 217 loggerAnnotationDao.debug("targetIDs: "+nullArgument); 218 return null; 219 } 220 if (targetIDs.isEmpty()) { 200 221 return new ArrayList<Number>(); 201 222 } 202 String values = makeListOfValues( TargetIDs);223 String values = makeListOfValues(targetIDs); 203 224 StringBuilder query = new StringBuilder("SELECT DISTINCT "); 204 225 query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" IN "); … … 210 231 public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) { 211 232 if (annotationID == null) { 233 loggerAnnotationDao.debug("annotationID: "+nullArgument); 212 234 return null; 213 235 } … … 247 269 public List<String> getAnnotationREFs(List<Number> annotationIDs) { 248 270 if (annotationIDs == null) { 271 loggerAnnotationDao.debug("annotationIDs: "+nullArgument); 249 272 return null; 250 273 } … … 269 292 public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID) { 270 293 if (annotationID == null) { 294 loggerAnnotationDao.debug("annotationID: "+nullArgument); 271 295 return null; 272 296 } … … 307 331 public Number getOwner(Number annotationID){ 308 332 if (annotationID == null) { 333 loggerAnnotationDao.debug("annotationID: "+nullArgument); 309 334 return null; 310 335 } … … 389 414 public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) { 390 415 416 if (annotationID == null) { 417 loggerAnnotationDao.debug("annotationID: "+nullArgument); 418 return 0; 419 } 420 421 if (userID == null) { 422 loggerAnnotationDao.debug("userID: "+nullArgument); 423 return 0; 424 } 425 426 if (permission == null) { 427 loggerAnnotationDao.debug("permission: "+nullArgument); 428 return 0; 429 } 430 391 431 Map<String, Object> params = new HashMap<String, Object>(); 392 432 … … 416 456 417 457 String[] body = retrieveBodyComponents(annotation.getBody()); 458 459 if (annotation == null) { 460 loggerAnnotationDao.debug("annotation: "+nullArgument); 461 return 0; 462 } 418 463 419 464 // generate a new annotation ID … … 437 482 @Override 438 483 public int addAnnotationTarget(Number annotationID, Number targetID) { 484 485 if (annotationID == null) { 486 loggerAnnotationDao.debug("annotationID: "+nullArgument); 487 return 0; 488 } 489 490 if (targetID == null) { 491 loggerAnnotationDao.debug("targetID: "+nullArgument); 492 return 0; 493 } 494 439 495 Map<String, Object> paramsAnnotationsTargets = new HashMap<String, Object>(); 440 496 paramsAnnotationsTargets.put("annotationId", annotationID); … … 448 504 @Override 449 505 public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) { 506 507 if (annotationID == null) { 508 loggerAnnotationDao.debug("annotationID: "+nullArgument); 509 return 0; 510 } 511 512 if (userID == null) { 513 loggerAnnotationDao.debug("userID: "+nullArgument); 514 return 0; 515 } 516 517 if (permission == null) { 518 loggerAnnotationDao.debug("permission: "+nullArgument); 519 return 0; 520 } 521 522 450 523 Map<String, Object> paramsPermissions = new HashMap<String, Object>(); 451 524 paramsPermissions.put("annotationId", annotationID); … … 470 543 return (getSimpleJdbcTemplate().update(sqlAnnotation.toString(), annotationID)); 471 544 } else { 545 loggerAnnotationDao.debug("annotationID: "+nullArgument); 472 546 return 0; 473 547 } … … 481 555 return getSimpleJdbcTemplate().update(sqlTargetTargets.toString(), annotationID); // # removed "annotations_target_Targets" rows 482 556 } else { 557 loggerAnnotationDao.debug("annotationID: "+nullArgument); 483 558 return 0; 484 559 } … … 493 568 return getSimpleJdbcTemplate().update(sqlPermissions.toString(), annotationID); // removed "permission" rows 494 569 } else { 570 loggerAnnotationDao.debug("annotationID: "+nullArgument); 495 571 return 0; 496 572 } … … 512 588 result[1] = textBody.getMimeType(); 513 589 } else { 514 logger .error("Ill-formed body: both options, xml-body and text-body, are set to null. ");590 loggerAnnotationDao.error("Ill-formed body: both options, xml-body and text-body, are set to null. "); 515 591 return null; 516 592 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3936 r4281 32 32 import org.springframework.jdbc.core.RowMapper; 33 33 import org.apache.commons.io.IOUtils; 34 import org.slf4j.Logger; 35 import org.slf4j.LoggerFactory; 34 36 35 37 /** … … 39 41 public class JdbcCachedRepresentationDao extends JdbcResourceDao implements CachedRepresentationDao { 40 42 43 private final Logger loggerCachedDao = LoggerFactory.getLogger(JdbcCachedRepresentationDao.class); 44 45 46 41 47 public JdbcCachedRepresentationDao(DataSource dataSource) { 42 48 setDataSource(dataSource); … … 53 59 @Override 54 60 public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID) { 55 61 if (internalID == null) { 62 loggerCachedDao.debug("internalID: " + nullArgument); 63 return null; 64 } 56 65 StringBuilder sql = new StringBuilder("SELECT "); 57 66 sql.append(cachedRepresentationStar).append(" FROM ").append(cachedRepresentationTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1"); … … 78 87 @Override 79 88 public InputStream getCachedRepresentationBlob(Number internalID) { 80 89 90 if (internalID == null) { 91 loggerCachedDao.debug("internalID: " + nullArgument); 92 return null; 93 } 81 94 StringBuilder sql = new StringBuilder("SELECT "); 82 95 sql.append(file_).append(" FROM ").append(cachedRepresentationTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1"); … … 98 111 ////////////////////////////////////// 99 112 private boolean cachedIsInUse(Number cachedID) { 113 114 if (cachedID == null) { 115 loggerCachedDao.debug("cachedID: " + nullArgument); 116 return false; 117 } 118 100 119 StringBuilder sql = new StringBuilder("SELECT "); 101 120 sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1"); … … 125 144 126 145 } catch (IOException ioe) { 146 loggerCachedDao.debug(ioe + "while adding cached representation"); 127 147 return null; 128 148 } … … 133 153 @Override 134 154 public int deleteCachedRepresentation(Number internalID) { 155 156 if (internalID == null) { 157 loggerCachedDao.debug("internalID: " + nullArgument); 158 return 0; 159 } 160 135 161 if (cachedIsInUse(internalID)) { 162 loggerCachedDao.debug("Cached Repr. is in use, and cannot be deleted."); 136 163 return 0; 137 164 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r4276 r4281 98 98 protected String resourceTableName = null; 99 99 protected String _serviceURI; 100 private static final Logger _logger = LoggerFactory.getLogger(JdbcResourceDao.class); 100 private final Logger _logger = LoggerFactory.getLogger(JdbcResourceDao.class); 101 protected String nullArgument = "Null argument is given to the method."; 101 102 102 103 //////// … … 110 111 @Override 111 112 public Number getInternalID(UUID externalId) { 112 if (externalId == null) {113 return null;114 }115 113 StringBuilder sql = new StringBuilder("SELECT "); 116 114 sql.append(internalIdName).append(" FROM ").append(resourceTableName).append(" WHERE ").append(external_id).append("= ? LIMIT 1"); 117 115 List<Number> sqlResult = getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, externalId.toString()); 118 return (sqlResult.isEmpty() ? null : sqlResult.get(0)); 116 if (sqlResult.isEmpty()) { 117 _logger.debug("The object with external ID " + externalId.toString() + " is not found in the database."); 118 return null; 119 } else { 120 return sqlResult.get(0); 121 } 122 119 123 } 120 124 … … 122 126 @Override 123 127 public UUID getExternalID(Number internalId) { 128 if (internalId == null) { 129 _logger.debug("internalId: " + nullArgument); 130 return null; 131 } 124 132 StringBuilder sql = new StringBuilder("SELECT "); 125 133 sql.append(external_id).append(" FROM ").append(resourceTableName).append(" WHERE ").append(internalIdName).append("= ? LIMIT 1"); … … 132 140 public Number getInternalIDFromURI(String uri) { 133 141 String externalID = stringURItoExternalID(uri); 134 return getInternalID(UUID.fromString(externalID)); 142 try { 143 return getInternalID(UUID.fromString(externalID)); 144 } catch (IllegalArgumentException e) { 145 _logger.debug("Got a non valid external ID (not an UUID) " + externalID + " from uri " + uri); 146 return null; 147 } 135 148 } 136 149 … … 138 151 @Override 139 152 public String getURIFromInternalID(Number internalID) { 153 if (internalID == null) { 154 _logger.debug("internalID: " + nullArgument); 155 return null; 156 } 140 157 return externalIDtoURI(getExternalID(internalID).toString()); 141 158 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDao.java
r4188 r4281 31 31 import javax.xml.datatype.DatatypeConfigurationException; 32 32 import javax.xml.datatype.XMLGregorianCalendar; 33 import org.slf4j.Logger; 34 import org.slf4j.LoggerFactory; 33 35 import org.springframework.jdbc.core.RowMapper; 34 36 … … 39 41 public class JdbcTargetDao extends JdbcResourceDao implements TargetDao { 40 42 43 private final Logger loggerTargetDao = LoggerFactory.getLogger(JdbcTargetDao.class); 44 41 45 public JdbcTargetDao(DataSource dataTarget) { 42 46 setDataSource(dataTarget); … … 53 57 @Override 54 58 public Target getTarget(Number internalID) { 59 60 if (internalID == null) { 61 loggerTargetDao.debug("internalID: " + nullArgument); 62 return null; 63 } 64 55 65 StringBuilder sql = new StringBuilder("SELECT "); 56 66 sql.append(targetStar).append(" FROM ").append(targetTableName).append(" WHERE ").append(target_id).append("= ? LIMIT 1"); … … 70 80 @Override 71 81 public String getLink(Number internalID) { 82 83 if (internalID == null) { 84 loggerTargetDao.debug("internalID: " + nullArgument); 85 return null; 86 } 87 72 88 StringBuilder sql = new StringBuilder("SELECT "); 73 89 sql.append(targetStar).append(" FROM ").append(targetTableName).append(" WHERE ").append(target_id).append("= ? LIMIT 1"); … … 86 102 public List<Number> getCachedRepresentations(Number targetID) { 87 103 104 if (targetID == null) { 105 loggerTargetDao.debug("targetID: " + nullArgument); 106 return null; 107 } 108 88 109 String sql = "SELECT " + cached_representation_id + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?"; 89 110 return getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, targetID); … … 92 113 @Override 93 114 public Map<Number, String> getCachedRepresentationFragmentPairs(Number targetID) { 115 116 if (targetID == null) { 117 loggerTargetDao.debug("targetID: " + nullArgument); 118 return null; 119 } 120 94 121 Map<Number, String> result = new HashMap<Number, String>(); 95 122 String sql = "SELECT " + cached_representation_id + "," + fragment_descriptor_in_cached + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?"; … … 113 140 public List<TargetInfo> getTargetInfos(List<Number> targets) { 114 141 if (targets == null) { 142 loggerTargetDao.debug("targets: " + nullArgument); 115 143 return null; 116 144 } … … 136 164 @Override 137 165 public List<Number> getTargetsReferringTo(String word) { 166 if (word == null) { 167 loggerTargetDao.debug("word: " + nullArgument); 168 return null; 169 } 138 170 String searchTerm = "%" + word + "%"; 139 171 StringBuilder sql = new StringBuilder("SELECT "); … … 145 177 @Override 146 178 public List<Number> getTargetsForLink(String link) { 179 if (link == null) { 180 loggerTargetDao.debug("link: " + nullArgument); 181 return null; 182 } 183 147 184 StringBuilder sql = new StringBuilder("SELECT "); 148 185 sql.append(target_id).append(" FROM ").append(targetTableName).append(" WHERE ").append(link_uri).append(" = ? "); … … 153 190 @Override 154 191 public boolean targetIsInUse(Number targetID) { 192 if (targetID == null) { 193 loggerTargetDao.debug("targetID: " + nullArgument); 194 return false; 195 } 196 197 155 198 StringBuilder sqlAnnotations = new StringBuilder("SELECT "); 156 199 sqlAnnotations.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" = ? LIMIT 1"); … … 165 208 @Override 166 209 public Number addTarget(Target target) { 210 211 if (target == null) { 212 loggerTargetDao.debug("target: " + nullArgument); 213 return null; 214 } 215 216 167 217 UUID externalID = UUID.randomUUID(); 168 218 String[] linkParts = splitLink(target.getLink()); … … 181 231 @Override 182 232 public int addTargetCachedRepresentation(Number targetID, Number cachedID, String fragmentDescriptor) { 233 if (targetID == null) { 234 loggerTargetDao.debug("targetID: " + nullArgument); 235 return 0; 236 } 237 238 if (cachedID == null) { 239 loggerTargetDao.debug("cachedID: " + nullArgument); 240 return 0; 241 } 242 183 243 Map<String, Object> paramsJoint = new HashMap<String, Object>(); 184 244 paramsJoint.put("targetId", targetID); … … 189 249 } 190 250 191 /////////////////////////////////////////////////////////////////// 192 @Override 193 public int updateSiblingClass(Number TargetID, int classID) { 194 if (TargetID == null) { 195 return 0; 196 } 197 StringBuilder sql = new StringBuilder("UPDATE "); 198 sql.append(targetTableName).append(" SET ").append(sibling_Target_class).append("= '").append(classID).append("' WHERE ").append(target_id).append("= ?"); 199 return getSimpleJdbcTemplate().update(sql.toString(), TargetID); 200 } 251 201 252 202 253 ////////////////////// DELETERS //////////////////////// 203 254 @Override 204 255 public int deleteTarget(Number internalID) { 256 if (internalID == null) { 257 loggerTargetDao.debug("internalID: " + nullArgument); 258 return 0; 259 } 260 205 261 if (targetIsInUse(internalID)) { 262 loggerTargetDao.debug("The target is in use, and cannot be deleted."); 206 263 return 0; 207 264 } … … 215 272 @Override 216 273 public int deleteTargetCachedRepresentation(Number targetID, Number cachedID) { 217 if (targetID == null || cachedID == null) { 218 return 0; 219 } 274 275 if (targetID == null) { 276 loggerTargetDao.debug("targetID: " + nullArgument); 277 return 0; 278 } 279 280 if (cachedID == null) { 281 loggerTargetDao.debug("cachedID: " + nullArgument); 282 return 0; 283 } 284 285 220 286 Map<String, Object> paramsJoint = new HashMap<String, Object>(); 221 287 paramsJoint.put("targetId", targetID); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r4276 r4281 27 27 import java.util.UUID; 28 28 import javax.sql.DataSource; 29 import org.slf4j.Logger; 30 import org.slf4j.LoggerFactory; 29 31 import org.springframework.jdbc.core.RowMapper; 30 32 … … 35 37 public class JdbcUserDao extends JdbcResourceDao implements UserDao { 36 38 39 private final Logger loggerUserDao = LoggerFactory.getLogger(JdbcUserDao.class); 40 37 41 public JdbcUserDao(DataSource dataSource) { 38 42 setDataSource(dataSource); … … 49 53 @Override 50 54 public User getUser(Number internalID) { 55 56 if (internalID == null) { 57 loggerUserDao.debug("internalID: " + nullArgument); 58 return null; 59 } 60 51 61 StringBuilder sql = new StringBuilder("SELECT "); 52 62 sql.append(principalStar).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1"); … … 75 85 @Override 76 86 public boolean userIsInUse(Number userID) { 87 88 if (userID == null) { 89 loggerUserDao.debug("userID: " + nullArgument); 90 return false; 91 } 92 77 93 StringBuilder sqlPermissions = new StringBuilder("SELECT "); 78 94 sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1"); … … 93 109 @Override 94 110 public boolean userExists(User user) { 111 if (user == null) { 112 loggerUserDao.debug("user: " + nullArgument); 113 return false; 114 } 115 95 116 String emailCriterion = user.getEMail().toLowerCase(); 96 117 StringBuilder sqlTargets = new StringBuilder("SELECT "); … … 106 127 @Override 107 128 public String getRemoteID(Number internalID) { 129 130 if (internalID == null) { 131 loggerUserDao.debug("internalID: " + nullArgument); 132 return null; 133 } 134 108 135 StringBuilder requestDB = new StringBuilder("SELECT "); 109 136 requestDB.append(remote_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1"); … … 120 147 @Override 121 148 public Number getUserInternalIDFromRemoteID(String remoteID) { 149 150 if (remoteID == null) { 151 loggerUserDao.debug("remoteID: " + nullArgument); 152 return null; 153 } 154 122 155 StringBuilder requestDB = new StringBuilder("SELECT "); 123 156 requestDB.append(principal_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(remote_id).append("= ? LIMIT 1"); … … 128 161 @Override 129 162 public String getTypeOfUserAccount(Number internalID) { 163 164 if (internalID == null) { 165 loggerUserDao.debug("internalID: " + nullArgument); 166 return null; 167 } 168 130 169 StringBuilder requestDB = new StringBuilder("SELECT "); 131 170 requestDB.append(account).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1"); … … 143 182 @Override 144 183 public Number addUser(User user, String remoteID) { 184 185 if (remoteID == null) { 186 loggerUserDao.debug("remoteID: " + nullArgument); 187 return null; 188 } 189 190 if (user == null) { 191 loggerUserDao.debug("user: " + nullArgument); 192 return null; 193 } 194 145 195 UUID externalIdentifier = UUID.randomUUID(); 146 196 String newExternalIdentifier = externalIdentifier.toString(); … … 162 212 @Override 163 213 public boolean updateAccount(UUID externalID, String account) { 214 215 if (externalID == null) { 216 loggerUserDao.debug("eternalId: " + nullArgument); 217 return false; 218 } 219 220 if (account == null) { 221 loggerUserDao.debug("account: " + nullArgument); 222 return false; 223 } 224 164 225 if (!account.equals(admin) && !account.equals(developer) && !account.equals(user)) { 165 226 logger.error("the given type of account '" + account + "' does not exist."); … … 191 252 @Override 192 253 public Number updateUser(User user) { 254 255 if (user == null) { 256 loggerUserDao.debug("user: " + nullArgument); 257 return null; 258 } 259 193 260 Number principalID = this.getInternalIDFromURI(user.getURI()); 194 261 StringBuilder sql = new StringBuilder("UPDATE "); … … 204 271 @Override 205 272 public int deleteUser(Number internalID) { 273 if (internalID == null) { 274 loggerUserDao.debug("internalID: " + nullArgument); 275 return 0; 276 } 277 206 278 207 279 StringBuilder sql = new StringBuilder("DELETE FROM "); … … 213 285 @Override 214 286 public int deleteUserSafe(Number internalID) { 287 288 if (internalID == null) { 289 loggerUserDao.debug("internalID: " + nullArgument); 290 return 0; 291 } 292 293 215 294 if (userIsInUse(internalID)) { 295 loggerUserDao.debug("User is in use, and cannot be deleted."); 216 296 return 0; 217 297 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4276 r4281 83 83 @Context 84 84 private ServletContext context; 85 86 85 final String default_permission = "reader"; 87 86 private final Logger logger = LoggerFactory.getLogger(AnnotationResource.class); 88 87 public static final Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); 88 final private String admin = "admin"; 89 89 90 public void setUriInfo(UriInfo uriInfo) { 90 91 this.uriInfo = uriInfo; … … 105 106 public AnnotationResource() { 106 107 } 107 108 109 108 110 109 @GET … … 112 111 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") 113 112 @Transactional(readOnly = true) 114 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String ExternalIdentifier) throws IOException {113 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException { 115 114 URI baseURI = uriInfo.getBaseUri(); 116 115 String baseURIstr = baseURI.toString(); 117 116 dbIntegrityService.setServiceURI(baseURIstr); 118 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString( ExternalIdentifier));117 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 119 118 if (annotationID != null) { 120 119 String remoteUser = httpServletRequest.getRemoteUser(); 121 120 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 122 121 if (userID != null) { 123 if ( canRead(userID, annotationID)) {122 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) { 124 123 final Annotation annotation = dbIntegrityService.getAnnotation(annotationID); 125 124 JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation); 126 logger.info("getAnnotation method: OK");127 125 return rootElement; 128 126 } else { 127 loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation."); 129 128 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 130 129 return null; 131 130 } 132 131 } else { 133 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 134 return null; 135 } 136 } else { 137 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 132 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 133 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 134 return null; 135 } 136 } else { 137 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 138 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database"); 138 139 return null; 139 140 } … … 146 147 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/targets") 147 148 @Transactional(readOnly = true) 148 public JAXBElement<ReferenceList> getAnnotationTargets(@PathParam("annotationid") String ExternalIdentifier) throws IOException {149 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 150 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString( ExternalIdentifier));149 public JAXBElement<ReferenceList> getAnnotationTargets(@PathParam("annotationid") String externalIdentifier) throws IOException { 150 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 151 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 151 152 if (annotationID != null) { 152 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 153 String remoteUser = httpServletRequest.getRemoteUser(); 154 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 153 155 if (userID != null) { 154 if ( canRead(userID, annotationID)) {156 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) { 155 157 final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID); 156 158 logger.info("getAnnotationTargets method: OK"); 157 159 return new ObjectFactory().createTargetList(TargetList); 158 160 } else { 161 loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation."); 159 162 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 160 163 return null; 161 164 } 162 165 } else { 163 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 164 return null; 165 } 166 } else { 167 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 166 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 167 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 168 return null; 169 } 170 } else { 171 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 172 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database"); 168 173 return null; 169 174 } … … 184 189 185 190 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 186 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 191 String remoteUser = httpServletRequest.getRemoteUser(); 192 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 187 193 if (userID != null) { 188 194 UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null; … … 192 198 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 193 199 } else { 194 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 200 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 201 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 195 202 return null; 196 203 } … … 203 210 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions") 204 211 @Transactional(readOnly = true) 205 public JAXBElement<UserWithPermissionList> getAnnotationPermissions(@PathParam("annotationid") String ExternalIdentifier) throws IOException { 206 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 207 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier)); 208 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 212 public JAXBElement<UserWithPermissionList> getAnnotationPermissions(@PathParam("annotationid") String externalIdentifier) throws IOException { 213 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 214 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 215 String remoteUser = httpServletRequest.getRemoteUser(); 216 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 209 217 if (userID != null) { 210 218 if (annotationID != null) { 211 if ( canRead(userID, annotationID)) {219 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) { 212 220 final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID); 213 logger. info("getAnnotationPermissions method: OK");221 logger.debug("getAnnotationPermissions method: OK"); 214 222 return new ObjectFactory().createPermissionList(permissionList); 215 223 } else { 224 loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation."); 216 225 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation."); 217 226 return null; 218 227 } 219 228 } else { 220 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database"); 221 return null; 222 } 223 } else { 224 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 229 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 230 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database"); 231 return null; 232 } 233 } else { 234 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 235 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 225 236 return null; 226 237 } … … 234 245 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 235 246 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 236 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 247 String remoteUser = httpServletRequest.getRemoteUser(); 248 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 237 249 if (userID != null) { 238 250 if (annotationID != null) { … … 243 255 return result + " annotation(s) deleted."; 244 256 } else { 257 loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot delete the annotation. Only the owner can delete the annotation."); 245 258 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation."); 246 259 return null; 247 260 } 248 261 } else { 249 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 250 return null; 251 } 252 253 } else { 254 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 262 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 263 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database."); 264 return null; 265 } 266 267 } else { 268 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database."); 269 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 255 270 return null; 256 271 } … … 265 280 public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws IOException { 266 281 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 267 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 282 String remoteUser = httpServletRequest.getRemoteUser(); 283 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 268 284 if (userID != null) { 269 285 Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation); 270 logger.info("createAnnotation method: OK");271 286 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 272 287 } else { 273 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 288 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 289 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 274 290 return null; 275 291 } … … 288 304 289 305 if (!(path + "annotations/" + externalIdentifier).equals(annotationURI)) { 290 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request: the external annotation ID and the annotation ID from the request body do not match. Correct the request and resend."); 306 loggerServer.debug(httpServletResponse.SC_CONFLICT + "Wrong request: the annotation identifier " + externalIdentifier + " and the annotation ID from the request body do not match. Correct the request and resend."); 307 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request: the annotation identifier " + externalIdentifier + " and the annotation ID from the request body do not match. Correct the request and resend."); 291 308 return null; 292 309 } … … 295 312 String ownerURI = annotation.getOwnerRef(); 296 313 if (!ownerIsListed(ownerURI, permissions)) { 314 loggerServer.debug(httpServletResponse.SC_CONFLICT + "Wrong request body: the owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend."); 297 315 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "Wrong request body: the owner URI's is not listed in the list of permissions as 'owner'. Correct the request and resend."); 298 316 return null; … … 302 320 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 303 321 if (annotationID != null) { 304 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 322 String remoteUser = httpServletRequest.getRemoteUser(); 323 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 305 324 if (userID != null) { 306 325 if (isOwner(userID, annotationID)) { 307 326 int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation); 308 logger.info("updateAnnotation method: OK");309 327 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 310 328 311 329 } else { 312 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Only owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body."); 313 return null; 314 } 315 } else { 316 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 317 return null; 318 } 319 } else { 320 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 330 loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "Only the owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body."); 331 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Only the owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body."); 332 return null; 333 } 334 } else { 335 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 336 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 337 return null; 338 } 339 } else { 340 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 341 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database."); 321 342 return null; 322 343 } … … 331 352 dbIntegrityService.setServiceURI(path); 332 353 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier)); 333 final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 354 String remoteUser = httpServletRequest.getRemoteUser(); 355 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 334 356 if (userID != null) { 335 357 if (annotationID != null) { 336 358 if (canWrite(userID, annotationID)) { 337 359 int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody); 338 logger.info("updateAnnotationBody method: OK");339 360 return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID)); 340 361 } else { 362 loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is not its 'writer'."); 341 363 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is not its 'writer'."); 342 364 return null; 343 365 } 344 366 } else { 345 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 346 return null; 347 } 348 } else { 349 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 367 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database"); 368 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database."); 369 return null; 370 } 371 } else { 372 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 373 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 350 374 return null; 351 375 } … … 358 382 public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws IOException { 359 383 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 360 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 384 String remoteUser = httpServletRequest.getRemoteUser(); 385 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 361 386 if (remoteUserID != null) { 362 387 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId)); … … 372 397 373 398 } else { 399 loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is not its 'writer'."); 374 400 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is not its owner."); 375 401 return null; 376 402 } 377 403 } else { 378 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 379 return null; 380 } 381 } else { 382 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database."); 383 return null; 384 } 385 386 } else { 387 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 404 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + annotationExternalId + " is not found in the database"); 405 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + annotationExternalId + " is not found in the database."); 406 return null; 407 } 408 } else { 409 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + userExternalId + " is not found in the database"); 410 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + userExternalId + " is not found in the database."); 411 return null; 412 } 413 414 } else { 415 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 416 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 388 417 return null; 389 418 } … … 397 426 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 398 427 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId)); 399 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 428 String remoteUser = httpServletRequest.getRemoteUser(); 429 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 400 430 if (remoteUserID != null) { 401 431 if (annotationID != null) { … … 404 434 return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID)); 405 435 } else { 406 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is not its owner."); 407 return null; 408 } 409 } else { 410 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database."); 411 return null; 412 } 413 } else { 414 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database."); 436 loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the access rights on this annotation because (s)he is not its owner."); 437 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the access rights on this annotation because (s)he is not its owner."); 438 return null; 439 } 440 } else { 441 loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + annotationExternalId + " is not found in the database"); 442 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + annotationExternalId + " is not found in the database."); 443 return null; 444 } 445 } else { 446 loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 447 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database."); 415 448 return null; 416 449 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
r4252 r4281 39 39 import javax.xml.bind.JAXBElement; 40 40 import javax.xml.parsers.ParserConfigurationException; 41 import org.slf4j.Logger; 42 import org.slf4j.LoggerFactory; 41 43 import org.springframework.beans.factory.annotation.Autowired; 42 44 import org.springframework.stereotype.Component; … … 60 62 @Context 61 63 private UriInfo uriInfo; 64 private final Logger logger = LoggerFactory.getLogger(CachedRepresentationResource.class); 62 65 63 66 public void setHttpRequest(HttpServletRequest request) { … … 73 76 public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException { 74 77 75 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 78 String remoteUser = httpServletRequest.getRemoteUser(); 79 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 76 80 if (remoteUserID != null) { 77 81 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); … … 81 85 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 82 86 } else { 87 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database"); 83 88 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 84 89 return null; 85 90 } 86 91 } else { 92 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 87 93 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 88 94 return null; … … 95 101 @Transactional(readOnly = true) 96 102 public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws SQLException, IOException { 97 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 103 String remoteUser = httpServletRequest.getRemoteUser(); 104 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 98 105 if (remoteUserID != null) { 99 106 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); … … 105 112 return result; 106 113 } else { 107 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 114 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database"); 115 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id " + externalId + " is not found in the database"); 108 116 return null; 109 117 } 110 118 } else { 111 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 119 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 120 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 112 121 return null; 113 122 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DebugResource.java
r4276 r4281 75 75 public JAXBElement<AnnotationInfoList> getAllAnnotations() throws IOException { 76 76 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 77 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 77 String remoteUser = httpServletRequest.getRemoteUser(); 78 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 78 79 if (userID != null) { 79 80 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); … … 82 83 return new ObjectFactory().createAnnotationInfoList(annotationInfoList); 83 84 } else { 84 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged 85 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request."); 85 86 return null; 86 87 } 87 88 } else { 88 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged 89 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 89 90 return null; 90 91 } … … 94 95 @GET 95 96 @Produces(MediaType.TEXT_PLAIN) 96 @Path("/log /{n}")97 @Path("/logDatabase/{n}") 97 98 @Transactional(readOnly = true) 98 99 public String getDasishBackendLog(@PathParam("n") int n) throws IOException { 100 return logFile("eu.dasish.annotation.backend.logDatabaseLocation", n); 101 } 102 103 @GET 104 @Produces(MediaType.TEXT_PLAIN) 105 @Path("/remoteID") 106 @Transactional(readOnly = true) 107 public String getLoggedInRemoteID() throws IOException { 108 return httpServletRequest.getRemoteUser(); 109 } 110 111 ///// 112 113 @GET 114 @Produces(MediaType.TEXT_PLAIN) 115 @Path("/logServer/{n}") 116 @Transactional(readOnly = true) 117 public String getDasishServerLog(@PathParam("n") int n) throws IOException { 118 return logFile("eu.dasish.annotation.backend.logServerLocation", n); 119 } 120 121 ////////////////////////////////// 122 @PUT 123 @Produces(MediaType.TEXT_XML) 124 @Path("account/{userId}/make/{account}") 125 @Transactional(readOnly = true) 126 public String updateUsersAccount(@PathParam("userId") String userId, @PathParam("account") String account) throws IOException { 99 127 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 100 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 128 String remoteUser = httpServletRequest.getRemoteUser(); 129 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 130 if (userID != null) { 131 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); 132 if (typeOfAccount.equals(admin)) { 133 final boolean update = dbIntegrityService.updateAccount(UUID.fromString(userId), account); 134 return (update ? "The account is updated" : "The account is not updated, see the log."); 135 } else { 136 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is not admin, and therefore cannot perform this request."); 137 return null; 138 } 139 } else { 140 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 141 return null; 142 } 143 144 } 145 146 /////////////////////////////////////////////////// 147 private String logFile(String location, int n) throws IOException{ 148 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 149 String remoteUser = httpServletRequest.getRemoteUser(); 150 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 101 151 if (userID != null) { 102 152 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID); 103 153 if (typeOfAccount.equals(admin) || typeOfAccount.equals(developer)) { 104 BufferedReader reader = new BufferedReader(new FileReader(context.getInitParameter( "eu.dasish.annotation.backend.logLocation")));154 BufferedReader reader = new BufferedReader(new FileReader(context.getInitParameter(location))); 105 155 List<String> lines = new ArrayList<String>(); 106 156 StringBuilder result = new StringBuilder(); … … 119 169 120 170 } else { 121 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged 171 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request."); 122 172 return null; 123 173 } 124 174 } else { 125 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged 175 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 126 176 return null; 127 } 128 177 } 129 178 } 130 131 @PUT132 @Produces(MediaType.TEXT_XML)133 @Path("account/{userId}/make/{account}")134 @Transactional(readOnly = true)135 public String updateUsersAccount(@PathParam("userId") String userId, @PathParam("account") String account) throws IOException {136 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());137 Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());138 if (userID != null) {139 String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID);140 if (typeOfAccount.equals(admin)) {141 final boolean update = dbIntegrityService.updateAccount(UUID.fromString(userId), account);142 return (update ? "The account is updated" : "The account is not updated, see the log.");143 } else {144 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged in user is not admin, and therefore cannot perform this request.");145 return null;146 }147 } else {148 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");149 return null;150 }151 152 }153 154 155 179 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r4252 r4281 44 44 import javax.xml.bind.JAXBElement; 45 45 import javax.xml.parsers.ParserConfigurationException; 46 import org.slf4j.Logger; 47 import org.slf4j.LoggerFactory; 46 48 import org.springframework.beans.factory.annotation.Autowired; 47 49 import org.springframework.stereotype.Component; … … 69 71 @Context 70 72 private UriInfo uriInfo; 73 private final Logger logger = LoggerFactory.getLogger(TargetResource.class); 71 74 72 75 public void setHttpRequest(HttpServletRequest request) { … … 82 85 @Path("{targetid: " + BackendConstants.regExpIdentifier + "}") 83 86 @Transactional(readOnly = true) 84 public JAXBElement<Target> getTarget(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException { 85 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 86 if (remoteUserID != null) { 87 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 88 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 87 public JAXBElement<Target> getTarget(@PathParam("targetid") String externalIdentifier) throws SQLException, IOException { 88 String remoteUser = httpServletRequest.getRemoteUser(); 89 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 90 if (remoteUserID != null) { 91 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 92 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier)); 89 93 if (targetID != null) { 90 94 final Target target = dbIntegrityService.getTarget(targetID); 91 95 return new ObjectFactory().createTarget(target); 92 96 } else { 93 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 94 return null; 95 } 96 } else { 97 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 97 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database"); 98 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + externalIdentifier + " is not found in the database"); 99 return null; 100 } 101 } else { 102 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 103 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 98 104 return null; 99 105 } … … 105 111 @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/versions") 106 112 @Transactional(readOnly = true) 107 public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException { 108 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 109 if (remoteUserID != null) { 110 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 111 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier)); 113 public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String externalIdentifier) throws SQLException, IOException { 114 String remoteUser = httpServletRequest.getRemoteUser(); 115 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 116 if (remoteUserID != null) { 117 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 118 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier)); 112 119 if (targetID != null) { 113 120 final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID); 114 121 return new ObjectFactory().createReferenceList(siblings); 115 122 } else { 116 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 117 return null; 118 } 119 } else { 120 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 123 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database"); 124 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + externalIdentifier + " is not found in the database"); 125 return null; 126 } 127 } else { 128 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 129 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 121 130 return null; 122 131 } … … 145 154 @PathParam("fragmentDescriptor") String fragmentDescriptor, 146 155 MultiPart multiPart) throws SQLException, IOException { 147 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 156 String remoteUser = httpServletRequest.getRemoteUser(); 157 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 148 158 if (remoteUserID != null) { 149 159 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 150 160 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier)); 151 CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class); 152 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity(); 153 InputStream cachedSource = bpe.getInputStream(); 154 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 155 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 156 return new ObjectFactory() 157 .createCashedRepresentationInfo(cachedInfo); 158 } else { 159 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 161 if (targetID != null) { 162 CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class); 163 BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity(); 164 InputStream cachedSource = bpe.getInputStream(); 165 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource); 166 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 167 return new ObjectFactory() 168 .createCashedRepresentationInfo(cachedInfo); 169 } else { 170 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + targetIdentifier + " is not found in the database"); 171 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + targetIdentifier + " is not found in the database"); 172 return null; 173 } 174 } else { 175 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 176 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 160 177 return null; 161 178 } … … 167 184 public String deleteCachedForTarget(@PathParam("targetid") String targetExternalIdentifier, 168 185 @PathParam("cachedid") String cachedExternalIdentifier) throws SQLException, IOException { 169 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 186 String remoteUser = httpServletRequest.getRemoteUser(); 187 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 170 188 if (remoteUserID != null) { 171 189 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); … … 178 196 return result + " pair(s) target-cached deleted."; 179 197 } else { 180 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database"); 198 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + cachedExternalIdentifier + " is not found in the database"); 199 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id " + cachedExternalIdentifier + " is not found in the database"); 181 200 return null; 182 201 } 183 202 } else { 184 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database"); 185 return null; 186 } 187 } else { 203 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + cachedExternalIdentifier + " is not found in the database"); 204 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id " + targetExternalIdentifier + " is not found in the database"); 205 return null; 206 } 207 } else { 208 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 188 209 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 189 210 return null; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
r4264 r4281 42 42 import javax.xml.bind.JAXBElement; 43 43 import javax.xml.parsers.ParserConfigurationException; 44 import org.slf4j.Logger; 45 import org.slf4j.LoggerFactory; 44 46 import org.springframework.beans.factory.annotation.Autowired; 45 47 import org.springframework.stereotype.Component; … … 64 66 private UriInfo uriInfo; 65 67 68 private final Logger logger = LoggerFactory.getLogger(UserResource.class); 69 70 66 71 final private String admin = "admin"; 67 72 … … 77 82 @Path("{userid}") 78 83 @Transactional(readOnly = true) 79 public JAXBElement<User> getUser(@PathParam("userid") String ExternalIdentifier) throws SQLException, IOException { 80 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 84 public JAXBElement<User> getUser(@PathParam("userid") String externalIdentifier) throws SQLException, IOException { 85 String remoteUser = httpServletRequest.getRemoteUser(); 86 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 81 87 if (remoteUserID != null) { 82 88 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 83 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString( ExternalIdentifier));89 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier)); 84 90 if (userID != null) { 85 91 final User user = dbIntegrityService.getUser(userID); 86 92 return new ObjectFactory().createUser(user); 87 93 } else { 88 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 89 return null; 90 } 91 } else { 92 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 94 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 95 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 96 return null; 97 } 98 } else { 99 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 100 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 93 101 return null; 94 102 } … … 100 108 @Transactional(readOnly = true) 101 109 public JAXBElement<User> getUserByInfo(@QueryParam("email") String email) throws SQLException, IOException { 102 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 110 String remoteUser = httpServletRequest.getRemoteUser(); 111 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 103 112 if (remoteUserID != null) { 104 113 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); … … 107 116 return new ObjectFactory().createUser(user); 108 117 } else { 118 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given info is not found in the database"); 109 119 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database"); 110 120 return null; 111 121 } 112 122 } else { 113 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 123 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 124 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 114 125 return null; 115 126 } … … 120 131 @Path("{userid}/current") 121 132 @Transactional(readOnly = true) 122 public JAXBElement<CurrentUserInfo> getCurrentUserInfo(@PathParam("userid") String ExternalIdentifier) throws IOException { 123 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 133 public JAXBElement<CurrentUserInfo> getCurrentUserInfo(@PathParam("userid") String externalIdentifier) throws IOException { 134 String remoteUser = httpServletRequest.getRemoteUser(); 135 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 124 136 if (remoteUserID != null) { 125 137 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 126 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString( ExternalIdentifier));138 final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier)); 127 139 if (userID != null) { 128 140 final CurrentUserInfo userInfo = new CurrentUserInfo(); … … 131 143 return new ObjectFactory().createCurrentUserInfo(userInfo); 132 144 } else { 133 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 134 return null; 135 } 136 } else { 137 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 145 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 146 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 147 return null; 148 } 149 } else { 150 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database"); 151 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 138 152 return null; 139 153 } … … 145 159 @Path("{remoteId}") 146 160 public JAXBElement<User> addUser(@PathParam("remoteId") String remoteId, User user) throws SQLException, IOException { 147 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 161 String remoteUser = httpServletRequest.getRemoteUser(); 162 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 148 163 if (remoteUserID != null) { 149 164 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 154 169 return new ObjectFactory().createUser(addedUser); 155 170 } else { 156 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "The user with the given e-mail already exists in the database");157 return null; 158 } 159 } else { 160 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged 161 return null; 162 } 163 } else { 164 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged 171 httpServletResponse.sendError(HttpServletResponse.SC_CONFLICT, "The user canot be added to the database, (possibly) because a user with the given e-mail already exist in the database."); 172 return null; 173 } 174 } else { 175 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to add a user to the database"); 176 return null; 177 } 178 } else { 179 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 165 180 return null; 166 181 } … … 172 187 @Path("") 173 188 public JAXBElement<User> updateUser(User user) throws IOException { 174 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 189 String remoteUser = httpServletRequest.getRemoteUser(); 190 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 175 191 if (remoteUserID != null) { 176 192 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 181 197 return new ObjectFactory().createUser(addedUser); 182 198 } else { 183 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 184 return null; 185 } 186 } else { 187 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to update a user info in the database"); 188 return null; 189 } 190 } else { 191 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 199 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id is not found in the database"); 200 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 201 return null; 202 } 203 } else { 204 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 205 return null; 206 } 207 } else { 208 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 192 209 return null; 193 210 } … … 197 214 @Path("{userId}") 198 215 public String deleteUser(@PathParam("userId") String externalIdentifier) throws IOException { 199 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 216 String remoteUser = httpServletRequest.getRemoteUser(); 217 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 200 218 if (remoteUserID != null) { 201 219 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 206 224 return "There is " + result.toString() + " row deleted"; 207 225 } else { 208 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database"); 209 return null; 210 } 211 } else { 212 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged in user does not have admin rights to update a user info in the database"); 213 return null; 214 } 215 } else { 216 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database"); 226 AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database"); 227 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 228 return null; 229 } 230 } else { 231 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 232 return null; 233 } 234 } else { 235 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 217 236 return null; 218 237 } … … 223 242 @Path("{userId}/safe") 224 243 public String deleteUserSafe(@PathParam("userId") String externalIdentifier) throws IOException { 225 final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser()); 244 String remoteUser = httpServletRequest.getRemoteUser(); 245 Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); 226 246 if (remoteUserID != null) { 227 247 if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) { … … 232 252 return "There is " + result.toString() + " row deleted"; 233 253 } else { 234 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database");235 return null; 236 } 237 } else { 238 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged 239 return null; 240 } 241 } else { 242 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged 254 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id " + externalIdentifier + " is not found in the database"); 255 return null; 256 } 257 } else { 258 httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user does not have admin rights to update a user info in the database"); 259 return null; 260 } 261 } else { 262 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database"); 243 263 return null; 244 264 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/resources/log4j.xml
r4010 r4281 19 19 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 20 20 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 21 21 22 <appender class="org.apache.log4j.DailyRollingFileAppender" name="ROOT"> 22 <param value="${catalina.base}/logs/dasish Annotator.log" name="File"/>23 <param value="${catalina.base}/logs/dasishRoot.log" name="File"/> 23 24 <layout class="org.apache.log4j.PatternLayout"> 24 25 <param value="%d %p [%c#%M:%L] - %m%n" name="ConversionPattern"/> 25 26 </layout> 26 27 </appender> 27 <logger name="eu.dasish.annotation.backend.rest.AnnotationResource"> 28 <level value="info"/> 28 29 <appender class="org.apache.log4j.DailyRollingFileAppender" name="DATABASE"> 30 <param value="${catalina.base}/logs/dasishDatabase.log" name="File"/> 31 <layout class="org.apache.log4j.PatternLayout"> 32 <param value="%d %p [%c#%M:%L] - %m%n" name="ConversionPattern"/> 33 </layout> 34 </appender> 35 36 <appender class="org.apache.log4j.DailyRollingFileAppender" name="SERVER"> 37 <param value="${catalina.base}/logs/dasishServer.log" name="File"/> 38 <layout class="org.apache.log4j.PatternLayout"> 39 <param value="%d %p [%c#%M:%L] - %m%n" name="ConversionPattern"/> 40 </layout> 41 </appender> 42 43 44 <logger name="eu.dasish.annotation.backend.rest.AnnotationResource" additivity="false"> 45 <level value="debug"/> 46 <appender-ref ref="DATABASE"/> 29 47 </logger> 30 <logger name="eu.dasish.annotation.backend.rest.TargetResource"> 31 <level value="info"/> 48 <logger name="eu.dasish.annotation.backend.rest.TargetResource" additivity="false"> 49 <level value="debug"/> 50 <appender-ref ref="DATABASE"/> 32 51 </logger> 33 <logger name="eu.dasish.annotation.backend.rest.UserResource"> 34 <level value="info"/> 52 <logger name="eu.dasish.annotation.backend.rest.UserResource" additivity="false"> 53 <level value="debug"/> 54 <appender-ref ref="DATABASE"/> 35 55 </logger> 36 <logger name="eu.dasish.annotation.backend.rest.CachedRepresentationResource"> 37 <level value="info"/> 56 <logger name="eu.dasish.annotation.backend.rest.CachedRepresentationResource" additivity="false"> 57 <level value="debug"/> 58 <appender-ref ref="DATABASE"/> 38 59 </logger> 60 <logger name="eu.dasish.annotation.backend.rest.DebugResource" additivity="false"> 61 <level value="debug"/> 62 <appender-ref ref="DATABASE"/> 63 </logger> 64 <logger name="org.springframework.jdbc.core.JdbcTemplate" additivity="false"> 65 <level value="error"/> 66 <appender-ref ref="DATABASE"/> 67 </logger> 68 <logger name="eu.dasish.annotation.backend.dao.impl.JdbcResourceDao" additivity="false"> 69 <level value="debug"/> 70 <appender-ref ref="DATABASE"/> 71 </logger> 72 73 <logger name="eu.dasish.annotation.backend.dao.impl.JdbcAnnotationDao" additivity="false"> 74 <level value="debug"/> 75 <appender-ref ref="DATABASE"/> 76 </logger> 77 78 <logger name="javax.servlet.http.HttpServletResponse" additivity="false"> 79 <level value="debug"/> 80 <appender-ref ref="SERVER"/> 81 <appender-ref ref="DATABASE"/> 82 </logger> 83 84 85 86 <logger name="org.springframework.beans.factory.xml.XmlBeanDefinitionReader" additivity="false"> 87 <level value="off"/> 88 <appender-ref ref="SERVER"/> 89 <appender-ref ref="DATABASE"/> 90 </logger> 91 92 <logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory" additivity="false"> 93 <level value="off"/> 94 <appender-ref ref="SERVER"/> 95 <appender-ref ref="DATABASE"/> 96 </logger> 97 98 <logger name="org.springframework.web.context.ContextLoader" additivity="false"> 99 <level value="off"/> 100 <appender-ref ref="SERVER"/> 101 <appender-ref ref="DATABASE"/> 102 </logger> 103 104 <logger name="org.springframework.web.context.support.XmlWebApplicationContext" additivity="false"> 105 <level value="off"/> 106 <appender-ref ref="SERVER"/> 107 <appender-ref ref="DATABASE"/> 108 </logger> 109 110 39 111 <root> 40 112 <level value="info"/> 41 <appender-ref ref="ROOT"/> 113 <appender-ref ref="ROOT"/> 114 <appender-ref ref="SERVER"/> 115 <appender-ref ref="DATABASE"/> 42 116 </root> 117 43 118 </log4j:configuration> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml
r4267 r4281 31 31 </context-param> 32 32 <context-param> 33 <param-name>eu.dasish.annotation.backend.logLocation</param-name> 34 <param-value>/Library/tomcat/Home/logs/dasishAnnotator.log</param-value> 33 <param-name>eu.dasish.annotation.backend.logDatabaseLocation</param-name> 34 <param-value>${catalina.base}/logs/dasishDatabase.log</param-value> 35 </context-param> 36 <context-param> 37 <param-name>eu.dasish.annotation.backend.logServerLocation</param-name> 38 <param-value>${catalina.base}/logs/dasishServer.log</param-value> 35 39 </context-param> 36 40 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp
r4267 r4281 62 62 <br> 63 63 <b>Debugging URI's (only for developers)</b><br> 64 GET <a href="api/debug/remoteID">api/debug/remoteID</a> <br> 64 65 GET <a href="api/debug/annotations">api/debug/annotations</a> <br> 65 GET <a href="api/debug/log/16">api/debug/log/16</a> <br> 66 GET <a href="api/debug/logDatabase/32">api/debug/logDatabase/32</a> <br> 67 GET <a href="api/debug/logServer/32">api/debug/logServer/32</a> <br> 66 68 </body> 67 69 </html> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r4276 r4281 206 206 assertEquals(null, annotaionIdNE); 207 207 208 final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null); 209 assertEquals(null, annotaionIdNull); 208 210 209 } 211 210 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java
r4173 r4281 81 81 assertEquals(null, testTwo); 82 82 83 Number testThree = jdbcUserDao.getInternalID(null);84 assertEquals(null, testThree);85 83 } 86 84 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r4276 r4281 111 111 112 112 oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(any(UUID.class))); 113 will(returnValue(2)); 113 will(returnValue(2)); 114 115 oneOf(mockDbIntegrityService).getTypeOfUserAccount(3); 116 will(returnValue("developer")); 114 117 115 118 oneOf(mockDbIntegrityService).getPermission(2, 3); … … 155 158 156 159 oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(aNonNull(UUID.class))); 157 will(returnValue(5)); 158 160 will(returnValue(5)); 161 162 159 163 oneOf(mockDbIntegrityService).getPermission(5, 3); 160 164 will(returnValue(Permission.OWNER));
Note: See TracChangeset
for help on using the changeset viewer.