scripts updated
This commit is contained in:
parent
804a6c68f1
commit
41d2693925
3
pom.xml
3
pom.xml
|
@ -17,7 +17,7 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.access</groupId>
|
<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>
|
<version>[1.0.0-SNAPSHOT,2.0.0)</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -45,6 +45,7 @@
|
||||||
<version>2.20.2</version>
|
<version>2.20.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,3 +1,5 @@
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
@ -21,19 +23,10 @@ public class GeneralScript implements AbstractScript{
|
||||||
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
|
try(OutputStream os = new ByteArrayOutputStream()){
|
||||||
//session.getNodeByIdentifier("6f4b7392-38fc-4c10-bc35-5bad9d21c5d6").remove();
|
session.exportDocumentView("/", os, true, false);
|
||||||
//session.save();
|
stringBuilder.append(os.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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);
|
|
||||||
}*/
|
|
||||||
}catch (Throwable e) {
|
}catch (Throwable e) {
|
||||||
log.error("error updating nodes",e);
|
log.error("error updating nodes",e);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
|
@ -44,6 +37,7 @@ public class GeneralScript implements AbstractScript{
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void visitChildren(StringBuilder stringBuilder, Node node, int level) throws Exception{
|
private void visitChildren(StringBuilder stringBuilder, Node node, int level) throws Exception{
|
||||||
stringBuilder.append("-").append(node.getPath()).append("\n");
|
stringBuilder.append("-").append(node.getPath()).append("\n");
|
||||||
PropertyIterator props = node.getProperties();
|
PropertyIterator props = node.getProperties();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.StringWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.jcr.nodetype.NodeType;
|
import javax.jcr.nodetype.NodeType;
|
||||||
|
import javax.jcr.nodetype.NodeTypeIterator;
|
||||||
|
|
||||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||||
import org.apache.jackrabbit.commons.cnd.CndImporter;
|
import org.apache.jackrabbit.commons.cnd.CndImporter;
|
||||||
|
@ -33,6 +34,71 @@ public class UpdateNodeType implements AbstractScript{
|
||||||
+ "<hl = 'http://ip-server:port/hl'>\n"+
|
+ "<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"
|
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"
|
+ "<nt = 'http://www.jcp.org/jcr/nt/1.0'>\n"
|
||||||
+ "<nthl = 'http://ip-server:port/hl/nthl'>\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) {
|
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
|
registerNodeType(stringBuilder, session);
|
||||||
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");
|
|
||||||
|
|
||||||
}catch (Throwable e) {
|
}catch (Throwable e) {
|
||||||
log.error("error updating nodes",e);
|
log.error("error updating nodes",e);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
|
@ -61,5 +120,23 @@ public class UpdateNodeType implements AbstractScript{
|
||||||
return stringBuilder.toString();
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue