diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/GetIDByName.java b/src/main/java/org/caosdb/server/database/backend/transaction/GetIDByName.java index 8fffb415bdb5ebeb5fb17b3603312bbfcab1551e..b43db0010eeeb3179bb91333d854872f5e8ab18a 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/GetIDByName.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/GetIDByName.java @@ -28,7 +28,6 @@ import org.caosdb.server.database.backend.interfaces.GetIDByNameImpl; import org.caosdb.server.database.exceptions.EntityDoesNotExistException; import org.caosdb.server.database.exceptions.EntityWasNotUniqueException; import org.caosdb.server.database.exceptions.TransactionException; -import org.caosdb.server.query.Query.Role; public class GetIDByName extends BackendTransaction { @@ -38,11 +37,11 @@ public class GetIDByName extends BackendTransaction { private final String role; public GetIDByName(final String name) { - this(name, (String) null, true); + this(name, null, true); } public GetIDByName(final String name, final boolean unique) { - this(name, (String) null, unique); + this(name, null, unique); } public GetIDByName(final String name, final String role) { @@ -55,10 +54,6 @@ public class GetIDByName extends BackendTransaction { this.unique = unique; } - public GetIDByName(String name, Role role, boolean unique) { - this(name, role.toString(), unique); - } - @Override public void execute() throws TransactionException { final GetIDByNameImpl t = getImplementation(GetIDByNameImpl.class); diff --git a/src/main/java/org/caosdb/server/database/backend/transaction/InsertEntityProperties.java b/src/main/java/org/caosdb/server/database/backend/transaction/InsertEntityProperties.java index 7cb0cb40f84e13107feef6d969718d99fda70530..bd5bf63a5eb7b194e119c56293e756ff0c4b6a20 100644 --- a/src/main/java/org/caosdb/server/database/backend/transaction/InsertEntityProperties.java +++ b/src/main/java/org/caosdb/server/database/backend/transaction/InsertEntityProperties.java @@ -167,11 +167,7 @@ public class InsertEntityProperties extends BackendTransaction { fp.collection = ((AbstractCollectionDatatype) property.getDatatype()).getCollectionName(); } else { - try { - fp.type = property.getDatatype().getId().toString(); - } catch (NullPointerException e) { - throw e; - } + fp.type = property.getDatatype().getId().toString(); } } } diff --git a/src/main/java/org/caosdb/server/entity/ClientMessage.java b/src/main/java/org/caosdb/server/entity/ClientMessage.java index 19fe9675a4dd0190304cd3164eb9fa4a40a6312f..40a8c713deafc1cce5f8343a2fa8d15cb054ee17 100644 --- a/src/main/java/org/caosdb/server/entity/ClientMessage.java +++ b/src/main/java/org/caosdb/server/entity/ClientMessage.java @@ -6,12 +6,22 @@ import java.util.Map.Entry; import org.jdom2.Attribute; import org.jdom2.Element; +/** + * Class which represents client messages. Client messages is a way to extend the Entity API with + * special properties which may be used by plug-ins. + * + * <p>If no plug-in handles the client message, it is printed back to the response unaltered. + * + * <p>Client message can have arbitrary key-value tuples {@link #properties}. + * + * @author Timm Fitschen (t.fitschen@indiscale.com) + */ public class ClientMessage extends Message { private static final long serialVersionUID = 1L; private Map<String, String> properties = new HashMap<>(); - public ClientMessage(String type) { + public ClientMessage(String type, String body) { super(type, null, null, null); } @@ -31,7 +41,7 @@ public class ClientMessage extends Message { } public static ClientMessage fromXML(Element pe) { - ClientMessage result = new ClientMessage(pe.getName()); + ClientMessage result = new ClientMessage(pe.getName(), pe.getText()); for (Attribute a : pe.getAttributes()) { result.properties.put(a.getName(), a.getValue()); } @@ -49,6 +59,8 @@ public class ClientMessage extends Message { @Override public int hashCode() { - return type.hashCode() + this.properties.hashCode(); + return type.hashCode() + + (this.getBody() == null ? 0 : this.getBody().hashCode()) + + this.properties.hashCode(); } } diff --git a/src/main/java/org/caosdb/server/jobs/Job.java b/src/main/java/org/caosdb/server/jobs/Job.java index e88bff24c28fb5151e35f2593450065dd637e10c..17d4500870f2372f793480692c27505fc3f71e72 100644 --- a/src/main/java/org/caosdb/server/jobs/Job.java +++ b/src/main/java/org/caosdb/server/jobs/Job.java @@ -74,7 +74,7 @@ public abstract class Job { return getContainer().getRequestId(); } - public Subject getUser() { + protected Subject getUser() { return getTransaction().getTransactor(); } @@ -169,8 +169,8 @@ public abstract class Job { return retrieveValidSparseEntityById(retrieveValidIDByName(name), null); } - public final EntityInterface retrieveValidSparseEntityById(final Integer id, final String version) - throws Message { + protected final EntityInterface retrieveValidSparseEntityById( + final Integer id, final String version) throws Message { String resulting_version = version; if (version == null || version.equals("HEAD")) { @@ -205,11 +205,11 @@ public abstract class Job { return ret; } - public final EntityInterface retrieveValidEntity(Integer id) { + protected final EntityInterface retrieveValidEntity(Integer id) { return execute(new RetrieveFullEntity(id)).getContainer().get(0); } - public final Integer retrieveValidIDByName(final String name) { + protected final Integer retrieveValidIDByName(final String name) { return execute(new GetIDByName(name)).getId(); } diff --git a/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java b/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java index b1a5ac7782236b88493e3c7f9b9cb14bc4123d52..35b0fdcfd24a3db356e4fa9f2debf20577ea4319 100644 --- a/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java +++ b/src/main/java/org/caosdb/server/jobs/core/CheckStateTransition.java @@ -10,9 +10,8 @@ import org.caosdb.server.transaction.WriteTransaction; /** * Check if the attempted state transition is allowed. - * - * @author Timm Fitschen (t.fitschen@indiscale.com) * + * @author Timm Fitschen (t.fitschen@indiscale.com) */ @JobAnnotation( time = JobExecutionTime.CHECK, @@ -26,10 +25,10 @@ public class CheckStateTransition extends EntityStateJob { new Message(MessageType.Error, "Initial state not allowed."); private static final Message FINAL_STATE_NOT_ALLOWED = new Message(MessageType.Error, "Final state not allowed."); - + /** - * The forceFinalState flag is especially useful if you want to delete - * entities in the middle of the state machine's usual state cycle. + * The forceFinalState flag is especially useful if you want to delete entities in the middle of + * the state machine's usual state cycle. */ private static final String FORCE_FINAL_STATE = "forceFinalState"; @@ -98,7 +97,8 @@ public class CheckStateTransition extends EntityStateJob { private void checkFinalState(State fromState) throws Message { if (!fromState.isFinal()) { - if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE)) || "true".equalsIgnoreCase(getEntity().getFlag(FORCE_FINAL_STATE))) { + if ("true".equalsIgnoreCase(getTransaction().getContainer().getFlags().get(FORCE_FINAL_STATE)) + || "true".equalsIgnoreCase(getEntity().getFlag(FORCE_FINAL_STATE))) { // TODO permissions return; } diff --git a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java index fcc200aef772ea58426732d4d10f2d1fec8934cf..1aa9608107b470f167724c354388c2d9059a839d 100644 --- a/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java +++ b/src/main/java/org/caosdb/server/jobs/core/EntityStateJob.java @@ -298,14 +298,16 @@ public abstract class EntityStateJob extends EntityJob { private State finalState; public StateModel(EntityInterface stateModelEntity) throws Message { - long time1 = System.currentTimeMillis(); + long time1 = System.currentTimeMillis(); this.name = stateModelEntity.getName(); this.transitions = getTransitions(stateModelEntity); this.states = getStates(transitions, this); this.finalState = getFinalState(stateModelEntity); this.initialState = getInitialState(stateModelEntity); long time2 = System.currentTimeMillis(); - getTransaction().getTransactionBenchmark().addMeasurement(this.getClass().getSimpleName() + "::1", time2 - time1); + getTransaction() + .getTransactionBenchmark() + .addMeasurement(this.getClass().getSimpleName() + "::1", time2 - time1); } private State getInitialState(EntityInterface stateModelEntity) throws Message { @@ -356,10 +358,11 @@ public abstract class EntityStateJob extends EntityJob { return result; } - private Set<State> getStates(Set<Transition> transitions, StateModel stateModel) throws Message { + private Set<State> getStates(Set<Transition> transitions, StateModel stateModel) + throws Message { Iterator<Transition> it = transitions.iterator(); Set<State> result = new HashSet<>(); - while(it.hasNext()) { + while (it.hasNext()) { Transition t = it.next(); result.add(t.getFromState()); result.add(t.getToState()); @@ -394,16 +397,32 @@ public abstract class EntityStateJob extends EntityJob { } return false; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("StateModel (name="); + sb.append(this.getName()); + sb.append(", initial="); + sb.append(this.getInitialState().stateName); + sb.append(", final="); + sb.append(this.getFinalState().stateName); + sb.append(", transitions=["); + Iterator<Transition> iterator = this.transitions.iterator(); + while (iterator.hasNext()) { + sb.append(iterator.next().name); + sb.append(iterator.next().name); + } + sb.append("])"); + return sb.toString(); + } } - protected EntityInterface retrieveStateEntity(String stateName) - throws Message { + protected EntityInterface retrieveStateEntity(String stateName) throws Message { try { return retrieveValidEntity(retrieveValidIDByName(stateName)); } catch (EntityDoesNotExistException e) { throw STATE_NOT_IN_STATE_MODEL; } - } protected EntityInterface retrieveStateModelEntity(String stateModel) throws Message { @@ -520,8 +539,7 @@ public abstract class EntityStateJob extends EntityJob { + " WHICH REFERENCES " + TRANSITION_RECORD_TYPE_NAME + " WHICH REFERENCES " - + Integer.toString(stateEntity.getId()) - , + + Integer.toString(stateEntity.getId()), getUser(), null); query.execute(getTransaction().getAccess()); diff --git a/src/main/java/org/caosdb/server/jobs/core/MakeStateMessage.java b/src/main/java/org/caosdb/server/jobs/core/MakeStateMessage.java index 6b252f3fff272eaf353cc577fb807a057923bc1f..ce1fd5a974b61c7ed69e7ad633af10a6dc027a24 100644 --- a/src/main/java/org/caosdb/server/jobs/core/MakeStateMessage.java +++ b/src/main/java/org/caosdb/server/jobs/core/MakeStateMessage.java @@ -8,12 +8,12 @@ import org.caosdb.server.jobs.JobExecutionTime; import org.caosdb.server.transaction.Retrieve; /** - * Remove the state property from the entity and, iff necessary, convert it into - * a State instance which is then being appended to the entity's messages. - * - * If this job belongs to a Write transaction there is already a State instance - * present and the conversion is not necessary. - * + * Remove the state property from the entity and, iff necessary, convert it into a State instance + * which is then being appended to the entity's messages. + * + * <p>If this job belongs to a Write transaction there is already a State instance present and the + * conversion is not necessary. + * * @author Timm Fitschen (t.fitschen@indiscale.com) */ @JobAnnotation(loadAlways = true, time = JobExecutionTime.POST_TRANSACTION)