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

Cleanup

parent 93a1200a
Branches
Tags
3 merge requests!21Release v0.4.0,!7F fsm,!6Draft: F acm permissions2
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
...@@ -28,7 +28,6 @@ import org.caosdb.server.database.backend.interfaces.GetIDByNameImpl; ...@@ -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.EntityDoesNotExistException;
import org.caosdb.server.database.exceptions.EntityWasNotUniqueException; import org.caosdb.server.database.exceptions.EntityWasNotUniqueException;
import org.caosdb.server.database.exceptions.TransactionException; import org.caosdb.server.database.exceptions.TransactionException;
import org.caosdb.server.query.Query.Role;
public class GetIDByName extends BackendTransaction { public class GetIDByName extends BackendTransaction {
...@@ -38,11 +37,11 @@ public class GetIDByName extends BackendTransaction { ...@@ -38,11 +37,11 @@ public class GetIDByName extends BackendTransaction {
private final String role; private final String role;
public GetIDByName(final String name) { public GetIDByName(final String name) {
this(name, (String) null, true); this(name, null, true);
} }
public GetIDByName(final String name, final boolean unique) { 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) { public GetIDByName(final String name, final String role) {
...@@ -55,10 +54,6 @@ public class GetIDByName extends BackendTransaction { ...@@ -55,10 +54,6 @@ public class GetIDByName extends BackendTransaction {
this.unique = unique; this.unique = unique;
} }
public GetIDByName(String name, Role role, boolean unique) {
this(name, role.toString(), unique);
}
@Override @Override
public void execute() throws TransactionException { public void execute() throws TransactionException {
final GetIDByNameImpl t = getImplementation(GetIDByNameImpl.class); final GetIDByNameImpl t = getImplementation(GetIDByNameImpl.class);
......
...@@ -167,11 +167,7 @@ public class InsertEntityProperties extends BackendTransaction { ...@@ -167,11 +167,7 @@ public class InsertEntityProperties extends BackendTransaction {
fp.collection = fp.collection =
((AbstractCollectionDatatype) property.getDatatype()).getCollectionName(); ((AbstractCollectionDatatype) property.getDatatype()).getCollectionName();
} else { } else {
try {
fp.type = property.getDatatype().getId().toString(); fp.type = property.getDatatype().getId().toString();
} catch (NullPointerException e) {
throw e;
}
} }
} }
} }
......
...@@ -6,12 +6,22 @@ import java.util.Map.Entry; ...@@ -6,12 +6,22 @@ import java.util.Map.Entry;
import org.jdom2.Attribute; import org.jdom2.Attribute;
import org.jdom2.Element; 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 { public class ClientMessage extends Message {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Map<String, String> properties = new HashMap<>(); private Map<String, String> properties = new HashMap<>();
public ClientMessage(String type) { public ClientMessage(String type, String body) {
super(type, null, null, null); super(type, null, null, null);
} }
...@@ -31,7 +41,7 @@ public class ClientMessage extends Message { ...@@ -31,7 +41,7 @@ public class ClientMessage extends Message {
} }
public static ClientMessage fromXML(Element pe) { 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()) { for (Attribute a : pe.getAttributes()) {
result.properties.put(a.getName(), a.getValue()); result.properties.put(a.getName(), a.getValue());
} }
...@@ -49,6 +59,8 @@ public class ClientMessage extends Message { ...@@ -49,6 +59,8 @@ public class ClientMessage extends Message {
@Override @Override
public int hashCode() { public int hashCode() {
return type.hashCode() + this.properties.hashCode(); return type.hashCode()
+ (this.getBody() == null ? 0 : this.getBody().hashCode())
+ this.properties.hashCode();
} }
} }
...@@ -74,7 +74,7 @@ public abstract class Job { ...@@ -74,7 +74,7 @@ public abstract class Job {
return getContainer().getRequestId(); return getContainer().getRequestId();
} }
public Subject getUser() { protected Subject getUser() {
return getTransaction().getTransactor(); return getTransaction().getTransactor();
} }
...@@ -169,8 +169,8 @@ public abstract class Job { ...@@ -169,8 +169,8 @@ public abstract class Job {
return retrieveValidSparseEntityById(retrieveValidIDByName(name), null); return retrieveValidSparseEntityById(retrieveValidIDByName(name), null);
} }
public final EntityInterface retrieveValidSparseEntityById(final Integer id, final String version) protected final EntityInterface retrieveValidSparseEntityById(
throws Message { final Integer id, final String version) throws Message {
String resulting_version = version; String resulting_version = version;
if (version == null || version.equals("HEAD")) { if (version == null || version.equals("HEAD")) {
...@@ -205,11 +205,11 @@ public abstract class Job { ...@@ -205,11 +205,11 @@ public abstract class Job {
return ret; return ret;
} }
public final EntityInterface retrieveValidEntity(Integer id) { protected final EntityInterface retrieveValidEntity(Integer id) {
return execute(new RetrieveFullEntity(id)).getContainer().get(0); 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(); return execute(new GetIDByName(name)).getId();
} }
......
...@@ -12,7 +12,6 @@ import org.caosdb.server.transaction.WriteTransaction; ...@@ -12,7 +12,6 @@ import org.caosdb.server.transaction.WriteTransaction;
* Check if the attempted state transition is allowed. * Check if the attempted state transition is allowed.
* *
* @author Timm Fitschen (t.fitschen@indiscale.com) * @author Timm Fitschen (t.fitschen@indiscale.com)
*
*/ */
@JobAnnotation( @JobAnnotation(
time = JobExecutionTime.CHECK, time = JobExecutionTime.CHECK,
...@@ -28,8 +27,8 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -28,8 +27,8 @@ public class CheckStateTransition extends EntityStateJob {
new Message(MessageType.Error, "Final state not allowed."); new Message(MessageType.Error, "Final state not allowed.");
/** /**
* The forceFinalState flag is especially useful if you want to delete * The forceFinalState flag is especially useful if you want to delete entities in the middle of
* entities in the middle of the state machine's usual state cycle. * the state machine's usual state cycle.
*/ */
private static final String FORCE_FINAL_STATE = "forceFinalState"; private static final String FORCE_FINAL_STATE = "forceFinalState";
...@@ -98,7 +97,8 @@ public class CheckStateTransition extends EntityStateJob { ...@@ -98,7 +97,8 @@ public class CheckStateTransition extends EntityStateJob {
private void checkFinalState(State fromState) throws Message { private void checkFinalState(State fromState) throws Message {
if (!fromState.isFinal()) { 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 // TODO permissions
return; return;
} }
......
...@@ -305,7 +305,9 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -305,7 +305,9 @@ public abstract class EntityStateJob extends EntityJob {
this.finalState = getFinalState(stateModelEntity); this.finalState = getFinalState(stateModelEntity);
this.initialState = getInitialState(stateModelEntity); this.initialState = getInitialState(stateModelEntity);
long time2 = System.currentTimeMillis(); 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 { private State getInitialState(EntityInterface stateModelEntity) throws Message {
...@@ -356,7 +358,8 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -356,7 +358,8 @@ public abstract class EntityStateJob extends EntityJob {
return result; 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(); Iterator<Transition> it = transitions.iterator();
Set<State> result = new HashSet<>(); Set<State> result = new HashSet<>();
while (it.hasNext()) { while (it.hasNext()) {
...@@ -394,16 +397,32 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -394,16 +397,32 @@ public abstract class EntityStateJob extends EntityJob {
} }
return false; 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) protected EntityInterface retrieveStateEntity(String stateName) throws Message {
throws Message {
try { try {
return retrieveValidEntity(retrieveValidIDByName(stateName)); return retrieveValidEntity(retrieveValidIDByName(stateName));
} catch (EntityDoesNotExistException e) { } catch (EntityDoesNotExistException e) {
throw STATE_NOT_IN_STATE_MODEL; throw STATE_NOT_IN_STATE_MODEL;
} }
} }
protected EntityInterface retrieveStateModelEntity(String stateModel) throws Message { protected EntityInterface retrieveStateModelEntity(String stateModel) throws Message {
...@@ -520,8 +539,7 @@ public abstract class EntityStateJob extends EntityJob { ...@@ -520,8 +539,7 @@ public abstract class EntityStateJob extends EntityJob {
+ " WHICH REFERENCES " + " WHICH REFERENCES "
+ TRANSITION_RECORD_TYPE_NAME + TRANSITION_RECORD_TYPE_NAME
+ " WHICH REFERENCES " + " WHICH REFERENCES "
+ Integer.toString(stateEntity.getId()) + Integer.toString(stateEntity.getId()),
,
getUser(), getUser(),
null); null);
query.execute(getTransaction().getAccess()); query.execute(getTransaction().getAccess());
......
...@@ -8,11 +8,11 @@ import org.caosdb.server.jobs.JobExecutionTime; ...@@ -8,11 +8,11 @@ import org.caosdb.server.jobs.JobExecutionTime;
import org.caosdb.server.transaction.Retrieve; import org.caosdb.server.transaction.Retrieve;
/** /**
* Remove the state property from the entity and, iff necessary, convert it into * Remove the state property from the entity and, iff necessary, convert it into a State instance
* a State instance which is then being appended to the entity's messages. * which is then being appended to the entity's messages.
* *
* If this job belongs to a Write transaction there is already a State instance * <p>If this job belongs to a Write transaction there is already a State instance present and the
* present and the conversion is not necessary. * conversion is not necessary.
* *
* @author Timm Fitschen (t.fitschen@indiscale.com) * @author Timm Fitschen (t.fitschen@indiscale.com)
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment