use of org.apache.sis.metadata.sql.MetadataStoreException in project sis by apache.
the class Store method getMetadata.
/**
* Returns the metadata associated to the CSV file, or {@code null} if none.
*
* @return the metadata associated to the CSV file, or {@code null} if none.
* @throws DataStoreException if an error occurred during the parsing process.
*/
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
if (metadata == null) {
final MetadataBuilder builder = new MetadataBuilder();
try {
builder.setFormat(timeEncoding != null && hasTrajectories ? StoreProvider.MOVING : StoreProvider.NAME);
} catch (MetadataStoreException e) {
listeners.warning(null, e);
}
builder.addEncoding(encoding, MetadataBuilder.Scope.ALL);
builder.addResourceScope(ScopeCode.DATASET, null);
try {
builder.addExtent(envelope);
} catch (TransformException e) {
throw new DataStoreReferencingException(getLocale(), StoreProvider.NAME, getDisplayName(), source).initCause(e);
} catch (UnsupportedOperationException e) {
/*
* Failed to set the temporal components if the sis-temporal module was
* not on the classpath, but the other dimensions still have been set.
*/
listeners.warning(null, e);
}
builder.addFeatureType(featureType, null);
addTitleOrIdentifier(builder);
metadata = builder.build(true);
}
return metadata;
}
use of org.apache.sis.metadata.sql.MetadataStoreException in project sis by apache.
the class GeoTiffStore method getMetadata.
/**
* Returns information about the dataset as a whole. The returned metadata object can contain information
* such as the spatiotemporal extent of the dataset, contact information about the creator or distributor,
* data quality, usage constraints and more.
*
* @return information about the dataset.
* @throws DataStoreException if an error occurred while reading the data.
*/
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
if (metadata == null) {
final Reader reader = reader();
final MetadataBuilder builder = reader.metadata;
try {
builder.setFormat(Constants.GEOTIFF);
} catch (MetadataStoreException e) {
warning(null, e);
}
builder.addEncoding(encoding, MetadataBuilder.Scope.METADATA);
builder.addResourceScope(ScopeCode.valueOf("COVERAGE"), null);
final Locale locale = getLocale();
int n = 0;
try {
ImageFileDirectory dir;
while ((dir = reader.getImageFileDirectory(n++)) != null) {
dir.completeMetadata(builder, locale);
}
} catch (IOException e) {
throw new DataStoreException(errors().getString(Errors.Keys.CanNotRead_1, reader.input.filename), e);
} catch (FactoryException | ArithmeticException e) {
throw new DataStoreContentException(getLocale(), Constants.GEOTIFF, reader.input.filename, null).initCause(e);
}
/*
* Add the filename as an identifier only if the input was something convertible to URI (URL, File or Path),
* otherwise reader.input.filename may not be useful; it may be just the InputStream classname. If the TIFF
* file did not specified any ImageDescription tag, then we will had the filename as a title instead than an
* identifier because the title is mandatory in ISO 19115 metadata.
*/
if (location != null) {
builder.addTitleOrIdentifier(IOUtilities.filenameWithoutExtension(reader.input.filename), MetadataBuilder.Scope.ALL);
}
metadata = builder.build(true);
}
return metadata;
}
use of org.apache.sis.metadata.sql.MetadataStoreException in project sis by apache.
the class DocumentedStoreProvider method getFormat.
/**
* Returns a more complete description of the format, sending warnings to the given listeners if non-null.
*
* @param listeners where to report the warning in case of error, or {@code null} if none.
* @return a description of the data format.
*/
public final Format getFormat(final WarningListeners<DataStore> listeners) {
/*
* Note: this method does not cache the format because such caching is already done by MetadataSource.
*/
if (name != null)
try {
return MetadataSource.getProvided().lookup(Format.class, name);
} catch (MetadataStoreException e) {
if (listeners != null) {
listeners.warning(null, e);
} else {
final Level level;
if (!logged) {
// Not atomic - not a big deal if we use warning level twice.
logged = true;
level = Level.WARNING;
} else {
level = Level.FINE;
}
final LogRecord record = Resources.forLocale(null).getLogRecord(level, Resources.Keys.CanNotGetCommonMetadata_2, getShortName(), e.getLocalizedMessage());
record.setLoggerName(Modules.STORAGE);
Logging.log(getClass(), "getFormat", record);
}
}
return super.getFormat();
}
Aggregations