Integrated with the Geoportal_Resolver service [#25031]

This commit is contained in:
Francesco Mangiacrapa 2023-05-02 17:56:30 +02:00
parent f0508b4fd9
commit 0fd55e8a58
7 changed files with 156 additions and 98 deletions

View File

@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [v2.1.0-SNAPSHOT] - 2023-04-12
- Integrated the deleteFileset method [#24977]
- Integrated with the Geoportal_Resolver service [#25031]
## [v2.0.3] - 2023-02-09

View File

@ -3,11 +3,15 @@ package org.gcube.application.geoportalcommon;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Map;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
import org.gcube.application.geoportalcommon.shared.PublicLink;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,39 +21,30 @@ import org.slf4j.LoggerFactory;
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 5, 2021
* May 2, 2023
*/
public class GeoportalCommon {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(GeoportalCommon.class);
private GNADataViewerConfigProfile geonaDataProfile;
/**
* Instantiates a new geoportal common.
*/
public GeoportalCommon() {
}
/**
* Instantiates a new geoportal common.
*
* @param geonaDataProfile the geona data profile
*/
public GeoportalCommon(GNADataViewerConfigProfile geonaDataProfile) {
this.geonaDataProfile = geonaDataProfile;
}
/**
* Gets the public links for.
*
* @param gcubeScope the gcube scope
* @param item the item
* @param createShortURL creates and returns the short URL also.
* @return the public links for
* @throws Exception the exception
*/
public GeoportalItemReferences getPublicLinksFor(GeoportalItemReferences item, boolean createShortURL) throws Exception {
public GeoportalItemReferences getPublicLinksFor(String gcubeScope, GeoportalItemReferences item,
boolean createShortURL) throws Exception {
LOG.info("getPublicLinksFor called for: " + item);
try {
@ -63,14 +58,16 @@ public class GeoportalCommon {
if (item.getProfileID() == null)
throw new Exception("Bad request, the ProfileID is null");
if (this.geonaDataProfile == null)
this.geonaDataProfile = readGNADataViewerConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
// Restricted Link
String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, item.getProjectID(),
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, item.getProfileID());
UriResolverManager resolver = new UriResolverManager("GEO");
// PRIVATE LINK
GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(item.getProfileID(),
item.getProjectID());
builder.scope(gcubeScope);
builder.resolverAs(RESOLVE_AS.PRIVATE);
// builder.resolverAs(RESOLVE_AS.PRIVATE);
Map<String, String> params = builder.buildQueryParameters();
String link = resolver.getLink(params, false);
String shortUrl = link;
try {
if (createShortURL)
@ -80,14 +77,14 @@ public class GeoportalCommon {
}
item.setRestrictedLink(new PublicLink(link, shortUrl));
// Open Link
link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
GeoportalCommonConstants.GET_GEONA_ITEM_ID, item.getProjectID(),
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, item.getProfileID());
// PUBLIC LINK
builder.resolverAs(RESOLVE_AS.PUBLIC);
params = builder.buildQueryParameters();
link = resolver.getLink(params, false);
shortUrl = link;
try {
shortUrl = getShortUrl(link);
if (createShortURL)
shortUrl = getShortUrl(link);
} catch (Exception e) {
LOG.warn("Error on shortening the URL: ", e);
}
@ -147,15 +144,6 @@ public class GeoportalCommon {
}
}
/**
* Gets the geona data profile.
*
* @return the geona data profile
*/
public GNADataViewerConfigProfile getGeonaDataProfile() {
return geonaDataProfile;
}
/**
* Read GNA data viewer config.
*

View File

@ -1,6 +1,8 @@
package org.gcube.application;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@ -11,6 +13,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@ -25,6 +28,7 @@ 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.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
import org.gcube.application.geoportalcommon.shared.WhereClause;
@ -34,8 +38,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.project.PhaseDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
@ -49,22 +51,21 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Project_Tests {
private static ProjectsCaller client = null;
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; //preVRE
private static final String GCUBE_CONFIG_PROPERTIES_FILENAME = "gcube_config.properties";
// APP Working Directory + /src/test/resources must be the location of
// gcube_config.properties
private static String gcube_config_path = String.format("%s/%s",
System.getProperty("user.dir") + "/src/test/resources", GCUBE_CONFIG_PROPERTIES_FILENAME);
private static String CONTEXT;
private static String TOKEN;
private static UseCaseDescriptorCaller clientUCD = null;
private static ProjectsCaller clientPrj = null;
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "642d3a1ac2133270c058ebe5";
private static String PROJECT_ID = "644a66e944aad51c80409a3b";
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; // preVRE
// private static String PROFILE_ID = "profiledConcessioni";
// private static String PROJECT_ID = "642d3a1ac2133270c058ebe5";
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; // preVRE
private static String MY_LOGIN = "francesco.mangiacrapa";
private static final String FOLLOWS = "follows";
private static final String PRECEDES = "precedes";
@ -76,17 +77,41 @@ public class Project_Tests {
}
@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
/**
* Read context settings.
*/
public static void readContextSettings() {
try (InputStream input = new FileInputStream(gcube_config_path)) {
Properties prop = new Properties();
// load a properties file
prop.load(input);
CONTEXT = prop.getProperty("CONTEXT");
TOKEN = prop.getProperty("TOKEN");
// get the property value and print it out
System.out.println("CONTEXT: " + CONTEXT);
System.out.println("TOKEN: " + TOKEN);
} catch (IOException ex) {
ex.printStackTrace();
}
}
// @Before
public void init() {
readContextSettings();
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
client = GeoportalClientCaller.projects();
clientPrj = GeoportalClientCaller.projects();
clientUCD = GeoportalClientCaller.useCaseDescriptors();
}
// @Test
public void getList() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
List<Project> listOfProjects = clientPrj.getListForProfileID(PROFILE_ID);
int i = 0;
for (Project project : listOfProjects) {
@ -96,7 +121,7 @@ public class Project_Tests {
// @Test
public void getByID() throws Exception {
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
Project project = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
System.out.println(projectDV);
@ -109,25 +134,23 @@ public class Project_Tests {
System.out.println(projectDV.getSpatialReference());
}
//@Test
public void checkDocumentSerDes() throws Exception {
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
String documentValueAsJson = project.getTheDocument().toJson();
System.out.println("1 "+documentValueAsJson);
String updatedDocumentAsJson = new Document(Project.THE_DOCUMENT,documentValueAsJson).toJson();
System.out.println("2 "+updatedDocumentAsJson);
Document setUpdatedDocument = new Document("$set", updatedDocumentAsJson);
System.out.println("3 "+setUpdatedDocument);
}
// @Test
public void checkDocumentSerDes() throws Exception {
Project project = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
String documentValueAsJson = project.getTheDocument().toJson();
System.out.println("1 " + documentValueAsJson);
String updatedDocumentAsJson = new Document(Project.THE_DOCUMENT, documentValueAsJson).toJson();
System.out.println("2 " + updatedDocumentAsJson);
Document setUpdatedDocument = new Document("$set", updatedDocumentAsJson);
System.out.println("3 " + setUpdatedDocument);
}
// @Test
public void getListProjectsDV() throws Exception {
List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
List<Project> listOfProjects = clientPrj.getListForProfileID(PROFILE_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
int i = 0;
for (Project project : listOfProjects) {
@ -201,8 +224,8 @@ public class Project_Tests {
filter.setProjection(projection);
Integer totalDocs = client.getTotalDocument(PROFILE_ID);
Iterator<Project> projects = client.queryOnMongo(PROFILE_ID, totalDocs, 0, null, filter);
Integer totalDocs = clientPrj.getTotalDocument(PROFILE_ID);
Iterator<Project> projects = clientPrj.queryOnMongo(PROFILE_ID, totalDocs, 0, null, filter);
Iterable<Project> itP = () -> projects;
Stream<Project> targetStream = StreamSupport.stream(itP.spliterator(), false);
List<String> listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList());
@ -259,7 +282,7 @@ public class Project_Tests {
// @Test
public void getLifecycleForProjectId() throws Exception {
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
Project project = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
LifecycleInformation lci = project.getLifecycleInformation();
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lci);
System.out.println(liDV);
@ -268,23 +291,23 @@ public class Project_Tests {
// @Test
public void getConfiguration() throws Exception {
Configuration config = client.getConfiguration(PROFILE_ID);
Configuration config = clientPrj.getConfiguration(PROFILE_ID);
System.out.println(config);
}
// @Test
public void getTotalDocument() throws Exception {
System.out.println(client.getTotalDocument(PROFILE_ID));
System.out.println(clientPrj.getTotalDocument(PROFILE_ID));
}
// @Test
public void getListPhases() throws Exception {
List<String> idsPhases = client.getIDsPhases(PROFILE_ID);
List<String> idsPhases = clientPrj.getIDsPhases(PROFILE_ID);
System.out.println(idsPhases);
PhaseDV[] phases = client.getPhasesIntoDocumentStoreCollection(PROFILE_ID);
PhaseDV[] phases = clientPrj.getPhasesIntoDocumentStoreCollection(PROFILE_ID);
for (PhaseDV phaseDV : phases) {
System.out.println(phaseDV);
}
@ -294,13 +317,13 @@ public class Project_Tests {
// @Test
public void getRelationshipsChain() throws Exception {
System.out.println("getRelationshipsChain test");
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
Project project = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
List<Relationship> relations = project.getRelationships();
for (Relationship relationship : relations) {
System.out.println("\n\ngetRelationshipsChain for " + relationship);
Iterator<RelationshipNavigationObject> iterator = client.getRelationshipChain(PROFILE_ID, PROJECT_ID,
Iterator<RelationshipNavigationObject> iterator = clientPrj.getRelationshipChain(PROFILE_ID, PROJECT_ID,
relationship.getRelationshipName(), true);
while (iterator.hasNext()) {
@ -386,7 +409,7 @@ public class Project_Tests {
}
}
//@Test
// @Test
public void testEvaluateRelationshipsChain() throws Exception {
System.out.println("testEvaluateRelationshipsChain test");
@ -400,7 +423,7 @@ public class Project_Tests {
PROJECT_ID = "63c80aebacb8c7657b858741";
Project project = client.getProjectByID(PROFILE_ID, PROJECT_ID);
Project project = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
evaluateAdditionalIndexParameters(project);
@ -438,7 +461,7 @@ public class Project_Tests {
List<String> toHideIds = new ArrayList<>();
log.info("projects are: " + projects.size());
// Reverse Order means from the last FOLLOW to the first one (temporal reverse
// order)
Collections.sort(projects, Collections.reverseOrder(new ProjectRelationComparator()));
@ -582,7 +605,7 @@ public class Project_Tests {
// target.setProfileID(relationship.getTargetUCD());
// target.setId(relationship.getTargetID());
Project target = client.getProjectByID(relationship.getTargetUCD(), relationship.getTargetID());
Project target = clientPrj.getProjectByID(relationship.getTargetUCD(), relationship.getTargetID());
linkedProject.setTarget(target);
if (recurse) {

View File

@ -1,45 +1,92 @@
package org.gcube.application;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
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 final String GCUBE_CONFIG_PROPERTIES_FILENAME = "gcube_config.properties";
// APP Working Directory + /src/test/resources must be the location of
// gcube_config.properties
private static String gcube_config_path = String.format("%s/%s",
System.getProperty("user.dir") + "/src/test/resources", GCUBE_CONFIG_PROPERTIES_FILENAME);
private static String CONTEXT;
private static String TOKEN;
private static String TOKEN = "";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
private static UseCaseDescriptorCaller clientUCD = null;
private static ProjectsCaller clientPrj = null;
private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "644a66e944aad51c80409a3b";
private static String MY_LOGIN = "francesco.mangiacrapa";
/**
* Read context settings.
*/
public static void readContextSettings() {
try (InputStream input = new FileInputStream(gcube_config_path)) {
Properties prop = new Properties();
// load a properties file
prop.load(input);
CONTEXT = prop.getProperty("CONTEXT");
TOKEN = prop.getProperty("TOKEN");
// get the property value and print it out
System.out.println("CONTEXT: " + CONTEXT);
System.out.println("TOKEN: " + TOKEN);
} catch (IOException ex) {
ex.printStackTrace();
}
}
//@Before
public void init() {
readContextSettings();
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
clientPrj = GeoportalClientCaller.projects();
clientUCD = GeoportalClientCaller.useCaseDescriptors();
}
// @Test
public GNADataViewerConfigProfile getGeoNaDataViewProfile() throws Exception {
public void getGeoNaDataViewProfile() throws Exception {
System.out.println("getGeoNaDataViewProfile called");
ScopeProvider.instance.set(CONTEXT);
GeoportalCommon gc = new GeoportalCommon();
GNADataViewerConfigProfile profile = gc.readGNADataViewerConfig(null);
System.out.println("Returning profile: " + profile);
return profile;
}
// @Test
public GeoportalItemReferences getLinks() throws Exception {
System.out.println("getGeoNaDataViewProfile called");
//@Test
public void getLinks() throws Exception {
System.out.println("getLinks called");
ScopeProvider.instance.set(CONTEXT);
GeoportalCommon gc = new GeoportalCommon();
GeoportalItemReferences item = new GeoportalItemReferences("", "concessione");
GeoportalItemReferences links = gc.getPublicLinksFor(item, true);
return links;
GeoportalItemReferences item = new GeoportalItemReferences(PROJECT_ID, PROFILE_ID);
GeoportalItemReferences links = gc.getPublicLinksFor(CONTEXT, item, true);
System.out.println(links);
}
// @Test

View File

@ -26,8 +26,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;

View File

@ -7,9 +7,9 @@ import java.util.ArrayList;
import java.util.List;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;

View File

@ -18,3 +18,4 @@
/FARM.gcubekey
/gCubeApps.gcubekey
/devVRE.gcubekey
/gcube_config.properties