added scritp for trash
This commit is contained in:
parent
41d2693925
commit
b27a314f9b
13
pom.xml
13
pom.xml
|
@ -7,6 +7,18 @@
|
|||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Storagehub Scripts</name>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
|
@ -24,7 +36,6 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-model</artifactId>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.gcube.common.storagehub.model.Path;
|
||||
import org.gcube.common.storagehub.model.Paths;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.TrashItem;
|
||||
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 CleanTrash implements AbstractScript{
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CleanTrash.class);
|
||||
|
||||
@Override
|
||||
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
try {
|
||||
Node node = session.getNode("/Home");
|
||||
|
||||
NodeIterator it = node.getNodes();
|
||||
|
||||
while (it.hasNext()) {
|
||||
Node home = it.nextNode();
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
Path workspacePath = Paths.append(Paths.getPath(home.getPath()),"Workspace");
|
||||
|
||||
if (!session.nodeExists(workspacePath.toPath())) continue;
|
||||
|
||||
|
||||
Node trashNode = session.getNode(Paths.append(workspacePath, "Trash").toPath());
|
||||
|
||||
List<Item> items = scriptUtil.getChildren(null, trashNode, null, true, TrashItem.class);
|
||||
|
||||
for (Item item: items) {
|
||||
TrashItem trashItem = (TrashItem) item;
|
||||
if (System.currentTimeMillis() - trashItem.getDeletedTime().getTimeInMillis() > 2629800000l ) {
|
||||
scriptUtil.removeNodes(session, Collections.singletonList(trashItem));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}catch (Exception e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter sw = new PrintWriter(writer, true);
|
||||
e.printStackTrace(sw);
|
||||
return writer.toString();
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
public class MongoToMinioPorting {
|
||||
|
||||
}
|
Loading…
Reference in New Issue