git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/workspace-widget-portlet@167023 82a268e6-3cf1-43bd-a215-b396298e98cf
parent
9ffa9a3e18
commit
b1a12012a3
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>workspace-widget-portlet</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>com.liferay.ide.core.liferayNature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/webapp"/>
|
||||
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||
<attributes>
|
||||
<attribute name="hide" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
validateFragments=false
|
||||
validation.use-project-settings=true
|
@ -0,0 +1,4 @@
|
||||
activeProfiles=Liferay-v6.2-CE-(Tomcat-7)-(2)
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="workspace-widget-portlet-portlet">
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<property name="context-root" value="workspace-widget-portlet"/>
|
||||
<property name="java-output-path" value="/workspace-widget-portlet/target/classes"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
@ -0,0 +1,7 @@
|
||||
<root>
|
||||
<facet id="jst.jaxrs">
|
||||
<node name="libprov">
|
||||
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
|
||||
</node>
|
||||
</facet>
|
||||
</root>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="jst.web" version="2.4"/>
|
||||
<installed facet="liferay.portlet" version="6.0"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<installed facet="jst.jaxrs" version="2.0"/>
|
||||
</faceted-project>
|
@ -0,0 +1 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
@ -0,0 +1 @@
|
||||
Window
|
@ -0,0 +1,2 @@
|
||||
disabled=06target
|
||||
eclipse.preferences.version=1
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"plugins": {
|
||||
"guess-types": {
|
||||
|
||||
},
|
||||
"outline": {
|
||||
|
||||
},
|
||||
"liferay": {
|
||||
|
||||
},
|
||||
"yui3": {
|
||||
|
||||
},
|
||||
"aui2.0.x": {
|
||||
|
||||
}
|
||||
},
|
||||
"libs": [
|
||||
"ecma5",
|
||||
"browser"
|
||||
]
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>workspace-widget-portlet</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>workspace-widget-portlet Portlet</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<description>
|
||||
Workspace Widget
|
||||
</description>
|
||||
<scm>
|
||||
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</connection>
|
||||
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</developerConnection>
|
||||
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
|
||||
</scm>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>Liferay-v6.2-CE-(Tomcat-7)-(2)</id>
|
||||
<properties>
|
||||
<liferay.version>6.2.5</liferay.version>
|
||||
<liferay.maven.plugin.version>6.2.10.12</liferay.maven.plugin.version>
|
||||
<liferay.auto.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy</liferay.auto.deploy.dir>
|
||||
<liferay.app.server.deploy.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps</liferay.app.server.deploy.dir>
|
||||
<liferay.app.server.lib.global.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext</liferay.app.server.lib.global.dir>
|
||||
<liferay.app.server.portal.dir>/Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT</liferay.app.server.portal.dir>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.liferay.maven.plugins</groupId>
|
||||
<artifactId>liferay-maven-plugin</artifactId>
|
||||
<version>${liferay.maven.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>build-css</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
|
||||
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
|
||||
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
|
||||
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
|
||||
<liferayVersion>${liferay.version}</liferayVersion>
|
||||
<pluginType>portlet</pluginType>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-portal-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-bridges</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-taglib</artifactId>
|
||||
<version>${liferay.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>util-java</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,155 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.wswidget;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
import org.gcube.common.storagehub.model.items.VreFolder;
|
||||
import org.gcube.portlets.user.wswidget.shared.ItemType;
|
||||
import org.gcube.portlets.user.wswidget.shared.WSItem;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
public static final Logger _log = LoggerFactory.getLogger(ItemBuilder.class);
|
||||
private static UserManager UMAN = new LiferayUserManager();
|
||||
/**
|
||||
*
|
||||
* @param parent
|
||||
* @param workspaceItem
|
||||
* @param workspaceItemPath
|
||||
* @param currentUserName
|
||||
* @return
|
||||
*/
|
||||
public static WSItem getItem(WSItem parent, Item workspaceItem, String workspaceItemPath, String currentUserName) {
|
||||
ItemType type = getItemType(workspaceItem);
|
||||
boolean isFolder = type.equals(ItemType.PRIVATE_FOLDER)?true:false;
|
||||
boolean isSharedFolder = (type.equals(ItemType.SHARED_FOLDER) || type.equals(ItemType.VRE_FOLDER )) ? true : false;
|
||||
|
||||
String itemName = workspaceItem.getName();
|
||||
|
||||
if(isSharedFolder){
|
||||
_log.info("Is shared folder: "+workspaceItem.getTitle());
|
||||
SharedFolder shared = (SharedFolder) workspaceItem;
|
||||
itemName = shared.isVreFolder()?shared.getDisplayName():workspaceItem.getTitle();
|
||||
}
|
||||
|
||||
_log.debug("Building Item for: "+itemName + " id="+workspaceItem.getId());
|
||||
WSItem item = null;
|
||||
try{
|
||||
String fullName = "me";
|
||||
if (currentUserName.compareTo(workspaceItem.getOwner()) != 0) {
|
||||
fullName = workspaceItem.getOwner();
|
||||
try {
|
||||
fullName = UMAN.getUserByUsername(workspaceItem.getOwner()).getFullname();
|
||||
}
|
||||
catch (UserRetrievalFault f) {
|
||||
_log.warn("The user does not exist in this portal: " + fullName);
|
||||
}
|
||||
}
|
||||
item = new WSItem(parent, workspaceItem.getId(), itemName, type, workspaceItemPath, fullName, toDate(workspaceItem.getCreationTime()), toDate(workspaceItem.getLastModificationTime()), isFolder, false);
|
||||
item.setSharedFolder(isSharedFolder);
|
||||
if (isSharedFolder) {
|
||||
item.setIconNameAndColor("folder_shared", "#8F8F8F"); //gray
|
||||
} else if (isFolder) {
|
||||
item.setIconNameAndColor("folder", "#8F8F8F");// #gray
|
||||
}
|
||||
else { //is a file
|
||||
String[] splits = item.getName().split("\\.");
|
||||
String extension = "";
|
||||
if (splits.length > 0) {
|
||||
extension = splits[splits.length-1];
|
||||
}
|
||||
String iconURL = Utils.getIconImage(Utils.getFileIconImageType(extension).toString());
|
||||
String iconColor = Utils.getIconColor(Utils.getFileIconImageType(extension).toString());
|
||||
item.setIconNameAndColor(iconURL, iconColor);
|
||||
}
|
||||
} catch(Exception e){
|
||||
_log.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item type.
|
||||
*
|
||||
* @param item the item
|
||||
* @return the item type
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
protected static ItemType getItemType(Item item) {
|
||||
if (item instanceof AbstractFileItem) {
|
||||
return ItemType.EXTERNAL_FILE;
|
||||
}
|
||||
else if (item instanceof FolderItem) {
|
||||
return getFolderItemType(item);
|
||||
}
|
||||
_log.warn("Item Type non found: ");
|
||||
return ItemType.UNKNOWN_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder item type.
|
||||
*
|
||||
* @param item the item
|
||||
* @return the folder item type
|
||||
*/
|
||||
protected static ItemType getFolderItemType(Item item){
|
||||
if (item instanceof SharedFolder || item instanceof VreFolder) {
|
||||
SharedFolder folder = (SharedFolder) item;
|
||||
if (folder.isVreFolder())
|
||||
return ItemType.VRE_FOLDER;
|
||||
return ItemType.SHARED_FOLDER;
|
||||
} else if (item instanceof FolderItem) {
|
||||
return ItemType.PRIVATE_FOLDER;
|
||||
}
|
||||
_log.warn("Item Type non found: ");
|
||||
return ItemType.UNKNOWN_TYPE;
|
||||
}
|
||||
/**
|
||||
* Check allowed mime types.
|
||||
*
|
||||
* @param type the type
|
||||
* @param item the item
|
||||
* @param allowedMimeTypes the allowed mime types
|
||||
* @return true, if successful
|
||||
*/
|
||||
protected static boolean checkAllowedMimeTypes(ItemType type, Item item, List<String> allowedMimeTypes){
|
||||
if (allowedMimeTypes==null || allowedMimeTypes.size()==0) {
|
||||
return true;
|
||||
}
|
||||
if (type == ItemType.EXTERNAL_FILE || type == ItemType.EXTERNAL_IMAGE || type == ItemType.EXTERNAL_PDF_FILE) {
|
||||
AbstractFileItem externalFile = (AbstractFileItem)item;
|
||||
String mimeType = externalFile.getContent().getMimeType();
|
||||
return allowedMimeTypes.contains(mimeType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* To date.
|
||||
*
|
||||
* @param calendar the calendar
|
||||
* @return the date
|
||||
*/
|
||||
public static Date toDate(Calendar calendar) {
|
||||
if (calendar == null) return null;
|
||||
return calendar.getTime();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.wswidget;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.gcube.portlets.user.wswidget.shared.WSItem;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A comparator that sorts the items first by type, folder up others down, the each group alphabetically on the item name.
|
||||
* @author "Federico De Faveri defaveri@isti.cnr.it"
|
||||
*/
|
||||
public class ItemComparator implements Comparator<WSItem> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compare(WSItem item1, WSItem item2) {
|
||||
|
||||
//if one of the item is folder and the other one not, we move up the folder
|
||||
boolean isItem1Folder = Utils.isFolder(item1.getType());
|
||||
boolean isItem2Folder = Utils.isFolder(item2.getType());
|
||||
|
||||
//XOR
|
||||
if (isSpecialFolder(item1) ^ isSpecialFolder(item2)) return isSpecialFolder(item1) ? -1 : 1;
|
||||
|
||||
//XOR
|
||||
if (isItem1Folder ^ isItem2Folder) return isItem1Folder ? -1 : 1;
|
||||
|
||||
//otherwise we compare the names
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(item1.getName(), item2.getName());
|
||||
}
|
||||
|
||||
private boolean isSpecialFolder(WSItem item) {
|
||||
return item.getName().equals(Utils.VRE_FOLDERS_LABEL) && item.isSpecialFolder();
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package org.gcube.portlets.user.wswidget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.portlet.ResourceRequest;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
|
||||
import org.gcube.portlets.user.wswidget.shared.WSItem;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
|
||||
public class StorageHubServiceUtil {
|
||||
private static Log _log = LogFactoryUtil.getLog(StorageHubServiceUtil.class);
|
||||
/**
|
||||
*
|
||||
* @param authUser
|
||||
* @param itemId
|
||||
* @param itemName
|
||||
* @param from
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
public static List<WSItem> getItemChildren(AuthorizedUser authUser, String itemId, String itemName, int from, int offset) {
|
||||
WSItem toReturn = new WSItem(itemId, itemName, true);
|
||||
_log.debug("getItemChildren folder/item = " + itemId);
|
||||
ArrayList<WSItem> children = new ArrayList<>();
|
||||
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
List<? extends Item> theChildren = null;
|
||||
if (offset >= 0) {
|
||||
int limit = offset;
|
||||
theChildren = client.getChildren(itemId, from, limit, "hl:accounting");
|
||||
}
|
||||
else { //all the items
|
||||
theChildren = client.getChildren(itemId, "hl:accounting");
|
||||
}
|
||||
if (theChildren == null || theChildren.isEmpty()) {
|
||||
toReturn.setChildren(children);
|
||||
_log.debug("*** Returning empty ");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (Item workspaceItem : theChildren) {
|
||||
WSItem toAdd = ItemBuilder.getItem(toReturn, workspaceItem, workspaceItem.getPath(), authUser.getUser().getUsername());
|
||||
children.add(toAdd);
|
||||
}
|
||||
toReturn.setChildren(children);
|
||||
Collections.sort(toReturn.getChildren(), new ItemComparator());
|
||||
_log.debug("*** Returning children size: "+toReturn.getChildren().size());
|
||||
return children;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static int getItemChildrenCount(ResourceRequest request, String itemId) {
|
||||
String userName = Utils.getCurrentUser(request).getUsername();
|
||||
String scope = Utils.getCurrentContext(request);
|
||||
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
return client.childrenCount(itemId);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param authUser
|
||||
* @param from
|
||||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
public static List<WSItem> getRootChildren(AuthorizedUser authUser, int from, int offset) {
|
||||
try {
|
||||
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
|
||||
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||
Item itemRoot = client.getWorkspace("hl:accounting");
|
||||
WSItem root = new WSItem(itemRoot.getId(), Utils.HOME_LABEL, true);
|
||||
root.setIsRoot(true);
|
||||
return getItemChildren(authUser, itemRoot.getId(), Utils.HOME_LABEL, from, offset);
|
||||
} catch (Exception e) {
|
||||
_log.error("Error during root retrieving", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,286 @@
|
||||
package org.gcube.portlets.user.wswidget;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.wswidget.shared.ImageType;
|
||||
import org.gcube.portlets.user.wswidget.shared.ItemType;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
|
||||
public class Utils {
|
||||
private static Log _log = LogFactoryUtil.getLog(Utils.class);
|
||||
private final static String DEFAULT_ROLE = "OrganizationMember";
|
||||
public static final String WORKSPACE_MY_SPECIAL_FOLDERS_PATH = "/Workspace/MySpecialFolders";
|
||||
public static final String SPECIAL_FOLDERS_NAME = "MySpecialFolders";
|
||||
public static final String VRE_FOLDERS_LABEL = "My VRE Folders";
|
||||
public static final String HOME_LABEL = "Home";
|
||||
|
||||
public static final ItemType[] FOLDERS = new ItemType[] {ItemType.PRIVATE_FOLDER, ItemType.SHARED_FOLDER, ItemType.VRE_FOLDER};
|
||||
|
||||
/**
|
||||
* Checks if is folder.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @return true, if is folder
|
||||
*/
|
||||
public static boolean isFolder(ItemType type) {
|
||||
for (ItemType folder : FOLDERS)
|
||||
if (type == folder)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getIconImage(String type) {
|
||||
switch (type) {
|
||||
case "DOC":
|
||||
return "description";
|
||||
case "XLS":
|
||||
return "description";
|
||||
case "PPT":
|
||||
return "description";
|
||||
case "PDF":
|
||||
return "picture_as_pdf";
|
||||
case "IMAGE":
|
||||
return "panorama";
|
||||
case "MOVIE":
|
||||
return "movie_creation";
|
||||
case "HTML":
|
||||
return "web";
|
||||
case "RAR":
|
||||
return "archive";
|
||||
case "ZIP":
|
||||
return "archive";
|
||||
case "TXT":
|
||||
return "description";
|
||||
default:
|
||||
return "insert_drive_file";
|
||||
}
|
||||
}
|
||||
public static String getIconColor(String type) {
|
||||
switch (type) {
|
||||
case "DOC":
|
||||
return "#0277bd"; // light-blue darken-3
|
||||
case "XLS":
|
||||
return "#4caf50"; //green
|
||||
case "PPT":
|
||||
return "#fb8c00"; //orange
|
||||
case "PDF":
|
||||
return "#f44336"; //red
|
||||
case "IMAGE":
|
||||
return "#d81b60"; //light blue
|
||||
case "MOVIE":
|
||||
return "#90caf9";
|
||||
case "HTML":
|
||||
return "#0277bd";
|
||||
case "RAR":
|
||||
return "#ffc107";
|
||||
case "ZIP":
|
||||
return "#ffc107";//amber
|
||||
case "TXT":
|
||||
return "#CCC"; // gray
|
||||
default:
|
||||
return "#CCC"; // gray
|
||||
}
|
||||
}
|
||||
|
||||
public static GCubeUser getCurrentUser(RenderRequest request) {
|
||||
long userId;
|
||||
try {
|
||||
userId = PortalUtil.getUser(request).getUserId();
|
||||
return getCurrentUser(userId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GCubeUser getCurrentUser(HttpServletRequest request) {
|
||||
long userId;
|
||||
try {
|
||||
userId = PortalUtil.getUser(request).getUserId();
|
||||
return getCurrentUser(userId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GCubeUser getCurrentUser(ResourceRequest request) {
|
||||
long userId;
|
||||
try {
|
||||
userId = PortalUtil.getUser(request).getUserId();
|
||||
return getCurrentUser(userId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static GCubeUser getCurrentUser(long userId) {
|
||||
try {
|
||||
return new LiferayUserManager().getUserById(userId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCurrentContext(ResourceRequest request) {
|
||||
long groupId = -1;
|
||||
try {
|
||||
groupId = PortalUtil.getScopeGroupId(request);
|
||||
return getCurrentContext(groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCurrentContext(RenderRequest request) {
|
||||
long groupId = -1;
|
||||
try {
|
||||
groupId = PortalUtil.getScopeGroupId(request);
|
||||
return getCurrentContext(groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCurrentContext(HttpServletRequest request) {
|
||||
long groupId = -1;
|
||||
try {
|
||||
groupId = PortalUtil.getScopeGroupId(request);
|
||||
return getCurrentContext(groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCurrentContext(long groupId) {
|
||||
try {
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
return pContext.getCurrentScope(""+groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the gCube authorisation token for the given user
|
||||
* </p>
|
||||
* @param scope infrastrucure context (scope)
|
||||
* @param username the GCubeUser username @see {@link GCubeUser}
|
||||
* @return the Token for the user in the context, or <code>null</code> if a token for this user could not be found
|
||||
*/
|
||||
public static String getCurrentUserToken(String scope, String username) {
|
||||
String userToken = null;
|
||||
|
||||
try {
|
||||
ScopeProvider.instance.set(scope);
|
||||
userToken = authorizationService().resolveTokenByUserAndContext(username, scope);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
}
|
||||
catch (ObjectNotFound ex) {
|
||||
userToken = generateAuthorizationToken(username, scope);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
_log.debug("generateAuthorizationToken OK for " + username + " in scope " + scope);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_log.error("Error while trying to generate token for user " + username + "in scope " + scope);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return userToken;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @param scope
|
||||
* @throws Exception
|
||||
*/
|
||||
private static String generateAuthorizationToken(String username, String scope) {
|
||||
List<String> userRoles = new ArrayList<>();
|
||||
userRoles.add(DEFAULT_ROLE);
|
||||
String token;
|
||||
try {
|
||||
token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public static ImageType getFileIconImageType(String extension) {
|
||||
if (extension == null || extension.compareTo("") == 0)
|
||||
return ImageType.NONE;
|
||||
|
||||
switch (extension) {
|
||||
case "doc":
|
||||
case "docx":
|
||||
return ImageType.DOC;
|
||||
case "rtf":
|
||||
case "txt":
|
||||
return ImageType.TXT;
|
||||
case "xls":
|
||||
case "xlsx":
|
||||
return ImageType.XLS;
|
||||
case "ppt":
|
||||
case "pptx":
|
||||
return ImageType.PPT;
|
||||
case "pdf":
|
||||
return ImageType.PDF;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "gif":
|
||||
case "bmp":
|
||||
case "png":
|
||||
case "tif":
|
||||
case "tiff":
|
||||
return ImageType.IMAGE;
|
||||
case "avi":
|
||||
case "mp4":
|
||||
case "mpeg":
|
||||
return ImageType.MOVIE;
|
||||
case "html":
|
||||
case "htm":
|
||||
case "jsp":
|
||||
return ImageType.HTML;
|
||||
case "rar":
|
||||
return ImageType.RAR;
|
||||
case "zip":
|
||||
case "tar":
|
||||
case "tar.gz":
|
||||
case ".cpgz":
|
||||
case ".gz":
|
||||
return ImageType.ZIP;
|
||||
default:
|
||||
return ImageType.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package org.gcube.portlets.user.wswidget;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletSession;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.portlet.ResourceResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
|
||||
import org.gcube.portlets.user.wswidget.shared.Breadcrumb;
|
||||
import org.gcube.portlets.user.wswidget.shared.WSItem;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
import com.liferay.portal.kernel.json.JSONArray;
|
||||
import com.liferay.portal.kernel.json.JSONFactoryUtil;
|
||||
import com.liferay.portal.kernel.json.JSONObject;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
|
||||
import com.liferay.portal.kernel.util.ParamUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||
|
||||
/**
|
||||
* Portlet implementation class WorkspaceWidget
|
||||
*/
|
||||
public class WorkspaceWidget extends MVCPortlet {
|
||||
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(WorkspaceWidget.class);
|
||||
public static String BREADCRUMB_ATTR = "BREADCRUMB_ATTR_name";
|
||||
|
||||
@Override
|
||||
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException {
|
||||
String fileToDownloadId = ParamUtil.getString(resourceRequest, "fileToDownloadId", null);
|
||||
//check if is a file download
|
||||
if (fileToDownloadId != null) {
|
||||
setAuthorizationToken(resourceRequest);
|
||||
String selectedItemId = fileToDownloadId.split("=")[1];
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
StreamDescriptor streamDescr = client.download(selectedItemId);
|
||||
HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
|
||||
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
|
||||
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
|
||||
streamDescr.getStream().close();
|
||||
}
|
||||
//the user is browsing the workspace
|
||||
else {
|
||||
String cmd = ParamUtil.getString(resourceRequest, "cmd", "");
|
||||
PortalUtil.getHttpServletRequest(resourceRequest);
|
||||
String selectedItemId = "root";
|
||||
String selectedItemName = "";
|
||||
if (cmd != null && cmd.split("_selectedName").length > 1) {
|
||||
String[] splits = cmd.split("_selectedName");
|
||||
selectedItemId = splits[0].split("=")[1];
|
||||
selectedItemName= splits[1].split("=")[1];
|
||||
}
|
||||
int start = ParamUtil.getInteger(resourceRequest, "start");
|
||||
int length = ParamUtil.getInteger(resourceRequest, "length");
|
||||
int draw = ParamUtil.getInteger(resourceRequest, "draw");
|
||||
listItems(resourceRequest, resourceResponse, selectedItemId, selectedItemName, start, length, draw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void listItems(ResourceRequest request, ResourceResponse resourceResponse, String itemId, String itemName, int start, int offset, int draw) {
|
||||
try {
|
||||
AuthorizedUser authUser = setAuthorizationToken(request);
|
||||
List<WSItem> itemsList = new ArrayList<>();
|
||||
Breadcrumb toSet = null;
|
||||
WSItem clicked = null;
|
||||
int count = 0;
|
||||
if (itemId.compareTo("root") == 0) {
|
||||
//here we have to check is is a VRE, in that case the content of the VRE Folder is the root
|
||||
itemId = getRootItem(request).getId();
|
||||
itemsList = StorageHubServiceUtil.getRootChildren(authUser, start, offset);
|
||||
toSet = new Breadcrumb(itemId, Utils.getCurrentUser(request).getFirstName()+"\'s home");
|
||||
request.getPortletSession().setAttribute(BREADCRUMB_ATTR, toSet, PortletSession.APPLICATION_SCOPE);
|
||||
}
|
||||
else {
|
||||
_log.debug("non root");
|
||||
itemsList = StorageHubServiceUtil.getItemChildren(authUser, itemId, itemId, start, offset);
|
||||
toSet = (Breadcrumb) request.getPortletSession().getAttribute(BREADCRUMB_ATTR, PortletSession.APPLICATION_SCOPE);
|
||||
clicked = new WSItem(itemId, itemName, true);
|
||||
computeBreadcrumb(clicked, toSet);
|
||||
}
|
||||
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
||||
JSONObject tableData = buildJSONResponse(itemsList, start, offset, draw, count, request);
|
||||
ServletResponseUtil.write(PortalUtil.getHttpServletResponse(resourceResponse),tableData.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* computes the breadcrumb
|
||||
* @param toReturn
|
||||
* @param toCompute
|
||||
*/
|
||||
public void computeBreadcrumb(WSItem toReturn, Breadcrumb toCompute) {
|
||||
boolean found = false;
|
||||
while (toCompute.hasChild()) {
|
||||
if (toReturn.getId().equals(toCompute.getId())) { //in case the user click on the breadcrumb
|
||||
toCompute.setChild(null);
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
toCompute = toCompute.getChild();
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (toReturn.getName().equals(Utils.SPECIAL_FOLDERS_NAME)) //in case the user clicked on the VRE Folders
|
||||
toReturn.setName(Utils.VRE_FOLDERS_LABEL);
|
||||
if (! toReturn.getId().equals(toCompute.getId()))
|
||||
toCompute.setChild(new Breadcrumb(toReturn.getId(), toReturn.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private static String constructBreadcrumbHTML(Breadcrumb toSet, ResourceRequest request) {
|
||||
StringBuilder sb =
|
||||
new StringBuilder("<ul class='breadcrumb'>");
|
||||
sb.append("<li>").append(getHREFJavascriptCall(toSet)).append("</li>");
|
||||
while (toSet.hasChild()) {
|
||||
toSet = toSet.getChild();
|
||||
if (!toSet.hasChild()) {
|
||||
sb.append("<li><span class='active'> / </span>").append(toSet.getName()).append("</li>");
|
||||
}
|
||||
else {
|
||||
sb.append("<li><span class='divider'>/</span>").append(getHREFJavascriptCall(toSet)).append("</li>");
|
||||
}
|
||||
}
|
||||
sb.append("</ul>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String getHREFJavascriptCall(Breadcrumb toSet) {
|
||||
String escapedItemName = toSet.getName().replaceAll("\"", "\\\"").replaceAll("'", "\\\\'");
|
||||
StringBuilder sb = new StringBuilder
|
||||
("<a href=\"javascript:loadItemsListIntoTable('").append(toSet.getId()).append("', '").append(escapedItemName).append("');\">")
|
||||
.append(toSet.getName()).append("</a>");
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param itemsList
|
||||
* @param start
|
||||
* @param offset
|
||||
* @param draw
|
||||
* @param count
|
||||
* @param request
|
||||
* @return the JSON response to the client
|
||||
*/
|
||||
private JSONObject buildJSONResponse(List<WSItem> itemsList, int start, int offset, int draw, int count, ResourceRequest request){
|
||||
JSONArray usersJsonArray = JSONFactoryUtil.createJSONArray();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM HH:ss yy");
|
||||
|
||||
JSONObject jsonUser = null;
|
||||
for (WSItem item : itemsList) {
|
||||
JSONArray nameAndIconArray = JSONFactoryUtil.createJSONArray();
|
||||
JSONObject nameAndIconObject = JSONFactoryUtil.createJSONObject();
|
||||
nameAndIconObject.put("Icon", item.getIconURL());
|
||||
nameAndIconObject.put("IconColor", item.getIconColor());
|
||||
nameAndIconObject.put("Name", item.getName());
|
||||
nameAndIconObject.put("Id", item.getId());
|
||||
nameAndIconObject.put("isFolder", item.isFolder() || item.isSharedFolder() || item.isSpecialFolder());
|
||||
nameAndIconArray.put(nameAndIconObject);
|
||||
|
||||
jsonUser = JSONFactoryUtil.createJSONObject();
|
||||
//we need to pass a JSON here as String without
|
||||
String stringfiedJsonArray = nameAndIconArray.toString();
|
||||
jsonUser.put("Id",item.getId());
|
||||
jsonUser.put("Name", stringfiedJsonArray.substring(1, stringfiedJsonArray.length()-1)); //without square brackets so that it is parsable in the client
|
||||
jsonUser.put("Owner",item.getOwner());
|
||||
jsonUser.put("LastModified", sdf.format(item.getLastUpdated()));
|
||||
jsonUser.put("isFolder", item.isFolder() || item.isSharedFolder() || item.isSpecialFolder());
|
||||
usersJsonArray.put(jsonUser);
|
||||
}
|
||||
|
||||
JSONObject tableData = JSONFactoryUtil.createJSONObject();
|
||||
tableData.put("mytabledata", usersJsonArray);
|
||||
Breadcrumb bcBegin = (Breadcrumb) request.getPortletSession().getAttribute(BREADCRUMB_ATTR, PortletSession.APPLICATION_SCOPE);
|
||||
tableData.put("breadcrumb", constructBreadcrumbHTML(bcBegin, request));
|
||||
tableData.put("draw", draw);
|
||||
tableData.put("recordsTotal", count);
|
||||
tableData.put("recordsFiltered", count);
|
||||
_log.debug("tableData:"+tableData.toString());
|
||||
return tableData;
|
||||
}
|
||||
|
||||
private static WSItem getRootItem(ResourceRequest request) {
|
||||
String userName = Utils.getCurrentUser(request).getUsername();
|
||||
String scope = Utils.getCurrentContext(request);
|
||||
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
||||
Item itemRoot = client.getWorkspace("hl:accounting");
|
||||
WSItem root = new WSItem(itemRoot.getId(), Utils.HOME_LABEL, true);
|
||||
root.setIsRoot(true);
|
||||
root.setFolder(true);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the authorization token in Thread local and return the current {@link AuthorizedUser} instance
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private AuthorizedUser setAuthorizationToken(ResourceRequest request) {
|
||||
GCubeUser currentUser = Utils.getCurrentUser(request);
|
||||
String scope = Utils.getCurrentContext(request);
|
||||
String authorizationToken = Utils.getCurrentUserToken(scope, currentUser.getUsername());
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
return new AuthorizedUser(currentUser, authorizationToken);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
public class AuthorizedUser {
|
||||
private GCubeUser user;
|
||||
private String token;
|
||||
public AuthorizedUser(GCubeUser user, String token) {
|
||||
super();
|
||||
this.user = user;
|
||||
this.token = token;
|
||||
}
|
||||
public GCubeUser getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(GCubeUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
public String getSecurityToken() {
|
||||
return token;
|
||||
}
|
||||
public void setSecurityToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("AuthorizedUser [user=");
|
||||
builder.append(user);
|
||||
builder.append(", token=");
|
||||
builder.append(token);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class Breadcrumb implements Serializable {
|
||||
String id;
|
||||
String name;
|
||||
Breadcrumb child = null;
|
||||
public Breadcrumb(String id, String name) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Breadcrumb getChild() {
|
||||
return child;
|
||||
}
|
||||
public void setChild(Breadcrumb child) {
|
||||
this.child = child;
|
||||
}
|
||||
public boolean hasChild() {
|
||||
return this.child != null;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Breadcrumb [id=" + id + ", name=" + name + ", child=" + ((child == null) ? "" : child.toString()) + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
public enum ImageType {
|
||||
DOC, PPT, XLS, NONE, MOVIE, HTML, PDF, IMAGE, RAR, ZIP, TXT
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Feb 26, 2016
|
||||
*/
|
||||
public interface ItemInterface {
|
||||
|
||||
public String getId();
|
||||
public String getName();
|
||||
public String getPath();
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
public enum ItemType {
|
||||
|
||||
PRIVATE_FOLDER, //MANDATORY
|
||||
SHARED_FOLDER,
|
||||
VRE_FOLDER,
|
||||
EXTERNAL_IMAGE,
|
||||
EXTERNAL_FILE,
|
||||
EXTERNAL_PDF_FILE,
|
||||
EXTERNAL_URL,
|
||||
QUERY,
|
||||
REPORT_TEMPLATE,
|
||||
REPORT,
|
||||
DOCUMENT,
|
||||
METADATA,
|
||||
PDF_DOCUMENT,
|
||||
IMAGE_DOCUMENT,
|
||||
URL_DOCUMENT,
|
||||
GCUBE_ITEM,
|
||||
TIME_SERIES,
|
||||
WORKFLOW_REPORT,
|
||||
UNKNOWN_TYPE;
|
||||
}
|
@ -0,0 +1,429 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.wswidget.shared;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The Class Item.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Dec 2, 2015
|
||||
*/
|
||||
public class WSItem implements ItemInterface {
|
||||
|
||||
protected WSItem parent;
|
||||
protected String id;
|
||||
protected String name;
|
||||
protected ItemType type;
|
||||
protected String path;
|
||||
protected String iconName;
|
||||
protected String iconColor;
|
||||
|
||||
protected ArrayList<WSItem> children;
|
||||
protected String owner;
|
||||
protected boolean isFolder;
|
||||
protected boolean isSpecialFolder = false;
|
||||
protected boolean isSharedFolder = false;
|
||||
protected boolean isRoot = false;
|
||||
protected Date dateCreated;
|
||||
protected Date lastUpdated;
|
||||
|
||||
|
||||
private Map<String, String> gcubeProperties;
|
||||
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*/
|
||||
public WSItem() {
|
||||
}
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param isFolder the is folder
|
||||
*/
|
||||
public WSItem(String id, String name, boolean isFolder) {
|
||||
this.id = id;
|
||||
this.isFolder = isFolder;
|
||||
this.name = name;
|
||||
this.type = isFolder?ItemType.PRIVATE_FOLDER:ItemType.UNKNOWN_TYPE;
|
||||
this.children = new ArrayList<WSItem>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param type the type
|
||||
* @param path the path
|
||||
* @param owner the owner
|
||||
* @param creationDate the creation date
|
||||
* @param isFolder the is folder
|
||||
* @param isRoot the is root
|
||||
*/
|
||||
public WSItem(WSItem parent, String id, String name, ItemType type, String path, String owner, Date creationDate, Date lastUpdated, boolean isFolder, boolean isRoot) {
|
||||
this(parent, id, name, type, path, owner, isFolder, isRoot);
|
||||
this.dateCreated = creationDate;
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new item.
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param type the type
|
||||
* @param path the path
|
||||
* @param owner the owner
|
||||
* @param isFolder the is folder
|
||||
* @param isRoot the is root
|
||||
*/
|
||||
public WSItem(WSItem parent, String id, String name, ItemType type, String path, String owner, boolean isFolder, boolean isRoot) {
|
||||
this(id, name, isFolder);
|
||||
this.parent = parent;
|
||||
this.type = type;
|
||||
this.path = path;
|
||||
this.children = new ArrayList<WSItem>();
|
||||
this.owner = owner;
|
||||
this.isRoot = isRoot;
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
|
||||
public String getIconURL() {
|
||||
return iconName;
|
||||
}
|
||||
public void setIconNameAndColor(String iconName, String color) {
|
||||
this.iconName = iconName;
|
||||
this.iconColor = color;
|
||||
}
|
||||
/**
|
||||
* Sets the children.
|
||||
*
|
||||
* @param children the new children
|
||||
*/
|
||||
public void setChildren(ArrayList<WSItem> children) {
|
||||
|
||||
this.children = children;
|
||||
}
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is root.
|
||||
*
|
||||
* @return true, if is root
|
||||
*/
|
||||
public boolean isRoot() {
|
||||
return isRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the is root.
|
||||
*
|
||||
* @param isRoot the is root
|
||||
* @return true, if successful
|
||||
*/
|
||||
public void setIsRoot(boolean isRoot) {
|
||||
this.isRoot = isRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is folder.
|
||||
*
|
||||
* @return the isFolder
|
||||
*/
|
||||
public boolean isFolder() {
|
||||
return isFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the folder.
|
||||
*
|
||||
* @param isFolder
|
||||
* the isFolder to set
|
||||
*/
|
||||
public void setFolder(boolean isFolder) {
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is shared folder.
|
||||
*
|
||||
* @return the isSharedFolder
|
||||
*/
|
||||
public boolean isSharedFolder() {
|
||||
return isSharedFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shared folder.
|
||||
*
|
||||
* @param isSharedFolder
|
||||
* the isSharedFolder to set
|
||||
*/
|
||||
public void setSharedFolder(boolean isSharedFolder) {
|
||||
this.isSharedFolder = isSharedFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item parent. Null if is the root.
|
||||
*
|
||||
* @return the item parent.
|
||||
*/
|
||||
public WSItem getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item id.
|
||||
*
|
||||
* @return the id.
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item name.
|
||||