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/02/22 16:21:37 UTC
[3/37] MARMOTTA-105: renamed packages in marmotta-core
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
new file mode 100644
index 0000000..f9dd25e
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
@@ -0,0 +1,613 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.resource;
+
+import static javax.ws.rs.core.Response.status;
+
+import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.content.ContentService;
+import org.apache.marmotta.platform.core.api.io.LMFIOService;
+import org.apache.marmotta.platform.core.api.triplestore.SesameService;
+import org.apache.marmotta.platform.core.services.sesame.KiWiSesameUtil;
+import org.apache.commons.lang.StringUtils;
+import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.commons.http.ETagGenerator;
+import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.openrdf.model.Resource;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Resource Web Services
+ *
+ * @author Thomas Kurz
+ * @author Sergio Fernández
+ */
+@ApplicationScoped
+@Path("/" + ConfigurationService.RESOURCE_PATH)
+public class ResourceWebService {
+
+ @Inject
+ private Logger log;
+
+ public static final String CHARSET = "utf-8";
+
+ public static final String MIME_PATTERN = "/{mimetype:[^/]+/[^/]+}";
+
+ public static final String UUID_PATTERN = "/{uuid:[^#?]+}";
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ @Inject
+ private ContentService contentService;
+
+ @Inject
+ private LMFIOService kiWiIOService;
+
+ @Inject
+ private SesameService sesameService;
+
+ @Inject
+ private ContentWebService contentWebService;
+
+ @Inject
+ private MetaWebService metaWebService;
+
+ /**
+ * Return the options that are available for a resource with the given URI.
+ *
+ * @param uri
+ * , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @return HTTP response (empty body)
+ * @ResponseHeader Access-Control-Allow-Methods the HTTP methods that are allowable for the given resource
+ * @ResponseHeader Access-Control-Allow-Origin the origins that are allowable for cross-site scripting on this resource
+ */
+ @OPTIONS
+ public Response optionsResourceRemote(@QueryParam("uri") String uri, @HeaderParam("Access-Control-Request-Headers") String reqHeaders) {
+ if(reqHeaders == null) {
+ reqHeaders = "Accept, Content-Type";
+ }
+
+ if(uri == null)
+ return Response.ok()
+ .header("Allow", "POST")
+ .header("Access-Control-Allow-Methods","POST")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .build();
+ else {
+ try {
+ uri = URLDecoder.decode(uri, "utf-8");
+
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ URI resource = ResourceUtils.getUriResource(conn,uri);
+ conn.commit();
+
+ if(resource != null) return Response.ok()
+ .header("Allow","PUT, GET, DELETE")
+ .header("Access-Control-Allow-Methods","PUT, GET, DELETE")
+ .header("Access-Control-Allow-Headers",reqHeaders)
+ .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .build();
+ else
+ return Response.ok()
+ .header("Allow", "POST")
+ .header("Access-Control-Allow-Methods","POST")
+ .header("Access-Control-Allow-Headers",reqHeaders)
+ .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .build();
+ } finally {
+ conn.close();
+ }
+
+ } catch(UnsupportedEncodingException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ } catch (RepositoryException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ }
+ }
+
+ }
+
+ /**
+ * Return the options that are available for a resource with the given URI.
+ *
+ * @param uuid
+ * , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @return HTTP response (empty body)
+ * @ResponseHeader Access-Control-Allow-Methods the HTTP methods that are allowable for the given resource
+ * @ResponseHeader Access-Control-Allow-Origin the origins that are allowable for cross-site scripting on this resource
+ */
+ @OPTIONS
+ @Path(UUID_PATTERN)
+ public Response optionsResourceLocal(@PathParam("uuid") String uuid, @HeaderParam("Access-Control-Request-Headers") String reqHeaders) {
+ String uri = configurationService.getBaseUri() + "resource/" + uuid;
+
+ if(reqHeaders == null) {
+ reqHeaders = "Accept, Content-Type";
+ }
+
+ if(uuid == null)
+ return Response.status(Status.NOT_FOUND).build();
+ else {
+ try {
+ uri = URLDecoder.decode(uri, "utf-8");
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ URI resource = ResourceUtils.getUriResource(conn,uri);
+ conn.commit();
+
+
+ if(resource != null) return Response.ok()
+ .header("Allow","PUT, GET, DELETE")
+ .header("Access-Control-Allow-Methods","PUT, GET, DELETE")
+ .header("Access-Control-Allow-Headers",reqHeaders)
+ .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .build();
+ else
+ return Response.ok()
+ .header("Allow","POST")
+ .header("Access-Control-Allow-Methods","POST")
+ .header("Access-Control-Allow-Headers",reqHeaders)
+ .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .build();
+
+ } finally {
+ conn.close();
+ }
+ } catch(UnsupportedEncodingException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ } catch (RepositoryException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ }
+ }
+
+ }
+
+ // ******************************************* P O S T
+ // ***********************************
+ // **************** POST (New or Remote)
+
+ /**
+ * Creates new resource with given uri. If no uri is defined it creates a
+ * local uri with random uuid
+ *
+ * @param uri
+ * , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @return HTTP response (body is a String message)
+ * @HTTP 201 new resource created
+ * @HTTP 302 resource already exists
+ * @HTTP 500 Internal Error
+ * @ResponseHeader Location the url of the new/found resource
+ */
+ @POST
+ public Response postNewOrRemote(@QueryParam("uri") String uri) throws UnsupportedEncodingException {
+ if (uri == null)
+ return post(configurationService.getBaseUri() + "resource/" + UUID.randomUUID().toString(), false);
+ else
+ return post(uri, true);
+ }
+
+ // **************** POST (Locale)
+
+ /**
+ * Creates new local resource with given uuid.
+ *
+ * @param uuid a unique identifier (must not contain url specific characters like /,# etc.)
+ * @return HTTP response (body is a String message)
+ * @HTTP 201 new resource created
+ * @HTTP 200 resource already exists
+ * @HTTP 500 Internal Error
+ * @ResponseHeader Location the url of the new/found resource
+ */
+ @POST
+ @Path(UUID_PATTERN)
+ public Response postLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException {
+ return post(configurationService.getBaseUri() + "resource/" + uuid, false);
+ }
+
+ // **************** POST (Generic)
+ private Response post(String uri, boolean remote) throws UnsupportedEncodingException {
+ try {
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ String location = remote ? configurationService.getServerUri() + ConfigurationService.RESOURCE_PATH + "?uri=" + uri : uri;
+ Response.Status status;
+ if (ResourceUtils.getUriResource(conn,uri) != null) {
+ status = Status.OK;
+ } else {
+ conn.getValueFactory().createURI(uri);
+ status = Status.CREATED;
+ }
+ Response response = status(status).entity(uri).build();
+ response.getMetadata().add("Location", location);
+ response.getMetadata().add("Vary", "Content-Type");
+ return response;
+ } finally {
+ conn.commit();
+ conn.close();
+ }
+ } catch (RepositoryException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ }
+ }
+
+ /**
+ * Returns a link to a local resource (data or content) with the given uuid
+ * and an accepted return type
+ *
+ * @param uuid
+ * , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @return a link to a local resource's data or content
+ * @HTTP 303 resource can be found in the requested format under Location
+ * @HTTP 404 resource cannot be found
+ * @HTTP 406 resource cannot be found in the given format
+ * @HTTP 500 Internal Error
+ * @RequestHeader Accept accepted mimetypes; value must follow the pattern
+ * (.+/.+(;rel=(content|meta))?,)+
+ * @ResponseHeader Location (for HTTP 303) the url of the resource in the
+ * requested format
+ * @ResponseHeader Content-Type (for HTTP 406) a list of available types
+ * (content and meta)
+ */
+ @GET
+ @Path(UUID_PATTERN)
+ public Response getLocal(@PathParam("uuid") String uuid, @HeaderParam("Accept") String types) throws UnsupportedEncodingException {
+ String uri = configurationService.getBaseUri() + "resource/" + uuid;
+ try {
+ return get(uri, types, uuid);
+ } catch (URISyntaxException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ // **************** GET REMOTE (eq. generic) ***********************
+
+ /**
+ * Returns a link to a remote resource (data or content) with the given uri
+ * and an accepted return type
+ *
+ * @param uri the fully-qualified URI of the resource to create in the triple store
+ * @param format forces representation format (optional, normal content negotiation performed if empty)
+ * @HTTP 303 resource can be found in the requested format under Location
+ * @HTTP 400 bad request (maybe uri is not defined)
+ * @HTTP 404 resource cannot be found
+ * @HTTP 406 resource cannot be found in the given format
+ * @HTTP 500 Internal Error
+ * @RequestHeader Accept accepted mimetypes; value must follow the pattern
+ * (.+/.+(;rel=(content|meta))?,)+
+ * @ResponseHeader Location the url of the resource in the requested format
+ * @ResponseHeader Content-Type (for HTTP 406) a list of available types
+ * (content and meta)
+ */
+ @GET
+ public Response getRemote(@QueryParam("uri") String uri, @QueryParam("format") String format, @HeaderParam("Accept") String types)
+ throws UnsupportedEncodingException {
+ try {
+ if (uri != null) {
+ if (format != null && StringUtils.isNotBlank(format)) {
+ types = format;
+ }
+ //TODO: add 'If-None-Match' support, sending a '304 Not Modified' when the ETag matches
+ return get(uri, types, null);
+ } else
+ return Response.status(400).entity("uri may not be null").build();
+ } catch (URISyntaxException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ private Response get(String uri, String types, String uuid) throws URISyntaxException, UnsupportedEncodingException {
+ try {
+
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ URI resource = ResourceUtils.getUriResource(conn, uri);
+ if (resource == null) return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "the requested resource could not be found in LMF right now, but may be available again in the future");
+ // FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
+ // "/" + uuid;
+
+ List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
+ for(ContentType t : offeredTypes) {
+ t.setParameter("rel", "meta");
+ }
+ String contentmime = contentService.getContentType(resource);
+ if(contentmime != null) {
+ ContentType tContent = LMFHttpUtils.parseContentType(contentmime);
+ tContent.setParameter("rel", "content");
+ offeredTypes.add(0,tContent);
+ }
+
+ if (types == null || types.equals("")) {
+ return build406(Collections.<ContentType>emptyList(), offeredTypes);
+ }
+
+ List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(types);
+ ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+
+ log.debug("identified best type: {}",bestType);
+
+ if(bestType != null) {
+ Response response = buildGetResponse(resource, uuid, bestType);
+ response.getMetadata().add("Last-Modified", KiWiSesameUtil.lastModified(resource, conn));
+ response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, resource) + "\"");
+ return response;
+ } else {
+ return build406(acceptedTypes, offeredTypes);
+ }
+ } finally {
+ conn.commit();
+ conn.close();
+ }
+ } catch (IllegalArgumentException e) {
+ return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
+ } catch (RepositoryException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ private Response build406(List<ContentType> acceptedTypes, List<ContentType> offeredTypes) {
+ ResponseBuilder response = Response.status(Status.NOT_ACCEPTABLE);
+ response.header("Content-Type", "text/plain; charset=UTF-8");
+
+ StringBuilder entity = new StringBuilder();
+ entity.append("Could not find matching type for "+acceptedTypes+"\n");
+ entity.append("choose one of the following:");
+ for (ContentType contentType : offeredTypes) {
+ entity.append(" ").append(contentType).append("\n");
+ }
+ entity.append("\n");
+ response.entity(entity.toString());
+ return response.build();
+ }
+
+
+
+
+ // ******************************************* P U T
+ // ***********************************
+ // **************** PUT LOCALE ***********************
+
+ /**
+ * Returns a Link where the given data (metadata or content) can be put to
+ * the local resource
+ *
+ * @param uuid
+ * , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @return a link where the data can be put (depends on Content-Type)
+ * @HTTP 303 resource in given format can be put under Location
+ * @HTTP 404 resource cannot be found
+ * @HTTP 415 Content-Type is not supported
+ * @HTTP 500 Internal Error
+ * @RequestHeader Content-Type type of the body; value must follow the
+ * pattern .+/.+(;rel=(content|meta))?
+ * @ResponseHeader Location (for HTTP 303) the url where data can be put
+ */
+ @PUT
+ @Path(UUID_PATTERN)
+ public Response putLocal(@PathParam("uuid") String uuid, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException {
+ String uri = configurationService.getBaseUri() + "resource/" + uuid;
+ try {
+ return put(uri, type, uuid,request);
+ } catch (URISyntaxException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ // **************** PUT REMOTE (eq. generic) ***********************
+
+ /**
+ * Returns a Link where the given data (metadata or content) can be put to
+ * the remote resource
+ *
+ * @param uri
+ * , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @return a link where the data can be put (depends on Content-Type)
+ * @HTTP 303 resource in given format can be put under Location
+ * @HTTP 400 bad request (e.g. uri is null)
+ * @HTTP 404 resource cannot be found
+ * @HTTP 415 Content-Type is not supported
+ * @HTTP 500 Internal Error
+ * @RequestHeader Content-Type type of the body; value must follow the
+ * pattern .+/.+(;rel=(content|meta))?
+ * @ResponseHeader Location (for HTTP 303) the url where data can be put
+ */
+ @PUT
+ public Response putRemote(@QueryParam("uri") String uri, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException {
+ try {
+ if (uri != null) return put(URLDecoder.decode(uri, "utf-8"), type, null, request);
+ else
+ return Response.status(400).entity("uri may not be null").build();
+ } catch (URISyntaxException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ private Response put(String uri, String mimetype, String uuid, HttpServletRequest request) throws URISyntaxException, UnsupportedEncodingException {
+ try {
+ // FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
+ // "/" + uuid;
+ if (mimetype == null) return Response.status(400).entity("content-type may not be null").build();
+
+
+ // the offered types are those sent by the client in the Content-Type header; if the rel attribute is not
+ // given, we add the default rel value
+ List<ContentType> types = LMFHttpUtils.parseAcceptHeader(mimetype);
+ for(ContentType type : types) {
+ if(type.getParameter("rel") == null) {
+ type.setParameter("rel",configurationService.getStringConfiguration("linkeddata.mime.rel.default", "meta"));
+ }
+ }
+
+ // the acceptable types are all types for content and the meta types we have parsers for; we do not care so
+ // much about the order ...
+ List<ContentType> acceptable = LMFHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
+ for(ContentType a : acceptable) {
+ a.setParameter("rel", "meta");
+ }
+ ContentType allContent = new ContentType("*","*");
+ allContent.setParameter("rel", "content");
+ acceptable.add(0,allContent);
+
+ // determine the best match between the offered types and the acceptable types
+ ContentType bestType = LMFHttpUtils.bestContentType(types,acceptable);
+
+ if (bestType != null) {
+ if (configurationService.getBooleanConfiguration("linkeddata.redirect.put", true)) {
+ final RepositoryConnection con = sesameService.getConnection();
+ try {
+ con.begin();
+ URI resource = ResourceUtils.getUriResource(con, uri);
+ con.commit();
+ return Response
+ .status(configurationService.getIntConfiguration("linkeddata.redirect.status", 303))
+ // .location(new URI(configurationService.getBaseUri() +
+ // bestType.getParameter("rel") + "/" + bestType.getMime() + appendix))
+ .location(new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource, bestType, configurationService)))
+ .build();
+ } finally {
+ con.close();
+ }
+ } else {
+ if("content".equalsIgnoreCase(bestType.getParameter("rel")))
+ return contentWebService.putContent(uri, bestType.getMime(), request);
+ else if ("meta".equalsIgnoreCase(bestType.getParameter("rel")))
+ return metaWebService.putMeta(uri, bestType.getMime(), request);
+ else
+ return Response.serverError().entity("request did not specify whether it uploads content or metadata; use rel=content|meta attribute in Content-Type header").build();
+ }
+ } else {
+ Response response = Response.status(415).entity("type " + mimetype + " not supported").build();
+ ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getAcceptTypes()));
+ return response;
+ }
+ } catch (RepositoryException e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ // ******************************************* D E L E T E
+ // ***********************************
+ // **************** DELETE RESOURCE ***********************
+
+ /**
+ * Delete remote resource with given uri
+ *
+ * @param uri
+ * , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @return HTTP response (success or error)
+ * @HTTP 200 resource deleted
+ * @HTTP 400 bad request (e.g, uri is null)
+ * @HTTP 404 resource not found
+ */
+ @DELETE
+ public Response deleteResourceRemote(@QueryParam("uri") String uri) throws UnsupportedEncodingException {
+
+ if (uri != null) {
+ try {
+ RepositoryConnection conn = sesameService.getConnection();
+ try {
+ conn.begin();
+ Resource resource = ResourceUtils.getUriResource(conn,URLDecoder.decode(uri, "utf-8"));
+ if (resource != null) {
+ ResourceUtils.removeResource(conn,resource);
+ return Response.ok().build();
+ } else
+ return Response.status(Response.Status.NOT_FOUND).build();
+ } finally {
+ conn.commit();
+ conn.close();
+ }
+ } catch (RepositoryException ex) {
+ return Response.serverError().entity(ex.getMessage()).build();
+ }
+ } else
+ return Response.status(400).entity("uri may not be null").build();
+ }
+
+ /**
+ * Delete local resource with given uuid
+ *
+ * @param uuid
+ * , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @return HTTP response (success or error)
+ * @HTTP 200 resource deleted
+ * @HTTP 404 resource not found
+ */
+ @DELETE
+ @Path(UUID_PATTERN)
+ public Response deleteResourceLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException {
+ String uri = configurationService.getBaseUri() + "resource/" + uuid;
+ return deleteResourceRemote(uri);
+ }
+
+ private Response buildGetResponse(URI resource, String uuid,
+ ContentType type) {
+ try {
+
+ return Response
+ .status(configurationService.getIntConfiguration(
+ "linkeddata.redirect.status", 303))
+ .header("Vary", "Accept")
+ .header("Content-Type", type.toString())
+ // .location(new URI(configurationService.getBaseUri() +
+ // type.getParameter("rel") + "/" + type.getType() + "/"
+ // +type.getSubtype() +
+ // appendix))
+ .location(
+ new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource,
+ type.getParameter("rel"), type.getMime(), configurationService)))
+ .build();
+
+ } catch (Exception e) {
+ return Response.serverError().build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
new file mode 100644
index 0000000..f25bcea
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.resource;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.services.templating.TemplatingHelper;
+import org.apache.marmotta.commons.http.ContentType;
+import org.openrdf.model.URI;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Helper methods shared accross the difference resource web services
+ *
+ * @author Sergio Fernández
+ *
+ */
+public class ResourceWebServiceHelper {
+
+ public static void addHeader(Response response, String name, String value) {
+ response.getMetadata().add(name, value);
+ }
+
+ public static String appendTypes(List<String> datamimes, String mime) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(appendContentTypes(mime));
+ sb.append(appendMetaTypes(datamimes));
+ return sb.toString();
+ }
+
+ public static String appendMetaTypes(List<String> datamimes) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < datamimes.size(); i++) {
+ sb.append(datamimes.get(i));
+ sb.append(";rel=meta");
+ if (i < datamimes.size() - 1) {
+ sb.append(",");
+ }
+ }
+ return sb.toString();
+ }
+
+ public static String appendContentTypes(String mime) {
+ if (mime != null) {
+ return mime + ";rel=content";
+ } else {
+ return "";
+ }
+ }
+
+ public static String buildContentLink(URI resource, String uuid, String mime, ConfigurationService configurationService) {
+ // test if there is content
+ StringBuffer b = new StringBuffer();
+ if (mime != null) {
+ b.append("<");
+ // b.append(configurationService.getBaseUri() + "content/" + mime +
+ // appendix);
+ b.append(buildResourceLink(resource, ConfigurationService.CONTENT_PATH, mime, configurationService));
+ b.append(">");
+ b.append(";type=");
+ b.append(mime);
+ b.append(";rel=content");
+ }
+ return b.toString();
+ }
+
+ public static String buildMetaLinks(URI resource, String uuid, List<String> datamimes, ConfigurationService configurationService) {
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < datamimes.size(); i++) {
+ b.append("<");
+ // b.append(configurationService.getBaseUri() + "meta/" +
+ // datamimes.get(i) + appendix);
+ b.append(buildResourceLink(resource, ConfigurationService.META_PATH, datamimes.get(i), configurationService));
+ b.append(">");
+ b.append(";type=");
+ b.append(datamimes.get(i));
+ b.append(";rel=meta");
+ if (i < datamimes.size() - 1) {
+ b.append(",");
+ }
+ }
+ return b.toString();
+ }
+
+ public static String buildResourceLink(URI resource, ContentType cType, ConfigurationService configurationService) {
+ return buildResourceLink(resource, cType.getParameter("rel"),
+ cType.getMime(), configurationService);
+ }
+
+ public static String buildResourceLink(URI resource, String rel, String mime, ConfigurationService configurationService) {
+ final String src = configurationService.getServerUri(), base = configurationService
+ .getBaseUri();
+
+ if (src.equals(base)
+ && resource.stringValue().startsWith(base + ConfigurationService.RESOURCE_PATH + "/")) {
+ final String uuid;
+ uuid = resource.stringValue().substring(
+ (base + "resource/").length());
+ return String.format("%s%s/%s/%s", base, rel, mime, uuid);
+
+ } else {
+ try {
+ return String.format("%s%s/%s?uri=%s", src, rel, mime,
+ URLEncoder.encode(resource.stringValue(), ResourceWebService.CHARSET));
+ } catch (UnsupportedEncodingException e) {
+ return String.format("%s%s/%s?uri=%s", src, rel, mime,
+ resource.stringValue());
+ }
+ }
+ }
+
+ public static Response buildErrorPage(String uri, String base, Status status, String message) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("uri", uri);
+ data.put("baseUri", base);
+ data.put("message", message);
+ try {
+ data.put("encoded_uri", URLEncoder.encode(uri, "UTF-8"));
+ } catch (UnsupportedEncodingException uee) {
+ data.put("encoded_uri", uri);
+ }
+ try {
+ return Response.status(status)
+ .entity(TemplatingHelper.processTemplate("404.ftl", data))
+ .build();
+ } catch (Exception e) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity("Not Found").build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/statistics/StatisticsWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/statistics/StatisticsWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/statistics/StatisticsWebService.java
new file mode 100644
index 0000000..b3c65c6
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/statistics/StatisticsWebService.java
@@ -0,0 +1,162 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.statistics;
+
+import org.apache.marmotta.platform.core.api.statistics.StatisticsModule;
+import org.apache.marmotta.platform.core.api.statistics.StatisticsService;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ * <p/>
+ * User: sschaffe
+ */
+@ApplicationScoped
+@Path("/statistics")
+public class StatisticsWebService {
+
+ @Inject
+ private Logger log;
+
+ @Inject
+ private StatisticsService statisticsService;
+
+
+ /**
+ * Enable or disable the statistics gathering. If enabled, might cause additional overhead in execution.
+ *
+ * @param enabled if true, statistics gathering will be enabled, if false, it will be disabled
+ * @HTTP 200 when the statistics gathering has been enabled or disabled successfully
+ * @return OK when changing the statistics setting was successful
+ */
+ @PUT
+ @Path("/enabled")
+ public Response setEnabled(@QueryParam("value") boolean enabled) {
+ if(enabled) {
+ log.info("enabling statistics gathering ...");
+ statisticsService.enableAll();
+ } else {
+ log.info("disabling statistics gathering ...");
+ statisticsService.disableAll();
+ }
+ return Response.ok().entity("statistics gathering "+(enabled?"enabled":"disabled")).build();
+ }
+
+ /**
+ * Return the status of statistics gathering.
+ *
+ * @return Returns true if statistics gathering is enabled, false if it is disabled.
+ */
+ @GET
+ @Path("/enabled")
+ public boolean isEnabled() {
+ return statisticsService.isEnabled();
+ }
+
+ /**
+ * Retrieve the statistics information of all statistics modules.
+ * @return a JSON-formatted map with an entry for each statistics module, where the value is a map of
+ * (key,value) entries for the statistics properties that are collected by the module
+ */
+ @GET
+ @Produces("application/json")
+ @Path("/list")
+ public Map<String,Map<String,String>> getStatistics() {
+ Map<String,Map<String,String>> result = new HashMap<String, Map<String, String>>();
+
+ for(String module : statisticsService.listModules()) {
+ result.put(module, statisticsService.getModule(module).getStatistics());
+ }
+
+ return result;
+ }
+
+ /**
+ * Retrieve the statistics information of the statistics module with the name passed as path argument. The
+ * result format is identical to the result returned by /list
+ *
+ * @param module the module for which to return the statistics
+ * @return a JSON-formatted map with an entry for each statistics module, where the value is a map of
+ * (key,value) entries for the statistics properties that are collected by the module
+ * @HTTP 200 if the statistics module exists
+ * @HTTP 404 if the statistics module does not exist
+ */
+ @GET
+ @Produces("application/json")
+ @Path("/{module}")
+ public Response getStatistics(@PathParam("module") String module) {
+ if(statisticsService.getModule(module) != null) {
+ Map<String,Map<String,String>> result = new HashMap<String, Map<String, String>>();
+
+ result.put(module, statisticsService.getModule(module).getStatistics());
+
+ return Response.ok().entity(result).build();
+ } else
+ return Response.status(404).entity("module with name "+module+" does not exist; available modules: "+statisticsService.listModules()).build();
+ }
+
+ @PUT
+ @Path("/{module}/enabled")
+ public Response setEnabled(@PathParam("module") String module, @QueryParam("value") boolean enabled) {
+ final StatisticsModule mod = statisticsService.getModule(module);
+ if (mod != null) {
+ if (enabled) {
+ mod.enable();
+ } else {
+ mod.disable();
+ }
+ return Response.ok().entity(enabled).build();
+ }
+ else
+ return Response.status(404)
+ .entity("module with name " + module + " does not exist; available modules: " + statisticsService.listModules()).build();
+ }
+
+ @GET
+ @Path("/{module}/enabled")
+ public boolean isEnabled(@PathParam("module") String module) {
+ final StatisticsModule mod = statisticsService.getModule(module);
+ if (mod != null)
+ return mod.isEnabled();
+ else
+ return false;
+ }
+
+ /**
+ * Return a JSON-formatted list of all statistics modules that are available in the system.
+ *
+ * @return a JSON-formatted list of strings, each representing the name of a statistics module
+ */
+ @GET
+ @Produces("application/json")
+ @Path("/modules")
+ public List<String> getModules() {
+ return statisticsService.listModules();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
new file mode 100644
index 0000000..c511d53
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.system;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.triplestore.SesameService;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * Perform various system actions like restarting database access or rebuilding indexes.
+ */
+@ApplicationScoped
+@Path("/system")
+public class SystemWebService {
+
+ @Inject
+ private Logger log;
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ @Inject
+ private SesameService sesameService;
+
+ /**
+ * Reinitialise the database configuration. Will close the database connection and
+ * reopen it, possibly with new settings.
+ *
+ * @return ok if successful, 500 if not
+ * @HTTP 200 if database was reinitialised successfully
+ * @HTTP 500 if there was an error while reinitialising database (see log)
+ */
+ @POST
+ @Path("/database/reinit")
+ public Response reinitDatabase() {
+ log.info("Reinitialising database after admin user request ...");
+ try {
+ sesameService.shutdown();
+ sesameService.initialise();
+
+ return Response.ok().entity("database reinitialised successfully").build();
+ } catch(Exception ex) {
+ log.error("Error while reinitalising database ...",ex);
+ return Response.status(500).entity("error while reinitialising database").build();
+ }
+ }
+
+ @POST
+ @Path("/database/ping")
+ public Response pingDatabase(@QueryParam("type")String type,@QueryParam("url")String url,@QueryParam("user")String user,@QueryParam("pwd")String pwd) {
+ if(type==null||url==null||user==null||pwd==null) {
+ return Response.status(400).entity("one or more values are not defined").build();
+ }
+
+ //get driver
+ String db_driver = configurationService.getStringConfiguration("database."+type+".driver");
+ if(db_driver==null) {
+ return Response.serverError().entity("driver for "+type+" not defined").build();
+ }
+
+ //try if type matches url
+ if(!url.startsWith("jdbc:"+type)) {
+ return Response.serverError().entity("database and url do not match properly").build();
+ }
+
+ //try to connect
+ try {
+ Class.forName(db_driver);
+ Connection conn = DriverManager.getConnection(url,user,pwd);
+ conn.close();
+ return Response.ok().build();
+ } catch (ClassNotFoundException e) {
+ return Response.serverError().entity("Can't load driver " + e).build();
+ } catch (SQLException e) {
+ return Response.serverError().entity("Database access failed " + e).build();
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/task/TaskManagerWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/task/TaskManagerWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/task/TaskManagerWebService.java
new file mode 100644
index 0000000..239b197
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/task/TaskManagerWebService.java
@@ -0,0 +1,134 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.task;
+
+import org.apache.marmotta.platform.core.api.task.Task;
+import org.apache.marmotta.platform.core.api.task.TaskInfo;
+import org.apache.marmotta.platform.core.api.task.TaskManagerService;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+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.core.Response;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+/**
+ * A webservice for listing and managing currently active background tasks of services that support the task manager
+ * interface.
+ *
+ * <p/>
+ * User: sschaffe
+ */
+@ApplicationScoped
+@Path("/tasks")
+public class TaskManagerWebService {
+
+ private static Logger log = LoggerFactory.getLogger(TaskManagerWebService.class);
+
+ @Inject
+ private TaskManagerService taskManagerService;
+
+ /**
+ * List all tasks in all groups currently running in the system. The result
+ * is a map from group to list of tasks, each task formatted as a key-value
+ * map.
+ *
+ * @return List of {@link TaskInfo}s boxed in {@link JSONObject}s
+ */
+ @GET
+ @Path("/")
+ @Produces("application/json")
+ public Map<String, List<TaskInfo>> list() {
+ log.debug("Listing all running tasks.");
+
+ return taskManagerService.getTasksByGroup();
+ }
+
+ @GET
+ @Path("/byThread")
+ @Produces("application/json")
+ public Map<String, List<TaskInfo>> listByThread() {
+ HashMap<String, List<TaskInfo>> result = new HashMap<String, List<TaskInfo>>();
+ final Map<WeakReference<Thread>, Stack<TaskInfo>> tasksByThread = taskManagerService.getTasksByThread();
+ for (Map.Entry<WeakReference<Thread>, Stack<TaskInfo>> e : tasksByThread.entrySet()) {
+ Thread t = e.getKey().get();
+ if (t != null) {
+ result.put(t.getName(), e.getValue());
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * List all tasks in the group given as argument. The result is a map from
+ * group to list of tasks, each task formatted as a key-value map.
+ *
+ * @param group
+ * the group to list the running tasks
+ * @return List of {@link TaskInfo}s boxed in {@link JSONObject}s
+ */
+ @GET
+ @Path("/{group}")
+ @Produces("application/json")
+ public Map<String, List<TaskInfo>> list(@PathParam("group") String group) {
+ log.debug("Listing all tasks of group '{}'", group);
+
+ Map<String, List<TaskInfo>> result = new HashMap<String, List<TaskInfo>>();
+
+ Map<String, List<TaskInfo>> allTasks = taskManagerService.getTasksByGroup();
+ if (allTasks.containsKey(group)) {
+ result.put(group, allTasks.get(group));
+ }
+
+ return result;
+ }
+
+
+ /**
+ * Return the task identified by the id given as argument.
+ *
+ * @param id
+ * the id of the task to return (long value)
+ * @return The {@link Task} boxed in a {@link JSONObject}
+ */
+ @GET
+ @Path("/{group}/{name}")
+ @Produces("application/json")
+ public Response get(@PathParam("group") String group, @PathParam("name") String name) {
+ Map<String, List<TaskInfo>> gList = list(group);
+ if (gList.containsKey(group)) return Response.status(404).entity("Group " + group + " not found").build();
+
+ for (TaskInfo t : gList.get(group)) {
+ if (t != null && t.getName().equals(name)) return Response.ok().entity(t).build();
+ }
+
+ return Response.status(404).entity("Task " + name + " in Group " + group + " not found").build();
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
new file mode 100644
index 0000000..b0d1e14
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
@@ -0,0 +1,193 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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 java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.triplestore.ContextService;
+import org.apache.marmotta.platform.core.util.JerseyUtils;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Context Web Service
+ *
+ * @author Thomas Kurz
+ * @author Sebastian Schaffert
+ * @author Sergio Fernández
+ */
+@ApplicationScoped
+@Path("/" + ConfigurationService.CONTEXT_PATH)
+public class ContextWebService {
+
+ @Inject
+ private ContextService contextService;
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ private static final String UUID_PATTERN = "{uuid:[^#?]+}";
+
+ /**
+ * Indirect context identification, listing in case 'graph' is missing
+ *
+ * @param types
+ * @param context uri
+ * @return
+ * @throws URISyntaxException
+ * @see http://www.w3.org/TR/sparql11-http-rdf-update/#indirect-graph-identification
+ */
+ @GET
+ public Response get(@HeaderParam("Accept") String types, @QueryParam("graph") String context) throws URISyntaxException {
+ URI uri;
+ if (StringUtils.isBlank(context)) {
+ uri = new URI(configurationService.getServerUri() + ConfigurationService.CONTEXT_PATH + "/list");
+ } else {
+ uri = buildExportUri(context);
+ }
+ return Response.seeOther(uri).header("Accept", types).build();
+ }
+
+ /**
+ *
+ * @return a list of URIs representing contexts
+ */
+ @GET
+ @Path("/list")
+ @Produces("application/json")
+ public Response listContexts(@QueryParam("labels") String labels, @QueryParam("filter") String filter) {
+ try {
+ if(labels == null) {
+ ArrayList<String> res = new ArrayList<String>();
+ for(org.openrdf.model.URI r : contextService.listContexts(filter != null)) {
+ res.add(r.stringValue());
+ }
+ return Response.ok().entity(res).build();
+ } else {
+ ArrayList<Map<String,String>> result = new ArrayList<Map<String, String>>();
+ for(org.openrdf.model.URI r : contextService.listContexts(filter != null)) {
+ Map<String,String> ctxDesc = new HashMap<String, String>();
+ ctxDesc.put("uri",r.stringValue());
+ ctxDesc.put("label", contextService.getContextLabel(r));
+ result.add(ctxDesc);
+ }
+ return Response.ok().entity(result).build();
+ }
+ } catch(Exception e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ /**
+ * Returns the content stored on this context
+ *
+ * @param types, accepted formats
+ * @param uuid, a unique context identifier
+ * @return redirects to the export service
+ */
+ @GET
+ @Path(UUID_PATTERN)
+ public Response getContext(@HeaderParam("Accept") String types, @PathParam("uuid") String uuid) throws UnsupportedEncodingException,
+ URISyntaxException {
+ String context = buildUri(uuid);
+ URI uri = buildExportUri(context);
+ return Response.seeOther(uri).header("Accept", types).build();
+ }
+
+ @PUT
+ public Response put(@QueryParam("graph") String context, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws IOException {
+ if (StringUtils.isBlank(context)) {
+ return Response.status(Status.NOT_ACCEPTABLE).entity("missing 'graph' uri for indirect grpah identification").build();
+ } else {
+ if(type != null && type.lastIndexOf(';') >= 0) {
+ type = type.substring(0,type.lastIndexOf(';'));
+ }
+ Set<String> acceptedFormats = contextService.getAcceptFormats();
+ if (type == null || !acceptedFormats.contains(type)) {
+ return Response.status(412).entity("define a valid content-type (types: " + acceptedFormats + ")").build();
+ }
+ final boolean imported = contextService.importContent(context, request.getInputStream(), type);
+ return imported ? Response.ok().build() : Response.status(Status.NOT_FOUND).build();
+ }
+ }
+
+ @PUT
+ public Response putContext(@PathParam("uuid") String uuid, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws IOException {
+ return put(buildUri(uuid), type, request);
+ }
+
+ @DELETE
+ public Response delete(@QueryParam("graph") String context) {
+ if (StringUtils.isBlank(context)) {
+ return Response.status(Status.NOT_ACCEPTABLE).entity("missing 'graph' uri for indirect grpah identification").build();
+ } else {
+ final boolean deleted = contextService.removeContext(context);
+ return deleted ? Response.ok().build() : Response.status(Status.NOT_FOUND).build();
+ }
+ }
+
+ /**
+ * Deletes a named graph from the system
+ *
+ * @param types formats accepted
+ * @param uuid context identifier
+ * @return status code
+ * @throws UnsupportedEncodingException
+ * @throws URISyntaxException
+ */
+ @DELETE
+ @Path(UUID_PATTERN)
+ public Response deleteContext(@PathParam("uuid") String uuid) {
+ return delete(buildUri(uuid));
+ }
+
+ private String buildBaseUri() {
+ String root = configurationService.getBaseUri();
+ return root.substring(0, root.length() - 1) + JerseyUtils.getResourcePath(this) + "/";
+ }
+
+ private String buildUri(String uuid) {
+ return buildBaseUri() + uuid;
+ }
+
+ private URI buildExportUri(String uri) throws URISyntaxException {
+ return new URI(configurationService.getBaseUri() + "export/download?context=" + uri);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/KnowledgeSpaceWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/KnowledgeSpaceWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/KnowledgeSpaceWebService.java
new file mode 100644
index 0000000..63d7e87
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/KnowledgeSpaceWebService.java
@@ -0,0 +1,120 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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 java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.triplestore.ContextService;
+import org.apache.marmotta.platform.core.util.JerseyUtils;
+
+/**
+ * Knowledge space related services
+ *
+ * @author Sergio Fernández
+ *
+ */
+@ApplicationScoped
+@Path("/" + ConfigurationService.KNOWLEDGESPACE_PATH)
+@Deprecated
+public class KnowledgeSpaceWebService {
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ @Inject
+ private ContextService contextService;
+ private static final String UUID_PATTERN = "{uuid:[^#?]+}";
+
+ /**
+ * Get all knowledge spaces
+ *
+ * @return a list of URIs representing the current knowledge spaces
+ */
+ @GET
+ @Produces("application/json")
+ public Response listSpaces() {
+ try {
+ List<org.openrdf.model.URI> l = contextService.listContexts();
+ ArrayList<String> res = new ArrayList<String>();
+ for(org.openrdf.model.URI r : l) {
+ String uri = r.stringValue();
+ if (uri.startsWith(buildBaseUri())) {
+ res.add(uri);
+ }
+ }
+ return Response.ok().entity(res).build();
+ } catch(Exception e) {
+ return Response.serverError().entity(e.getMessage()).build();
+ }
+ }
+
+ /**
+ * Returns the content stored on this context URI
+ *
+ * @param types, accepted formats
+ * @param uuid, a unique context identifier
+ * @return redirects to the export service
+ */
+ @GET
+ @Path(UUID_PATTERN)
+ public Response getContent(@HeaderParam("Accept") String types, @PathParam("uuid") String uuid) throws UnsupportedEncodingException, URISyntaxException {
+ String context = buildUri(uuid);
+ URI uri = new URI(configurationService.getBaseUri() + "export/download?context=" + context);
+ return Response.seeOther(uri).header("Accept", types).build();
+ }
+
+ /**
+ * Deletes a knowledge space from the system
+ *
+ * @param types formats accepted
+ * @param uuid knowledge space uuid
+ * @return status code
+ * @throws UnsupportedEncodingException
+ * @throws URISyntaxException
+ */
+ @DELETE
+ @Path(UUID_PATTERN)
+ public Response cleanContent(String types, @PathParam("uuid") String uuid) throws UnsupportedEncodingException, URISyntaxException {
+ final boolean deleted = contextService.removeContext(buildUri(uuid));
+ return deleted ? Response.ok().build() : Response.status(Status.NOT_FOUND).build();
+ }
+
+ private String buildBaseUri() {
+ String root = configurationService.getBaseUri();
+ return root.substring(0, root.length() - 1) + JerseyUtils.getResourcePath(this) + "/";
+ }
+
+ private String buildUri(String uuid) {
+ return buildBaseUri() + uuid;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/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
new file mode 100644
index 0000000..908f1b9
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/LdpWebService.java
@@ -0,0 +1,151 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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 static javax.ws.rs.core.Response.status;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+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.JerseyUtils;
+
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryException;
+
+/**
+ * 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) + JerseyUtils.getResourcePath(this) + "/";
+ }
+
+ private String buildUri(String uuid) {
+ return buildBaseUri() + uuid;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml b/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
index 1cb33e4..89c4efc 100644
--- a/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
+++ b/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
@@ -348,7 +348,7 @@ are "on" and "off". The default is "autodetect".
memoryStoreEvictionPolicy="LRU"
/>
- <cache name="kiwi.core.model.rdf.KiWiNode"
+ <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiNode"
statistics="true"
maxElementsInMemory="10000"
eternal="true"
@@ -363,21 +363,21 @@ are "on" and "off". The default is "autodetect".
memoryStoreEvictionPolicy="LRU"/>
- <cache name="kiwi.core.model.rdf.KiWiNamespace"
+ <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiNamespace"
statistics="true"
maxElementsInMemory="100"
eternal="true"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
- <cache name="kiwi.core.model.user.KiWiGroup"
+ <cache name="org.apache.marmotta.platform.core.model.user.KiWiGroup"
statistics="true"
maxElementsInMemory="100"
eternal="true"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
- <cache name="kiwi.core.model.user.KiWiUser"
+ <cache name="org.apache.marmotta.platform.core.model.user.KiWiUser"
statistics="true"
maxElementsInMemory="100"
eternal="true"
@@ -385,7 +385,7 @@ are "on" and "off". The default is "autodetect".
memoryStoreEvictionPolicy="LRU"/>
- <cache name="kiwi.core.model.rdf.KiWiTriple"
+ <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiTriple"
statistics="true"
maxElementsInMemory="100000"
eternal="true"
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-defaults.properties b/platform/marmotta-core/src/main/resources/config-defaults.properties
index a92feff..d734db4 100644
--- a/platform/marmotta-core/src/main/resources/config-defaults.properties
+++ b/platform/marmotta-core/src/main/resources/config-defaults.properties
@@ -114,8 +114,8 @@ logging.kiwi.reasoner = INFO
# a reader/writer for content stored in the file system; by default, this is applied to all resources that have
# a file:/ URI. It is disabled by default, because it potentially allows reading/writing all files in the file system
# to only enable reading but disable writing, remove the content.filesystem.writer property
-content.filesystem.reader=kiwi.core.services.content.FileSystemContentReader
-content.filesystem.writer=kiwi.core.services.content.FileSystemContentWriter
+content.filesystem.reader=org.apache.marmotta.platform.core.services.content.FileSystemContentReader
+content.filesystem.writer=org.apache.marmotta.platform.core.services.content.FileSystemContentWriter
content.filesystem.pattern=(${kiwi.home}/resources|${kiwi.context}resource/|urn:).*
#content.filesystem.pattern=file:/tmp/.*
content.filesystem.enabled=true
@@ -125,7 +125,7 @@ content.filesystem.secure=true
# a reader for content stored on a remote HTTP server; by default, this is applied to all resources that are not in
# the context of the LMF web application; enabled by default, because it is a safe operation
-content.http.reader=kiwi.core.services.content.HTTPContentReader
+content.http.reader=org.apache.marmotta.platform.core.services.content.HTTPContentReader
content.http.pattern=(?!${kiwi.context}resource)http://.*
content.http.enabled=false
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/jndi.properties b/platform/marmotta-core/src/main/resources/jndi.properties
index c57dbad..33a8419 100644
--- a/platform/marmotta-core/src/main/resources/jndi.properties
+++ b/platform/marmotta-core/src/main/resources/jndi.properties
@@ -14,4 +14,4 @@
# limitations under the License.
#
-java.naming.factory.initial=kiwi.core.jndi.LMFContextFactory
\ No newline at end of file
+java.naming.factory.initial=org.apache.marmotta.platform.core.jndi.LMFContextFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/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 28eef1f..17d5112 100644
--- a/platform/marmotta-core/src/main/resources/kiwi-module.properties
+++ b/platform/marmotta-core/src/main/resources/kiwi-module.properties
@@ -26,7 +26,7 @@ baseurl=/core
adminpages=/admin/first_steps.html,\
/admin/about.html,\
- /admin/configuration.html,\
+ /admin/configuration.html,^\
/admin/tasks.html,\
/admin/import.html,\
/admin/export.html,\
@@ -36,20 +36,20 @@ adminpages=/admin/first_steps.html,\
/admin/system.html,\
/admin/database.html,
-webservices=kiwi.core.webservices.config.ConfigurationWebService,\
- kiwi.core.webservices.config.DependenciesWebService,\
- kiwi.core.webservices.system.SystemWebService,\
- kiwi.core.webservices.task.TaskManagerWebService,\
- kiwi.core.webservices.io.ImportWebService,\
- kiwi.core.webservices.io.ExportWebService,\
- kiwi.core.webservices.statistics.StatisticsWebService,\
- kiwi.core.webservices.modules.ModuleWebService,\
- kiwi.core.webservices.resource.ResourceWebService,\
- kiwi.core.webservices.resource.MetaWebService,\
- kiwi.core.webservices.resource.ContentWebService,\
- kiwi.core.webservices.resource.InspectionWebService,\
- kiwi.core.webservices.triplestore.LdpWebService,\
- kiwi.core.webservices.triplestore.ContextWebService,\
- kiwi.core.webservices.triplestore.KnowledgeSpaceWebService,\
- kiwi.core.webservices.prefix.PrefixWebService
+webservices=org.apache.marmotta.platform.core.webservices.config.ConfigurationWebService,\
+ org.apache.marmotta.platform.core.webservices.config.DependenciesWebService,\
+ org.apache.marmotta.platform.core.webservices.system.SystemWebService,\
+ org.apache.marmotta.platform.core.webservices.task.TaskManagerWebService,\
+ org.apache.marmotta.platform.core.webservices.io.ImportWebService,\
+ org.apache.marmotta.platform.core.webservices.io.ExportWebService,\
+ org.apache.marmotta.platform.core.webservices.statistics.StatisticsWebService,\
+ org.apache.marmotta.platform.core.webservices.modules.ModuleWebService,\
+ org.apache.marmotta.platform.core.webservices.resource.ResourceWebService,\
+ 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.triplestore.KnowledgeSpaceWebService,\
+ org.apache.marmotta.platform.core.webservices.prefix.PrefixWebService
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/main/resources/logback-template.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/logback-template.xml b/platform/marmotta-core/src/main/resources/logback-template.xml
index 4eff3ea..5d75e67 100644
--- a/platform/marmotta-core/src/main/resources/logback-template.xml
+++ b/platform/marmotta-core/src/main/resources/logback-template.xml
@@ -17,11 +17,11 @@
-->
<configuration scan="true">
- <define name="LMF_HOME" class="kiwi.core.services.logging.LMFLogbackPropertyDefiner">
+ <define name="LMF_HOME" class="org.apache.marmotta.platform.core.services.logging.LMFLogbackPropertyDefiner">
<key>kiwi.home</key>
</define>
- <define name="DEBUG" class="kiwi.core.services.logging.LMFLogbackPropertyDefiner">
+ <define name="DEBUG" class="org.apache.marmotta.platform.core.services.logging.LMFLogbackPropertyDefiner">
<key>debug.enabled</key>
</define>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/ConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/ConfigurationServiceTest.java b/platform/marmotta-core/src/test/disabled/ConfigurationServiceTest.java
index cb5e585..c25ed5a 100644
--- a/platform/marmotta-core/src/test/disabled/ConfigurationServiceTest.java
+++ b/platform/marmotta-core/src/test/disabled/ConfigurationServiceTest.java
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package kiwi.core.test.config;
+package org.apache.marmotta.platform.core.test.config;
import com.google.common.collect.Lists;
-import kiwi.core.test.base.LMFBaseTest;
+import org.apache.marmotta.platform.core.test.base.LMFBaseTest;
import org.junit.Ignore;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/LMFBaseTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/LMFBaseTest.java b/platform/marmotta-core/src/test/disabled/LMFBaseTest.java
index 49ec3c1..d222cec 100644
--- a/platform/marmotta-core/src/test/disabled/LMFBaseTest.java
+++ b/platform/marmotta-core/src/test/disabled/LMFBaseTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package kiwi.core.test.base;
+package org.apache.marmotta.platform.core.test.base;
import com.jayway.restassured.RestAssured;
import org.apache.commons.lang.RandomStringUtils;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/PrefixCCTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/PrefixCCTest.java b/platform/marmotta-core/src/test/disabled/PrefixCCTest.java
index dbba648..7375aa4 100644
--- a/platform/marmotta-core/src/test/disabled/PrefixCCTest.java
+++ b/platform/marmotta-core/src/test/disabled/PrefixCCTest.java
@@ -1,4 +1,4 @@
-package kiwi.core.services.prefix;
+package org.apache.marmotta.platform.core.services.prefix;
import org.junit.After;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/PrefixServiceCCTests.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/PrefixServiceCCTests.java b/platform/marmotta-core/src/test/disabled/PrefixServiceCCTests.java
index fd6fb8d..290d607 100644
--- a/platform/marmotta-core/src/test/disabled/PrefixServiceCCTests.java
+++ b/platform/marmotta-core/src/test/disabled/PrefixServiceCCTests.java
@@ -1,4 +1,4 @@
-package kiwi.core.services.prefix;
+package org.apache.marmotta.platform.core.services.prefix;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/PrefixServiceTests.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/PrefixServiceTests.java b/platform/marmotta-core/src/test/disabled/PrefixServiceTests.java
index d903cd2..788f258 100644
--- a/platform/marmotta-core/src/test/disabled/PrefixServiceTests.java
+++ b/platform/marmotta-core/src/test/disabled/PrefixServiceTests.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package kiwi.core.services.prefix;
+package org.apache.marmotta.platform.core.services.prefix;
-import kiwi.core.api.prefix.PrefixService;
+import org.apache.marmotta.platform.core.api.prefix.PrefixService;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/ResourceServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/ResourceServiceTest.java b/platform/marmotta-core/src/test/disabled/ResourceServiceTest.java
index 07bf86a..15d66fa 100644
--- a/platform/marmotta-core/src/test/disabled/ResourceServiceTest.java
+++ b/platform/marmotta-core/src/test/disabled/ResourceServiceTest.java
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package kiwi.core.test.resource;
+package org.apache.marmotta.platform.core.test.resource;
import com.google.code.tempusfugit.concurrency.ConcurrentRule;
import com.google.code.tempusfugit.concurrency.RepeatingRule;
import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
import com.google.code.tempusfugit.concurrency.annotations.Repeating;
import com.googlecode.jatl.Html;
-import kiwi.core.test.base.LMFBaseTest;
+import org.apache.marmotta.platform.core.test.base.LMFBaseTest;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Rule;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/disabled/SparqlServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/disabled/SparqlServiceTest.java b/platform/marmotta-core/src/test/disabled/SparqlServiceTest.java
index d2e236e..49a6062 100644
--- a/platform/marmotta-core/src/test/disabled/SparqlServiceTest.java
+++ b/platform/marmotta-core/src/test/disabled/SparqlServiceTest.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package kiwi.core.test.sparql;
+package org.apache.marmotta.platform.core.test.sparql;
import com.google.code.tempusfugit.concurrency.ConcurrentRule;
import com.google.code.tempusfugit.concurrency.RepeatingRule;
@@ -22,7 +22,7 @@ import com.google.code.tempusfugit.concurrency.annotations.Repeating;
import com.google.common.io.Resources;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.parsing.Parser;
-import kiwi.core.test.base.LMFBaseTest;
+import org.apache.marmotta.platform.core.test.base.LMFBaseTest;
import org.junit.Rule;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4d3eebdd/platform/marmotta-core/src/test/java/kiwi/core/test/base/AbstractLMF.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/kiwi/core/test/base/AbstractLMF.java b/platform/marmotta-core/src/test/java/kiwi/core/test/base/AbstractLMF.java
deleted file mode 100644
index 8f2bd24..0000000
--- a/platform/marmotta-core/src/test/java/kiwi/core/test/base/AbstractLMF.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package kiwi.core.test.base;
-
-import com.google.common.io.Files;
-import kiwi.core.jndi.LMFInitialContextFactoryBuilder;
-import kiwi.core.startup.LMFStartupService;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.commons.io.FileUtils;
-import org.jboss.weld.environment.se.Weld;
-import org.jboss.weld.environment.se.WeldContainer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.spi.NamingManager;
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert
- */
-public abstract class AbstractLMF {
-
- protected static Logger log = LoggerFactory.getLogger(EmbeddedLMF.class);
-
- protected Weld weld;
- protected WeldContainer container;
- protected LMFStartupService startupService;
- protected Configuration override;
-
- protected File lmfHome;
-
- protected AbstractLMF() {
- // initialise JNDI environment
- try {
- NamingManager.setInitialContextFactoryBuilder(new LMFInitialContextFactoryBuilder());
- } catch (NamingException e) {
-
- } catch (IllegalStateException e) {
- }
-
- // initialise CDI environment
- weld = new Weld();
- container = weld.initialize();
-
- cleanJNDI();
-
-
- // put bean manager into JNDI
- try {
- new InitialContext().bind("java:comp/BeanManager",container.getBeanManager());
- } catch (NamingException e) {
- log.error("error adding bean manager to JNDI",e);
- }
-
-
- // create temporary LMF home directory
- lmfHome = Files.createTempDir();
-
- // create a temporary configuration with an in-memory database URL for h2
- override = new MapConfiguration(new HashMap<String,Object>());
- override.setProperty("database.h2.url","jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10");
- override.setProperty("logging.template", "/logback-testing.xml");
-
- // initialise LMF using a temporary directory
- startupService = getService(LMFStartupService.class);
- }
-
-
- public <T> T getService(Class<T> serviceClass) {
- return container.instance().select(serviceClass).get();
- }
-
-
- public void shutdown() {
- // remove bean manager from JNDI
- cleanJNDI();
-
- startupService.shutdown();
- weld.shutdown();
-
- try {
- FileUtils.deleteDirectory(lmfHome);
- } catch (IOException e) {
- log.error("error while deleting temporary LMF home directory");
- }
- }
-
-
- private void cleanJNDI() {
- try {
- new InitialContext().unbind("java:comp/env/BeanManager");
- } catch (NamingException e) {
- }
- try {
- new InitialContext().unbind("java:comp/BeanManager");
- } catch (NamingException e) {
- }
- try {
- new InitialContext().unbind("java:app/BeanManager");
- } catch (NamingException e) {
- }
-
- }
-}