diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index ebcf40f..0c84c23 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -99,7 +100,8 @@ - + + @@ -199,7 +201,8 @@ - + + @@ -299,7 +302,8 @@ - + + @@ -399,7 +403,8 @@ - + + @@ -451,16 +456,8 @@ - - uses - - - uses - - - uses - - + + @@ -560,7 +557,8 @@ - + + @@ -660,7 +658,8 @@ - + + @@ -760,7 +759,8 @@ - + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index 5fdcf17..f9c305e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -50,7 +50,7 @@ public class ConstantsGeoPortalDataEntryApp { public static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getFormat("dd MMMM yyyy"); - public static final String ALERT_MESSAGE_PROJECT_NOT_EDITABLE = "A Project can only be edited/updated in " + public static final String ALERT_MESSAGE_PROJECT_NOT_EDITABLE = "A Project can only be updated in " + WORKFLOW_PHASE.DRAFT.name() + " phase. You need to perform the step 'Reject' or 'UnPublish' to take back the project in " + WORKFLOW_PHASE.DRAFT.name() + " phase."; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index cf8cd40..c337ce1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -1869,6 +1869,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { } else { GWT.log("Instancing CreateMetadataForm with files"); List files = toListFileUploadedRemote(fileset); + GWT.log("files are: "+files); baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), appManagerBus, operation, files); } @@ -1885,21 +1886,20 @@ public class GeoPortalDataEntryApp implements EntryPoint { List fileUploaded = new ArrayList(); - FilesetDV filesetDV = fileset.get(0); - - GWT.log("listFiles name: "+filesetDV.getGcubeProfileFieldName()); + for (FilesetDV filesetDV : fileset) { + GWT.log("filesetDV fieldName: "+filesetDV.getFilesetFieldName() + " profile: "+filesetDV.getGcubeProfileFieldName()); - for (PayloadDV payload : filesetDV.getListPayload()) { - FileUploadedRemote fu = new FileUploadedRemote(); - fu.setFileName(payload.getName()); - fu.setUrl(payload.getLink()); - fu.setMimeType(payload.getMimetype()); - //adding FilePath according to spefic file registred in the UCD - FilePath filePath = new FilePath(filesetDV.getGcubeProfileFieldName(), filesetDV.getFilesetFieldName()); - fu.setFilePath(filePath); - fileUploaded.add(fu); + for (PayloadDV payload : filesetDV.getListPayload()) { + FileUploadedRemote fu = new FileUploadedRemote(); + fu.setFileName(payload.getName()); + fu.setUrl(payload.getLink()); + fu.setMimeType(payload.getMimetype()); + //adding FilePath according to spefic file registred in the UCD + FilePath filePath = new FilePath(filesetDV.getGcubeProfileFieldName(), filesetDV.getFilesetFieldName()); + fu.setFilePath(filePath); + fileUploaded.add(fu); + } } - return fileUploaded; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java index dcc68dd..d6ca574 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java @@ -242,6 +242,8 @@ public class UpdateRecord extends Composite { htmlMsg += "
    "; htmlMsg += "
  • id: " + projectID + "
  • "; htmlMsg += "
  • profile: " + profileID + "
  • "; + htmlMsg += "
  • " + theDocument.getFirstEntryOfMap().getKey() + ": " + + theDocument.getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "
"; panelContainer.add(new HTML(htmlMsg)); @@ -280,9 +282,11 @@ public class UpdateRecord extends Composite { htmlMsg += "
    "; htmlMsg += "
  • id: " + projectID + "
  • "; htmlMsg += "
  • profile: " + profileID + "
  • "; + htmlMsg += "
  • " + theDocument.getFirstEntryOfMap().getKey() + ": " + + theDocument.getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "
"; - htmlMsg += "has been updated correctly!"; + htmlMsg += "has been updated successfully!"; alert.setHTML(htmlMsg); ReportTemplateToHTML rtth2 = new ReportTemplateToHTML("Project", result.getProjectAsJSON(), diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index abafecb..806b3bd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -237,41 +237,65 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("and sectionPath {}", sectionPath); LOG.info("and listFilePaths {}", listFilePaths); + ProjectsCaller client = null; + Project currentProject = null; + JSONObject updatedSectionObject = null; + Configuration configurationGson = null; + GenericDatasetBean sectionBean = null; try { + if (projectID == null) + throw new Exception("projectID is null"); + + if (profileID == null) + throw new Exception("profileID is null"); + if (section == null || section.getListGDB() == null || section.getListGDB().get(0) == null) throw new Exception("Input error. The section is null"); - GenericDatasetBean sectionBean = section.getListGDB().get(0); + sectionBean = section.getListGDB().get(0); // Converter FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON(); // JSON Section to update converted as JSONObject - JSONObject updatedSectionObject = metadataConverter.genericDatasetBeanToJSON(sectionBean); + updatedSectionObject = metadataConverter.genericDatasetBeanToJSON(sectionBean); LOG.info("Input Json Section (to update): {}", updatedSectionObject.toString()); - Configuration configurationGson = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); + configurationGson = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); // Type type = new TypeToken>>() {}.getType(); // Set> myMap = gson.fromJson(json, type); + } catch (Exception e) { + LOG.error("Error on converting form data: ", e); + throw new Exception( + "Error occurred on converting data, try again or contact the support. Error: " + e.getMessage()); + } + + Boolean errorOccurred = false; + + try { + + client = GeoportalClientCaller.projects(); + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + currentProject = client.getProjectByID(profileID, projectID); + Document currentDoc = currentProject.getTheDocument(); + // Source Project - String theDocumentJson = getJSONDocumentInTheProject(profileID, projectID); - LOG.info("Source document: {}", theDocumentJson); + String theDocumentJson = currentDoc.toJson(); + LOG.debug("Source document: {}", theDocumentJson); // If the section path is the Root document, passed as "$.", fixing as "$" if (sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0) sectionPath = FormDataObjectToJSON.JSON_$_POINTER; - ProjectsCaller client = GeoportalClientCaller.projects(); - com.google.gson.JsonObject targetSectionJObject = JsonPath.parse(theDocumentJson, configurationGson) .read(sectionPath); - LOG.info("Current Section path {} in the Document is {}", sectionPath, targetSectionJObject.toString()); + LOG.debug("Current Section path {} in the Document is {}", sectionPath, targetSectionJObject.toString()); String srcJ = updatedSectionObject.toString(); String trgJ = targetSectionJObject.toString(); - LOG.info("Merging src {} in the target: {}", srcJ, trgJ); + LOG.debug("Merging src {} in the target: {}", srcJ, trgJ); String mergedDoc = JsonMerge.merge(srcJ, trgJ, MERGE_OPTION.REPLACE); - LOG.info("mergedDoc: {}", mergedDoc); + LOG.debug("mergedDoc: {}", mergedDoc); String newDocJson; // If Updating path is first level of the root @@ -293,9 +317,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class); LOG.info("New document is: {}", updatedDocument.toJson()); - Project project = client.updateProject(profileID, projectID, updatedDocument); + Project updatedProject = client.updateProject(profileID, projectID, updatedDocument); // Project project = client.getProjectByID(profileID, projectID); - LOG.debug("Medatata Updated with document: {}", project.getTheDocument()); + LOG.debug("Medatata Updated with document: {}", updatedProject.getTheDocument()); SessionUtil.getCurrentContext(getThreadLocalRequest(), true); @@ -310,29 +334,44 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen filesetPath = filesetPath.replaceFirst("\\.", ".."); LOG.info("Going to delete fileset path: {}", filesetPath); try { - client.deleteFileset(profileID, projectID, filesetPath, true); + client.deleteFileset(profileID, projectID, filesetPath, true, true); } catch (Exception e) { - LOG.warn("Error on into project id {} the fileset path {} ", projectID, filesetPath); + LOG.warn("Error deleting the fileset path {} for the project {}", filesetPath, projectID); } } // Registering new files List filesUploaded = sectionBean.getFilesUploaded(); if (filesUploaded != null && !filesUploaded.isEmpty()) { - replaceFiles(project, sectionPath, section.getGcubeProfileDV(), filesUploaded); + replaceFiles(currentProject, sectionPath, section.getGcubeProfileDV(), filesUploaded); } } - LOG.info("Project with id " + project.getId() + " updated correclty"); + LOG.info("Project with id " + currentProject.getId() + " updated correclty"); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); - ProjectDV toProjectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); + // Reading again the project to be sure + updatedProject = client.getProjectByID(profileID, projectID); + ProjectDV toProjectDV = ConvertToDataValueObjectModel.toProjectDV(updatedProject, projectBuilder); String newDocumentString = toProjectDV.getTheDocument().getDocumentAsJSON(); LOG.info("Got Document: {} ", newDocumentString); return new CommitReport(projectID, profileID, newDocumentString, null); } catch (Exception e) { - LOG.error("Error on converting form data: ", e); - throw new Exception( - "Error occurred on converting data, try again or contact the support. Error: " + e.getMessage()); + errorOccurred = true; + LOG.error("Error on updating data: ", e); + throw new Exception("Error occurred on updating data, try again or contact the support. Error: " + + e.getMessage() + ". Tried to revert the project to the previous version"); + } finally { + + // If an error occurs on updating, the previous version of the document will be + // restored + if (errorOccurred && currentProject != null) { + Document currentDocument = currentProject.getTheDocument(); + try { + Project updatedProject = client.updateProject(profileID, projectID, currentDocument); + } catch (Exception e) { + // Silent + } + } } } diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java index 0fd76a6..d43c983 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java @@ -196,7 +196,7 @@ public class Complex_Tests { } - @Test + //@Test public void testSectionPathRootParse() throws Exception { String sectionPath = "$.";