use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class DomainDynamicRegistry method createFragmentDtDefinition.
private static DtDefinition createFragmentDtDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdtDefinition) {
final DtDefinition from = definitionSpace.resolve(xdtDefinition.getDefinitionLinkName("from"), DtDefinition.class);
final String sortFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.SORT_FIELD);
final String displayFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.DISPLAY_FIELD);
// 0. clones characteristics
final DtDefinitionBuilder dtDefinitionBuilder = DtDefinition.builder(xdtDefinition.getName()).withFragment(from).withPackageName(xdtDefinition.getPackageName()).withDataSpace(from.getDataSpace()).withPackageName(from.getPackageName()).withSortField(sortFieldName).withDisplayField(displayFieldName);
// 1. adds aliases
for (final DslDefinition alias : xdtDefinition.getChildDefinitions("alias")) {
final DtField aliasDtField = from.getField(alias.getName());
// --- REQUIRED
final Boolean overiddenRequired = (Boolean) alias.getPropertyValue(KspProperty.NOT_NULL);
final boolean required = overiddenRequired != null ? overiddenRequired : aliasDtField.isRequired();
// --- LABEL
final String overiddenLabel = (String) alias.getPropertyValue(KspProperty.LABEL);
final String label = overiddenLabel != null ? overiddenLabel : aliasDtField.getLabel().getDisplay();
dtDefinitionBuilder.addDataField(aliasDtField.getName(), label, aliasDtField.getDomain(), required, aliasDtField.isPersistent());
}
// 2. adds data and computed fields
// Déclaration des champs du DT
final List<DslDefinition> fields = xdtDefinition.getChildDefinitions(DomainGrammar.FIELD);
populateDataDtField(definitionSpace, dtDefinitionBuilder, fields);
// Déclaration des champs calculés
final List<DslDefinition> computedFields = xdtDefinition.getChildDefinitions(DomainGrammar.COMPUTED);
populateComputedDtField(definitionSpace, dtDefinitionBuilder, computedFields);
final DtDefinition dtDefinition = dtDefinitionBuilder.build();
// 0. adds ID field -->>> Should be first, but needs an already build DtDefinition
if (from.getIdField().isPresent()) {
final DtField idField = from.getIdField().get();
dtDefinitionBuilder.addForeignKey(idField.getName(), idField.getLabel().getDisplay(), idField.getDomain(), true, from.getName());
}
return dtDefinition;
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class SearchDynamicRegistry method populateCopyFields.
private static Map<DtField, List<DtField>> populateCopyFields(final DslDefinition xsearchObjet, final DtDefinition indexDtDefinition) {
// (map fromField : [toField, toField, ...])
final Map<DtField, List<DtField>> copyToFields = new HashMap<>();
final List<DslDefinition> copyToFieldNames = xsearchObjet.getChildDefinitions(SearchGrammar.INDEX_COPY_TO_PROPERTY);
for (final DslDefinition copyToFieldDefinition : copyToFieldNames) {
final DtField dtFieldTo = indexDtDefinition.getField(copyToFieldDefinition.getName());
final String copyFromFieldNames = (String) copyToFieldDefinition.getPropertyValue(SearchGrammar.INDEX_COPY_FROM_PROPERTY);
for (final String copyFromFieldName : copyFromFieldNames.split(",")) {
final DtField dtFieldFrom = indexDtDefinition.getField(copyFromFieldName.trim());
copyToFields.computeIfAbsent(dtFieldFrom, k -> new ArrayList<>()).add(dtFieldTo);
}
}
return copyToFields;
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class BrokerBatchImpl method getMap.
/**
* {@inheritDoc}
*/
@Override
public Map<P, E> getMap(final DtDefinition dtDefinition, final Collection<P> idList) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(idList);
// -----
final DtField idField = dtDefinition.getIdField().get();
final Map<P, E> map = new HashMap<>();
for (final E entity : getList(dtDefinition, idList)) {
map.put((P) idField.getDataAccessor().getValue(entity), entity);
}
return map;
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class BrokerBatchImpl method getMapByField.
/**
* {@inheritDoc}
*/
@Override
public <O> Map<O, DtList<E>> getMapByField(final DtDefinition dtDefinition, final String fieldName, final Collection<O> value) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(fieldName);
// -----
final DtField field = dtDefinition.getField(fieldName);
final Map<O, DtList<E>> map = new HashMap<>();
for (final E entity : getListByField(dtDefinition, fieldName, value)) {
final O key = (O) field.getDataAccessor().getValue(entity);
map.computeIfAbsent(key, k -> new DtList<>(dtDefinition)).add(entity);
}
return map;
}
use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.
the class BrokerBatchImpl method getList.
/**
* {@inheritDoc}
*/
@Override
public DtList<E> getList(final DtDefinition dtDefinition, final Collection<P> idList) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(idList);
// -----
final DtList<E> dtc = new DtList<>(dtDefinition);
// On regarde s'il y a quelquechose à faire
if (idList.isEmpty()) {
// Rien à faire
return dtc;
}
// On génère une DTC d'identifiant
final DtField idField = dtDefinition.getIdField().get();
for (final P id : idList) {
Assertion.checkNotNull(id);
final E entity = (E) DtObjectUtil.createDtObject(dtDefinition);
idField.getDataAccessor().setValue(entity, id);
dtc.add(entity);
}
return getList(dtDefinition, idField.getName(), dtc);
}
Aggregations