1452: Implement a GUI for StatMan Algorithms Importer
Task-Url: https://support.d4science.org/issues/1452 Updated Code Generator git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122186 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3cdac18166
commit
5597655c7e
|
@ -64,4 +64,6 @@ public interface StatAlgoImporterService extends RemoteService {
|
|||
|
||||
public void saveCode(String code) throws StatAlgoImporterServiceException;
|
||||
|
||||
public void createAlgorithm() throws StatAlgoImporterServiceException;
|
||||
|
||||
}
|
||||
|
|
|
@ -55,4 +55,6 @@ public interface StatAlgoImporterServiceAsync {
|
|||
|
||||
void saveCode(String code, AsyncCallback<Void> asyncCallback);
|
||||
|
||||
void createAlgorithm(AsyncCallback<Void> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
@ -351,5 +352,33 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createAlgorithm() throws StatAlgoImporterServiceException {
|
||||
try {
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||
logger.debug("createAlgorithm()");
|
||||
Project project = SessionUtil.getProjectSession(session);
|
||||
if (project != null) {
|
||||
ProjectBuilder projectBuilder=new ProjectBuilder(project, aslSession);
|
||||
projectBuilder.build();
|
||||
} else {
|
||||
throw new StatAlgoImporterServiceException("No project open!");
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (StatAlgoImporterServiceException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
logger.error("createAlgorithm(): " + e.getLocalizedMessage(), e);
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ public class AlgorithmGenerator {
|
|||
return "AlgorithmGenerator [project=" + project + "]";
|
||||
}
|
||||
|
||||
public Path createAlgorithm() throws StatAlgoImporterServiceException,
|
||||
IOException {
|
||||
public Path createAlgorithm() throws StatAlgoImporterServiceException {
|
||||
|
||||
try {
|
||||
Path tempFile = Files.createTempFile(project.getClassName(),
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator;
|
||||
|
||||
import java.io.IOException;
|
||||
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.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ProjectBuilder {
|
||||
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";
|
||||
|
||||
public static final Logger logger = LoggerFactory
|
||||
.getLogger(ProjectBuilder.class);
|
||||
|
||||
private Project project;
|
||||
private ASLSession aslSession;
|
||||
|
||||
public ProjectBuilder(Project project, ASLSession aslSession) {
|
||||
this.project = project;
|
||||
this.aslSession = aslSession;
|
||||
}
|
||||
|
||||
public void build() throws StatAlgoImporterServiceException {
|
||||
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
||||
Path algorithm = algorithmGenerator.createAlgorithm();
|
||||
|
||||
FilesStorage filesStorage = new FilesStorage();
|
||||
try {
|
||||
filesStorage.saveItemOnWorkspace(aslSession.getUsername(),
|
||||
Files.newInputStream(algorithm, StandardOpenOption.READ),
|
||||
project.getClassName() + ALGORITHM_EXTENTION,
|
||||
ALGORITHM_DESCRIPTION, ALGORITHM_MIMETYPE, project
|
||||
.getProjectFolder().getItemDescription().getId());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||
e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -80,7 +80,7 @@ public class FilesStorage {
|
|||
|
||||
}
|
||||
|
||||
public void saveItemOnFolder(String user, InputStream inputStream,
|
||||
public void saveStatisticalAlgorithmProject(String user, InputStream inputStream,
|
||||
String folderId) throws StatAlgoImporterServiceException {
|
||||
Workspace ws;
|
||||
try {
|
||||
|
@ -116,6 +116,44 @@ public class FilesStorage {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public void saveItemOnWorkspace(String user, InputStream inputStream, String name,
|
||||
String description, String mimeType,
|
||||
String folderId) throws StatAlgoImporterServiceException {
|
||||
Workspace ws;
|
||||
try {
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
|
||||
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
||||
if (!workSpaceItem.isFolder()) {
|
||||
throw new StatAlgoImporterServiceException(
|
||||
"Destination is not a folder!");
|
||||
}
|
||||
|
||||
WorkspaceItem projectItem = ws.find(
|
||||
name, folderId);
|
||||
|
||||
if (projectItem == null) {
|
||||
ws.createExternalFile(name,
|
||||
description,
|
||||
mimeType, inputStream,
|
||||
folderId);
|
||||
} else {
|
||||
ws.updateItem(projectItem.getId(), inputStream);
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (WrongItemTypeException | WorkspaceFolderNotFoundException
|
||||
| InternalErrorException | HomeNotFoundException
|
||||
| ItemNotFoundException | InsufficientPrivilegesException
|
||||
| ItemAlreadyExistException | WrongDestinationException e) {
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ProjectArchiver {
|
|||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
|
||||
byteArrayOutputStream.toByteArray());
|
||||
FilesStorage filesStorage = new FilesStorage();
|
||||
filesStorage.saveItemOnFolder(aslSession.getUsername(),
|
||||
filesStorage.saveStatisticalAlgorithmProject(aslSession.getUsername(),
|
||||
byteArrayInputStream, project.getProjectFolder()
|
||||
.getItemDescription().getId());
|
||||
|
||||
|
|
Loading…
Reference in New Issue