From a551e572c58192bb010de74d3a6b191f47cfc2b8 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 16 Sep 2021 12:15:07 +0200 Subject: [PATCH] completed REAMDE. Added calls server-side --- CHANGELOG.md | 3 +- README.md | 7 + .../client/GeoportalDataEntryService.java | 4 + .../GeoportalDataEntryServiceAsync.java | 6 + .../server/GeoportalDataEntryServiceImpl.java | 210 ++++++++---------- ...ServiceUtil.java => MongoServiceUtil.java} | 18 +- .../server/SessionUtil.java | 2 +- 7 files changed, 124 insertions(+), 126 deletions(-) rename src/main/java/org/gcube/portlets/user/geoportaldataentry/server/{ServiceUtil.java => MongoServiceUtil.java} (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddf49a5..9013656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#20435] Client integration with MongoConcessioni Moved to maven-portal-bom 3.6.3 -[#21856] Implementing new user feedback +[#21856] Implemented new user feedback [#21890] Passed to mongoID [#20599] Get List of Records [#22002] Integrated with ValidationReport and status +[#21990] Provide the (first version of) edit mode ## [v1.2.0] - 2020-12-18 diff --git a/README.md b/README.md index c5195e3..30b0a92 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,13 @@ The GeoPortal Data Entry App is an application to build the web forms for data e * [OpenJDK](https://openjdk.java.net/) - The JDK used * [Maven](https://maven.apache.org/) - Dependency Management +**Uses** + +* GWT v.2.9.0. [GWT](http://www.gwtproject.org) is licensed under [Apache License 2.0](http://www.gwtproject.org/terms.html) +* GWT-Bootstrap v.2.3.2.0. [GWT-Bootstrap](https://github.com/gwtbootstrap) is licensed under [[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) +* pretty-print-json v.1.1. [pretty-print-json](https://github.com/center-key/pretty-print-json) is licensed under [MIT](https://github.com/center-key/pretty-print-json/blob/main/LICENSE.txt) +* jsoneditor v.9.5.5. [jsoneditor](https://github.com/josdejong/jsoneditor) is licensed under [Apache License 2.0](https://github.com/josdejong/jsoneditor/blob/master/LICENSE) + ## Documentation N/A diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index 2e4a3ca..0c8ab0e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -70,4 +70,8 @@ public interface GeoportalDataEntryService extends RemoteService { * @return true, if successful */ boolean deleteRecord(String itemId, RECORD_TYPE recordType) throws Exception; + + String getJSONRecord(String itemId, RECORD_TYPE recordType) throws Exception; + + String updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index ac5a768..806af14 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -53,4 +53,10 @@ public interface GeoportalDataEntryServiceAsync void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); + + + void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); + + + void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback callback); } 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 b235e07..94c963a 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 @@ -26,7 +26,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; -import org.gcube.portlets.user.geoportaldataentry.server.ServiceUtil.ConcessioneValidationReportStatusComparator; +import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil.ConcessioneValidationReportStatusComparator; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; @@ -86,7 +86,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Concessione concessioneNew; String mongoId = null; - ServiceUtil serviceUtil = new ServiceUtil(); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = null; try { @@ -224,7 +224,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen // Building TempFile for ABSTRACT DELLA RELAZIONE DI SCAVO SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); List ardsFiles = serviceUtil.toTemFiles(ards.getFilesUploaded()); - // TODO MUST BE UNIFIED WITH RELAZIONE OPPURE BISOGNA PREVEDERE UN + // TODO DEVE ESSERE PASSATO CON PATH RELAZIONE OPPURE BISOGNA PREVEDERE UN // ABSTRACT_RELAZIONE??? if (ardsFiles != null && ardsFiles.size() > 0) { // saving into back-end @@ -408,110 +408,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen return item; } - /* - * @Override public ResultSetPaginatedData getListConcessioni(Integer start, - * Integer limit, SortFilter filter, boolean reloadFromService) throws Exception - * { LOG.info("getListConcessioni called wit start: " + start + ", limit: " + - * limit + ", filter: " + filter); - * - * try { List listOfConcessioni = - * SessionUtil.getListOfConcessioni(getThreadLocalRequest(), reloadFromService); - * int listConcessioniSize = listOfConcessioni.size(); - * - * List toReturn = new ArrayList(); int startIndex; - * int limitIndex = 0; if (start == null && limit == null) { startIndex = 0; - * limitIndex = listConcessioniSize; } else { startIndex = start; limitIndex = - * start + limit; if (limitIndex > listConcessioniSize) { limitIndex = - * listConcessioniSize; } } - * - * ResultSetPaginatedData searchedData = new ResultSetPaginatedData(start, - * limit, startIndex, false); searchedData.setTotalItems(listConcessioniSize); - * - * if (filter == null) { // unsorted list of records toReturn = - * listOfConcessioni.subList(startIndex, limitIndex); } else { - * - * RECORD_FIELD orderBy = filter.getOrderByField(); ORDER order = - * filter.getOrder(); - * - * if (orderBy == null) orderBy = RECORD_FIELD.NAME; - * - * if (order == null) order = ORDER.ASC; - * - * ResultSetSorted resultSetSorted = - * SessionUtil.getLatestResultSetSorted(getThreadLocalRequest()); boolean - * latestOrderBy = - * resultSetSorted.getSearchFilter().getOrderByField().equals(orderBy); boolean - * latestOrder = resultSetSorted.getSearchFilter().getOrder().equals(order); - * - * //Checking if SortFilter is new (different to previous one used). If yes - * sorting again if(resultSetSorted==null || !latestOrderBy || !latestOrder) { - * - * // CASE INSENSITIVE COMPARATOR Comparator comparator = null; - * switch (orderBy) { case NAME: if (order.equals(ORDER.ASC)) { comparator = - * Comparator.comparing(Concessione::getNome, - * Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)); } else { comparator = - * Comparator .comparing(Concessione::getNome, - * Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)) .reversed(); } - * - * break; case CREATED: if (order.equals(ORDER.ASC)) { comparator = - * Comparator.comparing(Concessione::getCreationTime, - * Comparator.nullsLast(Comparator.naturalOrder())); } else { comparator = - * Comparator.comparing(Concessione::getCreationTime, - * Comparator.nullsLast(Comparator.naturalOrder())).reversed(); } break; - * - * case CREATED_BY: if (order.equals(ORDER.ASC)) { comparator = - * Comparator.comparing(Concessione::getCreationUser, - * Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)); } else { comparator = - * Comparator.comparing(Concessione::getCreationUser, - * Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)).reversed(); } break; - * - * case PROJECT_START: if (order.equals(ORDER.ASC)) { comparator = - * Comparator.comparing(Concessione::getDataInizioProgetto, - * Comparator.nullsLast(Comparator.naturalOrder())); } else { comparator = - * Comparator.comparing(Concessione::getDataInizioProgetto, - * Comparator.nullsLast(Comparator.naturalOrder())).reversed(); } break; - * - * default: break; } - * - * // sorting with nullsLast - * listOfConcessioni.sort(Comparator.nullsLast(comparator)); - * Log.debug("sorted list: " + listOfConcessioni); //saving in session the - * ResultSetSorted with SortFilter and ordered data ResultSetSorted rsSorted = - * new ResultSetSorted(new SortFilter(orderBy, order), listOfConcessioni); - * SessionUtil.setLatestResultSetSorted(getThreadLocalRequest(),rsSorted); - * - * }else { //Using the ResultSet sorted at previous request listOfConcessioni = - * resultSetSorted.getData(); } - * - * // pagination toReturn = listOfConcessioni.subList(startIndex, limitIndex); } - * - * List toReturnList = new - * ArrayList(toReturn.size()); - * - * for (Concessione concessione : toReturn) { ConcessioneDV concessioneDV = - * ConvertToDataViewModel.toBaseConcessione(concessione); - * toReturnList.add(concessioneDV); } - * - * - * searchedData.setData(toReturnList); - * - * if (listConcessioniSize == limit || listConcessioniSize == 0) { - * LOG.debug("Page completed returning " + listConcessioniSize + " items"); int - * newOffset = startIndex + start; - * searchedData.setServerSearchFinished(newOffset > listConcessioniSize || - * listConcessioniSize == 0); LOG.debug("is Search finished: " + - * searchedData.isServerSearchFinished()); return searchedData; } - * - * LOG.debug("Returning: " + toReturnList); - * LOG.info("Returning list of concessioni with size: " + toReturnList.size()); - * return searchedData; } catch (Exception e) { - * LOG.error("Error on loading list of concessioni: ", e); throw new - * Exception("Error occurred on loading list of Concessioni. Error: " + - * e.getMessage()); } - * - * } - */ - /** * Gets the list concessioni. * @@ -552,7 +448,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen RECORD_FIELD orderBy = null; ORDER order = null; ConcessioneValidationReportStatusComparator statusComparator = null; - + if (filter == null) { // unsorted list of records toReturn = listOfConcessioni.subList(startIndex, limitIndex); @@ -622,21 +518,20 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen // sorting with nullsLast if (comparator != null) listOfConcessioni.sort(Comparator.nullsLast(comparator)); - - //solution quick&dirty + + // solution quick&dirty try { - if(statusComparator!=null) { - if(order.equals(ORDER.ASC)) { + if (statusComparator != null) { + if (order.equals(ORDER.ASC)) { listOfConcessioni.sort(Comparator.nullsLast(statusComparator)); - } - else { - Collections.sort(listOfConcessioni, Comparator.nullsLast(Collections.reverseOrder(new ConcessioneValidationReportStatusComparator()))); + } else { + Collections.sort(listOfConcessioni, Comparator.nullsLast( + Collections.reverseOrder(new ConcessioneValidationReportStatusComparator()))); } } - }catch (Exception e) { + } catch (Exception e) { LOG.warn("comparator Exception: " + e.getMessage()); } - LOG.debug("sorted list: " + listOfConcessioni); // pagination @@ -649,7 +544,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); toReturnList.add(concessioneDV); } - + searchedData.setData(toReturnList); if (listConcessioniSize == limit || listConcessioniSize == 0) { @@ -698,8 +593,17 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } } + /** + * Delete record. + * + * @param itemId the item id + * @param recordType the record type + * @return true, if successful + * @throws Exception the exception + */ @Override public boolean deleteRecord(String itemId, RECORD_TYPE recordType) throws Exception { + LOG.info("deleteRecord called with itemId: " + itemId + ", recordType: " + recordType); try { if (itemId == null) @@ -707,7 +611,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen if (recordType.equals(RECORD_TYPE.CONCESSIONE)) { SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - ServiceUtil serviceUtil = new ServiceUtil(); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); clientMongo.deleteById(itemId); return true; @@ -721,4 +625,72 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on deleting the project with id: " + itemId + ". Error: " + e.getMessage()); } } + + /** + * Update record. + * + * @param itemId the item id + * @param jsonUpdate the json update + * @param recordType the record type + * @return the updated JSON string representing the itemId + * @throws Exception the exception + */ + @Override + public String updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception { + LOG.info("updateRecord called with itemId: " + itemId + ", recordType: " + recordType); + try { + + if (itemId == null) + throw new Exception("Item id is null"); + + LOG.debug("jsonUpdate is: " + jsonUpdate); + if (recordType.equals(RECORD_TYPE.CONCESSIONE)) { + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); + MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + Concessione concessione = clientMongo.update(itemId, jsonUpdate); + return serviceUtil.toJSON(concessione); + } + + return null; + + } catch (Exception e) { + LOG.error("Error on updating the project with item id: " + itemId, e); + throw new Exception( + "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); + } + } + + /** + * Gets the JSON record. + * + * @param itemId the item id + * @param recordType the record type + * @return the JSON record representing the itemId + * @throws Exception the exception + */ + @Override + public String getJSONRecord(String itemId, RECORD_TYPE recordType) throws Exception { + LOG.info("getJSONRecord called with itemId: " + itemId + ", recordType: " + recordType); + try { + + if (itemId == null) + throw new Exception("Item id is null"); + + if (recordType.equals(RECORD_TYPE.CONCESSIONE)) { + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); + MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + Concessione concessione = clientMongo.getById(itemId); + return serviceUtil.toJSON(concessione); + } + + return null; + + } catch (Exception e) { + LOG.error("Error on reading the JSON project with item id: " + itemId, e); + throw new Exception( + "Error occurred on reading the JSON project with id: " + itemId + ". Error: " + e.getMessage()); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java similarity index 91% rename from src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java rename to src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java index e63c458..e10ac71 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java @@ -20,16 +20,17 @@ import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** - * The Class ServiceUtil. + * The Class MongoServiceUtil. * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Jan 28, 2021 + * Sep 16, 2021 */ -public class ServiceUtil { +public class MongoServiceUtil { - private static Logger LOG = LoggerFactory.getLogger(ServiceUtil.class); + private static Logger LOG = LoggerFactory.getLogger(MongoServiceUtil.class); /** * Gets the instance mongo concessioni. @@ -136,6 +137,13 @@ public class ServiceUtil { } + /** + * The Class ConcessioneDVValidationReportStatusComparator. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 16, 2021 + */ public static class ConcessioneDVValidationReportStatusComparator implements Comparator { /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java index 03f06c2..0b6e5eb 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -145,7 +145,7 @@ public class SessionUtil { listOfConcessioni = new ArrayList(); LOG.info("Loading list of concessione from client mongo"); SessionUtil.getCurrentContext(httpServletRequest, true); - ServiceUtil serviceUtil = new ServiceUtil(); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); Iterator concessioni = clientMongo.getList();