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