Made the code "more robust" (adding some try/catch and checking null

value)
This commit is contained in:
Francesco Mangiacrapa 2023-01-19 11:35:50 +01:00
parent 3c12d6a841
commit 0d4428e341
5 changed files with 89 additions and 60 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">
@ -44,7 +45,8 @@
<wb-module deploy-name="geoportal-data-viewer-app-3.1.0"> <wb-module deploy-name="geoportal-data-viewer-app-3.1.0">
@ -89,7 +91,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -134,7 +137,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -179,7 +183,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
@ -224,7 +229,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -272,7 +278,8 @@
<dependent-module archiveName="geoportal-data-common-2.0.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common"> <dependent-module archiveName="geoportal-data-common-2.0.1.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>
@ -317,7 +324,8 @@
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
@ -362,7 +370,8 @@
<property name="context-root" value="geoportal-data-viewer-app"/> <property name="context-root" value="geoportal-data-viewer-app"/>
@ -407,7 +416,8 @@
</wb-module> </wb-module>

View File

@ -152,7 +152,7 @@ public class GeoportalDataViewerConstants {
var tabCell = tr.insertCell(-1); var tabCell = tr.insertCell(-1);
var theValue = jsonObj[j][col[i]]; var theValue = jsonObj[j][col[i]];
//console.log("the value: "+theValue); //console.log("the value: "+theValue);
if (Object.prototype.toString.call(theValue) === '[object Array]') { if (theValue !== null && Object.prototype.toString.call(theValue) === '[object Array]') {
var formattedValueArray = ""; var formattedValueArray = "";
for (var k = 0; k < theValue.length; k++) { for (var k = 0; k < theValue.length; k++) {
var theValueArray = theValue[k]; var theValueArray = theValue[k];

View File

@ -17,6 +17,8 @@ import com.github.gwtbootstrap.client.ui.PageHeader;
import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.IconType; import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
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.ui.Composite; import com.google.gwt.user.client.ui.Composite;
@ -42,76 +44,93 @@ public class SectionViewer extends Composite {
public SectionViewer(SectionView sectionView, String topTargetId) { public SectionViewer(SectionView sectionView, String topTargetId) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
this.sectionView = sectionView; this.sectionView = sectionView;
List<SubDocumentView> subDocuments = sectionView.getListSubDocuments(); List<SubDocumentView> subDocuments = sectionView.getListSubDocuments();
sectionTitle.setTitle(sectionView.getSectionTitle()); sectionTitle.setTitle(sectionView.getSectionTitle());
sectionTitle.setText(sectionView.getSectionTitle()); sectionTitle.setText(sectionView.getSectionTitle());
if (subDocuments == null)
return;
Button goToTop = new Button(""); Button goToTop = new Button("");
goToTop.setType(ButtonType.LINK); goToTop.setType(ButtonType.LINK);
goToTop.setIcon(IconType.DOUBLE_ANGLE_UP); goToTop.setIcon(IconType.DOUBLE_ANGLE_UP);
goToTop.setHref("#"+topTargetId); goToTop.setHref("#" + topTargetId);
goToTop.setTitle("Go to top"); goToTop.setTitle("Go to top");
goToTop.getElement().setClassName("go-top-right"); goToTop.getElement().setClassName("go-top-right");
sectionTitle.add(goToTop); sectionTitle.add(goToTop);
boolean displayAsGallery = false; 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; try {
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);
ImagesSectionGallery sectionGallery = new ImagesSectionGallery(sectionView);
sectionPanelContainer.add(sectionGallery.getGalleryPanel());
sectionGallery.fillGallery();
// Displaying the whole section as a Map of Layers
} else if (displayAsMapOfLayers) {
GWT.log("displayAsMapOfLayers the: "+sectionView);
for (SubDocumentView subDocumentView : subDocuments) { 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);
ImagesSectionGallery sectionGallery = new ImagesSectionGallery(sectionView);
sectionPanelContainer.add(sectionGallery.getGalleryPanel());
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
sectionGallery.fillGallery();
}
});
// 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()); // String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON());
// sectionPanelContainer.add(new HTML(table)); // sectionPanelContainer.add(new HTML(table));
List<GCubeSDIViewerLayerDV> layers = subDocumentView.getListLayers(); List<GCubeSDIViewerLayerDV> layers = subDocumentView.getListLayers();
if (layers != null) { if (layers != null) {
for (GCubeSDIViewerLayerDV gCubeLayer : layers) { for (GCubeSDIViewerLayerDV gCubeLayer : layers) {
LayersSectionViewer layerSectionViewer = new LayersSectionViewer(gCubeLayer, subDocumentView); LayersSectionViewer layerSectionViewer = new LayersSectionViewer(gCubeLayer,
sectionPanelContainer.add(layerSectionViewer); subDocumentView);
//showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload()); sectionPanelContainer.add(layerSectionViewer);
// showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload());
}
} }
} }
}
}else {
GWT.log("displaying default the: "+sectionView);
for (SubDocumentView subDocumentView : subDocuments) {
String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON());
sectionPanelContainer.add(new HTML(table));
List<FilesetDV> files = subDocumentView.getListFiles(); } else {
if (files != null) { GWT.log("displaying default the: " + sectionView);
for (FilesetDV fileset : files) { for (SubDocumentView subDocumentView : subDocuments) {
showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload()); String table = GeoportalDataViewerConstants.jsonToTableHTML(subDocumentView.getMetadataAsJSON());
sectionPanelContainer.add(new HTML(table));
List<FilesetDV> files = subDocumentView.getListFiles();
if (files != null) {
for (FilesetDV fileset : files) {
showLinkToDownloadWsContent(fileset.getName(), fileset.getListPayload());
}
} }
} }
} }
} catch (Exception e) {
GWT.log("Error on rendering the section: "+e.getMessage());
} }
} }

View File

@ -919,7 +919,7 @@ public class Geoportal_JSON_Mapper {
if (theObjectFieldValue instanceof String) { if (theObjectFieldValue instanceof String) {
String toString = (String) theObjectFieldValue; String toString = (String) theObjectFieldValue;
if (toString != null && !toString.isEmpty()) { if (toString != null && !toString.isEmpty()) {
toDoc.append(fieldLabel, theObjectFieldValue); toDoc.append(fieldLabel, toString.trim());
} else { } else {
LOG.debug("Skipping String field " + fieldLabel + " its value is null or empty"); LOG.debug("Skipping String field " + fieldLabel + " its value is null or empty");
} }

View File

@ -75,7 +75,7 @@
return [ year, month, day ].join('-'); return [ year, month, day ].join('-');
} }
return ""; return date + "";
} catch (err) { } catch (err) {
return date + ""; return date + "";
} }