Changeset 4301


Ignore:
Timestamp:
01/20/14 17:23:00 (10 years ago)
Author:
olhsha
Message:

Adjusting logging. Loggin null arguments is added

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt

    r4257 r4301  
    99is added to the table "principal" in the DB. Adding, updating and deleting a user
    1010in the DB (only by admin) is debugged and tested.
     11
     12January 20/01, 2014. The database is updated (redundant  duplicating ownerId column is removed f
     13rom annotation table, and "admin_rights" is replaced with more informative "account" for the
     14table principal. There are two profiles now: fot tomcat authentication (laptop developemnt testing)
     15and shibbolized one. The depolyment tarball is compiled with the shibbolized  profile.
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/UPDATE.txt

    r4257 r4301  
    552. Adjusting shhaa.xml:  you need to set "sso action" and "slo action". E.g.
    66for lux16 they look as follows:
    7 <sso action="lI">https://lux16.mpi.nl/Shibboleth.sso/Login</sso>
    8 <slo action="lO">https://lux16.mpi.nl/Shibboleth.sso/Logout</slo>
    9 For the other servers the sysadmins should know.
     7<sso action="lI">{$shibLI}</sso>
     8<slo action="lO">{$shibLI}</slo>
    109
    11 3. This time the dasish database on lux17 is changed because we removed spring-security
    12 related tables. You have 2 options. Option A: remove the databse and copy the database from lux16
    13 to lux17. Option B: remove the tables "users" and "authorities" from the databse, and add
    14 a boolean column "admin_rights" to the table "principal", with the default values "false";
    15 and set Olha's admin_rights to "true".
     10where the values of the variables are set by maven to 
     11http://lux16.mpi.nl/Shibboleth.sso/Login
     12 and
     13 http://lux16.mpi.nl/Shibboleth.sso/Logout</shibLO>
     14 respectively
     15
     16
     17For the other servers the sysadmins should know their values and place them in the shhaa.xml.
     18
     193. This time the dasish database on lux17 is changed because I have removed some obsolete columns
     20and added a new one "account" for principals. Its values are "admin", "developer", "user".
     21Remove the databse and copy the database from lux16 to lux17.
    1622
    17234. If the application is succesfully deployed, you will get the jsp page after requesting
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/nb-configuration.xml

    r4257 r4301  
    77Without this configuration present, some functionality in the IDE may be limited or fail altogether.
    88-->
     9    <spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
     10        <config-files>
     11            <config-file>src/main/webapp/WEB-INF/web-shaa.xml</config-file>
     12        </config-files>
     13        <config-file-groups/>
     14    </spring-data>
    915    <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
    1016        <!--
     
    1723        <org-netbeans-modules-maven-jaxws.rest_2e_jersey_2e_type>server</org-netbeans-modules-maven-jaxws.rest_2e_jersey_2e_type>
    1824    </properties>
    19     <spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
    20         <config-files>
    21             <config-file>src/main/webapp/WEB-INF/web-shaa.xml</config-file>
    22         </config-files>
    23         <config-file-groups/>
    24     </spring-data>
    2525</project-shared-configuration>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml

    r4257 r4301  
    334334        <netbeans.hint.license>gpl20</netbeans.hint.license> 
    335335        <plugin.license.copyrightYear>2013</plugin.license.copyrightYear>
    336         <project.version>1.1</project.version>
     336        <project.version>1.2</project.version>
    337337    </properties>
    338338   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java

    r4281 r4301  
    257257    public AnnotationInfoList getFilteredAnnotationInfos(String word, String text, Number inloggedUserID, String[] accessModes, String namespace, UUID owner, Timestamp after, Timestamp before) {
    258258        List<Number> annotationIDs = getFilteredAnnotationIDs(word, text, inloggedUserID, accessModes, namespace, after, before);
    259         Number givenOwnerID = userDao.getInternalID(owner);
     259        Number givenOwnerID = (owner != null) ? userDao.getInternalID(owner) : null;
    260260        if (annotationIDs != null) {
    261261            AnnotationInfoList result = new AnnotationInfoList();
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r4281 r4301  
    112112    @Transactional(readOnly = true)
    113113    public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException {
     114
    114115        URI baseURI = uriInfo.getBaseUri();
    115116        String baseURIstr = baseURI.toString();
    116117        dbIntegrityService.setServiceURI(baseURIstr);
    117         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    118         if (annotationID != null) {
    119             String remoteUser = httpServletRequest.getRemoteUser();
    120             final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    121             if (userID != null) {
    122                 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    123                     final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
    124                     JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
    125                     return rootElement;
    126                 } else {
    127                     loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    128                     httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    129                     return null;
    130                 }
    131             } else {
    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");
     118
     119        try {
     120            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     121            if (annotationID != null) {
     122                String remoteUser = httpServletRequest.getRemoteUser();
     123                final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     124                if (userID != null) {
     125                    if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     126                        final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
     127                        JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
     128                        return rootElement;
     129                    } else {
     130                        loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
     131                        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
     132                        return null;
     133                    }
     134                } else {
     135                    loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     136                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
     137                    return null;
     138                }
     139            } else {
     140                loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     141                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database");
     142                return null;
     143            }
     144        } catch (IllegalArgumentException e) {
     145            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     146            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    139147            return null;
    140148        }
     
    149157    public JAXBElement<ReferenceList> getAnnotationTargets(@PathParam("annotationid") String externalIdentifier) throws IOException {
    150158        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    151         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    152         if (annotationID != null) {
    153             String remoteUser = httpServletRequest.getRemoteUser();
    154             final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    155             if (userID != null) {
    156                 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    157                     final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
    158                     logger.info("getAnnotationTargets method: OK");
    159                     return new ObjectFactory().createTargetList(TargetList);
    160                 } else {
    161                     loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    162                     httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    163                     return null;
    164                 }
    165             } else {
    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");
     159
     160        try {
     161            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     162            if (annotationID != null) {
     163                String remoteUser = httpServletRequest.getRemoteUser();
     164                final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     165                if (userID != null) {
     166                    if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     167                        final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
     168                        logger.info("getAnnotationTargets method: OK");
     169                        return new ObjectFactory().createTargetList(TargetList);
     170                    } else {
     171                        loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
     172                        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
     173                        return null;
     174                    }
     175                } else {
     176                    loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     177                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
     178                    return null;
     179                }
     180            } else {
     181                loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     182                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database");
     183                return null;
     184            }
     185        } catch (IllegalArgumentException e) {
     186            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     187            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    173188            return null;
    174189        }
     
    192207        Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    193208        if (userID != null) {
    194             UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null;
    195             String access = (permission != null) ? permission : default_permission;
    196             final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before);
    197             logger.info("getFilteredAnnotations method: OK");
    198             return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
     209            try {
     210                UUID ownerExternalUUID = (ownerExternalId != null) ? UUID.fromString(ownerExternalId) : null;
     211                String access = (permission != null) ? permission : default_permission;
     212                final AnnotationInfoList annotationInfoList = dbIntegrityService.getFilteredAnnotationInfos(link, text, userID, makeAccessModeChain(access), namespace, ownerExternalUUID, after, before);
     213                logger.info("getFilteredAnnotations method: OK");
     214                return new ObjectFactory().createAnnotationInfoList(annotationInfoList);
     215            } catch (IllegalArgumentException e) {
     216                loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + ownerExternalId);
     217                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + ownerExternalId);
     218                return null;
     219            }
    199220        } else {
    200221            loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     
    212233    public JAXBElement<UserWithPermissionList> getAnnotationPermissions(@PathParam("annotationid") String externalIdentifier) throws IOException {
    213234        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);
    217         if (userID != null) {
    218             if (annotationID != null) {
    219                 if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
    220                     final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
    221                     logger.debug("getAnnotationPermissions method: OK");
    222                     return new ObjectFactory().createPermissionList(permissionList);
    223                 } else {
    224                     loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
    225                     httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
    226                     return null;
    227                 }
    228             } else {
    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");
     235        try {
     236            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     237            String remoteUser = httpServletRequest.getRemoteUser();
     238            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     239            if (userID != null) {
     240                if (annotationID != null) {
     241                    if (dbIntegrityService.getTypeOfUserAccount(userID).equals(admin) || canRead(userID, annotationID)) {
     242                        final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
     243                        logger.debug("getAnnotationPermissions method: OK");
     244                        return new ObjectFactory().createPermissionList(permissionList);
     245                    } else {
     246                        loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot read the annotation.");
     247                        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
     248                        return null;
     249                    }
     250                } else {
     251                    loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     252                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id " + externalIdentifier + " is not found in the database");
     253                    return null;
     254                }
     255            } else {
     256                loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     257                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
     258                return null;
     259            }
     260        } catch (IllegalArgumentException e) {
     261            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     262            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    236263            return null;
    237264        }
     
    244271    public String deleteAnnotation(@PathParam("annotationid") String externalIdentifier) throws IOException {
    245272        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    246         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    247         String remoteUser = httpServletRequest.getRemoteUser();
    248         Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    249         if (userID != null) {
    250             if (annotationID != null) {
    251                 if (isOwner(userID, annotationID)) {
    252                     int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
    253                     String result = Integer.toString(resultDelete[0]);
    254                     logger.info("deleteAnnotation method: OK");
    255                     return result + " annotation(s) deleted.";
    256                 } else {
    257                     loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
    258                     httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
    259                     return null;
    260                 }
    261             } else {
    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.");
     273        try {
     274            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     275            String remoteUser = httpServletRequest.getRemoteUser();
     276            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     277            if (userID != null) {
     278                if (annotationID != null) {
     279                    if (isOwner(userID, annotationID)) {
     280                        int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
     281                        String result = Integer.toString(resultDelete[0]);
     282                        logger.info("deleteAnnotation method: OK");
     283                        return result + " annotation(s) deleted.";
     284                    } else {
     285                        loggerServer.debug(httpServletResponse.SC_FORBIDDEN + ": The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
     286                        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
     287                        return null;
     288                    }
     289                } else {
     290                    loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     291                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id  " + externalIdentifier + " is not found in the database.");
     292                    return null;
     293                }
     294
     295            } else {
     296                loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database.");
     297                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database.");
     298                return null;
     299            }
     300        } catch (IllegalArgumentException e) {
     301            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     302            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    270303            return null;
    271304        }
     
    317350        }
    318351
    319 
    320         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    321         if (annotationID != null) {
    322             String remoteUser = httpServletRequest.getRemoteUser();
    323             Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    324             if (userID != null) {
    325                 if (isOwner(userID, annotationID)) {
    326                     int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
    327                     return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    328 
    329                 } else {
    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.");
     352        try {
     353            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     354            if (annotationID != null) {
     355                String remoteUser = httpServletRequest.getRemoteUser();
     356                Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     357                if (userID != null) {
     358                    if (isOwner(userID, annotationID)) {
     359                        int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
     360                        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     361
     362                    } else {
     363                        loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "Only the owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body.");
     364                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Only the owner can update the annotation fully (incl. permissions). Only writer can update the annotation's body.");
     365                        return null;
     366                    }
     367                } else {
     368                    loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     369                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database.");
     370                    return null;
     371                }
     372            } else {
     373                loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     374                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id   " + externalIdentifier + " is not found in the database.");
     375                return null;
     376            }
     377        } catch (IllegalArgumentException e) {
     378            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     379            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    342380            return null;
    343381        }
     
    351389        String path = uriInfo.getBaseUri().toString();
    352390        dbIntegrityService.setServiceURI(path);
    353         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
    354         String remoteUser = httpServletRequest.getRemoteUser();
    355         Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    356         if (userID != null) {
    357             if (annotationID != null) {
    358                 if (canWrite(userID, annotationID)) {
    359                     int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
    360                     return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
    361                 } else {
    362                     loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
    363                     httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
    364                     return null;
    365                 }
    366             } else {
    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.");
     391        try {
     392            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
     393            String remoteUser = httpServletRequest.getRemoteUser();
     394            Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     395            if (userID != null) {
     396                if (annotationID != null) {
     397                    if (canWrite(userID, annotationID)) {
     398                        int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
     399                        return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
     400                    } else {
     401                        loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
     402                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
     403                        return null;
     404                    }
     405                } else {
     406                    loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + externalIdentifier + " is not found in the database");
     407                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id   " + externalIdentifier + " is not found in the database.");
     408                    return null;
     409                }
     410            } else {
     411                loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     412                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database.");
     413                return null;
     414            }
     415        } catch (IllegalArgumentException e) {
     416            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     417            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    374418            return null;
    375419        }
     
    380424    @Produces(MediaType.APPLICATION_XML)
    381425    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}/permissions/{userid: " + BackendConstants.regExpIdentifier + "}")
    382     public String updatePermission(@PathParam("annotationid") String annotationExternalId, @PathParam("userid") String userExternalId, Permission permission) throws IOException {
     426    public String updatePermission(@PathParam("annotationid") String annotationExternalId,
     427            @PathParam("userid") String userExternalId, Permission permission) throws IOException {
    383428        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    384429        String remoteUser = httpServletRequest.getRemoteUser();
    385430        Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    386431        if (remoteUserID != null) {
    387             final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
    388             if (userID != null) {
    389                 final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    390                 if (annotationID != null) {
    391                     if (isOwner(remoteUserID, annotationID)) {
    392                         int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
    393                                 ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
    394                                 : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission);
    395                         logger.info("updatePermission method: OK");
    396                         return result + " rows are updated/added";
    397 
    398                     } else {
    399                         loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
    400                         httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is  not its owner.");
    401                         return null;
    402                     }
    403                 } else {
    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.");
     432            try {
     433                final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
     434                if (userID != null) {
     435                    try {
     436                        final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     437                        if (annotationID != null) {
     438                            if (isOwner(remoteUserID, annotationID)) {
     439                                int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
     440                                        ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
     441                                        : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission);
     442                                logger.info("updatePermission method: OK");
     443                                return result + " rows are updated/added";
     444
     445                            } else {
     446                                loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the body of this annotation because (s)he is  not its 'writer'.");
     447                                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the rights on this annotation because (s)he is  not its owner.");
     448                                return null;
     449                            }
     450                        } else {
     451                            loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + annotationExternalId + " is not found in the database");
     452                            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id  " + annotationExternalId + "  is not found in the database.");
     453                            return null;
     454                        }
     455                    } catch (IllegalArgumentException e) {
     456                        loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + annotationExternalId);
     457                        httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + annotationExternalId);
     458                        return null;
     459                    }
     460                } else {
     461                    loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id   " + userExternalId + " is not found in the database");
     462                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id   " + userExternalId + " is not found in the database.");
     463                    return null;
     464                }
     465            } catch (IllegalArgumentException e) {
     466                loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + userExternalId);
     467                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + userExternalId);
    411468                return null;
    412469            }
     
    425482    public JAXBElement<ResponseBody> updatePermissions(@PathParam("annotationid") String annotationExternalId, UserWithPermissionList permissions) throws IOException {
    426483        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    427         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
    428         String remoteUser = httpServletRequest.getRemoteUser();
    429         Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
    430         if (remoteUserID != null) {
    431             if (annotationID != null) {
    432                 if (isOwner(remoteUserID, annotationID)) {
    433                     int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
    434                     return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
    435                 } else {
    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.");
     484        try {
     485            final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
     486            String remoteUser = httpServletRequest.getRemoteUser();
     487            Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
     488            if (remoteUserID != null) {
     489                if (annotationID != null) {
     490                    if (isOwner(remoteUserID, annotationID)) {
     491                        int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
     492                        return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
     493                    } else {
     494                        loggerServer.debug(httpServletResponse.SC_UNAUTHORIZED + "The logged-in user cannot change the access rights on this annotation because (s)he is  not its owner.");
     495                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The logged-in user cannot change the access rights on this annotation because (s)he is  not its owner.");
     496                        return null;
     497                    }
     498                } else {
     499                    loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The annotation with the given id " + annotationExternalId + " is not found in the database");
     500                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id  " + annotationExternalId + "  is not found in the database.");
     501                    return null;
     502                }
     503            } else {
     504                loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": the logged-in user is not found in the database");
     505                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database.");
     506                return null;
     507            }
     508        } catch (IllegalArgumentException e) {
     509            loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + annotationExternalId);
     510            httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + annotationExternalId);
    448511            return null;
    449512        }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java

    r4281 r4301  
    8080        if (remoteUserID != null) {
    8181            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    82             final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
    83             if (cachedID != null) {
    84                 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
    85                 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
    86             } else {
    87                 AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database");
    88                 httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
     82            try {
     83                final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
     84                if (cachedID != null) {
     85                    final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
     86                    return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
     87                } else {
     88                    AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + ": The cached representation with the given id is not found in the database");
     89                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
     90                    return null;
     91                }
     92            } catch (IllegalArgumentException e) {
     93                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalId);
     94                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalId);
    8995                return null;
    9096            }
     
    105111        if (remoteUserID != null) {
    106112            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    107             final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
    108             if (cachedID != null) {
    109                 InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
    110                 ImageIO.setUseCache(false);
    111                 BufferedImage result = ImageIO.read(dbRespond);
    112                 return result;
    113             } else {
    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");
     113            try {
     114                final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
     115                if (cachedID != null) {
     116                    InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
     117                    ImageIO.setUseCache(false);
     118                    BufferedImage result = ImageIO.read(dbRespond);
     119                    return result;
     120                } else {
     121                    AnnotationResource.loggerServer.debug(httpServletResponse.SC_NOT_FOUND + "The cached representation with the given id is not found in the database");
     122                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation  with the given id   " + externalId + " is not found in the database");
     123                    return null;
     124                }
     125            } catch (IllegalArgumentException e) {
     126                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalId);
     127                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalId);
    116128                return null;
    117129            }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java

    r4281 r4301  
    9090        if (remoteUserID != null) {
    9191            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    92             final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
    93             if (targetID != null) {
    94                 final Target target = dbIntegrityService.getTarget(targetID);
    95                 return new ObjectFactory().createTarget(target);
    96             } else {
    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");
     92            try {
     93                final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
     94                if (targetID != null) {
     95                    final Target target = dbIntegrityService.getTarget(targetID);
     96                    return new ObjectFactory().createTarget(target);
     97                } else {
     98                    AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database");
     99                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id   " + externalIdentifier + " is not found in the database");
     100                    return null;
     101                }
     102            } catch (IllegalArgumentException e) {
     103                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     104                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    99105                return null;
    100106            }
     
    116122        if (remoteUserID != null) {
    117123            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    118             final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
    119             if (targetID != null) {
    120                 final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
    121                 return new ObjectFactory().createReferenceList(siblings);
    122             } else {
    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");
     124            try {
     125                final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(externalIdentifier));
     126                if (targetID != null) {
     127                    final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
     128                    return new ObjectFactory().createReferenceList(siblings);
     129                } else {
     130                    AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + externalIdentifier + " is not found in the database");
     131                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id   " + externalIdentifier + " is not found in the database");
     132                    return null;
     133                }
     134            } catch (IllegalArgumentException e) {
     135                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     136                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    125137                return null;
    126138            }
     
    158170        if (remoteUserID != null) {
    159171            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    160             final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier));
    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            try {
     173                final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier));
     174                if (targetID != null) {
     175                    CachedRepresentationInfo metadata = multiPart.getBodyParts().get(0).getEntityAs(CachedRepresentationInfo.class);
     176                    BodyPartEntity bpe = (BodyPartEntity) multiPart.getBodyParts().get(1).getEntity();
     177                    InputStream cachedSource = bpe.getInputStream();
     178                    final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource);
     179                    final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]);
     180                    return new ObjectFactory()
     181                            .createCashedRepresentationInfo(cachedInfo);
     182                } else {
     183                    AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + targetIdentifier + " is not found in the database");
     184                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id   " + targetIdentifier + " is not found in the database");
     185                    return null;
     186                }
     187            } catch (IllegalArgumentException e) {
     188                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + targetIdentifier);
     189                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + targetIdentifier);
    172190                return null;
    173191            }
     
    188206        if (remoteUserID != null) {
    189207            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    190             final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier));
    191             if (targetID != null) {
    192                 final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));
    193                 if (cachedID != null) {
    194                     int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);
    195                     String result = Integer.toString(resultDelete[0]);
    196                     return result + " pair(s) target-cached deleted.";
     208            try {
     209                final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier));
     210                if (targetID != null) {
     211                    final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));
     212                    if (cachedID != null) {
     213                        int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);
     214                        String result = Integer.toString(resultDelete[0]);
     215                        return result + " pair(s) target-cached deleted.";
     216                    } else {
     217                        AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The target with the given id " + cachedExternalIdentifier + " is not found in the database");
     218                        httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id   " + cachedExternalIdentifier + " is not found in the database");
     219                        return null;
     220                    }
    197221                } else {
    198222                    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");
    200                     return null;
    201                 }
    202             } 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");
     223                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id   " + targetExternalIdentifier + " is not found in the database");
     224                    return null;
     225                }
     226            } catch (IllegalArgumentException e) {
     227                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + targetExternalIdentifier);
     228                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + targetExternalIdentifier);
    205229                return null;
    206230            }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java

    r4281 r4301  
    6565    @Context
    6666    private UriInfo uriInfo;
    67    
    6867    private final Logger logger = LoggerFactory.getLogger(UserResource.class);
    69 
    70    
    7168    final private String admin = "admin";
    72    
     69
    7370    public void setHttpRequest(HttpServletRequest request) {
    7471        this.httpServletRequest = request;
     
    8784        if (remoteUserID != null) {
    8885            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    89             final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
    90             if (userID != null) {
    91                 final User user = dbIntegrityService.getUser(userID);
    92                 return new ObjectFactory().createUser(user);
    93             } else {
    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");
     86            try {
     87                final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     88                if (userID != null) {
     89                    final User user = dbIntegrityService.getUser(userID);
     90                    return new ObjectFactory().createUser(user);
     91                } else {
     92                    AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database");
     93                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id   " + externalIdentifier + " is not found in the database");
     94                    return null;
     95                }
     96            } catch (IllegalArgumentException e) {
     97                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     98                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    9699                return null;
    97100            }
     
    136139        if (remoteUserID != null) {
    137140            dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
    138             final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
    139             if (userID != null) {
    140                 final CurrentUserInfo userInfo = new CurrentUserInfo();
    141                 userInfo.setRef(dbIntegrityService.getUserURI(userID));
    142                 userInfo.setCurrentUser(ifLoggedIn(userID));
    143                 return new ObjectFactory().createCurrentUserInfo(userInfo);
    144             } else {
    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");
     141            try {
     142                final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(externalIdentifier));
     143                if (userID != null) {
     144                    final CurrentUserInfo userInfo = new CurrentUserInfo();
     145                    userInfo.setRef(dbIntegrityService.getUserURI(userID));
     146                    userInfo.setCurrentUser(ifLoggedIn(userID));
     147                    return new ObjectFactory().createCurrentUserInfo(userInfo);
     148                } else {
     149                    AnnotationResource.loggerServer.debug(HttpServletResponse.SC_NOT_FOUND + ": The user with the given id " + externalIdentifier + " is not found in the database");
     150                    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id   " + externalIdentifier + " is not found in the database");
     151                    return null;
     152                }
     153            } catch (IllegalArgumentException e) {
     154                AnnotationResource.loggerServer.debug(HttpServletResponse.SC_BAD_REQUEST + ": Illegal argument UUID " + externalIdentifier);
     155                httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument UUID " + externalIdentifier);
    147156                return null;
    148157            }
     
    176185                return null;
    177186            }
    178         } else {           
     187        } else {
    179188            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The logged-in user is not found in the database");
    180189            return null;
     
    237246        }
    238247    }
    239    
    240    
     248
    241249    @DELETE
    242250    @Path("{userId}/safe")
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/resources/log4j.xml

    r4281 r4301  
    6363    </logger>
    6464    <logger name="org.springframework.jdbc.core.JdbcTemplate" additivity="false">
    65         <level value="error"/>
     65        <level value="debug"/>
    6666        <appender-ref ref="DATABASE"/>
    6767    </logger>
     
    8282    </logger>
    8383   
    84    
    8584   
    86    <logger name="org.springframework.beans.factory.xml.XmlBeanDefinitionReader" additivity="false">
     85    <logger name="org.springframework">
    8786        <level value="off"/>
    8887        <appender-ref ref="SERVER"/>
    8988        <appender-ref ref="DATABASE"/>
    9089    </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    
     90
    11091   
    11192    <root>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web_shaa.xml

    r4267 r4301  
    3131    </context-param>
    3232     <context-param>
    33         <param-name>eu.dasish.annotation.backend.logLocation</param-name>
    34         <param-value>/lat/tomcat-webuser/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   
Note: See TracChangeset for help on using the changeset viewer.