From c34faa9f684c218baec8fc7117dd3b8d436e9b96 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 Oct 2022 15:30:12 +0200 Subject: [PATCH] Added Expand Button into View Relations Panel --- .settings/org.eclipse.wst.common.component | 33 +-- .../ConstantsGeoPortalDataEntryApp.java | 11 - .../client/ui/GeonaMainTabPanel.java | 2 +- .../ui/relation/ViewRelationshipPanel.java | 71 +++++-- .../ui/relation/ViewRelationshipPanel.ui.xml | 7 +- .../ui/report/ReportTemplateToHTML.java | 40 +--- .../server/GeoportalDataEntryServiceImpl.java | 2 +- src/main/webapp/GeoPortalDataEntryApp.css | 2 + .../geoportaldataentry/Complex_Tests.java | 189 +++++++++++++----- .../GcubeProfilesMetadataForUCD.java | 63 ++++++ 10 files changed, 283 insertions(+), 137 deletions(-) create mode 100644 src/test/java/org/gcube/portlets/user/geoportaldataentry/GcubeProfilesMetadataForUCD.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 1c62c02..961c545 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -51,7 +52,8 @@ - + + @@ -103,7 +105,8 @@ - + + @@ -155,7 +158,8 @@ - + + @@ -207,20 +211,16 @@ - + + - - uses - - - uses - uses - + + @@ -272,7 +272,8 @@ - + + @@ -324,7 +325,8 @@ - + + @@ -376,7 +378,8 @@ - + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index 3598e10..277d092 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -46,17 +46,6 @@ public class ConstantsGeoPortalDataEntryApp { public static final String WORKFLOW_ACTION_POST_CREATION_ACTION_ID = "post_creation_action"; -// /** -// * The Enum RECORD_TYPE. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Aug 6, 2021 -// */ -// public enum RECORD_TYPE { -// CONCESSIONE -// } - /** * The Enum ACTION_PERFORMED_ON_ITEM. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index 190dfcd..4bc1a4a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -656,7 +656,7 @@ public class GeonaMainTabPanel extends Composite { if (!bool) { return; } - viewRelationshipPanel = new ViewRelationshipPanel(appManagerBus, selectedDocument); + viewRelationshipPanel = new ViewRelationshipPanel(appManagerBus, selectedDocument, true); detailsPanel.add(viewRelationshipPanel); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.java index e4d489f..145718a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.java @@ -14,6 +14,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Label; +import com.github.gwtbootstrap.client.ui.Modal; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconSize; import com.github.gwtbootstrap.client.ui.constants.IconType; @@ -24,6 +25,7 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlexTable; @@ -59,13 +61,16 @@ public class ViewRelationshipPanel extends Composite { @UiField Button closeButton; + @UiField + Button buttonExpand; + private HashMap selectedProjects = new HashMap(2); private HandlerManager appManagerBus; - + private Map mapOfTargetProjectForId = new HashMap(); - public ViewRelationshipPanel(HandlerManager appManagerBus, ResultDocumentDV fromProject) { + public ViewRelationshipPanel(HandlerManager appManagerBus, ResultDocumentDV fromProject, boolean showExpand) { initWidget(uiBinder.createAndBindUi(this)); this.appManagerBus = appManagerBus; @@ -81,6 +86,34 @@ public class ViewRelationshipPanel extends Composite { } }); + buttonExpand.setType(ButtonType.LINK); + buttonExpand.setIcon(IconType.EXPAND); + buttonExpand.setTitle("Show this view in new Window"); + buttonExpand.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + Modal mw = new Modal(true, true); + mw.setTitle("Relationships"); + + int width = Window.getClientWidth(); + if(width > 1024) { + width = 1024; + mw.setWidth(width); + } + mw.add(new ViewRelationshipPanel(appManagerBus, fromProject, false)); + mw.show(); + + } + }); + + if (!showExpand) { + buttonExpand.setVisible(false); + panelTitle.setVisible(false); + closeButton.setVisible(false); + } + showRelationsOf(fromProject); } @@ -89,8 +122,8 @@ public class ViewRelationshipPanel extends Composite { secondProjectPanelContainer.clear(); Entry firstEntrySet = project.getFirstEntryOfMap(); - String htmlMsg = firstEntrySet.getKey() + ": " + firstEntrySet.getValue() - + " (id: " + project.getId() + ")"; + String htmlMsg = firstEntrySet.getKey() + ": " + firstEntrySet.getValue() + " (id: " + project.getId() + + ")"; firstProjectPanelContainer.add(new HTML(htmlMsg)); ReportTemplateToHTML rtth = new ReportTemplateToHTML("", project.getDocumentAsJSON(), false, false); @@ -105,37 +138,35 @@ public class ViewRelationshipPanel extends Composite { secondProjectPanelContainer.clear(); for (RelationshipDV relationDV : project.getListRelationshipDV()) { - final FlexTable flexTable = new FlexTable(); flexTable.getElement().addClassName("box-table-diplay-project"); Label label = new Label(); label.setType(LabelType.INFO); label.setText(relationDV.getRelationshipName()); - - + FlowPanel panelContainer = new FlowPanel(); - Button deleteRelation = new Button("",IconType.TRASH); + Button deleteRelation = new Button("", IconType.TRASH); deleteRelation.setTitle("Delete this releation"); deleteRelation.setType(ButtonType.LINK); deleteRelation.addClickHandler(new ClickHandler() { - + @Override public void onClick(ClickEvent event) { ResultDocumentDV toProject = mapOfTargetProjectForId.get(relationDV.getTargetUCD()); - appManagerBus.fireEvent(new RelationActionHandlerEvent(project, relationDV.getRelationshipName(), toProject)); - + appManagerBus.fireEvent( + new RelationActionHandlerEvent(project, relationDV.getRelationshipName(), toProject)); + } }); - + panelContainer.add(label); panelContainer.add(deleteRelation); flexTable.setWidget(0, 0, panelContainer); - - + flexTable.setWidget(1, 0, new LoaderIcon("loading project..")); - GeoportalDataEntryServiceAsync.Util.getInstance().getResultDocumentFoProjectByID(relationDV.getTargetUCD(), - relationDV.getTargetID(), new AsyncCallback() { + GeoportalDataEntryServiceAsync.Util.getInstance().getResultDocumentFoProjectByID( + relationDV.getTargetUCD(), relationDV.getTargetID(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -149,17 +180,17 @@ public class ViewRelationshipPanel extends Composite { Entry firstEntrySet = result.getFirstEntryOfMap(); String htmlMsg = firstEntrySet.getKey() + ": " + firstEntrySet.getValue() + " (id: " + result.getId() + ")"; - + flexTable.setWidget(1, 0, new HTML(htmlMsg)); - - ReportTemplateToHTML rtth2 = new ReportTemplateToHTML("", result.getDocumentAsJSON(), false, false); + + ReportTemplateToHTML rtth2 = new ReportTemplateToHTML("", result.getDocumentAsJSON(), + false, false); rtth2.showAsJSON(false); flexTable.setWidget(2, 0, rtth2); } }); - secondProjectPanelContainer.add(flexTable); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.ui.xml index f7b6c9e..12d5c11 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/relation/ViewRelationshipPanel.ui.xml @@ -34,6 +34,10 @@ padding-left: 10px; padding-top: 5px; } + + .float-right { + float: right; + } @@ -41,6 +45,8 @@ addStyleNames="{style.to-align-right}"> View Relations + Expand @@ -48,7 +54,6 @@ - diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/report/ReportTemplateToHTML.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/report/ReportTemplateToHTML.java index dd60c7b..700ceb3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/report/ReportTemplateToHTML.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/report/ReportTemplateToHTML.java @@ -136,30 +136,6 @@ public class ReportTemplateToHTML extends Composite { GWT.log("report is: " + theJSONDocument); vpContainer.setVisible(true); -// try { -// JSONValue jsonObj = JSONParser.parse(theJSONDocument); -// JSONObject json = (JSONObject) jsonObj; -// JSONValue valueChildren = json.get("children"); -// JSONArray jsonChildren = (JSONArray) valueChildren; -// -// String toTableHTML = null; -// for (int i = 0; i < jsonChildren.size(); i++) { -// JSONObject jsO = (JSONObject) jsonChildren.get(i); -// -// if (jsO.containsKey("children")) { -// toTableHTML = jsonToHTML(jsO.get("children").toString()); -// } else { -// toTableHTML = jsonToHTML(jsO.toString()); -// } -// -// htmlContainer.add(new HTML(toTableHTML)); -// } -// -// } catch (Exception e) { -// e.printStackTrace(); -// GWT.log("error: " + e.getMessage()); -// } - try { JSONValue jsonObj = JSONParser.parse(theJSONDocument); @@ -168,8 +144,6 @@ public class ReportTemplateToHTML extends Composite { reportTable.add(new HTML(toTableHTML)); - //htmlContainer.add(new HTML(toTableHTML)); - } catch (Exception e) { e.printStackTrace(); GWT.log("error: " + e.getMessage()); @@ -179,13 +153,14 @@ public class ReportTemplateToHTML extends Composite { reportJSON.add(new HTML("
" + ExternalLib.toPrettyPrintJSON(theJSONDocument) + "
")); } } - + /** - * Instantiates a new report template to HTML. Shows the JSON Document as Table HTML by default + * Instantiates a new report template to HTML. Shows the JSON Document as Table + * HTML by default * - * @param documentLabel the document label + * @param documentLabel the document label * @param theJSONDocument the the JSON document - * @param openJSONReport the open JSON report + * @param openJSONReport the open JSON report */ public ReportTemplateToHTML(String documentLabel, String theJSONDocument, boolean openJSONReport) { @@ -245,16 +220,15 @@ public class ReportTemplateToHTML extends Composite { } } - + public void showAsHTMLTable(boolean bool) { showReportAsTable.setVisible(bool); } - + public void showAsJSON(boolean bool) { showReportAsJSON.setVisible(bool); } - /** * Json to HTML. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 72f7c37..5cd41e4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -451,7 +451,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } catch (Exception e) { LOG.error("Error on loading paginated and filtered list of projects for id: ", e); - throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); + throw new Exception("Error occurred on loading list of Projects. Error: " + e.getMessage()); } } diff --git a/src/main/webapp/GeoPortalDataEntryApp.css b/src/main/webapp/GeoPortalDataEntryApp.css index 29064d2..039b5e0 100644 --- a/src/main/webapp/GeoPortalDataEntryApp.css +++ b/src/main/webapp/GeoPortalDataEntryApp.css @@ -54,6 +54,7 @@ h1 { .my-html-table td { padding: 5px; border-bottom: 1px solid gray; + min-width: 100px; } .my-html-table td:first-child { @@ -247,6 +248,7 @@ h1 { border: 1px solid #96a5b5; border-radius: 5px; margin-bottom: 5px; + word-break: break-word; } .box-table-diplay-project td { diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java index b7ad298..0443b29 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.geoportaldataentry; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; @@ -15,15 +16,16 @@ 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.geoportal.access.GeportalCheckAccessPolicy; +import org.gcube.application.geoportalcommon.geoportal.serdes.Payload; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; +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.ucd.GEOPORTAL_CONFIGURATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; -import org.gcube.application.geoportalcommon.shared.geoportal.view.FilesetDV; -import org.gcube.application.geoportalcommon.shared.geoportal.view.PayloadDV; 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; @@ -60,6 +62,38 @@ public class Complex_Tests { public static final String JSON_$_POINTER = "$"; private static final Logger LOG = LoggerFactory.getLogger(Complex_Tests.class); + private LinkedHashMap> linkedMap_UCDId_gCubeProfiles; + + public static enum COMMON_IMAGES_FORMAT { + gif, png, jpeg, jpg, bmp, tif, tiff, svg, avif, webp + } + + public static class ImageDetector { + + private static String[] getNames(Class> e) { + return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new); + } + + public static List listFormatImages; + + static { + + String[] arrayImgs = ImageDetector.getNames(COMMON_IMAGES_FORMAT.class); + listFormatImages = Arrays.asList(arrayImgs); + + } + + public static boolean isImage(String mimeType) { + if (mimeType == null || mimeType.isEmpty()) + return false; + + String inputImageFormat = mimeType.replaceAll("image/", ""); + + return listFormatImages.contains(inputImageFormat); + } + + } + @Before public void init() { ScopeProvider.instance.set(CONTEXT); @@ -68,51 +102,73 @@ public class Complex_Tests { clientUCD = GeoportalClientCaller.useCaseDescriptors(); } + @Before + public void preloadgCubeProfilesForUCDs() { + LOG.debug("preloadgCubeProfilesForUCDs called"); + try { + + List listUCDs = clientUCD.getList(); + + for (UseCaseDescriptor ucd : listUCDs) { + + LOG.debug("Loaded UCD for ID: " + ucd.getId()); + GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_data_entry; + List handlers = ucd.getHandlersByType(theHandler.getType()); + + if (handlers.size() == 0) { + LOG.warn("No handler " + theHandler + "found into UCD " + ucd.getId() + ", continue..."); + continue; + } + + // Loading Handler gcube_profiles + HandlerDeclaration dataEntryHandler = handlers.get(0); + HandlerDeclarationDV handlerGcubeProfiles = ConvertToDataValueObjectModel + .toHandlerDeclarationDV(dataEntryHandler, ucd, GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles); + + LOG.debug("Handler " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " for PROFILE_ID: " + ucd.getId()); + LOG.debug("" + handlerGcubeProfiles); + + ConfigurationDV config = handlerGcubeProfiles.getConfiguration(); + // List of gCube Profiles defined in the UCD + List listGcubeProfiles = toListGcubeProfiles(config); + LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles); + + List listProfilesBean = new ArrayList(); + // Loading Metadata Profile from IS + MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl(); + linkedMap_UCDId_gCubeProfiles = new LinkedHashMap>(); + for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) { + GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD(); + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + List listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(CONTEXT, + gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName()); + + String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName(); + LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles); + gCubeProfileMetadataForUCD.setGcubeProfile(gcubeProfileDV); + gCubeProfileMetadataForUCD.setListMetadataProfileBean(listProfiles); + listProfilesBean.add(gCubeProfileMetadataForUCD); + + } + linkedMap_UCDId_gCubeProfiles.put(ucd.getId(), listProfilesBean); + + for (String key : linkedMap_UCDId_gCubeProfiles.keySet()) { + LOG.debug("For key '" + key + "' got profiles: " + linkedMap_UCDId_gCubeProfiles.get(key)); + } + } + + } catch (Exception e) { + // TODO: handle exception + } + } + @Test public void testReadProjectForUCDDataEntry() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); try { - LOG.debug("Loading UCD for PROFILE_ID: " + PROFILE_ID); - UseCaseDescriptor ucd = clientUCD.getUCDForId(PROFILE_ID); - GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_data_entry; - List handlers = ucd.getHandlersByType(theHandler.getType()); - - if (handlers.size() == 0) - throw new Exception("No handler " + theHandler + "found"); - - // Loading Handler gcube_profiles - HandlerDeclaration dataEntryHandler = handlers.get(0); - HandlerDeclarationDV handlerGcubeProfiles = ConvertToDataValueObjectModel - .toHandlerDeclarationDV(dataEntryHandler, ucd, GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles); - - LOG.debug("Handler " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " for PROFILE_ID: " + PROFILE_ID); - LOG.debug("" + handlerGcubeProfiles); - - ConfigurationDV config = handlerGcubeProfiles.getConfiguration(); - // List of gCube Profiles defined in the UCD - List listGcubeProfiles = toListGcubeProfiles(config); - LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles); - - // Loading Metadata Profile from IS - MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl(); - LinkedHashMap> linkedHashProfiles = new LinkedHashMap>(); - for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) { - ScopeProvider.instance.set(CONTEXT); - SecurityTokenProvider.instance.set(TOKEN); - List listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(CONTEXT, - gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName()); - - String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName(); - LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles); - linkedHashProfiles.put(gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName(), - listProfiles); - } - - for (String key : linkedHashProfiles.keySet()) { - LOG.debug("For key: " + key + " got profiles: " + linkedHashProfiles.get(key)); - } Project theProject = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); @@ -126,7 +182,7 @@ public class Complex_Tests { projectView.setTheProjectDV(theProjectDV); // NO UCD defined, applyong default - if (listGcubeProfiles.size() == 0) { + if (linkedMap_UCDId_gCubeProfiles.size() == 0) { LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD"); LOG.info("Applying default business logic to display the project"); SectionView sectionView = new SectionView(); @@ -137,12 +193,15 @@ public class Complex_Tests { projectView.addSectionView(sectionView); } + List listProfilesBean = linkedMap_UCDId_gCubeProfiles.get(PROFILE_ID); + com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() .jsonProvider(new JsonOrgJsonProvider()).build(); // Reading the Project according to list of Profile defined in the UCD - for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) { + for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) { + GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile(); SectionView sectionView = new SectionView(); sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); LOG.debug("\n\nThe profile is: " + gcubeProfileDV); @@ -197,8 +256,7 @@ public class Complex_Tests { } LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); - List theProfileBeans = linkedHashProfiles - .get(gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName()); + List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); MetaDataProfileBean theProfileBean = theProfileBeans.get(0); // For each bson.Document creating the SubDocumentView @@ -230,17 +288,29 @@ public class Complex_Tests { // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG if (filePaths != null) { String fromSectionDocJSON = fromSectionDoc.toJson(); - List listFileSet = new ArrayList(); + List listFiles = new ArrayList(); + List listImages = new ArrayList(); for (FilePathDV filePath : filePaths) { String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); - List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); + List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); FilesetDV filesetDV = new FilesetDV(); filesetDV.setName(filePath.getGcubeProfileFieldName()); - filesetDV.addListPayloadsDV(listPayloads); - listFileSet.add(filesetDV); + for (Payload payload : listPayloads) { + PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); + filesetDV.addPayloadDV(payloadDV); + boolean isImage = ImageDetector.isImage(payload.getMimetype()); + + if (isImage) { + listImages.add(filesetDV); + } else { + listFiles.add(filesetDV); + } + } + } - subDocumentView.setListFiles(listFileSet); + subDocumentView.setListFiles(listFiles); + subDocumentView.setListImages(listImages); } sectionView.addSubDocument(subDocumentView); @@ -254,13 +324,22 @@ public class Complex_Tests { System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######"); int i = 1; for (SubDocumentView subDocument : section.getListSubDocuments()) { - System.out.println("## "+SubDocumentView.class.getSimpleName()+" n."+i); + System.out.println("## " + SubDocumentView.class.getSimpleName() + " n." + i); System.out.println("***** Metadata"); System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON())); System.out.println("***** Files"); if (subDocument.getListFiles() != null) { for (FilesetDV filesetDV : subDocument.getListFiles()) { - System.out.println("******* Fileset name: " + filesetDV.getName()); + System.out.println("******* File Fileset name: " + filesetDV.getName()); + for (PayloadDV payload : filesetDV.getListPayload()) { + System.out.println("********* Payload: " + payload); + } + } + } + System.out.println("***** Images"); + if (subDocument.getListImages() != null) { + for (FilesetDV filesetDV : subDocument.getListImages()) { + System.out.println("******* Image Fileset name: " + filesetDV.getName()); for (PayloadDV payload : filesetDV.getListPayload()) { System.out.println("********* Payload: " + payload); } @@ -278,10 +357,10 @@ public class Complex_Tests { System.out.println("\n\n Procedure termimated!!!"); } - private List readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { + private List readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { LOG.debug("readPayloadsForFileset called"); - List listPayloads = new ArrayList(); + List listPayloads = new ArrayList(); String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, "_payloads"); try { com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() @@ -296,7 +375,7 @@ public class Complex_Tests { LOG.trace("The _payloads is a String {}", toStringPayloads); JSONArray jsonArray = new JSONArray(toStringPayloads); for (int i = 0; i < jsonArray.length(); i++) { - PayloadDV payloadDV = Serialization.read(jsonArray.getJSONObject(i).toString(), PayloadDV.class); + Payload payloadDV = Serialization.read(jsonArray.getJSONObject(i).toString(), Payload.class); listPayloads.add(payloadDV); } } diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/GcubeProfilesMetadataForUCD.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/GcubeProfilesMetadataForUCD.java new file mode 100644 index 0000000..7489e8c --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/GcubeProfilesMetadataForUCD.java @@ -0,0 +1,63 @@ +package org.gcube.portlets.user.geoportaldataentry; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; + +public class GcubeProfilesMetadataForUCD { + + private String profileID; + private GcubeProfileDV gcubeProfile; + private List listMetadataProfileBean; + + public GcubeProfilesMetadataForUCD() { + + } + + public GcubeProfilesMetadataForUCD(String profileID, GcubeProfileDV gcubeProfile, + List listMetadataProfileBean) { + + this.profileID = profileID; + this.gcubeProfile = gcubeProfile; + this.listMetadataProfileBean = listMetadataProfileBean; + } + + public String getProfileID() { + return profileID; + } + + public GcubeProfileDV getGcubeProfile() { + return gcubeProfile; + } + + public List getListMetadataProfileBean() { + return listMetadataProfileBean; + } + + public void setProfileID(String profileID) { + this.profileID = profileID; + } + + public void setGcubeProfile(GcubeProfileDV gcubeProfile) { + this.gcubeProfile = gcubeProfile; + } + + public void setListMetadataProfileBean(List listMetadataProfileBean) { + this.listMetadataProfileBean = listMetadataProfileBean; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GcubeProfilesMetadataForUCD [profileID="); + builder.append(profileID); + builder.append(", gcubeProfile="); + builder.append(gcubeProfile); + builder.append(", listMetadataProfileBean="); + builder.append(listMetadataProfileBean); + builder.append("]"); + return builder.toString(); + } + +}