use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class I18NJsonEncoder method decodeI18NMetadata.
public AbstractI18NMetadata decodeI18NMetadata(JsonNode s) throws JSONException {
String type = s.path(TYPE).asText();
String id = s.path(ID).asText();
final AbstractI18NMetadata i18n;
if (type.equals(TYPE_FEATURE)) {
i18n = new I18NFeatureMetadata(id);
} else if (type.equals(TYPE_OBSERVABLE_PROPERTY)) {
i18n = new I18NObservablePropertyMetadata(id);
} else if (type.equals(TYPE_OFFERING)) {
i18n = new I18NOfferingMetadata(id);
} else if (type.equals(TYPE_PROCEDURE)) {
I18NProcedureMetadata pi18n = new I18NProcedureMetadata(id);
decodeMultilingualString(s.path(LONG_NAME), pi18n.getLongName());
decodeMultilingualString(s.path(SHORT_NAME), pi18n.getShortName());
i18n = pi18n;
} else {
throw new JSONException("Unknown type: " + type);
}
decodeMultilingualString(s.path(NAME), i18n.getName());
decodeMultilingualString(s.path(DESCRIPTION), i18n.getDescription());
return i18n;
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class ElasticsearchAdminHandler method addUuidToMetadataIfNeeded.
@SuppressWarnings("unchecked")
private void addUuidToMetadataIfNeeded(String uuid) throws ElasticsearchException {
GetResponse resp = client.prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
Object retValues = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
List<String> values;
if (retValues instanceof String) {
values = new LinkedList<>();
values.add((String) retValues);
} else if (retValues instanceof List<?>) {
values = (List<String>) retValues;
} else {
throw new ConfigurationError("Invalid %s field type %s should have String or java.util.Collection<String>", MetadataDataMapping.METADATA_UUIDS_FIELD, retValues.getClass());
}
// add new uuid if needed
if (!values.stream().anyMatch(m -> m.equals(uuid))) {
Map<String, Object> uuids = new HashMap<>();
values.add(uuid);
uuids.put(MetadataDataMapping.METADATA_UUIDS_FIELD.getName(), values);
uuids.put(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName(), Calendar.getInstance(DateTimeZone.UTC.toTimeZone()));
client.prepareUpdate(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, "1").setDoc(uuids).get();
logger.info("UUID {} is added to the {} type", uuid, MetadataDataMapping.METADATA_TYPE_NAME);
}
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class ElasticsearchAdminHandler method createSchema.
@Override
public synchronized void createSchema() {
IndicesAdminClient indices = client.admin().indices();
if (indices.prepareExists(settings.getIndexId()).get().isExists()) {
logger.info("Index {} already exists", settings.getIndexId());
// update mapping
Integer version = getCurrentVersion();
logger.info("Elasticsearch schema version is {}", version);
if (version == null) {
throw new ConfigurationError("Database inconsistency. Metadata version not found in type %s", MetadataDataMapping.METADATA_TYPE_NAME);
}
if (version != schemas.getSchemaVersion()) {
throw new ConfigurationError("Database schema version inconsistency. Version numbers don't match. " + "Database version number %d <-> Application version number %d", version, schemas.getSchemaVersion());
}
addUuidToMetadataIfNeeded(settings.getUuid());
} else {
logger.info("Index {} not exists creating a new one now.", settings.getIndexId());
// create metadata table and index table table
CreateIndexResponse response = indices.prepareCreate(settings.getIndexId()).addMapping(MetadataDataMapping.METADATA_TYPE_NAME, schemas.getMetadataSchema()).addMapping(settings.getTypeId(), schemas.getSchema()).get();
logger.debug("Created indices: {}", response);
// insert metadata values
createMetadataType(schemas.getSchemaVersion());
}
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class SweDataArrayValue method getPhenomenonTime.
@Override
public Time getPhenomenonTime() {
final TimePeriod timePeriod = new TimePeriod();
Set<Integer> dateTokenIndizes = Sets.newHashSet();
if (getValue() != null && getValue().getElementType() != null && getValue().getEncoding() != null) {
// get index of time token from elementtype
if (getValue().getElementType() instanceof SweDataRecord) {
final SweDataRecord elementType = (SweDataRecord) getValue().getElementType();
final List<SweField> fields = elementType.getFields();
for (int i = 0; i < fields.size(); i++) {
final SweField sweField = fields.get(i);
if (sweField.getElement() instanceof SweTime || sweField.getElement() instanceof SweTimeRange) {
if (checkFieldNameAndElementDefinition(sweField)) {
dateTokenIndizes.add(i);
}
}
}
}
if (CollectionHelper.isNotEmpty(dateTokenIndizes)) {
for (final List<String> block : getValue().getValues()) {
// datetimehelper to DateTime from joda time
for (Integer index : dateTokenIndizes) {
String token = null;
try {
token = block.get(index);
final Time time = DateTimeHelper.parseIsoString2DateTime2Time(token);
timePeriod.extendToContain(time);
} catch (final DateTimeParseException dte) {
LOGGER.error(String.format("Could not parse ISO8601 string \"%s\"", token), dte);
// try next block;
continue;
}
}
}
} else {
final String errorMsg = "PhenomenonTime field could not be found in ElementType";
LOGGER.error(errorMsg);
}
} else {
final String errorMsg = String.format("Value of type \"%s\" not set correct.", SweDataArrayValue.class.getName());
LOGGER.error(errorMsg);
}
return timePeriod;
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class SosOffering method from.
/**
* Creates a set of {@literal SosOffering}s from SWE simple type.
*
* @param type
* the type (may be {@literal null})
*
* @return the set (never {@literal null})
*/
public static SosOffering from(SweAbstractSimpleType<?> type) {
if (type == null) {
return null;
}
String identifer = type.getValue().toString();
CodeType name = type.getName();
SosOffering offering = new SosOffering(identifer, name);
if (type.isSetDescription()) {
offering.setDescription(type.getDescription());
}
return offering;
}
Aggregations