Skip to content
Permalink
Browse files

#1121 Add validation and placeholder for metadata 'Geo-coordinates'

-> Changes due to the added requirement 3, see ticket 1121.
-> Implementation variant 1: 'Geo-coordinates' is still part of the
general collection metadata (= additional information). If
'Geo-coordinates' exists as collection metadata with the exact label
'Geo-coordinates', it gets validated and has a placeholder.

- Add 'Geo-coordinates' and 'Article DOI' as specific additional
information labels to ImejiConfiguration
- Add getPlaceholder() method to CollectionBean (used in editForm.xhtml)
- Add validateGeoCoordinates() method to CollectionValidator
- Add appropriate placeholder and error message as label/message
  • Loading branch information...
helkv committed May 15, 2019
1 parent 86e7a12 commit 850f5f53767b1159e8b052c088482471e9d38997
@@ -22,7 +22,6 @@
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;

@@ -129,6 +128,10 @@
public static final String DEFAULT_GOOGLE_MAPS_API = "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=";
public static final String DEFAULT_CONE_AUTHORS = "http://pubman.mpdl.mpg.de/cone/persons/query?format=json&n=10&m=full&q=";

// Specific collection metadata (= ContainerAdditionalInfo), which have a validation or placeholder for their input field:
public static final String COLLECTION_METADATA_GEO_COORDINATES_LABEL = "Geo-coordinates";
public static final String COLLECTION_METADATA_ARTICLE_DOI_LABEL = "Article DOI";

private String dataViewerUrl;

private ProtectedPassword emailServerPassword;
@@ -10,6 +10,7 @@

import de.mpg.imeji.exceptions.UnprocessableError;
import de.mpg.imeji.logic.config.Imeji;
import de.mpg.imeji.logic.config.ImejiConfiguration;
import de.mpg.imeji.logic.model.CollectionImeji;
import de.mpg.imeji.logic.model.ContainerAdditionalInfo;
import de.mpg.imeji.logic.model.Organization;
@@ -64,15 +65,14 @@ private void validateAdditionalInfos(CollectionImeji c) {
setException(new UnprocessableError("error_additionalinfo_need_label", getException()));
}

if (info.getLabel().equals("Article DOI") && !isNullOrEmpty(info.getText())) {
if (info.getLabel().equals(ImejiConfiguration.COLLECTION_METADATA_ARTICLE_DOI_LABEL) && !isNullOrEmpty(info.getText())) {
validateDOI(info.getText());
}
/*
if (isNullOrEmpty(info.getText()) && isNullOrEmpty(info.getUrl())) {
//setException(new UnprocessableError("error_additionalinfo_need_value", getException()));

if (info.getLabel().equals(ImejiConfiguration.COLLECTION_METADATA_GEO_COORDINATES_LABEL) && !isNullOrEmpty(info.getText())
&& !validateGeoCoordinates(info.getText())) {
this.exception = new UnprocessableError("error_geo_coordinates_format", exception);
}
*/
}
}

@@ -207,6 +207,31 @@ private boolean validateORCIDString(String orcid) {
}
}

/**
* Validate Geo-coordinates. <br/>
* The Geo-coordinates String must be of the form: 'Latitude(double value from -90 to 90),
* Longitude(double value from -180 to 180)' e.g. 48.147870, 11.576709
*
* @param geoCoordinates The geoCoordinates as String, containing: latitude, longitude
* @return geoCoordinates are valid or not
*/
private boolean validateGeoCoordinates(String geoCoordinates) {
try {
String[] geoCoordinatesArray = geoCoordinates.split(",");

if (geoCoordinatesArray.length != 2) {
return false;
}

double latitude = Double.parseDouble(geoCoordinatesArray[0]);
double longitude = Double.parseDouble(geoCoordinatesArray[1]);

return (latitude >= -90.0 && latitude <= 90.0 && longitude >= -180.0 && longitude <= 180.0);
} catch (Exception e) {
return false;
}
}

private void setException(UnprocessableError e) {
this.exception = e;
}
@@ -2,12 +2,12 @@

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.faces.model.SelectItem;

import de.mpg.imeji.logic.config.Imeji;
import de.mpg.imeji.logic.config.ImejiConfiguration;
import de.mpg.imeji.logic.model.CollectionImeji;
import de.mpg.imeji.logic.model.ContainerAdditionalInfo;
import de.mpg.imeji.logic.model.Organization;
@@ -86,6 +86,22 @@ public void removeAdditionalInfo(int pos) {
collection.getAdditionalInformations().remove(pos);
}

/**
* Get the appropriate placeholder for an input field by its label. <br/>
* Used for additional informations, where only some of the additional information have a
* placeholder.
*
* @param inputFiledLabel The label of the input field.
* @return The placeholder or an empty String if no placeholder exists.
*/
public String getPlaceholder(String inputFiledLabel) {
if (ImejiConfiguration.COLLECTION_METADATA_GEO_COORDINATES_LABEL.equals(inputFiledLabel)) {
return Imeji.RESOURCE_BUNDLE.getLabel("placeholder_geocoordinates", getLocale());
} else {
return "";
}
}

/**
* Add a new author to the {@link CollectionImeji}
*
@@ -986,6 +986,8 @@ placeholder_additional_info_label = select from list

placeholder_date = 2000-01-01 oder 2000-01 oder 2000

placeholder_geocoordinates = Breite(-90 bis 90), L\u00E4nge(-180 bis 180) z.B. 60.123, -120.4567

placeholder_geolocation_latitude = min -90, max 90

placeholder_geolocation_longitude = min -180, max 180
@@ -990,6 +990,8 @@ placeholder_additional_info_label = select from list

placeholder_date = 2000-01-01 or 2000-01 or 2000

placeholder_geocoordinates = Latitude(-90 to 90), Longitude(-180 to 180) e.g. 60.123, -120.4567

placeholder_geolocation_latitude = min -90, max 90

placeholder_geolocation_longitude = min -180, max 180
@@ -205,6 +205,8 @@ error_empty_password = Sie haben kein Passwort eingegeben

error_file_not_found_logged_in = Die Datei wurde nicht gefunden. Bitte pr\u00FCfen Sie, ob die URL richtig ist, ob die Datei nicht gel\u00F6scht wurde, oder ob Sie die Berichtigung haben, um diese Datei zu sehen.

error_geo_coordinates_format = Die Geo-coordinates sind nicht valide. Flasches Format! Sie m\u00FCssen folgenderma\u00DFen eingegeben werden: Breite(-90 bis 90), L\u00E4nge(-180 bis 180) z.B. 60.123, -120.4567

error_image_delete = Fehler beim L\u00F6schen des Inhaltes!

error_image_load = Fehler beim Laden des Inhaltes!
@@ -207,6 +207,8 @@ error_empty_password = You did not enter a password

error_file_not_found_logged_in = The file you are looking for couldn't be found. Please check if the url is correct, if the file has not been removed, or if you are allowed to view this file.

error_geo_coordinates_format = The Geo-coordinates are not valid. Wrong format! Need to be: Latitude(-90 to 90), Longitude(-180 to 180) e.g. 60.123, -120.4567

error_image_delete = Error during deletion of the item!

error_image_load = Error during loading of the item!
@@ -109,7 +109,7 @@
</h:panelGroup>

<!-- <label class="imj_metadataLabel">#{lbl.text}</label>-->
<h:inputTextarea id="inputInfoText" styleClass="imj_metadataValue" value="#{info.text}" html5:placeholder="#{lbl.placeholder_text}" />
<h:inputTextarea id="inputInfoText" styleClass="imj_metadataValue" value="#{info.text}" html5:placeholder="#{cc.attrs.formularBean.getPlaceholder(info.label)}" />
</div>
<!--
<div class="imj_metadataSet">

0 comments on commit 850f5f5

Please sign in to comment.
You can’t perform that action at this time.