Passed to list of AccessPoint to APIMapBox

This commit is contained in:
Francesco Mangiacrapa 2023-12-20 15:36:51 +01:00
parent fe8fd981b0
commit 0b4a357037
4 changed files with 43 additions and 13 deletions

View File

@ -163,7 +163,7 @@ public class Geoportal_PDF_Exporter {
isAddTimpestampCreatedAt = pdfExporterConfigs.getTimestampCreatedAt();
}
ServiceAccessPoint sap = MapBoxEndpointReader.getMapBoxEndpoint();
List<ServiceAccessPoint> listSAP = MapBoxEndpointReader.getMapBoxEndpoint();
PdfDocument pdfDocument = null;
ByteArrayOutputStream out = null;
@ -267,7 +267,7 @@ public class Geoportal_PDF_Exporter {
if (theProjectDV.getSpatialReference() != null) {
String geoJSON = theProjectDV.getSpatialReference().getGeoJSON();
if (geoJSON != null && !geoJSON.isEmpty()) {
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid, sap);
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid, listSAP.get(0));
if (downMapBoxImg != null) {
Image backgroundImage = toImageFromLink(downMapBoxImg, 250);
if (backgroundImage != null) {
@ -283,6 +283,9 @@ public class Geoportal_PDF_Exporter {
}
}
}
//Getting API MapBox Access Point
ServiceAccessPoint sap = listSAP.size()>1?listSAP.get(1):listSAP.get(0);
for (SectionView section : projectView.getListSections()) {
document = appendSubDocumentToPDF(document, section, section.getListSubDocuments(),
@ -323,6 +326,7 @@ public class Geoportal_PDF_Exporter {
pdfFileURL = String.format("%s?contentType=%s&fileName=%s&content-disposition=%s", storageURL,
"application/pdf", tempFile.getFilename(), "inline");
LOG.info("returning pdf URL: " + pdfFileURL);
// TEST save file locally
// File targetFile = new File(projectTitleSanitized + ".pdf");

View File

@ -158,7 +158,7 @@ public class Geoportal_PDF_Exporter_double_layer {
isAddTimpestampCreatedAt = pdfExporterConfigs.getTimestampCreatedAt();
}
ServiceAccessPoint sap = MapBoxEndpointReader.getMapBoxEndpoint();
List<ServiceAccessPoint> listSAP = MapBoxEndpointReader.getMapBoxEndpoint();
PdfDocument pdfDocument = null;
ByteArrayOutputStream out = null;
@ -262,7 +262,7 @@ public class Geoportal_PDF_Exporter_double_layer {
if (theProjectDV.getSpatialReference() != null) {
String geoJSON = theProjectDV.getSpatialReference().getGeoJSON();
if (geoJSON != null && !geoJSON.isEmpty()) {
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid, sap);
String downMapBoxImg = linkToMarkerURLViaMapBoxStaticMap(geoJSON, 7, mapSizeWithCentroid, listSAP.get(0));
if (downMapBoxImg != null) {
Image backgroundImage = toImageFromLink(downMapBoxImg, 250);
if (backgroundImage != null) {
@ -278,6 +278,9 @@ public class Geoportal_PDF_Exporter_double_layer {
}
}
}
//Getting API MapBox Access Point
ServiceAccessPoint sap = listSAP.size()>1?listSAP.get(1):listSAP.get(0);
for (SectionView section : projectView.getListSections()) {
document = appendSubDocumentToPDF(document, section, section.getListSubDocuments(),

View File

@ -3,6 +3,7 @@ package org.gcube.application.geoportaldatamapper.reader;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -15,6 +16,13 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class MapBoxEndpointReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 20, 2023
*/
public class MapBoxEndpointReader {
private static Logger LOG = LoggerFactory.getLogger(MapBoxEndpointReader.class);
@ -23,17 +31,17 @@ public class MapBoxEndpointReader {
private static final String SE_CATEGORY_NAME = "OnlineService";
/**
* Gets the list base maps.
* Gets the map box endpoint.
*
* @return the list base maps
* @return the map box endpoint
* @throws Exception the exception
*/
public static ServiceAccessPoint getMapBoxEndpoint() throws Exception {
public static List<ServiceAccessPoint> getMapBoxEndpoint() throws Exception {
LOG.info("Searching SE in the scope: " + ScopeProvider.instance.get() + " with profile name: " + SE_PROFILE_NAME
+ " and category name: " + SE_CATEGORY_NAME);
ServiceAccessPoint ap = new ServiceAccessPoint();
List<ServiceAccessPoint> listSAP = new ArrayList<ServiceAccessPoint>();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '" + SE_PROFILE_NAME + "'");
@ -66,15 +74,23 @@ public class MapBoxEndpointReader {
throw new RuntimeException("Error on decrypting the pwd: ", e);
}
ServiceAccessPoint ap = new ServiceAccessPoint();
ap.setUrl(url);
ap.setApiTokenName(apiTokenName);
ap.setApiTokenPwd(apiTokenPwd);
listSAP.add(ap);
}
return ap;
return listSAP;
}
/**
* Checks if is valorized.
*
* @param value the value
* @return true, if is valorized
*/
private static boolean isValorized(String value) {
if (value != null && !value.isEmpty()) {
return true;

View File

@ -4,7 +4,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
@ -43,7 +45,8 @@ public class Geoportal_Export_To_PDF_Tests {
private static String PROFILE_ID = "profiledConcessioni";
private static String[] PROJECT_IDS = { "6388e4f8a1e60e66b7b584ac", "6388d9b3a1e60e66b7b5843a",
"646353c5d7fb4a4633022803", "63f8c481e9d6ac16f394f1e6", "638888fba1e60e66b7b581dd",
"650304487814b87373631242", "6388ea17a1e60e66b7b584dd", "64537208d7fb4a4633022039", "638885fea1e60e66b7b581bd"};
"650304487814b87373631242", "6388ea17a1e60e66b7b584dd", "64537208d7fb4a4633022039",
"638885fea1e60e66b7b581bd" };
// private static String[] PROJECT_IDS = { "646353c5d7fb4a4633022803" };
@ -120,8 +123,12 @@ public class Geoportal_Export_To_PDF_Tests {
//@Test
public void apiMapBoxServiceEndpointReader() {
try {
ServiceAccessPoint se = MapBoxEndpointReader.getMapBoxEndpoint();
System.out.println(se);
List<ServiceAccessPoint> listSAP = MapBoxEndpointReader.getMapBoxEndpoint();
String result = listSAP.stream().map(sap -> String.valueOf(sap)).collect(Collectors.joining("\n"));
System.out.println(result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -131,7 +138,7 @@ public class Geoportal_Export_To_PDF_Tests {
/**
* Test read project view.
*/
//@Test
@Test
public void testExportToPDF() {
ScopeProvider.instance.set(CONTEXT);