You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/07/22 12:56:09 UTC

[4/7] git commit: implemented deletion of versions also in platform and webservice (MARMOTTA-18)

implemented deletion of versions also in platform and webservice (MARMOTTA-18)


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/c550034d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/c550034d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/c550034d

Branch: refs/heads/develop
Commit: c550034d3a8d76595c662269c260eafc9325c80d
Parents: 18c428a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Jul 22 11:13:58 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Jul 22 11:13:58 2013 +0200

----------------------------------------------------------------------
 .../services/VersioningSailProvider.java        | 33 +++++++++++++++++++
 .../webservices/VersioningWebService.java       | 34 +++++++++++++++++---
 2 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c550034d/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
index 67ad27c..13ebe79 100644
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
+++ b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
@@ -223,4 +223,37 @@ public class VersioningSailProvider implements TransactionalSailProvider {
     public Version getLatestVersion(Resource r, Date date) throws SailException {
         return sail.getLatestVersion(r, date);
     }
+
+    /**
+     * Remove the version with the id passed as argument, including all references to added and removed triples. The
+     * triples themselves are not deleted immediately, we let the garbage collector carry this out periodically.
+     * @param id  the database ID of the version (see {@link org.apache.marmotta.kiwi.versioning.model.Version#getId()})
+     * @throws org.openrdf.sail.SailException
+     */
+    public void removeVersion(Long id) throws SailException {
+        sail.removeVersion(id);
+    }
+
+    /**
+     * Remove all versions in the given time interval. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param from date after which versions will be deleted
+     * @param to   date before which versions will be deleted
+     * @throws org.openrdf.sail.SailException
+     */
+    public void removeVersions(Date from, Date to) throws SailException {
+        sail.removeVersions(from, to);
+    }
+
+    /**
+     * Remove all versions until the date given as argument. Iterates over all versions and deletes them individually.
+     * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
+     * without version will later be cleaned up by the garbage collector
+     * @param until date until when to delete versions
+     * @throws org.openrdf.sail.SailException
+     */
+    public void removeVersions(Date until) throws SailException {
+        sail.removeVersions(until);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c550034d/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
index 22a7f32..a71d624 100644
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
+++ b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
@@ -38,11 +38,7 @@ import org.slf4j.Logger;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 import javax.inject.Inject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Response;
 import java.util.ArrayList;
 import java.util.Date;
@@ -201,5 +197,33 @@ public class VersioningWebService {
         }
     }
 
+    /**
+     * Remove the version with the given ID from the triple store. Calling this service will only remove the versioning
+     * metadata, not the triples themselves. Triples that are marked as deleted and no longer attached to a version will
+     * be cleaned up by a garbage collection process that is running periodically or can be triggered manually.
+     *
+     * @param id
+     * @return
+     */
+    @DELETE
+    @Path("/versions/{id:[0-9]+}")
+    public Response deleteVersion(@PathParam("id") Long id) {
+        try {
+            Version version = versioningService.getVersion(id);
+
+            if(version != null) {
+                versioningService.removeVersion(id);
+
+                return Response.ok().entity("success").build();
+
+            } else {
+                return Response.status(Response.Status.NOT_FOUND).entity("version with id "+id+" does not exist").build();
+            }
+
+        } catch (SailException e) {
+            return Response.serverError().entity("error deleting version "+id+": "+e.getMessage()).build();
+        }
+    }
+
 
 }