geoportal-data-common/src/test/java/org/gcube/application/TestGNACommon.java

141 lines
4.5 KiB
Java

package org.gcube.application;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.GeoportalCommonConstants;
import org.gcube.application.geoportalcommon.MongoServiceCommon;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
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.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class TestGNACommon {
private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
@Before
public void init() {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
}
// @Test
public GNADataViewerConfigProfile getGeoNaDataViewProfile() throws Exception {
System.out.println("getGeoNaDataViewProfile called");
ScopeProvider.instance.set(CONTEXT);
GeoportalCommon gc = new GeoportalCommon();
GNADataViewerConfigProfile profile = gc.readGNADataViewConfig(null);
System.out.println("Returning profile: " + profile);
return profile;
}
// @Test
public GeoNaItemRef getLinks() throws Exception {
System.out.println("getGeoNaDataViewProfile called");
ScopeProvider.instance.set(CONTEXT);
GeoportalCommon gc = new GeoportalCommon();
GeoNaItemRef item = new GeoNaItemRef("", "concessione");
GeoNaItemRef links = gc.getPublicLinksFor(item, true);
return links;
}
// @Test
public void queryConcessioniTest() throws Exception {
try {
ScopeProvider.instance.set(CONTEXT);
MongoServiceCommon msc = new MongoServiceCommon();
SearchingFilter filter = new SearchingFilter();
Map<String, Object> searchInto = new HashMap<String, Object>();
searchInto.put("nome", "san");
searchInto.put("authors", "silvia");
// searchInto.put("report.status", "PASSED");
WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto);
Map<String, Object> searchInto2 = new HashMap<String, Object>();
searchInto2.put("report.status", "PASSED");
WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2);
ArrayList<WhereClause> list = new ArrayList<WhereClause>();
list.add(where1);
// list.add(where2);
filter.setConditions(list);
ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione");
int i = 0;
for (ConcessioneDV concessione : result.getData()) {
System.out.println(++i + ") " + concessione);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void readGNDataEntryConfigsFromIS() throws Exception {
GeoportalCommon r = new GeoportalCommon();
try {
ScopeProvider.instance.set(CONTEXT);
GNADataEntryConfigProfile configurations = r.readGNADataEntryConfig();
System.out.println("Permissions are:");
int i = 0;
for (RoleRights role : configurations.getPermissionsForRole()) {
System.out.println(++i + " " + role);
}
System.out.println("Item Fields are:");
i = 0;
for (ItemField item : configurations.getListItemFields()) {
System.out.println(++i + " " + item);
}
} catch (Exception e) {
e.printStackTrace();
}
}
//@Test
public void readGNDataViewerConfigsFromIS() throws Exception {
GeoportalCommon r = new GeoportalCommon();
try {
ScopeProvider.instance.set(CONTEXT);
GNADataViewerConfigProfile configurations = r
.readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
System.out.println("Map layers are:");
System.out.println(configurations.getMapLayers());
System.out.println("Item Fields are:");
int i = 0;
for (ItemField item : configurations.getListItemFields()) {
System.out.println(++i + " " + item);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}