Improved Publication Report. Moved to -SNAPSHOT

Feature_20435
Francesco Mangiacrapa 3 years ago
parent 67a8a88f48
commit 6734edf04e

@ -5,7 +5,7 @@ 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.2.0] - 2020-12-18
## [v1.2.0-SNAPSHOT] - 2020-12-18
#### Enhancements

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>geoportal-data-entry-app</artifactId>
<packaging>war</packaging>
<version>1.2.0</version>
<version>1.2.0-SNAPSHOT</version>
<name>GeoPortal Data Entry App</name>
<description>The GeoPortal Data Entry App is an application to build the web forms for data entries needed to GeoNa project</description>
<scm>

@ -15,6 +15,9 @@ import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFor
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaDataEntryMainForm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaMainPanel;
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
import org.gcube.portlets.user.geoportaldataentry.client.ui.report.ReportTemplateToHTML;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
@ -34,6 +37,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@ -76,7 +80,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
mainPanel = new GeonaMainPanel(appManagerBus);
mainPanel.setLoaderVisible("Loading...", true);
geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus);
GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback<GeonaISConfig>() {
@ -216,7 +220,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
modal.setCloseVisible(false);
modal.setTitle("Saving project...");
modal.hide(false);
final HorizontalPanel modalContainerPanel = new HorizontalPanel();
modal.setWidth(600);
modal.setMaxHeigth("650px");
final VerticalPanel modalContainerPanel = new VerticalPanel();
final LoaderIcon loader = new LoaderIcon();
loader.setText("Trying to save the data, please wait...");
modalContainerPanel.add(loader);
@ -244,63 +250,73 @@ public class GeoPortalDataEntryApp implements EntryPoint {
public void onSuccess(CommitReport result) {
modalContainerPanel.clear();
modal.setCloseVisible(true);
Alert alert = new Alert(result.getMsg());
HTML recordPublished = new HTML();
switch (result.getState()) {
case OK:
alert.setType(AlertType.SUCCESS);
String success = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "32CD32", null, "SUCCESS");
recordPublished.setHTML("Record Published with "+success);
projectSavedWithSuccess = true;
geoNaMainForm.showAlertOnSaveAction(result.getMsg(), AlertType.SUCCESS, true);
String msg = result.getMsg()!=null?result.getMsg():"Record published with success";
geoNaMainForm.showAlertOnSaveAction(msg, AlertType.SUCCESS, true);
purgeFileUploaded();
break;
case WARN:
alert.setType(AlertType.WARNING);
String warning = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "FF8000", null, "WARNING");
recordPublished.setHTML("Record Published with "+warning);
geoNaMainForm.enableButtonSave(true);
if(result.getReport()!=null)
modal.add(new Alert(result.getReport(), AlertType.INFO));
break;
case ERROR:
alert.setType(AlertType.ERROR);
String error = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "FF0000", "bold", "ERROR");
recordPublished.setHTML(error+" on publishing the Record");
geoNaMainForm.enableButtonSave(true);
if(result.getReport()!=null)
modal.add(new Alert(result.getReport(), AlertType.INFO));
break;
default:
break;
}
alert.setClose(false);
modal.add(alert);
try {
savedMap.put(result.getRecordId(), saveGeonaDataFormsEvent.getListGeonaDataForms());
}catch (Exception e) {
// TODO: handle exception
}
final HorizontalPanel hpLoader = new HorizontalPanel();
final LoaderIcon lc = new LoaderIcon("Get link...");
hpLoader.add(lc);
modal.add(hpLoader);
GeoportalDataEntryServiceAsync.Util.getInstance().getLinksFor(result.getRecordId(), "concessione", new AsyncCallback<GeoNaItemRef>() {
@Override
public void onFailure(Throwable caught) {
hpLoader.clear();
}
modalContainerPanel.add(recordPublished);
if(result.getRecordId()!=null) {
modalContainerPanel.add(new HTML("Record id: "+(result.getRecordId())));
@Override
public void onSuccess(GeoNaItemRef result) {
hpLoader.clear();
String htmlLink = "<div>Go to record: <a href="+result.getRestrictedLink().getShortURL()+" target=\"_blank\">"+result.getRestrictedLink().getShortURL()+"</a></div>";
HTML html = new HTML(htmlLink);
modal.add(html);
try {
savedMap.put(result.getRecordId(), saveGeonaDataFormsEvent.getListGeonaDataForms());
}catch (Exception e) {
// TODO: handle exception
}
});
final HorizontalPanel hpGetLink = new HorizontalPanel();
final LoaderIcon lc = new LoaderIcon("Get link...");
hpGetLink.add(lc);
modalContainerPanel.add(hpGetLink);
GeoportalDataEntryServiceAsync.Util.getInstance().getLinksFor(result.getRecordId(), "concessione", new AsyncCallback<GeoNaItemRef>() {
@Override
public void onFailure(Throwable caught) {
hpGetLink.clear();
}
@Override
public void onSuccess(GeoNaItemRef result) {
hpGetLink.clear();
String theURL = result.getRestrictedLink().getShortURL()!=null?result.getRestrictedLink().getShortURL():result.getRestrictedLink().getCompleteURL();
String htmlLink = "<div>Go to record: <a href="+theURL+" target=\"_blank\">"+theURL+"</a></div>";
HTML html = new HTML(htmlLink);
hpGetLink.add(html);
//modal.add(html);
}
});
}
//geoNaMainForm.enableButtonSave(true);
//resetUI();
if(result.getReport()!=null) {
modalContainerPanel.add(new ReportTemplateToHTML(result.getReport()));
}
}
});
@ -336,6 +352,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
});
}
private void purgeFileUploaded() {
MetadataProfileFormBuilderServiceAsync.Util.getInstance().purgeFilesUploaded(new AsyncCallback<Integer>() {
@ -354,54 +371,6 @@ public class GeoPortalDataEntryApp implements EntryPoint {
});
}
public static native String jsonToHTML(String jsonTxt)/*-{
try
{
var jsonObj = JSON.parse(jsonTxt);
if(jsonObj.length==undefined)
jsonObj = [jsonObj]
//console.log(jsonObj.length)
// EXTRACT VALUE FOR HTML HEADER.
var col = [];
for (var i = 0; i < jsonObj.length; i++) {
for (var key in jsonObj[i]) {
//console.log('key json' +key)
if (col.indexOf(key) === -1) {
col.push(key);
}
}
}
// CREATE DYNAMIC TABLE.
var table = document.createElement("table");
try{
table.classList.add("my-html-table");
}catch(e){
console.log('invalid css add', e);
}
// ADD JSON DATA TO THE TABLE AS ROWS.
for (var i = 0; i < col.length; i++) {
tr = table.insertRow(-1);
var firstCell = tr.insertCell(-1);
//firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;";
firstCell.innerHTML = col[i];
for (var j = 0; j < jsonObj.length; j++) {
var tabCell = tr.insertCell(-1);
var theValue = jsonObj[j][col[i]];
tabCell.innerHTML = theValue;
}
}
return table;
}
catch(e){
console.log('invalid json', e);
}
}-*/;
}

@ -0,0 +1,172 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.report;
import com.github.gwtbootstrap.client.ui.Paragraph;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class ReportTemplateToHTML.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 25, 2021
*/
public class ReportTemplateToHTML extends Composite {
private static ReportTemplateToHTMLUiBinder uiBinder = GWT.create(ReportTemplateToHTMLUiBinder.class);
/**
* The Interface ReportTemplateToHTMLUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 25, 2021
*/
interface ReportTemplateToHTMLUiBinder extends UiBinder<Widget, ReportTemplateToHTML> {
}
@UiField
VerticalPanel vpContainer;
@UiField
VerticalPanel htmlContainer;
@UiField
Paragraph reportJSON;
boolean toJSONERROR = false;
/**
* Instantiates a new report template to HTML.
*
* @param report the report
*/
public ReportTemplateToHTML(String report) {
initWidget(uiBinder.createAndBindUi(this));
vpContainer.setVisible(false);
if (report != null) {
GWT.log("report is: " + report);
vpContainer.setVisible(true);
try {
JSONValue jsonObj = JSONParser.parse(report);
JSONObject json = (JSONObject) jsonObj;
JSONValue valueChildren = json.get("children");
JSONArray jsonChildren = (JSONArray) valueChildren;
/*JSONObject jsonChildrenObject = (JSONObject) jsonChildren.get(0);
if (jsonChildrenObject.containsKey("objectName")) {
JSONValue validationReportON = jsonChildrenObject.get("objectName");
String titleValue = HTMLUtil.getHTMLElement(HTML_TAG.div, 14, "000", "bold", validationReportON.toString());
htmlContainer.add(new HTML(titleValue));
}
String toTableHTML = jsonToHTML(jsonChildrenObject.get("children").toString());
GWT.log("toJSONERROR is: " + toJSONERROR);
GWT.log("toTableHTML is: " + toTableHTML);
Set<String> keySet = jsonChildrenObject.keySet();*/
String toTableHTML = null;
for (int i=0; i<jsonChildren.size(); i++) {
JSONObject jsO = (JSONObject) jsonChildren.get(i);
if (jsO.containsKey("children")) {
/*if (jsO.containsKey("objectName")) {
JSONValue validationReportON = jsO.get("objectName");
String titleValue = HTMLUtil.getHTMLElement(HTML_TAG.div, 14, "000", "bold", validationReportON.toString());
htmlContainer.add(new HTML(titleValue));
}*/
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());
}
reportJSON.setText(report);
}
}
/**
* Json to HTML.
*
* @param jsonTxt the json txt
* @return the string
*/
public static native String jsonToHTML(String jsonTxt)/*-{
try {
var jsonObj = JSON.parse(jsonTxt);
if (jsonObj.length == undefined)
jsonObj = [ jsonObj ]
//console.log(jsonObj.length)
// EXTRACT VALUE FOR HTML HEADER.
var col = [];
for (var i = 0; i < jsonObj.length; i++) {
for ( var key in jsonObj[i]) {
//console.log('key json' +key)
if (col.indexOf(key) === -1) {
col.push(key);
}
}
}
// CREATE DYNAMIC TABLE.
var table = document.createElement("table");
try {
table.classList.add("my-html-table");
} catch (e) {
console.log('invalid css add', e);
}
// ADD JSON DATA TO THE TABLE AS ROWS.
for (var i = 0; i < col.length; i++) {
tr = table.insertRow(-1);
var firstCell = tr.insertCell(-1);
//firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;";
firstCell.innerHTML = col[i];
for (var j = 0; j < jsonObj.length; j++) {
var tabCell = tr.insertCell(-1);
var theValue = jsonObj[j][col[i]];
//console.log("the value: "+theValue);
if(Object.prototype.toString.call(theValue) === '[object Array]'){
var formattedValueArray = "";
for(var k = 0; k < theValue.length; k++) {
var theValueArray = theValue[k];
//console.log(theValueArray);
formattedValueArray += theValueArray+"<br>";
}
tabCell.innerHTML = formattedValueArray;
}
else{
tabCell.innerHTML = theValue;
}
}
}
return table.outerHTML;
} catch (e) {
console.log('invalid json', e);
return jsonTxt;
}
}-*/;
}

@ -0,0 +1,25 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.important {
font-weight: bold;
}
.margin-top-10 {
margin-top: 10px;
}
</ui:style>
<g:HTMLPanel>
<g:VerticalPanel ui:field="vpContainer"
addStyleNames="{style.margin-top-10}">
<b:Label>Publication Report: </b:Label>
<g:VerticalPanel ui:field="htmlContainer" addStyleNames="{style.margin-top-10}"></g:VerticalPanel>
<b:AccordionGroup heading="Show Report as JSON">
<b:Paragraph ui:field="reportJSON"></b:Paragraph>
</b:AccordionGroup>
</g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

@ -0,0 +1,81 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.utils;
/**
* The Class HTMLUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 26, 2021
*/
public class HTMLUtil {
/**
* The Enum HTML_TAG.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 26, 2021
*/
public static enum HTML_TAG {
p, div, span
}
/**
* Gets the HTML element.
*
* @param tag the tag
* @param textSize the text size
* @param rgb the rgb
* @param fontWeight the font weight
* @param text the text
* @return the HTML element
*/
public static String getHTMLElement(HTML_TAG tag, Integer textSize, String rgb, String fontWeight, String text) {
StringBuilder htmlEl = new StringBuilder();
if (textSize != null || rgb != null || fontWeight != null) {
String style = "";
if (textSize != null) {
style += "font-size:" + textSize + ";";
}
if (rgb != null) {
style += "color:#" + rgb + ";";
}
if (fontWeight != null) {
style += "font-weight:" + fontWeight + ";";
}
htmlEl.append("<" + tag.name() + " style='" + style + "'>");
} else {
htmlEl.append(tagOPEN(tag));
}
if (text != null) {
htmlEl.append(text);
}
htmlEl.append(tagCLosed(tag));
return htmlEl.toString();
}
/**
* Tag OPEN.
*
* @param tag the tag
* @return the string
*/
public static String tagOPEN(HTML_TAG tag) {
return "<" + tag.name() + ">";
}
/**
* Tag C losed.
*
* @param tag the tag
* @return the string
*/
public static String tagCLosed(HTML_TAG tag) {
return "</" + tag.name() + ">";
}
}

@ -95,6 +95,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.debug("Built " + ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
// saving into back-end
//SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
manager = ManagerFactory.registerNew(concessione);
// ABSTRACT_RELAZIONE_DI_SCAVO

@ -37,4 +37,19 @@ h1 {
.green-text a {
color: green !important;
}
.my-html-table {
padding: 5px;
margin-left:10px;
margin-bottom: 10px;
}
.my-html-table td {
padding: 5px;
border: 1px solid gray;
}
.my-html-table td:first-child {
color: gray;
}
Loading…
Cancel
Save