Skip to content

Commit

Permalink
validation of station name and TSI. (#41)
Browse files Browse the repository at this point in the history
* Addition of validation / cleaning of station name in station editor form.

* Addition of validation / cleaning of station name in station editor form.

* Addition of validation / cleaning of station name in station editor form.

* Relax constraints on free text fields. Now tags and escape codes stripped.

* Additional of semi-colon and backslash to removed characters.

* Update of validation rules for import oscar.

* TSI not mandatory.
  • Loading branch information
david-i-berry authored Apr 26, 2024
1 parent 647b9d3 commit 671a3b4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
32 changes: 20 additions & 12 deletions src/components/ImportOSCAR.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<v-text-field
label="Traditional station identifier"
v-model="station.properties.traditional_station_identifier"
:rules="[rules.validTSI]"
hint="Enter the traditional (5 or 7 digit) station identifier" persistent-hint>
</v-text-field>
</v-card-item>
Expand Down Expand Up @@ -137,6 +136,16 @@
import CodeListSelector from '@/components/CodeListSelector.vue';
import APIStatus from '@/components/APIStatus.vue';
function stripHTMLTags(input){
if( typeof input !== 'string' ){
console.warning("Invalid input passed to stripHTMLTags, empty string returned")
return '';
}
const tag_regex = /<\/?[a-zA-Z]+\/?>/g;
const escapes = /[\x00-\x1F\x7F;\\]/g;
return input.replace(tag_regex,'').replace(escapes,'');
}
export default defineComponent({
name: "ImportOSCAR",
components: {
Expand Down Expand Up @@ -180,15 +189,14 @@
const token = ref(null);
const rules = ref({
validWSI: value => /^0-[0-9]{1,5}-[0-9]{0,5}-[0-9a-zA-Z]{1,16}$/.test(value) || 'Invalid WSI',
validTSI: value => (!value) || (/^\d{5}(\d{2})?$/.test(value) ) ? true : 'Invalid TSI',
validTSI: value => value && value.length > 0 ? true : 'TSI must be set',
validLongitude: value => ! (Math.abs(value) > 180 || isNaN(value)) ? true : 'Invalid longitude',
validLatitude: value => value && ! (Math.abs(value) > 90 || isNaN(value)) ? true : 'Invalid latitude',
validElevation: value => value && ! isNaN(value) ? true : 'Invalid elevation',
validBarometerHeight: value => value && ! isNaN(value) ? true : 'Invalid barometer height',
validName: value => value && value.length > 3 ? true : 'Name must be more than 3 characters',
token: value => value && value.length > 0 ? true: 'Please enter the authorization token',
validName: value => value && value.length > 0 ? true : 'Name must be set',
token: value => value && value.length > 0 ? true : 'Please enter the authorization token',
topic: value => value.length > 0 ? true : 'Select at least one topic'
});
const data = ref(null);
const router = useRouter();
Expand Down Expand Up @@ -232,7 +240,7 @@
var leaf = "";
apiURL = apiURL + leaf;
var record = {
id: station.value.properties.wigos_station_identifier, // WSI
id: stripHTMLTags(station.value.properties.wigos_station_identifier), // WSI
type: 'Feature',
geometry: {
type: 'Point',
Expand All @@ -241,18 +249,18 @@
parseFloat(station.value.geometry.elevation)]
},
properties: {
name: station.value.properties.name,
wigos_station_identifier: station.value.properties.wigos_station_identifier, // WSI
traditional_station_identifier: station.value.properties.traditional_station_identifier,
name: stripHTMLTags(station.value.properties.name),
wigos_station_identifier: stripHTMLTags(station.value.properties.wigos_station_identifier), // WSI
traditional_station_identifier: stripHTMLTags(station.value.properties.traditional_station_identifier),
facility_type: station.value.properties.facility_type['skos:notation'] ?? null,
territory_name: station.value.properties.territory_name['skos:notation'] ?? null,
barometer_height: parseFloat(station.value.properties.barometer_height),
wmo_region: station.value.properties.wmo_region['skos:notation'] ?? null,
url: "https://oscar.wmo.int/surface/#/search/station/stationReportDetails/" +
station.value.properties.wigos_station_identifier,
stripHTMLTags(station.value.properties.wigos_station_identifier),
topics: station.value.properties.topics.map( (topic) => (topic.id)),
status: station.value.properties.status['skos:notation'] ?? null,
id: station.value.properties.wigos_station_identifier // WSI
id: stripHTMLTags(station.value.properties.wigos_station_identifier) // WSI
}
}
Expand Down Expand Up @@ -307,7 +315,7 @@
var apiURL = `${import.meta.env.VITE_API_URL}/processes/oscar2feature/execution`;
var payload = {
"inputs": {
"wigos_station_identifier": wsi.value
"wigos_station_identifier": stripHTMLTags(wsi.value)
}
};
// get data
Expand Down
28 changes: 18 additions & 10 deletions src/components/StationEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
label="Traditional station identifier"
v-model="station.properties.traditional_station_identifier"
:readonly="readonly"
hint="Enter the traditional (5 or 7 digit) station identifier" persistent-hint>
hint="Enter the traditional station identifier (ASCII or numeric characters only)" persistent-hint>
</v-text-field>
</v-card-item>
<v-card-item>
Expand Down Expand Up @@ -119,7 +119,15 @@
import CodeListSelector from '@/components/CodeListSelector.vue';
import APIStatus from '@/components/APIStatus.vue';
function stripHTMLTags(input){
if( typeof input !== 'string' ){
console.warning("Invalid input passed to stripHTMLTags, empty string returned")
return '';
}
const tag_regex = /<\/?[a-zA-Z]+\/?>/g;
const escapes = /[\x00-\x1F\x7F;\\]/g;
return input.replace(tag_regex,'').replace(escapes,'');
}
export default defineComponent({
name: 'StationEditor',
Expand All @@ -146,12 +154,12 @@
// define validation rules
const rules = ref({
validWSI: value => /^0-[0-9]{1,5}-[0-9]{0,5}-[0-9a-zA-Z]{1,16}$/.test(value) || 'Invalid WSI',
validTSI: value => (!value) || (/^\d{5}(\d{2})?$/.test(value) ) ? true : 'Invalid TSI',
validTSI: value => value && value.length > 0 ? true : 'TSI must be set',
validLongitude: value => ! (Math.abs(value) > 180 || isNaN(value)) ? true : 'Invalid longitude',
validLatitude: value => value && ! (Math.abs(value) > 90 || isNaN(value)) ? true : 'Invalid latitude',
validElevation: value => value && ! isNaN(value) ? true : 'Invalid elevation',
validBarometerHeight: value => value && ! isNaN(value) ? true : 'Invalid barometer height',
validName: value => value && value.length > 3 ? true : 'Name must be more than 3 characters',
validName: value => value && value.length > 0 ? true : 'Name must be set',
token: value => value && value.length > 0 ? true : 'Please enter the authorization token',
topic: value => value.length > 0 ? true : 'Select at least one topic'
});
Expand All @@ -172,7 +180,7 @@
return;
}
var record = {
id: station.value.properties.wigos_station_identifier, // WSI
id: stripHTMLTags(station.value.properties.wigos_station_identifier), // WSI
type: 'Feature',
geometry: {
type: 'Point',
Expand All @@ -181,18 +189,18 @@
parseFloat(station.value.geometry.elevation)]
},
properties: {
name: station.value.properties.name,
wigos_station_identifier: station.value.properties.wigos_station_identifier, // WSI
traditional_station_identifier: station.value.properties.traditional_station_identifier,
name: stripHTMLTags(station.value.properties.name),
wigos_station_identifier: stripHTMLTags(station.value.properties.wigos_station_identifier), // WSI
traditional_station_identifier: stripHTMLTags(station.value.properties.traditional_station_identifier),
facility_type: station.value.properties.facility_type['skos:notation'] ?? null,
territory_name: station.value.properties.territory_name['skos:notation'] ?? null,
barometer_height: parseFloat(station.value.properties.barometer_height),
wmo_region: station.value.properties.wmo_region['skos:notation'] ?? null,
url: "https://oscar.wmo.int/surface/#/search/station/stationReportDetails/" +
station.value.properties.wigos_station_identifier,
stripHTMLTags(station.value.properties.wigos_station_identifier),
topics: station.value.properties.topics.map( (topic) => (topic.id)),
status: station.value.properties.status['skos:notation'] ?? null,
id: station.value.properties.wigos_station_identifier // WSI
id: stripHTMLTags(station.value.properties.wigos_station_identifier) // WSI
}
}
var apiURL = `${import.meta.env.VITE_API_URL}/collections/stations/items`;
Expand Down

0 comments on commit 671a3b4

Please sign in to comment.