Search in sources :

Example 1 with Type

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;
}
Also used : AbstractI18NMetadata(org.n52.iceland.i18n.metadata.AbstractI18NMetadata) I18NFeatureMetadata(org.n52.iceland.i18n.metadata.I18NFeatureMetadata) I18NOfferingMetadata(org.n52.iceland.i18n.metadata.I18NOfferingMetadata) JSONException(org.n52.iceland.exception.JSONException) MultilingualString(org.n52.janmayen.i18n.MultilingualString) LocalizedString(org.n52.janmayen.i18n.LocalizedString) I18NObservablePropertyMetadata(org.n52.iceland.i18n.metadata.I18NObservablePropertyMetadata) I18NProcedureMetadata(org.n52.iceland.i18n.metadata.I18NProcedureMetadata)

Example 2 with Type

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);
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) DateTimeZone(org.joda.time.DateTimeZone) ConfigurationError(org.n52.faroe.ConfigurationError) KibanaImporter(org.n52.iceland.statistics.api.utils.KibanaImporter) NodeBuilder(org.elasticsearch.node.NodeBuilder) TransportClient(org.elasticsearch.client.transport.TransportClient) LoggerFactory(org.slf4j.LoggerFactory) MetadataDataMapping(org.n52.iceland.statistics.api.mappings.MetadataDataMapping) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Inject(javax.inject.Inject) Calendar(java.util.Calendar) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) EmbeddedElasticsearch(org.n52.iceland.statistics.impl.server.EmbeddedElasticsearch) Node(org.elasticsearch.node.Node) ElasticsearchSettings(org.n52.iceland.statistics.api.ElasticsearchSettings) ElasticsearchSettingsKeys(org.n52.iceland.statistics.api.ElasticsearchSettingsKeys) LinkedList(java.util.LinkedList) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Logger(org.slf4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UnknownHostException(java.net.UnknownHostException) StandardCharsets(java.nio.charset.StandardCharsets) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ServletContext(javax.servlet.ServletContext) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IAdminDataHandler(org.n52.iceland.statistics.api.interfaces.datahandler.IAdminDataHandler) DefaultElasticsearchSchemas(org.n52.iceland.statistics.impl.schemabuilders.DefaultElasticsearchSchemas) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) List(java.util.List) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 3 with Type

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());
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 4 with Type

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;
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) Time(org.n52.shetland.ogc.gml.time.Time) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTimeParseException(java.time.format.DateTimeParseException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField)

Example 5 with Type

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;
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)27 DecodingException (org.n52.svalbard.decode.exception.DecodingException)15 Actuate (org.n52.shetland.w3c.xlink.Actuate)14 Reference (org.n52.shetland.w3c.xlink.Reference)14 Show (org.n52.shetland.w3c.xlink.Show)14 Type (org.n52.shetland.w3c.xlink.Type)14 ActuateType (org.w3.x1999.xlink.ActuateType)14 ShowType (org.w3.x1999.xlink.ShowType)14 TypeType (org.w3.x1999.xlink.TypeType)14 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)13 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)10 CodeType (net.opengis.gml.x32.CodeType)10 EXExtentType (org.isotc211.x2005.gmd.EXExtentType)10 XmlException (org.apache.xmlbeans.XmlException)9 Test (org.junit.Test)9 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)9 CIResponsiblePartyPropertyType (org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType)8 CIResponsiblePartyType (org.isotc211.x2005.gmd.CIResponsiblePartyType)8 BaseUnitType (net.opengis.gml.x32.BaseUnitType)6 SupportedType (org.n52.shetland.ogc.SupportedType)6