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@174652 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-12-07 11:02:49 +00:00
parent 46aacfc420
commit ab7baa8e4b
2 changed files with 46 additions and 33 deletions

View File

@ -466,7 +466,7 @@ public class FilesStorage {
} }
} catch (Throwable e) { } 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()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} }
} }
@ -536,7 +536,7 @@ public class FilesStorage {
return itemDescription; return itemDescription;
} catch (Throwable e) { } 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()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} }
} }
@ -566,7 +566,7 @@ public class FilesStorage {
return itemDescription; return itemDescription;
} catch (Throwable e) { } 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()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} }
} }

View File

@ -50,45 +50,58 @@ public class ProjectArchiver {
public static Project readProject(ItemDescription newProjectFolder, ServiceCredentials serviceCredentials) public static Project readProject(ItemDescription newProjectFolder, ServiceCredentials serviceCredentials)
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
FilesStorage filesStorage = new FilesStorage(); try {
InputStream inputStream = filesStorage.getProjectItemOnWorkspace(serviceCredentials.getUserName(), FilesStorage filesStorage = new FilesStorage();
newProjectFolder.getId()); InputStream inputStream = filesStorage.getProjectItemOnWorkspace(serviceCredentials.getUserName(),
newProjectFolder.getId());
XMLDecoder xmlDecoder = new XMLDecoder(inputStream); XMLDecoder xmlDecoder = new XMLDecoder(inputStream);
Project project = (Project) xmlDecoder.readObject(); Project project = (Project) xmlDecoder.readObject();
xmlDecoder.close(); xmlDecoder.close();
newProjectFolder = filesStorage.getFolderInfoOnWorkspace(serviceCredentials.getUserName(), if (project != null) {
newProjectFolder.getId()); 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) { if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null
logger.debug("ProjectArchiver set project folder: " + newProjectFolder); && project.getMainCode().getItemDescription().getId() != null
project.setProjectFolder(new ProjectFolder(newProjectFolder)); && !project.getMainCode().getItemDescription().getId().isEmpty()) {
if (project.getMainCode() != null && project.getMainCode().getItemDescription() != null) { try {
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); logger.debug("ProjectArchiver set main code: " + newMainCodeItemDescription);
logger.debug("ProjectArchiver set main code: " + newMainCodeItemDescription);
project.setMainCode(new MainCode(newMainCodeItemDescription)); project.setMainCode(new MainCode(newMainCodeItemDescription));
} catch (Throwable e) { archive(project, serviceCredentials);
logger.error("ProjectArchiver error reading the main code: " + project.getMainCode().getItemDescription()); logger.debug("Main Code info updated");
archive(project, serviceCredentials); } catch (Throwable e) {
throw new StatAlgoImporterServiceException("Error reading the main code of the project!"); 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 { return project;
logger.debug("ProjectArchiver project retrieved is null!"); } catch (StatAlgoImporterServiceException e) {
throw new StatAlgoImporterServiceException("The Project retrieved is not valid!"); 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;
} }
} }