Search in sources :

Example 1 with DataAccessor

use of io.vertigo.dynamo.domain.metamodel.DataAccessor 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 2 with DataAccessor

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

the class ESDocumentCodec method cloneDto.

private static <I extends DtObject> I cloneDto(final DtDefinition dtDefinition, final I dto, final List<DtField> excludedFields) {
    final I clonedDto = (I) DtObjectUtil.createDtObject(dtDefinition);
    for (final DtField dtField : dtDefinition.getFields()) {
        if (!excludedFields.contains(dtField)) {
            final DataAccessor dataAccessor = dtField.getDataAccessor();
            dataAccessor.setValue(clonedDto, dataAccessor.getValue(dto));
        }
    }
    return clonedDto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 3 with DataAccessor

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

the class ESDocumentCodec method cloneDto.

private static <I extends DtObject> I cloneDto(final DtDefinition dtDefinition, final I dto, final List<DtField> excludedFields) {
    final I clonedDto = (I) DtObjectUtil.createDtObject(dtDefinition);
    for (final DtField dtField : dtDefinition.getFields()) {
        if (!excludedFields.contains(dtField)) {
            final DataAccessor dataAccessor = dtField.getDataAccessor();
            dataAccessor.setValue(clonedDto, dataAccessor.getValue(dto));
        }
    }
    return clonedDto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 4 with DataAccessor

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

the class DAO method getFragment.

/**
 * Récupération d'un fragment persistant par son URI. L'objet doit exister.
 *
 * @param uri URI de l'objet à récupérer
 * @param fragmentClass Fragment class
 * @return F Fragment recherché
 */
public final <F extends Fragment<E>> F getFragment(final URI<E> uri, final Class<F> fragmentClass) {
    final E dto = dataStore.readOne(uri);
    final DtDefinition fragmentDefinition = DtObjectUtil.findDtDefinition(fragmentClass);
    final F fragment = fragmentClass.cast(DtObjectUtil.createDtObject(fragmentDefinition));
    for (final DtField dtField : fragmentDefinition.getFields()) {
        final DataAccessor dataAccessor = dtField.getDataAccessor();
        dataAccessor.setValue(fragment, dataAccessor.getValue(dto));
    // etrange on utilise l'accessor du fragment sur l'entity
    }
    return fragment;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 5 with DataAccessor

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

the class DtObjectComparator method compare.

/**
 * {@inheritDoc}
 */
@Override
public int compare(final D dto1, final D dto2) {
    Assertion.checkNotNull(dto1);
    Assertion.checkNotNull(dto2);
    // Les DTC ne contiennent pas d'éléments null.
    // -----
    final DataAccessor dataAccessor = sortField.getDataAccessor();
    return comparator.compare(dataAccessor.getValue(dto1), dataAccessor.getValue(dto2));
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor)

Aggregations

DataAccessor (io.vertigo.dynamo.domain.metamodel.DataAccessor)5 DtField (io.vertigo.dynamo.domain.metamodel.DtField)4 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)2 URI (io.vertigo.dynamo.domain.model.URI)2