get size method now returns 0 for folder and not null

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@169514 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-06-28 08:33:54 +00:00
parent 7b9708d2e2
commit a8722fb26a
1 changed files with 28 additions and 41 deletions

View File

@ -327,19 +327,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
@Override
public Long getSizeByItemId(String itemId) throws Exception {
_log.debug("get Size By ItemId "+ itemId);
try {
Item wsItem = StorageHubServiceUtil.getItem(getThreadLocalRequest(), itemId);
_log.trace("workspace retrieve item name: "+wsItem.getName());
if((wsItem instanceof FolderItem)) //if is a folder no mime
return null;
Item wsItem = StorageHubServiceUtil.getItem(getThreadLocalRequest(), itemId);
_log.trace("workspace retrieved item name: "+wsItem.getName());
if((wsItem instanceof FolderItem)) //if is a folder no Size
return 0L;
AbstractFileItem file = (AbstractFileItem) wsItem;
return file.getContent().getSize();
} catch (Exception e) {
_log.error("get MimeType By ItemId ", e);
throw new Exception(e.getMessage());
}
AbstractFileItem file = (AbstractFileItem) wsItem;
return file.getContent().getSize();
}
/* (non-Javadoc)
@ -355,19 +349,12 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
@Override
public String getMimeType(String itemId) throws Exception {
_log.debug("get MimeType By ItemId "+ itemId);
try {
Item wsItem = StorageHubServiceUtil.getItem(getThreadLocalRequest(), itemId);
_log.trace("workspace retrieve item name: "+wsItem.getName());
if((wsItem instanceof FolderItem)) //if is a folder no mime
return null;
AbstractFileItem file = (AbstractFileItem) wsItem;
return file.getContent().getMimeType();
} catch (Exception e) {
_log.error("get MimeType By ItemId ", e);
throw new Exception(e.getMessage());
}
Item wsItem = StorageHubServiceUtil.getItem(getThreadLocalRequest(), itemId);
_log.trace("workspace retrieved item name: "+wsItem.getName());
if((wsItem instanceof FolderItem)) //if is a folder no mime
return null;
AbstractFileItem file = (AbstractFileItem) wsItem;
return file.getContent().getMimeType();
}
@ -434,14 +421,14 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
_log.info("Path returned by StoHub: "+createdFolder.getPath());
List<ItemType> allTypes = Arrays.asList(ItemType.values());
return ItemBuilder.getItem(null, createdFolder, createdFolder.getPath(), allTypes, null, false, false);
// } catch(InsufficientPrivilegesException e){
// String error = "Insufficient Privileges to create the folder";
// _log.error(error, e);
// throw new Exception(error);
// } catch (ItemAlreadyExistException e) {
// String error = "An error occurred on creating folder, " +e.getMessage();
// _log.error(error, e);
// throw new Exception(error);
// } catch(InsufficientPrivilegesException e){
// String error = "Insufficient Privileges to create the folder";
// _log.error(error, e);
// throw new Exception(error);
// } catch (ItemAlreadyExistException e) {
// String error = "An error occurred on creating folder, " +e.getMessage();
// _log.error(error, e);
// throw new Exception(error);
} catch (Exception e) {
String error = "An error occurred on the sever during creating folder. Try again";
_log.error(error, e);
@ -465,14 +452,14 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
public Map<String, String> getGcubePropertiesForWorspaceId(String itemId) throws Exception {
_log.trace("getGcubePropertiesForWorspaceId "+itemId);
try {
StorageHubClient shc = new StorageHubClient();
Item item = shc.open(itemId).asItem().get();
return ItemBuilder.getGcubePropertiesForItem(item);
} catch (Throwable e) {
_log.error(e.getLocalizedMessage(), e);
return new HashMap<String, String>();
}
StorageHubClient shc = new StorageHubClient();
Item item = shc.open(itemId).asItem().get();
return ItemBuilder.getGcubePropertiesForItem(item);
} catch (Throwable e) {
_log.error(e.getLocalizedMessage(), e);
return new HashMap<String, String>();
}
}
/* (non-Javadoc)