Repository: marmotta Updated Branches: refs/heads/develop 7e5683c0d -> 8e0160f8d
MARMOTTA-514: Added support for LDP Sec. 4.2.4.3 (Non-normative note) - "HTTP PUT are allowed if server-managed properties have not changed" Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/8e0160f8 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/8e0160f8 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/8e0160f8 Branch: refs/heads/develop Commit: 8e0160f8dffcae7bb344712edaa5c0a4cbb9db1f Parents: 7e5683c Author: Jakob Frank <[email protected]> Authored: Thu Sep 25 18:11:15 2014 +0200 Committer: Jakob Frank <[email protected]> Committed: Thu Sep 25 18:11:37 2014 +0200 ---------------------------------------------------------------------- .../platform/ldp/services/LdpServiceImpl.java | 32 ++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/8e0160f8/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpServiceImpl.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpServiceImpl.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpServiceImpl.java index 3976f9c..283c548 100644 --- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpServiceImpl.java +++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/services/LdpServiceImpl.java @@ -433,14 +433,13 @@ public class LdpServiceImpl implements LdpService { } @Override - public String updateResource(RepositoryConnection connection, final URI resource, InputStream stream, final String type, final boolean overwrite) throws RepositoryException, IncompatibleResourceTypeException, RDFParseException, IOException, InvalidModificationException { + public String updateResource(final RepositoryConnection connection, final URI resource, InputStream stream, final String type, final boolean overwrite) throws RepositoryException, IncompatibleResourceTypeException, RDFParseException, IOException, InvalidModificationException { final ValueFactory valueFactory = connection.getValueFactory(); final Literal now = valueFactory.createLiteral(new Date()); - connection.remove(resource, DCTERMS.modified, null, ldpContext); - connection.add(resource, DCTERMS.modified, now, ldpContext); - final RDFFormat rdfFormat = Rio.getParserFormatForMIMEType(type); + // TODO: find a better way to ingest n-triples (text/plain) while still supporting regular text files + final RDFFormat rdfFormat = ("text/plain".equals(type) ? null : Rio.getParserFormatForMIMEType(type)); // Check submitted format vs. real resource type (RDF-S vs. Non-RDF) if (rdfFormat == null && isNonRdfSourceResource(connection, resource)) { log.debug("Updating <{}> as LDP-NR (binary) - {}", resource, type); @@ -449,6 +448,8 @@ public class LdpServiceImpl implements LdpService { connection.remove(resource, DCTERMS.format, null, ldpContext); connection.add(resource, DCTERMS.format, format, ldpContext); //nie:mimeType ? + connection.remove(resource, DCTERMS.modified, null, ldpContext); + connection.add(resource, DCTERMS.modified, now, ldpContext); final URI ldp_rs = getRdfSourceForNonRdfSource(connection, resource); if (ldp_rs != null) { @@ -473,9 +474,17 @@ public class LdpServiceImpl implements LdpService { filtered.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() { @Override public boolean add(RepositoryConnection conn, Resource subject, URI predicate, Value object, Resource... contexts) { - if (resource.equals(subject) && SERVER_MANAGED_PROPERTIES.contains(predicate)) { - deniedProperties.add(predicate); - return true; + try { + if (connection.hasStatement(subject, predicate, object, true, ldpContext)) { + // Ignore/Strip any triple that is already present in the mgnt-context (i.e. "unchanged" props). + return true; + } else if (resource.equals(subject) && SERVER_MANAGED_PROPERTIES.contains(predicate)) { + // We do NOT allow changing server-managed properties. + deniedProperties.add(predicate); + return true; + } + } catch (RepositoryException e) { + log.error("Error while filtering server managed properties: {}", e.getMessage()); } return false; } @@ -487,9 +496,14 @@ public class LdpServiceImpl implements LdpService { final URI prop = deniedProperties.iterator().next(); log.debug("Invalid property modification in update: <{}> is a server controlled property", prop); throw new InvalidModificationException(String.format("Must not update <%s> using PUT", prop)); + } else { + // This has to happen *AFTER* the post-body was added: + connection.remove(resource, DCTERMS.modified, null, ldpContext); + connection.add(resource, DCTERMS.modified, now, ldpContext); + + log.trace("LDP-RS <{}> updated", resource); + return resource.stringValue(); } - log.trace("LDP-RS <{}> updated", resource); - return resource.stringValue(); } else if (rdfFormat == null) { final String mimeType = getMimeType(connection, resource); log.debug("Incompatible replacement: Can't replace {} with {}", mimeType, type);
