Search in sources :

Example 46 with DtField

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;
}
Also used : DataType(io.vertigo.dynamo.domain.metamodel.DataType) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 47 with DtField

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;
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) ArrayList(java.util.ArrayList) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Transactional(io.vertigo.commons.transaction.Transactional)

Example 48 with DtField

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()));
}
Also used : HashMap(java.util.HashMap) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Authorization(io.vertigo.account.authorization.metamodel.Authorization) JsonElement(com.google.gson.JsonElement) SecurityDimension(io.vertigo.account.authorization.metamodel.SecurityDimension)

Example 49 with DtField

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);
}
Also used : Serializable(java.io.Serializable) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 50 with DtField

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);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtList(io.vertigo.dynamo.domain.model.DtList) Facet(io.vertigo.dynamo.collections.model.Facet)

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