removing old not versioned node
This commit is contained in:
parent
6b690caf56
commit
7591536a69
|
@ -7,6 +7,7 @@ import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -24,6 +25,7 @@ import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Session;
|
import javax.jcr.Session;
|
||||||
import javax.jcr.lock.Lock;
|
import javax.jcr.lock.Lock;
|
||||||
import javax.jcr.lock.LockException;
|
import javax.jcr.lock.LockException;
|
||||||
|
import javax.jcr.nodetype.NodeType;
|
||||||
import javax.jcr.query.Query;
|
import javax.jcr.query.Query;
|
||||||
import javax.jcr.version.Version;
|
import javax.jcr.version.Version;
|
||||||
|
|
||||||
|
@ -57,6 +59,8 @@ import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import net.bull.javamelody.internal.common.LOG;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public final static String SERVICE_NAME = "home-library";
|
public final static String SERVICE_NAME = "home-library";
|
||||||
|
@ -299,7 +303,18 @@ public class Utils {
|
||||||
|
|
||||||
public static void getAllContentIds(Session ses, Set<String> idsToDelete, Item itemToDelete, VersionHandler versionHandler) throws Exception{
|
public static void getAllContentIds(Session ses, Set<String> idsToDelete, Item itemToDelete, VersionHandler versionHandler) throws Exception{
|
||||||
if (itemToDelete instanceof AbstractFileItem) {
|
if (itemToDelete instanceof AbstractFileItem) {
|
||||||
List<Version> versions = versionHandler.getContentVersionHistory(ses.getNodeByIdentifier(itemToDelete.getId()), ses);
|
Node currentNode = ses.getNodeByIdentifier(itemToDelete.getId());
|
||||||
|
List<NodeType> ntList = Arrays.asList(currentNode.getMixinNodeTypes());
|
||||||
|
boolean isVersioned = false;
|
||||||
|
logger.debug("mixin node type are {}",ntList);
|
||||||
|
for (NodeType nt: ntList)
|
||||||
|
if(nt.getName().equals("mix:versionable")) {
|
||||||
|
isVersioned = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isVersioned) {
|
||||||
|
List<Version> versions = versionHandler.getContentVersionHistory(currentNode, ses);
|
||||||
|
|
||||||
versions.forEach(v -> {
|
versions.forEach(v -> {
|
||||||
try {
|
try {
|
||||||
|
@ -311,6 +326,9 @@ public class Utils {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else
|
||||||
|
logger.info("not versionable node type found of type {}", currentNode.getPrimaryNodeType().toString());
|
||||||
|
|
||||||
idsToDelete.add(((AbstractFileItem) itemToDelete).getContent().getStorageId());
|
idsToDelete.add(((AbstractFileItem) itemToDelete).getContent().getStorageId());
|
||||||
}else if (itemToDelete instanceof FolderItem) {
|
}else if (itemToDelete instanceof FolderItem) {
|
||||||
List<Item> items = Utils.getItemList(ses.getNodeByIdentifier(itemToDelete.getId()), Excludes.GET_ONLY_CONTENT , null, true, null);
|
List<Item> items = Utils.getItemList(ses.getNodeByIdentifier(itemToDelete.getId()), Excludes.GET_ONLY_CONTENT , null, true, null);
|
||||||
|
|
|
@ -65,11 +65,18 @@ public class TrashHandler {
|
||||||
public void removeNodes(Session ses, List<Item> itemsToDelete) throws RepositoryException, StorageHubException{
|
public void removeNodes(Session ses, List<Item> itemsToDelete) throws RepositoryException, StorageHubException{
|
||||||
log.debug("defnitively removing nodes with ids {}",itemsToDelete);
|
log.debug("defnitively removing nodes with ids {}",itemsToDelete);
|
||||||
for (Item item: itemsToDelete) {
|
for (Item item: itemsToDelete) {
|
||||||
removeNodesInternally(ses, item);
|
removeNodesInternally(ses, item, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeNodesInternally(Session ses, Item itemToDelete) throws RepositoryException, StorageHubException {
|
public void removeOnlyNodesContent(Session ses, List<Item> itemsToDelete) throws RepositoryException, StorageHubException{
|
||||||
|
log.debug("defnitively removing nodes with ids {}",itemsToDelete);
|
||||||
|
for (Item item: itemsToDelete) {
|
||||||
|
removeNodesInternally(ses, item, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeNodesInternally(Session ses, Item itemToDelete, boolean onlyContent) throws RepositoryException, StorageHubException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Set<String> contentIdsToDelete = new HashSet<>();
|
Set<String> contentIdsToDelete = new HashSet<>();
|
||||||
|
@ -83,6 +90,7 @@ public class TrashHandler {
|
||||||
} else {
|
} else {
|
||||||
Utils.getAllContentIds(ses, contentIdsToDelete, itemToDelete, versionHandler);
|
Utils.getAllContentIds(ses, contentIdsToDelete, itemToDelete, versionHandler);
|
||||||
}
|
}
|
||||||
|
if (!onlyContent)
|
||||||
nodeToDelete.remove();
|
nodeToDelete.remove();
|
||||||
|
|
||||||
log.debug("content ids to remove are {}",contentIdsToDelete);
|
log.debug("content ids to remove are {}",contentIdsToDelete);
|
||||||
|
@ -104,7 +112,7 @@ public class TrashHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
executor.execute(deleteFromStorageRunnable);
|
executor.execute(deleteFromStorageRunnable);
|
||||||
|
if (!onlyContent)
|
||||||
ses.save();
|
ses.save();
|
||||||
}catch (LockException e) {
|
}catch (LockException e) {
|
||||||
throw new ItemLockedException("the selected node or his parent is locked", e);
|
throw new ItemLockedException("the selected node or his parent is locked", e);
|
||||||
|
|
|
@ -254,11 +254,6 @@ public class UserManager {
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.warn("error getting folder shared with ", t);
|
log.warn("error getting folder shared with ", t);
|
||||||
}
|
}
|
||||||
Authorizable authorizable = usrManager.getAuthorizable(new PrincipalImpl(user));
|
|
||||||
if (authorizable!=null && !authorizable.isGroup()) {
|
|
||||||
log.info("removing user {}", user);
|
|
||||||
authorizable.remove();
|
|
||||||
} else log.warn("the user {} was already deleted", user);
|
|
||||||
|
|
||||||
org.gcube.common.storagehub.model.Path homePath = Utils.getHome(user);
|
org.gcube.common.storagehub.model.Path homePath = Utils.getHome(user);
|
||||||
org.gcube.common.storagehub.model.Path workspacePath = Utils.getWorkspacePath(user);
|
org.gcube.common.storagehub.model.Path workspacePath = Utils.getWorkspacePath(user);
|
||||||
|
@ -267,11 +262,18 @@ public class UserManager {
|
||||||
Node workspaceNode = session.getNode(workspacePath.toPath());
|
Node workspaceNode = session.getNode(workspacePath.toPath());
|
||||||
Node homeNode = session.getNode(homePath.toPath());
|
Node homeNode = session.getNode(homePath.toPath());
|
||||||
List<Item> workspaceItems = Utils.getItemList(workspaceNode, Excludes.GET_ONLY_CONTENT, null, true, null);
|
List<Item> workspaceItems = Utils.getItemList(workspaceNode, Excludes.GET_ONLY_CONTENT, null, true, null);
|
||||||
trashHandler.removeNodes(session, workspaceItems);
|
trashHandler.removeOnlyNodesContent(session, workspaceItems);
|
||||||
homeNode.remove();
|
homeNode.remove();
|
||||||
} catch (PathNotFoundException e) {
|
} catch (PathNotFoundException e) {
|
||||||
log.warn("{} home dir was already deleted", user);
|
log.warn("{} home dir was already deleted", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Authorizable authorizable = usrManager.getAuthorizable(new PrincipalImpl(user));
|
||||||
|
if (authorizable!=null && !authorizable.isGroup()) {
|
||||||
|
log.info("removing user {}", user);
|
||||||
|
authorizable.remove();
|
||||||
|
} else log.warn("the user {} was already deleted", user);
|
||||||
|
|
||||||
session.save();
|
session.save();
|
||||||
}catch(StorageHubException she ){
|
}catch(StorageHubException she ){
|
||||||
log.error(she.getErrorMessage(), she);
|
log.error(she.getErrorMessage(), she);
|
||||||
|
|
Loading…
Reference in New Issue