diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/StatAlgoImporterResources.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/StatAlgoImporterResources.java index 0efd501..33f5db0 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/StatAlgoImporterResources.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/StatAlgoImporterResources.java @@ -29,7 +29,13 @@ public interface StatAlgoImporterResources extends ClientBundle { @Source("download_32.png") ImageResource download32(); + + @Source("download_24.png") + ImageResource download24(); + @Source("download_16.png") + ImageResource download16(); + @Source("upload_32.png") ImageResource upload32(); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png new file mode 100644 index 0000000..9f2fb7d Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png differ diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png new file mode 100644 index 0000000..7ae805b Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png differ diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterService.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterService.java index ec2ca2b..7f7e6c0 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterService.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterService.java @@ -66,4 +66,6 @@ public interface StatAlgoImporterService extends RemoteService { public void createSoftware(InputData inputData) throws StatAlgoImporterServiceException; + public String getUriFromResolver(ItemDescription itemDescription) throws StatAlgoImporterServiceException; + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterServiceAsync.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterServiceAsync.java index a60cbe1..bf0fc1c 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/rpc/StatAlgoImporterServiceAsync.java @@ -57,4 +57,7 @@ public interface StatAlgoImporterServiceAsync { void createSoftware(InputData inputData, AsyncCallback callback); + void getUriFromResolver(ItemDescription itemDescription, + AsyncCallback asyncCallback); + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/explorer/ExplorerProjectPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/explorer/ExplorerProjectPanel.java index 2195533..e06bb6a 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/explorer/ExplorerProjectPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/explorer/ExplorerProjectPanel.java @@ -3,8 +3,12 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.explo 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; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync; +import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType; import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE; @@ -16,6 +20,8 @@ import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.event.shared.EventBus; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; @@ -44,9 +50,10 @@ public class ExplorerProjectPanel extends ContentPanel { private EventBus eventBus; private Item selectedItem; - private TextButton btnSetMain; private MultipleDNDUpload dnd; private WorkspaceResourcesExplorerPanel wsResourcesExplorerPanel; + private TextButton btnSetMain; + private TextButton btnOpen; private TextButton btnDelete; private TextButton btnReload; @@ -82,12 +89,10 @@ public class ExplorerProjectPanel extends ContentPanel { setResize(true); setAnimCollapse(false); setHeadingText("Project Explorer"); - } private void bindToEvents() { - eventBus.addHandler(ProjectStatusEvent.TYPE, new ProjectStatusEvent.ProjectStatusEventHandler() { @@ -100,7 +105,6 @@ public class ExplorerProjectPanel extends ContentPanel { }); } - private void manageProjectStatusEvents(ProjectStatusEvent event) { Log.debug("InputVariablePanel recieved event ProjectStatus: " + event.toString()); @@ -111,7 +115,7 @@ public class ExplorerProjectPanel extends ContentPanel { case UPDATE: case SAVE: case ADD_RESOURCE: - case DELETE_RESOURCE: + case DELETE_RESOURCE: create(event); break; case MAIN_CODE_SET: @@ -127,7 +131,8 @@ public class ExplorerProjectPanel extends ContentPanel { try { wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel( - event.getProject().getProjectFolder().getItemDescription().getId(), false); + event.getProject().getProjectFolder().getItemDescription() + .getId(), false); WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { @Override @@ -166,7 +171,8 @@ public class ExplorerProjectPanel extends ContentPanel { // DND dnd = new MultipleDNDUpload(); - dnd.setParameters(event.getProject().getProjectFolder().getItemDescription().getId(), UPLOAD_TYPE.File); + dnd.setParameters(event.getProject().getProjectFolder() + .getItemDescription().getId(), UPLOAD_TYPE.File); dnd.addUniqueContainer(vResourcesExplorerContainer); WorskpaceUploadNotificationListener workspaceUploaderListener = new WorskpaceUploadNotificationListener() { @@ -218,7 +224,21 @@ public class ExplorerProjectPanel extends ContentPanel { } }); - + + btnOpen = new TextButton("Open"); + btnOpen.setIcon(StatAlgoImporterResources.INSTANCE.download16()); + btnOpen.setScale(ButtonScale.SMALL); + btnOpen.setIconAlign(IconAlign.LEFT); + btnOpen.setToolTip("Open"); + btnOpen.addSelectHandler(new SelectHandler() { + + @Override + public void onSelect(SelectEvent event) { + openFile(); + } + + }); + btnDelete = new TextButton("Delete"); btnDelete.setIcon(StatAlgoImporterResources.INSTANCE.delete16()); btnDelete.setScale(ButtonScale.SMALL); @@ -231,10 +251,8 @@ public class ExplorerProjectPanel extends ContentPanel { deleteItem(event); } - - }); - + btnReload = new TextButton("Reload"); btnReload.setIcon(StatAlgoImporterResources.INSTANCE.reload16()); btnReload.setScale(ButtonScale.SMALL); @@ -247,18 +265,14 @@ public class ExplorerProjectPanel extends ContentPanel { reloadWSResourceExplorerPanel(); } - - }); - - - ToolBar toolBar = new ToolBar(); toolBar.add(btnSetMain, new BoxLayoutData(new Margins(0))); - toolBar.add(btnReload, new BoxLayoutData(new Margins(0))); + toolBar.add(btnOpen, new BoxLayoutData(new Margins(0))); toolBar.add(btnDelete, new BoxLayoutData(new Margins(0))); - + toolBar.add(btnReload, new BoxLayoutData(new Margins(0))); + VerticalLayoutContainer v = new VerticalLayoutContainer(); v.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0))); @@ -273,10 +287,10 @@ public class ExplorerProjectPanel extends ContentPanel { } protected void reloadWSResourceExplorerPanel() { - if(wsResourcesExplorerPanel!=null){ + if (wsResourcesExplorerPanel != null) { wsResourcesExplorerPanel.refreshRootFolderView(); } - + } private void setMainCode(SelectEvent event) { @@ -289,7 +303,7 @@ public class ExplorerProjectPanel extends ContentPanel { "Select a valid file to be used as main!"); } } - + private void deleteItem(SelectEvent event) { final ConfirmMessageBox mb = new ConfirmMessageBox("Delete", "Would you like to delete this resource?"); @@ -303,7 +317,8 @@ public class ExplorerProjectPanel extends ContentPanel { case YES: ItemDescription itemDescription = new ItemDescription( selectedItem.getId(), selectedItem.getName(), - selectedItem.getOwner(), selectedItem.getPath(), selectedItem.getType().name()); + selectedItem.getOwner(), selectedItem.getPath(), + selectedItem.getType().name()); DeleteItemEvent deleteItemEvent = new DeleteItemEvent( itemDescription); eventBus.fireEvent(deleteItemEvent); @@ -318,12 +333,12 @@ public class ExplorerProjectPanel extends ContentPanel { mb.setWidth(300); mb.show(); } - private void loadData() { ItemDescription itemDescription = new ItemDescription( selectedItem.getId(), selectedItem.getName(), - selectedItem.getOwner(), selectedItem.getPath(), selectedItem.getType().name()); + selectedItem.getOwner(), selectedItem.getPath(), selectedItem + .getType().name()); MainCodeSetEvent mainCodeSetEvent = new MainCodeSetEvent( itemDescription); eventBus.fireEvent(mainCodeSetEvent); @@ -331,4 +346,45 @@ public class ExplorerProjectPanel extends ContentPanel { } + private void openFile() { + if (selectedItem != null + && !selectedItem.isFolder()) { + + final ItemDescription itemDescription = new ItemDescription( + selectedItem.getId(), selectedItem.getName(), + selectedItem.getOwner(), selectedItem.getPath(), + selectedItem.getType().name()); + + StatAlgoImporterServiceAsync.INSTANCE.getUriFromResolver( + itemDescription, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + if (caught instanceof StatAlgoImporterSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("Error open file: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error", + caught.getLocalizedMessage()); + } + caught.printStackTrace(); + + } + + @Override + public void onSuccess(String link) { + Log.debug("Retrieved link: " + link); + Window.open(link, itemDescription.getName(), ""); + } + + }); + + } else { + UtilsGXT3.info("Attention", "Select a file!"); + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java index 87d79dd..26a4288 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java @@ -11,6 +11,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeRea 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.server.uriresolver.UriResolverSMIClient; 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; @@ -381,6 +382,26 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements } } + + @Override + public String getUriFromResolver(ItemDescription itemDescription) + throws StatAlgoImporterServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + logger.debug("GetUriFromResolver(): "+itemDescription); + UriResolverSMIClient resolver=new UriResolverSMIClient(); + String link=resolver.resolve(itemDescription, aslSession); + return link; + } catch (StatAlgoImporterServiceException e) { + e.printStackTrace(); + throw e; + } catch (Throwable e) { + logger.error("getUriFromResolver(): " + e.getLocalizedMessage(), e); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java index 8662a3a..350abcd 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java @@ -3,12 +3,18 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; import javax.servlet.http.HttpSession; +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; @@ -39,6 +45,16 @@ public class ProjectBuilder { private static final String PROJECT_PACKAGE_MIMETYPE = "application/zip"; private static final String PROJECT_PACKAGE_DESCRIPTION = "Statical Algorithm Project Package"; private static final String PROJECT_PACKAGE_EXTENTION = ".zip"; + private static final String LOG_TXT = "log.txt"; + private static final String LOG_JAR_TXT = "logjar.txt"; + private static final String ECOLOGICAL_ENGINE_JAR = "ecological-engine.jar"; + private static final String ECOLOGICAL_ENGINE_JAR_URL = "http://data.d4science.org/id?fileName=ecological-engine.jar&smp-id=56952e9ce4b0e2fd6457272c&contentType=application%2Fjava-archive"; + private static final String ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL = "http://data.d4science.org/id?fileName=ecological-engine-smart-executor.jar&smp-id=56952e9ce4b0e2fd6457272e&contentType=application%2Fjava-archive"; + private static final String ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR = "ecological-engine-smart-executor.jar"; + + private static final String CODE_JAR_MIMETYPE = "application/java-archive"; + private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar"; + private static final String JAR_EXTENTION = ".jar"; public static final Logger logger = LoggerFactory .getLogger(ProjectBuilder.class); @@ -47,6 +63,8 @@ public class ProjectBuilder { private ASLSession aslSession; private HttpSession session; private ProjectTarget projectTarget; + private Path algorithmJava; + private Path infoTXT; public ProjectBuilder(Project project, ASLSession aslSession, HttpSession session) { @@ -98,6 +116,7 @@ public class ProjectBuilder { createProjectPackage(); createAlgorithm(); createIntegrationInfo(); + createProjectJarFile(); SessionUtil.setProjectSession(session, project); @@ -105,17 +124,17 @@ public class ProjectBuilder { protected void createAlgorithm() throws StatAlgoImporterServiceException { AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project); - Path algorithm = algorithmGenerator.createAlgorithm(); + algorithmJava = algorithmGenerator.createAlgorithm(); FilesStorage filesStorage = new FilesStorage(); WorkspaceItem algorithmItem; try { - algorithmItem = filesStorage.createItemOnWorkspace( - aslSession.getUsername(), - Files.newInputStream(algorithm, StandardOpenOption.READ), - project.getInputData().getProjectInfo().getClassName() - + ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION, + algorithmItem = filesStorage.createItemOnWorkspace(aslSession + .getUsername(), Files.newInputStream(algorithmJava, + StandardOpenOption.READ), project.getInputData() + .getProjectInfo().getClassName() + + ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION, ALGORITHM_MIMETYPE, project.getProjectTarget() .getTargetFolder().getId()); } catch (IOException e) { @@ -223,7 +242,7 @@ public class ProjectBuilder { throws StatAlgoImporterServiceException { IntegrationInfoGenerator integrationInfoGenerator = new IntegrationInfoGenerator( project); - Path infoFile = integrationInfoGenerator.createIntegrationInfo(); + infoTXT = integrationInfoGenerator.createIntegrationInfo(); FilesStorage filesStorage = new FilesStorage(); WorkspaceItem infoItem; @@ -231,11 +250,10 @@ public class ProjectBuilder { try { infoItem = filesStorage.createItemOnWorkspace( aslSession.getUsername(), - Files.newInputStream(infoFile, StandardOpenOption.READ), - INTEGRATION_INFO_NAME - + INTEGRATION_INFO_EXTENTION, INTEGRATION_INFO_DESCRIPTION, - INTEGRATION_INFO_MIMETYPE, project.getProjectTarget() - .getTargetFolder().getId()); + Files.newInputStream(infoTXT, StandardOpenOption.READ), + INTEGRATION_INFO_NAME + INTEGRATION_INFO_EXTENTION, + INTEGRATION_INFO_DESCRIPTION, INTEGRATION_INFO_MIMETYPE, + project.getProjectTarget().getTargetFolder().getId()); } catch (IOException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); @@ -263,4 +281,156 @@ public class ProjectBuilder { } + private void createProjectJarFile() throws StatAlgoImporterServiceException { + try { + FilesStorage storage = new FilesStorage(); + + Path tempDirectory = Files.createTempDirectory("StatAlgorithmsJar"); + logger.debug("TempDir: " + tempDirectory); + Path ecologicalEngineJar = new File(tempDirectory.toFile(), + ECOLOGICAL_ENGINE_JAR).toPath(); + storage.downloadInputFile(ECOLOGICAL_ENGINE_JAR_URL, + ecologicalEngineJar); + Path ecologicalEngineSmartExecutorJar = new File( + tempDirectory.toFile(), + ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR).toPath(); + storage.downloadInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL, + ecologicalEngineSmartExecutorJar); + Path algorithmTempFile = new File(tempDirectory.toFile(), project + .getInputData().getProjectInfo().getClassName() + + ALGORITHM_EXTENTION).toPath(); + Files.copy(algorithmJava, algorithmTempFile); + Path infoTempFile = new File(tempDirectory.toFile(), + INTEGRATION_INFO_NAME + INTEGRATION_INFO_EXTENTION) + .toPath(); + Files.copy(infoTXT, infoTempFile); + + createClassFile(tempDirectory); + createJarFile(tempDirectory, infoTempFile); + copyJarOnWorkspace(tempDirectory); + FileUtils.cleanDirectory(tempDirectory.toFile()); + FileUtils.deleteDirectory(tempDirectory.toFile()); + + return; + + } catch (IOException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), + e); + } + } + + private void copyJarOnWorkspace(Path tempDirectory) throws StatAlgoImporterServiceException { + Path codeJar=Paths.get(tempDirectory.toString(),project.getInputData().getProjectInfo().getClassName() + + JAR_EXTENTION); + + FilesStorage filesStorage = new FilesStorage(); + WorkspaceItem codeJarItem; + + try { + codeJarItem = filesStorage.createItemOnWorkspace(aslSession + .getUsername(), Files.newInputStream(codeJar, + StandardOpenOption.READ), project.getInputData().getProjectInfo().getClassName() + + JAR_EXTENTION, CODE_JAR_DESCRIPTION, + CODE_JAR_MIMETYPE, project.getProjectTarget() + .getTargetFolder().getId()); + } catch (IOException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), + e); + } + + ItemDescription codeJarItemDescription; + try { + codeJarItemDescription = new ItemDescription(codeJarItem.getId(), + codeJarItem.getName(), codeJarItem.getOwner() + .getPortalLogin(), codeJarItem.getPath(), + codeJarItem.getType().name()); + codeJarItemDescription.setPublicLink(codeJarItem.getPublicLink(true)); + } catch (InternalErrorException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); + + } + + projectTarget.setCodeJar(codeJarItemDescription); + logger.debug("ProjectTarget: " + projectTarget); + project.setProjectTarget(projectTarget); + + } + + private void createClassFile(Path tempDirectory) + throws StatAlgoImporterServiceException { + + try { + + ProcessBuilder pb = new ProcessBuilder("javac", "-cp", + tempDirectory.toAbsolutePath().toString() + "/*", project + .getInputData().getProjectInfo().getClassName() + + ALGORITHM_EXTENTION); + pb.directory(tempDirectory.toFile()); + Path logTXT = new File(tempDirectory.toFile(), LOG_TXT).toPath(); + + pb.redirectErrorStream(true); + pb.redirectOutput(Redirect.appendTo(logTXT.toFile())); + logger.debug("Process: " + pb.toString()); + Process process = pb.start(); + + // Wait to get exit value + int exitValue = process.waitFor(); + logger.debug("Create Algo Class: Exit Value is " + exitValue); + + } catch (IOException | InterruptedException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), + e); + } + + } + + private void createJarFile(Path tempDirectory, Path infoTempFile) + throws StatAlgoImporterServiceException { + try { + List commands = new ArrayList<>(); + commands.add("jar"); + commands.add("-cvf"); + commands.add(project.getInputData().getProjectInfo().getClassName() + + JAR_EXTENTION); + + DirectoryStream directoryStream = Files + .newDirectoryStream(tempDirectory); + for (Path path : directoryStream) { + if (path.toString().endsWith(".class")) + commands.add(path.getFileName().toString()); + + } + + commands.add(infoTempFile.getFileName().toString()); + + ProcessBuilder pb = new ProcessBuilder(commands); + pb.directory(tempDirectory.toFile()); + Path logTXT = new File(tempDirectory.toFile(), LOG_JAR_TXT) + .toPath(); + + pb.redirectErrorStream(true); + pb.redirectOutput(Redirect.appendTo(logTXT.toFile())); + logger.debug("Process: " + pb.toString()); + Process process = pb.start(); + + // Wait to get exit value + int exitValue = process.waitFor(); + logger.debug("Create Algo Jar: Exit Value is " + exitValue); + + } catch (IOException | InterruptedException e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), + e); + } + + } } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java index 2079575..1d55b88 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/FilesStorage.java @@ -2,9 +2,13 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.net.URLConnection; +import java.nio.file.Path; import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; @@ -132,10 +136,10 @@ public class FilesStorage { "Project Target", folderId); return projectTargetFolder; - } catch (WorkspaceFolderNotFoundException - | InternalErrorException | HomeNotFoundException - | ItemNotFoundException | InsufficientPrivilegesException - | ItemAlreadyExistException | WrongDestinationException e) { + } catch (WorkspaceFolderNotFoundException | InternalErrorException + | HomeNotFoundException | ItemNotFoundException + | InsufficientPrivilegesException | ItemAlreadyExistException + | WrongDestinationException e) { e.printStackTrace(); throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); @@ -211,10 +215,10 @@ public class FilesStorage { } } - - - public WorkspaceItem createItemOnWorkspace(String user, InputStream inputStream, - String name, String description, String mimeType, String folderId) + + public WorkspaceItem createItemOnWorkspace(String user, + InputStream inputStream, String name, String description, + String mimeType, String folderId) throws StatAlgoImporterServiceException { Workspace ws; try { @@ -226,21 +230,19 @@ public class FilesStorage { "Destination is not a folder!"); } - - ExternalFile workspaceItem=ws.createExternalFile(name, description, mimeType, inputStream, - folderId); - + ExternalFile workspaceItem = ws.createExternalFile(name, + description, mimeType, inputStream, folderId); + return workspaceItem; - } catch ( WorkspaceFolderNotFoundException - | InternalErrorException | HomeNotFoundException - | ItemNotFoundException | InsufficientPrivilegesException - | ItemAlreadyExistException | WrongDestinationException e) { + } catch (WorkspaceFolderNotFoundException | InternalErrorException + | HomeNotFoundException | ItemNotFoundException + | InsufficientPrivilegesException | ItemAlreadyExistException + | WrongDestinationException e) { e.printStackTrace(); throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); } } - /** * @@ -406,4 +408,31 @@ public class FilesStorage { } + public void downloadInputFile(String fileUrl, Path destination) + throws StatAlgoImporterServiceException { + try { + + URL smpFile = new URL(fileUrl); + URLConnection uc = (URLConnection) smpFile.openConnection(); + InputStream is = uc.getInputStream(); + inputStreamToFile(is, destination); + is.close(); + + } catch (Throwable e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); + } + } + + private void inputStreamToFile(InputStream is, Path destination) + throws FileNotFoundException, IOException { + FileOutputStream out = new FileOutputStream(destination.toFile()); + byte buf[] = new byte[1024]; + int len = 0; + while ((len = is.read(buf)) > 0) + out.write(buf, 0, len); + out.close(); + } + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/ApplicationType.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/ApplicationType.java new file mode 100644 index 0000000..674321b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/ApplicationType.java @@ -0,0 +1,25 @@ +package org.gcube.portlets.user.statisticalalgorithmsimporter.server.uriresolver; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public enum ApplicationType { + GIS("GIS"), SMP("SMP"), SMP_ID("SMP-ID"); + + /** + * @param text + */ + private ApplicationType(final String id) { + this.id = id; + } + + private final String id; + + @Override + public String toString() { + return id; + } +} diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/UriResolverSMIClient.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/UriResolverSMIClient.java index e4d8a9a..7f3e9c1 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/UriResolverSMIClient.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/uriresolver/UriResolverSMIClient.java @@ -37,7 +37,8 @@ public class UriResolverSMIClient { UriResolverManager resolver; Map params = new HashMap(); if (itemDescription != null) { - resolver = new UriResolverManager(); + resolver = new UriResolverManager( + ApplicationType.SMP_ID.toString()); params.put("smp-id", itemDescription.getId()); if (itemDescription.getName() == null) { params.put("fileName", ""); @@ -53,9 +54,9 @@ public class UriResolverSMIClient { link = resolver.getLink(params, true); // true, link is shorted // otherwise none } else { - logger.debug("No valid ItemDescription: "+itemDescription); - throw new StatAlgoImporterServiceException ( - "No valid ItemDescription: "+itemDescription); + logger.debug("No valid ItemDescription: " + itemDescription); + throw new StatAlgoImporterServiceException( + "No valid ItemDescription: " + itemDescription); } diff --git a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png new file mode 100644 index 0000000..9f2fb7d Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_16.png differ diff --git a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png new file mode 100644 index 0000000..7ae805b Binary files /dev/null and b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/client/resource/download_24.png differ diff --git a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml index 6fd59cb..40f868b 100644 --- a/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/statisticalalgorithmsimporter/statalgoimporter.gwt.xml @@ -57,11 +57,11 @@ /> - +