From 6617655492983582d923658514036b307c8fce87 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 15 Oct 2024 12:41:11 +0200 Subject: [PATCH] improved the monitoring.. --- .../client/GeoPortalDataEntryApp.java | 2 +- .../server/GeoportalDataEntryServiceImpl.java | 126 +++++++++++------- 2 files changed, 76 insertions(+), 52 deletions(-) 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 ceaa9cd..595d772 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 @@ -905,7 +905,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { break; case FAILED: icon = new Icon(IconType.WARNING_SIGN); - icon.getElement().getStyle().setColor("#800000"); + icon.getElement().getStyle().setColor("#FF0000"); icon.setSize(IconSize.TWO_TIMES); icon.setTitle(action.getStatus().getLabel()); break; 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 dd04ac9..612a9f4 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 @@ -157,8 +157,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen long startTime = System.currentTimeMillis(); LOG.info("Procedure starting at: " + startTime); final String uuidAsString = uuid.toString(); - - //Uncomment this to test the monitor + + // Uncomment this to test the monitor // if(!SessionUtil.isIntoPortal()) { // MockData.mockMonitor(uuidAsString, getThreadLocalRequest()); // return; @@ -172,18 +172,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen MongoServiceUtil mongoService = new MongoServiceUtil(); String theDocumentString = null; try { - // 1. Action to Monitoring - MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, - "Converting project metadata to Geoportal data model"); - action = monitoringActionsOnServer.pushAction(action); +// // 1. Action to Monitoring +// MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, +// "Converting project metadata to Geoportal data model"); +// action = monitoringActionsOnServer.pushAction(action); FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON(); JSONObject theDocument = metadataConverter.convert(tree_Node, null); - // 1. Action completed - action.setMsg("Converted project metadata to Geoportal data model"); - action.setStatus(STATUS.DONE); - monitoringActionsOnServer.overrideAction(action); +// // 1. Action completed +// action.setMsg("Converted project metadata to Geoportal data model"); +// action.setStatus(STATUS.DONE); +// monitoringActionsOnServer.overrideAction(action); theDocumentString = theDocument.toString(); LOG.info("Got Document: " + theDocumentString); @@ -199,13 +199,13 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.debug("Going to create the project..."); // 2. Action to Monitoring MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, - "Creating project on Geoportal Storage service"); + "Creating the project on the Geoportal storage service"); action = monitoringActionsOnServer.pushAction(action); theProject = mongoService.createNew(profileID, theDocumentString); // 2. Action completed - action.setMsg("Created project on Geoportal Storage service"); + action.setMsg("Created the project on the Geoportal storage service"); action.setStatus(STATUS.DONE); monitoringActionsOnServer.overrideAction(action); @@ -494,7 +494,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } - LOG.info("Project with id " + currentProject.getId() + " updated correclty"); + LOG.info("Project with id " + currentProject.getId() + " updated correctly"); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); // Reading again the project to be sure updatedProject = client.getProjectByID(profileID, projectID); @@ -591,7 +591,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Map collectFilesetPerFieldDef = new HashMap(); List files = gdb.getFilesUploaded(); if (files.size() > 0) { - List fileNames = files.stream().map(fl -> fl.getFileName()).collect(Collectors.toList()); + // List fileNames = files.stream().map(fl -> + // fl.getFileName()).collect(Collectors.toList()); // 1..N Monitoring Copying files // MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, // "Copying file/s: " + fileNames); @@ -645,9 +646,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen + ". Please upload it/them again and retry"); } } - + // 1..N Monitoring Fileset copied action completed -// action.setMsg("File/s " + fileNames + " copied correclty"); +// action.setMsg("File/s " + fileNames + " copied correctly"); // action.setStatus(STATUS.DONE); // monitorActions.overrideAction(action); @@ -661,12 +662,11 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen File[] fileset = uploadedFileset.getFileset(); FilePathDV filePath = uploadedFileset.getFilePathDV(); - - //Getting fileNames for the monitoring + + // Getting fileNames for the monitoring List fileNames = new ArrayList(); - if(fileset!=null) - fileNames = Arrays.asList(fileset).stream().map(f -> f.getName()) - .collect(Collectors.toList()); + if (fileset != null) + fileNames = Arrays.asList(fileset).stream().map(f -> f.getName()).collect(Collectors.toList()); Access access; // If the maxOccurs is not 1 @@ -674,43 +674,30 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("The gCube Profile with the section " + sectionJSONPath + " has maxOccurs > 1 need to manage it as array, going to add the array index"); String arraySectionJSONPAth = String.format("%s[%d]", sectionJSONPath, jpcV); - LOG.debug("registering the fileset in the array section: " + sectionJSONPath); - + LOG.debug("registering the fileset in the array section: " + arraySectionJSONPAth); access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument, arraySectionJSONPAth); + + monitoredRegisteredFileset(mongoService, monitorActions, profileID, theProject, + arraySectionJSONPAth, filePath.getFieldName(), filePath.getFieldDefinition(), access, + fileset); - // 1..N Monitoring Registering Fileset - MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, - "Registering and indexing the fileset: " + fileNames); - monitorActions.pushAction(action); - - mongoService.registerFileSet(profileID, theProject, arraySectionJSONPAth, - filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset); - - // 1..N Monitoring Fileset uploaded action completed - action.setMsg("Fileset " + fileNames + " registered correclty"); - action.setStatus(STATUS.DONE); - monitorActions.overrideAction(action); - +// mongoService.registerFileSet(profileID, theProject, arraySectionJSONPAth, +// filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset); + } else { LOG.info("The gCube Profile with the section " + sectionJSONPath + " has maxOccurs = 1"); LOG.debug("registering the fileset in the section: " + sectionJSONPath); access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument, sectionJSONPath); - // 1..N Monitoring Registering Fileset - MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, - "Registering and indexing the fileset: " + fileNames); - monitorActions.pushAction(action); + monitoredRegisteredFileset(mongoService, monitorActions, profileID, theProject, sectionJSONPath, + filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset); - mongoService.registerFileSet(profileID, theProject, sectionJSONPath, filePath.getFieldName(), - filePath.getFieldDefinition(), access, fileset); +// mongoService.registerFileSet(profileID, theProject, sectionJSONPath, filePath.getFieldName(), +// filePath.getFieldDefinition(), access, fileset); - // 1..N Monitoring Fileset uploaded action completed - action.setMsg("Fileset " + fileNames + " registered correclty"); - action.setStatus(STATUS.DONE); - monitorActions.overrideAction(action); } } @@ -725,6 +712,44 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } + private void monitoredRegisteredFileset(final MongoServiceUtil mongoService, + final MonitoringActionsOnServer monitorActions, String profileID, Project theProject, + String sectionJSONPath, String fieldName, String fieldDefinition, Access access, File... fileset) { + + // Getting fileNames for the monitoring + List fileNames = new ArrayList(); + if (fileset != null) + fileNames = Arrays.asList(fileset).stream().map(f -> f.getName()).collect(Collectors.toList()); + + // 1..N Monitoring Registering Fileset + MonitoringAction action = new MonitoringAction(STATUS.IN_PROGESS, + "Registering and indexing the fileset: " + fileNames); + monitorActions.pushAction(action); + + boolean error = false; + try { + + mongoService.registerFileSet(profileID, theProject, sectionJSONPath, fieldName, fieldDefinition, access, + fileset); + + } catch (Exception e) { + error = true; + LOG.error("Error on registering fileset: ", e); + // 1..N Monitoring Fileset not registered + action.setMsg("Fileset " + fileNames + " not registered. Error: "+e.getMessage()); + action.setStatus(STATUS.FAILED); + monitorActions.overrideAction(action); + } finally { + if (!error) { + // 1..N Monitoring Fileset registered correctly completed + action.setMsg("Fileset " + fileNames + " registered correctly"); + action.setStatus(STATUS.DONE); + monitorActions.overrideAction(action); + } + } + + } + /** * Collect files. * @@ -1169,21 +1194,20 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen client.deleteProject(profileID, projectID, true); - //To be sure project deleted + // To be sure project deleted Project deletedP = null; try { deletedP = client.getProjectByID(profileID, projectID); } catch (Exception e) { - //silent + // silent } - + if (deletedP != null) { String error = "The project with id " + projectID + " still exists"; LOG.error(error + ". Sending exception.."); throw new Exception(error); } - // Updating count of Documents in session per profileID Integer totalProjectForProfile = client.getTotalDocument(profileID); SessionUtil.setTotalDocumentForProfileID(getThreadLocalRequest(), profileID, totalProjectForProfile); @@ -1218,7 +1242,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Document updatedDocument = Serialization.read(jsonUpdate, Document.class); LOG.info("updatedDocument is {}", updatedDocument); Project project = client.updateProject(profileID, projectID, updatedDocument); - LOG.info("Project with id " + project.getId() + " updated correclty"); + LOG.info("Project with id " + project.getId() + " updated correctly"); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); return ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); } catch (Exception e) {