marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [2/3] git commit: MARMOTTA-24: removed the ldp experiments from core
Date Tue, 11 Feb 2014 08:08:44 GMT
MARMOTTA-24: removed the ldp experiments from core


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

Branch: refs/heads/ldp
Commit: 1e3bf9b2300dba6e499e167ade9ce32301c09191
Parents: bc9ebf2
Author: Sergio Fernández <wikier@apache.org>
Authored: Tue Feb 11 08:58:35 2014 +0100
Committer: Sergio Fernández <wikier@apache.org>
Committed: Tue Feb 11 08:58:35 2014 +0100

----------------------------------------------------------------------
 .../core/api/triplestore/LdpService.java        |  86 -----
 .../services/triplestore/LdpServiceImpl.java    | 357 -------------------
 .../webservices/triplestore/LdpWebService.java  | 144 --------
 .../src/main/resources/kiwi-module.properties   |   3 +-
 4 files changed, 1 insertion(+), 589 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/1e3bf9b2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/LdpService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/LdpService.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/LdpService.java
deleted file mode 100644
index 8644867..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/triplestore/LdpService.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.platform.core.api.triplestore;
-
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.openrdf.model.URI;
-import org.openrdf.repository.RepositoryException;
-
-/**
- * Interface for supporting LDP (WIP)
- * 
- * @see http://www.w3.org/TR/ldp/
- * @author Sergio Fernández
- *
- */
-public interface LdpService {
-    
-    static final String DEFAULT_PREFIX = "container";
-    
-    /**
-     * Get the base context URI
-     * 
-     * @return base context
-     */
-    String getBaseContainer();
-    
-    /**
-     * Lists the current container
-     * 
-     * @return list of containers
-     */
-    List<URI> list();
-    
-    /**
-     * Return the URI for this LDPR
-     * 
-     * @param container plain text URI
-     * @return container's URI, null if does not exit
-     */
-    URI get(String resource);
-    
-    /**
-     * Creates a new LDPR
-     * 
-     * @param container plain text URI
-     * @return URI of the new container if success
-     * @throws URISyntaxException 
-     */
-    boolean create(String resource) throws URISyntaxException;
-    
-    /**
-     * Creates a new LDPR defining a title for it
-     * 
-     * @param container plain text URI
-     * @return URI of the new container if success
-     * @throws URISyntaxException 
-     */
-    boolean create(String resource, String title) throws URISyntaxException;
-    
-    /**
-     * Delete this LDPR
-     * 
-     * @param resource uri
-     * @return
-     * @throws RepositoryException 
-     */
-    boolean delete(String resource) throws RepositoryException;
-
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/1e3bf9b2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/LdpServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/LdpServiceImpl.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/LdpServiceImpl.java
deleted file mode 100644
index e4821f4..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/triplestore/LdpServiceImpl.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.platform.core.services.triplestore;
-import static org.apache.marmotta.commons.sesame.repository.ExceptionUtils.handleRepositoryException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.api.prefix.PrefixService;
-import org.apache.marmotta.platform.core.api.triplestore.ContextService;
-import org.apache.marmotta.platform.core.api.triplestore.LdpService;
-import org.apache.marmotta.platform.core.api.triplestore.SesameService;
-
-import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.vocabulary.RDF;
-import org.openrdf.model.vocabulary.RDFS;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.slf4j.Logger;
-
-import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
-
-/**
- * (Experimental) Implementation for supporting LDP (WIP)
- * 
- * @author Sergio Fernández
- *
- */
-@ApplicationScoped
-public class LdpServiceImpl implements LdpService {
-    
-    private URI context;
-    
-    @Inject
-    private Logger log;
-    
-    @Inject
-    private ConfigurationService configurationService;
-    
-    @Inject
-    private SesameService sesameService;
-    
-    @Inject
-    private ContextService contextService;
-    
-    @Inject
-    private PrefixService prefixService;
-    
-    @PostConstruct
-    public void initialize() {
-        String uri = getBaseContainer();
-        try {
-            this.context = contextService.createContext(uri, "ldp (experimental context)");
-            createContainer(uri, "ldp base container");
-        } catch (URISyntaxException e) {
-            log.error("Root LDP Container {} cannot be created: {}", uri, e.getMessage());
-        }        
-    }
-    
-    @Override
-    public String getBaseContainer() {
-        return configurationService.getBaseContext() + ConfigurationService.LDP_PATH;
-    }
-    
-    @Override
-    public List<URI> list() {
-        List<URI> containers = new ArrayList<URI>();
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                Iterable<Resource> results = ResourceUtils.listResources(conn, conn.getValueFactory().createURI(prefixService.getNamespace("ldp"),
"Container"));
-                for (Resource result : results) {
-                    if(result instanceof URI) {
-                        containers.add((URI)result);
-                    }  
-                }
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch (RepositoryException e) {
-            handleRepositoryException(e, LdpServiceImpl.class);
-        }
-        return containers;
-    }
-    
-    @Override
-    public URI get(String uri) {
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                return (ResourceUtils.existsResource(conn, uri) ? ResourceUtils.getUriResource(conn,
uri) : null);
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch(RepositoryException ex) {
-            handleRepositoryException(ex, LdpServiceImpl.class);
-        }
-        return null;
-    }
-
-    @Override
-    public boolean create(String uri) throws URISyntaxException {
-        return create(uri, null);
-    }
-
-    @Override
-    public boolean create(String uri, String title) throws URISyntaxException {
-        URI parent = getParentContainer(uri);
-        if (parent != null) {
-            return createResource(uri, parent);
-        } else {
-           throw new URISyntaxException(uri, "Non suitable parent container found");
-        }
-    }
-    
-    private boolean createResource(String uri, URI container) {
-        //TODO: refactor this code, already implemented at the ResourceWebService, 
-        //by moving all business logic to a service
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                ValueFactory factory = conn.getValueFactory();
-                URI resource = ResourceUtils.getUriResource(conn, uri);
-                //TODO: chek if already exists
-                conn.add(resource, RDF.TYPE, factory.createURI(prefixService.getNamespace("ldp"),
"Resource"), container);
-                conn.add(resource, factory.createURI(prefixService.getNamespace("dct"), "created"),
factory.createLiteral(new Date()), container);
-                conn.add(container, RDFS.MEMBER, resource, container);
-                return true; //FIXME: 201 vs 200
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch (RepositoryException ex) {
-            return false;
-        }
-    }
-
-    private boolean createContainer(String container, String title) throws URISyntaxException
{
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                ValueFactory factory = conn.getValueFactory();
-                URI uri = ResourceUtils.getUriResource(conn, container);
-                conn.add(uri, RDF.TYPE, factory.createURI(prefixService.getNamespace("ldp"),
"Container"), context);
-                conn.add(uri, RDFS.LABEL, factory.createLiteral(title), context);
-                conn.add(uri, factory.createURI(prefixService.getNamespace("dct"), "created"),
factory.createLiteral(new Date()), context);
-                log.info("Created new container <{}>", uri.stringValue());
-                return true;
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch(RepositoryException ex) {
-            handleRepositoryException(ex, LdpServiceImpl.class);
-        }
-        return false;
-    }
-    
-//    @Override
-//    public boolean addMember(String container, String member) {
-//        //TODO: check parent relationship
-//        try {
-//            RepositoryConnection conn = sesameService.getConnection();
-//            try {
-//                checkConnectionNamespace(conn);
-//                URI parent = ResourceUtils.getUriResource(conn, container);
-//                URI uri = ResourceUtils.getUriResource(conn, member);
-//                URI context = parent; //TODO: for the moment, every container is also a
context (named graph) for us
-//                conn.add(parent, RDFS.MEMBER, uri, context);
-//                log.info("Created new container <{}>", uri.stringValue());
-//            } finally {
-//                conn.commit();
-//                conn.close();path
-//            }
-//            return true;
-//        } catch(RepositoryException ex) {
-//            handleRepositoryException(ex, LdpServiceImpl.class);
-//            return false;
-//        }
-//    }
-
-    @Override
-    public boolean delete(String uri) throws RepositoryException {
-        if (isContainer(uri)) {
-            return deleteContainer(uri);
-        } else {
-            return deleteResource(uri);
-        }
-    }
-
-    /**
-     * Resource deletion
-     * 
-     * @todo refactor this code, already implemented at the ResourceWebService, by moving
all business logic to a service
-     * 
-     * @param uri
-     * @return
-     * @throws RepositoryException
-     */
-    private boolean deleteResource(String uri) throws RepositoryException {
-        //TODO: refactor this code, already implemented at the ResourceWebService, 
-        //by moving all business logic to a service
-        RepositoryConnection conn = sesameService.getConnection();
-        URI parent;
-        try {
-            parent = getParentContainer(uri);
-        } catch (URISyntaxException e) {
-            parent = null;
-        }
-        try {
-            conn.begin();
-            URI resource = conn.getValueFactory().createURI(uri);
-            conn.remove(resource, null, null, parent);
-            return true;
-        } finally {
-            conn.commit();
-            conn.close();
-        }
-    }
-
-    /**
-     * Container deleteion
-     * (using a composition model)
-     * 
-     * @param uri
-     * @return
-     * @throws RepositoryException 
-     */
-    private boolean deleteContainer(String uri) throws RepositoryException {
-        RepositoryConnection conn = sesameService.getConnection();
-        try {
-            conn.begin();
-            URI context = conn.getValueFactory().createURI(uri);
-            conn.remove((Resource)null, null, null, context);
-            return true;
-        } finally {
-            conn.commit();
-            conn.close();
-        }
-    }
-
-    /**
-     * Check the connection's namespace, using the base context when needed
-     * 
-     * @param conn
-     * @throws RepositoryException
-     */
-    private void checkConnectionNamespace(RepositoryConnection conn)
-            throws RepositoryException {
-        if(conn.getNamespace(DEFAULT_PREFIX) == null) {
-            conn.setNamespace(DEFAULT_PREFIX, getBaseContainer());
-        }
-    }
-    
-    /**
-     * Check whenever this URI represents a PDPC
-     * 
-     * @param uri
-     * @return
-     */
-    private boolean isContainer(String uri) {
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                Iterable<Resource> results = ResourceUtils.listResources(conn, conn.getValueFactory().createURI(prefixService.getNamespace("ldp"),
"Container"),  conn.getValueFactory().createURI(uri));
-                for (Resource result : results) {
-                    if(result instanceof URI) {
-                        if (uri.equals(result.stringValue())) {
-                            return true;
-                        }
-                    }  
-                }
-                return false;
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch (RepositoryException e) {
-            handleRepositoryException(e, LdpServiceImpl.class);
-            return false;
-        }
-    }
-    
-    /**
-     * Get the parent container for a resource
-     * 
-     * @param uri
-     * @return
-     * @throws URISyntaxException
-     */
-    private URI getParentContainer(String uri) throws URISyntaxException {
-        String base = this.getBaseContainer();
-        if (!uri.startsWith(base)) {
-            throw new URISyntaxException(uri, "Invalid URI: base URI does not matches with
" + base);
-        }
-        if (base.equals(uri)) {
-            log.error("{} is already the base container", uri);
-            return null;
-        }
-        String parent = uri.substring(0, uri.lastIndexOf('/'));
-        try {
-            RepositoryConnection conn = sesameService.getConnection();
-            try {
-                checkConnectionNamespace(conn);
-                conn.begin();
-                if (!ResourceUtils.existsResource(conn, parent)) {
-                    log.warn("Container {} does not exist, so creating it...", parent);
-                    createContainer(parent, parent);
-                }
-                return ResourceUtils.getUriResource(conn, parent);
-            } finally {
-                conn.commit();
-                conn.close();
-            }
-        } catch (RepositoryException e) {
-            log.error("Error checking context {}: {}", parent, e.getMessage());
-            return null;
-        }
-        
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/1e3bf9b2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/LdpWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/LdpWebService.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/LdpWebService.java
deleted file mode 100644
index d489512..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/LdpWebService.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.platform.core.webservices.triplestore;
-
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.api.triplestore.LdpService;
-import org.apache.marmotta.platform.core.util.WebServiceUtil;
-import org.openrdf.model.URI;
-import org.openrdf.repository.RepositoryException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static javax.ws.rs.core.Response.status;
-
-/**
- * LDP Web Service (isolated for the moment for experimenting with
- * the concepts, but at some point it should be merged back to 
- * {@link org.apache.marmotta.platform.core.webservices.resource.ResourceWebService})
- * 
- * @author Sergio Fernández
- *
- */
-@ApplicationScoped
-@Path("/" + ConfigurationService.LDP_PATH)
-public class LdpWebService {
-
-    @Inject
-    private ConfigurationService configurationService;
-    
-    @Inject
-    private LdpService ldpService;
-
-    private static final String  UUID_PATTERN = "{uuid:[^#?]+}";
-    
-    /**
-     * Produces a list of all containers available 
-     * 
-     * @return list of container
-     */
-    @GET
-    @Produces("application/json")
-    public Response list() {
-        try {
-            List<String> l = new ArrayList<String>();
-            for(URI container : ldpService.list()) {
-                l.add(container.stringValue());
-            }
-            return Response.ok().entity(l).build();
-        } catch(Exception e) {
-            return Response.serverError().entity(e.getMessage()).build();
-        }
-    }
-    
-    /**
-     * Returns the content stored on this resource/container
-     * 
-     * @param types, accepted formats
-     * @param uuid, a unique container identifier
-     * @return redirect response to the export service
-     */
-    @GET
-    @Path(UUID_PATTERN) 
-    public Response get(@HeaderParam("Accept") String types, @PathParam("uuid") String uuid)
throws UnsupportedEncodingException,
-    URISyntaxException {
-        String uri = buildUri(uuid);
-        if (ldpService.get(uri) != null) {
-            java.net.URI seeAlso = new java.net.URI(configurationService.getBaseUri() + ConfigurationService.RESOURCE_PATH
+ "?uri=" + uri);
-            return Response.seeOther(seeAlso).header("Accept", types).build();
-        } else {
-            return Response.status(Status.NOT_FOUND).entity("Container not found").header("Accept",
types).build();
-        }
-    }
-    
-    @POST
-    @Path(UUID_PATTERN) 
-    public Response create(@HeaderParam("Accept") String types, @PathParam("uuid") String
uuid, @QueryParam("title") String title) throws UnsupportedEncodingException,
-    URISyntaxException {
-        String uri = buildUri(uuid);
-        if (ldpService.create(uri)) {
-            Response response = status(Status.CREATED).entity("Container created").header("Accept",
types).build();
-            response.getMetadata().add("Location", uri);
-            response.getMetadata().add("Vary", "Content-Type");
-            return response;
-        } else {
-            return Response.status(Status.CONFLICT).entity("Container already exists").header("Accept",
types).build();
-        }
-    }
-    
-    /**
-     * Deletes this resource/container
-     * 
-     * @param types formats accepted
-     * @param uuid container identifier
-     * @return response
-     */
-    @DELETE
-    @Path(UUID_PATTERN)
-    public Response delete(String types, @PathParam("uuid") String uuid) {
-        String uri = buildUri(uuid);
-        try {
-            final boolean deleted = ldpService.delete(uri);
-            if (deleted) {
-                return Response.ok().build();
-            } else {
-                return Response.status(Response.Status.NOT_FOUND).build();
-            }
-        } catch (RepositoryException ex) {
-            return Response.serverError().entity(ex.getMessage()).build();
-        }
-    }
-    
-    private String buildBaseUri() {
-        String root = configurationService.getBaseUri();
-        return root.substring(0, root.length() - 1) + WebServiceUtil.getResourcePath(this)
+ "/";
-    }
-
-    private String buildUri(String uuid) {
-        return buildBaseUri() + uuid;
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/1e3bf9b2/platform/marmotta-core/src/main/resources/kiwi-module.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/kiwi-module.properties b/platform/marmotta-core/src/main/resources/kiwi-module.properties
index 7fe8273..5e758f2 100644
--- a/platform/marmotta-core/src/main/resources/kiwi-module.properties
+++ b/platform/marmotta-core/src/main/resources/kiwi-module.properties
@@ -71,8 +71,7 @@ webservices=org.apache.marmotta.platform.core.webservices.config.ConfigurationWe
   org.apache.marmotta.platform.core.webservices.resource.MetaWebService,\
   org.apache.marmotta.platform.core.webservices.resource.ContentWebService,\
   org.apache.marmotta.platform.core.webservices.resource.InspectionWebService,\
-  org.apache.marmotta.platform.core.webservices.triplestore.LdpWebService,\
   org.apache.marmotta.platform.core.webservices.triplestore.ContextWebService,\
   org.apache.marmotta.platform.core.webservices.prefix.PrefixWebService,\
   org.apache.marmotta.platform.core.webservices.logging.LoggingWebService
-  
\ No newline at end of file
+  


Mime
View raw message