ported to Liferay 6.2

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@129625 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Massimiliano Assante 8 years ago
parent 5bf417cb40
commit 6b75b527e1

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/reports-5.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/reports-6.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/reports-5.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/reports-6.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -4,7 +4,10 @@
<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="/target/generated-sources/gwt"/>
<dependent-module archiveName="gcube-reporting-library-3.6.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-reporting-library_trunk/gcube-reporting-library_trunk">
<dependent-module archiveName="session-checker-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="gcube-reporting-library-3.6.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-reporting-library/gcube-reporting-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>reports</artifactId>
<packaging>war</packaging>
<version>5.1.0-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<name>gCube Reports Manager</name>
<description>
gCube Reports Portlet.
@ -38,23 +38,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>offline</id>
<properties>
<setScope>compile</setScope>
<setClassifier>offline</setClassifier>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore-offline</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>${setScope}</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
@ -71,13 +54,13 @@
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
@ -92,7 +75,7 @@
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[0.4.0-SNAPSHOT, 1.0.0-SNAPSHOT)</version>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
@ -107,22 +90,22 @@
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sencha.gxt</groupId>
@ -153,6 +136,10 @@
<artifactId>javax.el-api</artifactId>
<groupId>javax.el</groupId>
</exclusion>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@ -176,11 +163,6 @@
<artifactId>workspace-explorer</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.admin</groupId>
<artifactId>document-workflow-library</artifactId>
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>report-exporter-widget</artifactId>
@ -221,7 +203,6 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<!-- <classifier>${setClassifier}</classifier> -->
<scope>provided</scope>
</dependency>
<dependency>
@ -232,27 +213,27 @@
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>${setScope}</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>

@ -213,26 +213,6 @@ public class Headerbar extends Composite{
MenuBar workflowMenu = new MenuBar(true);
workflowMenu.setAnimationEnabled(true);
MenuItem menu = new MenuItem("<nobr>Workflow Document Options</nobr>", true, workflowMenu);
menu.setWidth("400px");
Command updateWfDocument = new Command() {
public void execute() {
presenter.updateWorkflowDocument(true);
}
};
Command backCommand = new Command() {
public void execute() {
presenter.updateWorkflowDocument(false);
}
};
if (canUpdate)
workflowMenu.addItem("Update this document", updateWfDocument);
//workflowMenu.addItem("Show previous changes", showChanges);
workflowMenu.addSeparator();
workflowMenu.addItem("Back to My Workflow Documents", backCommand);
menuBar.addItem(menu);
separator1 = menuBar.addSeparator();
viewMenu = getViewMenu();
menuBar.addItem(viewMenu);

@ -98,12 +98,6 @@ public interface ReportService extends RemoteService{
VmeExportResponse deleteReportFromRSG(VMETypeIdentifier refType, String idToDelete);
Model getWorkflowDocumentFromDocumentLibrary();
void updateWorkflowDocument(Model toSave, boolean update);
void renewLock();
/**
*
* @param tempPath

@ -65,12 +65,6 @@ public interface ReportServiceAsync {
*/
void getSessionInfo(String currentHost, AsyncCallback<SessionInfo> callback);
void getWorkflowDocumentFromDocumentLibrary(AsyncCallback<Model> callback);
void updateWorkflowDocument(Model toSave, boolean update, AsyncCallback<Void> callback);
void renewLock(AsyncCallback<Void> callback);
void readImportedModel(String tempPath, AsyncCallback<Model> callback);
void save(String filePath, String workspaceFolderId, String ItemName, TypeExporter type, boolean overwrite, AsyncCallback<String> callback);

@ -101,31 +101,6 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
mainLayout.setStyleName("titleBar");
}
/**
* add the buttons well visible on the top
* @param isEdit
*/
public void addWorkflowButtons(final boolean isEdit) {
Button update = new Button("Update (SAVE)");
update.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.updateWorkflowDocument(isEdit);
}
});
Button back = new Button("Do not Update");
back.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.updateWorkflowDocument(isEdit);
}
});
update.addStyleName("addEntryButton");
back.addStyleName("deleteEntryButton");
captionPanel.add(update);
captionPanel.add(back);
}
/**

@ -1,312 +0,0 @@
package org.gcube.portlets.user.reportgenerator.server.servlet;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portlets.admin.wfdocslibrary.shared.PermissionType;
import org.gcube.portlets.admin.wfdocslibrary.shared.Step;
import org.gcube.portlets.admin.wfdocslibrary.shared.WfRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.ResourceConstants;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.PermissionLocalServiceUtil;
import com.liferay.portal.service.ResourceLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portlet.documentlibrary.NoSuchFolderException;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.documentlibrary.model.DLFolder;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
public class DocLibraryUtil {
public static final String WORKFLOWS_FOLDER = "Workflow Documents";
/**
*
*/
private static final Logger log = LoggerFactory.getLogger(DocLibraryUtil.class);
/**
* write the Report File (payload) into Liferay DocLibrary in the workflowdocs folder
* @param roles
* @param start each Step contains a Map<WfRole, ArrayList<PermissionType>> that is needed in the writeFileIntoDocLibrary
* @param fileName
* @param buffer the payload as byte array
*/
public static boolean writeFileIntoDocLibrary(ASLSession session, List<Role> roles, Step start, String fileName, byte[] buffer) {
long docfolderid = -1;
try {
docfolderid = getWfFolder(session);
long userId = getUserId(session);
//write the file into doclib
DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(
userId,
getGroupID(session),
docfolderid,
fileName,
fileName,
"workflow document",
"",
"",
buffer,
new ServiceContext());
log.debug("Wrote file into DocumentLibrary");
//get the file entry resource id
long resourceId = ResourceLocalServiceUtil.getResource(fileEntry.getCompanyId(),
DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry.getFileEntryId())).getResourceId();
//set the permission on the file for each role
for (Role role : roles) {
String[] actionIds = getPermissionsFromWfStep(role, start);
PermissionLocalServiceUtil.setRolePermissions(role.getRoleId(), actionIds, resourceId);
log.debug("set the permissions for Role: " + role.getName());
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
log.debug(" WROTE INTO DOCsLib and ADDING permissions for name: " + fileName);
return true;
}
public static DLFileEntry updateFileIntoDocLibrary(ASLSession session, String workflowid, byte[] buffer) {
long docfolderid = -1;
DLFileEntry fileEntry = null;
try {
fileEntry = getFileEntry(session, workflowid);
docfolderid = getWfFolder(session);
long userId = getUserId(session);
String fileName = fileEntry.getTitle();
log.debug("Update file into DocumentLibrary with Name: " + fileName);
DLFileEntryLocalServiceUtil.updateFileEntry(
userId,
getGroupID(session),
docfolderid,
fileEntry.getName(),
fileEntry.getName(),
fileName,
fileEntry.getDescription(),
"",
true,
"",
buffer,
new ServiceContext());
log.debug("Update file into DocumentLibrary");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return fileEntry;
}
public static boolean deleteFileFromDocLibrary(ASLSession session, String workflowid) {
DLFileEntry fileEntry = null;
try {
fileEntry = getFileEntry(session, workflowid);
DLFileEntryLocalServiceUtil.deleteDLFileEntry(fileEntry);
log.debug("Deleted");
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
*
* @param session
* @param workflowid
* @return
* @throws Exception
* @throws SystemException
* @throws PortalException
*/
public static InputStream getFileEntryAsStream(ASLSession session, String workflowid) throws Exception {
String titleWithExtension = workflowid+".zip";
DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntryByTitle(getGroupID(session), getWfFolder(session),
titleWithExtension);
return DLFileEntryLocalServiceUtil.getFileAsStream(fileEntry.getCompanyId(),
getUserId(session), getGroupID(session), getWfFolder(session), fileEntry.getName());
}
public static DLFileEntry getFileEntry(ASLSession session, String workflowid) throws PortalException, SystemException, Exception {
String titleWithExtension = workflowid+".zip";
return DLFileEntryLocalServiceUtil.getFileEntryByTitle(getGroupID(session), getWfFolder(session),
titleWithExtension);
}
/**
*
* @param role is the liferay role, for convention is created as ROLENAME_WFID e.g. EDITOR_123
* @param step containts the permissions attached to each role (just the name, e.g. EDITOR)
* @return the permissions to apply
*/
public static String[] getPermissionsFromWfStep(Role role, Step step) {
ArrayList<PermissionType> toConvert = new ArrayList<PermissionType>();
for (WfRole steprole : step.getPermissions().keySet()) {
System.out.println("Steprole: "+ steprole.getRolename());
String name = role.getName().split("_")[0]; //e.g. EDITOR <- EDITOR_123
System.out.println("role Name: "+ name);
if (steprole.getRolename().equals(name)) {
toConvert = step.getPermissions().get(steprole);
}
}
String[] toReturn = new String[toConvert.size()];
int i = 0;
for (PermissionType p : toConvert) {
toReturn[i] = getLRActionIdFromWfPermissionType(p);
i++;
}
return toReturn;
}
/**
* check the existence of the WFFolder or create it if not exists
* @param session
* @return true is everything goes ok
* @throws PortalException
* @throws SystemException
*/
public static long getWfFolder(ASLSession session) throws Exception {
long parentFolderId = 0;
DLFolder folder = null;
if (! wfFolderExists(session)) {
folder = DLFolderLocalServiceUtil.addFolder(getUserId(session), getGroupID(session), parentFolderId, WORKFLOWS_FOLDER, "Folder for Workflow Documents", new ServiceContext());
log.debug("Folder for WorkflowDocs created: /" + WORKFLOWS_FOLDER);
} else
folder = DLFolderLocalServiceUtil.getFolder( getGroupID(session), parentFolderId, WORKFLOWS_FOLDER);
return folder.getFolderId();
}
/**
*
* @param session the ASL Session instance
* @return true if the workflow docs exists
*/
public static boolean wfFolderExists(ASLSession session) {
try {
long groupid = getGroupID(session);
long parentfolder = 0;
if (DLFolderLocalServiceUtil.getFolder(groupid, parentfolder, "Workflow Documents") != null)
return true;
else
return false;
}
catch (NoSuchFolderException ex) {
log.debug("Folder does not exists");
return false;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
*
* @param session
* @return
* @throws PortalException
* @throws SystemException
*/
public static long getGroupID(ASLSession session) throws PortalException, SystemException {
long organizationid = session.getGroupId();
Organization myOrg = OrganizationLocalServiceUtil.getOrganization(organizationid);
return myOrg.getGroup().getGroupId();
}
/**
*
* @return the company webid
* @throws PortalException
* @throws SystemException
*/
public static long getCompanyID() throws PortalException, SystemException {
return OrganizationsUtil.getCompany().getCompanyId();
}
/**
*
* @param session the ASL Session instance
* @return the list of the root folders
* @throws SystemException .
* @throws PortalException .
*/
public static List<DLFolder> getFolders(ASLSession session) throws SystemException, PortalException {
long companyid = getCompanyID();
List<DLFolder> folders = null;
folders = DLFolderLocalServiceUtil.getFolders(companyid);
for (DLFolder folder : folders) {
log.debug("Folder name: " + folder.getName() + " ID: " + folder.getFolderId() + " Parent: " + folder.getParentFolderId() + " Groupid: " + folder.getGroupId());
}
return folders;
}
/**
*
* @param session the ASL Session instance
* @return the userid in the liferay system
*/
public static long getUserId(ASLSession session) {
List<User> users = null;
long userId = 0;
try {
users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
} catch (SystemException e) {
e.printStackTrace();
}
for(User user: users){
if(user.getScreenName().equalsIgnoreCase(session.getUsername())){
userId = user.getUserId();
break;
}
}
return userId;
}
/**
* needed to convert Workflows permission into Lifearay permissions (ActionIDs)
* @param type
* @return
*/
private static String getLRActionIdFromWfPermissionType(PermissionType type) {
switch (type) {
case EDIT_PERMISSIONS:
return "PERMISSIONS";
case VIEW:
return "VIEW";
case UPDATE:
return "UPDATE";
case DELETE:
return "DELETE";
case ADD_DISCUSSION:
return "ADD_DISCUSSION";
case DELETE_DISCUSSION:
return "DELETE_DISCUSSION";
case UPDATE_DISCUSSION:
return "UPDATE_DISCUSSION";
default:
return "";
}
}
}

@ -1,51 +0,0 @@
package org.gcube.portlets.user.reportgenerator.server.servlet;
import java.util.List;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Massimiliano Assante ISTI-CNR
*
*/
public class NotificationsThread implements Runnable {
private static final Logger _log = LoggerFactory.getLogger(NotificationsThread.class);
private static final String WORKSPACE_PORTLET_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl";
private NotificationsManager nm;
private List<String> userIdsToBeNotified;
private WorkspaceItem subjectItem;
private WorkspaceFolder sharedFolder;
public NotificationsThread(ASLSession session, List<String> userIdsToBeNotified, WorkspaceItem item, WorkspaceFolder sharedFolder) {
nm = new ApplicationNotificationsManager(session, WORKSPACE_PORTLET_ID);
this.userIdsToBeNotified = userIdsToBeNotified;
subjectItem = item;
this.sharedFolder = sharedFolder;
}
@Override
public void run() {
for (String userId : userIdsToBeNotified) {
try {
// boolean notifResult = nm.notifyUpdatedItem(userId, subjectItem, sharedFolder);
//_log.trace("Update Notification sent to " + userId + " result="+notifResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
@ -50,8 +49,6 @@ import org.gcube.application.rsg.service.dto.response.ServiceResponseMessage;
import org.gcube.application.rsg.support.builder.exceptions.ReportBuilderException;
import org.gcube.application.rsg.support.builder.impl.ReportManagerReportBuilder;
import org.gcube.application.rsg.support.model.components.impl.CompiledReport;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.homelibary.model.items.type.FolderItemType;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
@ -75,11 +72,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.admin.wfdocslibrary.client.WfDocsLibrary;
import org.gcube.portlets.admin.wfdocslibrary.server.db.MyDerbyStore;
import org.gcube.portlets.admin.wfdocslibrary.server.db.Store;
import org.gcube.portlets.d4sreporting.common.server.ServiceUtil;
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
import org.gcube.portlets.d4sreporting.common.shared.BasicSection;
@ -93,8 +86,6 @@ import org.gcube.portlets.user.reportgenerator.client.ReportConstants;
import org.gcube.portlets.user.reportgenerator.client.ReportService;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.CreateReportLogEntry;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenReportLogEntry;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenWorkflowLogEntry;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.SaveWorkflowLogEntry;
import org.gcube.portlets.user.reportgenerator.shared.RSGAccessPoint;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
@ -109,17 +100,18 @@ import org.gcube.portlets.widgets.exporter.shared.TypeExporter;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.RoleModel;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserModel;
import com.liferay.portal.service.LockLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
@ -156,24 +148,11 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
public static final String TEST_USER = "test.user";
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
/**
* the WF DB Store
*/
private Store store;
//the client for the VME-DB case
private RsgReadClient rsgReadClient;
private RsgWriteClient rsgWriteClient;
//set to true if want to test workflow menu mode
boolean testWorkflow = false;
/**
* Called then servlet is intialized
*/
public void init() {
_log.info("Initializing Servlet ReportServiceImpl... connecting to WF DB");
store = new MyDerbyStore();
}
/**
* the current ASLSession
@ -756,13 +735,6 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
String templateid = (String) d4Session.getAttribute("idreport");
Object workflowid = getASLSession().getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID);
_log.debug(" (templateid != null && workflowid != null) = " + (templateid != null) + " - " + (workflowid != null));
if (workflowid != null) {
getASLSession().setAttribute(WfDocsLibrary.LAST_WORKFLOW_ID, null);
return null;
}
String templateName = "";
_log.debug("TEMPLATE ID==NULL " + (templateid == null));
if (templateid != null) {
@ -1061,13 +1033,6 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
storeReportItemIDInSession(rep.getId());
if (toSaveIn.getType() == WorkspaceItemType.SHARED_FOLDER) {
sendReportUpdateNotification(toSaveIn, rep);
}
AccessLogger log = AccessLogger.getAccessLogger();
CreateReportLogEntry logEntry = new CreateReportLogEntry(model.getTemplateName(), rep.getId());
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
} catch (Exception e) {
e.printStackTrace();
@ -1106,19 +1071,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
return null;
}
/**
* send an update notification to all the user sharing this folder
* @param toSaveIn
* @throws InternalErrorException
*/
private void sendReportUpdateNotification(WorkspaceFolder sharedFolder, WorkspaceItem wsItem) throws InternalErrorException {
if (sharedFolder.getType() == WorkspaceItemType.SHARED_FOLDER) {
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) sharedFolder;
List<String> usersToNotify = wsFolder.getUsers();
Thread thread = new Thread(new NotificationsThread(getASLSession(), usersToNotify, wsItem, sharedFolder));
thread.start();
}
}
/**
* return a sample of the given TS to the client
* @param sTS .
@ -1315,215 +1268,15 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
* @return a SessionInfo bean containing the username the scope andis opening a workflow document or not
*/
public SessionInfo getSessionInfo(String currentHost) {
if (testWorkflow) {
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE, "1");
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME, "TEST REPORT");
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE, true);
return new SessionInfo(getUserBean(), getVreName(), true, true, false, "");
}
boolean isVME = isReportsStoreGatewayAvailable();
String rsgEndpoint = "";
if (getRSGWSAddress() != null)
rsgEndpoint = ((RSGAccessPoint) getRSGWSAddress()).getRestUrl();
return new SessionInfo(getUserBean(), getVreName(), false, false, isVME, rsgEndpoint);
if (getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE) == null) {
_log.debug("WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE is NULL: ");
String rsgEndpoint = "";
if (getRSGWSAddress() != null)
rsgEndpoint = ((RSGAccessPoint) getRSGWSAddress()).getRestUrl();
return new SessionInfo(getUserBean(), getVreName(), false, false, isVME, rsgEndpoint);
}
else {
_log.debug("FOUND WORKFLOW_ID_ATTRIBUTE ***** ");
//String workflowid = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE).toString();
Boolean canEdit = ! (Boolean) getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE);
return new SessionInfo(getUserBean(), getVreName(), true, canEdit, false, "");
}
}
public Model getWorkflowDocumentFromDocumentLibrary() {
ServiceUtil myUtil = new ServiceUtil(getASLSession());
if (testWorkflow) {
FileInputStream fis = null;
ObjectInputStream in = null;
Model toConvert = null;
try {
fis = new FileInputStream("/Users/massi/portal/CURRENT_OPEN.d4st");
in = new ObjectInputStream(fis);
toConvert = (Model) in.readObject();
in.close();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
toConvert.setTemplateName("TEST");
_log.info(" Converting TEST REPORT to Serializable object, model name: \n" + toConvert.getTemplateName());
return toConvert;
}
else {
String workflowid = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE).toString();
Boolean canEdit = ! (Boolean) getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE);
String documentName = getASLSession().getAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME).toString();
_log.info("getWorkflowDocumentFromDocumentLibrary() CALLED ***** ID = " + workflowid + " name:\n " + documentName);
//TODO: check this
//reset the values in session
_log.info("Reset the values in session ... ");
getASLSession().setAttribute(WfDocsLibrary.LAST_WORKFLOW_ID, workflowid);
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_ID_ATTRIBUTE, null);
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_READONLY_ATTRIBUTE, null);
getASLSession().setAttribute(WfDocsLibrary.WORKFLOW_GIVEN_NAME, null);
try {
InputStream inputStream = DocLibraryUtil.getFileEntryAsStream(getASLSession(), workflowid);
String templatePath = myUtil.getTemplateFolder(getVreName(), getUsername()) + "CURRENT_OPEN/";
String pathToFile = templatePath;
File toExtract = writeReportToDisk(inputStream, pathToFile, "Workflodoc-report.zip");
File outputDir = new File( myUtil.getTemplatePath("", getVreName(), getUsername()) );
ZipUtil.unzipArchive(toExtract, outputDir);
toExtract.delete();
FileInputStream fis = null;
ObjectInputStream in = null;
Model toConvert = null;
try {
String path = myUtil.getTemplateFolder(getVreName(), getUsername());
String reportFileName = seekModel(templatePath, UUID.randomUUID().toString()); //random name just to make sure it look for the name
String pathToReport = path + "CURRENT_OPEN/"+reportFileName+".d4st";
_log.trace("WF PathToReport = " + pathToReport);
fis = new FileInputStream(pathToReport);
in = new ObjectInputStream(fis);
toConvert = (Model) in.readObject();
in.close();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
toConvert.setTemplateName(documentName);
_log.debug("Converting fileToRead to Serializable object, model name: \n" + toConvert.getTemplateName());
Model toReturn = (toConvert);
//saves this model as previous one in session
getASLSession().setAttribute(PREVIOUS_REPORT_INSTANCE, toConvert);
AccessLogger log = AccessLogger.getAccessLogger();
OpenWorkflowLogEntry logEntry = new OpenWorkflowLogEntry(toConvert.getTemplateName(), toConvert.getUniqueID(), toConvert.getAuthor());
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
return toReturn;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
/**
* get the report instance from the Basket
* @param repTmp .
* @param pathToFile the directory where to save the file
* @param filename the filename to give to the newly created file
* @return
*/
private File writeReportToDisk(InputStream isData, String pathToFile, String filename) {
try {
File dir = new File(pathToFile);
_log.debug("DIR: " + pathToFile);
if (! dir.exists() )
dir.mkdirs();
File f = new File(pathToFile+filename);
OutputStream out = new FileOutputStream(f);
IOUtils.copy(isData, out);
out.close();
_log.debug("Successfully WROTE ReportTemplate from DL: " + pathToFile);
return f;
}
catch (IOException e){
e.printStackTrace();
return null;
}
}
/**
* update the Workflow Document in session
*/
public void updateWorkflowDocument(Model toSave, boolean update) {
ASLSession session = getASLSession();
ServiceUtil myUtil = new ServiceUtil(session);
String workflowid = session.getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID).toString();
Model model = null;
String documentWorkflowOwnerId = store.getWorkflowById(workflowid).getAuthor();
String documentWorkflowName = store.getWorkflowById(workflowid).getName();
if (update) {
_log.debug("SAVING in WorkflowDocument Library ");
model = (Model) toSave;
_log.debug("Trying to convert dynamic images ... ");
convertDynamicImagesFromHL(model);
boolean result = myUtil.writeModel(model, "CURRENT_OPEN", getVreName(), getUsername());
if (!result) {
_log.error("Could not save report, serializing failed");
}
else {
String templatePath = myUtil.getTemplateFolder(getVreName(), getUsername()) + "CURRENT_OPEN";
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
_log.debug("Trying to zip folder: " + templatePath);
String folderToZip = templatePath;
String outZip = templatePath+"-report.zip";
try {
ZipUtil.zipDir(outZip, folderToZip);
_log.debug("Folder zipped, result: "+ outZip);
InputStream isZip = new BufferedInputStream(new FileInputStream(outZip));
DocLibraryUtil.updateFileIntoDocLibrary(getASLSession(), workflowid, getBytesFromInputStream(isZip));
_log.info("Updated in DOC LIB OK");
store.addWorkflowLogAction(workflowid, getASLSession().getUsername(), "Updated");
//send the notification
NotificationsManager nm = new ApplicationNotificationsManager(session, "org.gcube.admin.portlet.wfdocviewer.server.WorkflowDocServiceImpl");
nm.notifyDocumentWorkflowUpdate(documentWorkflowOwnerId, workflowid, documentWorkflowName);
AccessLogger log = AccessLogger.getAccessLogger();
SaveWorkflowLogEntry logEntry = new SaveWorkflowLogEntry(model.getTemplateName(), model.getUniqueID(), model.getAuthor());
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
}
catch (Exception e) {
_log.error("Could not zip template, serializing failed");
e.printStackTrace();
}
}
} else {
store.addWorkflowLogAction(workflowid, getASLSession().getUsername(), "Viewed");
//send the notification
NotificationsManager nm = new ApplicationNotificationsManager(session, "org.gcube.admin.portlet.wfdocviewer.server.WorkflowDocServiceImpl");
nm.notifyDocumentWorkflowView(documentWorkflowOwnerId, workflowid, documentWorkflowName);
}
//unlocks
unlock(workflowid);
getASLSession().setAttribute("idreport", null);
}
}
/**
*
* @return the info about the current user
@ -1538,17 +1291,17 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
if (isWithinPortal()) {
UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
fullName = user.getFirstName() + " " + user.getLastName();
email = user.getEmailAddress();
UserBean toReturn = new UserBean(username, fullName, thumbnailURL, user.getEmailAddress());
_log.info("Returning USER: " + toReturn);
GCubeUser user = new LiferayUserManager().getUserByUsername(username);
thumbnailURL = user.getUserAvatarURL();
fullName = user.getFullname();
email = user.getEmail();
UserBean toReturn = new UserBean(username, fullName, thumbnailURL, email);
_log.debug("Returning USER: " + toReturn);
return toReturn;
}
else {
UserBean toReturn = new UserBean(getASLSession().getUsername(), fullName, thumbnailURL, email);
_log.info("Returning test USER: " + toReturn);
_log.debug("Returning test USER: " + toReturn);
return toReturn;
}
@ -1564,45 +1317,11 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
try {
IOUtils.copy(is, os);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return os.toByteArray();
}
/**
*
* @param workflowid .
*/
private void unlock(String workflowid) {
DLFileEntry fileEntry;
try {
fileEntry = DocLibraryUtil.getFileEntry(getASLSession(), workflowid);
_log.info("Log action saved, trying ot unlock document ...");
LockLocalServiceUtil.unlock(DLFileEntry.class.getName(), fileEntry.getFileEntryId());
_log.info("UNLOCK OK!");
}
catch (Exception e) {
e.printStackTrace();
}
}
public void renewLock() {
HttpSession httpSes = this.getThreadLocalRequest().getSession();
httpSes.setMaxInactiveInterval(-1); //session won't expire
String workflowid = getASLSession().getAttribute(WfDocsLibrary.LAST_WORKFLOW_ID).toString();
try {
DLFileEntry fileEntry = DocLibraryUtil.getFileEntry(getASLSession(), workflowid);
_log.info("Renewing Lock ...");
long fifteenMin = 900000;
Date currTimePlus15 = new Date(new Date().getTime() + fifteenMin);
LockLocalServiceUtil.getLock(DLFileEntry.class.getName(), fileEntry.getFileEntryId()).setExpirationDate(currTimePlus15);
_log.info("Lock Renewed, expiring: " + currTimePlus15);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public String save(String filePath, String workspaceFolderId, String itemName, TypeExporter type, boolean overwrite) throws SaveReportFileException, SaveReportFileExistException {
try {
@ -1655,7 +1374,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
RSGAccessPoint rsgWsAddr = getRSGWSAddress();
if (rsgReadClient == null) {
rsgReadClient = new RsgReadClient(rsgWsAddr.getRestUrl());
System.out.println("rsgReadClient = new RsgReadClient(rsgWsAddr.getRestUrl()"+rsgWsAddr.getRestUrl());
_log.info("rsgReadClient = new RsgReadClient(rsgWsAddr.getRestUrl()"+rsgWsAddr.getRestUrl());
}
return rsgReadClient;
}
@ -1667,7 +1386,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
try {
rsgWriteClient.secureWithPlainTokenSecurity(rsgWsAddr.getTokenUrl());
System.out.println("rsgWriteClient.secureWithPlainTokenSecurity(rsgWsAddr.getTokenUrl())"+rsgWsAddr.getTokenUrl());
_log.info("rsgWriteClient.secureWithPlainTokenSecurity(rsgWsAddr.getTokenUrl())"+rsgWsAddr.getTokenUrl());
} catch (MalformedURLException e) {
e.printStackTrace();
}
@ -1687,12 +1406,13 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
RoleManager rm = new LiferayRoleManager();
ASLSession session = getASLSession();
try {
User theUser = OrganizationsUtil.validateUser(session.getUsername());
List<RoleModel> roles = rm.listRolesByUserAndGroup(""+session.getGroupId(), ""+theUser.getUserId());
for (RoleModel role : roles) {
_log.info("Role " + role.getRoleName() + " Adding RFMO");
if (role.getRoleName().endsWith("-Editor")) {
String[] splits = role.getRoleName().split("-");
GCubeUser theUser = new LiferayUserManager().getUserByUsername(session.getUsername());
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(session.getScope());
List<GCubeTeam> roles = rm.listTeamsByUserAndGroup(theUser.getUserId(), groupId);
for (GCubeTeam team : roles) {
_log.info("VRE Group " + team.getTeamName() + " Adding RFMO");
if (team.getTeamName().endsWith("-Editor")) {
String[] splits = team.getTeamName().split("-");
toReturn.add(splits[0]);
_log.info("Added grant for RFMO="+splits[0]);
}
@ -1712,10 +1432,11 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
ASLSession session = getASLSession();
try {
User theUser = OrganizationsUtil.validateUser(session.getUsername());
List<RoleModel> roles = rm.listRolesByUserAndGroup(""+session.getGroupId(), ""+theUser.getUserId());
for (RoleModel role : roles)
if (role.getRoleName().equalsIgnoreCase("VRE-Manager")) return true;
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(session.getScope());
GCubeUser theUser = new LiferayUserManager().getUserByUsername(session.getUsername());
List<GCubeRole> roles = rm.listRolesByUserAndGroup(theUser.getUserId(), groupId);
for (GCubeRole role : roles)
if (role.getRoleName().equals(GatewayRolesNames.VRE_MANAGER.getRoleName())) return true;
}
catch (Exception e) {
e.printStackTrace();
@ -1996,6 +1717,8 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
}
RSGAccessPoint rsgAp = new RSGAccessPoint(host+address, iMarineSkrURL, vmeSkrURL, password);
setRSGWSAddress(rsgAp);
new RsgReadClient(rsgAp.getRestUrl());
return true;
}
else return false;

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 5.2.0//EN" "http://www.liferay.com/dtd/liferay-display_5_2_0.dtd">
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN" "http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
<display>
<category name="gCube Applications">

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_5_2_0.dtd">
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app>
<portlet>