Replace the call `getItem` with `getItemForExplorer`

This commit is contained in:
Francesco Mangiacrapa 2020-04-17 12:17:18 +02:00
parent 9a749d41ca
commit 53c63f8c9e
6 changed files with 14 additions and 129 deletions

View File

@ -13,15 +13,15 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">

View File

@ -2,5 +2,4 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -135,7 +135,7 @@ public class DownloadWorkspaceExplorerServlet extends HttpServlet{
// }
//SINGLE DONWLOAD - DOWNLOAD WORKSPACE ITEM
item = wa.getItem(ids.get(0));
item = wa.getItemForExplorer(ids.get(0), false, false, false);
if(isValidItem){ //ADDED 25/06/2013 - THIS CODE RETURN A SC_ACCEPT IS ITEM EXIST
String message = HttpServletResponse.SC_ACCEPTED+ ": The resource is available";
sendMessageResourceAvailable(resp, message);
@ -453,7 +453,7 @@ public class DownloadWorkspaceExplorerServlet extends HttpServlet{
* @param workspaceItemIds the workspace item ids
* @return the list
*/
private List<WorkspaceItem> toWorkspaceItems(Workspace ws, List<String> workspaceItemIds){
/*private List<WorkspaceItem> toWorkspaceItems(Workspace ws, List<String> workspaceItemIds){
if(workspaceItemIds==null)
return null;
@ -468,7 +468,7 @@ public class DownloadWorkspaceExplorerServlet extends HttpServlet{
}
}
return listWI;
}
}*/
/**
* Method to manage HttpServletResponse content length also to big data.

View File

@ -40,7 +40,6 @@ public class ItemComparator implements Comparator<Item> {
}
private boolean isSpecialFolder(Item item) {
// return item.getName().equals(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL) && item.getParent()!=null && item.getParent().isRoot();
return item.getName().equals(WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL) && item.isSpecialFolder();
}
}

View File

@ -141,7 +141,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
throw new Exception("Item id is null");
workspace = getWorkspace();
workspaceItem = workspace.getItem(item.getId());
workspaceItem = workspace.getItemForExplorer(item.getId(), false, false, false);
} catch (Exception e) {
logger.error("Error during item retrieving", e);
@ -232,122 +232,6 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
}
}
/**
* Gets Breadcrumbs (the list of parents) by item identifier.
*
* @param itemIdentifier the item identifier
* @param includeItemAsParent - if parameter is true and item passed in input is a folder, the folder is included in path returned as last parent
* @return the list parents by item identifier
* @throws Exception the exception
*/
//@Override
/*public List<Item> getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception {
logger.trace("ListParents By Item Identifier "+ itemIdentifier);
try {
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
logger.trace("workspace retrieve item name: "+wsItem.getName());
List<? extends WorkspaceItem> parents = workspace.getParentsById(itemIdentifier);
logger.trace("parents size: "+parents.size());
Item[] arrayParents;
switch (parents.size()) {
case 0: // itemIdentifier is ROOT
logger.trace("itemIdentifier isRoot...");
if (includeItemAsParent) { //ADDING ROOT
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsFolder =
(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wsItem;
Item root = ItemBuilder.buildFolderForBreadcrumbs(wsFolder, null);
List<Item> listParents = new ArrayList<Item>(1);
listParents.add(root);
//workspaceLogger.trace("returning: "+listParents.toString());
return listParents;
}
else{
logger.trace("returning empty list");
return new ArrayList<Item>(); // empty list
}
case 1: //itemIdentifier is first level from root
logger.trace("itemIdentifier is first level...");
List<Item> listParents = new ArrayList<Item>();
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsRootFolder = (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) parents.get(0); //isRoot
Item root = ItemBuilder.buildFolderForBreadcrumbs(wsRootFolder, null);
Item parent = null;
if(includeItemAsParent){
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder wsFolder1 =
(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) workspace.getItem(itemIdentifier); //root
parent = ItemBuilder.buildFolderForBreadcrumbs(wsFolder1, null);
}
listParents.add(root);
if(parent!=null)
listParents.add(parent);
// workspaceLogger.trace("returning: "+listParents.toString());
return listParents;
default:
break;
}
WorkspaceItem lastItem = parents.get(parents.size()-1);
//CONVERTING LAST ELEMENT IF NECESSARY
logger.trace("converting last element..");
if(includeItemAsParent && lastItem.isFolder()){ //FIX BUG #298
arrayParents = new Item[parents.size()];
logger.debug("including last item into path: "+lastItem.getName());
arrayParents[parents.size()-1] = ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) lastItem, null);
}else
arrayParents = new Item[parents.size()-1];
// HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER BUT RETURNING ONLY /MY_SPECIAL_FOLDER
if(wsItem.isFolder()){
if(ItemBuilder.isSpecialFolder((WorkspaceFolder) wsItem, lastItem.isRoot())){
return new ArrayList<Item>(Arrays.asList(arrayParents));
}
}
//CONVERTING PATH
logger.trace("converting path from second-last..");
for (int i = parents.size()-2; i >= 0; i--) {
WorkspaceFolder wsParentFolder = (WorkspaceFolder) parents.get(i);
arrayParents[i] = ItemBuilder.buildFolderForBreadcrumbs(wsParentFolder, null);
if(arrayParents[i].isSpecialFolder()){ //SKIP HOME PARENT FOR MY_SPECIAL_FOLDER
logger.info("arrayParents index "+i+" is special folder, exit");
break;
}
}
//SET PARENTS
logger.trace("setting parents..");
for(int i=0; i<arrayParents.length-1; i++){
Item parent = arrayParents[i];
Item fileModel = arrayParents[i+1];
fileModel.setParent(parent);
}
logger.trace("ListParents return size: "+arrayParents.length);
if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER
List<Item> breadcrumbs = new ArrayList<Item>(arrayParents.length-1);
for (int i=1; i<arrayParents.length; i++) {
breadcrumbs.add(arrayParents[i]);
}
return breadcrumbs;
}
else {
return new ArrayList<Item>(Arrays.asList(arrayParents));
}
} catch (Exception e) {
logger.error("Error in get List Parents By Item Identifier ", e);
throw new Exception("Sorry, an error occurred during path retrieving!");
}
}*/
/**
* Gets the parents by item identifier to limit.
* when limit is reached parents are null
@ -363,8 +247,9 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
try {
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
logger.trace("workspace retrieve item name: "+wsItem.getName());
WorkspaceItem wsItem = workspace.getItemForExplorer(itemIdentifier,false,false,false);
logger.info("\n\nworkspace retrieve item name: "+wsItem.getName());
logger.info("\n\n");
List<? extends WorkspaceItem> parents = null;
try{
parents = workspace.getParentsById(itemIdentifier);
@ -378,7 +263,8 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
if(logger.isDebugEnabled()) {
for (WorkspaceItem workspaceItem : parents) {
logger.debug("the parent is: "+workspaceItem.getName());
logger.info("the parent is: "+workspaceItem.getName());
logger.info("\n\n");
}
}
@ -386,6 +272,8 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
List<Item> arrayParents = new ArrayList<Item>();
parentLimit = parentLimit!=null?parentLimit:"";
logger.info("parent size returned by SHUB is: "+parents.size());
switch (parents.size()) {
case 0: // itemIdentifier is ROOT
logger.trace("itemIdentifier isRoot...");
@ -519,7 +407,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem
throw new Exception("Sorry, the itemId is null. The public link for empty item is unavailable");
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemId);
WorkspaceItem wsItem = workspace.getItemForExplorer(itemId,false,false,false);
if(wsItem==null)
throw new Exception("Sorry, the workspace item is null. The public link for empty item is unavailable");

View File

@ -213,7 +213,6 @@ public class ItemBuilder {
switch (item.getType()) {
case SHARED_FOLDER:
case FOLDER: {
// if (item.isRoot()) return ItemType.ROOT;
return ItemType.FOLDER;
}
case FILE_ITEM: