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.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
|
@ -24,6 +25,7 @@ import javax.jcr.RepositoryException;
|
|||
import javax.jcr.Session;
|
||||
import javax.jcr.lock.Lock;
|
||||
import javax.jcr.lock.LockException;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.query.Query;
|
||||
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.LoggerFactory;
|
||||
|
||||
import net.bull.javamelody.internal.common.LOG;
|
||||
|
||||
public class Utils {
|
||||
|
||||
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{
|
||||
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 -> {
|
||||
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());
|
||||
}else if (itemToDelete instanceof FolderItem) {
|
||||
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{
|
||||
log.debug("defnitively removing nodes with ids {}",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 {
|
||||
Set<String> contentIdsToDelete = new HashSet<>();
|
||||
|
@ -83,6 +90,7 @@ public class TrashHandler {
|
|||
} else {
|
||||
Utils.getAllContentIds(ses, contentIdsToDelete, itemToDelete, versionHandler);
|
||||
}
|
||||
if (!onlyContent)
|
||||
nodeToDelete.remove();
|
||||
|
||||
log.debug("content ids to remove are {}",contentIdsToDelete);
|
||||
|
@ -104,7 +112,7 @@ public class TrashHandler {
|
|||
}
|
||||
});
|
||||
executor.execute(deleteFromStorageRunnable);
|
||||
|
||||
if (!onlyContent)
|
||||
ses.save();
|
||||
}catch (LockException e) {
|
||||
throw new ItemLockedException("the selected node or his parent is locked", e);
|
||||
|
|
|
@ -254,11 +254,6 @@ public class UserManager {
|
|||
} catch (Throwable 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 workspacePath = Utils.getWorkspacePath(user);
|
||||
|
@ -267,11 +262,18 @@ public class UserManager {
|
|||
Node workspaceNode = session.getNode(workspacePath.toPath());
|
||||
Node homeNode = session.getNode(homePath.toPath());
|
||||
List<Item> workspaceItems = Utils.getItemList(workspaceNode, Excludes.GET_ONLY_CONTENT, null, true, null);
|
||||
trashHandler.removeNodes(session, workspaceItems);
|
||||
trashHandler.removeOnlyNodesContent(session, workspaceItems);
|
||||
homeNode.remove();
|
||||
} catch (PathNotFoundException e) {
|
||||
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();
|
||||
}catch(StorageHubException she ){
|
||||
log.error(she.getErrorMessage(), she);
|
||||
|
|
Loading…
Reference in New Issue