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

Cleanup

parent 93a1200a
No related branches found
No related tags found
3 merge requests!21Release v0.4.0,!7F fsm,!6Draft: F acm permissions2
......@@ -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);
......
......@@ -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();
}
}
}
......
......@@ -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();
}
}
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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());
......
......@@ -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)
......
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