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