From 3448f0625d877591f73f9674d032f904105f3a5d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 27 Feb 2024 09:58:06 +0100 Subject: [PATCH] Updated `geoportal-data-mapper` range at [1.0.1, 2.0.0-SNAPSHOT) --- .classpath | 6 + .settings/org.eclipse.core.resources.prefs | 1 + .settings/org.eclipse.wst.common.component | 10 + CHANGELOG.md | 4 + pom.xml | 6 +- src/test/.gitignore | 1 + .../client/Geoportal_Export_To_PDF_Tests.java | 275 ++++++++++++++++++ 7 files changed, 300 insertions(+), 3 deletions(-) create mode 100644 src/test/.gitignore create mode 100644 src/test/java/org/gcube/portlets/widgets/gdvw/client/Geoportal_Export_To_PDF_Tests.java diff --git a/.classpath b/.classpath index 5734fb4..fa4552d 100644 --- a/.classpath +++ b/.classpath @@ -18,6 +18,12 @@ + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 839d647..29abf99 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -2,4 +2,5 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 encoding/=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index bc5cd71..54119af 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,10 +1,20 @@ + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index d25dad6..5f6eea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.0.1] + +- Updated `geoportal-data-mapper` range at [1.0.1, 2.0.0-SNAPSHOT) + ## [v1.0.0] #### First release diff --git a/pom.xml b/pom.xml index ecfdb4f..68b229a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ maven-parent org.gcube.tools - 1.1.0 + 1.2.0 @@ -14,7 +14,7 @@ org.gcube.portlets.widgets geoportal-data-viewer-widget jar - 1.0.0 + 1.0.1 org.gcube.portlets.widgets.gdvw.geoportal_data_viewer_widget @@ -83,7 +83,7 @@ org.gcube.application geoportal-data-mapper - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [1.0.1, 2.0.0-SNAPSHOT) compile diff --git a/src/test/.gitignore b/src/test/.gitignore new file mode 100644 index 0000000..cb6eb2c --- /dev/null +++ b/src/test/.gitignore @@ -0,0 +1 @@ +/resources/ diff --git a/src/test/java/org/gcube/portlets/widgets/gdvw/client/Geoportal_Export_To_PDF_Tests.java b/src/test/java/org/gcube/portlets/widgets/gdvw/client/Geoportal_Export_To_PDF_Tests.java new file mode 100644 index 0000000..fad8150 --- /dev/null +++ b/src/test/java/org/gcube/portlets/widgets/gdvw/client/Geoportal_Export_To_PDF_Tests.java @@ -0,0 +1,275 @@ +//package org.gcube.portlets.widgets.gdvw.client; +// +//import java.io.FileInputStream; +//import java.io.FileOutputStream; +//import java.io.IOException; +//import java.io.InputStream; +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Properties; +//import java.util.stream.Stream; +// +//import org.gcube.application.geoportal.common.model.document.Project; +//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.geoportal.materialization.GCubeSDIViewerLayerDV; +//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.FilesetDV; +//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; +//import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; +//import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; +//import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; +//import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; +//import org.gcube.application.geoportaldatamapper.Geoportal_JSON_Mapper; +//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.google.gwt.core.client.GWT; +//import com.itextpdf.text.Anchor; +//import com.itextpdf.text.BaseColor; +//import com.itextpdf.text.Chunk; +//import com.itextpdf.text.Document; +//import com.itextpdf.text.Font; +//import com.itextpdf.text.FontFactory; +//import com.itextpdf.text.Paragraph; +//import com.itextpdf.text.Phrase; +//import com.itextpdf.text.pdf.PdfPCell; +//import com.itextpdf.text.pdf.PdfPTable; +//import com.itextpdf.text.pdf.PdfWriter; +// +///** +// * The Class Geoportal_Export_To_PDF_Tests. +// * +// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it +// * +// * Dec 5, 2022 +// */ +//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_ID = "6384d44d308f5c28c5ee0a01"; // 63d011c4dcac4551b9a6b930 +// // //6442653ac6a0422d9e9042e0 +// // //6399de3ca0a4545420373251 +// +// // IMPORTANT!!!! #NB SET USERNAME = null to test PUBLIC ACCESS +// +// private static String USERNAME = "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(); +// } +// } +// +// /** +// * 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(); +// } +// +// /** +// * Test read project view. +// */ +// @Test +// public void testExportToPDF() { +// +// try { +// ScopeProvider.instance.set(CONTEXT); +// SecurityTokenProvider.instance.set(TOKEN); +// Project theProject = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID); +// ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); +// projectBuilder.relationships(true); +// +// System.out.println("project json: " + theProject.getTheDocument().toJson()); +// +// ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); +// ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME); +// Geoportal_JSON_Mapper.prettyPrintProjectView(projectView); +// +// //CREATING NEW PDF +// Document document = new Document(); +// PdfWriter.getInstance(document, new FileOutputStream("iTextHelloWorld.pdf")); +// document.open(); +// +// Font font = FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK); +// Chunk chunk = new Chunk("Hello World", font); +// +// document.add(chunk); +// +// for (SectionView section : projectView.getListSections()) { +// +// List subdocs = section.getListSubDocuments(); +// section.getSectionTitle(); +// +// if (subdocs != null && subdocs.size() > 0) { +// document = appendSubDocumentToPDF(document, section, subdocs); +// } +// +// } +// +// document.close(); +// +//// ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME); +//// Geoportal_JSON_Mapper.prettyPrintProjectView(projectView); +// System.out.println("\n\n testReadProjectView terminated!!!"); +// } catch (Exception e) { +// System.err.println("Error"); +// e.printStackTrace(); +// } +// } +// +// private Document appendSubDocumentToPDF(Document document, SectionView sectionView, +// List subDocuments) { +// try { +// boolean displayAsGallery = false; +// +// for (SubDocumentView subDocumentView : subDocuments) { +// if (subDocumentView.getListImages() != null && subDocumentView.getListImages().size() > 0) { +// GWT.log("Section with images: " + subDocumentView.getListImages()); +// displayAsGallery = true; +// break; +// } +// } +// +// boolean displayAsMapOfLayers = false; +// for (SubDocumentView subDocumentView : subDocuments) { +// if (subDocumentView.getListLayers() != null && subDocumentView.getListLayers().size() > 0) { +// GWT.log("Section with layers: " + subDocumentView.getListImages()); +// displayAsMapOfLayers = true; +// break; +// } +// } +// +// // Displaying the whole section as a Gallery +// if (displayAsGallery) { +// GWT.log("displayAsGallery the: " + sectionView); +// +// // Displaying the whole section as a Map of Layers +// } else if (displayAsMapOfLayers) { +// GWT.log("displayAsMapOfLayers the: " + sectionView); +// for (SubDocumentView subDocumentView : subDocuments) { +//// String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON()); +//// sectionPanelContainer.add(new HTML(table)); +// +// List layers = subDocumentView.getListLayers(); +// if (layers != null) { +// for (GCubeSDIViewerLayerDV gCubeLayer : layers) { +//// LayersSectionViewer layerSectionViewer = new LayersSectionViewer(gCubeLayer, +//// subDocumentView); +//// sectionPanelContainer.add(layerSectionViewer); +//// // showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload()); +// } +// } +// } +// +// } else { +// GWT.log("displaying default the: " + sectionView); +// for (SubDocumentView subDocumentView : subDocuments) { +// PdfPTable table = jsonToPDFTable(subDocumentView.getMetadataAsJSON()); +// document.add(table); +// +// List files = subDocumentView.getListFiles(); +// if (files != null) { +// for (FilesetDV fileset : files) { +// Paragraph paragraph = new Paragraph(fileset.getGcubeProfileFieldName()); +// document.add(paragraph); +// List anchors = toPDFAnchors(fileset.getListPayload()); +// for (Anchor anchor : anchors) { +// document.add(anchor); +// } +// } +// } +// } +// } +// } catch (Exception e) { +// GWT.log("Error on rendering the section: " + e.getMessage()); +// } +// +// return document; +// +// } +// +// private static List toPDFAnchors(List payloads) { +// +// List anchors = new ArrayList(payloads.size()); +// for (PayloadDV payloadDV : payloads) { +// Anchor anchor = new Anchor(payloadDV.getName()); +// anchor.setReference(payloadDV.getLink()); +// anchors.add(anchor); +// } +// +// return anchors; +// +// } +// +//// toPDFImage(){ +//// +//// } +// +// private static PdfPTable jsonToPDFTable(String json) { +// PdfPTable table = new PdfPTable(3); +// addTableHeader(table); +// addRows(table); +// // addCustomRows(table); +// return table; +// } +// +// private static void addTableHeader(PdfPTable table) { +// Stream.of("column header 1", "column header 2", "column header 3").forEach(columnTitle -> { +// PdfPCell header = new PdfPCell(); +// header.setBackgroundColor(BaseColor.LIGHT_GRAY); +// header.setBorderWidth(2); +// header.setPhrase(new Phrase(columnTitle)); +// table.addCell(header); +// }); +// } +// +// private static void addRows(PdfPTable table) { +// table.addCell("row 1, col 1"); +// table.addCell("row 1, col 2"); +// table.addCell("row 1, col 3"); +// } +// +//}