Skip to content
Snippets Groups Projects
Commit 3c8e4a22 authored by Truong Le's avatar Truong Le
Browse files

feat: resolved PR comments

parent 7d3491b7
No related branches found
No related tags found
2 merge requests!130integer data type,!124Validation CSV metadata
......@@ -7,41 +7,44 @@ import org.json4s.jackson.JsonMethods.parse
object ValidationMessages {
val emptyKind = "Kind in the request is missing or null"
val invalidKind = "Kind is not valid"
val emptyAcl = "Acl in the request is missing or null"
val emptyViewersOrOwners = "Viewers or owners in the [Acl] request is missing or null"
val emptyKind = "Metadata kind is missing or empty"
val invalidKind = "Metadata kind is not valid"
val emptyAcl = "Metadata acl section is missing or empty"
val emptyViewersOrOwners = "Viewers or owners in the [Acl] section is missing or empty"
val invalidViewersOrOwners = "Invalid viewers or owners group name"
val emptyData = "Data section in the request is missing or null"
val emptyLegal = "Legal in the request is missing or null"
val invalidEndian = "Invalid endian. Endian is an enumeration with values BIG or LITTLE"
val emptyEndian = "Endian in the request is missing or null"
val emptyDatasetProperties = "Dataset properties section in the request is missing or null"
val emptyFileSourceInfo = "File source info in the request is missing or null"
val emptyFileSource = "File source in the request is missing or null"
val emptyFileSize = "File size in the request is missing or null"
val invalidFileSize = "File size must be a integer"
val emptyLegalTags = "Legal tags in the request is missing or null"
val emptyOtherRelevantDataCountries = "Other relevant data countries in the request is missing or null"
val invalidOtherRelevantDataCountries = "Other relevant data countries just supports only the US region"
val emptyExtensionProperty = "Extension properties section in the request is missing or null"
val emptyFileContentsDetails = "File contents details in the request is missing or null"
val emptyEntities = "Entities in the request is missing or null"
val emptySourceColumn = "Source field of entities in the request is missing or null"
val emptyValuesStorage = "Entities values field in the request is missing or null"
val emptyTimeSeries = "Time Series in the request is missing or null"
val emptyPoints = "Points of time series in the request is missing or null"
val emptyTimeZoneOfSet = "Time zone of set in the request is missing or null"
val invalidTimeZoneOfSet = "Invalid time zone offset. The valid time zone offset eg: ±HH:MM"
val emptyData = "Metadata data section is missing or empty"
val emptyLegal = "Metadata legal section is missing or empty"
val invalidEndian = "Invalid endian. Allowed values are BIG or LITTLE"
val emptyEndian = "Metadata endian is missing or empty"
val emptyDatasetProperties = "Metadata datasetProperties section is missing or empty"
val emptyFileSourceInfo = "Metadata fileSourceInfo section is missing or empty"
val emptyFileSource = "Metadata fileSource is missing or empty"
val emptyFileSize = "Metadata fileSize is missing or empty"
val invalidFileSize = "Metadata fileSize allowed a integer value"
val emptyLegalTags = "Metadata legalTags is missing or empty"
val emptyOtherRelevantDataCountries = "Metadata otherRelevantDataCountries is missing or empty"
val invalidOtherRelevantDataCountries = "Invalid otherRelevantDataCountries. Allowed value is US"
val emptyExtensionProperty = "Metadata extensionProperties section is missing or empty"
val emptyFileContentsDetails = "Metadata fileContentsDetails section is missing or empty"
val emptyEntities = "Metadata entities is missing or empty"
val emptySourceColumn = "Metadata sourceColumn is missing or empty"
val emptyValuesStorage = "Metadata values of entities section is missing or empty"
val emptyTimeSeries = "Metadata timeSeries section is missing or empty"
val emptyPoints = "Metadata points section is missing or empty"
val emptyTimeZoneOfSet = "Metadata timeZoneOffset is missing or empty"
val invalidTimeZoneOfSet = "Invalid timeZoneOffset. The valid time zone offset eg: ±HH:MM"
val validRequest = "Metadata request is valid"
val reasonFailed = "Failed metadata validation"
val reasonSuccess = "Successfully metadata validation"
val emptyValueType = "Value type field in the request is missing or null"
val emptyValueTypeIfDefineFormat = "Value type field in the request is missing or null if value type field is DATETIME"
val invalidValueType = "Invalid value type. Value type is an enumeration with values DATETIME or TIMESTAMP"
val invalidFormat = "Invalid format. Format must be matches with the format DATETIME patterns"
val emptyValueTimeSeries = "Values section of time series in the request is missing or null"
val invalidValueTypesTimeSeries = "Invalid value type %: %. Value type of values in the request must be matches list of type: %"
val emptyValueType = "Metadata valueType is missing or empty"
val emptyFormatIfDefineValueType = "Metadata format is missing or empty. Because valueType is DATETIME. "
val invalidValueType = "Invalid valueType. Allowed values are DATETIME or TIMESTAMP"
val invalidFormat = "Invalid format. Allowed value matches with the format DATETIME patterns"
val emptyValueTimeSeries = "Metadata values section of timeSeries is missing or empty"
val invalidValueTypesTimeSeries = "Invalid values[%].valueType value: %. Allowed values are %"
val emptyValueTypesTimeSeries = "Metadata values[%].valueType is missing or empty"
val emptySourceColumnTimeSeries = "Metadata values[%].sourceColumn is missing or empty"
val emptyTargetPropertyDescriptor = "Metadata values[%].targetPropertyDescriptor is missing or empty"
def createMessage(msg: String, args: String*): String = {
var message = msg
......
package org.opengroup.osdu.production.util.validation
import org.opengroup.osdu.production.common.{LogF, ValidationMessages, ValueTypes}
import org.opengroup.osdu.production.inputRequestJson.{ValidationRequest, Data, DatasetProperty, Legal, ExtensionProperty}
import org.opengroup.osdu.production.inputRequestJson.{Data, DatasetProperty, ExtensionProperty, Legal, ValidationRequest}
import org.scalactic.{Bad, ErrorMessage, Good, Or}
import java.lang.IllegalArgumentException
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import scala.util.boundary
import scala.util.boundary.{Label, break}
object MetadataValidator extends LogF {
......@@ -162,7 +164,7 @@ object MetadataValidator extends LogF {
return Bad(ValidationMessages.emptyValueType)
} else if (valueType.get == "DATETIME") {
if (format.isEmpty) {
return Bad(ValidationMessages.emptyValueTypeIfDefineFormat)
return Bad(ValidationMessages.emptyFormatIfDefineValueType)
}
try {
DateTimeFormatter.ofPattern(format.get)
......@@ -172,7 +174,7 @@ object MetadataValidator extends LogF {
} else if (valueType.get != "TIMESTAMP") {
return Bad(ValidationMessages.invalidValueType)
}
if (format.isDefined) {
val timeZoneOfSet = points.get.timezoneOffset
if (timeZoneOfSet.isEmpty) {
......@@ -183,24 +185,41 @@ object MetadataValidator extends LogF {
return Bad(ValidationMessages.invalidTimeZoneOfSet)
}
}
val valueTimeSeries = timeSeries.get.values
if (valueTimeSeries.isEmpty) {
return Bad(ValidationMessages.emptyValueTimeSeries)
}
val timeSeriesValues = valueTimeSeries.get
for (i <- timeSeriesValues.indices) {
val valueType = timeSeriesValues(i)
if (valueType.valueType.isDefined) {
val validValueTypes = new ValueTypes
if (!validValueTypes.listOfValidValueTypes.exists(_.equals(valueType.valueType.get))) {
return Bad(ValidationMessages.createMessage(ValidationMessages.invalidValueTypesTimeSeries, (i + 1).toString,
valueType.valueType.get, validValueTypes.listOfValidValueTypes.mkString(", ")))
boundary {
for (i <- timeSeriesValues.indices) {
val value = timeSeriesValues(i)
val sourceColumn = value.sourceColumn
if (sourceColumn.isEmpty) {
break(Bad(ValidationMessages.createMessage(ValidationMessages.emptySourceColumnTimeSeries, (i + 1).toString)))
}
val targetPropertyDescriptor = value.targetPropertyDescriptor
if (targetPropertyDescriptor.isEmpty) {
break(Bad(ValidationMessages.createMessage(ValidationMessages.emptyTargetPropertyDescriptor, (i + 1).toString)))
}
}
}
Good(true)
val valueType = value.valueType
if (valueType.isDefined) {
val validValueTypes = new ValueTypes
if (!validValueTypes.listOfValidValueTypes.exists(_.equals(valueType.get))) {
break(Bad(ValidationMessages.createMessage(ValidationMessages.invalidValueTypesTimeSeries, (i + 1).toString,
valueType.get, validValueTypes.listOfValidValueTypes.mkString(", "))))
}
} else {
break(Bad(ValidationMessages.createMessage(ValidationMessages.emptyValueTypesTimeSeries, (i + 1).toString)))
}
}
Good(true)
} match
case Good(b) => Good(true)
case Bad(b) => Bad(b)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment