ref 10523: Fixed Set Main behavior in case of R

https://support.d4science.org/issues/10523

Fixed Set Main behavior in case of R 

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@160310 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-12-11 18:26:34 +00:00
parent 2a2eabfce7
commit 874f744833
2 changed files with 61 additions and 70 deletions

View File

@ -317,7 +317,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
String link = filesStorage.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId()); String link = filesStorage.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId());
itemDescription.setPublicLink(link); itemDescription.setPublicLink(link);
project.setMainCode(new MainCode(itemDescription)); project.setMainCode(new MainCode(itemDescription));
project.setInputData(null); InputData inputData=project.getInputData();
if(inputData!=null){
inputData.setListInputOutputVariables(null);
}
project.setProjectTarget(null); project.setProjectTarget(null);
WPS4RParser wps4Parser = new WPS4RParser(project, serviceCredentials); WPS4RParser wps4Parser = new WPS4RParser(project, serviceCredentials);
project = wps4Parser.parse(); project = wps4Parser.parse();
@ -646,6 +649,28 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
} }
@Override
public String getPublicLink(ItemDescription itemDescription) throws StatAlgoImporterServiceException {
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
logger.debug("GetPublicLink(): " + itemDescription);
FilesStorage filesStorage = new FilesStorage();
String link = filesStorage.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId());
return link;
} catch (StatAlgoImporterServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("getPublicLink(): " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
@Override @Override
public Project createSoftware(InputData inputData) throws StatAlgoImporterServiceException { public Project createSoftware(InputData inputData) throws StatAlgoImporterServiceException {
try { try {
@ -678,26 +703,6 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
} }
@Override
public String getPublicLink(ItemDescription itemDescription) throws StatAlgoImporterServiceException {
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
logger.debug("GetPublicLink(): " + itemDescription);
FilesStorage filesStorage = new FilesStorage();
String link = filesStorage.getPublicLink(serviceCredentials.getUserName(), itemDescription.getId());
return link;
} catch (StatAlgoImporterServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
logger.error("getPublicLink(): " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
@Override @Override
public String publishSoftware() throws StatAlgoImporterServiceException { public String publishSoftware() throws StatAlgoImporterServiceException {
try { try {

View File

@ -36,8 +36,7 @@ import org.slf4j.LoggerFactory;
*/ */
public class WPS4RParser { public class WPS4RParser {
public static final Logger logger = LoggerFactory public static final Logger logger = LoggerFactory.getLogger(WPS4RParser.class);
.getLogger(WPS4RParser.class);
private Project project; private Project project;
private ServiceCredentials serviceCredentials; private ServiceCredentials serviceCredentials;
@ -51,8 +50,7 @@ public class WPS4RParser {
logger.debug("MainCode: " + project.getMainCode()); logger.debug("MainCode: " + project.getMainCode());
ItemDescription mainCode = project.getMainCode().getItemDescription(); ItemDescription mainCode = project.getMainCode().getItemDescription();
FilesStorage fileStorage = new FilesStorage(); FilesStorage fileStorage = new FilesStorage();
InputStream is = fileStorage.retrieveItemOnWorkspace( InputStream is = fileStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(), mainCode.getId());
serviceCredentials.getUserName(), mainCode.getId());
logger.debug("MainCode InputStream: " + is); logger.debug("MainCode InputStream: " + is);
Path tempFile = null; Path tempFile = null;
@ -77,8 +75,7 @@ public class WPS4RParser {
try { try {
RAnnotationParser parser = new RAnnotationParser(config); RAnnotationParser parser = new RAnnotationParser(config);
logger.debug("RAnnotations Parser:" + parser); logger.debug("RAnnotations Parser:" + parser);
annotations = parser.parseAnnotationsfromScript(Files annotations = parser.parseAnnotationsfromScript(Files.newInputStream(tempFile, StandardOpenOption.READ));
.newInputStream(tempFile, StandardOpenOption.READ));
} catch (RAnnotationException e) { } catch (RAnnotationException e) {
e.printStackTrace(); e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
@ -97,54 +94,53 @@ public class WPS4RParser {
WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations); WPSAlgorithmInfo wpsAlgorithmInfo = mapAnnotations(annotations);
logger.debug("wpsAlgorithmInfo: " + wpsAlgorithmInfo); logger.debug("wpsAlgorithmInfo: " + wpsAlgorithmInfo);
if (wpsAlgorithmInfo == null if (wpsAlgorithmInfo == null || wpsAlgorithmInfo.getAlgorithmName() == null)
|| wpsAlgorithmInfo.getAlgorithmName() == null)
return project; return project;
else else
return mapToProject(wpsAlgorithmInfo); return mapToProject(wpsAlgorithmInfo);
} }
private Project mapToProject(WPSAlgorithmInfo wpsAlgorithmInfo) private Project mapToProject(WPSAlgorithmInfo wpsAlgorithmInfo) throws StatAlgoImporterServiceException {
throws StatAlgoImporterServiceException {
if (project == null) { if (project == null) {
throw new StatAlgoImporterServiceException("Open project before!"); throw new StatAlgoImporterServiceException("Open project before!");
} }
if (project.getInputData() == null) { if (project.getInputData() == null) {
ProjectInfo projectInfo = new ProjectInfo( ProjectInfo projectInfo = new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(),
wpsAlgorithmInfo.getAlgorithmName(),
wpsAlgorithmInfo.getDescription(), null); wpsAlgorithmInfo.getDescription(), null);
InputData inputData = new InputData(projectInfo, null, null, InputData inputData = new InputData(projectInfo, null, null, wpsAlgorithmInfo.getInputOutputVariables());
wpsAlgorithmInfo.getInputOutputVariables());
project.setInputData(inputData); project.setInputData(inputData);
} else { } else {
if (project.getInputData().getProjectInfo() == null) { if (project.getInputData().getProjectInfo() == null) {
InputData inputData = project.getInputData(); InputData inputData = project.getInputData();
ProjectInfo projectInfo = new ProjectInfo( ProjectInfo projectInfo = new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(),
wpsAlgorithmInfo.getAlgorithmName(),
wpsAlgorithmInfo.getDescription(), null); wpsAlgorithmInfo.getDescription(), null);
inputData.setProjectInfo(projectInfo); inputData.setProjectInfo(projectInfo);
inputData.setListInputOutputVariables(wpsAlgorithmInfo inputData.setListInputOutputVariables(wpsAlgorithmInfo.getInputOutputVariables());
.getInputOutputVariables());
} else { } else {
InputData inputData = project.getInputData(); InputData inputData = project.getInputData();
ProjectInfo projectInfo = new ProjectInfo( ProjectInfo projectInfo = project.getInputData().getProjectInfo();
wpsAlgorithmInfo.getAlgorithmName(),
wpsAlgorithmInfo.getDescription(), project if (project.getInputData().getProjectInfo().getAlgorithmName() == null
.getInputData().getProjectInfo() || project.getInputData().getProjectInfo().getAlgorithmName().isEmpty()) {
.getAlgorithmCategory()); projectInfo.setAlgorithmName(wpsAlgorithmInfo.getAlgorithmName());
}
if (project.getInputData().getProjectInfo().getAlgorithmDescription() == null
|| project.getInputData().getProjectInfo().getAlgorithmDescription().isEmpty()) {
projectInfo.setAlgorithmDescription(wpsAlgorithmInfo.getDescription());
}
inputData.setProjectInfo(projectInfo); inputData.setProjectInfo(projectInfo);
inputData.setListInputOutputVariables(wpsAlgorithmInfo inputData.setListInputOutputVariables(wpsAlgorithmInfo.getInputOutputVariables());
.getInputOutputVariables()); }
}
} }
return project; return project;
} }
private WPSAlgorithmInfo mapAnnotations(List<RAnnotation> annotations) private WPSAlgorithmInfo mapAnnotations(List<RAnnotation> annotations) throws StatAlgoImporterServiceException {
throws StatAlgoImporterServiceException {
try { try {
WPSAlgorithmInfo wpsAlgorithmInfo = new WPSAlgorithmInfo(); WPSAlgorithmInfo wpsAlgorithmInfo = new WPSAlgorithmInfo();
@ -153,28 +149,20 @@ public class WPS4RParser {
for (RAnnotation rAnnotation : annotations) { for (RAnnotation rAnnotation : annotations) {
logger.debug("RAnnotation: " + rAnnotation); logger.debug("RAnnotation: " + rAnnotation);
if (rAnnotation.getType().equals(RAnnotationType.DESCRIPTION)) { if (rAnnotation.getType().equals(RAnnotationType.DESCRIPTION)) {
wpsAlgorithmInfo.setVersion(rAnnotation wpsAlgorithmInfo.setVersion(rAnnotation.getStringValue(RAttribute.VERSION));
.getStringValue(RAttribute.VERSION)); wpsAlgorithmInfo.setDescription(rAnnotation.getStringValue(RAttribute.ABSTRACT));
wpsAlgorithmInfo.setDescription(rAnnotation String algorithmName = rAnnotation.getStringValue(RAttribute.TITLE);
.getStringValue(RAttribute.ABSTRACT)); algorithmName = algorithmName.replaceAll("[^A-Za-z0-9]", "_");
String algorithmName = rAnnotation
.getStringValue(RAttribute.TITLE);
algorithmName = algorithmName.replaceAll("[^A-Za-z0-9]",
"_");
wpsAlgorithmInfo.setAlgorithmName(algorithmName); wpsAlgorithmInfo.setAlgorithmName(algorithmName);
wpsAlgorithmInfo.setVersion(rAnnotation wpsAlgorithmInfo.setVersion(rAnnotation.getStringValue(RAttribute.VERSION));
.getStringValue(RAttribute.VERSION));
} else if (rAnnotation.getType().equals(RAnnotationType.OUTPUT) } else if (rAnnotation.getType().equals(RAnnotationType.OUTPUT)
|| rAnnotation.getType().equals(RAnnotationType.INPUT)) { || rAnnotation.getType().equals(RAnnotationType.INPUT)) {
// output, text, Random number list, // output, text, Random number list,
String type = rAnnotation.getStringValue(RAttribute.TYPE); String type = rAnnotation.getStringValue(RAttribute.TYPE);
String name = rAnnotation String name = rAnnotation.getStringValue(RAttribute.IDENTIFIER);
.getStringValue(RAttribute.IDENTIFIER); String description = rAnnotation.getStringValue(RAttribute.TITLE);
String description = rAnnotation String defaultValue = rAnnotation.getStringValue(RAttribute.DEFAULT_VALUE);
.getStringValue(RAttribute.TITLE);
String defaultValue = rAnnotation
.getStringValue(RAttribute.DEFAULT_VALUE);
if (type == null) if (type == null)
type = "string"; type = "string";
if (name == null) if (name == null)
@ -190,13 +178,11 @@ public class WPS4RParser {
ioType = IOType.OUTPUT; ioType = IOType.OUTPUT;
DataType dataType = WPStype2DataType(type); DataType dataType = WPStype2DataType(type);
if (defaultValue != null && defaultValue.contains("|") if (defaultValue != null && defaultValue.contains("|") && dataType == DataType.STRING)
&& dataType == DataType.STRING)
dataType = DataType.ENUMERATED; dataType = DataType.ENUMERATED;
InputOutputVariables ioVariable = new InputOutputVariables( InputOutputVariables ioVariable = new InputOutputVariables(index, name, description, defaultValue,
index, name, description, defaultValue, dataType, dataType, ioType, "");
ioType, "");
inputOutputVariables.add(ioVariable); inputOutputVariables.add(ioVariable);
index++; index++;
} }