Search in sources :

Example 31 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class VegaUiObject method mergeInput.

// ==========================================================================
private void mergeInput() {
    Assertion.checkNotNull(serverSideDto, "serverSideDto is mandatory");
    Assertion.checkNotNull(inputDto, "inputDto is mandatory");
    // -----
    for (final DtField dtField : getDtDefinition().getFields()) {
        if (isModified(const2CamelIndex.get(dtField.getName()))) {
            dtField.getDataAccessor().setValue(serverSideDto, dtField.getDataAccessor().getValue(inputDto));
        }
    }
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 32 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class AbstractDtObjectValidator method validate.

/**
 * {@inheritDoc}
 */
@Override
public void validate(final O dtObject, final Set<String> modifiedFieldNames, final DtObjectErrors dtObjectErrors) {
    for (final String fieldName : modifiedFieldNames) {
        final DtField dtField = getDtField(fieldName, dtObject);
        checkMonoFieldConstraints(dtObject, dtField, dtObjectErrors);
    }
    checkMultiFieldConstraints(dtObject, modifiedFieldNames, dtObjectErrors);
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 33 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class AbstractESSearchServicesPlugin method updateTypeMapping.

/**
 * Update template definition of this type.
 * @param indexDefinition Index concerné
 */
private void updateTypeMapping(final SearchIndexDefinition indexDefinition, final boolean sortableNormalizer) {
    Assertion.checkNotNull(indexDefinition);
    // -----
    try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
        typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
        /* 3 : Les champs du dto index */
        final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
        final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
            typeMapping.startObject(dtField.getName());
            appendIndexTypeMapping(typeMapping, indexType);
            if (copyFromFields.contains(dtField)) {
                appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
            }
            if (indexType.isIndexSubKeyword()) {
                typeMapping.startObject("fields");
                typeMapping.startObject("keyword");
                typeMapping.field("type", "keyword");
                if (sortableNormalizer) {
                    typeMapping.field("normalizer", "sortable");
                }
                typeMapping.endObject();
                typeMapping.endObject();
            }
            if (indexType.isIndexFieldData()) {
                typeMapping.field("fielddata", true);
            }
            typeMapping.endObject();
        }
        // end properties
        typeMapping.endObject().endObject();
        final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ROOT)).setSource(typeMapping).get();
        putMappingResponse.isAcknowledged();
    } catch (final IOException e) {
        throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
    }
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 34 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class ESDocumentCodec method cloneDto.

private static <I extends DtObject> I cloneDto(final DtDefinition dtDefinition, final I dto, final List<DtField> excludedFields) {
    final I clonedDto = (I) DtObjectUtil.createDtObject(dtDefinition);
    for (final DtField dtField : dtDefinition.getFields()) {
        if (!excludedFields.contains(dtField)) {
            final DataAccessor dataAccessor = dtField.getDataAccessor();
            dataAccessor.setValue(clonedDto, dataAccessor.getValue(dto));
        }
    }
    return clonedDto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 35 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class ESDocumentCodec method index2XContentBuilder.

/**
 * Transformation d'un index en un document ElasticSearch.
 * @param <S> Type du sujet représenté par ce document
 * @param <I> Type d'object indexé
 * @param index Objet logique de recherche
 * @return Document SOLR
 * @throws IOException Json exception
 */
<S extends KeyConcept, I extends DtObject> XContentBuilder index2XContentBuilder(final SearchIndex<S, I> index) throws IOException {
    Assertion.checkNotNull(index);
    // -----
    final DtDefinition dtDefinition = index.getDefinition().getIndexDtDefinition();
    // on ne copie pas les champs not stored dans le domain
    final List<DtField> notStoredFields = getNotStoredFields(dtDefinition);
    // on ne copie pas les champs (copyTo)
    notStoredFields.addAll(index.getDefinition().getIndexCopyToFields());
    final I dtResult;
    if (notStoredFields.isEmpty()) {
        dtResult = index.getIndexDtObject();
    } else {
        dtResult = cloneDto(dtDefinition, index.getIndexDtObject(), notStoredFields);
    }
    /* 2: Result stocké */
    final String result = encode(dtResult);
    /* 1 : URI */
    try (final XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
        xContentBuilder.startObject().field(FULL_RESULT, result).field("urn", index.getURI().urn());
        /* 3 : Les champs du dto index */
        final DtObject dtIndex = index.getIndexDtObject();
        final DtDefinition indexDtDefinition = DtObjectUtil.findDtDefinition(dtIndex);
        final Set<DtField> copyToFields = index.getDefinition().getIndexCopyToFields();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            if (!copyToFields.contains(dtField)) {
                // On index pas les copyFields
                final Object value = dtField.getDataAccessor().getValue(dtIndex);
                if (value != null) {
                    // les valeurs null ne sont pas indexées => conséquence : on ne peut pas les rechercher
                    final String indexFieldName = dtField.getName();
                    if (value instanceof String) {
                        final String encodedValue = escapeInvalidUTF8Char((String) value);
                        xContentBuilder.field(indexFieldName, encodedValue);
                    } else {
                        xContentBuilder.field(indexFieldName, value);
                    }
                }
            }
        }
        return xContentBuilder.endObject();
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObject(io.vertigo.dynamo.domain.model.DtObject) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DtField (io.vertigo.dynamo.domain.metamodel.DtField)77 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)28 DtObject (io.vertigo.dynamo.domain.model.DtObject)14 DtList (io.vertigo.dynamo.domain.model.DtList)13 URI (io.vertigo.dynamo.domain.model.URI)12 HashMap (java.util.HashMap)11 Map (java.util.Map)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Task (io.vertigo.dynamo.task.model.Task)7 ArrayList (java.util.ArrayList)7 Entity (io.vertigo.dynamo.domain.model.Entity)6 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)6 Serializable (java.io.Serializable)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 MessageText (io.vertigo.core.locale.MessageText)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)5 Date (java.util.Date)4 SearchHit (org.elasticsearch.search.SearchHit)4 JsonObject (com.google.gson.JsonObject)3