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

Merge branch 'f-fsm' into f-fsm-v0.2

parents 71590d03 d6fbc634
No related branches found
No related tags found
3 merge requests!21Release v0.4.0,!7F fsm,!6Draft: F acm permissions2
...@@ -34,7 +34,6 @@ import org.apache.shiro.SecurityUtils; ...@@ -34,7 +34,6 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.Permission; import org.apache.shiro.authz.Permission;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.caosdb.datetime.UTCDateTime;
import org.caosdb.server.CaosDBException; import org.caosdb.server.CaosDBException;
import org.caosdb.server.accessControl.Principal; import org.caosdb.server.accessControl.Principal;
import org.caosdb.server.database.proto.SparseEntity; import org.caosdb.server.database.proto.SparseEntity;
...@@ -1055,11 +1054,9 @@ public class Entity extends AbstractObservable implements EntityInterface { ...@@ -1055,11 +1054,9 @@ public class Entity extends AbstractObservable implements EntityInterface {
setId(spe.id); setId(spe.id);
this.setRole(spe.role); this.setRole(spe.role);
setEntityACL(spe.acl); setEntityACL(spe.acl);
UTCDateTime versionDate = null; if (spe.versionId != null) {
if (spe.versionSeconds != null) { this.version = new Version(spe.versionId);
versionDate = UTCDateTime.UTCSeconds(spe.versionSeconds, spe.versionNanos);
} }
this.version = new Version(spe.version, versionDate);
if (!isNameOverride()) { if (!isNameOverride()) {
setName(spe.name); setName(spe.name);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
package org.caosdb.server.entity; package org.caosdb.server.entity;
import java.util.LinkedList; import java.util.List;
import org.caosdb.datetime.UTCDateTime; import org.caosdb.datetime.UTCDateTime;
/** /**
...@@ -31,25 +31,35 @@ import org.caosdb.datetime.UTCDateTime; ...@@ -31,25 +31,35 @@ import org.caosdb.datetime.UTCDateTime;
public class Version { public class Version {
private String id = null; private String id = null;
private LinkedList<Version> predecessors = null; private String username = null;
private LinkedList<Version> successors = null; private String realm = null;
private List<Version> predecessors = null;
private List<Version> successors = null;
private UTCDateTime date = null; private UTCDateTime date = null;
private boolean isHead = false;
private boolean isCompleteHistory = false;
public Version(String id, long seconds, int nanos) { public Version(String id, long seconds, int nanos) {
this(id, UTCDateTime.UTCSeconds(seconds, nanos)); this(id, UTCDateTime.UTCSeconds(seconds, nanos), null, null);
} }
public Version(String id, UTCDateTime date) { public Version(String id, UTCDateTime date, String username, String realm) {
this.id = id; this.id = id;
this.date = date; this.date = date;
this.username = username;
this.realm = realm;
} }
public Version(String id) { public Version(String id) {
this(id, null); this(id, null, null, null);
} }
public Version() {} public Version() {}
public Version(String id, UTCDateTime timestamp) {
this(id, timestamp, null, null);
}
public UTCDateTime getDate() { public UTCDateTime getDate() {
return date; return date;
} }
...@@ -66,19 +76,55 @@ public class Version { ...@@ -66,19 +76,55 @@ public class Version {
this.id = id; this.id = id;
} }
public LinkedList<Version> getSuccessors() { public List<Version> getSuccessors() {
return successors; return successors;
} }
public void setSuccessors(LinkedList<Version> successors) { public void setSuccessors(List<Version> successors) {
this.successors = successors; this.successors = successors;
} }
public LinkedList<Version> getPredecessors() { public List<Version> getPredecessors() {
return predecessors; return predecessors;
} }
public void setPredecessors(LinkedList<Version> predecessors) { public void setPredecessors(List<Version> predecessors) {
this.predecessors = predecessors; this.predecessors = predecessors;
} }
public String getRealm() {
return realm;
}
public void setRealm(String realm) {
this.realm = realm;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void setDate(Long timestamp) {
this.date = UTCDateTime.SystemMillisToUTCDateTime(timestamp);
}
public boolean isHead() {
return isHead;
}
public void setHead(boolean isHead) {
this.isHead = isHead;
}
public boolean isCompleteHistory() {
return isCompleteHistory;
}
public void setCompleteHistory(boolean isCompleteHistory) {
this.isCompleteHistory = isCompleteHistory;
}
} }
...@@ -30,28 +30,43 @@ import org.jdom2.Element; ...@@ -30,28 +30,43 @@ import org.jdom2.Element;
* @author Timm Fitschen <t.fitschen@indiscale.com> * @author Timm Fitschen <t.fitschen@indiscale.com>
*/ */
class VersionXMLSerializer { class VersionXMLSerializer {
public Element toElement(Version version) { public Element toElement(Version version) {
Element result = new Element("Version"); return toElement(version, "Version");
result.setAttribute("id", version.getId()); }
if (version.getDate() != null) {
result.setAttribute("date", version.getDate().toDateTimeString(TimeZone.getDefault())); private Element toElement(Version version, String tag) {
} Element element = new Element(tag);
setAttributes(version, element);
if (version.getPredecessors() != null) { if (version.getPredecessors() != null) {
for (Version p : version.getPredecessors()) { for (Version p : version.getPredecessors()) {
Element predecessor = new Element("Predecessor"); element.addContent(toElement(p, "Predecessor"));
predecessor.setAttribute("id", p.getId());
predecessor.setAttribute("date", p.getDate().toDateTimeString(TimeZone.getDefault()));
result.addContent(predecessor);
} }
} }
if (version.getSuccessors() != null) { if (version.getSuccessors() != null) {
for (Version s : version.getSuccessors()) { for (Version s : version.getSuccessors()) {
Element successor = new Element("Successor"); element.addContent(toElement(s, "Successor"));
successor.setAttribute("id", s.getId());
successor.setAttribute("date", s.getDate().toDateTimeString(TimeZone.getDefault()));
result.addContent(successor);
} }
} }
return result; return element;
}
private void setAttributes(Version version, Element element) {
element.setAttribute("id", version.getId());
if (version.getUsername() != null) {
element.setAttribute("username", version.getUsername());
}
if (version.getRealm() != null) {
element.setAttribute("realm", version.getRealm());
}
if (version.getDate() != null) {
element.setAttribute("date", version.getDate().toDateTimeString(TimeZone.getDefault()));
}
if (version.isHead()) {
element.setAttribute("head", "true");
}
if (version.isCompleteHistory()) {
element.setAttribute("completeHistory", "true");
}
} }
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
package org.caosdb.server.jobs.core; package org.caosdb.server.jobs.core;
import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.caosdb.server.database.backend.transaction.RetrieveTransactionHistory; import org.caosdb.server.database.backend.transaction.RetrieveVersionHistory;
import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.EntityInterface;
import org.caosdb.server.jobs.FlagJob; import org.caosdb.server.jobs.FlagJob;
import org.caosdb.server.jobs.JobAnnotation; import org.caosdb.server.jobs.JobAnnotation;
...@@ -32,6 +32,11 @@ import org.caosdb.server.permissions.EntityPermission; ...@@ -32,6 +32,11 @@ import org.caosdb.server.permissions.EntityPermission;
import org.caosdb.server.utils.EntityStatus; import org.caosdb.server.utils.EntityStatus;
import org.caosdb.server.utils.ServerMessages; import org.caosdb.server.utils.ServerMessages;
/**
* Retrieves the complete version history of each entity and appends it to the entity.
*
* @author Timm Fitschen (t.fitschen@indiscale.com)
*/
@JobAnnotation(time = JobExecutionTime.POST_TRANSACTION, flag = "H") @JobAnnotation(time = JobExecutionTime.POST_TRANSACTION, flag = "H")
public class History extends FlagJob { public class History extends FlagJob {
...@@ -42,7 +47,7 @@ public class History extends FlagJob { ...@@ -42,7 +47,7 @@ public class History extends FlagJob {
if (entity.getId() != null && entity.getId() > 0) { if (entity.getId() != null && entity.getId() > 0) {
try { try {
entity.checkPermission(EntityPermission.RETRIEVE_HISTORY); entity.checkPermission(EntityPermission.RETRIEVE_HISTORY);
final RetrieveTransactionHistory t = new RetrieveTransactionHistory(entity); final RetrieveVersionHistory t = new RetrieveVersionHistory(entity);
execute(t); execute(t);
} catch (final AuthorizationException e) { } catch (final AuthorizationException e) {
entity.setEntityStatus(EntityStatus.UNQUALIFIED); entity.setEntityStatus(EntityStatus.UNQUALIFIED);
......
...@@ -27,7 +27,6 @@ import org.caosdb.server.database.access.Access; ...@@ -27,7 +27,6 @@ import org.caosdb.server.database.access.Access;
import org.caosdb.server.database.backend.transaction.InsertEntity; import org.caosdb.server.database.backend.transaction.InsertEntity;
import org.caosdb.server.entity.EntityInterface; import org.caosdb.server.entity.EntityInterface;
import org.caosdb.server.entity.FileProperties; import org.caosdb.server.entity.FileProperties;
import org.caosdb.server.entity.Version;
import org.caosdb.server.entity.container.InsertContainer; import org.caosdb.server.entity.container.InsertContainer;
import org.caosdb.server.entity.container.TransactionContainer; import org.caosdb.server.entity.container.TransactionContainer;
import org.caosdb.server.permissions.EntityACL; import org.caosdb.server.permissions.EntityACL;
...@@ -104,10 +103,6 @@ public class Insert extends WriteTransaction<InsertContainer> { ...@@ -104,10 +103,6 @@ public class Insert extends WriteTransaction<InsertContainer> {
public void insert(final TransactionContainer container, final Access access) throws Exception { public void insert(final TransactionContainer container, final Access access) throws Exception {
if (container.getStatus().ordinal() >= EntityStatus.QUALIFIED.ordinal()) { if (container.getStatus().ordinal() >= EntityStatus.QUALIFIED.ordinal()) {
execute(new InsertEntity(container), access); execute(new InsertEntity(container), access);
for (EntityInterface e : container) {
// TODO move to InsertEntity transaction
e.setVersion(new Version(e.getVersion().getId(), this.getTimestamp()));
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment