Updated to PortalContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@134737 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-11-24 17:45:59 +00:00
parent 91ad8e8b6c
commit c012e007d1
21 changed files with 440 additions and 331 deletions

25
pom.xml
View File

@ -185,13 +185,8 @@
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
@ -201,6 +196,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>client-context-library</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<!-- Authorization -->
<dependency>
@ -222,14 +223,6 @@
<scope>compile</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
@ -326,7 +319,7 @@
<artifactId>workspace-uploader</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- GitHub Connector -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>

View File

@ -1,13 +1,11 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.maindata.MainDataPanel;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.ribbon.StatAlgoImporterRibbon;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterService;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.ToolsPanel;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
@ -15,8 +13,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
@ -58,13 +54,14 @@ public class StatAlgoImporter implements EntryPoint {
// onModuleLoad2
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loadScope();
//loadScope();
loadMainPanel();
}
});
}
private void loadScope() {
/*private void loadScope() {
ClientScopeHelper.getService().setScope(Location.getHref(),
new AsyncCallback<Boolean>() {
@Override
@ -86,7 +83,7 @@ public class StatAlgoImporter implements EntryPoint {
}
});
}
}*/
private void loadMainPanel() {
StatAlgoImporterResources.INSTANCE.saiStyles().ensureInjected();

View File

@ -21,7 +21,6 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.session.UserInfo;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.shared.EventBus;
@ -74,11 +73,11 @@ public class StatAlgoImporterController {
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
//CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
//CheckSession.showLogoutDialog();
}
/**

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.explorer;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.DeleteItemEvent;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.MainCodeSetEvent;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.ProjectStatusEvent;
@ -177,7 +178,7 @@ public class ExplorerProjectPanel extends ContentPanel {
dnd = new MultipleDNDUpload();
dnd.setParameters(event.getProject().getProjectFolder()
.getFolder().getId(), UPLOAD_TYPE.File);
.getFolder().getId(), UPLOAD_TYPE.File, GCubeClientContext.getCurrentContextId());
dnd.addUniqueContainer(vResourcesExplorerContainer);
WorskpaceUploadNotificationListener workspaceUploaderListener = new WorskpaceUploadNotificationListener() {

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.upload;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.upload.progress.FileUploadProgressBarUpdater;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.upload.progress.FileUploadProgressListener;
@ -12,6 +13,7 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Hidden;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.ProgressBar;
@ -182,9 +184,11 @@ public class CodeUploadPanel extends FormPanel {
parent.addButton(btnUploadCode);
parent.addButton(cancelBtn);
parent.setButtonAlign(BoxLayoutPack.CENTER);
Hidden currGroupId=new Hidden(Constants.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId());
VerticalLayoutContainer vlc = new VerticalLayoutContainer();
vlc.add(currGroupId);
vlc.add(fileUploadFieldLabel, new VerticalLayoutData(1, -1, new Margins(0)));
vlc.add(uploadProgressBar, new VerticalLayoutData(1, -1, new Margins(5,0,0,0)));
uploadProgressBar.setVisible(false);

View File

@ -18,11 +18,11 @@ import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUploadListener;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUtil;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadMonitor;
@ -67,10 +67,9 @@ public class LocalUploadServlet extends HttpServlet {
logger.info("Code Import session id: " + session.getId());
try {
ASLSession aslSession = SessionUtil.getASLSession(session);
String token=SessionUtil.getToken(aslSession);
logger.debug("UserToken: "+token);
ScopeProvider.instance.set(aslSession.getScope().toString());
String scopeGroupId=request.getParameter(Constants.CURR_GROUP_ID);
ServiceCredentials aslSession = SessionUtil.getServiceCredentials(request, scopeGroupId);
ScopeProvider.instance.set(aslSession.getScope());
} catch (StatAlgoImporterServiceException e) {
logger.error(e.getLocalizedMessage());

View File

@ -6,13 +6,13 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server;
import java.util.ArrayList;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
@ -32,56 +32,72 @@ public class SessionUtil {
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession)
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest)
throws StatAlgoImporterServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession aslSession;
if (username == null) {
if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user");
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username);
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("no user found in session!");
throw new StatAlgoImporterSessionExpiredException(
"Session Expired!");
}
} else {
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ aslSession.getScope());
return aslSession;
return getServiceCredentials(httpServletRequest, null);
}
public static String getToken(ASLSession aslSession)
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId)
throws StatAlgoImporterServiceException {
ServiceCredentials sCredentials = null;
String userName = null;
String scope = null;
String token = null;
if (Constants.DEBUG_MODE) {
token = Constants.DEFAULT_TOKEN;
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
if (Constants.DEBUG_MODE) {
logger.info("No credential found in session, use test user!");
userName = Constants.DEFAULT_USER;
scope = Constants.DEFAULT_SCOPE;
token = Constants.DEFAULT_TOKEN;
sCredentials = new ServiceCredentials(userName, scope, token);
} else {
logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration();
if(scopeGroupId!=null&&!scopeGroupId.isEmpty()){
scope = pContext.getCurrentScope(scopeGroupId);
} else {
scope = pContext.getCurrentScope(httpServletRequest);
}
userName = pContext.getCurrentUser(httpServletRequest)
.getUsername();
token = pContext.getCurrentUserToken(httpServletRequest);
String name = pContext.getCurrentUser(httpServletRequest)
.getFirstName();
String lastName = pContext.getCurrentUser(httpServletRequest)
.getLastName();
String fullName = pContext.getCurrentUser(httpServletRequest)
.getFullname();
String userAvatarURL = pContext.getCurrentUser(httpServletRequest)
.getUserAvatarURL();
String email = pContext.getCurrentUser(httpServletRequest)
.getEmail();
String groupId = String.valueOf(pContext
.getCurrentGroupId(httpServletRequest));
String groupName = pContext.getCurrentGroupName(httpServletRequest);
sCredentials = new ServiceCredentials(userName, fullName, name,
lastName, email, scope, groupId, groupName, userAvatarURL, token);
}
logger.info("ServiceCredentials: " + sCredentials);
return sCredentials;
}
//
public static ArrayList<Recipient> getRecipients(
ServletContext servletContest) {

View File

@ -9,7 +9,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.IOUtils;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterService;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation.WPS4RParser;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeReader;
@ -19,6 +18,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recip
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.MainCodeSave;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ProjectArchiver;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
@ -98,16 +98,16 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
@Override
public UserInfo hello() throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(),
aslSession.getUserFullName());
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("hello()");
UserInfo userInfo = new UserInfo(serviceCredentials.getUserName(),
serviceCredentials.getGroupId(),
serviceCredentials.getGroupName(),
serviceCredentials.getScope(),
serviceCredentials.getEmail(),
serviceCredentials.getFullName());
logger.debug("UserInfo: " + userInfo);
logger.debug("UserToken: " + token);
return userInfo;
} catch (StatAlgoImporterServiceException e) {
e.printStackTrace();
@ -125,9 +125,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("restoreUISession(): " + value);
Project project = SessionUtil.getProjectSession(session);
return project;
@ -152,9 +150,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
FileUploadMonitor fileUploadMonitor = SessionUtil
.getFileUploadMonitor(session);
@ -178,14 +174,14 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("getCode()");
Project projectSession = SessionUtil.getProjectSession(session);
if (projectSession != null) {
CodeReader codeFileReader = new CodeReader(projectSession,
aslSession);
serviceCredentials);
ArrayList<CodeData> codeList = codeFileReader.getCodeList();
for (CodeData codeData : codeList) {
logger.debug("" + codeData.getId() + " "
@ -216,12 +212,11 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("createProjectOnWorkspace(): " + newProjectFolder);
if (ProjectArchiver.existProjectInFolder(newProjectFolder,
aslSession)) {
serviceCredentials)) {
throw new StatAlgoImporterServiceException(
"Attention a project is present in this folder, use open or another folder!");
} else {
@ -249,13 +244,12 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("openProjectOnWorkspace()");
Project project = ProjectArchiver.readProject(newProjectFolder,
aslSession);
serviceCredentials);
SessionUtil.setProjectSession(session, project);
return project;
@ -276,16 +270,16 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("SetMainCode(): " + itemDescription);
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
project.setMainCode(new MainCode(itemDescription));
project.setInputData(null);
project.setProjectTarget(null);
WPS4RParser wps4Parser = new WPS4RParser(project, aslSession);
WPS4RParser wps4Parser = new WPS4RParser(project,
serviceCredentials);
project = wps4Parser.parse();
SessionUtil.setProjectSession(session, project);
logger.debug("Project: " + project);
@ -310,9 +304,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("addResourceToProject(): " + itemDescription);
if (itemDescription == null || itemDescription.getId() == null) {
throw new StatAlgoImporterServiceException(
@ -324,7 +317,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
if (project != null && project.getProjectFolder() != null
&& project.getProjectFolder().getFolder() != null) {
FilesStorage fileStorage = new FilesStorage();
fileStorage.copyItemOnFolder(aslSession.getUsername(),
fileStorage.copyItemOnFolder(serviceCredentials.getUserName(),
itemDescription.getId(), project.getProjectFolder()
.getFolder().getId());
} else {
@ -349,9 +342,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("deleteResourceOnProject(): " + itemDescription);
if (itemDescription == null || itemDescription.getId() == null) {
throw new StatAlgoImporterServiceException(
@ -360,10 +353,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
}
Project project = SessionUtil.getProjectSession(session);
checkProjectInfoForDelete(itemDescription, aslSession, session,
project);
checkProjectInfoForDelete(itemDescription, serviceCredentials,
session, project);
FilesStorage fileStorage = new FilesStorage();
fileStorage.deleteItemOnFolder(aslSession.getUsername(),
fileStorage.deleteItemOnFolder(serviceCredentials.getUserName(),
itemDescription.getId());
return project;
@ -380,8 +373,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
}
private void checkProjectInfoForDelete(ItemDescription itemDescription,
ASLSession aslSession, HttpSession session, Project project)
throws StatAlgoImporterSessionExpiredException,
ServiceCredentials serviceCredentials, HttpSession session,
Project project) throws StatAlgoImporterSessionExpiredException,
StatAlgoImporterServiceException {
if (project != null) {
if (project.getMainCode() != null
@ -392,7 +385,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
project.setInputData(null);
project.setProjectTarget(null);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
if (project.getProjectTarget() != null
&& project.getProjectTarget().getFolder() != null
@ -400,7 +393,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
.compareTo(itemDescription.getId()) == 0) {
project.setProjectTarget(null);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
if (project.getProjectTarget() != null
&& project.getProjectTarget().getProjectCompile() != null
@ -411,7 +404,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
.compareTo(itemDescription.getId()) == 0) {
project.getProjectTarget().setProjectCompile(null);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
if (project.getProjectTarget() != null
&& project.getProjectTarget()
@ -423,7 +416,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
.compareTo(itemDescription.getId()) == 0) {
project.getProjectTarget().setProjectDeploy(null);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver
.archive(project, serviceCredentials);
} else {
if (project.getProjectTarget() != null
&& project.getProjectTarget()
@ -438,7 +432,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
project.getProjectTarget().getProjectDeploy()
.setPackageProject(null);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project,
serviceCredentials);
} else {
}
@ -456,15 +451,15 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("saveProject():" + inputData);
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
project.setInputData(inputData);
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
throw new StatAlgoImporterServiceException("No project open!");
}
@ -485,9 +480,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void saveCode(String code) throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("saveCode():" + code);
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
@ -497,7 +492,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
"No main code set!");
} else {
MainCodeSave mainCodeSave = new MainCodeSave();
mainCodeSave.save(aslSession,
mainCodeSave.save(serviceCredentials,
mainCode.getItemDescription(), code, project);
}
} else {
@ -521,9 +516,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("saveCode(): itemDescription" + fileDescription
+ ", code:" + code);
Project project = SessionUtil.getProjectSession(session);
@ -531,12 +525,13 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
&& project.getProjectFolder().getFolder() != null) {
MainCodeSave mainCodeSave = new MainCodeSave();
ItemDescription mainCodeItemDescription = mainCodeSave.saveNew(
aslSession, fileDescription, code, project);
serviceCredentials, fileDescription, code, project);
MainCode mainCode = new MainCode(mainCodeItemDescription);
project.setMainCode(mainCode);
project.setInputData(null);
project.setProjectTarget(null);
WPS4RParser wps4Parser = new WPS4RParser(project, aslSession);
WPS4RParser wps4Parser = new WPS4RParser(project,
serviceCredentials);
project = wps4Parser.parse();
SessionUtil.setProjectSession(session, project);
return project;
@ -560,19 +555,18 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("createSoftware(): " + inputData);
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
project.setInputData(inputData);
SessionUtil.setProjectSession(session, project);
ProjectBuilder projectBuilder = new ProjectBuilder(project,
aslSession);
serviceCredentials);
project = projectBuilder.buildTarget();
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
throw new StatAlgoImporterServiceException("No project open!");
}
@ -593,13 +587,11 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public String getPublicLink(ItemDescription itemDescription)
throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("GetPublicLink(): " + itemDescription);
FilesStorage filesStorage = new FilesStorage();
String link = filesStorage.getPublicLink(aslSession.getUsername(),
String link = filesStorage.getPublicLink(serviceCredentials.getUserName(),
itemDescription.getId());
return link;
@ -617,22 +609,20 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void publishSoftware() throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("PublishSoftware()");
ArrayList<Recipient> recipients = SessionUtil.getRecipients(session
.getServletContext());
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
ProjectBuilder projectBuilder = new ProjectBuilder(project,
aslSession);
serviceCredentials);
project = projectBuilder.buildDeploy();
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
AlgorithmNotification notify = new AlgorithmNotification(
this.getThreadLocalRequest(), token, aslSession,
this.getThreadLocalRequest(), serviceCredentials,
project, recipients);
notify.run();
} else {
@ -656,17 +646,16 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void repackageSoftware() throws StatAlgoImporterServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("RepackageSoftware()");
Project project = SessionUtil.getProjectSession(session);
if (project != null) {
ProjectBuilder projectBuilder = new ProjectBuilder(project,
aslSession);
serviceCredentials);
project = projectBuilder.buildRepackage();
SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession);
ProjectArchiver.archive(project, serviceCredentials);
} else {
throw new StatAlgoImporterServiceException(
"The script was not packaged correctly!");

View File

@ -9,8 +9,8 @@ import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.DataType;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.IOType;
@ -40,11 +40,11 @@ public class WPS4RParser {
.getLogger(WPS4RParser.class);
private Project project;
private ASLSession aslSession;
private ServiceCredentials serviceCredentials;
public WPS4RParser(Project project, ASLSession aslSession) {
public WPS4RParser(Project project, ServiceCredentials serviceCredentials) {
this.project = project;
this.aslSession = aslSession;
this.serviceCredentials = serviceCredentials;
}
public Project parse() throws StatAlgoImporterServiceException {
@ -52,10 +52,10 @@ public class WPS4RParser {
ItemDescription mainCode = project.getMainCode().getItemDescription();
FilesStorage fileStorage = new FilesStorage();
InputStream is = fileStorage.retrieveItemOnWorkspace(
aslSession.getUsername(), mainCode.getId());
serviceCredentials.getUserName(), mainCode.getId());
logger.debug("MainCode InputStream: " + is);
Path tempFile=null;
Path tempFile = null;
try {
tempFile = Files.createTempFile("RCodeToParse", ".R");
Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING);
@ -71,33 +71,34 @@ public class WPS4RParser {
}
logger.debug("" + tempFile);
R_Config config = R_Config.getInstance();
logger.debug("R_Config: " + config);
List<RAnnotation> annotations;
try {
RAnnotationParser parser = new RAnnotationParser(config);
logger.debug("RAnnotations Parser:" + parser);
annotations = parser.parseAnnotationsfromScript(Files.newInputStream(tempFile, StandardOpenOption.READ));
annotations = parser.parseAnnotationsfromScript(Files
.newInputStream(tempFile, StandardOpenOption.READ));
} catch (RAnnotationException e) {
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} catch (Throwable e) {
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
try {
Files.delete(tempFile);
} catch (IOException e) {
e.printStackTrace();
}
logger.debug("RAnnotations: " + annotations);
WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations);
logger.debug("wpsAlgorithmInfo: " + wpsAlgorithmInfo);
if (wpsAlgorithmInfo==null || wpsAlgorithmInfo.getAlgorithmName() == null)
if (wpsAlgorithmInfo == null
|| wpsAlgorithmInfo.getAlgorithmName() == null)
return project;
else
return mapToProject(wpsAlgorithmInfo);
@ -109,8 +110,7 @@ public class WPS4RParser {
if (project == null) {
throw new StatAlgoImporterServiceException("Open project before!");
}
if (project.getInputData() == null) {
ProjectInfo projectInfo = new ProjectInfo(
wpsAlgorithmInfo.getAlgorithmName(),
@ -146,9 +146,10 @@ public class WPS4RParser {
.getStringValue(RAttribute.VERSION));
wpsAlgorithmInfo.setDescription(rAnnotation
.getStringValue(RAttribute.ABSTRACT));
String algorithmName=rAnnotation
.getStringValue(RAttribute.TITLE);
algorithmName=algorithmName.replaceAll("[^A-Za-z0-9]", "_");
String algorithmName = rAnnotation
.getStringValue(RAttribute.TITLE);
algorithmName = algorithmName.replaceAll("[^A-Za-z0-9]",
"_");
wpsAlgorithmInfo.setAlgorithmName(algorithmName);
wpsAlgorithmInfo.setVersion(rAnnotation
.getStringValue(RAttribute.VERSION));

View File

@ -7,8 +7,8 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
@ -28,7 +28,8 @@ public class CodeReader {
private Logger logger = LoggerFactory.getLogger(CodeReader.class);
private ArrayList<CodeData> code;
public CodeReader(Project projectSession, ASLSession aslSession)
public CodeReader(Project projectSession,
ServiceCredentials serviceCredentials)
throws StatAlgoImporterServiceException {
try {
@ -47,7 +48,7 @@ public class CodeReader {
code = new ArrayList<CodeData>();
FilesStorage filesStorage = new FilesStorage();
InputStream is = filesStorage.retrieveItemOnWorkspace(
aslSession.getUsername(), itemId);
serviceCredentials.getUserName(), itemId);
InputStreamReader isr = new InputStreamReader(is);

View File

@ -15,11 +15,11 @@ import java.util.GregorianCalendar;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectCompile;
@ -44,8 +44,7 @@ public class ProjectBuilder {
private static final String STATISTICAL_ALGORITHM_COMPILE_FOLDER_DESCRIPTION = "Project Compile";
private static final String STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME = "Backup";
private static final String STATISTICAL_ALGORITHM_BACKUP_FOLDER_DESCRIPTION = "Project Backup";
private static final String ALGORITHM_MIMETYPE = "text/plain";
private static final String ALGORITHM_DESCRIPTION = "Statistical Algorithm Java Code";
private static final String ALGORITHM_EXTENTION = ".java";
@ -75,14 +74,13 @@ public class ProjectBuilder {
private Project project;
private String backupFolderId;
private ASLSession aslSession;
private ServiceCredentials serviceCredentials;
private Path algorithmJava;
private Path infoTXT;
public ProjectBuilder(Project project, ASLSession aslSession) {
public ProjectBuilder(Project project, ServiceCredentials serviceCredentials) {
this.project = project;
this.aslSession = aslSession;
this.serviceCredentials = serviceCredentials;
}
public Project buildTarget() throws StatAlgoImporterServiceException {
@ -113,7 +111,6 @@ public class ProjectBuilder {
}
public Project buildDeploy() throws StatAlgoImporterServiceException {
checkInfoForDeploy();
copyJarInDeploy();
@ -130,17 +127,14 @@ public class ProjectBuilder {
private void createBackup() throws StatAlgoImporterServiceException {
createBackupOfPackageProject();
}
private void repackageProjectPackage()
throws StatAlgoImporterServiceException {
List<String> idsToExclude = new ArrayList<String>();
idsToExclude.add(backupFolderId);
FilesStorage filesStorage = new FilesStorage();
if (project.getProjectTarget() != null
&& project.getProjectTarget().getFolder() != null
&& project.getProjectTarget().getFolder().getId() != null
@ -149,7 +143,7 @@ public class ProjectBuilder {
}
File projectPackageFile = filesStorage.zipFolder(
aslSession.getUsername(), project.getProjectFolder()
serviceCredentials.getUserName(), project.getProjectFolder()
.getFolder().getId(), idsToExclude);
InputStream inputStream;
@ -163,14 +157,14 @@ public class ProjectBuilder {
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
filesStorage.saveInputStreamInItem(aslSession.getUsername(), project
.getProjectTarget().getProjectDeploy().getPackageProject()
.getId(), inputStream);
filesStorage.saveInputStreamInItem(serviceCredentials.getUserName(),
project.getProjectTarget().getProjectDeploy()
.getPackageProject().getId(), inputStream);
WorkspaceItem packageProject = filesStorage
.retrieveItemInfoOnWorkspace(aslSession.getUsername(), project
.getProjectTarget().getProjectDeploy()
.getPackageProject().getId());
.retrieveItemInfoOnWorkspace(serviceCredentials.getUserName(),
project.getProjectTarget().getProjectDeploy()
.getPackageProject().getId());
ItemDescription packageProjectItemDescription;
try {
@ -205,9 +199,9 @@ public class ProjectBuilder {
.getPackageProject().getId() != null
&& !project.getProjectTarget().getProjectDeploy()
.getPackageProject().getId().isEmpty()) {
createBackupFolder();
FilesStorage filesStorage = new FilesStorage();
GregorianCalendar now = new GregorianCalendar();
@ -218,9 +212,11 @@ public class ProjectBuilder {
+ sdf.format(now.getTime())
+ PROJECT_PACKAGE_EXTENTION;
filesStorage.copyItemOnFolderWithNewName(aslSession.getUsername(),
project.getProjectTarget().getProjectDeploy()
.getPackageProject().getId(), backupFolderId, packageProjectNewName);
filesStorage.copyItemOnFolderWithNewName(
serviceCredentials.getUserName(), project
.getProjectTarget().getProjectDeploy()
.getPackageProject().getId(), backupFolderId,
packageProjectNewName);
}
}
@ -232,14 +228,13 @@ public class ProjectBuilder {
.getId() != null
&& !project.getProjectTarget().getProjectDeploy().getCodeJar()
.getId().isEmpty()) {
filesStorage
.deleteItemOnFolder(aslSession.getUsername(), project
.getProjectTarget().getProjectDeploy().getCodeJar()
filesStorage.deleteItemOnFolder(serviceCredentials.getUserName(),
project.getProjectTarget().getProjectDeploy().getCodeJar()
.getId());
}
WorkspaceItem deployableCodeJarItem = filesStorage.copyItemOnFolder(
aslSession.getUsername(), project.getProjectTarget()
serviceCredentials.getUserName(), project.getProjectTarget()
.getProjectCompile().getCodeJar().getId(), project
.getProjectTarget().getProjectDeploy().getFolder()
.getId());
@ -369,12 +364,12 @@ public class ProjectBuilder {
private void createDeployFolder() throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
filesStorage.deleteFolder(aslSession.getUsername(), project
filesStorage.deleteFolder(serviceCredentials.getUserName(), project
.getProjectTarget().getFolder().getId(),
STATISTICAL_ALGORITHM_DEPLOY_FOLDER_NAME);
WorkspaceFolder deployFolder = filesStorage.createFolder(
aslSession.getUsername(), project.getProjectTarget()
serviceCredentials.getUserName(), project.getProjectTarget()
.getFolder().getId(),
STATISTICAL_ALGORITHM_DEPLOY_FOLDER_NAME,
STATISTICAL_ALGORITHM_DEPLOY_FOLDER_DESCRIPTION);
@ -464,10 +459,9 @@ public class ProjectBuilder {
private void createProjectPackage() throws StatAlgoImporterServiceException {
List<String> idsToExclude = new ArrayList<String>();
idsToExclude.add(backupFolderId);
FilesStorage filesStorage = new FilesStorage();
if (project.getProjectTarget() != null
&& project.getProjectTarget().getFolder() != null
&& project.getProjectTarget().getFolder().getId() != null
@ -476,7 +470,7 @@ public class ProjectBuilder {
}
File projectPackageFile = filesStorage.zipFolder(
aslSession.getUsername(), project.getProjectFolder()
serviceCredentials.getUserName(), project.getProjectFolder()
.getFolder().getId(), idsToExclude);
InputStream inputStream;
@ -493,8 +487,9 @@ public class ProjectBuilder {
WorkspaceItem projectPackageItem;
projectPackageItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(), inputStream, project.getInputData()
.getProjectInfo().getAlgorithmNameToClassName()
serviceCredentials.getUserName(), inputStream, project
.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ PROJECT_PACKAGE_EXTENTION,
PROJECT_PACKAGE_DESCRIPTION, PROJECT_PACKAGE_MIMETYPE, project
.getProjectTarget().getProjectDeploy().getFolder()
@ -521,12 +516,12 @@ public class ProjectBuilder {
private void createTargetFolder() throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
filesStorage.deleteFolder(aslSession.getUsername(), project
filesStorage.deleteFolder(serviceCredentials.getUserName(), project
.getProjectFolder().getFolder().getId(),
STATISTICAL_ALGORITHM_TARGET_FOLDER_NAME);
WorkspaceFolder targetFolder = filesStorage.createFolder(
aslSession.getUsername(), project.getProjectFolder()
serviceCredentials.getUserName(), project.getProjectFolder()
.getFolder().getId(),
STATISTICAL_ALGORITHM_TARGET_FOLDER_NAME,
STATISTICAL_ALGORITHM_TARGET_FOLDER_DESCRIPTION);
@ -551,12 +546,12 @@ public class ProjectBuilder {
private void createCompileFolder() throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
filesStorage.deleteFolder(aslSession.getUsername(), project
filesStorage.deleteFolder(serviceCredentials.getUserName(), project
.getProjectTarget().getFolder().getId(),
STATISTICAL_ALGORITHM_COMPILE_FOLDER_NAME);
WorkspaceFolder compileFolder = filesStorage.createFolder(
aslSession.getUsername(), project.getProjectTarget()
serviceCredentials.getUserName(), project.getProjectTarget()
.getFolder().getId(),
STATISTICAL_ALGORITHM_COMPILE_FOLDER_NAME,
STATISTICAL_ALGORITHM_COMPILE_FOLDER_DESCRIPTION);
@ -581,41 +576,44 @@ public class ProjectBuilder {
private void createBackupFolder() throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
WorkspaceItem backupFolder=filesStorage.find(aslSession.getUsername(), project
.getProjectFolder().getFolder().getId(), STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME);
if(backupFolder==null){
WorkspaceItem backupFolder = filesStorage.find(
serviceCredentials.getUserName(), project.getProjectFolder()
.getFolder().getId(),
STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME);
if (backupFolder == null) {
WorkspaceFolder newBackupFolder = filesStorage.createFolder(
aslSession.getUsername(), project.getProjectFolder()
.getFolder().getId(),
serviceCredentials.getUserName(), project
.getProjectFolder().getFolder().getId(),
STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME,
STATISTICAL_ALGORITHM_BACKUP_FOLDER_DESCRIPTION);
logger.debug("BackupFolder:" + backupFolder);
try {
backupFolderId=newBackupFolder.getId();
backupFolderId = newBackupFolder.getId();
} catch (InternalErrorException e) {
logger.error("Error retrieving Backup Folder Id: "+e.getLocalizedMessage());
logger.error("Error retrieving Backup Folder Id: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new StatAlgoImporterServiceException("Error retrieving Backup Folder Id",e);
throw new StatAlgoImporterServiceException(
"Error retrieving Backup Folder Id", e);
}
} else {
try {
backupFolderId=backupFolder.getId();
backupFolderId = backupFolder.getId();
} catch (InternalErrorException e) {
logger.error("Error retrieving Backup Folder Id: "+e.getLocalizedMessage());
logger.error("Error retrieving Backup Folder Id: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new StatAlgoImporterServiceException("Error retrieving Backup Folder Id",e);
throw new StatAlgoImporterServiceException(
"Error retrieving Backup Folder Id", e);
}
}
}
private void createAlgorithm() throws StatAlgoImporterServiceException {
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
algorithmJava = algorithmGenerator.createAlgorithm();
@ -624,11 +622,12 @@ public class ProjectBuilder {
WorkspaceItem algorithmItem;
try {
algorithmItem = filesStorage.createItemOnWorkspace(aslSession
.getUsername(), Files.newInputStream(algorithmJava,
StandardOpenOption.READ), project.getInputData()
.getProjectInfo().getAlgorithmNameToClassName()
+ ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION,
algorithmItem = filesStorage.createItemOnWorkspace(
serviceCredentials.getUserName(), Files.newInputStream(
algorithmJava, StandardOpenOption.READ), project
.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()
+ ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION,
ALGORITHM_MIMETYPE, project.getProjectTarget()
.getProjectCompile().getFolder().getId());
} catch (IOException e) {
@ -669,7 +668,7 @@ public class ProjectBuilder {
try {
infoItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(),
serviceCredentials.getUserName(),
Files.newInputStream(infoTXT, StandardOpenOption.READ),
INFO_NAME + INFO_EXTENTION, INFO_DESCRIPTION,
INFO_MIMETYPE, project.getProjectTarget()
@ -801,7 +800,7 @@ public class ProjectBuilder {
try {
codeJarItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(),
serviceCredentials.getUserName(),
Files.newInputStream(codeJar, StandardOpenOption.READ),
project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()

View File

@ -11,7 +11,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,8 +45,8 @@ public class StatAlgoImporterPortlet extends GenericPortlet {
logger.trace("Loading from JSP: "+VIEW_JSP);
logger.trace("setting context using ScopeHelper");
ScopeHelper.setContext(request);
//logger.trace("setting context using ScopeHelper");
//ScopeHelper.setContext(request);
logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);

View File

@ -5,7 +5,6 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
@ -17,6 +16,7 @@ import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,16 +32,16 @@ public class AlgorithmNotification extends Thread {
private static Logger logger = LoggerFactory
.getLogger(AlgorithmNotification.class);
private HttpServletRequest httpServletRequest;
private ASLSession aslSession;
private ServiceCredentials serviceCredentials;
// private NotificationType notificationType;
private Project project;
private ArrayList<Recipient> recipients;
public AlgorithmNotification(HttpServletRequest httpServletRequest,
String token, ASLSession aslSession, Project project,
ServiceCredentials serviceCredentials, Project project,
ArrayList<Recipient> recipients) {
this.aslSession = aslSession;
this.serviceCredentials = serviceCredentials;
this.project = project;
this.recipients = recipients;
this.httpServletRequest = httpServletRequest;
@ -53,12 +53,10 @@ public class AlgorithmNotification extends Thread {
algorithmPublicationEmail();
}
private void algorithmPublicationEmail() {
try {
Workspace workspace = HomeLibrary.getUserWorkspace(aslSession
.getUsername());
Workspace workspace = HomeLibrary
.getUserWorkspace(serviceCredentials.getUserName());
List<String> recipientIds = retrieveListAddressee();
@ -66,7 +64,7 @@ public class AlgorithmNotification extends Thread {
String subject = "[SAI] New software publication requested";
String body = "The user "
+ aslSession.getUserFullName()
+ serviceCredentials.getFullName()
+ "\n\n has requested to publish the algorithm "
+ project.getInputData().getProjectInfo()
.getAlgorithmName()
@ -86,10 +84,12 @@ public class AlgorithmNotification extends Thread {
SocialNetworkingSite site = new SocialNetworkingSite(
httpServletRequest);
SocialNetworkingUser user = new SocialNetworkingUser(
aslSession.getUsername(), aslSession.getUserEmailAddress(),
aslSession.getUserFullName(), aslSession.getUserAvatarId());
serviceCredentials.getUserName(),
serviceCredentials.getEmail(),
serviceCredentials.getFullName(),
serviceCredentials.getUserAvatarURL());
NotificationsManager nm = new ApplicationNotificationsManager(site,
aslSession.getScope(), user);
serviceCredentials.getScope(), user);
Thread thread = new Thread(new MessageNotificationsThread(
recipients, messageId, subject, body, nm));

View File

@ -5,9 +5,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
@ -33,33 +33,33 @@ public class MainCodeSave {
/**
*
* @param aslSession
* @param serviceCredentials
* @param file
* @param code
* @param project
* @throws StatAlgoImporterServiceException
*/
public void save(ASLSession aslSession, ItemDescription file,
public void save(ServiceCredentials serviceCredentials, ItemDescription file,
String code, Project project) throws StatAlgoImporterServiceException{
FilesStorage filesStorage = new FilesStorage();
filesStorage.saveStringInItem(aslSession.getUsername(), file.getId(), code);
filesStorage.saveStringInItem(serviceCredentials.getUserName(), file.getId(), code);
}
/**
*
* @param aslSession
* @param serviceCredentials
* @param file description of destination file
* @param code code to insert in the file
* @param project
* @return ItemDescription
* @throws StatAlgoImporterServiceException
*/
public ItemDescription saveNew(ASLSession aslSession, ItemDescription file,
public ItemDescription saveNew(ServiceCredentials serviceCredentials, ItemDescription file,
String code, Project project)
throws StatAlgoImporterServiceException {
Path tempFile = createTempFile(file, code);
ItemDescription mainCode = saveInWorkspace(tempFile, aslSession, file,
ItemDescription mainCode = saveInWorkspace(tempFile, serviceCredentials, file,
project);
return mainCode;
}
@ -84,14 +84,14 @@ public class MainCodeSave {
}
private ItemDescription saveInWorkspace(Path tempFile,
ASLSession aslSession, ItemDescription file, Project project)
ServiceCredentials serviceCredentials, ItemDescription file, Project project)
throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
WorkspaceItem mainCodeItem;
try {
mainCodeItem = filesStorage.createItemOnWorkspace(
aslSession.getUsername(),
serviceCredentials.getUserName(),
Files.newInputStream(tempFile, StandardOpenOption.READ),
file.getName(), ALGORITHM_DESCRIPTION, ALGORITHM_MIMETYPE,
project.getProjectFolder().getFolder().getId());

View File

@ -6,9 +6,9 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.MainCode;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
@ -28,7 +28,7 @@ public class ProjectArchiver {
public static final Logger logger = LoggerFactory
.getLogger(ProjectArchiver.class);
public static void archive(Project project, ASLSession aslSession)
public static void archive(Project project, ServiceCredentials serviceCredentials)
throws StatAlgoImporterServiceException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@ -40,33 +40,33 @@ public class ProjectArchiver {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
byteArrayOutputStream.toByteArray());
FilesStorage filesStorage = new FilesStorage();
filesStorage.saveStatisticalAlgorithmProject(aslSession.getUsername(),
filesStorage.saveStatisticalAlgorithmProject(serviceCredentials.getUserName(),
byteArrayInputStream, project.getProjectFolder()
.getFolder().getId());
}
public static boolean existProjectInFolder(
ItemDescription newProjectFolder, ASLSession aslSession)
ItemDescription newProjectFolder, ServiceCredentials serviceCredentials)
throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
return filesStorage.existProjectItemOnWorkspace(
aslSession.getUsername(), newProjectFolder.getId());
serviceCredentials.getUserName(), newProjectFolder.getId());
}
public static Project readProject(ItemDescription newProjectFolder,
ASLSession aslSession) throws StatAlgoImporterServiceException {
ServiceCredentials serviceCredentials) throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage();
InputStream inputStream = filesStorage.retrieveProjectItemOnWorkspace(
aslSession.getUsername(), newProjectFolder.getId());
serviceCredentials.getUserName(), newProjectFolder.getId());
XMLDecoder xmlDecoder = new XMLDecoder(inputStream);
Project project = (Project) xmlDecoder.readObject();
xmlDecoder.close();
WorkspaceItem projectFolderItem = filesStorage
.retrieveItemInfoOnWorkspace(aslSession.getUsername(),
.retrieveItemInfoOnWorkspace(serviceCredentials.getUserName(),
newProjectFolder.getId());
try {
newProjectFolder.setId(projectFolderItem.getId());
@ -89,13 +89,13 @@ public class ProjectArchiver {
} else {
project.setProjectFolder(new ProjectFolder(newProjectFolder));
archive(project, aslSession);
archive(project, serviceCredentials);
}
if (project != null && project.getMainCode() != null
&& project.getMainCode().getItemDescription() != null) {
WorkspaceItem mainCodeItem = filesStorage
.retrieveItemInfoOnWorkspace(aslSession.getUsername(),
.retrieveItemInfoOnWorkspace(serviceCredentials.getUserName(),
project.getMainCode().getItemDescription().getId());
ItemDescription newMainCodeItemDescription;
try {
@ -114,12 +114,12 @@ public class ProjectArchiver {
.getItemDescription())) {
} else {
project.setMainCode(new MainCode(newMainCodeItemDescription));
archive(project, aslSession);
archive(project, serviceCredentials);
}
} else {
project.setProjectFolder(new ProjectFolder(newProjectFolder));
archive(project, aslSession);
archive(project, serviceCredentials);
}
return project;

View File

@ -0,0 +1,141 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.util;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ServiceCredentials implements Serializable {
private static final long serialVersionUID = 3560918948310315680L;
private String userName;
private String fullName;
private String name;
private String lastName;
private String email;
private String scope;
private String groupId;
private String groupName;
private String userAvatarURL;
private String token;
public ServiceCredentials() {
super();
}
public ServiceCredentials(String userName, String scope, String token) {
super();
this.userName = userName;
this.scope = scope;
this.token = token;
}
public ServiceCredentials(String userName, String fullName, String name,
String lastName, String email, String scope, String groupId,
String groupName, String userAvatarURL, String token) {
super();
this.userName = userName;
this.fullName = fullName;
this.name = name;
this.lastName = lastName;
this.email = email;
this.scope = scope;
this.groupId = groupId;
this.groupName = groupName;
this.userAvatarURL = userAvatarURL;
this.token = token;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getUserAvatarURL() {
return userAvatarURL;
}
public void setUserAvatarURL(String userAvatarURL) {
this.userAvatarURL = userAvatarURL;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@Override
public String toString() {
return "ServiceCredentials [userName=" + userName + ", fullName="
+ fullName + ", name=" + name + ", lastName=" + lastName
+ ", email=" + email + ", scope=" + scope + ", groupId="
+ groupId + ", groupName=" + groupName + ", userAvatarURL="
+ userAvatarURL + ", token=" + token + "]";
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.shared;
/**
*
* @author giancarlo email: <a
@ -24,5 +25,7 @@ public class Constants {
public static final String FILE_UPLOADED_FIELD = "FileUploadedField";
public static final String STATISTICAL_ALGORITHMS_IMPORTER_JAR_PUBLIC_LINK = "JarPublicLink";
public static final String RECIPIENTS = "Recipients";
public static final String CURR_GROUP_ID="CURR_GROUP_ID";
}

View File

@ -4,8 +4,8 @@ import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UserInfo implements Serializable {
@ -13,10 +13,9 @@ public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L;
private String username;
private long groupId;
private String groupId;
private String groupName;
private String scope;
private String scopeName;
private String userEmailAddress;
private String userFullName;
@ -34,15 +33,13 @@ public class UserInfo implements Serializable {
* @param userEmailAddress
* @param userFullName
*/
public UserInfo(String username, long groupId, String groupName,
String scope, String scopeName, String userEmailAddress,
String userFullName) {
public UserInfo(String username, String groupId, String groupName,
String scope, String userEmailAddress, String userFullName) {
super();
this.username = username;
this.groupId = groupId;
this.groupName = groupName;
this.scope = scope;
this.scopeName = scopeName;
this.userEmailAddress = userEmailAddress;
this.userFullName = userFullName;
}
@ -55,11 +52,11 @@ public class UserInfo implements Serializable {
this.username = username;
}
public long getGroupId() {
public String getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@ -79,14 +76,6 @@ public class UserInfo implements Serializable {
this.scope = scope;
}
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public String getUserEmailAddress() {
return userEmailAddress;
}
@ -107,8 +96,8 @@ public class UserInfo implements Serializable {
public String toString() {
return "UserInfo [username=" + username + ", groupId=" + groupId
+ ", groupName=" + groupName + ", scope=" + scope
+ ", scopeName=" + scopeName + ", userEmailAddress="
+ userEmailAddress + ", userFullName=" + userFullName + "]";
+ ", userEmailAddress=" + userEmailAddress + ", userFullName="
+ userFullName + "]";
}
}

View File

@ -26,7 +26,7 @@
<set-configuration-property name="CssResource.style"
value="pretty" />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />
<inherits name='edu.ycp.cs.dh.acegwt.acegwt' />
<!-- inherits WorkspaceExplorer widget -->

View File

@ -26,7 +26,7 @@
<set-configuration-property name="CssResource.style"
value="pretty" />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />
<inherits name='edu.ycp.cs.dh.acegwt.acegwt' />
<!-- inherits WorkspaceExplorer widget -->

View File

@ -12,18 +12,6 @@
</servlet>
<!-- Check Session Expired -->
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<!-- Scope Helper -->
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<!-- StatisticalAlgoImporterService -->
<servlet>
<servlet-name>StatAlgoImporterService</servlet-name>
@ -68,11 +56,6 @@
<url-pattern>/statalgoimporter/junithost/*</url-pattern>
</servlet-mapping>
<!-- Check Session Expired -->
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/statalgoimporter/checksession</url-pattern>
</servlet-mapping>
<!--StatAlgoImporterService -->
<servlet-mapping>
@ -111,11 +94,6 @@
<url-pattern>/statalgoimporter/githubconnectorservice</url-pattern>
</servlet-mapping>
<!-- Scope Helper -->
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/statalgoimporter/scopeService</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>