Mongo porting modfiied
This commit is contained in:
parent
e02623c1fb
commit
5a4aa31298
|
@ -3,10 +3,10 @@ import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.jcr.Node;
|
import javax.jcr.Node;
|
||||||
|
import javax.jcr.NodeIterator;
|
||||||
import javax.jcr.Session;
|
import javax.jcr.Session;
|
||||||
import javax.jcr.lock.LockManager;
|
import javax.jcr.lock.LockManager;
|
||||||
import javax.jcr.version.Version;
|
import javax.jcr.version.Version;
|
||||||
|
@ -17,6 +17,9 @@ import javax.jcr.version.VersionManager;
|
||||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||||
import org.gcube.common.storagehub.model.Constants;
|
import org.gcube.common.storagehub.model.Constants;
|
||||||
import org.gcube.common.storagehub.model.NodeConstants;
|
import org.gcube.common.storagehub.model.NodeConstants;
|
||||||
|
import org.gcube.common.storagehub.model.Path;
|
||||||
|
import org.gcube.common.storagehub.model.Paths;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.StorageIdNotFoundException;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
@ -28,12 +31,10 @@ import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
||||||
import org.gcube.data.access.storagehub.scripting.AbstractScript;
|
import org.gcube.data.access.storagehub.scripting.AbstractScript;
|
||||||
import org.gcube.data.access.storagehub.scripting.ScriptParameter;
|
import org.gcube.data.access.storagehub.scripting.ScriptParameter;
|
||||||
import org.gcube.data.access.storagehub.scripting.ScriptUtil;
|
import org.gcube.data.access.storagehub.scripting.ScriptUtil;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class MongoToMinioPortingNotShared implements AbstractScript{
|
public class MongoToMinioPortingNotShared implements AbstractScript{
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(MongoToMinioPortingNotShared.class);
|
//private static Logger log = LoggerFactory.getLogger(MongoToMinioPortingNotShared.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
public String run(JackrabbitSession session, ScriptParameter prameters, ScriptUtil scriptUtil) {
|
||||||
|
@ -42,13 +43,13 @@ public class MongoToMinioPortingNotShared implements AbstractScript{
|
||||||
long startall = System.currentTimeMillis();
|
long startall = System.currentTimeMillis();
|
||||||
|
|
||||||
for (Node home: nodeToelaborate(session)) {
|
for (Node home: nodeToelaborate(session)) {
|
||||||
|
stringBuilder.append("\n").append("elaborated user home of ").append(home.getPath());
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
Item item = scriptUtil.getItem(home, null);
|
Item item = scriptUtil.getItem(home, null);
|
||||||
stringBuilder.append(elaborateItem(item, session, scriptUtil));
|
elaborateItem(item, session, scriptUtil, stringBuilder);
|
||||||
|
|
||||||
stringBuilder.append("\n").append("elaborated user home of ").append(home.getName()).append(" in ").append(System.currentTimeMillis()-start).append(" millis");
|
stringBuilder.append("\n").append("elaborated user home of ").append(home.getPath()).append(" in ").append(System.currentTimeMillis()-start).append(" millis");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,18 +64,17 @@ public class MongoToMinioPortingNotShared implements AbstractScript{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String elaborateItem(Item item, JackrabbitSession session, ScriptUtil scriptUtil ) {
|
private void elaborateItem(Item item, JackrabbitSession session, ScriptUtil scriptUtil, StringBuilder stringBuilder ) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
if (item instanceof FolderItem) {
|
if (item instanceof FolderItem) {
|
||||||
if (item.isShared()) {
|
if (item.isShared()) {
|
||||||
stringBuilder.append("\n").append("shared folder ").append(item.getId()).append(" skipped");
|
stringBuilder.append("\n").append("shared folder ").append(item.getId()).append(" skipped");
|
||||||
return stringBuilder.toString();
|
return;
|
||||||
}
|
}
|
||||||
FolderItem folder = (FolderItem) item;
|
FolderItem folder = (FolderItem) item;
|
||||||
try {
|
try {
|
||||||
List<Item> items = scriptUtil.getChildren(null, (Node) folder.getRelatedNode(), null, true, null);
|
List<Item> items = scriptUtil.getChildren(null, (Node) folder.getRelatedNode(), null, true, null);
|
||||||
stringBuilder.append("\n").append("elaborating folder ").append(folder.getId()).append(" - ").append(folder.getTitle());
|
stringBuilder.append("\n").append("elaborating folder ").append(folder.getId()).append(" - ").append(folder.getTitle());
|
||||||
items.stream().forEach(i -> stringBuilder.append(elaborateItem(i, session, scriptUtil)));
|
items.stream().forEach(i -> elaborateItem(i, session, scriptUtil, stringBuilder));
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
stringBuilder.append("\n").append("error on folder ").append(folder.getId()).append(" - ").append(folder.getTitle()).append(e.getMessage());
|
stringBuilder.append("\n").append("error on folder ").append(folder.getId()).append(" - ").append(folder.getTitle()).append(e.getMessage());
|
||||||
|
@ -104,8 +104,12 @@ public class MongoToMinioPortingNotShared implements AbstractScript{
|
||||||
String mongoId = file.getContent().getStorageId();
|
String mongoId = file.getContent().getStorageId();
|
||||||
stringBuilder.append("\n").append("searching for content id ").append(mongoId);
|
stringBuilder.append("\n").append("searching for content id ").append(mongoId);
|
||||||
MetaInfo info;
|
MetaInfo info;
|
||||||
try (InputStream is = mongo.download(mongoId)){
|
|
||||||
|
try (InputStream is = mongo.download(mongoId);){
|
||||||
info = minio.upload(is, file.getContent().getRemotePath() , item.getName(), mongoId, file.getContent().getSize() );
|
info = minio.upload(is, file.getContent().getRemotePath() , item.getName(), mongoId, file.getContent().getSize() );
|
||||||
|
}catch (StorageIdNotFoundException e) {
|
||||||
|
stringBuilder.append("\n").append("not found content id ").append(mongoId);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
Content content = ((AbstractFileItem) item).getContent();
|
Content content = ((AbstractFileItem) item).getContent();
|
||||||
|
|
||||||
|
@ -172,26 +176,35 @@ public class MongoToMinioPortingNotShared implements AbstractScript{
|
||||||
stringBuilder.append("\n").append("error TOTAL on file ").append(item.getTitle()).append(e.getMessage());
|
stringBuilder.append("\n").append("error TOTAL on file ").append(item.getTitle()).append(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Node> nodeToelaborate(JackrabbitSession session) throws Exception{
|
private List<Node> nodeToelaborate(JackrabbitSession session) throws Exception{
|
||||||
Node node = session.getNode("/Home/leonardo.candela/Workspace");
|
Node home = session.getNode("/Home");
|
||||||
|
|
||||||
//Path workspacePath = Paths.append(Paths.getPath(home.getPath()),"Workspace");
|
NodeIterator it = home.getNodes();
|
||||||
|
|
||||||
//if (!session.nodeExists(workspacePath.toPath())) continue;
|
List<Node> homes = new ArrayList<>();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
|
||||||
//NodeIterator it = node.getNodes();
|
Node userHome = it.nextNode();
|
||||||
return Collections.singletonList(node);
|
Path workspacePath = Paths.append(Paths.getPath(userHome.getPath()),"Workspace");
|
||||||
|
|
||||||
|
if (!session.nodeExists(workspacePath.toPath()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
homes.add(session.getNode(workspacePath.toPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkinContentNode(Node node) throws Exception{
|
return homes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* private void checkinContentNode(Node node) throws Exception{
|
||||||
Session session = node.getSession();
|
Session session = node.getSession();
|
||||||
VersionManager versionManager = session.getWorkspace().getVersionManager();
|
VersionManager versionManager = session.getWorkspace().getVersionManager();
|
||||||
versionManager.checkin(node.getPath());
|
versionManager.checkin(node.getPath());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void checkoutContentNode(Node node) throws Exception{
|
private void checkoutContentNode(Node node) throws Exception{
|
||||||
Session session = node.getSession();
|
Session session = node.getSession();
|
||||||
|
|
Loading…
Reference in New Issue