added WS info call
This commit is contained in:
parent
e36f4eb776
commit
afbaceffa9
|
@ -6,6 +6,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.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -34,16 +35,19 @@ import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
|||
import org.gcube.common.storagehub.model.items.ExternalLink;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||
import org.gcube.common.storagehub.model.items.GenericFileItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
import org.gcube.common.storagehub.model.storages.MetaInfo;
|
||||
import org.gcube.common.storagehub.model.types.ItemAction;
|
||||
import org.gcube.common.storagehub.model.types.NodeProperty;
|
||||
import org.gcube.common.storagehub.model.types.FolderInfoType;
|
||||
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationParameters;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.predicates.IncludeTypePredicate;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -79,7 +83,45 @@ public class Utils {
|
|||
return getItemList(parent, Excludes.ALL, null, showHidden, itemTypePredicate).size();
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static long countSubItems(Node parent) throws RepositoryException, BackendGenericError{
|
||||
long count = 0;
|
||||
List<Item> items = getItemList(parent, Excludes.ALL, null, true, null);
|
||||
for (Item item: items) {
|
||||
if (item instanceof FolderItem)
|
||||
count += Utils.countSubItems((Node)item.getRelatedNode());
|
||||
}
|
||||
count += items.size();
|
||||
return count;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static long getSubItemsSize(Node parent) throws RepositoryException, BackendGenericError{
|
||||
long size = 0;
|
||||
List<Item> items = getItemList(parent, Excludes.GET_ONLY_CONTENT, null, true, new IncludeTypePredicate(Arrays.asList(GenericFileItem.class, FolderItem.class)));
|
||||
for (Item item: items)
|
||||
if (item instanceof FolderItem)
|
||||
size += Utils.getSubItemsSize((Node)item.getRelatedNode());
|
||||
else if (item instanceof GenericFileItem gfi)
|
||||
size += gfi.getContent().getSize();
|
||||
return size;
|
||||
}
|
||||
|
||||
public static FolderInfoType getFolderInfo(Node parent) throws RepositoryException, BackendGenericError{
|
||||
FolderInfoType info = new FolderInfoType(0, 0);
|
||||
List<Item> items = getItemList(parent, Excludes.GET_ONLY_CONTENT, null, true, null);
|
||||
for (Item item: items)
|
||||
if (item instanceof FolderItem) {
|
||||
FolderInfoType fit = getFolderInfo((Node) item.getRelatedNode());
|
||||
info.setCount(info.getCount() + fit.getCount());
|
||||
info.setSize(info.getSize() + fit.getSize());
|
||||
} else if (item instanceof GenericFileItem gfi)
|
||||
info.setSize(info.getSize() + gfi.getContent().getSize());
|
||||
info.setCount(info.getCount() + items.size());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
public static void acquireLockWithWait(Session ses, String nodePath, boolean isDeep, String login, int maxTries) throws RepositoryException, ItemLockedException {
|
||||
|
||||
Lock lock = null;
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.gcube.common.storagehub.model.service.ItemWrapper;
|
|||
import org.gcube.common.storagehub.model.storages.MetaInfo;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
||||
import org.gcube.common.storagehub.model.types.FolderInfoType;
|
||||
import org.gcube.data.access.storagehub.AuthorizationChecker;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
|
@ -491,17 +492,73 @@ public class WorkspaceManager extends Impersonable {
|
|||
|
||||
@Path("count")
|
||||
@GET
|
||||
@Deprecated
|
||||
public String getTotalItemsCount() {
|
||||
InnerMethodName.set("getTotalItemsCount");
|
||||
return "1203";
|
||||
Session ses = null;
|
||||
try {
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
Node wsNode = ses.getNode(pathUtil.getWorkspacePath(currentUser).toPath());
|
||||
return Long.toString(Utils.countSubItems(wsNode));
|
||||
} catch (RepositoryException re) {
|
||||
log.error("error getting workspace total item count", re);
|
||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||
} catch (StorageHubException she) {
|
||||
log.error(she.getErrorMessage(), she);
|
||||
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
||||
} finally {
|
||||
if (ses != null)
|
||||
ses.logout();
|
||||
}
|
||||
|
||||
return "0";
|
||||
}
|
||||
|
||||
@Path("size")
|
||||
@GET
|
||||
@Deprecated
|
||||
public String getTotalVolume() {
|
||||
InnerMethodName.set("getTotalSize");
|
||||
return "120300000";
|
||||
|
||||
Session ses = null;
|
||||
try {
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
Node wsNode = ses.getNode(pathUtil.getWorkspacePath(currentUser).toPath());
|
||||
return Long.toString(Utils.getSubItemsSize(wsNode));
|
||||
} catch (RepositoryException re) {
|
||||
log.error("error getting workspace total size", re);
|
||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||
} catch (StorageHubException she) {
|
||||
log.error(she.getErrorMessage(), she);
|
||||
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
||||
} finally {
|
||||
if (ses != null)
|
||||
ses.logout();
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
@Path("info")
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public FolderInfoType getWorkspaceInfo() {
|
||||
InnerMethodName.set("getWorkspaceInfo");
|
||||
Session ses = null;
|
||||
try {
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
Node wsNode = ses.getNode(pathUtil.getWorkspacePath(currentUser).toPath());
|
||||
return Utils.getFolderInfo(wsNode);
|
||||
} catch (RepositoryException re) {
|
||||
log.error("error getting workspace total size", re);
|
||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||
} catch (StorageHubException she) {
|
||||
log.error(she.getErrorMessage(), she);
|
||||
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
||||
} finally {
|
||||
if (ses != null)
|
||||
ses.logout();
|
||||
}
|
||||
return new FolderInfoType(0, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue