You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:48:05 UTC
[sling-org-apache-sling-jcr-contentloader] 25/28: SLING-1627 import
operation support for overwrite of properties
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit fda07c0691badf1cf52b974fb049da46ecc2ab8f
Author: Eric Norman <en...@apache.org>
AuthorDate: Fri Aug 6 22:23:05 2010 +0000
SLING-1627 import operation support for overwrite of properties
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentloader@983135 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 ++
.../sling/jcr/contentloader/ImportOptions.java | 24 ++++++
.../internal/DefaultContentCreator.java | 8 +-
.../jcr/contentloader/internal/PathEntry.java | 27 +++++-
.../internal/DefaultContentCreatorTest.java | 97 ++++++++++++++++++++++
5 files changed, 158 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 05718ef..eb2c58f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,6 +161,12 @@
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-nop</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
<!-- for security content loader (users/groups/acls) -->
<dependency>
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java b/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
index fa3d53c..b380f8b 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/ImportOptions.java
@@ -24,10 +24,34 @@ package org.apache.sling.jcr.contentloader;
*/
public abstract class ImportOptions {
+ /**
+ * Specifies whether imported nodes should overwrite existing nodes.
+ * NOTE: this means the existing node will be deleted and a new node
+ * will be created in the same location.
+ * @return true to overwrite nodes, false otherwise
+ */
public abstract boolean isOverwrite();
+ /**
+ * Specifies whether imported properties should overwrite existing properties.
+ * @return true to overwrite node properties, false otherwise
+ */
+ public abstract boolean isPropertyOverwrite();
+
+ /**
+ * Specifies whether versionable nodes is automatically checked in at the
+ * end of the import operation.
+ * @return true to checkin the versionable nodes, false otherwise
+ */
public abstract boolean isCheckin();
+ /**
+ * Check if the import provider for the given file extension should
+ * be ignored.
+ *
+ * @param extension the extension to check
+ * @return true to ignore the provider, false otherwise
+ */
public abstract boolean isIgnoredImportProvider(String extension);
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
index 97bf1b9..a67b72f 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
@@ -307,9 +307,10 @@ public class DefaultContentCreator implements ContentCreator {
public void createProperty(String name, int propertyType, String value)
throws RepositoryException {
final Node node = this.parentNodeStack.peek();
- // check if the property already exists, don't overwrite it in this case
+ // check if the property already exists and isPropertyOverwrite() is false, don't overwrite it in this case
if (node.hasProperty(name)
- && !node.getProperty(name).isNew()) {
+ && !this.configuration.isPropertyOverwrite()
+ && !node.getProperty(name).isNew()) {
return;
}
@@ -364,8 +365,9 @@ public class DefaultContentCreator implements ContentCreator {
public void createProperty(String name, int propertyType, String[] values)
throws RepositoryException {
final Node node = this.parentNodeStack.peek();
- // check if the property already exists, don't overwrite it in this case
+ // check if the property already exists and isPropertyOverwrite() is false, don't overwrite it in this case
if (node.hasProperty(name)
+ && !this.configuration.isPropertyOverwrite()
&& !node.getProperty(name).isNew()) {
return;
}
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
index aa003c4..75989a3 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
@@ -41,6 +41,12 @@ public class PathEntry extends ImportOptions {
*/
public static final String OVERWRITE_DIRECTIVE = "overwrite";
+ /**
+ * The overwriteProperties directive specifying if content properties
+ * should be overwritten or just initially added.
+ */
+ public static final String OVERWRITE_PROPERTIES_DIRECTIVE = "overwriteProperties";
+
/** The uninstall directive specifying if content should be uninstalled. */
public static final String UNINSTALL_DIRECTIVE = "uninstall";
@@ -75,6 +81,9 @@ public class PathEntry extends ImportOptions {
/** Should existing content be overwritten? */
private final boolean overwrite;
+ /** Should existing content properties be overwritten? */
+ private final boolean overwriteProperties;
+
/** Should existing content be uninstalled? */
private final boolean uninstall;
@@ -123,6 +132,14 @@ public class PathEntry extends ImportOptions {
this.overwrite = false;
}
+ // overwriteProperties directive
+ final String overwritePropertiesValue = entry.getDirectiveValue(OVERWRITE_PROPERTIES_DIRECTIVE);
+ if (overwritePropertiesValue != null) {
+ this.overwriteProperties = Boolean.valueOf(overwritePropertiesValue);
+ } else {
+ this.overwriteProperties = false;
+ }
+
// uninstall directive
final String uninstallValue = entry.getDirectiveValue(UNINSTALL_DIRECTIVE);
if (uninstallValue != null) {
@@ -177,7 +194,15 @@ public class PathEntry extends ImportOptions {
return this.overwrite;
}
- public boolean isUninstall() {
+ /* (non-Javadoc)
+ * @see org.apache.sling.jcr.contentloader.ImportOptions#isPropertyOverwrite()
+ */
+ @Override
+ public boolean isPropertyOverwrite() {
+ return this.overwriteProperties;
+ }
+
+ public boolean isUninstall() {
return this.uninstall;
}
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
new file mode 100644
index 0000000..c195396
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
@@ -0,0 +1,97 @@
+package org.apache.sling.jcr.contentloader.internal;
+
+import java.util.HashMap;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.contentloader.ImportOptions;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class DefaultContentCreatorTest {
+
+ DefaultContentCreator contentCreator;
+
+ Mockery mockery = new JUnit4Mockery();
+
+ Node parentNode;
+
+ Property prop;
+
+ @org.junit.Test public void willRewriteUndefinedPropertyType() throws RepositoryException {
+ contentCreator = new DefaultContentCreator(null);
+ parentNode = mockery.mock(Node.class);
+ prop = mockery.mock(Property.class);
+ contentCreator.init(new ImportOptions(){
+
+ @Override
+ public boolean isCheckin() {
+ return false;
+ }
+
+ @Override
+ public boolean isIgnoredImportProvider(String extension) {
+ return false;
+ }
+
+ @Override
+ public boolean isOverwrite() {
+ return true;
+ }
+
+ @Override
+ public boolean isPropertyOverwrite() {
+ return true;
+ } }, new HashMap<String, ImportProvider>(), null, null);
+
+ contentCreator.prepareParsing(parentNode, null);
+ this.mockery.checking(new Expectations() {{
+ oneOf (parentNode).hasProperty("foo"); will(returnValue(Boolean.TRUE));
+ oneOf (parentNode).setProperty(with(equal("foo")), with(equal("bar")));
+ }});
+ contentCreator.createProperty("foo", PropertyType.UNDEFINED, "bar");
+ }
+
+ @org.junit.Test public void willNotRewriteUndefinedPropertyType() throws RepositoryException {
+ contentCreator = new DefaultContentCreator(null);
+ parentNode = mockery.mock(Node.class);
+ prop = mockery.mock(Property.class);
+ contentCreator.init(new ImportOptions(){
+
+ @Override
+ public boolean isCheckin() {
+ return false;
+ }
+
+ @Override
+ public boolean isIgnoredImportProvider(String extension) {
+ return false;
+ }
+
+ @Override
+ public boolean isOverwrite() {
+ return false;
+ }
+
+ @Override
+ public boolean isPropertyOverwrite() {
+ return false;
+ } }, new HashMap<String, ImportProvider>(), null, null);
+
+ contentCreator.prepareParsing(parentNode, null);
+ this.mockery.checking(new Expectations() {{
+ oneOf (parentNode).hasProperty("foo"); will(returnValue(Boolean.TRUE));
+ oneOf (parentNode).getProperty("foo"); will(returnValue(prop));
+ oneOf (prop).isNew(); will(returnValue(Boolean.FALSE));
+ }});
+ contentCreator.createProperty("foo", PropertyType.UNDEFINED, "bar");
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.