Class JsonUtils
java.lang.Object
org.opengis.cite.ogcapifeatures10.util.JsonUtils
JsonUtils class.
- Author:
- Lyn Goltz
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcollectNumberOfAllReturnedFeatures(io.restassured.path.json.JsonPath jsonPath, int maximumLimit) Collects the number of all returned features by iterating over all 'next' links and summarizing the size of features in 'features' array property.static StringfindFeaturesUrlForGeoJson(URI rootUri, io.restassured.path.json.JsonPath collection) Finds the URL to the resource /collections/{collectionId}/items from the path /collections/{collectionId}static StringfindFeaturesUrlForGeoJson(URI rootUri, Map<String, Object> collection) Finds the URL to the resource /collections/{collectionId}/items from the path /collectionsstatic StringfindFeatureUrlForGeoJson(URI rootUri, io.restassured.path.json.JsonPath collection, String featureId) Finds the URL to the resource /collections/{collectionId}/items/{featureId} from the path /collections and creates an valid url to this resourcestatic StringFinds the URL to the resource /collections/{collectionId}/items/{featureId} from the path /collections and creates an valid url to this resourceParses the link with 'rel=self'.Parses the links without 'rel' or 'type' property.findLinksWithSupportedMediaTypeByRel(List<Map<String, Object>> links, List<String> mediaTypesToSupport, String expectedRel) Parses all links with 'type' of one of the passed mediaTypes and the 'rel' property with the passed value.Parsing the media types which does not have a link woth property 'type' for.static StringformatDate(LocalDate date) Formats the passed string as ISO 8601 date.static StringformatDate(ZonedDateTime dateTime) Formats the passed string as ISO 8601 date.static StringformatDateRange(ZonedDateTime beginDateTime, ZonedDateTime endDateTime) Formats the passed string as a period using a start and end time.static StringformatDateRangeWithDuration(LocalDate beginDate, LocalDate endDate) Formats the passed string as a period using start time and a duration.static booleanhasAtLeastOneSpatialFeatureCollection(io.restassured.path.json.JsonPath jsonPath) Checks if a at least one of the collection in the /collections response has a spatial extent.static booleanChecks if the extent contains a spatial extent.static booleanhasAtLeastOneSpatialFeatureCollection(Map<String, Object> collection) Checks if a at least one of the collection in the /collections response has a spatial extent.static booleanhasProperty(String propertyName, io.restassured.path.json.JsonPath jsonPath) Checks if a property with the passed name exists in the jsonPath.static booleanlinkIncludesRelAndType(Map<String, Object> link) Checks if the passed link contains 'rel' and 'type' properties.static ZonedDateTimeparseAsDate(String dateTime) Parses the passed string as ISO 8601 date.parseAsList(String propertyName, io.restassured.path.json.JsonPath jsonPath) Retrieves the property values as list.parseAsList(String propertyName, Map<String, Object> json) Retrieves the property values as list.parseAsListOfMaps(String propertyName, io.restassured.path.json.JsonPath jsonPath) Retrieves the property values as list.static StringparseAsString(Object value) Parse value ass string.static org.locationtech.jts.geom.GeometryparseFeatureGeometry(Map<String, Object> feature, CoordinateSystem crs) Parse the geometry property as geometry.static StringparseFeatureId(io.restassured.path.json.JsonPath collectionItemJson) Parses the id of the first feature from the passed json.static BBoxparseSpatialExtent(Map<String, Object> collection) Parses the spatial extent from the passed collection.static TemporalExtentparseTemporalExtent(Map<String, Object> collection) Parses the temporal extent from the passed collection.
-
Method Details
-
parseAsString
Parse value ass string.- Parameters:
value- to parse, may benull- Returns:
- the value as string,
nullif the passed value wasnull
-
parseFeatureId
Parses the id of the first feature from the passed json.- Parameters:
collectionItemJson- the json document containing the features, nevernull- Returns:
- the parsed id, may be
nullif no feature could be found
-
parseTemporalExtent
Parses the temporal extent from the passed collection.- Parameters:
collection- the collection containing the extent to parse, nevernull- Returns:
- the parsed temporal extent,
nullif no extent exists - Throws:
IllegalArgumentException- if the number of items in the extent invalid
-
parseAsDate
Parses the passed string as ISO 8601 date.- Parameters:
dateTime- the dateTime to parse, nevernull- Returns:
- the parsed date, never
null
-
formatDate
Formats the passed string as ISO 8601 date. Example: "2018-02-12T23:20:50Z"- Parameters:
dateTime- the dateTime to format, nevernull- Returns:
- the formatted date, never
null
-
formatDate
Formats the passed string as ISO 8601 date. Example: "2018-02-12"- Parameters:
date- the dateTime to format, nevernull- Returns:
- the formatted date, never
null
-
formatDateRange
Formats the passed string as a period using a start and end time. Example: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"- Parameters:
beginDateTime- the begin dateTime to format, nevernullendDateTime- the end dateTime to format, nevernull- Returns:
- the formatted date, never
null
-
formatDateRangeWithDuration
Formats the passed string as a period using start time and a duration. Example: "2018-02-12T00:00:00Z/P1M6DT12H31M12S"- Parameters:
beginDate- the begin date to format, nevernullendDate- the end date to format, nevernull- Returns:
- the formatted date, never
null
-
parseSpatialExtent
Parses the spatial extent from the passed collection.- Parameters:
collection- the collection containing the extent to parse, nevernull- Returns:
- the parsed bbox,
nullif no extent exists - Throws:
IllegalArgumentException- if the number of items in the extent invalid
-
findLinksWithSupportedMediaTypeByRel
public static List<Map<String,Object>> findLinksWithSupportedMediaTypeByRel(List<Map<String, Object>> links, List<String> mediaTypesToSupport, String expectedRel) Parses all links with 'type' of one of the passed mediaTypes and the 'rel' property with the passed value.- Parameters:
links- list of all links, nevernullmediaTypesToSupport- a list of media types the links searched for should support, may be empty but nevernullexpectedRel- the expected value of the property 'rel', nevernull- Returns:
- a list of links supporting one of the media types and with the expected
'rel' property, may be empty but never
null
-
findUnsupportedTypes
public static List<String> findUnsupportedTypes(List<Map<String, Object>> links, List<String> mediaTypesToSuppport) Parsing the media types which does not have a link woth property 'type' for.- Parameters:
links- list of links to search in, nevernullmediaTypesToSuppport- a list of media types which should be supported, nevernull- Returns:
- the media types which does not have a link for.
-
findLinksWithoutRelOrType
public static List<String> findLinksWithoutRelOrType(List<Map<String, Object>> links, Set<String> rels) Parses the links without 'rel' or 'type' property.- Parameters:
links- list of links to search in, nevernullrels- Set of relation types, nevernull- Returns:
- the links without 'rel' or 'type' property
-
findLinkByRel
Parses the link with 'rel=self'.- Parameters:
links- list of links to search in, nevernullexpectedRel- the expected value of the property 'rel', nevernull- Returns:
- the link to itself or
nullif no such link exists
-
linkIncludesRelAndType
Checks if the passed link contains 'rel' and 'type' properties.- Parameters:
link- to check, nevernull- Returns:
trueif the link contains 'rel' and 'type' properties,falseotherwise
-
hasProperty
Checks if a property with the passed name exists in the jsonPath.- Parameters:
propertyName- name of the property to check, nevernulljsonPath- to check, nevernull- Returns:
trueif the property exists,falseotherwise
-
hasAtLeastOneSpatialFeatureCollection
public static boolean hasAtLeastOneSpatialFeatureCollection(io.restassured.path.json.JsonPath jsonPath) Checks if a at least one of the collection in the /collections response has a spatial extent.- Parameters:
jsonPath- to check, nevernull- Returns:
trueat least one of the collection has a spatial extent,falseotherwise
-
hasAtLeastOneSpatialFeatureCollection
Checks if a at least one of the collection in the /collections response has a spatial extent.- Parameters:
collection- to check, nevernull- Returns:
trueat least one of the collection has a spatial extent,falseotherwise
-
hasAtLeastOneSpatialFeatureCollection
Checks if the extent contains a spatial extent.- Parameters:
extent- to check, nevernull- Returns:
trueif extent contains a spatial extent,falseotherwise
-
parseAsList
public static List<String> parseAsList(String propertyName, io.restassured.path.json.JsonPath jsonPath) Retrieves the property values as list.- Parameters:
propertyName- name of the property, nevernulljsonPath- the json document to retrieve properties from, nevernull- Returns:
- the property values as list, may be empty but never
null
-
parseAsListOfMaps
public static List<Map<String,Object>> parseAsListOfMaps(String propertyName, io.restassured.path.json.JsonPath jsonPath) Retrieves the property values as list.- Parameters:
propertyName- name of the property, nevernulljsonPath- the json document to retrieve properties from, nevernull- Returns:
- the property values as list, may be empty but never
null
-
parseAsList
Retrieves the property values as list.- Parameters:
propertyName- name of the property, nevernulljson- the json map to retrieve properties from, nevernull- Returns:
- the property values as list, may be empty but never
null
-
collectNumberOfAllReturnedFeatures
public static int collectNumberOfAllReturnedFeatures(io.restassured.path.json.JsonPath jsonPath, int maximumLimit) throws URISyntaxException Collects the number of all returned features by iterating over all 'next' links and summarizing the size of features in 'features' array property.- Parameters:
jsonPath- the initial collection, nevernullmaximumLimit- the limit parameter value to use, if <= 0 the parameter is omitted- Returns:
- the number of all returned features
- Throws:
URISyntaxException- if the creation of a uri fails
-
findFeaturesUrlForGeoJson
public static String findFeaturesUrlForGeoJson(URI rootUri, io.restassured.path.json.JsonPath collection) Finds the URL to the resource /collections/{collectionId}/items from the path /collections/{collectionId}- Parameters:
rootUri- nevernullcollection- the /collections/{collectionId} response, nevernull- Returns:
- the url to the resource /collections/{collectionId}/items or
null
-
findFeaturesUrlForGeoJson
Finds the URL to the resource /collections/{collectionId}/items from the path /collections- Parameters:
rootUri- nevernullcollection- the collection object /collections response, nevernull- Returns:
- the url to the resource /collections/{collectionId}/items or
null
-
findFeatureUrlForGeoJson
public static String findFeatureUrlForGeoJson(URI rootUri, io.restassured.path.json.JsonPath collection, String featureId) Finds the URL to the resource /collections/{collectionId}/items/{featureId} from the path /collections and creates an valid url to this resource- Parameters:
rootUri- nevernullcollection- the /collections/{collectionId} response, nevernullfeatureId- id of the feature, nevernull- Returns:
- the url to the resource /collections/{collectionId}/items or
null
-
findFeatureUrlForGeoJson
public static String findFeatureUrlForGeoJson(URI rootUri, Map<String, Object> collection, String featureId) Finds the URL to the resource /collections/{collectionId}/items/{featureId} from the path /collections and creates an valid url to this resource- Parameters:
rootUri- nevernullcollection- the collection object /collections response, nevernullfeatureId- id of the feature, nevernull- Returns:
- the url to the resource /collections/{collectionId}/items or
null
-
parseFeatureGeometry
public static org.locationtech.jts.geom.Geometry parseFeatureGeometry(Map<String, Object> feature, CoordinateSystem crs) throws org.locationtech.jts.io.ParseExceptionParse the geometry property as geometry.- Parameters:
feature- to parse, nevernullcrs- the crs of the geometry, may benull- Returns:
- the parsed geometry,
nullif the feature has no geometry property - Throws:
org.locationtech.jts.io.ParseException- if the geometry could not be parsed
-