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