- using groupHandler method to retrieve VRE

- added logs to ScriptManager error
This commit is contained in:
lucio.lelii 2021-10-06 10:37:14 +02:00
parent 68eb65e168
commit f30029c052
4 changed files with 26 additions and 38 deletions

View File

@ -2,6 +2,7 @@ package org.gcube.data.access.storagehub.handlers;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
@ -39,7 +40,7 @@ public class GroupHandler {
//delete folder on user
String folderName = group.getPrincipal().getName();
Node folder = getVreFolderNode(session, folderName);
Node folder = getFolderNodeRelatedToGroup(session, folderName);
NodeIterator ni = folder.getSharedSet();
while (ni.hasNext()) {
@ -54,7 +55,7 @@ public class GroupHandler {
}
public Node getVreFolderNode(JackrabbitSession session, String name) throws InvalidItemException, RepositoryException {
public Node getFolderNodeRelatedToGroup(JackrabbitSession session, String name) throws ItemNotFoundException, RepositoryException {
Node sharedRootNode = session.getNode(Constants.SHARED_FOLDER_PATH);
Node vreFolder = null;
@ -64,6 +65,7 @@ public class GroupHandler {
log.debug("is an old HL VRE");
}
if (vreFolder==null) {
NodeIterator nodes = sharedRootNode.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
@ -72,8 +74,9 @@ public class GroupHandler {
break;
}
}
}
if (vreFolder==null) throw new InvalidItemException("vre folder not found");
if (vreFolder==null) throw new ItemNotFoundException("vre folder not found for group "+name);
return vreFolder;
}

View File

@ -12,9 +12,7 @@ import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.query.Query;
import javax.servlet.ServletContext;
import org.apache.jackrabbit.api.JackrabbitSession;
@ -30,6 +28,7 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.data.access.storagehub.Constants;
import org.gcube.data.access.storagehub.PathUtil;
import org.gcube.data.access.storagehub.handlers.GroupHandler;
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
import org.slf4j.Logger;
@ -51,6 +50,9 @@ public class VREManager {
@Inject
PathUtil pathUtil;
@Inject
GroupHandler groupHandler;
ExecutorService executor = Executors.newFixedThreadPool(5);
SimpleCredentials credentials;
@ -98,26 +100,11 @@ public class VREManager {
throw new InvalidCallParameters("error getting VRE with user "+userId+" for group "+groupName);
org.gcube.common.storagehub.model.Path vrePath = pathUtil.getVREsPath(userId, ses);
VRE vre = this.getVRE(groupName);
if (vre!=null) return vre;
else {
Node shareNode = ses.getNode(Constants.SHARED_FOLDER_PATH);
NodeIterator it = shareNode.getNodes();
Node vreFolderNode = null;
while (it.hasNext()) {
Node nextNode = it.nextNode();
if (nextNode.hasProperty("jcr:title") && nextNode.getProperty("jcr:title").getString().equals(groupName)) {
vreFolderNode = nextNode;
break;
}
}
if (vreFolderNode==null) throw new ItemNotFoundException("vre folder not found for context "+groupName);
Node vreFolderNode = groupHandler.getFolderNodeRelatedToGroup(ses, groupName);
Item vreFolder = node2Item.getItem(vreFolderNode, excludes);
return this.putVRE(vreFolder);

View File

@ -9,7 +9,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@ -40,7 +39,6 @@ import org.apache.jackrabbit.api.security.user.QueryBuilder;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
import org.gcube.common.scope.api.ScopeProvider;
@ -200,11 +198,11 @@ public class GroupManager {
org.apache.jackrabbit.api.security.user.UserManager usrManager = session.getUserManager();
Authorizable authorizable = usrManager.getAuthorizable(group);
if (authorizable.isGroup())
if (authorizable!=null && authorizable.isGroup())
authorizable.remove();
try {
Node node = groupHandler.getVreFolderNode(session, group);
Node node = groupHandler.getFolderNodeRelatedToGroup(session, group);
List<Item> workspaceItems = Utils.getItemList(node, Excludes.GET_ONLY_CONTENT, null, true, null);
trashHandler.removeOnlyNodesContent(session, workspaceItems);
node.removeSharedSet();
@ -242,7 +240,7 @@ public class GroupManager {
session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
Node vreFolder = groupHandler.getVreFolderNode(session, groupId);
Node vreFolder = groupHandler.getFolderNodeRelatedToGroup(session, groupId);
String currentUser = AuthorizationProvider.instance.get().getClient().getId();
if (!isInfraManager() && !(isVREManager() && isValidGroupForContext(groupId) ))
@ -296,7 +294,7 @@ public class GroupManager {
Objects.nonNull(userId);
session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
Node vreFolder = groupHandler.getVreFolderNode(session, groupId);
Node vreFolder = groupHandler.getFolderNodeRelatedToGroup(session, groupId);
String currentUser = AuthorizationProvider.instance.get().getClient().getId();
if (!isInfraManager() && !(isVREManager() && isValidGroupForContext(groupId) ))
@ -422,7 +420,7 @@ public class GroupManager {
boolean success = group.addMember(user);
session.save();
String folderName = group.getPrincipal().getName();
Node folder = groupHandler.getVreFolderNode(session, folderName);
Node folder = groupHandler.getFolderNodeRelatedToGroup(session, folderName);
String userPath = Paths.append(pathUtil.getVREsPath(user.getPrincipal().getName(), session), folderName).toPath();
log.debug("creating folder in user path {} from {}", userPath, folder.getPath() );

View File

@ -168,7 +168,7 @@ public class ScriptManager {
.stream(stream).on(parentId).with(ses).author(login);
itemHandler.create(builder.build());
} catch (Throwable e) {
log.error("error saving script result {} in the Workspace",name);
log.error("error saving script result {} in the Workspace",name, e);
}
} finally {