scripts updated

This commit is contained in:
Lucio Lelii 2021-12-21 19:39:55 +01:00
parent 804a6c68f1
commit 41d2693925
3 changed files with 95 additions and 23 deletions

View File

@ -17,7 +17,7 @@
<dependencies>
<dependency>
<groupId>org.gcube.data.access</groupId>
<artifactId>storagehub-scripting-util</artifactId>
<artifactId>storagehub-script-utils</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0)</version>
<scope>provided</scope>
</dependency>
@ -45,6 +45,7 @@
<version>2.20.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -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");

View File

@ -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{
+ "<hl = 'http://ip-server:port/hl'>\n"+
"";
private static final String addPayloadBackendInFiles = "<mix = 'http://www.jcp.org/jcr/mix/1.0'>\n"
+ "<nt = 'http://www.jcp.org/jcr/nt/1.0'>\n"
+ "<nthl = 'http://ip-server:port/hl/nthl'>\n"
+ "<hl = 'http://ip-server:port/hl'>\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 = "<mix = 'http://www.jcp.org/jcr/mix/1.0'>\n"
+ "<nt = 'http://www.jcp.org/jcr/nt/1.0'>\n"
+ "<nthl = 'http://ip-server:port/hl/nthl'>\n"
+ "<hl = 'http://ip-server:port/hl'>\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 ="<mix = 'http://www.jcp.org/jcr/mix/1.0'>\n"
+ "<nt = 'http://www.jcp.org/jcr/nt/1.0'>\n"
+ "<nthl = 'http://ip-server:port/hl/nthl'>\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");
}
}