use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class DomainDynamicRegistry method populateComputedDtField.
/**
* Ajoute une liste de champs d'un certain type à la dtDefinition
*
* @param fields List
*/
private static void populateComputedDtField(final DefinitionSpace definitionSpace, final DtDefinitionBuilder dtDefinitionBuilder, final List<DslDefinition> fields) {
for (final DslDefinition field : fields) {
final Domain domain = definitionSpace.resolve(field.getDefinitionLinkName("domain"), Domain.class);
// --
Assertion.checkArgument(field.getPropertyNames().contains(KspProperty.LABEL), "Label est une propriété obligatoire");
final String label = (String) field.getPropertyValue(KspProperty.LABEL);
// ---
final String expression = (String) field.getPropertyValue(KspProperty.EXPRESSION);
final ComputedExpression computedExpression = new ComputedExpression(expression);
// --
final String fieldName = field.getName();
dtDefinitionBuilder.addComputedField(fieldName, label, domain, computedExpression);
}
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition 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.plugins.environment.dsl.dynamic.DslDefinition 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.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class AbstractXmlLoader method buildFkFieldName.
private static String buildFkFieldName(final XmlAssociation association, final DslDefinitionRepository dynamicModelrepository) {
// Dans le cas d'une association simple, on recherche le nom de la FK
// recherche de code de contrainte destiné à renommer la fk selon convention du vbsript PowerAMC
// Cas de la relation 1-n : où le nom de la FK est redéfini.
// Exemple : DOS_UTI_LIQUIDATION (relation entre dossier et utilisateur : FK >> UTILISATEUR_ID_LIQUIDATION)
final DslDefinition dtDefinitionA = dynamicModelrepository.getDefinition(getDtDefinitionName(association.getCodeA()));
final DslDefinition dtDefinitionB = dynamicModelrepository.getDefinition(getDtDefinitionName(association.getCodeB()));
final DslDefinition foreignDefinition = AssociationUtil.isAPrimaryNode(association.getMultiplicityA(), association.getMultiplicityB()) ? dtDefinitionA : dtDefinitionB;
final List<DslDefinition> primaryKeys = foreignDefinition.getChildDefinitions(DomainGrammar.ID);
if (primaryKeys.isEmpty()) {
throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' aucune clé primaire sur la définition '" + foreignDefinition.getName() + "'");
}
if (primaryKeys.size() > 1) {
throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' clé multiple non géré sur '" + foreignDefinition.getName() + "'");
}
if (dtDefinitionA.getName().equals(dtDefinitionB.getName()) && association.getCodeName() == null) {
throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' le nom de la clé est obligatoire (AutoJointure) '" + foreignDefinition.getName() + "'. Ce nom est déduit du code l'association, le code doit être composé ainsi : {Trigramme Table1}_{Trigramme Table2}_{Code association}." + " Par exemple : DOS_UTI_EMMETEUR, DOS_UTI_DESTINATAIRE, DOS_DOS_PARENT, ...");
}
// On récupère le nom de LA clé primaire .
final String pkFieldName = primaryKeys.get(0).getName();
// Par défaut le nom de la clé étrangère est constituée de la clé primaire référencée.
String fkFieldName = pkFieldName;
// Si l'association possède une nom défini par l'utilisateur, alors on l'ajoute à la FK avec un séparateur.
if (association.getCodeName() != null) {
// On construit le nom de la clé étrangère.
fkFieldName = fkFieldName + '_' + association.getCodeName();
}
// On raccourci le nom de la clé étrangère.
if (fkFieldName.length() > MAX_COLUMN_LENGTH) {
// 30 est le max de dynamo (et de Oracle)
fkFieldName = fkFieldName.substring(0, MAX_COLUMN_LENGTH);
while (fkFieldName.endsWith("_")) {
fkFieldName = fkFieldName.substring(0, fkFieldName.length() - 1);
}
}
LOGGER.trace(KspProperty.FK_FIELD_NAME + "=" + fkFieldName);
// -----
Assertion.checkNotNull(fkFieldName, "La clé primaire n''a pas pu être définie pour l'association '{0}'", association.getCode());
return fkFieldName;
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class TaskDynamicRegistry method createTaskDefinition.
private static TaskDefinition createTaskDefinition(final DslDefinition xtaskDefinition) {
final String taskDefinitionName = xtaskDefinition.getName();
final String request = (String) xtaskDefinition.getPropertyValue(KspProperty.REQUEST);
Assertion.checkNotNull(taskDefinitionName);
final Class<? extends TaskEngine> taskEngineClass = getTaskEngineClass(xtaskDefinition);
final String dataSpace = (String) xtaskDefinition.getPropertyValue(KspProperty.DATA_SPACE);
final TaskDefinitionBuilder taskDefinitionBuilder = TaskDefinition.builder(taskDefinitionName).withEngine(taskEngineClass).withDataSpace(dataSpace).withRequest(request).withPackageName(xtaskDefinition.getPackageName());
for (final DslDefinition xtaskAttribute : xtaskDefinition.getChildDefinitions(TaskGrammar.TASK_ATTRIBUTE)) {
final String attributeName = xtaskAttribute.getName();
Assertion.checkNotNull(attributeName);
final String domainName = xtaskAttribute.getDefinitionLinkName("domain");
final Domain domain = Home.getApp().getDefinitionSpace().resolve(domainName, Domain.class);
// -----
final boolean required = (Boolean) xtaskAttribute.getPropertyValue(KspProperty.NOT_NULL);
if (isInValue((String) xtaskAttribute.getPropertyValue(KspProperty.IN_OUT))) {
if (required) {
taskDefinitionBuilder.addInRequired(attributeName, domain);
} else {
taskDefinitionBuilder.addInOptional(attributeName, domain);
}
} else {
if (required) {
taskDefinitionBuilder.withOutRequired(attributeName, domain);
} else {
taskDefinitionBuilder.withOutOptional(attributeName, domain);
}
}
}
return taskDefinitionBuilder.build();
}
Aggregations