Improved queryOnMongo and JUnit tests
This commit is contained in:
parent
41e3dc28d9
commit
83f6fb915c
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
|
@ -74,6 +75,7 @@ public class ProjectsCaller {
|
|||
Document myDocument = Document.parse(jsonDocument);
|
||||
Projects<Project> client = getClient(profileID);
|
||||
Project project = client.createNew(myDocument);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -251,8 +253,9 @@ public class ProjectsCaller {
|
|||
}
|
||||
|
||||
Map<String, Object> projection = filter.getProjection();
|
||||
|
||||
Document projectionDocument = null;
|
||||
if(projection!=null) {
|
||||
if(projection!=null && !projection.isEmpty()) {
|
||||
projectionDocument = new Document(projection);
|
||||
}
|
||||
|
||||
|
@ -262,10 +265,6 @@ public class ProjectsCaller {
|
|||
paging.setLimit(limitIndex);
|
||||
request.setPaging(paging);
|
||||
|
||||
if(projectionDocument!=null) {
|
||||
request.setProjection(projectionDocument);
|
||||
}
|
||||
|
||||
OrderedRequest ordering = new OrderedRequest();
|
||||
ordering.setDirection(sDirection);
|
||||
ordering.setFields(orderingFields);
|
||||
|
@ -281,7 +280,7 @@ public class ProjectsCaller {
|
|||
searchWithOperator = LOGICAL_OP.OR;
|
||||
}
|
||||
|
||||
if (whereClause.getSearchInto() != null) {
|
||||
if (whereClause.getSearchInto() != null && !whereClause.getSearchInto().isEmpty()) {
|
||||
Map<String, Object> searchFields = whereClause.getSearchInto();
|
||||
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
|
||||
for (String key : searchFields.keySet()) {
|
||||
|
@ -312,7 +311,36 @@ public class ProjectsCaller {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(projectionDocument!=null) {
|
||||
request.setProjection(projectionDocument);
|
||||
|
||||
//THE first field specified in the projection must be not null
|
||||
BasicDBObject bsNotEqualEmpty = new BasicDBObject();
|
||||
bsNotEqualEmpty.append("$ne", null);
|
||||
|
||||
Optional<String> firstKey = projection.keySet().stream().findFirst();
|
||||
if (firstKey.isPresent()) {
|
||||
String firstFieldPath = firstKey.get();
|
||||
query.append(firstFieldPath, bsNotEqualEmpty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
BasicDBObject bsValid_Document = new BasicDBObject();
|
||||
bsValid_Document.append("$exists", true);
|
||||
bsValid_Document.append("$ne", null);
|
||||
query.append("_theDocument", bsValid_Document);
|
||||
|
||||
BasicDBObject bsDocumentExists = new BasicDBObject();
|
||||
bsDocumentExists.append("$exists", false);
|
||||
query.append("theDocument", bsDocumentExists);
|
||||
|
||||
// BasicDBObject bsNotEqualEmpty = new BasicDBObject();
|
||||
// bsNotEqualEmpty.append("$ne", null);
|
||||
// query.append("_theDocument.nome", bsNotEqualEmpty);
|
||||
|
||||
request.setFilter(query);
|
||||
|
||||
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
|
||||
|
@ -355,8 +383,8 @@ public class ProjectsCaller {
|
|||
return searchedData;
|
||||
|
||||
} catch (Exception 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());
|
||||
LOG.error("Error on loading paginated and filtered list of Project: ", e);
|
||||
throw new Exception("Error occurred on loading list of Project. Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ public class UseCaseDescriptorCaller {
|
|||
listUCD.add(prg);
|
||||
|
||||
}
|
||||
|
||||
LOG.info("returning {} {}", listUCD.size(), UseCaseDescriptor.class.getName());
|
||||
return listUCD;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
package org.gcube.application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
||||
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
||||
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
||||
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
|
||||
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
|
||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
||||
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.LifecycleInformationDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
@ -22,6 +31,7 @@ public class Project_Tests {
|
|||
private static String CONTEXT = "/gcube/devsec/devVRE";
|
||||
private static String TOKEN = ""; // devVRE
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROJECT_ID = "6226220daf515916fdb54e08";
|
||||
|
||||
@Before
|
||||
public void getClient() {
|
||||
|
@ -31,7 +41,7 @@ public class Project_Tests {
|
|||
client = GeoportalClientCaller.projects();
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void getList() throws Exception {
|
||||
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
||||
|
||||
|
@ -40,8 +50,16 @@ public class Project_Tests {
|
|||
System.out.println(++i + ") " + project);
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getByID() throws Exception {
|
||||
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
||||
System.out.println(projectDV);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void getListProjectsDV() throws Exception {
|
||||
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
|
@ -52,4 +70,57 @@ public class Project_Tests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getListProjectsDVFiltered() throws Exception {
|
||||
//List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
||||
|
||||
SearchingFilter filter = new SearchingFilter();
|
||||
|
||||
|
||||
//Where Clause
|
||||
List<WhereClause> conditions = new ArrayList<WhereClause>();
|
||||
Map<String, Object> searchInto = new HashMap<String, Object>();
|
||||
//searchInto.put("_id", "61f0299baf51592c36795f52");
|
||||
//searchInto.put("_theDocument.nome", "Test progetto con clustering di fileset");
|
||||
WhereClause whereClause = new WhereClause(LOGICAL_OP.AND, searchInto);
|
||||
conditions.add(whereClause);
|
||||
filter.setConditions(conditions);
|
||||
|
||||
Map<String, Object> projection = new HashMap<String, Object>();
|
||||
//default
|
||||
projection.put("_profileID", 1);
|
||||
projection.put("_profileVersion", 1);
|
||||
projection.put("_version", 1);
|
||||
projection.put("_theDocument", 1);
|
||||
|
||||
projection.put("_theDocument.paroleChiaveLibere", 1);
|
||||
projection.put("_theDocument.editore", 1);
|
||||
projection.put("_theDocument.paroleChiaveICCD", 1);
|
||||
projection.put("_theDocument.nome", 1);
|
||||
projection.put("_theDocument.responsabile", 1);
|
||||
projection.put("_theDocument.authors", 1);
|
||||
|
||||
projection.put("_theDocument.nome", 1);
|
||||
projection.put("_theDocument.introduzione", 1);
|
||||
projection.put("_theDocument.authors", 1);
|
||||
filter.setProjection(projection);
|
||||
|
||||
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
||||
ResultSetPaginatedData results = client.queryOnMongo(PROFILE_ID, 300, 0, 10, filter, projectBuilder);
|
||||
int i = 0;
|
||||
for (ProjectDV projectDV : results.getData()) {
|
||||
System.out.println(++i + ") " + projectDV);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getLifecycleForProjectId() throws Exception {
|
||||
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
|
||||
LifecycleInformation lci = project.getLifecycleInformation();
|
||||
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lci);
|
||||
System.out.println(liDV);
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,16 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.utils.FileSets;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
||||
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
||||
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Before;
|
||||
|
@ -27,7 +32,7 @@ public class UCD_Tests {
|
|||
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
|
||||
//@Before
|
||||
@Before
|
||||
public void getClient() {
|
||||
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
|
@ -70,7 +75,7 @@ public class UCD_Tests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getUCDForDataEntryHandlerIds() throws Exception {
|
||||
public void getUCDFor_DataEntry_HandlerIds() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
|
@ -99,16 +104,15 @@ public class UCD_Tests {
|
|||
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
||||
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
||||
}
|
||||
|
||||
|
||||
for (UseCaseDescriptorDV useCaseDescriptorDV : listUCDDV) {
|
||||
System.out.println("Found: "+useCaseDescriptorDV);
|
||||
System.out.println("Found: " + useCaseDescriptorDV);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//@Test
|
||||
public void getUCDForDatalistHandlerIds() throws Exception {
|
||||
|
||||
// @Test
|
||||
public void getUCDFor_DataList_HandlerIds() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
|
@ -137,9 +141,115 @@ public class UCD_Tests {
|
|||
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
||||
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
||||
}
|
||||
|
||||
|
||||
System.out.println(listUCDDV);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConfigurations_ForUCD_Data_Handlers() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
List<String> handlersIds = null;
|
||||
List<UseCaseDescriptor> listUseCaseDescriptor;
|
||||
try {
|
||||
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
||||
|
||||
if (handlersIds == null) {
|
||||
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
|
||||
System.out.println("handlersIds is null, so using default: " + handlersIds);
|
||||
}
|
||||
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
|
||||
} catch (Exception e) {
|
||||
String error = "Error on contacting the Geoportal service";
|
||||
System.out.println(error + " for handlers: " + handlersIds);
|
||||
throw new Exception(
|
||||
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
|
||||
}
|
||||
|
||||
if (listUseCaseDescriptor == null) {
|
||||
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
|
||||
}
|
||||
|
||||
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
|
||||
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
|
||||
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
|
||||
}
|
||||
|
||||
for (UseCaseDescriptorDV useCaseDescriptorDV : listUCDDV) {
|
||||
System.out.println("\n");
|
||||
System.out.println("UCD name:" + useCaseDescriptorDV.getName());
|
||||
System.out.println("UCD profileID:" + useCaseDescriptorDV.getProfileID());
|
||||
List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers();
|
||||
for (HandlerDeclarationDV handler : handlers) {
|
||||
ConfigurationDV<?> config = handler.getConfiguration();
|
||||
System.out.println("\tConfig type:" + config.getConfigurationType());
|
||||
//System.out.println("\tConfig:" + config.getConfiguration());
|
||||
switch (config.getConfigurationType()) {
|
||||
case gcube_profiles:
|
||||
List<GcubeProfileDV> listProfiles = toListGcubeProfiles(config);
|
||||
System.out.println("\t\t"+listProfiles);
|
||||
break;
|
||||
case item_fields:
|
||||
List<ItemFieldDV> listItems = toListItemFields(config);
|
||||
System.out.println("\t\t"+listItems);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void registrerFileSets() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
||||
// FileSets.build(TOKEN, PROFILE_ID, CONTEXT)
|
||||
|
||||
// System.out.println(listUCDDV);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To list gcube profiles.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the list
|
||||
*/
|
||||
private List<GcubeProfileDV> toListGcubeProfiles(ConfigurationDV<?> config) {
|
||||
|
||||
try {
|
||||
return (List<GcubeProfileDV>) config.getConfiguration();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
|
||||
+ GcubeProfileDV.class.getName());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* To list item fields.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the list
|
||||
*/
|
||||
private List<ItemFieldDV> toListItemFields(ConfigurationDV<?> config) {
|
||||
|
||||
try {
|
||||
return (List<ItemFieldDV>) config.getConfiguration();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error on casting " + ConfigurationDV.class.getName() + " to List of "
|
||||
+ ItemFieldDV.class.getName());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"_id": "org.gcube.geoportal-data-list",
|
||||
"_id": "org.gcube.portlets.user.geoportal-data-list",
|
||||
"_type": "DATA_LIST_GUI",
|
||||
"case": "FullList",
|
||||
"_configuration": {
|
||||
"projection": "{\"nome\" : 1, \"lifecycleInformation.phase\" : 1}",
|
||||
"projection": "{\"_theDocument\" : 1, \"lifecycleInformation.phase\" : 1}",
|
||||
"itemFields": [
|
||||
{
|
||||
"label": "Name",
|
||||
"paths": [
|
||||
"Nome del progetto"
|
||||
"nome"
|
||||
],
|
||||
"operator": "$and",
|
||||
"searchable": true,
|
||||
|
@ -18,7 +18,7 @@
|
|||
{
|
||||
"label": "Introduction",
|
||||
"paths": [
|
||||
"Introduzione"
|
||||
"introduzione"
|
||||
],
|
||||
"operator": "$and",
|
||||
"searchable": true,
|
||||
|
@ -28,7 +28,7 @@
|
|||
{
|
||||
"label": "Author/s",
|
||||
"paths": [
|
||||
"Nome Autore, Email, Ruolo"
|
||||
"authors"
|
||||
],
|
||||
"operator": "$and",
|
||||
"searchable": false,
|
||||
|
@ -38,7 +38,7 @@
|
|||
{
|
||||
"label": "Project Start",
|
||||
"paths": [
|
||||
"Data inizio Progetto"
|
||||
"dataInizioProgetto"
|
||||
],
|
||||
"operator": "$and",
|
||||
"searchable": false,
|
||||
|
@ -48,11 +48,11 @@
|
|||
{
|
||||
"label": "Director/Staff",
|
||||
"paths": [
|
||||
"Nome Autore, Email, Ruolo",
|
||||
"Contributore",
|
||||
"Titolare dei dati",
|
||||
"Editore",
|
||||
"Responsabile"
|
||||
"authors",
|
||||
"contributore",
|
||||
"titolari",
|
||||
"editore",
|
||||
"responsabile"
|
||||
],
|
||||
"operator": "$or",
|
||||
"searchable": true,
|
||||
|
@ -62,8 +62,8 @@
|
|||
{
|
||||
"label": "Keywords",
|
||||
"paths": [
|
||||
"Parola chiave a scelta libera",
|
||||
"Parola chiave relativa alla cronologia"
|
||||
"paroleChiaveLibere",
|
||||
"paroleChiaveICCD"
|
||||
],
|
||||
"operator": "$or",
|
||||
"searchable": true,
|
||||
|
@ -72,4 +72,4 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue