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));
}
}
}
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);
}
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");
}
}
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;
}
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();
}
}
Aggregations