use of io.vertigo.dynamo.domain.metamodel.DtField 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.DtField in project vertigo by KleeGroup.
the class FacetFactory method createTermCluster.
private static <D extends DtObject> Map<FacetValue, DtList<D>> createTermCluster(final FacetDefinition facetDefinition, final DtList<D> dtList) {
// map résultat avec les docs par FacetFilter
final Map<FacetValue, DtList<D>> clusterValues = new LinkedHashMap<>();
// Cas des facettes par Term
final DtField dtField = facetDefinition.getDtField();
// on garde un index pour incrémenter le facetFilter pour chaque Term
final Map<Object, FacetValue> facetFilterIndex = new HashMap<>();
FacetValue facetValue;
for (final D dto : dtList) {
final Object value = dtField.getDataAccessor().getValue(dto);
facetValue = facetFilterIndex.get(value);
if (facetValue == null) {
final String valueAsString = dtField.getDomain().valueToString(value);
final String label;
if (StringUtil.isEmpty(valueAsString)) {
label = "<==no label==>";
} else {
label = valueAsString;
}
final MessageText labelMsg = MessageText.of(label);
// on garde la syntaxe Solr pour l'instant
final ListFilter listFilter = ListFilter.of(dtField.getName() + ":\"" + valueAsString + "\"");
facetValue = new FacetValue(label, listFilter, labelMsg);
facetFilterIndex.put(value, facetValue);
clusterValues.put(facetValue, new DtList<D>(dtList.getDefinition()));
}
clusterValues.get(facetValue).add(dto);
}
// tri des facettes
final Comparator<FacetValue> facetComparator = new FacetComparator<>(clusterValues);
final Map<FacetValue, DtList<D>> sortedFacetValues = new TreeMap<>(facetComparator);
sortedFacetValues.putAll(clusterValues);
return sortedFacetValues;
}
use of io.vertigo.dynamo.domain.metamodel.DtField 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.DtField 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.DtField in project vertigo by KleeGroup.
the class UiErrorBuilder method checkFieldNotNull.
/**
* Vérifie que le champ est renseigner.
* @param dto Object a tester
* @param fieldName Champs
* @param messageText Message à appliquer si erreur
*/
public void checkFieldNotNull(final DtObject dto, final String fieldName, final MessageText messageText) {
final DtField dtField = getDtField(dto, fieldName);
final Object value = getValue(dto, dtField);
if (value == null || value.toString().isEmpty()) {
addError(dto, dtField, messageText);
}
}
Aggregations