Merge pull request 'export_to_pdf' (#1) from export_to_pdf into master
Reviewed-on: #1
This commit is contained in:
commit
7189cc64eb
|
@ -20,7 +20,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONF
|
|||
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataDiscovery;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -126,13 +126,21 @@ public class GcubeProfilesPerUCDIdCache {
|
|||
|
||||
List<GcubeProfilesMetadataForUCD> listProfilesBean = new ArrayList<GcubeProfilesMetadataForUCD>();
|
||||
// Loading Metadata Profile from IS
|
||||
MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
|
||||
|
||||
//MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
|
||||
List<MetaDataProfileBean> listProfiles = null;
|
||||
for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
|
||||
ScopeProvider.instance.set(scope);
|
||||
GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD();
|
||||
List<MetaDataProfileBean> listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(scope,
|
||||
gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
|
||||
// List<MetaDataProfileBean> listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(scope,
|
||||
// gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
|
||||
|
||||
try {
|
||||
LOG.debug("Evaluated scope is " + scope);
|
||||
listProfiles = MetadataDiscovery.getMetadataProfilesList(scope, gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to retrieve profiles for scope " +scope, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName();
|
||||
LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles);
|
||||
|
|
|
@ -953,7 +953,20 @@ public class Geoportal_JSON_Mapper {
|
|||
} catch (Exception e) {
|
||||
LOG.error("AccessPolicy not found. Check OK");
|
||||
}
|
||||
LOG.info("It is {} accessible the section {}", isAccessible, sectionDocumentJSON);
|
||||
|
||||
//Just to print
|
||||
int toEndString = 0;
|
||||
try {
|
||||
toEndString = sectionDocumentJSON.length()/3;
|
||||
}catch (Exception e) {
|
||||
//Silent
|
||||
toEndString = 0;
|
||||
}
|
||||
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("It is {} accessible the section {}", isAccessible, sectionDocumentJSON);
|
||||
}
|
||||
LOG.info("It is {} accessible the section {}", isAccessible, sectionDocumentJSON.substring(0,toEndString)+"...");
|
||||
return isAccessible;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
public class ImageDetector {
|
||||
|
||||
public static enum COMMON_IMAGES_FORMAT {
|
||||
gif, png, jpeg, jpg, bmp, tif, tiff, svg, avif, webp
|
||||
gif, png, jpeg, jpg, bmp, svg, avif, webp
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,6 +42,37 @@ public class URLParserUtil {
|
|||
return queryParameter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of parameter.
|
||||
*
|
||||
* @param wmsParam the wms param
|
||||
* @param wmsLink the wms link
|
||||
* @param newValue the new value
|
||||
* @param addIfNotExists the add if not exists
|
||||
* @return the string
|
||||
*/
|
||||
public static String setValueOfParameter(String wmsParam, String wmsLink, String newValue, boolean addIfNotExists) {
|
||||
String toLowerWmsLink = wmsLink.toLowerCase();
|
||||
String toLowerWmsParam = wmsParam.toLowerCase();
|
||||
|
||||
int index = toLowerWmsLink.indexOf(toLowerWmsParam + "="); // END WITH CHAR "=" TO BE SURE THAT IT IS A
|
||||
// PARAMETER
|
||||
if (index > -1) {
|
||||
int indexStartValue = index + toLowerWmsParam.length() + 1; // add +1 for char '='
|
||||
int indexOfSeparator = toLowerWmsLink.indexOf("&", indexStartValue); // GET THE FIRST "&" STARTING FROM
|
||||
// INDEX VALUE
|
||||
// logger.trace("indexOfSeparator index of "+wmsParam+ " is: "+indexOfSeparator);
|
||||
int indexEndValue = indexOfSeparator != -1 ? indexOfSeparator : toLowerWmsLink.length();
|
||||
// logger.trace("end: "+indexEndValue);
|
||||
return wmsLink.substring(0, indexStartValue) + newValue
|
||||
+ wmsLink.substring(indexEndValue, wmsLink.length());
|
||||
} else if (addIfNotExists) {
|
||||
wmsLink += "&" + wmsParam + "=" + newValue;
|
||||
}
|
||||
// logger.trace("return value: "+value);
|
||||
return wmsLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract value of parameter from URL.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,148 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.application.geoportaldatamapper.exporter.beans.PDFExporterConfig;
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* Retrieves available 'PDF Exporter Config' from a single Generic Resource -
|
||||
* secondary Type : "CMS" - name : "PDF_Exporter_Config".
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Nov 20, 2023
|
||||
*/
|
||||
public class PDFExporterConfigProvider {
|
||||
|
||||
private static final String GR_SECONDARY_TYPE = "CMS";
|
||||
private static final String GR_NAME = "PDF_Exporter_Config";
|
||||
|
||||
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
|
||||
private static final String PDF_EXPORTER_CONFIG = "pdf_exporter_config";
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(PDFExporterConfigProvider.class);
|
||||
|
||||
/**
|
||||
* Instantiates a new exporter file provider.
|
||||
*/
|
||||
public PDFExporterConfigProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read configs from GR.
|
||||
*
|
||||
* @return the PDF exporter project config
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected PDFExporterConfig readConfigsFromGR() throws Exception {
|
||||
|
||||
String queryString = getGcubeGenericQueryString(GR_SECONDARY_TYPE, GR_NAME);
|
||||
LOG.info("Trying to perform query: " + queryString);
|
||||
|
||||
String pdf_exporter_onfig = null;
|
||||
PDFExporterConfig epc = null;
|
||||
String scope = ScopeProvider.instance.get();
|
||||
|
||||
if (scope == null)
|
||||
throw new Exception("Set the scope into " + ScopeProvider.class.getName());
|
||||
|
||||
try {
|
||||
|
||||
LOG.info("Trying to fetch GenericResource in the scope: " + scope + ", SecondaryType: " + GR_SECONDARY_TYPE
|
||||
+ ", Name: " + GR_NAME);
|
||||
Query q = new QueryBox(queryString);
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> appProfile = client.submit(q);
|
||||
// String item_fields = "";
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
LOG.warn("No GenericResource found in the scope: " + scope + ", SecondaryType: " + GR_SECONDARY_TYPE
|
||||
+ ", Name: " + GR_NAME);
|
||||
else {
|
||||
String elem = appProfile.get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
|
||||
|
||||
XPathHelper helper = new XPathHelper(doc.getDocumentElement());
|
||||
|
||||
List<String> currValue = null;
|
||||
String xPathExp = RESOURCE_PROFILE_BODY + "/" + PDF_EXPORTER_CONFIG;
|
||||
currValue = helper.evaluate(xPathExp);
|
||||
// System.out.println("currValue is: "+currValue);
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
pdf_exporter_onfig = currValue.get(0);
|
||||
}
|
||||
|
||||
if (pdf_exporter_onfig != null) {
|
||||
try {
|
||||
epc = fromXml(pdf_exporter_onfig, PDFExporterConfig.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
LOG.info("returning: " + epc);
|
||||
return epc;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while trying to read the GenericResource with SecondaryType " + GR_SECONDARY_TYPE
|
||||
+ "and name " + GR_NAME + " from the scope " + scope, e);
|
||||
|
||||
} finally {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @param resourceName the resource name
|
||||
* @return the gcube generic query string
|
||||
*/
|
||||
public static String getGcubeGenericQueryString(String secondaryType, String resourceName) {
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
|
||||
+ "' and $profile/Profile/Name/string() " + " eq '" + resourceName + "'" + "return $profile";
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a XML text to Object.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @param xml the xml
|
||||
* @param clazz the clazz
|
||||
* @return the t
|
||||
*/
|
||||
public <T> T fromXml(String xml, Class<T> clazz) {
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(clazz);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
//unmarshaller.setAdapter(new NormalizedStringAdapter());
|
||||
|
||||
Object o = unmarshaller.unmarshal(new StringReader(xml));
|
||||
return clazz.cast(o);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Error while deserializing a XML text to Object of type " + clazz, e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@XmlRootElement(name = "credits")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@Data
|
||||
public class Credits {
|
||||
|
||||
String header;
|
||||
String footer;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@XmlRootElement(name = "pdf_exporter_config")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@Data
|
||||
public class PDFExporterConfig {
|
||||
|
||||
private Credits credits;
|
||||
|
||||
@XmlElement(required = false)
|
||||
private Watermarker watermarker;
|
||||
|
||||
@XmlElement(required = false)
|
||||
private PageNumber pagenumber;
|
||||
|
||||
@XmlElement(name = "timestamp_created_at", required = false)
|
||||
private Boolean timestampCreatedAt;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "pagenumber")
|
||||
@Data
|
||||
public class PageNumber {
|
||||
|
||||
@XmlValue
|
||||
private String value;
|
||||
|
||||
@XmlAttribute
|
||||
private Integer fontSize;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.beans;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "watermarker")
|
||||
@Data
|
||||
public class Watermarker {
|
||||
|
||||
@XmlValue
|
||||
private String value;
|
||||
|
||||
@XmlAttribute
|
||||
private Integer fontSize;
|
||||
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.gis;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.spatial.data.geoutility.shared.BBOX;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class BBOXConverter.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Dec 18, 2023
|
||||
*/
|
||||
public class BBOXConverter {
|
||||
|
||||
Integer[] size = new Integer[2];
|
||||
Double[] bbox = new Double[4];
|
||||
public static final double EQUATOR = 40075016.68557849;
|
||||
private static Logger LOG = LoggerFactory.getLogger(BBOXConverter.class);
|
||||
|
||||
/**
|
||||
* The Class BBOXPixel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Dec 18, 2023
|
||||
*/
|
||||
public static class BBOXPixel {
|
||||
public double x;
|
||||
public double y;
|
||||
public double w;
|
||||
public double h;
|
||||
|
||||
/**
|
||||
* Instantiates a new BBOX pixel.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param w the w
|
||||
* @param h the h
|
||||
*/
|
||||
public BBOXPixel(double x, double y, double w, double h) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("BBOXPixel [x=");
|
||||
builder.append(x);
|
||||
builder.append(", y=");
|
||||
builder.append(y);
|
||||
builder.append(", w=");
|
||||
builder.append(w);
|
||||
builder.append(", h=");
|
||||
builder.append(h);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to pixel.
|
||||
*
|
||||
* @param size the size
|
||||
* @param bbox the bbox
|
||||
* @return the BBOX converter. BBOX pixel
|
||||
*/
|
||||
public static BBOXConverter.BBOXPixel convertToPixel(Integer[] size, Double[] bbox) {
|
||||
double dw = 1. / size[0];
|
||||
double dh = 1. / size[1];
|
||||
double x = (bbox[0] + bbox[1]) / 2.0;
|
||||
double y = (bbox[2] + bbox[3]) / 2.0;
|
||||
double w = bbox[1] - bbox[0];
|
||||
double h = bbox[3] - bbox[2];
|
||||
x = x * dw;
|
||||
w = w * dw;
|
||||
y = y * dh;
|
||||
h = h * dh;
|
||||
return new BBOXPixel(x, y, w, h);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to coordinate.
|
||||
*
|
||||
* @param bboxP the bbox P
|
||||
* @param size the size
|
||||
* @return the bbox
|
||||
*/
|
||||
public static BBOX convertToCoordinate(BBOXPixel bboxP, Integer[] size) {
|
||||
|
||||
double h = bboxP.h;
|
||||
double l = bboxP.x;
|
||||
double t = bboxP.y;
|
||||
double w = bboxP.w;
|
||||
|
||||
Integer img_w = size[0];
|
||||
Integer img_h = size[1];
|
||||
|
||||
double x1 = l / img_w;
|
||||
double y1 = t / img_h;
|
||||
double x2 = (l + w) / img_w;
|
||||
double y2 = (t + h) / img_h;
|
||||
return new BBOX(x1, y1, x2, y2, "");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Bbox with offset.
|
||||
*
|
||||
* @param wmsVersion the wms version
|
||||
* @param bbox the bbox
|
||||
* @param bboxOffset the bbox offset
|
||||
* @return the string
|
||||
*/
|
||||
public static String bboxWithOffset(String wmsVersion, String bbox, double bboxOffset) {
|
||||
|
||||
BBOX.COORDINATE_FORMAT bboxFormat = wmsVersion.contains("1.3") ? BBOX.COORDINATE_FORMAT.YX
|
||||
: BBOX.COORDINATE_FORMAT.XY;
|
||||
|
||||
BBOX theBBOX = new BBOX(bbox, bboxFormat);
|
||||
|
||||
// double lowerXR = theBBOX.getLowerLeftX() - (theBBOX.getLowerLeftX()*bboxOffset/100);
|
||||
// double lowerYR = theBBOX.getLowerLeftY() - (theBBOX.getLowerLeftY()*bboxOffset/100);
|
||||
// double upperXR = theBBOX.getUpperRightX() + (theBBOX.getUpperRightX()*bboxOffset/100);
|
||||
// double upperYR = theBBOX.getUpperRightY() + (theBBOX.getUpperRightY()*bboxOffset/100);
|
||||
|
||||
double lowerXR = theBBOX.getLowerLeftX() - bboxOffset;
|
||||
double lowerYR = theBBOX.getLowerLeftY() - bboxOffset;
|
||||
double upperXR = theBBOX.getUpperRightX() + bboxOffset;
|
||||
double upperYR = theBBOX.getUpperRightY() + bboxOffset;
|
||||
|
||||
return BBOX.toBBOXString(new BBOX(lowerXR, lowerYR, upperXR, upperYR, ""), bboxFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* To BBOX.
|
||||
*
|
||||
* @param wmsVersion the wms version
|
||||
* @param bbox the bbox
|
||||
* @return the bbox
|
||||
*/
|
||||
public static BBOX toBBOX(String wmsVersion, String bbox) {
|
||||
BBOX.COORDINATE_FORMAT bboxFormat = wmsVersion.contains("1.3") ? BBOX.COORDINATE_FORMAT.YX
|
||||
: BBOX.COORDINATE_FORMAT.XY;
|
||||
|
||||
return new BBOX(bbox, bboxFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts spherical web mercator to tile pixel X/Y at zoom level 0 for 256x256
|
||||
* tile size and inverts y coordinates.
|
||||
*
|
||||
* @param bbox the bbox
|
||||
* @return {L.point} point with tile pixel x and y coordinates.
|
||||
*/
|
||||
public static List<Double> mercatorToPixels(List<Double> bbox) {
|
||||
|
||||
double pixelX1 = (bbox.get(0) + (EQUATOR / 2.0)) / (EQUATOR / 256.0);
|
||||
double pixelY1 = ((bbox.get(1) - (EQUATOR / 2.0)) / (EQUATOR / -256.0));
|
||||
double pixelX2 = (bbox.get(2) + (EQUATOR / 2.0)) / (EQUATOR / 256.0);
|
||||
double pixelY2 = ((bbox.get(3) - (EQUATOR / 2.0)) / (EQUATOR / -256.0));
|
||||
return Arrays.asList(pixelX1, pixelY1, pixelX2, pixelY2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bbox offset.
|
||||
*
|
||||
* @param cMin the c min
|
||||
* @param cMax the c max
|
||||
* @return the double
|
||||
*/
|
||||
public static Double bboxOffset(String cMin, String cMax) {
|
||||
String bboxOffsetString = "0.";
|
||||
int startIndex = cMax.indexOf(".")+1;
|
||||
int lenght = cMax.length();
|
||||
if (startIndex < lenght) {
|
||||
for (int i = startIndex; i < lenght; i++) {
|
||||
if (cMin.charAt(i) == cMax.charAt(i)) {
|
||||
bboxOffsetString += "0";
|
||||
} else {
|
||||
bboxOffsetString += "1";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
bboxOffsetString = "0.0"; //no offset
|
||||
}
|
||||
|
||||
return Double.parseDouble(bboxOffsetString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Best BBOX offset.
|
||||
*
|
||||
* @param wmsVersion the wms version
|
||||
* @param source_bbox the source bbox
|
||||
* @return the double
|
||||
*/
|
||||
public static Double bestBBOXOffset(String wmsVersion, String source_bbox) {
|
||||
BBOX theBBOX = BBOXConverter.toBBOX(wmsVersion, source_bbox);
|
||||
|
||||
String xMin = new Double(theBBOX.getLowerLeftX()).toString();
|
||||
String xMax = new Double(theBBOX.getUpperRightX()).toString();
|
||||
|
||||
Double offsetWidth = bboxOffset(xMin, xMax);
|
||||
//System.out.println("offsetWidth: " + offsetWidth);
|
||||
LOG.debug("offset width: "+offsetWidth);
|
||||
|
||||
String yMin = new Double(theBBOX.getLowerLeftY()).toString();
|
||||
String yMax = new Double(theBBOX.getUpperRightY()).toString();
|
||||
Double offsetHeight = bboxOffset(yMax, yMin);
|
||||
//System.out.println("offsetHeight: " + offsetHeight);
|
||||
LOG.debug("offset width: "+offsetHeight);
|
||||
|
||||
return offsetWidth < offsetHeight ? offsetWidth : offsetHeight;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.gis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Recalculate_WGS84_Offset {
|
||||
|
||||
private String wmsVersion;
|
||||
private String sourceBBOX;
|
||||
private double bboxOffset;
|
||||
private String bboxWithOffset;
|
||||
|
||||
public Double expWidth = 500.0;
|
||||
public Double expHeight = 500.0;
|
||||
|
||||
private int aspectratioWidth;
|
||||
private int aspectratioHeight;
|
||||
private double ratio_Width_Height;
|
||||
|
||||
private Logger LOG = LoggerFactory.getLogger(Recalculate_WGS84_Offset.class);
|
||||
|
||||
public Recalculate_WGS84_Offset(String wmsVersion, String bbox, double bboxOffset) {
|
||||
this.wmsVersion = wmsVersion;
|
||||
this.sourceBBOX = bbox;
|
||||
this.bboxOffset = bboxOffset;
|
||||
LOG.trace("sourceBBOX: " + sourceBBOX);
|
||||
this.bboxWithOffset = BBOXConverter.bboxWithOffset(wmsVersion, sourceBBOX, this.bboxOffset);
|
||||
|
||||
// Calculating bounding box dimension
|
||||
List<Double> bbox3857_BB = WGS84_CoordinatesConverter.toEPSG3857_BBOX(bboxWithOffset);
|
||||
String bbox3857 = WGS84_CoordinatesConverter.toString(bbox3857_BB);
|
||||
LOG.debug("toEPSG3857_BBOX: " + bbox3857);
|
||||
ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBOX(bbox3857);
|
||||
LOG.debug("BoudingBox [width dimension, height dimension]: " + diff);
|
||||
double width = diff.get(0);
|
||||
double height = diff.get(1);
|
||||
// Calculating width/height ratio
|
||||
ratio_Width_Height = width / height;
|
||||
LOG.trace("bbox width: " + width);
|
||||
LOG.trace("bbox heigth: " + height);
|
||||
LOG.debug("bbox ratio: " + ratio_Width_Height);
|
||||
|
||||
//resizing width according to ratio width/height
|
||||
expWidth = expWidth * ratio_Width_Height;
|
||||
|
||||
this.aspectratioWidth = expWidth.intValue();
|
||||
LOG.debug("aspectratioWidth: " + aspectratioWidth);
|
||||
this.aspectratioHeight = expHeight.intValue();
|
||||
LOG.debug("aspectratioHeight: " + aspectratioHeight);
|
||||
}
|
||||
|
||||
public String getWmsVersion() {
|
||||
return wmsVersion;
|
||||
}
|
||||
|
||||
public String getSourceBBOX() {
|
||||
return sourceBBOX;
|
||||
}
|
||||
|
||||
public double getBboxOffset() {
|
||||
return bboxOffset;
|
||||
}
|
||||
|
||||
public String getBboxWithOffset() {
|
||||
return bboxWithOffset;
|
||||
}
|
||||
|
||||
public Double getExpWidth() {
|
||||
return expWidth;
|
||||
}
|
||||
|
||||
public Double getExpHeight() {
|
||||
return expHeight;
|
||||
}
|
||||
|
||||
public int getAspectratioWidth() {
|
||||
return aspectratioWidth;
|
||||
}
|
||||
|
||||
public int getAspectratioHeight() {
|
||||
return aspectratioHeight;
|
||||
}
|
||||
|
||||
public double getRatio_Width_Height() {
|
||||
return ratio_Width_Height;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package org.gcube.application.geoportaldatamapper.exporter.gis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Class WGS84_CoordinatesConverter.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Dec 18, 2023
|
||||
*/
|
||||
public class WGS84_CoordinatesConverter {
|
||||
|
||||
private static double EARTH_RADIUS = 6378137.0;
|
||||
|
||||
/**
|
||||
* From 4326 To epsg 3857.
|
||||
*
|
||||
* @param coordinates the coordinates as long/lat
|
||||
* @return the list
|
||||
*/
|
||||
public static List<Double> toEpsg3857(List<Double> coordinates) {
|
||||
double x = Math.toRadians(coordinates.get(0)) * EARTH_RADIUS;
|
||||
double y = Math.log(Math.tan(Math.PI / 4 + Math.toRadians(coordinates.get(1)) / 2)) * EARTH_RADIUS;
|
||||
return Arrays.asList(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* From 3857 To 4326.
|
||||
*
|
||||
* @param coordinates the coordinates as long/lat
|
||||
* @return the list
|
||||
*/
|
||||
public static List<Double> to4326(List<Double> coordinates) {
|
||||
double lat = Math.toDegrees(Math.atan(Math.exp(coordinates.get(1) / EARTH_RADIUS)) * 2 - Math.PI / 2);
|
||||
double lng = Math.toDegrees(coordinates.get(0) / EARTH_RADIUS);
|
||||
return Arrays.asList(lng, lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* From 4326 To EPSG 3857 BBOX.
|
||||
*
|
||||
* @param bbox the bbox
|
||||
* @return the list
|
||||
*/
|
||||
public static List<Double> toEPSG3857_BBOX(String bbox) {
|
||||
String[] parts = bbox.split(","); // remove spaces and split on ,
|
||||
double minX = Double.parseDouble(parts[0]);
|
||||
double minY = Double.parseDouble(parts[1]);
|
||||
double maxX = Double.parseDouble(parts[2]);
|
||||
double maxY = Double.parseDouble(parts[3]);
|
||||
List<Double> l1 = toEpsg3857(Arrays.asList(minX, minY));
|
||||
List<Double> l2 = toEpsg3857(Arrays.asList(maxX, maxY));
|
||||
// return String.format("%s,%s,%s,%s", l1.get(0), l1.get(1), l2.get(0),
|
||||
// l2.get(1));
|
||||
return Arrays.asList(l1.get(0), l1.get(1), l2.get(0), l2.get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @param bbox the bbox
|
||||
* @return the string
|
||||
*/
|
||||
public static String toString(List<Double> bbox) {
|
||||
return String.format("%s,%s,%s,%s", bbox.get(0), bbox.get(1), bbox.get(2), bbox.get(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* From 3857 To EPSG 4326 BBOX.
|
||||
*
|
||||
* @param bbox the bbox
|
||||
* @return the list
|
||||
*/
|
||||
public static List<Double> toEPSG4326_BBOX(String bbox) {
|
||||
String[] parts = bbox.split(","); // remove spaces and split on ,
|
||||
double minX = Double.parseDouble(parts[0]);
|
||||
double minY = Double.parseDouble(parts[1]);
|
||||
double maxX = Double.parseDouble(parts[2]);
|
||||
double maxY = Double.parseDouble(parts[3]);
|
||||
List<Double> l1 = to4326(Arrays.asList(minX, minY));
|
||||
List<Double> l2 = to4326(Arrays.asList(maxX, maxY));
|
||||
// return String.format("%s,%s,%s,%s", l1.get(0), l1.get(1), l2.get(0),
|
||||
// l2.get(1));
|
||||
return Arrays.asList(l1.get(0), l1.get(1), l2.get(0), l2.get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff BBOX.
|
||||
*
|
||||
* @param bbox the bbox
|
||||
* @return the array list
|
||||
*/
|
||||
public static ArrayList<Double> diffBBOX(String bbox) {
|
||||
String[] parts = bbox.replaceAll("\\s", "").split(","); // remove spaces and split on ,
|
||||
|
||||
double minX = Double.parseDouble(parts[0]);
|
||||
double minY = Double.parseDouble(parts[1]);
|
||||
double maxX = Double.parseDouble(parts[2]);
|
||||
double maxY = Double.parseDouble(parts[3]);
|
||||
|
||||
double width = maxX - minX;
|
||||
double height = maxY - minY;
|
||||
|
||||
ArrayList size = new ArrayList<Double>();
|
||||
size.add(width);
|
||||
size.add(height);
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
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;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
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;
|
||||
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);
|
||||
|
||||
private static final String SE_PROFILE_NAME = "API_MapBox";
|
||||
private static final String SE_CATEGORY_NAME = "OnlineService";
|
||||
|
||||
/**
|
||||
* Gets the map box endpoint.
|
||||
*
|
||||
* @return the map box endpoint
|
||||
* @throws Exception the 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);
|
||||
|
||||
List<ServiceAccessPoint> listSAP = new ArrayList<ServiceAccessPoint>();
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/text() eq '" + SE_PROFILE_NAME + "'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '" + SE_CATEGORY_NAME + "'");
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> resources = client.submit(query);
|
||||
|
||||
if (resources.size() > 0)
|
||||
LOG.info("The query returned " + resources.size() + " ServiceEndpoint/s");
|
||||
else
|
||||
throw new RuntimeException("ServiceEndpoint not found. Searching for profile name: " + SE_PROFILE_NAME
|
||||
+ " and category name: " + SE_CATEGORY_NAME + ", in the scope: " + ScopeProvider.instance.get());
|
||||
|
||||
ServiceEndpoint se = resources.get(0);
|
||||
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
|
||||
for (AccessPoint accessPoint : theAccessPoints) {
|
||||
String url = accessPoint.address();
|
||||
String apiTokenName = accessPoint.username();
|
||||
String apiTokenPwd = accessPoint.password();
|
||||
LOG.debug("Found API_TOKEN name: " + apiTokenName + ", encrypted token: " + apiTokenPwd);
|
||||
// decrypting the pwd
|
||||
try {
|
||||
if (isValorized(apiTokenPwd)) {
|
||||
apiTokenPwd = StringEncrypter.getEncrypter().decrypt(apiTokenPwd);
|
||||
LOG.debug("Token decrypted is: " + apiTokenPwd.substring(0, apiTokenPwd.length() / 2)
|
||||
+ "_MASKED_TOKEN_");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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);
|
||||
}
|
||||
|
||||
LOG.info("SE in the scope: " + ScopeProvider.instance.get() + " with profile name: " + SE_PROFILE_NAME
|
||||
+ " and category name: " + SE_CATEGORY_NAME + "is returning: "+listSAP);
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.application.geoportaldatamapper.reader;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ServiceAccessPoint {
|
||||
String url;
|
||||
String apiTokenName;
|
||||
String apiTokenPwd;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ServiceAccessPoint [url=");
|
||||
builder.append(url);
|
||||
builder.append(", apiTokenName=");
|
||||
builder.append(apiTokenName);
|
||||
builder.append(", apiTokenPwd=");
|
||||
builder.append("MASKED_PWD");
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.gcube.application.geoportaldatamapper.shared;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ExporterProjectSource {
|
||||
|
||||
// Required fields
|
||||
String profileID;
|
||||
String projectID;
|
||||
String scope;
|
||||
|
||||
// Optional fields
|
||||
String profileTitle;
|
||||
String accountname; // if null the exporter will use PUBLIC ACCESS
|
||||
String gisLink;
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.gcube.application.geoportaldatamapper.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
|
||||
public class FileReference implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5398263987693453776L;
|
||||
|
||||
private URL storageVolatileURL;
|
||||
private String fileName;
|
||||
private String contentType;
|
||||
|
||||
public FileReference() {
|
||||
|
||||
}
|
||||
|
||||
public URL getStorageVolatileURL() {
|
||||
return storageVolatileURL;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setStorageVolatileURL(URL storageVolatileURL) {
|
||||
this.storageVolatileURL = storageVolatileURL;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("FileReference [storageVolatileURL=");
|
||||
builder.append(storageVolatileURL);
|
||||
builder.append(", fileName=");
|
||||
builder.append(fileName);
|
||||
builder.append(", contentType=");
|
||||
builder.append(contentType);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/resources/
|
|
@ -0,0 +1,116 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.application.geoportaldatamapper.exporter.gis.WGS84_CoordinatesConverter;
|
||||
import org.gcube.spatial.data.geoutility.shared.BBOX;
|
||||
import org.gcube.application.geoportaldatamapper.exporter.gis.BBOXConverter;
|
||||
import org.gcube.application.geoportaldatamapper.exporter.gis.Recalculate_WGS84_Offset;
|
||||
|
||||
public class CoordinatesConverter_Tests {
|
||||
|
||||
private static double EARTH_RADIUS = 6378137.0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// String bbox = "14.350604,40.632238,14.353074,40.634530";
|
||||
String source_bbox = "15.208508,41.442976,15.209360,41.443437";
|
||||
System.out.println("source bbox: " + source_bbox);
|
||||
|
||||
String wmsVersion = "1.1";
|
||||
double bboxOffset = 0.0;
|
||||
Recalculate_WGS84_Offset recalculate = new Recalculate_WGS84_Offset(wmsVersion, source_bbox, bboxOffset);
|
||||
|
||||
System.out.println("offset width: " + recalculate.getAspectratioWidth());
|
||||
System.out.println("offset heigth: " + recalculate.getAspectratioHeight());
|
||||
System.out.println("ratio: " + recalculate.getRatio_Width_Height());
|
||||
System.out.println("bbox with offset: " + recalculate.getBboxWithOffset());
|
||||
|
||||
int height = recalculate.getAspectratioHeight();
|
||||
int width = recalculate.getAspectratioWidth();
|
||||
|
||||
ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBOX(source_bbox);
|
||||
System.out.println("diff WGS84: " + diff);
|
||||
|
||||
BBOX theBBOX = BBOXConverter.toBBOX(wmsVersion, source_bbox);
|
||||
|
||||
String xMin = new Double(theBBOX.getLowerLeftX()).toString();
|
||||
String xMax = new Double(theBBOX.getUpperRightX()).toString();
|
||||
|
||||
Double offsetWidth = BBOXConverter.bboxOffset(xMin, xMax);
|
||||
System.out.println("offsetWidth: " + offsetWidth);
|
||||
|
||||
String yMin = new Double(theBBOX.getLowerLeftY()).toString();
|
||||
String yMax = new Double(theBBOX.getUpperRightY()).toString();
|
||||
Double offsetHeight = BBOXConverter.bboxOffset(yMax, yMin);
|
||||
System.out.println("offsetHeight: " + offsetHeight);
|
||||
|
||||
// int expWidth = getExponentForNumber(diff.get(0));
|
||||
// int expHeight = getExponentForNumber(diff.get(1));
|
||||
// System.out.println("expWidth: " + expWidth);
|
||||
// System.out.println("expHeight: " + expHeight);
|
||||
|
||||
if (width < 100 || height < 100) {
|
||||
bboxOffset = 0.00001;
|
||||
} else if (width < 200 || height < 200) {
|
||||
bboxOffset = 0.0001;
|
||||
} else if (width < 500 || height < 500) {
|
||||
bboxOffset = 0.001;
|
||||
} else if (width < 1000 || height < 1000) {
|
||||
bboxOffset = 0.01;
|
||||
}
|
||||
|
||||
bboxOffset = 0.0001;
|
||||
|
||||
System.out.println("applying offset: " + bboxOffset);
|
||||
|
||||
recalculate = new Recalculate_WGS84_Offset(source_bbox, source_bbox, bboxOffset);
|
||||
|
||||
System.out.println("offset width: " + recalculate.getAspectratioWidth());
|
||||
System.out.println("offset heigth: " + recalculate.getAspectratioHeight());
|
||||
System.out.println("ratio: " + recalculate.getRatio_Width_Height());
|
||||
System.out.println("bbox with offset: " + recalculate.getBboxWithOffset());
|
||||
|
||||
}
|
||||
|
||||
private static int getExponentForNumber(double number) {
|
||||
String numberAsString = String.valueOf(number);
|
||||
return numberAsString.substring(numberAsString.indexOf('.') + 1).length() * -1;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// // double bboxOffset = 0.003;
|
||||
// String theBBOX = "15.208508,41.442976,15.209360,41.443437";
|
||||
// double bboxOffset = 0.01; // no offset
|
||||
// double lowerXR = theBBOX.getLowerLeftX() - bboxOffset;
|
||||
// double lowerYR = theBBOX.getLowerLeftY() - bboxOffset;
|
||||
// double upperXR = theBBOX.getUpperRightX() + bboxOffset;
|
||||
// double upperYR = theBBOX.getUpperRightY() + bboxOffset;
|
||||
//
|
||||
// String parmBBOX = BBOX.toBBOXString(new BBOX(lowerXR, lowerYR, upperXR, upperYR, ""),
|
||||
// bboxFormat);
|
||||
//
|
||||
// // Calculating bounding box dimension
|
||||
// String bbox3857 = WGS84_CoordinatesConverter.toEPSG3857_BBOX(parmBBOX);
|
||||
// LOG.debug("toEPSG3857_BBOX: " + bbox3857);
|
||||
// ArrayList<Double> diff = WGS84_CoordinatesConverter.diffBBox(bbox3857);
|
||||
// LOG.debug("BoudingBox width - height: " + diff);
|
||||
// double width = diff.get(0);
|
||||
// double height = diff.get(1);
|
||||
// double ratio = width / height;
|
||||
// LOG.trace("bbox width: " + width);
|
||||
// LOG.trace("bbox heigth: " + height);
|
||||
// LOG.trace("bbox ratio: " + ratio);
|
||||
//
|
||||
// // Calculating width/height ratio
|
||||
// if (ratio > 1) {
|
||||
// expWidth = expWidth * ratio;
|
||||
// } else {
|
||||
// expHeight = expHeight * ratio;
|
||||
// }
|
||||
//
|
||||
// int aspectratioWidth = expWidth.intValue();
|
||||
// int aspectratioHeight = expHeight.intValue();
|
||||
//
|
||||
//}
|
||||
|
||||
}
|
|
@ -40,8 +40,10 @@ public class Geoportal_DataMapper_Tests {
|
|||
private ProjectsCaller clientProjects;
|
||||
|
||||
//private static String PROFILE_ID = "concessioni-estere";
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROJECT_ID = "6475a6a2a827c6201915917d"; //63d011c4dcac4551b9a6b930 //6442653ac6a0422d9e9042e0 //6399de3ca0a4545420373251
|
||||
//private static String PROFILE_ID = "profiledConcessioni";
|
||||
private static String PROFILE_ID = "test_basemodel";
|
||||
|
||||
private static String PROJECT_ID = "663cd047c387f9177ca09bcc"; //63d011c4dcac4551b9a6b930 //6442653ac6a0422d9e9042e0 //6399de3ca0a4545420373251
|
||||
|
||||
//IMPORTANT!!!! #NB SET USERNAME = null to test PUBLIC ACCESS
|
||||
|
||||
|
@ -75,7 +77,7 @@ public class Geoportal_DataMapper_Tests {
|
|||
*
|
||||
* @return the client
|
||||
*/
|
||||
//@Before
|
||||
@Before
|
||||
public void getClient() {
|
||||
readContextSettings();
|
||||
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
|
@ -113,7 +115,7 @@ public class Geoportal_DataMapper_Tests {
|
|||
/**
|
||||
* Test read project view.
|
||||
*/
|
||||
//@Test
|
||||
@Test
|
||||
public void testReadProjectView() {
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,293 @@
|
|||
|
||||
import java.io.FileInputStream;
|
||||
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;
|
||||
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
||||
import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter;
|
||||
import org.gcube.application.geoportaldatamapper.reader.MapBoxEndpointReader;
|
||||
import org.gcube.application.geoportaldatamapper.reader.ServiceAccessPoint;
|
||||
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geoutility.shared.BBOX;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The Class Geoportal_Export_To_PDF_Tests.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Nov 15, 2023
|
||||
*/
|
||||
public class Geoportal_Export_To_PDF_Tests {
|
||||
|
||||
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 UseCaseDescriptorCaller clientUCD;
|
||||
private ProjectsCaller clientProjects;
|
||||
|
||||
// private static String PROFILE_ID = "concessioni-estere";
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
|
||||
// private static String[] PROJECT_IDS = { "6388e4f8a1e60e66b7b584ac", "6388d9b3a1e60e66b7b5843a",
|
||||
// "646353c5d7fb4a4633022803", "63f8c481e9d6ac16f394f1e6", "638888fba1e60e66b7b581dd",
|
||||
// "650304487814b87373631242", "6388ea17a1e60e66b7b584dd", "64537208d7fb4a4633022039",
|
||||
// "638885fea1e60e66b7b581bd" };
|
||||
|
||||
//PROD
|
||||
//private static String[] PROJECT_IDS = { "6388e4f8a1e60e66b7b584ac" };
|
||||
|
||||
//DEV
|
||||
private static String[] PROJECT_IDS = { "661d2c6f8804530afb90b132" };
|
||||
|
||||
// DEV
|
||||
// 654e07a75bdd5478cca320c0
|
||||
// 655489965bdd5478cca320ea
|
||||
|
||||
// PROD Concessioni
|
||||
// 6388e4f8a1e60e66b7b584ac Ficocle-Cervia Vecchia
|
||||
// 6388d9b3a1e60e66b7b5843a
|
||||
// 646353c5d7fb4a4633022803 Villa Romana del Capo di Sorrento
|
||||
// 63f8c481e9d6ac16f394f1e6
|
||||
// 638888fba1e60e66b7b581dd
|
||||
// 650304487814b87373631242 Scavi a Calvatone-Bedriacum
|
||||
// 6388ea17a1e60e66b7b584dd Indagini archeologiche presso la pieve di San Pietro
|
||||
// in Bossolo, Barberino Tavarnelle (FI)
|
||||
// 64537208d7fb4a4633022039 PArCo di Poggio del Molino - Progetto Archeodig
|
||||
// 638885fea1e60e66b7b581bd Scavo della Grotta della Ciota Ciara
|
||||
|
||||
// PRE
|
||||
// 63d011c4dcac4551b9a6b930
|
||||
// //6442653ac6a0422d9e9042e0
|
||||
// //6399de3ca0a4545420373251
|
||||
// 645a152fd7fb4a463302240d
|
||||
// 63f8c481e9d6ac16f394f1e6
|
||||
|
||||
// PROD concessione-estere
|
||||
// 64a2c5c6a827c620191599ff
|
||||
|
||||
// IMPORTANT!!!! #NB SET USERNAME = null to test PUBLIC ACCESS
|
||||
private static String USERNAME = null;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client.
|
||||
*
|
||||
* @return the client
|
||||
*/
|
||||
//@Before
|
||||
public void getClient() {
|
||||
readContextSettings();
|
||||
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
clientUCD = GeoportalClientCaller.useCaseDescriptors();
|
||||
clientProjects = GeoportalClientCaller.projects();
|
||||
}
|
||||
|
||||
/**
|
||||
* API map box service endpoint reader.
|
||||
*/
|
||||
//@Test
|
||||
public void apiMapBoxServiceEndpointReader() {
|
||||
try {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test read project view.
|
||||
*/
|
||||
//@Test
|
||||
public void testExportToPDF() {
|
||||
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
Geoportal_PDF_Exporter pdfExporter = new Geoportal_PDF_Exporter();
|
||||
ExporterProjectSource exporterSource = new ExporterProjectSource();
|
||||
// #NB SET USERNAME = null to test PUBLIC ACCESS
|
||||
USERNAME = "francesco.mangiacrapa";
|
||||
exporterSource.setAccountname(USERNAME);
|
||||
exporterSource.setProfileID(PROFILE_ID);
|
||||
//exporterSource.setProfileTitle("Regime di Concessione");
|
||||
exporterSource.setScope(CONTEXT);
|
||||
try {
|
||||
|
||||
for (String project_ID : PROJECT_IDS) {
|
||||
exporterSource.setProjectID(project_ID);
|
||||
pdfExporter.createPDFFile(exporterSource);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("testExportToPDF terminated");
|
||||
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// GeoServerRESTReader reader = new GeoServerRESTReader("");
|
||||
//
|
||||
// RESTLayer layer = reader.getLayer("");
|
||||
//
|
||||
// layer.get
|
||||
//
|
||||
// }
|
||||
/*
|
||||
* public static void main(String[] args) { double imageWidth = 400; double
|
||||
* imageHeight = 400;
|
||||
*
|
||||
* double expansionFactor = 0.1;
|
||||
*
|
||||
* String bbox = "8.310868,45.710911,8.310912,45.710940";
|
||||
*
|
||||
* BBOX theBBOX = new BBOX(bbox, COORDINATE_FORMAT.XY); // double x = imageWidth
|
||||
* * theBBOX.getLowerLeftX(); // double y = imageHeight *
|
||||
* theBBOX.getLowerLeftY() ; // double w = imageWidth *
|
||||
* theBBOX.getUpperRightX(); // double h = imageHeight *
|
||||
* theBBOX.getUpperRightY();
|
||||
*
|
||||
* Integer[] size = new Integer[2]; size[0] = 400; size[1] = 400; Double[] bboxD
|
||||
* = new Double[4]; bboxD[0] = theBBOX.getLowerLeftX(); bboxD[1] =
|
||||
* theBBOX.getLowerLeftY() ; bboxD[2] = theBBOX.getUpperRightX(); bboxD[3] =
|
||||
* theBBOX.getUpperRightY(); BBOXPixel bboxP =
|
||||
* BBOXConverter.convertToPixel(size, bboxD);
|
||||
*
|
||||
* System.out.println("bboxP: "+bboxP);
|
||||
*
|
||||
* double left = Math.max(bboxP.x - bboxP.w * expansionFactor, 0); double top =
|
||||
* Math.max(bboxP.y - bboxP.h * expansionFactor, 0); double width =
|
||||
* Math.min(bboxP.x + bboxP.w * 2 * expansionFactor, imageWidth - left); double
|
||||
* height = Math.min(bboxP.h + bboxP.h * 2 * expansionFactor, imageHeight -
|
||||
* top);
|
||||
*
|
||||
* BBOXPixel bboxP2 = new BBOXPixel(left, top, width, height);
|
||||
*
|
||||
* BBOX bboxE = BBOXConverter.convertToCoordinate(bboxP2, size);
|
||||
* System.out.println(bboxE);
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
static class BoundingBox {
|
||||
public double north, south, east, west;
|
||||
|
||||
public BoundingBox(String location, float km) {
|
||||
// System.out.println(location + " : "+ km);
|
||||
String[] parts = location.replaceAll("\\s", "").split(","); // remove spaces and split on ,
|
||||
System.out.println("parts" + " : " + Arrays.asList(parts));
|
||||
|
||||
double lng = Double.parseDouble(parts[0]);
|
||||
double lat = Double.parseDouble(parts[1]);
|
||||
|
||||
double adjust = .008983112; // 1km in degrees at equator.
|
||||
// adjust = 0.008983152770714983; // 1km in degrees at equator.
|
||||
|
||||
// System.out.println("deg: "+(1.0/40075.017)*360.0);
|
||||
|
||||
north = lat + (km * adjust);
|
||||
south = lat - (km * adjust);
|
||||
|
||||
double lngRatio = 1 / Math.cos(Math.toRadians(lat)); // ratio for lng size
|
||||
// System.out.println("lngRatio: "+lngRatio);
|
||||
|
||||
east = lng + (km * adjust) * lngRatio;
|
||||
west = lng - (km * adjust) * lngRatio;
|
||||
|
||||
System.out.println(new BBOX(west, south, east, north, ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// gdal.AllRegister();
|
||||
//
|
||||
// DataSource dataSource = ogr.Open("https://geoserver-1.cloud-dev.d4science.org/geoserver/profiledconcessioni_gcube_devsec_devvre_654e07a75bdd5478cca320c0/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&STYLES=&LAYERS=profiledconcessioni_gcube_devsec_devvre_654e07a75bdd5478cca320c0:ce19_09&exceptions=application/vnd.ogc.se_inimage&SRS=EPSG:4326&WIDTH=400&HEIGHT=400&BBOX=12.235679626464844,44.179115295410156,12.373008728027344,44.316444396972656");
|
||||
// Layer layer = dataSource.GetLayer(0);
|
||||
//
|
||||
// }
|
||||
|
||||
// Mercator projection
|
||||
public static ArrayList<Double> convertToPixel(double lng, double lat, double mapWidth, double mapHeight) {
|
||||
// get x
|
||||
double x = (lng + 180) * (mapWidth / 360);
|
||||
// convert from degrees to radians
|
||||
double latRad = lat * Math.PI / 180;
|
||||
// get y value
|
||||
double mercN = Math.log(Math.tan((Math.PI / 4) + (latRad / 2)));
|
||||
double y = (mapHeight / 2) - (mapWidth * mercN / (2 * Math.PI));
|
||||
|
||||
ArrayList size = new ArrayList<Double>();
|
||||
size.add(x);
|
||||
size.add(y);
|
||||
return size;
|
||||
}
|
||||
|
||||
public static ArrayList<Double> convertPixed(double lng, double lat, double mapWidth, double mapHeight) {
|
||||
// get x
|
||||
double x = (lng * mapWidth) / 360;
|
||||
double y = (lat * mapHeight) / 180;
|
||||
|
||||
ArrayList size = new ArrayList<Double>();
|
||||
size.add(x);
|
||||
size.add(y);
|
||||
return size;
|
||||
}
|
||||
|
||||
public static Double[] epsg4326toEpsg3857(Double[] coordinates) {
|
||||
double x = (coordinates[0] * 20037508.34) / 180;
|
||||
double y = Math.log(Math.tan(((90 + coordinates[1]) * Math.PI) / 360)) / (Math.PI / 180);
|
||||
y = (y * 20037508.34) / 180;
|
||||
Double[] xy = new Double[2];
|
||||
xy[0] = x;
|
||||
xy[1] = y;
|
||||
return xy;
|
||||
}
|
||||
}
|
|
@ -1,2 +1,5 @@
|
|||
/gcube_config.properties
|
||||
/log4j.properties
|
||||
/D4OS.gcubekey
|
||||
/devsec.gcubekey
|
||||
/gcube.gcubekey
|
||||
|
|
Loading…
Reference in New Issue