Skip to content
Snippets Groups Projects
Verified Commit 459e275f authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: use entityDoesNotExistException instead of nullpointer

parent c21e4d0c
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ package caosdb.server.database.backend.transaction;
import caosdb.server.caching.Cache;
import caosdb.server.database.CacheableBackendTransaction;
import caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl;
import caosdb.server.database.exceptions.EntityDoesNotExistException;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.database.proto.SparseEntity;
import org.apache.commons.jcs.access.behavior.ICacheAccess;
......@@ -62,7 +63,11 @@ public class GetFileRecordByPath extends CacheableBackendTransaction<String, Spa
@Override
public SparseEntity executeNoCache() throws TransactionException {
final GetFileRecordByPathImpl t = getImplementation(GetFileRecordByPathImpl.class);
return t.execute(getKey());
SparseEntity result = t.execute(getKey());
if (result == null) {
throw new EntityDoesNotExistException();
}
return result;
}
public Integer getId() {
......
......@@ -79,8 +79,8 @@ public class Message extends Exception implements Comparable<Message>, ToElement
this(type, code, null, null);
}
public Message(final Integer code, final String description) {
this("Message", code, description, null);
public Message(Integer code, String description) {
this(MessageType.Info, code, description);
}
public Message(final MessageType type, final Integer code, final String description) {
......@@ -96,6 +96,10 @@ public class Message extends Exception implements Comparable<Message>, ToElement
this(type, code, description, null);
}
public Message(MessageType type, String description) {
this(type.toString(), 0, description);
}
public Message(
final String type, final Integer code, final String description, final String body) {
this.code = code;
......
......@@ -26,10 +26,12 @@ import static caosdb.server.FileSystem.getFromFileSystem;
import static java.net.URLDecoder.decode;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.exceptions.EntityDoesNotExistException;
import caosdb.server.database.misc.TransactionBenchmark;
import caosdb.server.entity.Entity;
import caosdb.server.entity.FileProperties;
import caosdb.server.entity.Message;
import caosdb.server.entity.Message.MessageType;
import caosdb.server.entity.RetrieveEntity;
import caosdb.server.entity.container.TransactionContainer;
import caosdb.server.permissions.EntityPermission;
......@@ -162,7 +164,10 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
final String entId =
getEntityID((directory.endsWith("/") ? directory : directory + "/") + file.getName());
if (entId == null) {
new Message("Orphaned file").addToElement(celem);
new Message(
MessageType.Warning,
"Orphaned file. The file is not tracked. This is probably a harmless inconsistency but it might be a sign of other problems.")
.addToElement(celem);
} else {
celem.setAttribute("id", entId);
}
......@@ -188,8 +193,8 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
final Transaction<?> t = new RetrieveSparseEntityByPath(c);
try {
t.execute();
} catch (NullPointerException npe) {
// For example files in file system without corresponding File records.
} catch (EntityDoesNotExistException exception) {
// This file in the file system has no corresponding File record.
return null;
}
final long t2 = System.currentTimeMillis();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment