Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add /fedora:system for storing fcrepo configuration in the JCR tree, …
…and add a demo LDPath Program
  • Loading branch information
cbeer committed Jul 14, 2013
1 parent deac6ef commit 0d4efee
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

package org.fcrepo.ldpath.http;
package org.fcrepo.transform.http;

import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableList;
import com.hp.hpl.jena.query.Dataset;
import org.apache.marmotta.ldpath.exception.LDPathParseException;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.ldpath.LDPathService;
import org.fcrepo.transform.services.LDPathService;
import org.fcrepo.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.fcrepo.ldpath;
package org.fcrepo.transform.services;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
Expand All @@ -27,18 +27,58 @@
import org.apache.marmotta.ldpath.exception.LDPathParseException;
import org.apache.marmotta.ldpath.parser.Configuration;
import org.apache.marmotta.ldpath.parser.DefaultConfiguration;
import org.fcrepo.session.SessionFactory;
import org.fcrepo.utils.JcrRdfTools;
import org.modeshape.jcr.api.JcrTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.Map;

import static org.fcrepo.rdf.SerializationUtils.getDatasetSubject;
import static org.fcrepo.rdf.SerializationUtils.unifyDatasetModel;

@Component
public class LDPathService {

@Autowired
protected SessionFactory sessions;

/**
* A convenience object provided by ModeShape for acting against the JCR
* repository.
*/
protected static final JcrTools jcrTools = new JcrTools(true);

/**
* Register the LDPath configuration tree in JCR
* @throws RepositoryException
* @throws IOException
*/
@PostConstruct
public void initialize() throws RepositoryException, IOException {

final Session session = sessions.getSession();
jcrTools.registerNodeTypes(session, "ldpath.cnd");

jcrTools.findOrCreateNode(session, "/fedora:system/fedora:transform", "fedora:configuration", "fedora:node_type_configuration");
final javax.jcr.Node node = jcrTools.findOrCreateNode(session, "/fedora:system/fedora:transform/fedora:ldpath/default", NodeType.NT_FOLDER, NodeType.NT_FOLDER);

if (node.isNew()) {
final javax.jcr.Node base_config = node.addNode(NodeType.NT_BASE, NodeType.NT_FILE);
jcrTools.uploadFile(session, base_config.getPath(), getClass().getResourceAsStream("/ldpath/default/nt_base_ldpath_program.txt") );
}
session.save();
session.logout();
}

/**
* Execute an LDPath Program against a Dataset
* @param session
Expand Down
11 changes: 11 additions & 0 deletions fcrepo-transform/src/main/resources/ldpath.cnd
@@ -0,0 +1,11 @@
/*
* Generic Fedora namespace
*/
<fedora = 'info:fedora/'>

/*
* Any Fedora resource.
*/
[fedora:configuration] > nt:folder

[fedora:node_type_configuration] > nt:folder
@@ -0,0 +1,2 @@
id = . :: xsd:string ;
uuid = fedora-internal:uuid :: xsd:string;
Expand Up @@ -18,7 +18,7 @@

import org.apache.marmotta.ldpath.exception.LDPathParseException;
import org.fcrepo.FedoraObject;
import org.fcrepo.ldpath.LDPathService;
import org.fcrepo.transform.services.LDPathService;
import org.fcrepo.services.ObjectService;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
2 changes: 1 addition & 1 deletion fcrepo-transform/src/test/resources/spring-test/rest.xml
Expand Up @@ -15,7 +15,7 @@

<context:annotation-config/>

<context:component-scan base-package="org.fcrepo.services, org.fcrepo.session, org.fcrepo.api, org.fcrepo.ldpath.http, org.fcrepo.serialization, org.fcrepo.exceptionhandlers"/>
<context:component-scan base-package="org.fcrepo.services, org.fcrepo.session, org.fcrepo.api, org.fcrepo.transform.http, org.fcrepo.transform.services, org.fcrepo.serialization, org.fcrepo.exceptionhandlers"/>

<bean class="org.fcrepo.session.SessionFactory" />

Expand Down
3 changes: 2 additions & 1 deletion fcrepo-transform/src/test/resources/web.xml
Expand Up @@ -21,7 +21,8 @@
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.fcrepo.services, org.fcrepo.session, org.fcrepo.ldpath.http, org.fcrepo.exceptionhandlers</param-value>
<param-value>org.fcrepo.services, org.fcrepo.session, org.fcrepo.transform.http,
org.fcrepo.transform.services, org.fcrepo.exceptionhandlers</param-value>

</init-param>
<init-param>
Expand Down

0 comments on commit 0d4efee

Please sign in to comment.