Search in sources :

Example 36 with DtField

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

the class ESFacetedQueryResultBuilder method createHighlight.

private static Map<DtField, String> createHighlight(final SearchHit searchHit, final DtDefinition resultDtDefinition) {
    final Map<DtField, String> highlights = new HashMap<>();
    final Map<String, HighlightField> highlightsMap = searchHit.getHighlightFields();
    for (final Map.Entry<String, HighlightField> entry : highlightsMap.entrySet()) {
        final String fieldName = entry.getKey();
        if (resultDtDefinition.contains(fieldName)) {
            // We only keep highlighs match on result's fields
            final DtField dtField = resultDtDefinition.getField(fieldName);
            final StringBuilder sb = new StringBuilder();
            for (final Text fragment : entry.getValue().getFragments()) {
                sb.append("<hlfrag>").append(fragment).append("</hlfrag>");
            }
            highlights.put(dtField, sb.toString());
        }
    }
    return highlights;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) Text(org.elasticsearch.common.text.Text) MessageText(io.vertigo.core.locale.MessageText) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 37 with DtField

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

the class ESFacetedQueryResultBuilder method populateCluster.

private void populateCluster(final Bucket bucket, final FacetValue facetValue, final Map<FacetValue, DtList<I>> resultCluster, final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
    final SearchHits facetSearchHits = ((TopHits) bucket.getAggregations().get(TOPHITS_SUBAGGREAGTION_NAME)).getHits();
    final DtList<I> facetDtc = new DtList<>(indexDefinition.getIndexDtDefinition());
    for (final SearchHit searchHit : facetSearchHits) {
        I result = dtcIndex.get(searchHit.getId());
        if (result == null) {
            final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
            result = index.getIndexDtObject();
            dtcIndex.put(searchHit.getId(), result);
            final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
            resultHighlights.put(result, highlights);
        }
        facetDtc.add(result);
    }
    resultCluster.put(facetValue, facetDtc);
}
Also used : TopHits(org.elasticsearch.search.aggregations.metrics.tophits.TopHits) SearchHit(org.elasticsearch.search.SearchHit) SearchHits(org.elasticsearch.search.SearchHits) DtList(io.vertigo.dynamo.domain.model.DtList) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 38 with DtField

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

the class JpaDataStorePlugin method findAll.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForSimpleAssociation dtcUri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(dtcUri);
    // -----
    final DtField fkField = dtcUri.getAssociationDefinition().getFKField();
    final Serializable value = dtcUri.getSource().getId();
    return findByCriteria(dtDefinition, Criterions.isEqualTo(fkField::getName, value), null);
}
Also used : Serializable(java.io.Serializable) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 39 with DtField

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

the class SqlDataStorePlugin method readNullable.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> E readNullable(final DtDefinition dtDefinition, final URI<E> uri) {
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_SELECT + "_" + dtDefinition.getLocalName() + "_BY_URI";
    final String requestedFields = getRequestedFields(dtDefinition);
    final DtField idField = getIdField(dtDefinition);
    final String idFieldName = idField.getName();
    final String request = new StringBuilder().append(" select ").append(requestedFields).append(" from ").append(tableName).append(" where ").append(idFieldName).append(" = #").append(idFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutOptional("dto", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + uri.getDefinition().getName() + "_DTO", Domain.class)).build();
    final Task task = Task.builder(taskDefinition).addValue(idFieldName, uri.getId()).build();
    return taskManager.execute(task).getResult();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 40 with DtField

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

the class SqlDataStorePlugin method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final DtDefinition dtDefinition, final URI uri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(uri);
    // ---
    final DtField idField = getIdField(dtDefinition);
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_DELETE + "_" + tableName;
    final String idFieldName = idField.getName();
    final String request = new StringBuilder().append("delete from ").append(tableName).append(" where ").append(idFieldName).append(" = #").append(idFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withDataSpace(dataSpace).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    final Task task = Task.builder(taskDefinition).addValue(idFieldName, uri.getId()).build();
    final int sqlRowCount = taskManager.execute(task).getResult();
    if (sqlRowCount > 1) {
        throw new VSystemException("more than one row has been deleted");
    } else if (sqlRowCount == 0) {
        throw new VSystemException("no row has been deleted");
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) VSystemException(io.vertigo.lang.VSystemException) 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