Search in sources :

Example 26 with DtDefinition

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

the class DAO method reloadAndMerge.

/**
 * Reloads entity from fragment, and keep fragment modifications.
 *
 * @param fragment  merged from datastore and input
 * @return merged root entity merged with the fragment
 */
public final E reloadAndMerge(final Fragment<E> fragment) {
    final DtDefinition fragmentDefinition = DtObjectUtil.findDtDefinition(fragment);
    final DtDefinition entityDefinition = fragmentDefinition.getFragment().get();
    final Map<String, DtField> entityFields = indexFields(entityDefinition.getFields());
    final DtField idField = entityDefinition.getIdField().get();
    // etrange on utilise l'accessor de l'entity sur le fragment
    final P entityId = (P) idField.getDataAccessor().getValue(fragment);
    final E dto = get(entityId);
    for (final DtField fragmentField : fragmentDefinition.getFields()) {
        // On vérifie la présence du champ dans l'Entity (il peut s'agir d'un champ non persistent d'UI
        if (entityFields.containsKey(fragmentField.getName())) {
            final DataAccessor fragmentDataAccessor = fragmentField.getDataAccessor();
            final DataAccessor entityDataAccessor = entityFields.get(fragmentField.getName()).getDataAccessor();
            entityDataAccessor.setValue(dto, fragmentDataAccessor.getValue(fragment));
        }
    }
    return dto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 27 with DtDefinition

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

the class DataStoreImpl method readOneForUpdate.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> E readOneForUpdate(final URI<E> uri) {
    Assertion.checkNotNull(uri);
    // -----
    final DtDefinition dtDefinition = uri.getDefinition();
    final E entity = getPhysicalStore(dtDefinition).readNullableForUpdate(dtDefinition, uri);
    // -----
    Assertion.checkNotNull(entity, "no entity found for : '{0}'", uri);
    // -----
    fireAfterCommit(StoreEvent.Type.UPDATE, uri);
    return entity;
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition)

Example 28 with DtDefinition

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

the class DtListURIForCriteria method createCriteria.

/**
 * Construit automatiquement un Criteria à partir d'un DtObject de critère.
 * Les noms des champs dans l'objet de critère doivent correspondre à ceux de l'objet métier.
 * @param dtoCriteria Objet de critère
 * @return Criteria resultant
 */
public static <E extends Entity> Criteria<E> createCriteria(final DtObject dtoCriteria) {
    Assertion.checkNotNull(dtoCriteria);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dtoCriteria);
    Criteria<E> criteria = Criterions.alwaysTrue();
    for (final DtField field : dtDefinition.getFields()) {
        final String fieldName = field.getName();
        if (field.getType() != DtField.FieldType.COMPUTED) {
            final Object value = field.getDataAccessor().getValue(dtoCriteria);
            if (value instanceof String && field.getType() != DtField.FieldType.FOREIGN_KEY) {
                // si String et pas une FK : on met en préfix
                criteria = criteria.and(Criterions.startsWith(() -> fieldName, (String) value));
            } else if (value != null) {
                criteria = criteria.and(Criterions.isEqualTo(() -> fieldName, (Serializable) value));
            }
        }
    // si null, alors on ne filtre pas
    }
    return criteria;
}
Also used : Serializable(java.io.Serializable) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 29 with DtDefinition

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

the class DtObjectUtil method createEntityURI.

/**
 * Creates an URI of entity from an existing fragment.
 * @param fragment fragment
 * @return related entity URI
 */
public static <E extends Entity, F extends Fragment<E>> URI<E> createEntityURI(final F fragment) {
    Assertion.checkNotNull(fragment);
    // -----
    final DtDefinition dtDefinition = findDtDefinition(fragment);
    final DtDefinition entityDtDefinition = dtDefinition.getFragment().get();
    final DtField idField = entityDtDefinition.getIdField().get();
    final Object idValue = idField.getDataAccessor().getValue(fragment);
    return new URI<>(entityDtDefinition, idValue);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObject(io.vertigo.dynamo.domain.model.DtObject) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 30 with DtDefinition

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

the class DtList method add.

// ==========================================================================
/**
 * {@inheritDoc}
 */
@Override
public boolean add(final D dto) {
    Assertion.checkNotNull(dto);
    final DtDefinition foundDtDefinition = DtObjectUtil.findDtDefinition(dto);
    Assertion.checkArgument(getDefinition().equals(foundDtDefinition), "Ne peut pas inserer un dto '{0}' dans une collection '{1}'", foundDtDefinition, getDefinition());
    // -----
    return dtObjects.add(dto);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5