public class DcatFactory extends Object
GreedyDcatFactory
or extend this class and override the extract*
and/or postProcess* methods.Modifier and Type | Field and Description |
---|---|
protected static String |
DESCRIPTION |
protected static String |
ISSUED |
protected static String |
MODIFIED |
protected static String |
TITLE |
protected static String |
URI_FIELD |
Constructor and Description |
---|
DcatFactory()
Creates a factory with default configuration.
|
Modifier and Type | Method and Description |
---|---|
protected String |
extractAccessUrl(CkanResource resource) |
protected String |
extractAccrualPeriodicity(CkanDataset dataset) |
protected int |
extractByteSize(CkanResource resource) |
protected eu.trentorise.opendata.traceprov.dcat.VCard |
extractContactPoint(CkanDataset dataset) |
protected eu.trentorise.opendata.commons.Dict |
extractDescription(CkanDataset dataset,
Locale locale) |
protected eu.trentorise.opendata.commons.Dict |
extractDescription(CkanResource dataset,
Locale locale) |
protected String |
extractDownloadUrl(CkanResource resource) |
protected <T> T |
extractField(CkanDataset dataset,
String field,
Class<T> toClass) |
protected <T> T |
extractField(CkanDataset dataset,
String field,
com.fasterxml.jackson.core.type.TypeReference<T> toType)
Tries to extract a string field from a CkanDataset and casts it to target
type
|
protected String |
extractFieldAsNonEmptyString(CkanDataset dataset,
String field)
Like
extractFieldAsString(CkanDataset, String) but also checks
for trimmed non-emptiness. |
protected String |
extractFieldAsNonEmptyString(CkanResource resource,
String field)
Like
extractFieldAsString(CkanResource, String) but also checks
for trimmed non-emptiness. |
protected Object |
extractFieldAsObject(CkanDataset dataset,
String field)
Searches a field in
CkanDatasetBase.getOthers() and then in
CkanDatasetBase.getExtras() . |
protected String |
extractFieldAsString(CkanDataset dataset,
String field)
Searches a field in
CkanDatasetBase.getOthers() and then in
CkanDatasetBase.getExtras() . |
protected String |
extractFieldAsString(CkanResource resource,
String field)
Searches a field in
CkanResourceBase.getOthers() . |
protected String |
extractFormat(CkanResource resource) |
protected String |
extractIdentifier(CkanDataset dataset) |
protected String |
extractIssued(CkanDataset dataset) |
protected String |
extractIssued(CkanResource resource) |
protected List<String> |
extractKeywords(CkanDataset dataset) |
protected String |
extractLandingPage(CkanDataset dataset) |
protected List<Locale> |
extractLanguages(CkanDataset dataset)
i.e.
|
protected String |
extractLicense(CkanResource resource,
String license) |
protected String |
extractMediaType(CkanResource resource) |
protected String |
extractModified(CkanDataset dataset) |
protected String |
extractModified(CkanResource resource) |
protected eu.trentorise.opendata.traceprov.dcat.FoafAgent |
extractPublisher(CkanDataset dataset,
Locale locale)
Notice this extractor will mostly look for special dcat fields in
dataset, without resorting to ckan group, organization or maintainer as
fallback.
|
protected String |
extractRights(CkanResource resource) |
protected eu.trentorise.opendata.traceprov.geojson.GeoJson |
extractSpatial(CkanDataset dataset) |
protected eu.trentorise.opendata.commons.PeriodOfTime |
extractTemporal(CkanDataset dataset)
Returns a string with values trying to respect ISO 8601 format for time
intervals: https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
|
protected List<eu.trentorise.opendata.traceprov.dcat.SkosConcept> |
extractThemes(CkanDataset dataset,
Locale locale,
String catalogUrl)
Notice this extractor only looks for 'theme' field in dataset special
'others' and then 'extras', and doesn't fall back on groups.
|
protected eu.trentorise.opendata.commons.Dict |
extractTitle(CkanDataset dataset,
Locale locale) |
protected eu.trentorise.opendata.commons.Dict |
extractTitle(CkanResource resource,
Locale locale) |
protected String |
extractUri(CkanDataset dataset,
String catalogUrl) |
protected String |
extractUri(CkanResource resource,
String catalogUrl,
String datasetId) |
protected String |
formatLanguages(Iterable<Locale> locales)
Formats languages list so they can be put into a ckan extras field as
string (i.e.
|
protected String |
formatTimestamp(Timestamp timestamp)
Formats CKAN timestamp according to ISO 8601.
|
protected Logger |
getLogger()
Returns internal logger
|
protected com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper()
Returns internal object mapper
|
protected static boolean |
isTrimmedEmpty(String s)
Return true if the provided string is empty after getting trimmed.
|
protected void |
logCantExtract(String clazz,
String attribute,
Throwable ex) |
protected void |
logCantFind(String clazz,
String attribute) |
protected void |
logDatasetCantExtract(String attribute,
Throwable ex) |
protected void |
logDatasetCantFind(String attribute) |
protected void |
logDistribCantExtract(String attribute,
Throwable ex) |
protected void |
logDistribCantFind(String attribute) |
eu.trentorise.opendata.traceprov.dcat.DcatDataset |
makeDataset(CkanDataset dataset,
String catalogUrl,
Locale locale)
Converts a CkanDataset to a DcatDataset.
|
eu.trentorise.opendata.traceprov.dcat.DcatDistribution |
makeDistribution(CkanResource resource,
String catalogURL,
String datasetIdOrName,
String license,
Locale locale)
Converts a Ckan resource to a DcatDistribution.
|
protected void |
postProcessDataset(eu.trentorise.opendata.traceprov.dcat.DcatDataset.Builder datasetBuilder,
String catalogUrl,
Locale locale)
Post process the dataset builder after the extractions and prior to
creating the immutable DcatDataset object.
|
protected void |
postProcessDistribution(eu.trentorise.opendata.traceprov.dcat.DcatDistribution.Builder distributionBuilder,
CkanResource resource,
String catalogURL,
String datasetId,
String license,
Locale locale)
Post processes the distribution builder after the extractions and prior
to creating the immutable DcatDistribution object.
|
protected void |
setLogger(Logger logger)
Sets internal logger
|
protected void |
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets internal object mapper, registering also required modules of
traceprov
|
protected static String |
trim(String s)
Returns a new string with spaces removed at begin and end.
|
protected static final String ISSUED
protected static final String MODIFIED
protected static final String DESCRIPTION
protected static final String URI_FIELD
protected static final String TITLE
protected Logger getLogger()
protected void setLogger(Logger logger)
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
protected void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
protected String formatLanguages(Iterable<Locale> locales)
JackanException
- on errorprotected List<Locale> extractLanguages(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractFieldAsNonEmptyString(CkanDataset dataset, String field)
extractFieldAsString(CkanDataset, String)
but also checks
for trimmed non-emptiness.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractFieldAsNonEmptyString(CkanResource resource, String field)
extractFieldAsString(CkanResource, String)
but also checks
for trimmed non-emptiness.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractFieldAsString(CkanDataset dataset, String field)
CkanDatasetBase.getOthers()
and then in
CkanDatasetBase.getExtras()
. If search fails throws
JackanNotFoundException, even if field is found but has null value.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractFieldAsString(CkanResource resource, String field)
CkanResourceBase.getOthers()
. If search fails
throws JackanNotFoundException, even if field is found but has null value.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected Object extractFieldAsObject(CkanDataset dataset, String field)
CkanDatasetBase.getOthers()
and then in
CkanDatasetBase.getExtras()
. If search fails throws
JackanNotFoundException, even if field is found but has null value.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected <T> T extractField(CkanDataset dataset, String field, com.fasterxml.jackson.core.type.TypeReference<T> toType)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected <T> T extractField(CkanDataset dataset, String field, Class<T> toClass)
JackanNotFoundException
- when not foundJackanException
- on generic errorextractField(eu.trentorise.opendata.jackan.model.CkanDataset,
java.lang.String, com.fasterxml.jackson.core.type.TypeReference)
protected String formatTimestamp(Timestamp timestamp)
protected eu.trentorise.opendata.traceprov.geojson.GeoJson extractSpatial(CkanDataset dataset)
JackanNotFoundException
- if spatial is not foundJackanException
- for other errors.protected List<eu.trentorise.opendata.traceprov.dcat.SkosConcept> extractThemes(CkanDataset dataset, Locale locale, String catalogUrl)
locale
- the locale of the theme names. If unknown pass
Locale.ROOT
JackanNotFoundException
- if needed fields are missing.JackanException
- on generic errorprotected String extractUri(CkanDataset dataset, String catalogUrl)
catalogUrl
- i.e. http://dati.trentino.itJackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.commons.PeriodOfTime extractTemporal(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractIdentifier(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractIssued(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractModified(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.traceprov.dcat.FoafAgent extractPublisher(CkanDataset dataset, Locale locale)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.traceprov.dcat.VCard extractContactPoint(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected List<String> extractKeywords(CkanDataset dataset)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected static String trim(@Nullable String s)
protected eu.trentorise.opendata.commons.Dict extractTitle(CkanDataset dataset, Locale locale)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.commons.Dict extractDescription(CkanDataset dataset, Locale locale)
locale
- if unknown pass Locale.ROOT
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractAccrualPeriodicity(CkanDataset dataset)
protected String extractLandingPage(CkanDataset dataset)
protected void logDatasetCantFind(String attribute)
@Beta public eu.trentorise.opendata.traceprov.dcat.DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale locale)
dataset
- must be non null, but it may have missing or null fields.catalogUrl
- non-null catalog url, i.e. "http://dati.trentino.it" or empty
one ""locale
- the locale of metadata text. If locale is unknown, use
Locale.ROOT
. todo write about data localeprotected void postProcessDataset(eu.trentorise.opendata.traceprov.dcat.DcatDataset.Builder datasetBuilder, String catalogUrl, Locale locale)
datasetBuilder
- postProcessDistribution(eu.trentorise.opendata.traceprov.dcat.DcatDistribution.Builder,
CkanResource, String, String, String, Locale)
protected void logDistribCantFind(String attribute)
protected String extractUri(CkanResource resource, String catalogUrl, String datasetId)
resource
- catalogUrl
- i.e. http://dati.trentino.itdatasetId
- JackanNotFoundException
- when not foundJackanException
- on generic errorprotected static boolean isTrimmedEmpty(@Nullable String s)
protected void postProcessDistribution(eu.trentorise.opendata.traceprov.dcat.DcatDistribution.Builder distributionBuilder, CkanResource resource, String catalogURL, String datasetId, String license, Locale locale)
protected String extractModified(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractIssued(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractAccessUrl(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractDownloadUrl(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected int extractByteSize(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.commons.Dict extractDescription(CkanResource dataset, Locale locale)
locale
- if unknown pass Locale.ROOT
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractFormat(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractLicense(CkanResource resource, String license)
license
- value used if resource does not already have a license field.
If unknown pass the empty string.JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractMediaType(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected String extractRights(CkanResource resource)
JackanNotFoundException
- when not foundJackanException
- on generic errorprotected eu.trentorise.opendata.commons.Dict extractTitle(CkanResource resource, Locale locale)
locale
- if unknown pass Locale.ROOT
JackanNotFoundException
- when not foundJackanException
- on generic error@Beta public eu.trentorise.opendata.traceprov.dcat.DcatDistribution makeDistribution(CkanResource resource, String catalogURL, String datasetIdOrName, String license, Locale locale)
resource
- must be non null, but it may have missing or null fields.catalogURL
- catalog string, i.e. http://dati.trentino.itdatasetIdOrName
- owner dataset alphanumerical id (i.e.
fccc07ce-3750-4970-92fd-6a6f432b4466, preferred as stable) or
dataset name (less preferred, as names can change over time)license
- A link to the license document under which the distribution is
made available. For more info, see
ADcatDistribution.getLicense()
. If license is unknown, use an empty string.locale
- The language of the distribution. if unknown use
Locale.ROOT
Copyright © 2015 Trento Rise. All rights reserved.