Author: justin
Date: Thu Jul 14 15:57:28 2011
New Revision: 1146769
URL: http://svn.apache.org/viewvc?rev=1146769&view=rev
Log:
SLING-1704 - adding support for changing primary node type in post servlet
Modified:
sling/trunk/bundles/servlets/post/pom.xml
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java
Modified: sling/trunk/bundles/servlets/post/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/pom.xml?rev=1146769&r1=1146768&r2=1146769&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/pom.xml (original)
+++ sling/trunk/bundles/servlets/post/pom.xml Thu Jul 14 15:57:28 2011
@@ -106,6 +106,7 @@
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
+ <version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified:
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java?rev=1146769&r1=1146768&r2=1146769&view=diff
==============================================================================
---
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java
(original)
+++
sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java
Thu Jul 14 15:57:28 2011
@@ -102,11 +102,35 @@ abstract class AbstractCreateOperation e
response.setCreateRequest(true);
} else {
-
+ updateNodeType(session, path, reqProperties, changes,
versioningConfiguration);
updateMixins(session, path, reqProperties, changes,
versioningConfiguration);
}
}
+ protected void updateNodeType(Session session, String path, Map<String,
RequestProperty> reqProperties,
+ List<Modification> changes, VersioningConfiguration
versioningConfiguration) throws PathNotFoundException,
+ RepositoryException, NoSuchNodeTypeException, VersionException,
ConstraintViolationException, LockException {
+ String nodeType = getPrimaryType(reqProperties, path);
+ if (nodeType != null) {
+ Item item = session.getItem(path);
+ if (item.isNode()) {
+ Node node = (Node) item;
+ boolean wasVersionable = isVersionable(node);
+
+ checkoutIfNecessary(node, changes, versioningConfiguration);
+ node.setPrimaryType(nodeType);
+
+ // this is a bit of a cheat; there isn't a formal checkout,
but assigning
+ // the mix:versionable mixin does an implicit checkout
+ if (!wasVersionable &&
+
versioningConfiguration.isCheckinOnNewVersionableNode() &&
+ isVersionable(node)) {
+ changes.add(Modification.onCheckout(path));
+ }
+ }
+ }
+ }
+
protected void updateMixins(Session session, String path, Map<String,
RequestProperty> reqProperties,
List<Modification> changes, VersioningConfiguration
versioningConfiguration) throws PathNotFoundException,
RepositoryException, NoSuchNodeTypeException, VersionException,
ConstraintViolationException, LockException {
@@ -426,6 +450,7 @@ abstract class AbstractCreateOperation e
startingNode = session.getRootNode();
} else if (session.itemExists(startingNodePath)) {
startingNode = (Node) session.getItem(startingNodePath);
+ updateNodeType(session, startingNodePath, reqProperties,
changes, versioningConfiguration);
updateMixins(session, startingNodePath, reqProperties,
changes, versioningConfiguration);
} else {
int pos = startingNodePath.lastIndexOf('/');
@@ -454,6 +479,7 @@ abstract class AbstractCreateOperation e
// we do a sanety check.
if (node.hasNode(name)) {
node = node.getNode(name);
+ updateNodeType(session, node.getPath(), reqProperties,
changes, versioningConfiguration);
updateMixins(session, node.getPath(), reqProperties, changes,
versioningConfiguration);
} else {
final String tmpPath = to < 0 ? path : path.substring(0, to);
Modified:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java?rev=1146769&r1=1146768&r2=1146769&view=diff
==============================================================================
---
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java
(original)
+++
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java
Thu Jul 14 15:57:28 2011
@@ -184,6 +184,29 @@ public void testPostPathIsUnique() throw
json = new JSONObject(content);
assertTrue("no jcr:mixinTypes expected after clearing it",
!json.has("jcr:mixinTypes"));
}
+
+ public void testUpdatingNodetype() throws IOException, JSONException {
+
+ // create a node without mixin node types
+ final Map <String, String> props = new HashMap <String, String> ();
+ props.put("jcr:primaryType","nt:unstructured");
+ final String location = testClient.createNode(postUrl +
SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
+
+ // assert correct nodetype
+ String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+ JSONObject json = new JSONObject(content);
+ assertTrue("jcr:primaryType isn't set correctly",
json.getString("jcr:primaryType").equals("nt:unstructured"));
+
+ // change nodetype
+ props.clear();
+ props.put("jcr:primaryType", "sling:Folder");
+ testClient.createNode(location, props);
+
+ // assert correct nodetype
+ content = getContent(location + ".json", CONTENT_TYPE_JSON);
+ json = new JSONObject(content);
+ assertTrue("jcr:primaryType isn't set correctly",
json.getString("jcr:primaryType").equals("sling:Folder"));
+ }
/**
* Test for SLING-897 fix: