ref 12977: SAI - Force the path of the project folder to be updated to a new format
https://support.d4science.org/issues/12977 Now, when the project is open the path is forced to be updated git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@174614 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
293ef88721
commit
ed86e2dc5f
|
@ -0,0 +1,31 @@
|
||||||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.workspace;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BrowserWindowSupport extends JavaScriptObject {
|
||||||
|
// All types that extend JavaScriptObject must have a protected,
|
||||||
|
// no-args constructor.
|
||||||
|
protected BrowserWindowSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native BrowserWindowSupport open(String url, String target,
|
||||||
|
String options) /*-{
|
||||||
|
return $wnd.open(url, target, options);
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
public native void close() /*-{
|
||||||
|
this.close();
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
public native void setUrl(String url) /*-{
|
||||||
|
if (this.location) {
|
||||||
|
this.location = url;
|
||||||
|
}
|
||||||
|
}-*/;
|
||||||
|
}
|
|
@ -13,7 +13,6 @@ import com.allen_sauer.gwt.log.client.Log;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.event.shared.EventBus;
|
import com.google.gwt.event.shared.EventBus;
|
||||||
import com.google.gwt.http.client.URL;
|
import com.google.gwt.http.client.URL;
|
||||||
import com.google.gwt.user.client.Window;
|
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +25,7 @@ public class DownloadWidget {
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
public DownloadWidget(EventBus eventBus) {
|
public DownloadWidget(EventBus eventBus) {
|
||||||
this.eventBus=eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void download(String itemId) {
|
public void download(String itemId) {
|
||||||
|
@ -73,8 +72,9 @@ public class DownloadWidget {
|
||||||
url.append(Constants.DOWNLOAD_SERVLET + "/" + itemDescription.getName() + "?itemId=" + itemDescription.getId()
|
url.append(Constants.DOWNLOAD_SERVLET + "/" + itemDescription.getName() + "?itemId=" + itemDescription.getId()
|
||||||
+ "&" + Constants.CURR_GROUP_ID + "=" + GCubeClientContext.getCurrentContextId());
|
+ "&" + Constants.CURR_GROUP_ID + "=" + GCubeClientContext.getCurrentContextId());
|
||||||
|
|
||||||
Window.open(URL.encode(url.toString()), "_blank", "");
|
// Window.open(URL.encode(url.toString()), "_blank", "");
|
||||||
|
BrowserWindowSupport browserWindowSupport = BrowserWindowSupport.open("", "_blank", "");
|
||||||
|
browserWindowSupport.setUrl(URL.encode(url.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,29 +61,31 @@ public class ProjectArchiver {
|
||||||
newProjectFolder = filesStorage.getFolderInfoOnWorkspace(serviceCredentials.getUserName(),
|
newProjectFolder = filesStorage.getFolderInfoOnWorkspace(serviceCredentials.getUserName(),
|
||||||
newProjectFolder.getId());
|
newProjectFolder.getId());
|
||||||
|
|
||||||
if (project != null && project.getProjectFolder() != null
|
if (project != null) {
|
||||||
&& newProjectFolder.compareInfo(project.getProjectFolder().getFolder())) {
|
logger.debug("ProjectArchiver set project folder: " + newProjectFolder);
|
||||||
|
|
||||||
} else {
|
|
||||||
project.setProjectFolder(new ProjectFolder(newProjectFolder));
|
project.setProjectFolder(new ProjectFolder(newProjectFolder));
|
||||||
archive(project, serviceCredentials);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project != null && project.getMainCode() != null && project.getMainCode().getItemDescription() != null) {
|
if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null) {
|
||||||
|
try {
|
||||||
ItemDescription newMainCodeItemDescription = filesStorage.getFileInfoOnWorkspace(
|
ItemDescription newMainCodeItemDescription = filesStorage.getFileInfoOnWorkspace(
|
||||||
serviceCredentials.getUserName(), project.getMainCode().getItemDescription().getId());
|
serviceCredentials.getUserName(), project.getMainCode().getItemDescription().getId());
|
||||||
String pLink = filesStorage.getPublicLink(serviceCredentials.getUserName(),
|
String pLink = filesStorage.getPublicLink(serviceCredentials.getUserName(),
|
||||||
newMainCodeItemDescription.getId());
|
newMainCodeItemDescription.getId());
|
||||||
newMainCodeItemDescription.setPublicLink(pLink);
|
newMainCodeItemDescription.setPublicLink(pLink);
|
||||||
if (newMainCodeItemDescription.compareInfo(project.getMainCode().getItemDescription())) {
|
logger.debug("ProjectArchiver set main code: " + newMainCodeItemDescription);
|
||||||
} else {
|
|
||||||
project.setMainCode(new MainCode(newMainCodeItemDescription));
|
project.setMainCode(new MainCode(newMainCodeItemDescription));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("ProjectArchiver error reading the main code: " + project.getMainCode().getItemDescription());
|
||||||
archive(project, serviceCredentials);
|
archive(project, serviceCredentials);
|
||||||
|
throw new StatAlgoImporterServiceException("Error reading the main code of the project!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
archive(project, serviceCredentials);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
project.setProjectFolder(new ProjectFolder(newProjectFolder));
|
logger.debug("ProjectArchiver project retrieved is null!");
|
||||||
archive(project, serviceCredentials);
|
throw new StatAlgoImporterServiceException("The Project retrieved is not valid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return project;
|
return project;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class StatAlgoImporterTest extends TestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testSpecialCharacters() {
|
public void testSpecialCharacters() {
|
||||||
|
|
||||||
if (true) {
|
if (Constants.TEST_ENABLE) {
|
||||||
try {
|
try {
|
||||||
String patternToMatch = "[\\\\!\"#$%&()*+,/:;<=>?@\\[\\]^{|}~]+";
|
String patternToMatch = "[\\\\!\"#$%&()*+,/:;<=>?@\\[\\]^{|}~]+";
|
||||||
Pattern p = Pattern.compile(patternToMatch);
|
Pattern p = Pattern.compile(patternToMatch);
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter;
|
||||||
|
|
||||||
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
||||||
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StorageHubTest extends TestCase {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(StorageHubTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopy() {
|
||||||
|
if (Constants.TEST_ENABLE) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String itemId = "5bd115b1-3235-4256-bf29-14e2f6adcba3";
|
||||||
|
String folderId = "08c47365-d534-45ff-a690-882ced63100f";
|
||||||
|
|
||||||
|
String scope = Constants.DEFAULT_SCOPE;
|
||||||
|
String user = Constants.DEFAULT_USER;
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"Copy item on folder: [user=" + user + ", itemId=" + itemId + ", folderId=" + folderId + "]");
|
||||||
|
|
||||||
|
List<String> userRoles = new ArrayList<>();
|
||||||
|
userRoles.add(Constants.DEFAULT_ROLE);
|
||||||
|
/*
|
||||||
|
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
|
||||||
|
* userRoles.add("VRE-Manager");
|
||||||
|
*/
|
||||||
|
|
||||||
|
String token;
|
||||||
|
try {
|
||||||
|
token = authorizationService().generateUserToken(new UserInfo(user, userRoles),
|
||||||
|
scope);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error generating the token for test: " + e.getLocalizedMessage(),e);
|
||||||
|
throw new Exception("Error generating the token for test: " + e.getLocalizedMessage(),e);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Set SecurityToken: " + token);
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
logger.debug("Set ScopeProvider: " + scope);
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
logger.debug("StorageHub client retrieved!");
|
||||||
|
logger.debug("Retrieve file: "+itemId);
|
||||||
|
OpenResolver openResolverForFile = shc.open(itemId);
|
||||||
|
logger.debug("Retrieve FileContainer");
|
||||||
|
FileContainer fileContainer = openResolverForFile.asFile();
|
||||||
|
logger.debug("FileContainer retrieved!");
|
||||||
|
|
||||||
|
OpenResolver openResolverForFolder = shc.open(folderId);
|
||||||
|
FolderContainer folderContainer = openResolverForFolder.asFolder();
|
||||||
|
logger.debug("FolderContainer retrieved!");
|
||||||
|
logger.debug("Copy Start");
|
||||||
|
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, fileContainer.get().getName());
|
||||||
|
logger.debug("Copy Done");
|
||||||
|
AbstractFileItem item = fileCreatedContainer.get();
|
||||||
|
logger.debug("File retrieved");
|
||||||
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
|
item.getPath(), "");
|
||||||
|
logger.debug("Item: " + itemDescription);
|
||||||
|
assertTrue("Success", true);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
fail("Error:" + e.getLocalizedMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
assertTrue("Success", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,50 +0,0 @@
|
||||||
package org.gcube.dataanalysis.executor.rscripts;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
|
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType;
|
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
|
|
||||||
import org.gcube.dataanalysis.executor.rscripts.generic.GenericRScript;
|
|
||||||
|
|
||||||
public class KnitrCompiler extends GenericRScript {
|
|
||||||
|
|
||||||
public static enum operators {
|
|
||||||
EQUAL, NOT_EQUAL, CONTAINS, BEGINS_WITH, ENDS_WITH
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "An algorithm to compile Knitr documents. Developed by IRD (reference Julien Bard, julien.barde@ird.fr)";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initVariables(){
|
|
||||||
mainScriptName="IRDTunaAtlas-master/report/knitr/compileKnitR_CNR.R";
|
|
||||||
packageURL="http://goo.gl/T7V8LV";
|
|
||||||
|
|
||||||
environmentalvariables = new ArrayList<String>();
|
|
||||||
inputvariables.add("zipfile");
|
|
||||||
inputvariables.add("file.inout");
|
|
||||||
outputvariables.add("pdfresult");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setInputParameters() {
|
|
||||||
|
|
||||||
inputs.add(new PrimitiveType(Enum.class.getName(), operators.values(), PrimitiveTypes.ENUMERATED, name, description, defaultvalue));
|
|
||||||
inputs.add(new PrimitiveType(File.class.getName(), null, PrimitiveTypes.FILE, "zipfile", "The file containing R and the markdown (Rnw) files to compile","knitr_wfs.zip"));
|
|
||||||
inputs.add(new PrimitiveType(String.class.getName(), null, PrimitiveTypes.STRING, "file.inout", "The name of the R file in the zip package", "main.r"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StatisticalType getOutput() {
|
|
||||||
output.put("pdfresult",new PrimitiveType(File.class.getName(), new File(outputValues.get("pdfresult")), PrimitiveTypes.FILE, "pdfresult", "The compiled PDF file"));
|
|
||||||
PrimitiveType o = new PrimitiveType(LinkedHashMap.class.getName(), output, PrimitiveTypes.MAP, "Output", "");
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue