Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/CHANGES.txt	(revision 4217)
@@ -1,4 +1,5 @@
 January 2, 2014: the first deployment on lux16.
 
-January 3, 2014: files README, ISNTALL, UPDATE, CHANGES are added to the deployment tar-ball which
-is from now on is generated using maven assembly plug-in
+January 3, 2014: files README, INSTALL, UPDATE, CHANGES are added to the 
+deployment tar-ball which is from now on is generated using maven assembly 
+plug-in.
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/INSTALL.txt
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/INSTALL.txt	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/INSTALL.txt	(revision 4217)
@@ -21,5 +21,5 @@
 = Installation and configuration   =
 =========================================================================================
-== Plasing war-file and ds#webannotator.xml at the tomcat's conf/Catalina/localhost ==
+== Placing war-file and ds#webannotator.xml at the tomcat's conf/Catalina/localhost ==
 
 You must deploy the annotator's .war file to the tomcat-webuser. Make a directory for the 
@@ -42,5 +42,5 @@
 
          <Resource
-                 name="jdbc/DASISH"
+                 name="jdbc/DASISHAnnotator"
                  auth="Container"
                  type="javax.sql.DataSource"
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/README.txt
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/README.txt	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/README.txt	(revision 4217)
@@ -8,5 +8,5 @@
 The DASISH web-annotator back-end consists of two parts: the database, where the 
 annotations are stored, and the Jerseys web-application that by means of REST requests 
-performs  authentified red/write  access to the database.
+performs  authentified read/write  access to the database.
 
 === Requests ===
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java	(revision 4217)
@@ -80,6 +80,4 @@
     @Context
     private Providers providers;
-    
-    
     final String default_permission = "reader";
     private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
@@ -97,6 +95,4 @@
     }
 
-  
-    
     public void setProviders(Providers providers) {
         this.providers = providers;
@@ -116,13 +112,18 @@
         dbIntegrityService.setServiceURI(baseURIstr);
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        String remoteUser = httpServletRequest.getRemoteUser();
-        final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
-        if (canRead(userID, annotationID)) {
-            final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
-            JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
-            logger.info("getAnnotation method: OK");
-            return rootElement;
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
+        if (annotationID != null) {
+            String remoteUser = httpServletRequest.getRemoteUser();
+            final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
+            if (canRead(userID, annotationID)) {
+                final Annotation annotation = dbIntegrityService.getAnnotation(annotationID);
+                JAXBElement<Annotation> rootElement = new ObjectFactory().createAnnotation(annotation);
+                logger.info("getAnnotation method: OK");
+                return rootElement;
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
             return null;
         }
@@ -139,11 +140,16 @@
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (canRead(userID, annotationID)) {
-            final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
-            logger.info("getAnnotationTargets method: OK");
-            return new ObjectFactory().createTargetList(TargetList);
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
+        if (annotationID != null) {
+            final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
+            if (canRead(userID, annotationID)) {
+                final ReferenceList TargetList = dbIntegrityService.getAnnotationTargets(annotationID);
+                logger.info("getAnnotationTargets method: OK");
+                return new ObjectFactory().createTargetList(TargetList);
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
             return null;
         }
@@ -183,13 +189,17 @@
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(ExternalIdentifier));
         final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (canRead(userID, annotationID)) {
-            final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
-            logger.info("getAnnotationPermissions method: OK");
-            return new ObjectFactory().createPermissionList(permissionList);
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
-            return null;
-        }
-
+        if (annotationID != null) {
+            if (canRead(userID, annotationID)) {
+                final UserWithPermissionList permissionList = dbIntegrityService.getPermissionsForAnnotation(annotationID);
+                logger.info("getAnnotationPermissions method: OK");
+                return new ObjectFactory().createPermissionList(permissionList);
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot read the annotation.");
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -203,14 +213,18 @@
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
         final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (isOwner(userID, annotationID)) {
-            int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
-            String result = Integer.toString(resultDelete[0]);
-            logger.info("deleteAnnotation method: OK");
-            return result + " annotation(s) deleted.";
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
-            return null;
-        }
-
+        if (annotationID != null) {
+            if (isOwner(userID, annotationID)) {
+                int[] resultDelete = dbIntegrityService.deleteAnnotation(annotationID);
+                String result = Integer.toString(resultDelete[0]);
+                logger.info("deleteAnnotation method: OK");
+                return result + " annotation(s) deleted.";
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "The logged-in user cannot delete the annotation. Only the owner can delete the annotation.");
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -246,15 +260,19 @@
         }
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
-        final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (canWrite(userID, annotationID)) {
-            int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
-            logger.info("updateAnnotation method: OK");
-            return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
-
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-            return null;
-        }
-
+        if (annotationID != null) {
+            final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
+            if (canWrite(userID, annotationID)) {
+                int updatedRows = dbIntegrityService.updateUsersAnnotation(userID, annotation);
+                logger.info("updateAnnotation method: OK");
+                return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
+
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -270,13 +288,17 @@
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(externalIdentifier));
         final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (canWrite(userID, annotationID)) {
-            int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
-            logger.info("updateAnnotationBody method: OK");
-            return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-            return null;
-        }
-
+        if (annotationID != null) {
+            if (canWrite(userID, annotationID)) {
+                int updatedRows = dbIntegrityService.updateAnnotationBody(annotationID, annotationBody);
+                logger.info("updateAnnotationBody method: OK");
+                return new ObjectFactory().createResponseBody(makeAnnotationResponseEnvelope(annotationID));
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -291,13 +313,18 @@
         final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
         final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(userExternalId));
-        if (isOwner(remoteUserID, annotationID)) {
-            int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
-                    ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
-                    : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission);
-            logger.info("updatePermission method: OK");
-            return result + " rows are updated/added";
-
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+        if (annotationID != null) {
+            if (isOwner(remoteUserID, annotationID)) {
+                int result = (dbIntegrityService.getPermission(annotationID, userID) != null)
+                        ? dbIntegrityService.updateAnnotationPrincipalPermission(annotationID, userID, permission)
+                        : dbIntegrityService.addAnnotationPrincipalPermission(annotationID, userID, permission);
+                logger.info("updatePermission method: OK");
+                return result + " rows are updated/added";
+
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
             return null;
         }
@@ -313,10 +340,15 @@
         final Number annotationID = dbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(annotationExternalId));
         final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(httpServletRequest.getRemoteUser());
-        if (isOwner(remoteUserID, annotationID)) {
-            int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
-            logger.info("updatePermissions method: OK");
-            return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
-        } else {
-            httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+        if (annotationID != null) {
+            if (isOwner(remoteUserID, annotationID)) {
+                int updatedRows = dbIntegrityService.updatePermissions(annotationID, permissions);
+                logger.info("updatePermissions method: OK");
+                return new ObjectFactory().createResponseBody(makePermissionResponseEnvelope(annotationID));
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The annotation with the given id is not found in the database");
             return null;
         }
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/CachedRepresentationResource.java	(revision 4217)
@@ -29,4 +29,5 @@
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -49,5 +50,5 @@
 @Component
 @Path("/cached")
-@Transactional(rollbackFor={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
+@Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
 public class CachedRepresentationResource {
 
@@ -56,4 +57,6 @@
     @Context
     private HttpServletRequest httpServletRequest;
+    @Context
+    private HttpServletResponse httpServletResponse;
     @Context
     private UriInfo uriInfo;
@@ -68,11 +71,16 @@
     @Produces(MediaType.TEXT_XML)
     @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/metadata")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException {
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<CachedRepresentationInfo> getCachedRepresentationInfo(@PathParam("cachedid") String externalId) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
-        final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
-        return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
+        if (cachedID != null) {
+            final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(cachedID);
+            return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -80,15 +88,18 @@
     @Produces({"image/jpeg", "image/png"})
     @Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/content")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
     public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(externalId));
-        InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
-        ImageIO.setUseCache(false);
-        BufferedImage result = ImageIO.read(dbRespond);
-        return result;
+        if (cachedID != null) {
+            InputStream dbRespond = dbIntegrityService.getCachedRepresentationBlob(cachedID);
+            ImageIO.setUseCache(false);
+            BufferedImage result = ImageIO.read(dbRespond);
+            return result;
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation  with the given id is not found in the database");
+            return null;
+        }
     }
-    
-   
 }
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java	(revision 4217)
@@ -31,4 +31,5 @@
 import java.util.UUID;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -58,5 +59,5 @@
 @Component
 @Path("/targets")
-@Transactional(rollbackFor={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
+@Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
 public class TargetResource {
 
@@ -65,4 +66,6 @@
     @Context
     private HttpServletRequest httpServletRequest;
+    @Context
+    private HttpServletResponse httpServletResponse;
     @Context
     private UriInfo uriInfo;
@@ -79,11 +82,16 @@
     @Produces(MediaType.TEXT_XML)
     @Path("{targetid: " + BackendConstants.regExpIdentifier + "}")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<Target> getTarget(@PathParam("targetid") String ExternalIdentifier) throws SQLException {
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<Target> getTarget(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        final Target target = dbIntegrityService.getTarget(targetID);
-        return new ObjectFactory().createTarget(target);
+        if (targetID != null) {
+            final Target target = dbIntegrityService.getTarget(targetID);
+            return new ObjectFactory().createTarget(target);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database");
+            return null;
+        }
     }
 
@@ -92,17 +100,22 @@
     @Produces(MediaType.TEXT_XML)
     @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/versions")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String ExternalIdentifier) throws SQLException {
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<ReferenceList> getSiblingTargets(@PathParam("targetid") String ExternalIdentifier) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
-        return new ObjectFactory().createReferenceList(siblings);
+        if (targetID != null) {
+            final ReferenceList siblings = dbIntegrityService.getTargetsForTheSameLinkAs(targetID);
+            return new ObjectFactory().createReferenceList(siblings);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database");
+            return null;
+        }
     }
 
-    // TODO both unit tests
-    //changed path, /Targetpart is removed
-    //how to overwork the input stream to make it downloadable
-    // using mime type as well
+// TODO both unit tests
+//changed path, /Targetpart is removed
+//how to overwork the input stream to make it downloadable
+// using mime type as well
 //    @DELETE
 //    @Produces(MediaType.TEXT_XML)
@@ -116,5 +129,4 @@
 //        return result[1];
 //    }
-
     @POST
     @Consumes("multipart/mixed")
@@ -123,7 +135,6 @@
     @Secured("ROLE_USER")
     public JAXBElement<CachedRepresentationInfo> postCached(@PathParam("targetid") String targetIdentifier,
-            @PathParam("fragmentDescriptor") String fragmentDescriptor, 
+            @PathParam("fragmentDescriptor") String fragmentDescriptor,
             MultiPart multiPart) throws SQLException {
-
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier));
@@ -133,22 +144,30 @@
         final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, fragmentDescriptor, metadata, cachedSource);
         final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]);
-        return new ObjectFactory().createCashedRepresentationInfo(cachedInfo);
+        return new ObjectFactory()
+                .createCashedRepresentationInfo(cachedInfo);
 
     }
-    
-    
+
     @DELETE
     @Path("{targetid: " + BackendConstants.regExpIdentifier + "}/cached/{cachedid: " + BackendConstants.regExpIdentifier + "}")
     @Secured("ROLE_ADMIN")
-    public String deleteCachedForTarget(@PathParam("targetid") String targetExternalIdentifier, 
-    @PathParam("cachedid") String cachedExternalIdentifier) throws SQLException {
+    public String deleteCachedForTarget(@PathParam("targetid") String targetExternalIdentifier,
+            @PathParam("cachedid") String cachedExternalIdentifier) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetExternalIdentifier));
-        final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));
-        int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);
-        String result = Integer.toString(resultDelete[0]);
-        return result + " pair(s) target-cached deleted.";
+        if (targetID != null) {
+            final Number cachedID = dbIntegrityService.getCachedRepresentationInternalIdentifier(UUID.fromString(cachedExternalIdentifier));
+            if (cachedID != null) {
+                int[] resultDelete = dbIntegrityService.deleteCachedRepresentationOfTarget(targetID, cachedID);
+                String result = Integer.toString(resultDelete[0]);
+                return result + " pair(s) target-cached deleted.";
+            } else {
+                httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The cached representation with the given id is not found in the database");
+                return null;
+            }
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The target with the given id is not found in the database");
+            return null;
+        }
     }
-
-    
 }
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java	(revision 4216)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/UserResource.java	(revision 4217)
@@ -27,4 +27,5 @@
 import java.util.UUID;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -51,10 +52,13 @@
 @Component
 @Path("/users")
-@Transactional(rollbackFor={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
+@Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
 public class UserResource {
+
     @Autowired
     private DBIntegrityService dbIntegrityService;
     @Context
     private HttpServletRequest httpServletRequest;
+    @Context
+    private HttpServletResponse httpServletResponse;
     @Context
     private UriInfo uriInfo;
@@ -66,42 +70,57 @@
     public UserResource() {
     }
-    
+
     @GET
     @Produces(MediaType.TEXT_XML)
     @Path("{userid: " + BackendConstants.regExpIdentifier + "}")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<User> getUser(@PathParam("userid") String ExternalIdentifier) throws SQLException {
-         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<User> getUser(@PathParam("userid") String ExternalIdentifier) throws SQLException, IOException {
+        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        final User user = dbIntegrityService.getUser(userID);
-        return new ObjectFactory().createUser(user);
+        if (userID != null) {
+            final User user = dbIntegrityService.getUser(userID);
+            return new ObjectFactory().createUser(user);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database");
+            return null;
+        }
     }
-    
+
     @GET
     @Produces(MediaType.TEXT_XML)
     @Path("/info")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<User> getUserByInfo(@QueryParam("email") String email) throws SQLException {
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<User> getUserByInfo(@QueryParam("email") String email) throws SQLException, IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final User user = dbIntegrityService.getUserByInfo(email);
-        return new ObjectFactory().createUser(user);
+        if (user != null) {
+            return new ObjectFactory().createUser(user);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given info is not found in the database");
+            return null;
+        }
     }
-    
+
     @GET
     @Produces(MediaType.TEXT_XML)
     @Path("{userid: " + BackendConstants.regExpIdentifier + "}/current")
-    @Secured("ROLE_USER")    
-    @Transactional(readOnly=true)
-    public JAXBElement<CurrentUserInfo> getCurrentUserInfo(@PathParam("userid") String ExternalIdentifier){
+    @Secured("ROLE_USER")
+    @Transactional(readOnly = true)
+    public JAXBElement<CurrentUserInfo> getCurrentUserInfo(@PathParam("userid") String ExternalIdentifier) throws IOException {
         dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number userID = dbIntegrityService.getUserInternalIdentifier(UUID.fromString(ExternalIdentifier));
-        final CurrentUserInfo userInfo = new CurrentUserInfo();
-        userInfo.setRef(dbIntegrityService.getUserURI(userID));
-        userInfo.setCurrentUser(ifLoggedIn(userID));
-        return new ObjectFactory().createCurrentUserInfo(userInfo);
+        if (userID != null) {
+            final CurrentUserInfo userInfo = new CurrentUserInfo();
+            userInfo.setRef(dbIntegrityService.getUserURI(userID));
+            userInfo.setCurrentUser(ifLoggedIn(userID));
+            return new ObjectFactory().createCurrentUserInfo(userInfo);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database");
+            return null;
+        }
     }
-    
+
     @POST
     @Consumes(MediaType.TEXT_XML)
@@ -110,10 +129,10 @@
     @Secured("ROLE_ADMIN")
     public JAXBElement<User> addUser(@PathParam("userid") String remoteId, User user) throws SQLException {
-        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());        
+        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number userID = dbIntegrityService.addUser(user, remoteId);
         final User addedUser = dbIntegrityService.getUser(userID);
         return new ObjectFactory().createUser(addedUser);
     }
-    
+
     @PUT
     @Consumes(MediaType.TEXT_XML)
@@ -121,14 +140,17 @@
     @Path("")
     @Secured("ROLE_ADMIN")
-    public JAXBElement<User> updateUser(User user){
-        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());        
+    public JAXBElement<User> updateUser(User user) throws IOException{
+        dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
         final Number userID = dbIntegrityService.updateUser(user);
-        final User addedUser = dbIntegrityService.getUser(userID);
-        return new ObjectFactory().createUser(addedUser);
+        if (userID != null) {
+            final User addedUser = dbIntegrityService.getUser(userID);
+            return new ObjectFactory().createUser(addedUser);
+        } else {
+            httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "The user with the given id is not found in the database");
+            return null;
+        }
     }
-    
-    
-    
-    private boolean ifLoggedIn(Number userID){
+
+    private boolean ifLoggedIn(Number userID) {
         return httpServletRequest.getRemoteUser().equals(dbIntegrityService.getUserRemoteID(userID));
     }
