diff --git a/pom.xml b/pom.xml
index a8ad4dc..b6195f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,7 @@
org.gcube.data.access
- storagehub-scripting-util
+ storagehub-script-utils
[1.0.0-SNAPSHOT,2.0.0)
provided
@@ -45,6 +45,7 @@
2.20.2
provided
+
\ No newline at end of file
diff --git a/src/main/java/GeneralScript.java b/src/main/java/GeneralScript.java
index a481cbb..4fcc6b5 100644
--- a/src/main/java/GeneralScript.java
+++ b/src/main/java/GeneralScript.java
@@ -1,3 +1,5 @@
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -21,28 +23,20 @@ public class GeneralScript implements AbstractScript{
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
StringBuilder stringBuilder = new StringBuilder();
try {
-
- //session.getNodeByIdentifier("6f4b7392-38fc-4c10-bc35-5bad9d21c5d6").remove();
- //session.save();
-
-
- /*
- Node node = session.getNode("/Home/andrea.rossi/InBox");
- NodeIterator it = node.getNodes();
- while (it.hasNext()) {
- Node child = it.nextNode();
- Node attachment = child.getNode("hl:attachments");
- visitChildren(stringBuilder, attachment, 1);
- }*/
+ try(OutputStream os = new ByteArrayOutputStream()){
+ session.exportDocumentView("/", os, true, false);
+ stringBuilder.append(os.toString());
+ }
}catch (Throwable e) {
log.error("error updating nodes",e);
StringWriter writer = new StringWriter();
PrintWriter sw = new PrintWriter(writer, true);
e.printStackTrace(sw);
return writer.toString();
- }
+ }
return stringBuilder.toString();
}
+
private void visitChildren(StringBuilder stringBuilder, Node node, int level) throws Exception{
stringBuilder.append("-").append(node.getPath()).append("\n");
diff --git a/src/main/java/UpdateNodeType.java b/src/main/java/UpdateNodeType.java
index bdf4cbc..d7cb2f0 100644
--- a/src/main/java/UpdateNodeType.java
+++ b/src/main/java/UpdateNodeType.java
@@ -4,6 +4,7 @@ import java.io.StringWriter;
import java.util.Arrays;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.commons.cnd.CndImporter;
@@ -33,6 +34,71 @@ public class UpdateNodeType implements AbstractScript{
+ "\n"+
"";
+
+ private static final String addPayloadBackendInFiles = "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "[nthl:payloadBackend] > nt:base \n" +
+ " - hl:storageName (String)\n" +
+ " + hl:parameters (nt:unstructured)\n" +
+ " = nt:unstructured\n" +
+ " autocreated\n"+
+ "\n"+
+ " [nthl:file] > nt:resource\n" +
+ " - hl:size (long)\n" +
+ " - hl:remotePath (String)\n" +
+ " - hl:storageId (String)\n"
+ + "- hl:storageName (String)\n"
+ + "+ hl:payloadBackend (nthl:payloadBackend)\n" +
+ " = nthl:payloadBackend\n"
+ + "";
+
+ private static final String addPayloadBackendInFolders = "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "[nthl:workspaceItem] > mix:referenceable, mix:title, mix:lastModified, nt:hierarchyNode, mix:lockable\n" +
+ " - hl:portalLogin (String)\n" +
+ " - hl:lastAction (String) mandatory\n" +
+ " - hl:oldRemotePath (String)\n" +
+ " - hl:storagePath (String)\n" +
+ " - hl:moved (Boolean)\n" +
+ " \n" +
+ " - hl:hidden (Boolean)\n" +
+ " = 'false'\n" +
+ " autocreated\n" +
+ " \n" +
+ " - hl:IsSystemFolder (Boolean)\n" +
+ " = 'false'\n" +
+ " autocreated\n" +
+ " \n" +
+ " - hl:isPublic (Boolean)\n" +
+ " = 'false'\n" +
+ " autocreated\n" +
+ " \n" +
+ " + hl:readers (nthl:readersSet)\n" +
+ " = nthl:readersSet\n" +
+ " autocreated\n" +
+ "\n" +
+ " + hl:accounting (nthl:accountingSet)\n" +
+ " = nthl:accountingSet\n" +
+ " autocreated\n" +
+ " \n" +
+ " + hl:metadata (nt:unstructured)\n" +
+ " = nt:unstructured\n" +
+ " autocreated\n" +
+ "\n" +
+ " + hl:owner(nthl:user)\n" +
+ " = nthl:user\n" +
+ " autocreated \n" +
+ "\n" +
+ " + hl:payloadBackend (nthl:payloadBackend)\n" +
+ " = nthl:payloadBackend\n" +
+ "\n" +
+ " + *"
+ + "";
+
private static final String addSharableToItemSent ="\n"
+ "\n"
+ "\n"
@@ -43,14 +109,7 @@ public class UpdateNodeType implements AbstractScript{
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
StringBuilder stringBuilder = new StringBuilder();
try {
-
- StringReader reader = new StringReader(addVersionToHomes);
-
- NodeType[] nodeTypes = CndImporter.registerNodeTypes(reader, session, true);
- if (nodeTypes.length>0)
- Arrays.asList(nodeTypes).forEach(n -> stringBuilder.append(n.getName()).append("\n"));
- else stringBuilder.append("node type not returned");
-
+ registerNodeType(stringBuilder, session);
}catch (Throwable e) {
log.error("error updating nodes",e);
StringWriter writer = new StringWriter();
@@ -61,5 +120,23 @@ public class UpdateNodeType implements AbstractScript{
return stringBuilder.toString();
}
+ private void retrieveNodeType(StringBuilder stringBuilder, JackrabbitSession session) throws Exception {
+ NodeTypeIterator nodeTypeIt = session.getWorkspace().getNodeTypeManager().getAllNodeTypes();
+
+ while(nodeTypeIt.hasNext()){
+ NodeType node = nodeTypeIt.nextNodeType();
+ stringBuilder.append(node.getName() + node.getDeclaredChildNodeDefinitions() );
+ }
+ }
+
+ private void registerNodeType(StringBuilder stringBuilder, JackrabbitSession session) throws Exception{
+ StringReader reader = new StringReader(addPayloadBackendInFolders);
+
+ NodeType[] nodeTypes = CndImporter.registerNodeTypes(reader, session, true);
+ if (nodeTypes.length>0)
+ Arrays.asList(nodeTypes).forEach(n -> stringBuilder.append(n.getName()).append("\n"));
+ else stringBuilder.append("node type not returned");
+ }
+
}