387 lines
12 KiB
Java
387 lines
12 KiB
Java
package org.gcube.portlets.user.statisticalalgorithmsimporter.server;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterService;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeReader;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ProjectArchiver;
|
|
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.file.FileUploadMonitor;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.InputData;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.MainCode;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectFolder;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.session.UserInfo;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
/**
|
|
* The server side implementation of the RPC service.
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|
StatAlgoImporterService {
|
|
|
|
private static Logger logger = LoggerFactory
|
|
.getLogger(StatAlgoImporterServiceImpl.class);
|
|
|
|
/**
|
|
*
|
|
* {@inheritDoc}
|
|
*
|
|
*/
|
|
@Override
|
|
public void init() throws ServletException {
|
|
super.init();
|
|
System.out.println("Fix JAXP: jdk.xml.entityExpansionLimit=0");
|
|
System.setProperty("jdk.xml.entityExpansionLimit", "0");
|
|
|
|
System.out.println("initializing StatAlgoImporterService");
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* {@inheritDoc}
|
|
*
|
|
*/
|
|
@Override
|
|
public UserInfo hello() throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
|
|
aslSession.getGroupId(), aslSession.getGroupName(),
|
|
aslSession.getScope(), aslSession.getScopeName(),
|
|
aslSession.getUserEmailAddress(),
|
|
aslSession.getUserFullName());
|
|
logger.debug("UserInfo: " + userInfo);
|
|
return userInfo;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
e.printStackTrace();
|
|
logger.error("Hello(): " + e.getLocalizedMessage(), e);
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* {@inheritDoc}
|
|
*
|
|
*/
|
|
@Override
|
|
public FileUploadMonitor getFileUploadMonitor()
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
if (session == null) {
|
|
throw new StatAlgoImporterServiceException(
|
|
"Error retrieving the session: null");
|
|
}
|
|
|
|
FileUploadMonitor fileUploadMonitor = SessionUtil
|
|
.getFileUploadMonitor(session);
|
|
if (fileUploadMonitor == null) {
|
|
throw new StatAlgoImporterServiceException(
|
|
"Error retrieving the fileUploadMonitor: null");
|
|
}
|
|
|
|
logger.debug("FileUploadMonitor: " + fileUploadMonitor);
|
|
|
|
return fileUploadMonitor;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* {@inheritDoc}
|
|
*
|
|
*/
|
|
@Override
|
|
public ArrayList<CodeData> getCode()
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("getCode()");
|
|
Project projectSession = SessionUtil.getProjectSession(session);
|
|
if (projectSession != null) {
|
|
CodeReader codeFileReader = new CodeReader(projectSession,
|
|
aslSession);
|
|
ArrayList<CodeData> codeList = codeFileReader.getCodeList();
|
|
for (CodeData codeData : codeList) {
|
|
logger.debug("" + codeData.getId() + " "
|
|
+ codeData.getCodeLine());
|
|
}
|
|
return codeList;
|
|
} else {
|
|
return new ArrayList<CodeData>();
|
|
}
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("getCode(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* {@inheritDoc}
|
|
*
|
|
*/
|
|
@Override
|
|
public void createProjectOnWorkspace(ItemDescription newProjectFolder)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
SessionUtil.getAslSession(session);
|
|
logger.debug("createProjectOnWorkspace()");
|
|
ProjectFolder projectFolder = new ProjectFolder(newProjectFolder);
|
|
Project projectSession = new Project(projectFolder);
|
|
SessionUtil.setProjectSession(session, projectSession);
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error(
|
|
"createProjectOnWorkspace(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Project openProjectOnWorkspace(ItemDescription newProjectFolder)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("openProjectOnWorkspace()");
|
|
|
|
Project project = ProjectArchiver.readProject(newProjectFolder,
|
|
aslSession);
|
|
SessionUtil.setProjectSession(session, project);
|
|
|
|
return project;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error(
|
|
"openProjectOnWorkspace(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setMainCode(ItemDescription itemDescription)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
SessionUtil.getAslSession(session);
|
|
logger.debug("SetMainCode()");
|
|
Project project = SessionUtil.getProjectSession(session);
|
|
if (project != null) {
|
|
project.setMainCode(new MainCode(itemDescription));
|
|
SessionUtil.setProjectSession(session, project);
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("setMainCode(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void addResourceToProject(ItemDescription itemDescription)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("addResourceToProject(): " + itemDescription);
|
|
if (itemDescription == null || itemDescription.getId() == null) {
|
|
throw new StatAlgoImporterServiceException(
|
|
"Add resource to project is failed, invalid resource: "
|
|
+ itemDescription);
|
|
}
|
|
|
|
Project project = SessionUtil.getProjectSession(session);
|
|
if (project != null && project.getProjectFolder() != null
|
|
&& project.getProjectFolder().getItemDescription() != null) {
|
|
FilesStorage fileStorage = new FilesStorage();
|
|
fileStorage.copyItemOnFolder(aslSession.getUsername(),
|
|
itemDescription.getId(), project.getProjectFolder()
|
|
.getItemDescription().getId());
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("addResourceToProject(): " + e.getLocalizedMessage(),
|
|
e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void deleteResourceOnProject(ItemDescription itemDescription)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("deleteResourceOnProject(): " + itemDescription);
|
|
if (itemDescription == null || itemDescription.getId() == null) {
|
|
throw new StatAlgoImporterServiceException(
|
|
"Delete resource on project is failed, invalid resource: "
|
|
+ itemDescription);
|
|
}
|
|
|
|
Project project = SessionUtil.getProjectSession(session);
|
|
if (project != null) {
|
|
FilesStorage fileStorage = new FilesStorage();
|
|
fileStorage.deleteItemOnFolder(aslSession.getUsername(),
|
|
itemDescription.getId());
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error(
|
|
"deleteResourceOnProject(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void saveProject(InputData inputData)
|
|
throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("saveProject():" + inputData);
|
|
Project project = SessionUtil.getProjectSession(session);
|
|
if (project != null) {
|
|
project.setInputData(inputData);
|
|
SessionUtil.setProjectSession(session, project);
|
|
ProjectArchiver.archive(project, aslSession);
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("saveProject(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void saveCode(String code) throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
logger.debug("saveCode():" + code);
|
|
Project project = SessionUtil.getProjectSession(session);
|
|
if (project != null) {
|
|
MainCode mainCode = project.getMainCode();
|
|
if (mainCode == null|| mainCode.getItemDescription()==null) {
|
|
throw new StatAlgoImporterServiceException("No main code set!");
|
|
} else {
|
|
FilesStorage filesStorage = new FilesStorage();
|
|
filesStorage.saveItem(aslSession.getUsername(), mainCode
|
|
.getItemDescription().getId(), code);
|
|
}
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("saveCode(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
public void createSoftware(InputData inputData) throws StatAlgoImporterServiceException {
|
|
try {
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
|
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, session);
|
|
projectBuilder.build();
|
|
} else {
|
|
throw new StatAlgoImporterServiceException("No project open!");
|
|
}
|
|
|
|
return;
|
|
} catch (StatAlgoImporterServiceException e) {
|
|
e.printStackTrace();
|
|
throw e;
|
|
} catch (Throwable e) {
|
|
logger.error("createSoftware(): " + e.getLocalizedMessage(), e);
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|