Added Expand Button into View Relations Panel

This commit is contained in:
Francesco Mangiacrapa 2022-10-18 15:30:12 +02:00
parent f576b0f966
commit c34faa9f68
10 changed files with 283 additions and 137 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -51,7 +52,8 @@
<wb-module deploy-name="geoportal-data-entry-app-3.0.0-SNAPSHOT"> <wb-module deploy-name="geoportal-data-entry-app-3.0.0-SNAPSHOT">
@ -103,7 +105,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -155,7 +158,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -207,20 +211,16 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="metadata-profile-form-builder-widget-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-form-builder-widget/metadata-profile-form-builder-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="metadata-profile-discovery-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-discovery/metadata-profile-discovery">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="geoportal-data-common-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common"> <dependent-module archiveName="geoportal-data-common-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
@ -272,7 +272,8 @@
<property name="context-root" value="geoportal-data-entry-app"/> <property name="context-root" value="geoportal-data-entry-app"/>
@ -324,7 +325,8 @@
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
@ -376,7 +378,8 @@
</wb-module> </wb-module>

View File

@ -46,17 +46,6 @@ public class ConstantsGeoPortalDataEntryApp {
public static final String WORKFLOW_ACTION_POST_CREATION_ACTION_ID = "post_creation_action"; 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. * The Enum ACTION_PERFORMED_ON_ITEM.
* *

View File

@ -656,7 +656,7 @@ public class GeonaMainTabPanel extends Composite {
if (!bool) { if (!bool) {
return; return;
} }
viewRelationshipPanel = new ViewRelationshipPanel(appManagerBus, selectedDocument); viewRelationshipPanel = new ViewRelationshipPanel(appManagerBus, selectedDocument, true);
detailsPanel.add(viewRelationshipPanel); detailsPanel.add(viewRelationshipPanel);
} }

View File

@ -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.Button;
import com.github.gwtbootstrap.client.ui.Label; 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.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.IconSize; import com.github.gwtbootstrap.client.ui.constants.IconSize;
import com.github.gwtbootstrap.client.ui.constants.IconType; 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.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; 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.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlexTable;
@ -59,13 +61,16 @@ public class ViewRelationshipPanel extends Composite {
@UiField @UiField
Button closeButton; Button closeButton;
@UiField
Button buttonExpand;
private HashMap<Integer, ResultDocumentDV> selectedProjects = new HashMap<Integer, ResultDocumentDV>(2); private HashMap<Integer, ResultDocumentDV> selectedProjects = new HashMap<Integer, ResultDocumentDV>(2);
private HandlerManager appManagerBus; private HandlerManager appManagerBus;
private Map<String, ResultDocumentDV> mapOfTargetProjectForId = new HashMap<String, ResultDocumentDV>(); private Map<String, ResultDocumentDV> mapOfTargetProjectForId = new HashMap<String, ResultDocumentDV>();
public ViewRelationshipPanel(HandlerManager appManagerBus, ResultDocumentDV fromProject) { public ViewRelationshipPanel(HandlerManager appManagerBus, ResultDocumentDV fromProject, boolean showExpand) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
this.appManagerBus = appManagerBus; 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); showRelationsOf(fromProject);
} }
@ -89,8 +122,8 @@ public class ViewRelationshipPanel extends Composite {
secondProjectPanelContainer.clear(); secondProjectPanelContainer.clear();
Entry<String, Object> firstEntrySet = project.getFirstEntryOfMap(); Entry<String, Object> firstEntrySet = project.getFirstEntryOfMap();
String htmlMsg = firstEntrySet.getKey() + ": <b>" + firstEntrySet.getValue() String htmlMsg = firstEntrySet.getKey() + ": <b>" + firstEntrySet.getValue() + "</b> (id: " + project.getId()
+ "</b> (id: " + project.getId() + ")"; + ")";
firstProjectPanelContainer.add(new HTML(htmlMsg)); firstProjectPanelContainer.add(new HTML(htmlMsg));
ReportTemplateToHTML rtth = new ReportTemplateToHTML("", project.getDocumentAsJSON(), false, false); ReportTemplateToHTML rtth = new ReportTemplateToHTML("", project.getDocumentAsJSON(), false, false);
@ -105,37 +138,35 @@ public class ViewRelationshipPanel extends Composite {
secondProjectPanelContainer.clear(); secondProjectPanelContainer.clear();
for (RelationshipDV relationDV : project.getListRelationshipDV()) { for (RelationshipDV relationDV : project.getListRelationshipDV()) {
final FlexTable flexTable = new FlexTable(); final FlexTable flexTable = new FlexTable();
flexTable.getElement().addClassName("box-table-diplay-project"); flexTable.getElement().addClassName("box-table-diplay-project");
Label label = new Label(); Label label = new Label();
label.setType(LabelType.INFO); label.setType(LabelType.INFO);
label.setText(relationDV.getRelationshipName()); label.setText(relationDV.getRelationshipName());
FlowPanel panelContainer = new FlowPanel(); FlowPanel panelContainer = new FlowPanel();
Button deleteRelation = new Button("",IconType.TRASH); Button deleteRelation = new Button("", IconType.TRASH);
deleteRelation.setTitle("Delete this releation"); deleteRelation.setTitle("Delete this releation");
deleteRelation.setType(ButtonType.LINK); deleteRelation.setType(ButtonType.LINK);
deleteRelation.addClickHandler(new ClickHandler() { deleteRelation.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
ResultDocumentDV toProject = mapOfTargetProjectForId.get(relationDV.getTargetUCD()); 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(label);
panelContainer.add(deleteRelation); panelContainer.add(deleteRelation);
flexTable.setWidget(0, 0, panelContainer); flexTable.setWidget(0, 0, panelContainer);
flexTable.setWidget(1, 0, new LoaderIcon("loading project..")); flexTable.setWidget(1, 0, new LoaderIcon("loading project.."));
GeoportalDataEntryServiceAsync.Util.getInstance().getResultDocumentFoProjectByID(relationDV.getTargetUCD(), GeoportalDataEntryServiceAsync.Util.getInstance().getResultDocumentFoProjectByID(
relationDV.getTargetID(), new AsyncCallback<ResultDocumentDV>() { relationDV.getTargetUCD(), relationDV.getTargetID(), new AsyncCallback<ResultDocumentDV>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
@ -149,17 +180,17 @@ public class ViewRelationshipPanel extends Composite {
Entry<String, Object> firstEntrySet = result.getFirstEntryOfMap(); Entry<String, Object> firstEntrySet = result.getFirstEntryOfMap();
String htmlMsg = firstEntrySet.getKey() + ": <b>" + firstEntrySet.getValue() String htmlMsg = firstEntrySet.getKey() + ": <b>" + firstEntrySet.getValue()
+ "</b> (id: " + result.getId() + ")"; + "</b> (id: " + result.getId() + ")";
flexTable.setWidget(1, 0, new HTML(htmlMsg)); 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); rtth2.showAsJSON(false);
flexTable.setWidget(2, 0, rtth2); flexTable.setWidget(2, 0, rtth2);
} }
}); });
secondProjectPanelContainer.add(flexTable); secondProjectPanelContainer.add(flexTable);
} }

View File

@ -34,6 +34,10 @@
padding-left: 10px; padding-left: 10px;
padding-top: 5px; padding-top: 5px;
} }
.float-right {
float: right;
}
</ui:style> </ui:style>
<g:HTMLPanel> <g:HTMLPanel>
@ -41,6 +45,8 @@
addStyleNames="{style.to-align-right}"></b:Button> addStyleNames="{style.to-align-right}"></b:Button>
<g:HTMLPanel ui:field="panelTitle" <g:HTMLPanel ui:field="panelTitle"
addStyleNames="{style.view-rel-title}">View Relations</g:HTMLPanel> addStyleNames="{style.view-rel-title}">View Relations</g:HTMLPanel>
<b:Button ui:field="buttonExpand"
addStyleNames="{style.float-right}">Expand</b:Button>
<g:HTMLPanel ui:field="firstPanelContainer" <g:HTMLPanel ui:field="firstPanelContainer"
addStyleNames="{style.panel-style}"> addStyleNames="{style.panel-style}">
<g:FlowPanel> <g:FlowPanel>
@ -48,7 +54,6 @@
</g:FlowPanel> </g:FlowPanel>
<g:FlowPanel ui:field="firstProjectPanelContainer" <g:FlowPanel ui:field="firstProjectPanelContainer"
addStyleNames="{style.panel-container-style}"></g:FlowPanel> addStyleNames="{style.panel-container-style}"></g:FlowPanel>
</g:HTMLPanel> </g:HTMLPanel>
<g:HTMLPanel ui:field="secondPanelContainer" <g:HTMLPanel ui:field="secondPanelContainer"
addStyleNames="{style.panel-style}"> addStyleNames="{style.panel-style}">

View File

@ -136,30 +136,6 @@ public class ReportTemplateToHTML extends Composite {
GWT.log("report is: " + theJSONDocument); GWT.log("report is: " + theJSONDocument);
vpContainer.setVisible(true); 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 { try {
JSONValue jsonObj = JSONParser.parse(theJSONDocument); JSONValue jsonObj = JSONParser.parse(theJSONDocument);
@ -168,8 +144,6 @@ public class ReportTemplateToHTML extends Composite {
reportTable.add(new HTML(toTableHTML)); reportTable.add(new HTML(toTableHTML));
//htmlContainer.add(new HTML(toTableHTML));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
GWT.log("error: " + e.getMessage()); GWT.log("error: " + e.getMessage());
@ -179,13 +153,14 @@ public class ReportTemplateToHTML extends Composite {
reportJSON.add(new HTML("<pre>" + ExternalLib.toPrettyPrintJSON(theJSONDocument) + "</pre>")); reportJSON.add(new HTML("<pre>" + ExternalLib.toPrettyPrintJSON(theJSONDocument) + "</pre>"));
} }
} }
/** /**
* 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 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) { public ReportTemplateToHTML(String documentLabel, String theJSONDocument, boolean openJSONReport) {
@ -245,16 +220,15 @@ public class ReportTemplateToHTML extends Composite {
} }
} }
public void showAsHTMLTable(boolean bool) { public void showAsHTMLTable(boolean bool) {
showReportAsTable.setVisible(bool); showReportAsTable.setVisible(bool);
} }
public void showAsJSON(boolean bool) { public void showAsJSON(boolean bool) {
showReportAsJSON.setVisible(bool); showReportAsJSON.setVisible(bool);
} }
/** /**
* Json to HTML. * Json to HTML.
* *

View File

@ -451,7 +451,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of projects for id: ", 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());
} }
} }

View File

@ -54,6 +54,7 @@ h1 {
.my-html-table td { .my-html-table td {
padding: 5px; padding: 5px;
border-bottom: 1px solid gray; border-bottom: 1px solid gray;
min-width: 100px;
} }
.my-html-table td:first-child { .my-html-table td:first-child {
@ -247,6 +248,7 @@ h1 {
border: 1px solid #96a5b5; border: 1px solid #96a5b5;
border-radius: 5px; border-radius: 5px;
margin-bottom: 5px; margin-bottom: 5px;
word-break: break-word;
} }
.box-table-diplay-project td { .box-table-diplay-project td {

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.geoportaldataentry; package org.gcube.portlets.user.geoportaldataentry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; 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.ProjectsCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.geoportal.access.GeportalCheckAccessPolicy; 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.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; 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.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.project.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; 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.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; 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.ProjectView;
import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView;
import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView;
@ -60,6 +62,38 @@ public class Complex_Tests {
public static final String JSON_$_POINTER = "$"; public static final String JSON_$_POINTER = "$";
private static final Logger LOG = LoggerFactory.getLogger(Complex_Tests.class); private static final Logger LOG = LoggerFactory.getLogger(Complex_Tests.class);
private LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> 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<? extends Enum<?>> e) {
return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new);
}
public static List<String> 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 @Before
public void init() { public void init() {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
@ -68,51 +102,73 @@ public class Complex_Tests {
clientUCD = GeoportalClientCaller.useCaseDescriptors(); clientUCD = GeoportalClientCaller.useCaseDescriptors();
} }
@Before
public void preloadgCubeProfilesForUCDs() {
LOG.debug("preloadgCubeProfilesForUCDs called");
try {
List<UseCaseDescriptor> 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<HandlerDeclaration> 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<GcubeProfileDV> listGcubeProfiles = toListGcubeProfiles(config);
LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles);
List<GcubeProfilesMetadataForUCD> listProfilesBean = new ArrayList<GcubeProfilesMetadataForUCD>();
// Loading Metadata Profile from IS
MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
linkedMap_UCDId_gCubeProfiles = new LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>();
for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD();
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<MetaDataProfileBean> 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 @Test
public void testReadProjectForUCDDataEntry() { public void testReadProjectForUCDDataEntry() {
ScopeProvider.instance.set(CONTEXT); ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN); SecurityTokenProvider.instance.set(TOKEN);
try { 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<HandlerDeclaration> 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<GcubeProfileDV> listGcubeProfiles = toListGcubeProfiles(config);
LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles);
// Loading Metadata Profile from IS
MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
LinkedHashMap<String, List<MetaDataProfileBean>> linkedHashProfiles = new LinkedHashMap<String, List<MetaDataProfileBean>>();
for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<MetaDataProfileBean> 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); Project theProject = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
@ -126,7 +182,7 @@ public class Complex_Tests {
projectView.setTheProjectDV(theProjectDV); projectView.setTheProjectDV(theProjectDV);
// NO UCD defined, applyong default // 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.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD");
LOG.info("Applying default business logic to display the project"); LOG.info("Applying default business logic to display the project");
SectionView sectionView = new SectionView(); SectionView sectionView = new SectionView();
@ -137,12 +193,15 @@ public class Complex_Tests {
projectView.addSectionView(sectionView); projectView.addSectionView(sectionView);
} }
List<GcubeProfilesMetadataForUCD> listProfilesBean = linkedMap_UCDId_gCubeProfiles.get(PROFILE_ID);
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build(); .jsonProvider(new JsonOrgJsonProvider()).build();
// Reading the Project according to list of Profile defined in the UCD // 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 sectionView = new SectionView();
sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle());
LOG.debug("\n\nThe profile is: " + gcubeProfileDV); LOG.debug("\n\nThe profile is: " + gcubeProfileDV);
@ -197,8 +256,7 @@ public class Complex_Tests {
} }
LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument);
List<MetaDataProfileBean> theProfileBeans = linkedHashProfiles List<MetaDataProfileBean> theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean();
.get(gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName());
MetaDataProfileBean theProfileBean = theProfileBeans.get(0); MetaDataProfileBean theProfileBean = theProfileBeans.get(0);
// For each bson.Document creating the SubDocumentView // 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 // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG
if (filePaths != null) { if (filePaths != null) {
String fromSectionDocJSON = fromSectionDoc.toJson(); String fromSectionDocJSON = fromSectionDoc.toJson();
List<FilesetDV> listFileSet = new ArrayList<FilesetDV>(); List<FilesetDV> listFiles = new ArrayList<FilesetDV>();
List<FilesetDV> listImages = new ArrayList<FilesetDV>();
for (FilePathDV filePath : filePaths) { for (FilePathDV filePath : filePaths) {
String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName());
List<PayloadDV> listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); List<Payload> listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON);
FilesetDV filesetDV = new FilesetDV(); FilesetDV filesetDV = new FilesetDV();
filesetDV.setName(filePath.getGcubeProfileFieldName()); filesetDV.setName(filePath.getGcubeProfileFieldName());
filesetDV.addListPayloadsDV(listPayloads); for (Payload payload : listPayloads) {
listFileSet.add(filesetDV); 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); sectionView.addSubDocument(subDocumentView);
@ -254,13 +324,22 @@ public class Complex_Tests {
System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######"); System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######");
int i = 1; int i = 1;
for (SubDocumentView subDocument : section.getListSubDocuments()) { 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("***** Metadata");
System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON())); System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON()));
System.out.println("***** Files"); System.out.println("***** Files");
if (subDocument.getListFiles() != null) { if (subDocument.getListFiles() != null) {
for (FilesetDV filesetDV : subDocument.getListFiles()) { 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()) { for (PayloadDV payload : filesetDV.getListPayload()) {
System.out.println("********* Payload: " + payload); System.out.println("********* Payload: " + payload);
} }
@ -278,10 +357,10 @@ public class Complex_Tests {
System.out.println("\n\n Procedure termimated!!!"); System.out.println("\n\n Procedure termimated!!!");
} }
private List<PayloadDV> readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { private List<Payload> readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) {
LOG.debug("readPayloadsForFileset called"); LOG.debug("readPayloadsForFileset called");
List<PayloadDV> listPayloads = new ArrayList<PayloadDV>(); List<Payload> listPayloads = new ArrayList<Payload>();
String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, "_payloads"); String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, "_payloads");
try { try {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() 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); LOG.trace("The _payloads is a String {}", toStringPayloads);
JSONArray jsonArray = new JSONArray(toStringPayloads); JSONArray jsonArray = new JSONArray(toStringPayloads);
for (int i = 0; i < jsonArray.length(); i++) { 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); listPayloads.add(payloadDV);
} }
} }

View File

@ -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<MetaDataProfileBean> listMetadataProfileBean;
public GcubeProfilesMetadataForUCD() {
}
public GcubeProfilesMetadataForUCD(String profileID, GcubeProfileDV gcubeProfile,
List<MetaDataProfileBean> listMetadataProfileBean) {
this.profileID = profileID;
this.gcubeProfile = gcubeProfile;
this.listMetadataProfileBean = listMetadataProfileBean;
}
public String getProfileID() {
return profileID;
}
public GcubeProfileDV getGcubeProfile() {
return gcubeProfile;
}
public List<MetaDataProfileBean> getListMetadataProfileBean() {
return listMetadataProfileBean;
}
public void setProfileID(String profileID) {
this.profileID = profileID;
}
public void setGcubeProfile(GcubeProfileDV gcubeProfile) {
this.gcubeProfile = gcubeProfile;
}
public void setListMetadataProfileBean(List<MetaDataProfileBean> 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();
}
}