1452: Implement a GUI for StatMan Algorithms Importer
Task-Url: https://support.d4science.org/issues/1452 Updated Added Jar Creation git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122219 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6e41b0e124
commit
f2aed31faa
|
@ -30,6 +30,12 @@ public interface StatAlgoImporterResources extends ClientBundle {
|
||||||
@Source("download_32.png")
|
@Source("download_32.png")
|
||||||
ImageResource download32();
|
ImageResource download32();
|
||||||
|
|
||||||
|
@Source("download_24.png")
|
||||||
|
ImageResource download24();
|
||||||
|
|
||||||
|
@Source("download_16.png")
|
||||||
|
ImageResource download16();
|
||||||
|
|
||||||
@Source("upload_32.png")
|
@Source("upload_32.png")
|
||||||
ImageResource upload32();
|
ImageResource upload32();
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 546 B |
Binary file not shown.
After Width: | Height: | Size: 799 B |
|
@ -66,4 +66,6 @@ public interface StatAlgoImporterService extends RemoteService {
|
||||||
|
|
||||||
public void createSoftware(InputData inputData) throws StatAlgoImporterServiceException;
|
public void createSoftware(InputData inputData) throws StatAlgoImporterServiceException;
|
||||||
|
|
||||||
|
public String getUriFromResolver(ItemDescription itemDescription) throws StatAlgoImporterServiceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,4 +57,7 @@ public interface StatAlgoImporterServiceAsync {
|
||||||
|
|
||||||
void createSoftware(InputData inputData, AsyncCallback<Void> callback);
|
void createSoftware(InputData inputData, AsyncCallback<Void> callback);
|
||||||
|
|
||||||
|
void getUriFromResolver(ItemDescription itemDescription,
|
||||||
|
AsyncCallback<String> asyncCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.DeleteItemEvent;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.MainCodeSetEvent;
|
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.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.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.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.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
|
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.allen_sauer.gwt.log.client.Log;
|
||||||
import com.google.gwt.event.shared.EventBus;
|
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.ButtonScale;
|
||||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||||
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||||
|
@ -44,9 +50,10 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
|
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private Item selectedItem;
|
private Item selectedItem;
|
||||||
private TextButton btnSetMain;
|
|
||||||
private MultipleDNDUpload dnd;
|
private MultipleDNDUpload dnd;
|
||||||
private WorkspaceResourcesExplorerPanel wsResourcesExplorerPanel;
|
private WorkspaceResourcesExplorerPanel wsResourcesExplorerPanel;
|
||||||
|
private TextButton btnSetMain;
|
||||||
|
private TextButton btnOpen;
|
||||||
private TextButton btnDelete;
|
private TextButton btnDelete;
|
||||||
private TextButton btnReload;
|
private TextButton btnReload;
|
||||||
|
|
||||||
|
@ -83,12 +90,10 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
setAnimCollapse(false);
|
setAnimCollapse(false);
|
||||||
setHeadingText("Project Explorer");
|
setHeadingText("Project Explorer");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindToEvents() {
|
private void bindToEvents() {
|
||||||
|
|
||||||
|
|
||||||
eventBus.addHandler(ProjectStatusEvent.TYPE,
|
eventBus.addHandler(ProjectStatusEvent.TYPE,
|
||||||
new ProjectStatusEvent.ProjectStatusEventHandler() {
|
new ProjectStatusEvent.ProjectStatusEventHandler() {
|
||||||
|
|
||||||
|
@ -100,7 +105,6 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void manageProjectStatusEvents(ProjectStatusEvent event) {
|
private void manageProjectStatusEvents(ProjectStatusEvent event) {
|
||||||
Log.debug("InputVariablePanel recieved event ProjectStatus: "
|
Log.debug("InputVariablePanel recieved event ProjectStatus: "
|
||||||
+ event.toString());
|
+ event.toString());
|
||||||
|
@ -127,7 +131,8 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel(
|
wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel(
|
||||||
event.getProject().getProjectFolder().getItemDescription().getId(), false);
|
event.getProject().getProjectFolder().getItemDescription()
|
||||||
|
.getId(), false);
|
||||||
|
|
||||||
WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() {
|
WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -166,7 +171,8 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
// DND
|
// DND
|
||||||
|
|
||||||
dnd = new MultipleDNDUpload();
|
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);
|
dnd.addUniqueContainer(vResourcesExplorerContainer);
|
||||||
WorskpaceUploadNotificationListener workspaceUploaderListener = new WorskpaceUploadNotificationListener() {
|
WorskpaceUploadNotificationListener workspaceUploaderListener = new WorskpaceUploadNotificationListener() {
|
||||||
|
|
||||||
|
@ -219,6 +225,20 @@ 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 = new TextButton("Delete");
|
||||||
btnDelete.setIcon(StatAlgoImporterResources.INSTANCE.delete16());
|
btnDelete.setIcon(StatAlgoImporterResources.INSTANCE.delete16());
|
||||||
btnDelete.setScale(ButtonScale.SMALL);
|
btnDelete.setScale(ButtonScale.SMALL);
|
||||||
|
@ -231,8 +251,6 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
deleteItem(event);
|
deleteItem(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
btnReload = new TextButton("Reload");
|
btnReload = new TextButton("Reload");
|
||||||
|
@ -247,17 +265,13 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
reloadWSResourceExplorerPanel();
|
reloadWSResourceExplorerPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ToolBar toolBar = new ToolBar();
|
ToolBar toolBar = new ToolBar();
|
||||||
toolBar.add(btnSetMain, new BoxLayoutData(new Margins(0)));
|
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(btnDelete, new BoxLayoutData(new Margins(0)));
|
||||||
|
toolBar.add(btnReload, new BoxLayoutData(new Margins(0)));
|
||||||
|
|
||||||
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
||||||
|
|
||||||
|
@ -273,7 +287,7 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reloadWSResourceExplorerPanel() {
|
protected void reloadWSResourceExplorerPanel() {
|
||||||
if(wsResourcesExplorerPanel!=null){
|
if (wsResourcesExplorerPanel != null) {
|
||||||
wsResourcesExplorerPanel.refreshRootFolderView();
|
wsResourcesExplorerPanel.refreshRootFolderView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +317,8 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
case YES:
|
case YES:
|
||||||
ItemDescription itemDescription = new ItemDescription(
|
ItemDescription itemDescription = new ItemDescription(
|
||||||
selectedItem.getId(), selectedItem.getName(),
|
selectedItem.getId(), selectedItem.getName(),
|
||||||
selectedItem.getOwner(), selectedItem.getPath(), selectedItem.getType().name());
|
selectedItem.getOwner(), selectedItem.getPath(),
|
||||||
|
selectedItem.getType().name());
|
||||||
DeleteItemEvent deleteItemEvent = new DeleteItemEvent(
|
DeleteItemEvent deleteItemEvent = new DeleteItemEvent(
|
||||||
itemDescription);
|
itemDescription);
|
||||||
eventBus.fireEvent(deleteItemEvent);
|
eventBus.fireEvent(deleteItemEvent);
|
||||||
|
@ -319,11 +334,11 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
mb.show();
|
mb.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadData() {
|
private void loadData() {
|
||||||
ItemDescription itemDescription = new ItemDescription(
|
ItemDescription itemDescription = new ItemDescription(
|
||||||
selectedItem.getId(), selectedItem.getName(),
|
selectedItem.getId(), selectedItem.getName(),
|
||||||
selectedItem.getOwner(), selectedItem.getPath(), selectedItem.getType().name());
|
selectedItem.getOwner(), selectedItem.getPath(), selectedItem
|
||||||
|
.getType().name());
|
||||||
MainCodeSetEvent mainCodeSetEvent = new MainCodeSetEvent(
|
MainCodeSetEvent mainCodeSetEvent = new MainCodeSetEvent(
|
||||||
itemDescription);
|
itemDescription);
|
||||||
eventBus.fireEvent(mainCodeSetEvent);
|
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<String>() {
|
||||||
|
|
||||||
|
@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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.generator.ProjectBuilder;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
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.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.code.CodeData;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
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.file.FileUploadMonitor;
|
||||||
|
@ -382,5 +383,25 @@ 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,18 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
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_MIMETYPE = "application/zip";
|
||||||
private static final String PROJECT_PACKAGE_DESCRIPTION = "Statical Algorithm Project Package";
|
private static final String PROJECT_PACKAGE_DESCRIPTION = "Statical Algorithm Project Package";
|
||||||
private static final String PROJECT_PACKAGE_EXTENTION = ".zip";
|
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
|
public static final Logger logger = LoggerFactory
|
||||||
.getLogger(ProjectBuilder.class);
|
.getLogger(ProjectBuilder.class);
|
||||||
|
@ -47,6 +63,8 @@ public class ProjectBuilder {
|
||||||
private ASLSession aslSession;
|
private ASLSession aslSession;
|
||||||
private HttpSession session;
|
private HttpSession session;
|
||||||
private ProjectTarget projectTarget;
|
private ProjectTarget projectTarget;
|
||||||
|
private Path algorithmJava;
|
||||||
|
private Path infoTXT;
|
||||||
|
|
||||||
public ProjectBuilder(Project project, ASLSession aslSession,
|
public ProjectBuilder(Project project, ASLSession aslSession,
|
||||||
HttpSession session) {
|
HttpSession session) {
|
||||||
|
@ -98,6 +116,7 @@ public class ProjectBuilder {
|
||||||
createProjectPackage();
|
createProjectPackage();
|
||||||
createAlgorithm();
|
createAlgorithm();
|
||||||
createIntegrationInfo();
|
createIntegrationInfo();
|
||||||
|
createProjectJarFile();
|
||||||
|
|
||||||
SessionUtil.setProjectSession(session, project);
|
SessionUtil.setProjectSession(session, project);
|
||||||
|
|
||||||
|
@ -105,17 +124,17 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
protected void createAlgorithm() throws StatAlgoImporterServiceException {
|
protected void createAlgorithm() throws StatAlgoImporterServiceException {
|
||||||
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
||||||
Path algorithm = algorithmGenerator.createAlgorithm();
|
algorithmJava = algorithmGenerator.createAlgorithm();
|
||||||
|
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
WorkspaceItem algorithmItem;
|
WorkspaceItem algorithmItem;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
algorithmItem = filesStorage.createItemOnWorkspace(
|
algorithmItem = filesStorage.createItemOnWorkspace(aslSession
|
||||||
aslSession.getUsername(),
|
.getUsername(), Files.newInputStream(algorithmJava,
|
||||||
Files.newInputStream(algorithm, StandardOpenOption.READ),
|
StandardOpenOption.READ), project.getInputData()
|
||||||
project.getInputData().getProjectInfo().getClassName()
|
.getProjectInfo().getClassName()
|
||||||
+ ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION,
|
+ ALGORITHM_EXTENTION, ALGORITHM_DESCRIPTION,
|
||||||
ALGORITHM_MIMETYPE, project.getProjectTarget()
|
ALGORITHM_MIMETYPE, project.getProjectTarget()
|
||||||
.getTargetFolder().getId());
|
.getTargetFolder().getId());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -223,7 +242,7 @@ public class ProjectBuilder {
|
||||||
throws StatAlgoImporterServiceException {
|
throws StatAlgoImporterServiceException {
|
||||||
IntegrationInfoGenerator integrationInfoGenerator = new IntegrationInfoGenerator(
|
IntegrationInfoGenerator integrationInfoGenerator = new IntegrationInfoGenerator(
|
||||||
project);
|
project);
|
||||||
Path infoFile = integrationInfoGenerator.createIntegrationInfo();
|
infoTXT = integrationInfoGenerator.createIntegrationInfo();
|
||||||
|
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
WorkspaceItem infoItem;
|
WorkspaceItem infoItem;
|
||||||
|
@ -231,11 +250,10 @@ public class ProjectBuilder {
|
||||||
try {
|
try {
|
||||||
infoItem = filesStorage.createItemOnWorkspace(
|
infoItem = filesStorage.createItemOnWorkspace(
|
||||||
aslSession.getUsername(),
|
aslSession.getUsername(),
|
||||||
Files.newInputStream(infoFile, StandardOpenOption.READ),
|
Files.newInputStream(infoTXT, StandardOpenOption.READ),
|
||||||
INTEGRATION_INFO_NAME
|
INTEGRATION_INFO_NAME + INTEGRATION_INFO_EXTENTION,
|
||||||
+ INTEGRATION_INFO_EXTENTION, INTEGRATION_INFO_DESCRIPTION,
|
INTEGRATION_INFO_DESCRIPTION, INTEGRATION_INFO_MIMETYPE,
|
||||||
INTEGRATION_INFO_MIMETYPE, project.getProjectTarget()
|
project.getProjectTarget().getTargetFolder().getId());
|
||||||
.getTargetFolder().getId());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
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<String> commands = new ArrayList<>();
|
||||||
|
commands.add("jar");
|
||||||
|
commands.add("-cvf");
|
||||||
|
commands.add(project.getInputData().getProjectInfo().getClassName()
|
||||||
|
+ JAR_EXTENTION);
|
||||||
|
|
||||||
|
DirectoryStream<Path> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,13 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||||
|
@ -132,10 +136,10 @@ public class FilesStorage {
|
||||||
"Project Target", folderId);
|
"Project Target", folderId);
|
||||||
|
|
||||||
return projectTargetFolder;
|
return projectTargetFolder;
|
||||||
} catch (WorkspaceFolderNotFoundException
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
||||||
| InternalErrorException | HomeNotFoundException
|
| HomeNotFoundException | ItemNotFoundException
|
||||||
| ItemNotFoundException | InsufficientPrivilegesException
|
| InsufficientPrivilegesException | ItemAlreadyExistException
|
||||||
| ItemAlreadyExistException | WrongDestinationException e) {
|
| WrongDestinationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
|
||||||
|
@ -212,9 +216,9 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WorkspaceItem createItemOnWorkspace(String user,
|
||||||
public WorkspaceItem createItemOnWorkspace(String user, InputStream inputStream,
|
InputStream inputStream, String name, String description,
|
||||||
String name, String description, String mimeType, String folderId)
|
String mimeType, String folderId)
|
||||||
throws StatAlgoImporterServiceException {
|
throws StatAlgoImporterServiceException {
|
||||||
Workspace ws;
|
Workspace ws;
|
||||||
try {
|
try {
|
||||||
|
@ -226,22 +230,20 @@ public class FilesStorage {
|
||||||
"Destination is not a folder!");
|
"Destination is not a folder!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExternalFile workspaceItem = ws.createExternalFile(name,
|
||||||
ExternalFile workspaceItem=ws.createExternalFile(name, description, mimeType, inputStream,
|
description, mimeType, inputStream, folderId);
|
||||||
folderId);
|
|
||||||
|
|
||||||
return workspaceItem;
|
return workspaceItem;
|
||||||
} catch ( WorkspaceFolderNotFoundException
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
||||||
| InternalErrorException | HomeNotFoundException
|
| HomeNotFoundException | ItemNotFoundException
|
||||||
| ItemNotFoundException | InsufficientPrivilegesException
|
| InsufficientPrivilegesException | ItemAlreadyExistException
|
||||||
| ItemAlreadyExistException | WrongDestinationException e) {
|
| WrongDestinationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.uriresolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,8 @@ public class UriResolverSMIClient {
|
||||||
UriResolverManager resolver;
|
UriResolverManager resolver;
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
if (itemDescription != null) {
|
if (itemDescription != null) {
|
||||||
resolver = new UriResolverManager();
|
resolver = new UriResolverManager(
|
||||||
|
ApplicationType.SMP_ID.toString());
|
||||||
params.put("smp-id", itemDescription.getId());
|
params.put("smp-id", itemDescription.getId());
|
||||||
if (itemDescription.getName() == null) {
|
if (itemDescription.getName() == null) {
|
||||||
params.put("fileName", "");
|
params.put("fileName", "");
|
||||||
|
@ -53,9 +54,9 @@ public class UriResolverSMIClient {
|
||||||
link = resolver.getLink(params, true); // true, link is shorted
|
link = resolver.getLink(params, true); // true, link is shorted
|
||||||
// otherwise none
|
// otherwise none
|
||||||
} else {
|
} else {
|
||||||
logger.debug("No valid ItemDescription: "+itemDescription);
|
logger.debug("No valid ItemDescription: " + itemDescription);
|
||||||
throw new StatAlgoImporterServiceException (
|
throw new StatAlgoImporterServiceException(
|
||||||
"No valid ItemDescription: "+itemDescription);
|
"No valid ItemDescription: " + itemDescription);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 546 B |
Binary file not shown.
After Width: | Height: | Size: 799 B |
|
@ -57,11 +57,11 @@
|
||||||
/>
|
/>
|
||||||
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED"
|
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED"
|
||||||
/> -->
|
/> -->
|
||||||
|
<!--
|
||||||
<set-property name="log_ConsoleLogger" value="DISABLED" />
|
<set-property name="log_ConsoleLogger" value="DISABLED" />
|
||||||
<set-property name="log_DivLogger" value="DISABLED" />
|
<set-property name="log_DivLogger" value="DISABLED" />
|
||||||
<set-property name="log_GWTLogger" value="DISABLED" />
|
<set-property name="log_GWTLogger" value="DISABLED" />
|
||||||
<set-property name="log_SystemLogger" value="DISABLED" />
|
<set-property name="log_SystemLogger" value="DISABLED" /> -->
|
||||||
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="DISABLED"
|
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="DISABLED"
|
||||||
/> -->
|
/> -->
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue