|
| 1 | +package cavendish.blazegraph.task; |
| 2 | + |
| 3 | +import java.util.Collection; |
| 4 | +import java.util.Collections; |
| 5 | +import java.util.Iterator; |
| 6 | + |
| 7 | +import org.openrdf.model.Statement; |
| 8 | +import org.openrdf.model.URI; |
| 9 | +import org.openrdf.model.impl.ContextStatementImpl; |
| 10 | +import org.openrdf.model.impl.URIImpl; |
| 11 | +import org.openrdf.rio.RDFHandler; |
| 12 | +import org.openrdf.rio.RDFHandlerException; |
| 13 | +import org.slf4j.Logger; |
| 14 | +import org.slf4j.LoggerFactory; |
| 15 | + |
| 16 | +import com.bigdata.rdf.task.AbstractApiTask; |
| 17 | + |
| 18 | +import cavendish.blazegraph.ldp.Vocabulary; |
| 19 | + |
| 20 | +public abstract class InsertResourceTask extends AbstractApiTask<Long> implements MutatingTask { |
| 21 | + private static final Logger LOG = LoggerFactory.getLogger(InsertResourceTask.class); |
| 22 | + protected final URI subject; |
| 23 | + protected final Iterator<Statement> statementIterator; |
| 24 | + /** |
| 25 | + * @param namespace |
| 26 | + * The namespace of the target KB instance. |
| 27 | + * @param timestamp |
| 28 | + * The timestamp of the view of that KB instance. |
| 29 | + * @param isGRSRequired |
| 30 | + * <code>true</code> iff the task requires a lock on the GRS |
| 31 | + * index. |
| 32 | + */ |
| 33 | + public InsertResourceTask(final String namespace, final boolean isGRSRequired, |
| 34 | + final URI subject) { |
| 35 | + this(namespace, isGRSRequired, subject, Collections.<Statement> emptyList()); |
| 36 | + } |
| 37 | + |
| 38 | + public InsertResourceTask(final String namespace, final boolean isGRSRequired, |
| 39 | + final URI subject, Collection<Statement> statements) { |
| 40 | + this(namespace, isGRSRequired, subject, statements.iterator()); |
| 41 | + } |
| 42 | + |
| 43 | + public InsertResourceTask(final String namespace, final boolean isGRSRequired, |
| 44 | + final URI subject, Iterator<Statement> statements) { |
| 45 | + super(namespace, -1, isGRSRequired); // setting a > 0 time makes view read-only |
| 46 | + this.subject = subject; |
| 47 | + this.statementIterator = statements; |
| 48 | + } |
| 49 | + |
| 50 | + public static void addTimeMap(URI subject, RDFHandler handler) throws RDFHandlerException { |
| 51 | + java.net.URI parsed = java.net.URI.create(subject.stringValue()); |
| 52 | + parsed = parsed.resolve("/timemaps" + parsed.getPath()); |
| 53 | + LOG.info("creating LDPCv/TimeMap at %s", parsed); |
| 54 | + URIImpl timemap = new URIImpl(parsed.toString()); |
| 55 | + handler.handleStatement(new ContextStatementImpl(subject, Vocabulary.IANA_TIMEMAP, timemap, Vocabulary.INTERNAL_CONTEXT)); |
| 56 | + handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_ORIGINAL, subject, Vocabulary.INTERNAL_CONTEXT)); |
| 57 | + handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.DIRECT_CONTAINER, Vocabulary.INTERNAL_CONTEXT)); |
| 58 | + handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.IANA_TYPE, Vocabulary.MEMENTO_TIMEMAP, Vocabulary.INTERNAL_CONTEXT)); |
| 59 | + handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.MEMBERSHIP_RESOURCE, subject, null)); |
| 60 | + handler.handleStatement(new ContextStatementImpl(timemap, Vocabulary.INSERTED_CONTENT_RELATION, timemap, null)); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public boolean isReadOnly() { |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments