@ -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. Mongo ServiceUtil.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( ) ;
Mongo ServiceUtil serviceUtil = new Mongo ServiceUtil( ) ;
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 < TempFile > ardsFiles = serviceUtil . toTemFiles ( ards . getFilesUploaded ( ) ) ;
// TODO MUST BE UNIFIED WI TH RELAZIONE OPPURE BISOGNA PREVEDERE UN
// TODO DEVE ESSERE PASSATO CON PA TH 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 < 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 ) { 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<Concessione> 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 < ConcessioneDV > toReturnList = new
* ArrayList < ConcessioneDV > ( 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( ) ;
Mongo ServiceUtil serviceUtil = new Mongo ServiceUtil( ) ;
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 ( ) ) ;
}
}
}