use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class AbstractSearchLoader method getLowestIdValue.
private P getLowestIdValue(final DtDefinition dtDefinition) {
final DtField idField = dtDefinition.getIdField().get();
final DataType idDataType = idField.getDomain().getDataType();
P pkValue;
switch(idDataType) {
case Integer:
pkValue = (P) Integer.valueOf(-1);
break;
case Long:
pkValue = (P) Long.valueOf(-1);
break;
case String:
pkValue = (P) "";
break;
case BigDecimal:
case DataStream:
case Boolean:
case Double:
case Date:
default:
throw new IllegalArgumentException("Type's PK " + idDataType.name() + " of " + dtDefinition.getClassSimpleName() + " is not supported, prefer int, long or String ID.");
}
return pkValue;
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class AbstractSqlSearchLoader method loadNextURI.
/**
* {@inheritDoc}
*/
@Override
@Transactional
protected final List<URI<S>> loadNextURI(final P lastId, final DtDefinition dtDefinition) {
try (final VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
final String tableName = getTableName(dtDefinition);
final String taskName = "TK_SELECT_" + tableName + "_NEXT_SEARCH_CHUNK";
final DtField idField = dtDefinition.getIdField().get();
final String idFieldName = idField.getName();
final String request = getNextIdsSqlQuery(tableName, idFieldName);
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dtDefinition.getDataSpace()).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
final Task task = Task.builder(taskDefinition).addValue(idFieldName, lastId).build();
final DtList<S> resultDtc = taskManager.execute(task).getResult();
final List<URI<S>> uris = new ArrayList<>(resultDtc.size());
for (final S dto : resultDtc) {
uris.add(new URI<S>(dtDefinition, DtObjectUtil.getId(dto)));
}
return uris;
}
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class SecuredEntityDeserializer method deserialize.
/**
* {@inheritDoc}
*/
@Override
public SecuredEntity deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
final JsonObject jsonSecuredEntity = json.getAsJsonObject();
final DtDefinition entityDefinition = findDtDefinition(jsonSecuredEntity.get("entity").getAsString());
final List<DtField> securityFields = new ArrayList<>();
for (final JsonElement securityField : jsonSecuredEntity.get("securityFields").getAsJsonArray()) {
securityFields.add(deserializeDtField(entityDefinition, securityField.getAsString()));
}
final List<SecurityDimension> advancedDimensions = new ArrayList<>();
for (final JsonElement advancedDimension : jsonSecuredEntity.get("securityDimensions").getAsJsonArray()) {
// TODO if null ?
advancedDimensions.add(deserializeSecurityDimensions(entityDefinition, advancedDimension.getAsJsonObject(), context));
}
// on garde la map des operations pour resoudre les grants
final Map<String, Authorization> permissionPerOperations = new HashMap<>();
for (final JsonElement operation : jsonSecuredEntity.get("operations").getAsJsonArray()) {
// TODO if null ?
final Authorization permission = deserializeOperations(entityDefinition, operation.getAsJsonObject(), context, permissionPerOperations);
Assertion.checkArgument(!permissionPerOperations.containsKey(permission.getOperation().get()), "Operation {0} already declared on {1}", permission.getOperation().get(), entityDefinition.getName());
permissionPerOperations.put(permission.getOperation().get(), permission);
}
return new SecuredEntity(entityDefinition, securityFields, advancedDimensions, new ArrayList<>(permissionPerOperations.values()));
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class TextIdentityProviderPlugin method setTypedValue.
private static void setTypedValue(final DtDefinition userDtDefinition, final Entity user, final String propertyName, final String valueStr) throws FormatterException {
final DtField dtField = userDtDefinition.getField(propertyName);
final Serializable typedValue = (Serializable) dtField.getDomain().stringToValue(valueStr);
dtField.getDataAccessor().setValue(user, typedValue);
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method build.
/**
* {@inheritDoc}
*/
@Override
public FacetedQueryResult<I, SearchQuery> build() {
final Map<I, Map<DtField, String>> resultHighlights = new HashMap<>();
final Map<FacetValue, DtList<I>> resultCluster;
final DtList<I> dtc = new DtList<>(indexDefinition.getIndexDtDefinition());
if (searchQuery.isClusteringFacet()) {
final Map<String, I> dtcIndex = new LinkedHashMap<>();
resultCluster = createCluster(dtcIndex, resultHighlights);
dtc.addAll(dtcIndex.values());
} else {
for (final SearchHit searchHit : queryResponse.getHits()) {
final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
final I result = index.getIndexDtObject();
dtc.add(result);
final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
resultHighlights.put(result, highlights);
}
resultCluster = Collections.emptyMap();
}
// On fabrique à la volée le résultat.
final List<Facet> facets = createFacetList(searchQuery, queryResponse);
final long count = queryResponse.getHits().getTotalHits();
return new FacetedQueryResult<>(searchQuery.getFacetedQuery(), count, dtc, facets, searchQuery.isClusteringFacet() ? Optional.of(searchQuery.getClusteringFacetDefinition()) : Optional.empty(), resultCluster, resultHighlights, searchQuery);
}
Aggregations