Changeset 4281


Ignore:
Timestamp:
01/17/14 18:46:22 (10 years ago)
Author:
olhsha
Message:

Adjusting logging. Server responds are redirected to a separate server logging files as well.

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  
    112112    public int addTargetCachedRepresentation(Number TargetID, Number cachedID, String fragmentDescription);
    113113   
    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   
    122115   
    123116   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4276 r4281  
    283283            AnnotationInfoList result = new AnnotationInfoList();
    284284            for (Number annotationID : annotationIDs) {
    285                 Number ownerID = annotationDao.getOwner(annotationID);               
     285                Number ownerID = annotationDao.getOwner(annotationID);
    286286                ReferenceList targets = getAnnotationTargets(annotationID);
    287287                AnnotationInfo annotationInfo = annotationDao.getAnnotationInfoWithoutTargets(annotationID);
    288288                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!!!!");
    293293                }
    294294                result.getAnnotationInfo().add(annotationInfo);
     
    371371
    372372    ///// UPDATERS /////////////////
    373    
    374373    @Override
    375374    public boolean updateAccount(UUID userExternalID, String account) {
    376375        return userDao.updateAccount(userExternalID, account);
    377376    }
    378    
     377
    379378    @Override
    380379    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) {
     
    462461        Number annotationID = annotationDao.addAnnotation(annotation);
    463462        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        }
    465468        int affectedPermissions = annotationDao.addAnnotationPrincipalPermission(annotationID, userID, Permission.OWNER);
    466469        return annotationID;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r4276 r4281  
    3636import java.util.UUID;
    3737import javax.sql.DataSource;
     38import org.slf4j.Logger;
     39import org.slf4j.LoggerFactory;
    3840import org.springframework.jdbc.core.RowMapper;
    3941
     
    4547public class JdbcAnnotationDao extends JdbcResourceDao implements AnnotationDao {
    4648
     49    private  final Logger loggerAnnotationDao = LoggerFactory.getLogger(JdbcAnnotationDao.class);
     50   
    4751    public JdbcAnnotationDao(DataSource dataSource) {
    4852        setDataSource(dataSource);
     
    6569            return getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, annotationID);
    6670        } else {
     71            loggerAnnotationDao.debug(nullArgument);
    6772            return null;
    6873        }
     
    7378    public List<Map<Number, String>> getPermissions(Number annotationID) {
    7479        if (annotationID == null) {
     80            loggerAnnotationDao.debug(nullArgument);
    7581            return null;
    7682        }
     
    9096    @Override
    9197    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       
    95108        StringBuilder sql = new StringBuilder("SELECT ");
    96109        sql.append(permission).append(" FROM ").append(permissionsTableName).append(" WHERE ").
     
    115128    @Override
    116129    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);
    118137            return null;
    119138        }
     
    154173
    155174        if (annotationIDs == null) {
     175            loggerAnnotationDao.debug("annotationIDs: "+nullArgument);
    156176            return null;
    157177        } else {
     
    193213    //////////////////////////////
    194214    @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()) {
    200221            return new ArrayList<Number>();
    201222        }
    202         String values = makeListOfValues(TargetIDs);
     223        String values = makeListOfValues(targetIDs);
    203224        StringBuilder query = new StringBuilder("SELECT DISTINCT ");
    204225        query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" IN ");
     
    210231    public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) {
    211232        if (annotationID == null) {
     233            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    212234            return null;
    213235        }
     
    247269    public List<String> getAnnotationREFs(List<Number> annotationIDs) {
    248270        if (annotationIDs == null) {
     271           loggerAnnotationDao.debug("annotationIDs: "+nullArgument);
    249272            return null;
    250273        }
     
    269292    public Annotation getAnnotationWithoutTargetsAndPermissions(Number annotationID) {
    270293        if (annotationID == null) {
     294            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    271295            return null;
    272296        }
     
    307331    public Number  getOwner(Number annotationID){
    308332        if (annotationID == null) {
     333            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    309334            return null;
    310335        }
     
    389414    public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) {
    390415
     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       
    391431        Map<String, Object> params = new HashMap<String, Object>();
    392432
     
    416456
    417457        String[] body = retrieveBodyComponents(annotation.getBody());
     458       
     459        if (annotation == null) {
     460            loggerAnnotationDao.debug("annotation: "+nullArgument);
     461            return 0;
     462        }
    418463
    419464        // generate a new annotation ID
     
    437482    @Override
    438483    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       
    439495        Map<String, Object> paramsAnnotationsTargets = new HashMap<String, Object>();
    440496        paramsAnnotationsTargets.put("annotationId", annotationID);
     
    448504    @Override
    449505    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       
    450523        Map<String, Object> paramsPermissions = new HashMap<String, Object>();
    451524        paramsPermissions.put("annotationId", annotationID);
     
    470543            return (getSimpleJdbcTemplate().update(sqlAnnotation.toString(), annotationID));
    471544        } else {
     545            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    472546            return 0;
    473547        }
     
    481555            return getSimpleJdbcTemplate().update(sqlTargetTargets.toString(), annotationID); // # removed "annotations_target_Targets" rows
    482556        } else {
     557            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    483558            return 0;
    484559        }
     
    493568            return getSimpleJdbcTemplate().update(sqlPermissions.toString(), annotationID); // removed "permission" rows
    494569        } else {
     570            loggerAnnotationDao.debug("annotationID: "+nullArgument);
    495571            return 0;
    496572        }
     
    512588                result[1] = textBody.getMimeType();
    513589            } 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. ");
    515591                return null;
    516592            }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java

    r3936 r4281  
    3232import org.springframework.jdbc.core.RowMapper;
    3333import org.apache.commons.io.IOUtils;
     34import org.slf4j.Logger;
     35import org.slf4j.LoggerFactory;
    3436
    3537/**
     
    3941public class JdbcCachedRepresentationDao extends JdbcResourceDao implements CachedRepresentationDao {
    4042
     43    private  final Logger loggerCachedDao = LoggerFactory.getLogger(JdbcCachedRepresentationDao.class);
     44   
     45   
     46   
    4147    public JdbcCachedRepresentationDao(DataSource dataSource) {
    4248        setDataSource(dataSource);
     
    5359    @Override
    5460    public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID) {
    55 
     61        if (internalID == null) {
     62            loggerCachedDao.debug("internalID: " + nullArgument);
     63            return null;
     64        }
    5665        StringBuilder sql = new StringBuilder("SELECT ");
    5766        sql.append(cachedRepresentationStar).append(" FROM ").append(cachedRepresentationTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
     
    7887    @Override
    7988    public InputStream getCachedRepresentationBlob(Number internalID) {
    80 
     89       
     90        if (internalID == null) {
     91            loggerCachedDao.debug("internalID: " + nullArgument);
     92            return null;
     93        }
    8194        StringBuilder sql = new StringBuilder("SELECT ");
    8295        sql.append(file_).append(" FROM ").append(cachedRepresentationTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
     
    98111    //////////////////////////////////////
    99112    private boolean cachedIsInUse(Number cachedID) {
     113       
     114        if (cachedID == null) {
     115            loggerCachedDao.debug("cachedID: " + nullArgument);
     116            return false;
     117        }
     118       
    100119        StringBuilder sql = new StringBuilder("SELECT ");
    101120        sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
     
    125144
    126145        } catch (IOException ioe) {
     146            loggerCachedDao.debug(ioe + "while adding cached representation");
    127147            return null;
    128148        }
     
    133153    @Override
    134154    public int deleteCachedRepresentation(Number internalID) {
     155       
     156        if (internalID == null) {
     157            loggerCachedDao.debug("internalID: " + nullArgument);
     158            return 0;
     159        }
     160       
    135161        if (cachedIsInUse(internalID)) {
     162            loggerCachedDao.debug("Cached Repr. is in use, and cannot be deleted.");
    136163            return 0;
    137164        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r4276 r4281  
    9898    protected String resourceTableName = null;
    9999    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.";
    101102
    102103    ////////
     
    110111    @Override
    111112    public Number getInternalID(UUID externalId) {
    112         if (externalId == null) {
    113             return null;
    114         }
    115113        StringBuilder sql = new StringBuilder("SELECT ");
    116114        sql.append(internalIdName).append(" FROM ").append(resourceTableName).append(" WHERE ").append(external_id).append("= ? LIMIT 1");
    117115        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
    119123    }
    120124
     
    122126    @Override
    123127    public UUID getExternalID(Number internalId) {
     128        if (internalId == null) {
     129            _logger.debug("internalId: " + nullArgument);
     130            return null;
     131        }
    124132        StringBuilder sql = new StringBuilder("SELECT ");
    125133        sql.append(external_id).append(" FROM ").append(resourceTableName).append(" WHERE ").append(internalIdName).append("= ? LIMIT 1");
     
    132140    public Number getInternalIDFromURI(String uri) {
    133141        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        }
    135148    }
    136149
     
    138151    @Override
    139152    public String getURIFromInternalID(Number internalID) {
     153        if (internalID == null) {
     154            _logger.debug("internalID: " + nullArgument);
     155            return null;
     156        }
    140157        return externalIDtoURI(getExternalID(internalID).toString());
    141158    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcTargetDao.java

    r4188 r4281  
    3131import javax.xml.datatype.DatatypeConfigurationException;
    3232import javax.xml.datatype.XMLGregorianCalendar;
     33import org.slf4j.Logger;
     34import org.slf4j.LoggerFactory;
    3335import org.springframework.jdbc.core.RowMapper;
    3436
     
    3941public class JdbcTargetDao extends JdbcResourceDao implements TargetDao {
    4042
     43    private final Logger loggerTargetDao = LoggerFactory.getLogger(JdbcTargetDao.class);
     44
    4145    public JdbcTargetDao(DataSource dataTarget) {
    4246        setDataSource(dataTarget);
     
    5357    @Override
    5458    public Target getTarget(Number internalID) {
     59
     60        if (internalID == null) {
     61            loggerTargetDao.debug("internalID: " + nullArgument);
     62            return null;
     63        }
     64
    5565        StringBuilder sql = new StringBuilder("SELECT ");
    5666        sql.append(targetStar).append(" FROM ").append(targetTableName).append(" WHERE ").append(target_id).append("= ? LIMIT 1");
     
    7080    @Override
    7181    public String getLink(Number internalID) {
     82
     83        if (internalID == null) {
     84            loggerTargetDao.debug("internalID: " + nullArgument);
     85            return null;
     86        }
     87
    7288        StringBuilder sql = new StringBuilder("SELECT ");
    7389        sql.append(targetStar).append(" FROM ").append(targetTableName).append(" WHERE ").append(target_id).append("= ? LIMIT 1");
     
    86102    public List<Number> getCachedRepresentations(Number targetID) {
    87103
     104        if (targetID == null) {
     105            loggerTargetDao.debug("targetID: " + nullArgument);
     106            return null;
     107        }
     108
    88109        String sql = "SELECT " + cached_representation_id + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?";
    89110        return getSimpleJdbcTemplate().query(sql, cachedIDRowMapper, targetID);
     
    92113    @Override
    93114    public Map<Number, String> getCachedRepresentationFragmentPairs(Number targetID) {
     115
     116        if (targetID == null) {
     117            loggerTargetDao.debug("targetID: " + nullArgument);
     118            return null;
     119        }
     120
    94121        Map<Number, String> result = new HashMap<Number, String>();
    95122        String sql = "SELECT " + cached_representation_id + "," + fragment_descriptor_in_cached + " FROM " + targetsCachedRepresentationsTableName + " WHERE " + target_id + " = ?";
     
    113140    public List<TargetInfo> getTargetInfos(List<Number> targets) {
    114141        if (targets == null) {
     142            loggerTargetDao.debug("targets: " + nullArgument);
    115143            return null;
    116144        }
     
    136164    @Override
    137165    public List<Number> getTargetsReferringTo(String word) {
     166        if (word == null) {
     167            loggerTargetDao.debug("word: " + nullArgument);
     168            return null;
     169        }
    138170        String searchTerm = "%" + word + "%";
    139171        StringBuilder sql = new StringBuilder("SELECT ");
     
    145177    @Override
    146178    public List<Number> getTargetsForLink(String link) {
     179        if (link == null) {
     180            loggerTargetDao.debug("link: " + nullArgument);
     181            return null;
     182        }
     183
    147184        StringBuilder sql = new StringBuilder("SELECT ");
    148185        sql.append(target_id).append(" FROM ").append(targetTableName).append(" WHERE ").append(link_uri).append(" =  ? ");
     
    153190    @Override
    154191    public boolean targetIsInUse(Number targetID) {
     192        if (targetID == null) {
     193            loggerTargetDao.debug("targetID: " + nullArgument);
     194            return false;
     195        }
     196
     197
    155198        StringBuilder sqlAnnotations = new StringBuilder("SELECT ");
    156199        sqlAnnotations.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(target_id).append(" = ? LIMIT 1");
     
    165208    @Override
    166209    public Number addTarget(Target target) {
     210       
     211        if (target == null) {
     212            loggerTargetDao.debug("target: " + nullArgument);
     213            return null;
     214        }
     215
     216       
    167217        UUID externalID = UUID.randomUUID();
    168218        String[] linkParts = splitLink(target.getLink());
     
    181231    @Override
    182232    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         
    183243        Map<String, Object> paramsJoint = new HashMap<String, Object>();
    184244        paramsJoint.put("targetId", targetID);
     
    189249    }
    190250
    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   
    201252
    202253////////////////////// DELETERS ////////////////////////
    203254    @Override
    204255    public int deleteTarget(Number internalID) {
     256        if (internalID == null) {
     257            loggerTargetDao.debug("internalID: " + nullArgument);
     258            return 0;
     259        }
     260       
    205261        if (targetIsInUse(internalID)) {
     262            loggerTargetDao.debug("The target is in use, and cannot be deleted.");
    206263            return 0;
    207264        }
     
    215272    @Override
    216273    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       
    220286        Map<String, Object> paramsJoint = new HashMap<String, Object>();
    221287        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  
    2727import java.util.UUID;
    2828import javax.sql.DataSource;
     29import org.slf4j.Logger;
     30import org.slf4j.LoggerFactory;
    2931import org.springframework.jdbc.core.RowMapper;
    3032
     
    3537public class JdbcUserDao extends JdbcResourceDao implements UserDao {
    3638
     39    private final Logger loggerUserDao = LoggerFactory.getLogger(JdbcUserDao.class);
     40
    3741    public JdbcUserDao(DataSource dataSource) {
    3842        setDataSource(dataSource);
     
    4953    @Override
    5054    public User getUser(Number internalID) {
     55
     56        if (internalID == null) {
     57            loggerUserDao.debug("internalID: " + nullArgument);
     58            return null;
     59        }
     60
    5161        StringBuilder sql = new StringBuilder("SELECT ");
    5262        sql.append(principalStar).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
     
    7585    @Override
    7686    public boolean userIsInUse(Number userID) {
     87
     88        if (userID == null) {
     89            loggerUserDao.debug("userID: " + nullArgument);
     90            return false;
     91        }
     92
    7793        StringBuilder sqlPermissions = new StringBuilder("SELECT ");
    7894        sqlPermissions.append(principal_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
     
    93109    @Override
    94110    public boolean userExists(User user) {
     111        if (user == null) {
     112            loggerUserDao.debug("user: " + nullArgument);
     113            return false;
     114        }
     115
    95116        String emailCriterion = user.getEMail().toLowerCase();
    96117        StringBuilder sqlTargets = new StringBuilder("SELECT ");
     
    106127    @Override
    107128    public String getRemoteID(Number internalID) {
     129
     130        if (internalID == null) {
     131            loggerUserDao.debug("internalID: " + nullArgument);
     132            return null;
     133        }
     134
    108135        StringBuilder requestDB = new StringBuilder("SELECT ");
    109136        requestDB.append(remote_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
     
    120147    @Override
    121148    public Number getUserInternalIDFromRemoteID(String remoteID) {
     149
     150        if (remoteID == null) {
     151            loggerUserDao.debug("remoteID: " + nullArgument);
     152            return null;
     153        }
     154
    122155        StringBuilder requestDB = new StringBuilder("SELECT ");
    123156        requestDB.append(principal_id).append(" FROM ").append(principalTableName).append(" WHERE ").append(remote_id).append("= ? LIMIT 1");
     
    128161    @Override
    129162    public String getTypeOfUserAccount(Number internalID) {
     163
     164        if (internalID == null) {
     165            loggerUserDao.debug("internalID: " + nullArgument);
     166            return null;
     167        }
     168
    130169        StringBuilder requestDB = new StringBuilder("SELECT ");
    131170        requestDB.append(account).append(" FROM ").append(principalTableName).append(" WHERE ").append(principal_id).append("= ? LIMIT 1");
     
    143182    @Override
    144183    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
    145195        UUID externalIdentifier = UUID.randomUUID();
    146196        String newExternalIdentifier = externalIdentifier.toString();
     
    162212    @Override
    163213    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
    164225        if (!account.equals(admin) && !account.equals(developer) && !account.equals(user)) {
    165226            logger.error("the given type of account '" + account + "' does not exist.");
     
    191252    @Override
    192253    public Number updateUser(User user) {
     254
     255        if (user == null) {
     256            loggerUserDao.debug("user: " + nullArgument);
     257            return null;
     258        }
     259
    193260        Number principalID = this.getInternalIDFromURI(user.getURI());
    194261        StringBuilder sql = new StringBuilder("UPDATE ");
     
    204271    @Override
    205272    public int deleteUser(Number internalID) {
     273        if (internalID == null) {
     274            loggerUserDao.debug("internalID: " + nullArgument);
     275            return 0;
     276        }
     277
    206278
    207279        StringBuilder sql = new StringBuilder("DELETE FROM ");
     
    213285    @Override
    214286    public int deleteUserSafe(Number internalID) {
     287         
     288        if (internalID == null) {
     289            loggerUserDao.debug("internalID: " + nullArgument);
     290            return 0;
     291        }
     292       
     293       
    215294        if (userIsInUse(internalID)) {
     295            loggerUserDao.debug("User is in use, and cannot be deleted.");
    216296            return 0;
    217297        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4276 r4281  
    8383    @Context
    8484    private ServletContext context;
    85    
    8685    final String default_permission = "reader";
    8786    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
    8990    public void setUriInfo(UriInfo uriInfo) {
    9091        this.uriInfo = uriInfo;
     
    105106    public AnnotationResource() {
    106107    }
    107 
    108    
    109108
    110109    @GET
     
    112111    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
    113112    @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 {
    115114        URI baseURI = uriInfo.getBaseUri();
    116115        String baseURIstr = baseURI.toString();
    117116        dbIntegrityService.setServiceURI(baseURIstr);
    118         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier));
     117        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    119118        if (annotationID != null) {
    120119            String remoteUser = httpServletRequest.getRemoteUser();
    121120            final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    122121            if (userID != null) {
    123                 if (canRead(userID, annotationID)) {
     122                if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    124123                    final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
    125124                    JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
    126                     logger.info("getAnnotation method: OK");
    127125                    return rootElement;
    128126                } else {
     127                    loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    129128                    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    130129                    return null;
    131130                }
    132131            } 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");
    138139            return null;
    139140        }
     
    146147    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/targets")
    147148    @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));
    151152        if (annotationID != null) {
    152             final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     153            String remoteUser = httpServletRequest.getRemoteUser();
     154            final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    153155            if (userID != null) {
    154                 if (canRead(userID, annotationID)) {
     156                if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    155157                    final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
    156158                    logger.info("getAnnotationTargets method: OK");
    157159                    return new ObjectFactory().createTargetList(TargetList);
    158160                } else {
     161                    loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    159162                    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    160163                    return null;
    161164                }
    162165            } 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");
    168173            return null;
    169174        }
     
    184189
    185190        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    186         Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     191        String remoteUser = httpServletRequest.getRemoteUser();
     192        Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    187193        if (userID != null) {
    188194            UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null;
     
    192198            return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
    193199        } 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");
    195202            return null;
    196203        }
     
    203210    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions")
    204211    @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);
    209217        if (userID != null) {
    210218            if (annotationID != null) {
    211                 if (canRead(userID, annotationID)) {
     219                if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    212220                    final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
    213                     logger.info("getAnnotationPermissions method: OK");
     221                    logger.debug("getAnnotationPermissions method: OK");
    214222                    return new ObjectFactory().createPermissionList(permissionList);
    215223                } else {
     224                    loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    216225                    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    217226                    return null;
    218227                }
    219228            } 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");
    225236            return null;
    226237        }
     
    234245        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    235246        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);
    237249        if (userID != null) {
    238250            if (annotationID != null) {
     
    243255                    return result + " annotation(s) deleted.";
    244256                } else {
     257                    loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
    245258                    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
    246259                    return null;
    247260                }
    248261            } 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.");
    255270            return null;
    256271        }
     
    265280    public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws IOException {
    266281        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    267         final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     282        String remoteUser = httpServletRequest.getRemoteUser();
     283        Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    268284        if (userID != null) {
    269285            Number annotationID = dbIntegrityService.addUsersAnnotation(userID, annotation);
    270             logger.info("createAnnotation method: OK");
    271286            return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    272287        } 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.");
    274290            return null;
    275291        }
     
    288304
    289305        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.");
    291308            return null;
    292309        }
     
    295312        String ownerURI = annotation.getOwnerRef();
    296313        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.");
    297315            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.");
    298316            return null;
     
    302320        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    303321        if (annotationID != null) {
    304             final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     322            String remoteUser = httpServletRequest.getRemoteUser();
     323            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    305324            if (userID != null) {
    306325                if (isOwner(userID, annotationID)) {
    307326                    int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
    308                     logger.info("updateAnnotation method: OK");
    309327                    return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    310328
    311329                } 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.");
    321342            return null;
    322343        }
     
    331352        dbIntegrityService.setServiceURI(path);
    332353        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);
    334356        if (userID != null) {
    335357            if (annotationID != null) {
    336358                if (canWrite(userID, annotationID)) {
    337359                    int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
    338                     logger.info("updateAnnotationBody method: OK");
    339360                    return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    340361                } 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'.");
    341363                    httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
    342364                    return null;
    343365                }
    344366            } 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.");
    350374            return null;
    351375        }
     
    358382    public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws IOException {
    359383        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    360         final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     384        String remoteUser = httpServletRequest.getRemoteUser();
     385        Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    361386        if (remoteUserID != null) {
    362387            final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
     
    372397
    373398                    } 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'.");
    374400                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is  not its owner.");
    375401                        return null;
    376402                    }
    377403                } 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.");
    388417            return null;
    389418        }
     
    397426        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    398427        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);
    400430        if (remoteUserID != null) {
    401431            if (annotationID != null) {
     
    404434                    return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
    405435                } 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.");
    415448            return null;
    416449        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java

    r4252 r4281  
    3939import javax.xml.bind.JAXBElement;
    4040import javax.xml.parsers.ParserConfigurationException;
     41import org.slf4j.Logger;
     42import org.slf4j.LoggerFactory;
    4143import org.springframework.beans.factory.annotation.Autowired;
    4244import org.springframework.stereotype.Component;
     
    6062    @Context
    6163    private UriInfo uriInfo;
     64    private final Logger logger = LoggerFactory.getLogger(CachedRepresentationResource.class);
    6265
    6366    public void setHttpRequest(HttpServletRequest request) {
     
    7376    public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException {
    7477
    75         final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     78        String remoteUser = httpServletRequest.getRemoteUser();
     79        Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    7680        if (remoteUserID != null) {
    7781            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     
    8185                return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
    8286            } else {
     87                AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database");
    8388                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
    8489                return null;
    8590            }
    8691        } else {
     92            AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
    8793            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
    8894            return null;
     
    95101    @Transactional(readOnly = true)
    96102    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);
    98105        if (remoteUserID != null) {
    99106            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     
    105112                return result;
    106113            } 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");
    108116                return null;
    109117            }
    110118        } 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");
    112121            return null;
    113122        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DebugResource.java

    r4276 r4281  
    7575    public JAXBElement<AnnotationInfoList> getAllAnnotations() throws IOException {
    7676        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    77         Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     77        String remoteUser = httpServletRequest.getRemoteUser();
     78        Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    7879        if (userID != null) {
    7980            String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID);
     
    8283                return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
    8384            } else {
    84                 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged in user is neither developer nor admin, and therefore cannot perform this request.");
     85                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request.");
    8586                return null;
    8687            }
    8788        } else {
    88             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     89            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
    8990            return null;
    9091        }
     
    9495    @GET
    9596    @Produces(MediaType.TEXT_PLAIN)
    96     @Path("/log/{n}")
     97    @Path("/logDatabase/{n}")
    9798    @Transactional(readOnly = true)
    9899    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 {
    99127        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);
    101151        if (userID != null) {
    102152            String typeOfAccount = dbIntegrityService.getTypeOfUserAccount(userID);
    103153            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)));
    105155                List<String> lines = new ArrayList<String>();
    106156                StringBuilder result = new StringBuilder();
     
    119169
    120170            } else {
    121                 httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged in user is neither developer nor admin, and therefore cannot perform this request.");
     171                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user is neither developer nor admin, and therefore cannot perform this request.");
    122172                return null;
    123173            }
    124174        } else {
    125             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     175            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
    126176            return null;
    127         }
    128 
     177        }
    129178    }
    130    
    131     @PUT
    132     @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    
    155179}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java

    r4252 r4281  
    4444import javax.xml.bind.JAXBElement;
    4545import javax.xml.parsers.ParserConfigurationException;
     46import org.slf4j.Logger;
     47import org.slf4j.LoggerFactory;
    4648import org.springframework.beans.factory.annotation.Autowired;
    4749import org.springframework.stereotype.Component;
     
    6971    @Context
    7072    private UriInfo uriInfo;
     73    private final Logger logger = LoggerFactory.getLogger(TargetResource.class);
    7174
    7275    public void setHttpRequest(HttpServletRequest request) {
     
    8285    @Path("{targetid: " + BackendConstants.regExpIdentifier + "}")
    8386    @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));
    8993            if (targetID != null) {
    9094                final Target target = dbIntegrityService.getTarget(targetID);
    9195                return new ObjectFactory().createTarget(target);
    9296            } 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");
    98104            return null;
    99105        }
     
    105111    @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/versions")
    106112    @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));
    112119            if (targetID != null) {
    113120                final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
    114121                return new ObjectFactory().createReferenceList(siblings);
    115122            } 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");
    121130            return null;
    122131        }
     
    145154            @PathParam("fragmentDescriptor") String fragmentDescriptor,
    146155            MultiPart multiPart) throws SQLException, IOException {
    147         final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
     156        String remoteUser = httpServletRequest.getRemoteUser();
     157        Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    148158        if (remoteUserID != null) {
    149159            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    150160            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");
    160177            return null;
    161178        }
     
    167184    public String deleteCachedForTarget(@PathParam("targetid") String targetExternalIdentifier,
    168185            @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);
    170188        if (remoteUserID != null) {
    171189            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     
    178196                    return result + " pair(s) target-cached deleted.";
    179197                } 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");
    181200                    return null;
    182201                }
    183202            } 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");
    188209            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
    189210            return null;
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java

    r4264 r4281  
    4242import javax.xml.bind.JAXBElement;
    4343import javax.xml.parsers.ParserConfigurationException;
     44import org.slf4j.Logger;
     45import org.slf4j.LoggerFactory;
    4446import org.springframework.beans.factory.annotation.Autowired;
    4547import org.springframework.stereotype.Component;
     
    6466    private UriInfo uriInfo;
    6567   
     68    private final Logger logger = LoggerFactory.getLogger(UserResource.class);
     69
     70   
    6671    final private String admin = "admin";
    6772   
     
    7782    @Path("{userid}")
    7883    @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);
    8187        if (remoteUserID != null) {
    8288            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    83             final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier));
     89            final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
    8490            if (userID != null) {
    8591                final User user = dbIntegrityService.getUser(userID);
    8692                return new ObjectFactory().createUser(user);
    8793            } 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");
    93101            return null;
    94102        }
     
    100108    @Transactional(readOnly = true)
    101109    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);
    103112        if (remoteUserID != null) {
    104113            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
     
    107116                return new ObjectFactory().createUser(user);
    108117            } else {
     118                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given info is not found in the database");
    109119                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database");
    110120                return null;
    111121            }
    112122        } 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");
    114125            return null;
    115126        }
     
    120131    @Path("{userid}/current")
    121132    @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);
    124136        if (remoteUserID != null) {
    125137            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    126             final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier));
     138            final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
    127139            if (userID != null) {
    128140                final CurrentUserInfo userInfo = new CurrentUserInfo();
     
    131143                return new ObjectFactory().createCurrentUserInfo(userInfo);
    132144            } 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");
    138152            return null;
    139153        }
     
    145159    @Path("{remoteId}")
    146160    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);
    148163        if (remoteUserID != null) {
    149164            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     
    154169                    return new ObjectFactory().createUser(addedUser);
    155170                } 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 in user does not have admin rights to add a user to the database");
    161                 return null;
    162             }
    163         } else {
    164             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     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");
    165180            return null;
    166181        }
     
    172187    @Path("")
    173188    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);
    175191        if (remoteUserID != null) {
    176192            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     
    181197                    return new ObjectFactory().createUser(addedUser);
    182198                } 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");
    192209            return null;
    193210        }
     
    197214    @Path("{userId}")
    198215    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);
    200218        if (remoteUserID != null) {
    201219            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     
    206224                    return "There is " + result.toString() + " row deleted";
    207225                } 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");
    217236            return null;
    218237        }
     
    223242    @Path("{userId}/safe")
    224243    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);
    226246        if (remoteUserID != null) {
    227247            if (dbIntegrityService.getTypeOfUserAccount(remoteUserID).equals(admin)) {
     
    232252                    return "There is " + result.toString() + " row deleted";
    233253                } 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 in user does not have admin rights to update a user info in the database");
    239                 return null;
    240             }
    241         } else {
    242             httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged in user is not found in the database");
     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");
    243263            return null;
    244264        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/resources/log4j.xml

    r4010 r4281  
    1919<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    2020<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
     21   
    2122    <appender class="org.apache.log4j.DailyRollingFileAppender" name="ROOT">
    22         <param value="${catalina.base}/logs/dasishAnnotator.log" name="File"/>
     23        <param value="${catalina.base}/logs/dasishRoot.log" name="File"/>
    2324        <layout class="org.apache.log4j.PatternLayout">
    2425            <param value="%d %p [%c#%M:%L] - %m%n" name="ConversionPattern"/>
    2526        </layout>
    2627    </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"/>
    2947    </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"/>
    3251    </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"/>
    3555    </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"/>
    3859    </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   
    39111    <root>
    40112        <level value="info"/>
    41         <appender-ref ref="ROOT"/>
     113        <appender-ref ref="ROOT"/> 
     114        <appender-ref ref="SERVER"/>
     115        <appender-ref ref="DATABASE"/>
    42116    </root>
     117   
    43118</log4j:configuration>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml

    r4267 r4281  
    3131    </context-param>
    3232    <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>
    3539    </context-param>
    3640   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r4267 r4281  
    6262        <br>
    6363        <b>Debugging URI's (only for developers)</b><br>
     64        GET <a href="api/debug/remoteID">api/debug/remoteID</a> <br>
    6465        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>
    6668    </body>
    6769</html>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r4276 r4281  
    206206        assertEquals(null, annotaionIdNE);
    207207
    208         final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null);
    209         assertEquals(null, annotaionIdNull);
     208       
    210209    }
    211210   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDaoTest.java

    r4173 r4281  
    8181        assertEquals(null, testTwo);
    8282
    83         Number testThree = jdbcUserDao.getInternalID(null);
    84         assertEquals(null, testThree);
    8583    }
    8684
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r4276 r4281  
    111111               
    112112                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"));
    114117               
    115118                oneOf(mockDbIntegrityService).getPermission(2, 3);
     
    155158               
    156159                oneOf(mockDbIntegrityService).getAnnotationInternalIdentifier(with(aNonNull(UUID.class)));             
    157                 will(returnValue(5));   
    158                
     160                will(returnValue(5));
     161               
     162               
    159163                oneOf(mockDbIntegrityService).getPermission(5, 3);
    160164                will(returnValue(Permission.OWNER)); 
Note: See TracChangeset for help on using the changeset viewer.