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 5dd9956..d2174a3 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 @@ -466,7 +466,7 @@ public class FilesStorage { } } catch (Throwable e) { - logger.error("Retrieve project item on workspace: " + e.getLocalizedMessage(), e); + logger.error("Error retrieving project item on workspace: " + e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); } } @@ -536,7 +536,7 @@ public class FilesStorage { return itemDescription; } catch (Throwable e) { - logger.error("Retrieve file info on workspace: " + e.getLocalizedMessage(), e); + logger.error("Error retrieving file info on workspace: " + e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); } } @@ -566,7 +566,7 @@ public class FilesStorage { return itemDescription; } catch (Throwable e) { - logger.error("Retrieve folder info on workspace: " + e.getLocalizedMessage(), e); + logger.error("Error retrieving folder info on workspace: " + e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); } } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/ProjectArchiver.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/ProjectArchiver.java index e791fdf..392455f 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/ProjectArchiver.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/storage/ProjectArchiver.java @@ -50,45 +50,58 @@ public class ProjectArchiver { public static Project readProject(ItemDescription newProjectFolder, ServiceCredentials serviceCredentials) throws StatAlgoImporterServiceException { - FilesStorage filesStorage = new FilesStorage(); - InputStream inputStream = filesStorage.getProjectItemOnWorkspace(serviceCredentials.getUserName(), - newProjectFolder.getId()); + try { + FilesStorage filesStorage = new FilesStorage(); + InputStream inputStream = filesStorage.getProjectItemOnWorkspace(serviceCredentials.getUserName(), + newProjectFolder.getId()); - XMLDecoder xmlDecoder = new XMLDecoder(inputStream); - Project project = (Project) xmlDecoder.readObject(); - xmlDecoder.close(); + XMLDecoder xmlDecoder = new XMLDecoder(inputStream); + Project project = (Project) xmlDecoder.readObject(); + xmlDecoder.close(); - newProjectFolder = filesStorage.getFolderInfoOnWorkspace(serviceCredentials.getUserName(), - newProjectFolder.getId()); + if (project != null) { + newProjectFolder = filesStorage.getFolderInfoOnWorkspace(serviceCredentials.getUserName(), + newProjectFolder.getId()); + logger.debug("ProjectArchiver set project folder: " + newProjectFolder); + project.setProjectFolder(new ProjectFolder(newProjectFolder)); + archive(project, serviceCredentials); + logger.debug("ProjectFolder info updated"); - if (project != null) { - logger.debug("ProjectArchiver set project folder: " + newProjectFolder); - project.setProjectFolder(new ProjectFolder(newProjectFolder)); + if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null + && project.getMainCode().getItemDescription().getId() != null + && !project.getMainCode().getItemDescription().getId().isEmpty()) { - if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null) { - try { - ItemDescription newMainCodeItemDescription = filesStorage.getFileInfoOnWorkspace( - serviceCredentials.getUserName(), project.getMainCode().getItemDescription().getId()); - String pLink = filesStorage.getPublicLink(serviceCredentials.getUserName(), - newMainCodeItemDescription.getId()); - newMainCodeItemDescription.setPublicLink(pLink); - logger.debug("ProjectArchiver set main code: " + newMainCodeItemDescription); + try { + ItemDescription newMainCodeItemDescription = filesStorage.getFileInfoOnWorkspace( + serviceCredentials.getUserName(), project.getMainCode().getItemDescription().getId()); + String pLink = filesStorage.getPublicLink(serviceCredentials.getUserName(), + newMainCodeItemDescription.getId()); + newMainCodeItemDescription.setPublicLink(pLink); + logger.debug("ProjectArchiver set main code: " + newMainCodeItemDescription); - project.setMainCode(new MainCode(newMainCodeItemDescription)); - } catch (Throwable e) { - logger.error("ProjectArchiver error reading the main code: " + project.getMainCode().getItemDescription()); - archive(project, serviceCredentials); - throw new StatAlgoImporterServiceException("Error reading the main code of the project!"); + project.setMainCode(new MainCode(newMainCodeItemDescription)); + archive(project, serviceCredentials); + logger.debug("Main Code info updated"); + } catch (Throwable e) { + logger.error("ProjectArchiver error reading the main code: " + + project.getMainCode().getItemDescription(), e); + throw new StatAlgoImporterServiceException("Invalid main code of the project!"); + } } + + } else { + logger.debug("ProjectArchiver project retrieved is null!"); + throw new StatAlgoImporterServiceException("The project retrieved is not valid!"); } - archive(project, serviceCredentials); - } else { - logger.debug("ProjectArchiver project retrieved is null!"); - throw new StatAlgoImporterServiceException("The Project retrieved is not valid!"); + return project; + } catch (StatAlgoImporterServiceException e) { + logger.error("Error reading the project info: " + e.getLocalizedMessage(), e); + throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); + } catch (Throwable e) { + logger.error("Error reading the project info: " + e.getLocalizedMessage(), e); + throw new StatAlgoImporterServiceException("Invalid project info"); } - - return project; } }