use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class DomainDynamicRegistry method createAssociationSimpleDefinition.
private AssociationSimpleDefinition createAssociationSimpleDefinition(final DefinitionSpace definitionSpace, final DslDefinition xassociation) {
final String multiplicityA = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_A);
final String multiplicityB = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_B);
// Vérification que l'on est bien dans le cas d'une association simple de type 1-n
if (AssociationUtil.isMultiple(multiplicityB) && AssociationUtil.isMultiple(multiplicityA)) {
// Relation n-n
throw new IllegalArgumentException("Utiliser la déclaration AssociationNN");
}
if (!AssociationUtil.isMultiple(multiplicityB) && !AssociationUtil.isMultiple(multiplicityA)) {
// Relation 1-1
throw new IllegalArgumentException("Les associations 1-1 sont interdites");
}
final String fkFieldName = (String) xassociation.getPropertyValue(KspProperty.FK_FIELD_NAME);
final DtDefinition dtDefinitionA = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionA"), DtDefinition.class);
final boolean navigabilityA = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_A);
final String roleA = (String) xassociation.getPropertyValue(KspProperty.ROLE_A);
final String labelA = (String) xassociation.getPropertyValue(KspProperty.LABEL_A);
final DtDefinition dtDefinitionB = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionB"), DtDefinition.class);
final boolean navigabilityB = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_B);
final String roleB = (String) xassociation.getPropertyValue(KspProperty.ROLE_B);
final String labelB = (String) xassociation.getPropertyValue(KspProperty.LABEL_B);
// Relation 1-n ou 1-1
final String urn = fixAssociationName(ASSOCIATION_SIMPLE_DEFINITION_PREFIX, xassociation.getName());
final AssociationNode associationNodeA = new AssociationNode(dtDefinitionA, navigabilityA, roleA, labelA, AssociationUtil.isMultiple(multiplicityA), AssociationUtil.isNotNull(multiplicityA));
final AssociationNode associationNodeB = new AssociationNode(dtDefinitionB, navigabilityB, roleB, labelB, AssociationUtil.isMultiple(multiplicityB), AssociationUtil.isNotNull(multiplicityB));
final AssociationSimpleDefinition associationSimpleDefinition = new AssociationSimpleDefinition(urn, fkFieldName, associationNodeA, associationNodeB);
final AssociationNode primaryAssociationNode = associationSimpleDefinition.getPrimaryAssociationNode();
final AssociationNode foreignAssociationNode = associationSimpleDefinition.getForeignAssociationNode();
final DtDefinition fkDefinition = primaryAssociationNode.getDtDefinition();
LOGGER.trace("" + xassociation.getName() + " : ajout d'une FK [" + fkFieldName + "] sur la table '" + foreignAssociationNode.getDtDefinition().getName() + "'");
final String label = primaryAssociationNode.getLabel();
dtDefinitionBuilders.get(foreignAssociationNode.getDtDefinition().getName()).addForeignKey(fkFieldName, label, fkDefinition.getIdField().get().getDomain(), primaryAssociationNode.isNotNull(), fkDefinition.getName());
return associationSimpleDefinition;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createFacetedQueryDefinition.
private static FacetedQueryDefinition createFacetedQueryDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
final String definitionName = xdefinition.getName();
final DtDefinition keyConceptDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("keyConcept"), DtDefinition.class);
final List<String> dynamicFacetDefinitionNames = xdefinition.getDefinitionLinkNames("facets");
final List<FacetDefinition> facetDefinitions = dynamicFacetDefinitionNames.stream().map(dynamicDefinitionName -> definitionSpace.resolve(dynamicDefinitionName, FacetDefinition.class)).collect(Collectors.toList());
final String listFilterBuilderQuery = (String) xdefinition.getPropertyValue(SearchGrammar.LIST_FILTER_BUILDER_QUERY);
final Class<? extends ListFilterBuilder> listFilterBuilderClass = getListFilterBuilderClass(xdefinition);
final String criteriaDomainName = xdefinition.getDefinitionLinkName("domainCriteria");
final Domain criteriaDomain = definitionSpace.resolve(criteriaDomainName, Domain.class);
return new FacetedQueryDefinition(definitionName, keyConceptDtDefinition, facetDefinitions, criteriaDomain, listFilterBuilderClass, listFilterBuilderQuery);
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition 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.DtDefinition in project vertigo by KleeGroup.
the class CacheDataStore method readNullable.
/**
* @param <E> the type of entity
* @param uri Element uri
* @return Element by uri
*/
public <E extends Entity> E readNullable(final URI<E> uri) {
Assertion.checkNotNull(uri);
// -----
final DtDefinition dtDefinition = uri.getDefinition();
E entity;
if (cacheDataStoreConfig.isCacheable(dtDefinition)) {
// - Prise en compte du cache
entity = cacheDataStoreConfig.getDataCache().getDtObject(uri);
// - Prise en compte du cache
if (entity == null) {
// Cas ou le dto représente un objet non mis en cache
entity = this.<E>loadNullable(dtDefinition, uri);
}
} else {
entity = getPhysicalStore(dtDefinition).readNullable(dtDefinition, uri);
}
return entity;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition 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;
}
Aggregations