diff --git a/src/main/java/RetoreJackrabbitBackup.java b/src/main/java/RetoreJackrabbitBackup.java new file mode 100644 index 0000000..6b6a45c --- /dev/null +++ b/src/main/java/RetoreJackrabbitBackup.java @@ -0,0 +1,37 @@ +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URI; + +import org.apache.jackrabbit.api.JackrabbitSession; +import org.gcube.data.access.storagehub.scripting.AbstractScript; +import org.gcube.data.access.storagehub.scripting.ScriptParameter; +import org.gcube.data.access.storagehub.scripting.ScriptUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class RetoreJackrabbitBackup implements AbstractScript{ + + private static Logger log = LoggerFactory.getLogger(RetoreJackrabbitBackup.class); + + @Override + public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) { + + StringBuilder stringBuilder = new StringBuilder(); + + try { + try(InputStream is = new URI("https://data-dev.d4science.net/VoyH").toURL().openStream()){ + session.importXML("/", is, 1); + } + session.save(); + }catch (Throwable e) { + log.error("error getting jcr backup",e); + StringWriter writer = new StringWriter(); + PrintWriter sw = new PrintWriter(writer, true); + e.printStackTrace(sw); + return writer.toString(); + } + return stringBuilder.toString(); + } +} diff --git a/src/main/java/RetrieveRegisteredNodeTypes.java b/src/main/java/RetrieveRegisteredNodeTypes.java new file mode 100644 index 0000000..19915ce --- /dev/null +++ b/src/main/java/RetrieveRegisteredNodeTypes.java @@ -0,0 +1,36 @@ +import java.util.Arrays; +import java.util.stream.Collectors; + +import javax.jcr.nodetype.NodeType; +import javax.jcr.nodetype.NodeTypeIterator; +import javax.jcr.nodetype.PropertyDefinition; + +import org.apache.jackrabbit.api.JackrabbitSession; +import org.gcube.data.access.storagehub.scripting.AbstractScript; +import org.gcube.data.access.storagehub.scripting.ScriptParameter; +import org.gcube.data.access.storagehub.scripting.ScriptUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RetrieveRegisteredNodeTypes implements AbstractScript{ + + private static Logger log = LoggerFactory.getLogger(RetrieveRegisteredNodeTypes.class); + + @Override + public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) throws Exception { + StringBuilder sbuilder = new StringBuilder(); + NodeTypeIterator nodeTypeIt = session.getWorkspace().getNodeTypeManager().getAllNodeTypes(); + while(nodeTypeIt.hasNext()){ + NodeType node = nodeTypeIt.nextNodeType(); + sbuilder.append("\n").append(node.getName()).append(" > ").append(Arrays.asList(node.getDeclaredSupertypeNames()).stream().collect(Collectors.joining(" , "))); + log.info("Registered "+node.getName()); + for (PropertyDefinition def: node.getDeclaredPropertyDefinitions()){ + sbuilder.append("\n").append(" - ").append(def.getName()); + } + + + } + + return sbuilder.toString(); + } +}