Pushing first version of update facility, #24166

This commit is contained in:
Francesco Mangiacrapa 2023-04-26 17:01:08 +02:00
parent fbbc84e6e4
commit bf526add90
6 changed files with 97 additions and 54 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -99,7 +100,8 @@
<wb-module deploy-name="geoportal-data-entry-app-3.2.0-SNAPSHOT">
@ -199,7 +201,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -299,7 +302,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -399,7 +403,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -451,16 +456,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="geoportal-data-mapper-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-mapper/geoportal-data-mapper">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="metadata-profile-form-builder-widget-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-form-builder-widget/metadata-profile-form-builder-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="geoportal-data-common-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -560,7 +557,8 @@
<property name="context-root" value="geoportal-data-entry-app"/>
@ -660,7 +658,8 @@
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
@ -760,7 +759,8 @@
</wb-module>

View File

@ -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.";

View File

@ -1869,6 +1869,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
} else {
GWT.log("Instancing CreateMetadataForm with files");
List<? extends FileUploaded> 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<FileUploadedRemote> fileUploaded = new ArrayList<FileUploadedRemote>();
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;
}

View File

@ -242,6 +242,8 @@ public class UpdateRecord extends Composite {
htmlMsg += "<ul>";
htmlMsg += "<li>id: " + projectID + "</li>";
htmlMsg += "<li>profile: " + profileID + "</li>";
htmlMsg += "<li>" + theDocument.getFirstEntryOfMap().getKey() + ": "
+ theDocument.getFirstEntryOfMap().getValue() + "</li>";
htmlMsg += "</ul>";
htmlMsg += "<br>";
panelContainer.add(new HTML(htmlMsg));
@ -280,9 +282,11 @@ public class UpdateRecord extends Composite {
htmlMsg += "<ul>";
htmlMsg += "<li>id: " + projectID + "</li>";
htmlMsg += "<li>profile: " + profileID + "</li>";
htmlMsg += "<li>" + theDocument.getFirstEntryOfMap().getKey() + ": "
+ theDocument.getFirstEntryOfMap().getValue() + "</li>";
htmlMsg += "</ul>";
htmlMsg += "<br>";
htmlMsg += "has been updated correctly!";
htmlMsg += "has been updated successfully!";
alert.setHTML(htmlMsg);
ReportTemplateToHTML rtth2 = new ReportTemplateToHTML("Project", result.getProjectAsJSON(),

View File

@ -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<Set<LinkedTreeMap<String, Object>>>() {}.getType();
// Set<LinkedTreeMap<String, Object>> 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<? extends FileUploaded> 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
}
}
}
}

View File

@ -196,7 +196,7 @@ public class Complex_Tests {
}
@Test
//@Test
public void testSectionPathRootParse() throws Exception {
String sectionPath = "$.";