|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
|
|
|
|
@ -15,6 +16,10 @@ import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
|
|
|
|
|
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
|
|
|
|
|
import org.gcube.application.geoportal.common.rest.TempFile;
|
|
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
|
|
|
@ -30,10 +35,10 @@ 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.MongoServiceUtil.ConcessioneValidationReportStatusComparator;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
|
|
|
@ -41,8 +46,8 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
|
|
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
|
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
|
|
|
|
@ -56,6 +61,7 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.mongodb.BasicDBObject;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
@ -409,160 +415,190 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the list concessioni.
|
|
|
|
|
* Query on mongo.
|
|
|
|
|
*
|
|
|
|
|
* @param start the start
|
|
|
|
|
* @param offset the offset
|
|
|
|
|
* @param limit the limit
|
|
|
|
|
* @param filter the filter
|
|
|
|
|
* @param recordType the record type
|
|
|
|
|
* @param reloadFromService the reload from service
|
|
|
|
|
* @return the list concessioni
|
|
|
|
|
* @return the result set paginated data
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SortFilter filter,
|
|
|
|
|
private ResultSetPaginatedData queryOnMongo(Integer offset, Integer limit, SearchingFilter filter, String recordType,
|
|
|
|
|
boolean reloadFromService) throws Exception {
|
|
|
|
|
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
|
|
|
|
|
reloadFromService);
|
|
|
|
|
int listConcessioniSize = listOfConcessioni.size();
|
|
|
|
|
|
|
|
|
|
List<Concessione> toReturn = new ArrayList<Concessione>();
|
|
|
|
|
int startIndex;
|
|
|
|
|
int limitIndex = 0;
|
|
|
|
|
if (start == null && limit == null) {
|
|
|
|
|
startIndex = 0;
|
|
|
|
|
limitIndex = listConcessioniSize;
|
|
|
|
|
} else {
|
|
|
|
|
startIndex = start;
|
|
|
|
|
limitIndex = start + limit;
|
|
|
|
|
if (limitIndex > listConcessioniSize) {
|
|
|
|
|
|
|
|
|
|
if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) {
|
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
MongoServiceUtil serviceUtil = new MongoServiceUtil();
|
|
|
|
|
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
|
|
|
|
|
|
// TODO MUST BE REPLACED BY COUNT
|
|
|
|
|
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
|
|
|
|
|
reloadFromService);
|
|
|
|
|
int listConcessioniSize = listOfConcessioni.size();
|
|
|
|
|
|
|
|
|
|
Integer offsetIndex = offset;
|
|
|
|
|
Integer limitIndex = limit;
|
|
|
|
|
|
|
|
|
|
if (offset == null) {
|
|
|
|
|
offsetIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
if (limit == null) {
|
|
|
|
|
limitIndex = listConcessioniSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(start, limit, startIndex, false);
|
|
|
|
|
searchedData.setTotalItems(listConcessioniSize);
|
|
|
|
|
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false);
|
|
|
|
|
searchedData.setTotalItems(listConcessioniSize);
|
|
|
|
|
|
|
|
|
|
RECORD_FIELD orderBy = null;
|
|
|
|
|
ORDER order = null;
|
|
|
|
|
ConcessioneValidationReportStatusComparator statusComparator = null;
|
|
|
|
|
List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>();
|
|
|
|
|
Direction sDirection = null;
|
|
|
|
|
List<String> fields = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
if (filter == null) {
|
|
|
|
|
// unsorted list of records
|
|
|
|
|
toReturn = listOfConcessioni.subList(startIndex, limitIndex);
|
|
|
|
|
} else {
|
|
|
|
|
if (filter == null) {
|
|
|
|
|
LOG.info("No filter found, creating empty filter");
|
|
|
|
|
filter = new SearchingFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderBy = filter.getOrderByField();
|
|
|
|
|
order = filter.getOrder();
|
|
|
|
|
ORDER order = filter.getOrder();
|
|
|
|
|
|
|
|
|
|
if (orderBy == null)
|
|
|
|
|
orderBy = RECORD_FIELD.NAME;
|
|
|
|
|
if (order == null) {
|
|
|
|
|
sDirection = Direction.ASCENDING;
|
|
|
|
|
LOG.info("No direction/order found, using default: " + sDirection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (order == null)
|
|
|
|
|
order = ORDER.ASC;
|
|
|
|
|
switch (order) {
|
|
|
|
|
case ASC:
|
|
|
|
|
sDirection = Direction.ASCENDING;
|
|
|
|
|
break;
|
|
|
|
|
case DESC:
|
|
|
|
|
sDirection = Direction.DESCENDING;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CASE INSENSITIVE COMPARATOR
|
|
|
|
|
Comparator<Concessione> comparator = null;
|
|
|
|
|
RECORD_FIELD orderByFields = filter.getOrderByField();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
if (orderByFields == null) {
|
|
|
|
|
orderByFields = RECORD_FIELD.NAME;
|
|
|
|
|
LOG.info("No fields for searching found, using default: " + orderByFields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (orderByFields) {
|
|
|
|
|
case NAME:
|
|
|
|
|
fields.add(RECORD_FIELD.NAME.getJsonFieldName());
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
fields.add(RECORD_FIELD.CREATED.getJsonFieldName());
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
fields.add(RECORD_FIELD.CREATED_BY.getJsonFieldName());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// TODO is buggy must be performed by service
|
|
|
|
|
case PROJECT_START_END_DATE:
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
fields.add("dataInizioProgetto");
|
|
|
|
|
fields.add("dataFineProgetto");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECORD_STATUS:
|
|
|
|
|
statusComparator = new ConcessioneValidationReportStatusComparator();
|
|
|
|
|
fields.add("report:status");
|
|
|
|
|
// statusComparator = new ConcessioneValidationReportStatusComparator();
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sorting with nullsLast
|
|
|
|
|
if (comparator != null)
|
|
|
|
|
listOfConcessioni.sort(Comparator.nullsLast(comparator));
|
|
|
|
|
|
|
|
|
|
// solution quick&dirty
|
|
|
|
|
try {
|
|
|
|
|
if (statusComparator != null) {
|
|
|
|
|
if (order.equals(ORDER.ASC)) {
|
|
|
|
|
listOfConcessioni.sort(Comparator.nullsLast(statusComparator));
|
|
|
|
|
} else {
|
|
|
|
|
Collections.sort(listOfConcessioni, Comparator.nullsLast(
|
|
|
|
|
Collections.reverseOrder(new ConcessioneValidationReportStatusComparator())));
|
|
|
|
|
}
|
|
|
|
|
QueryRequest request = new QueryRequest();
|
|
|
|
|
PagedRequest paging = new PagedRequest();
|
|
|
|
|
paging.setOffset(offsetIndex);
|
|
|
|
|
paging.setLimit(limitIndex);
|
|
|
|
|
request.setPaging(paging);
|
|
|
|
|
|
|
|
|
|
OrderedRequest ordering = new OrderedRequest();
|
|
|
|
|
ordering.setDirection(sDirection);
|
|
|
|
|
ordering.setFields(fields);
|
|
|
|
|
request.setOrdering(ordering);
|
|
|
|
|
|
|
|
|
|
if(filter.getSearchInto()!=null) {
|
|
|
|
|
Map<String, Object> searchFields = filter.getSearchInto();
|
|
|
|
|
//List<BasicDBObject> list = new ArrayList<BasicDBObject>();
|
|
|
|
|
//Map map = new HashMap<BasicDBObject, BasicDBObject>();
|
|
|
|
|
Document query = new Document();
|
|
|
|
|
|
|
|
|
|
for (String key : searchFields.keySet()) {
|
|
|
|
|
query.put(key, searchFields.get(key));
|
|
|
|
|
query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.warn("comparator Exception: " + e.getMessage());
|
|
|
|
|
|
|
|
|
|
request.setFilter(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
|
|
|
|
|
LOG.info("Direction: " + sDirection);
|
|
|
|
|
LOG.info("Order by Fields: " + fields);
|
|
|
|
|
LOG.info("Search for: " + filter.getSearchInto());
|
|
|
|
|
|
|
|
|
|
Iterator<Concessione> concessioni = clientMongo.query(request);
|
|
|
|
|
while (concessioni.hasNext()) {
|
|
|
|
|
Concessione concessione = concessioni.next();
|
|
|
|
|
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
|
|
|
|
|
toReturnList.add(concessioneDV);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.trace("sorted list: " + listOfConcessioni);
|
|
|
|
|
// pagination
|
|
|
|
|
toReturn = listOfConcessioni.subList(startIndex, limitIndex);
|
|
|
|
|
}
|
|
|
|
|
searchedData.setData(toReturnList);
|
|
|
|
|
|
|
|
|
|
List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>(toReturn.size());
|
|
|
|
|
if (listConcessioniSize == limit || listConcessioniSize == 0) {
|
|
|
|
|
LOG.debug("Page completed returning " + listConcessioniSize + " items");
|
|
|
|
|
int newOffset = offsetIndex + limitIndex;
|
|
|
|
|
searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0);
|
|
|
|
|
LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
|
|
|
|
|
|
|
|
|
|
for (Concessione concessione : toReturn) {
|
|
|
|
|
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
|
|
|
|
|
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);
|
|
|
|
|
LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
|
|
|
|
|
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta
|
|
|
|
|
/**
|
|
|
|
|
* List display fields.
|
|
|
|
|
*
|
|
|
|
|
* @return the list
|
|
|
|
|
*/
|
|
|
|
|
// Profile
|
|
|
|
|
public List<DisplayField> listDisplayFields() {
|
|
|
|
|
|
|
|
|
|
List<DisplayField> listDisplayFields = new ArrayList<DisplayField>();
|
|
|
|
|
|
|
|
|
|
DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true);
|
|
|
|
|
// etc
|
|
|
|
|
|
|
|
|
|
return listDisplayFields;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the list concessioni.
|
|
|
|
|
*
|
|
|
|
|
* @param start the start
|
|
|
|
|
* @param limit the limit
|
|
|
|
|
* @param filter the filter
|
|
|
|
|
* @param reloadFromService the reload from service
|
|
|
|
|
* @return the list concessioni
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
|
|
|
|
|
boolean reloadFromService) throws Exception {
|
|
|
|
|
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
|
|
|
|
|
return queryOnMongo(start, limit, filter, "concessione", reloadFromService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -848,6 +884,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the my rights in the context.
|
|
|
|
|
*
|
|
|
|
|
* @return the my rights in the context
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public UserRights getMyRightsInTheContext() throws Exception {
|
|
|
|
|
LOG.info("getMyRightsInTheContext called");
|
|
|
|
|