use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class AdvancedTestWebServices method createFilterFunction.
private <C extends DtObject, E extends Entity> Predicate<E> createFilterFunction(final C criteria, final Class<E> resultClass) {
Predicate<E> filter = (o) -> true;
final DtDefinition criteriaDefinition = DtObjectUtil.findDtDefinition(criteria);
final DtDefinition resultDefinition = DtObjectUtil.findDtDefinition(resultClass);
final Set<String> alreadyAddedField = new HashSet<>();
for (final DtField field : criteriaDefinition.getFields()) {
final String fieldName = field.getName();
if (!alreadyAddedField.contains(fieldName)) {
// when we consume two fields at once (min;max)
final Object value = field.getDataAccessor().getValue(criteria);
if (value != null) {
if (fieldName.endsWith("_MIN") || fieldName.endsWith("_MAX")) {
final String filteredField = fieldName.substring(0, fieldName.length() - "_MIN".length());
final DtField resultDtField = resultDefinition.getField(filteredField);
final DtField minField = fieldName.endsWith("_MIN") ? field : criteriaDefinition.getField(filteredField + "_MIN");
final DtField maxField = fieldName.endsWith("_MAX") ? field : criteriaDefinition.getField(filteredField + "_MAX");
final Serializable minValue = (Serializable) minField.getDataAccessor().getValue(criteria);
final Serializable maxValue = (Serializable) maxField.getDataAccessor().getValue(criteria);
filter = filter.and(Criterions.isBetween(() -> resultDtField.getName(), CriterionLimit.ofIncluded(minValue), CriterionLimit.ofExcluded(maxValue)).toPredicate());
} else {
final Predicate predicate = Criterions.isEqualTo(() -> fieldName, Serializable.class.cast(value)).toPredicate();
filter.and(predicate);
}
}
}
// si null, alors on ne filtre pas
}
return filter;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class DomainDynamicRegistry method createAssociationNNDefinition.
private static AssociationNNDefinition createAssociationNNDefinition(final DefinitionSpace definitionSpace, final DslDefinition xassociation) {
final String tableName = (String) xassociation.getPropertyValue(KspProperty.TABLE_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);
final AssociationNode associationNodeA = new AssociationNode(dtDefinitionA, navigabilityA, roleA, labelA, true, false);
final AssociationNode associationNodeB = new AssociationNode(dtDefinitionB, navigabilityB, roleB, labelB, true, false);
final String name = fixAssociationName(ASSOCIATION_NN_DEFINITION_PREFIX, xassociation.getName());
return new AssociationNNDefinition(name, tableName, associationNodeA, associationNodeB);
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createIndexDefinition.
private static SearchIndexDefinition createIndexDefinition(final DefinitionSpace definitionSpace, final DslDefinition xsearchObjet) {
final DtDefinition keyConceptDtDefinition = definitionSpace.resolve(xsearchObjet.getDefinitionLinkName("keyConcept"), DtDefinition.class);
final DtDefinition indexDtDefinition = definitionSpace.resolve(xsearchObjet.getDefinitionLinkName("dtIndex"), DtDefinition.class);
final String definitionName = xsearchObjet.getName();
// Déclaration des copyField
final Map<DtField, List<DtField>> copyFields = populateCopyFields(xsearchObjet, indexDtDefinition);
final String searchLoaderId = (String) xsearchObjet.getPropertyValue(SearchGrammar.SEARCH_LOADER_PROPERTY);
return new SearchIndexDefinition(definitionName, keyConceptDtDefinition, indexDtDefinition, copyFields, searchLoaderId);
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createFacetDefinition.
private static FacetDefinition createFacetDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
final String definitionName = xdefinition.getName();
final DtDefinition indexDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("dtDefinition"), DtDefinition.class);
final String dtFieldName = (String) xdefinition.getPropertyValue(SearchGrammar.FIELD_NAME);
final DtField dtField = indexDtDefinition.getField(dtFieldName);
final String label = (String) xdefinition.getPropertyValue(KspProperty.LABEL);
// Déclaration des ranges
final List<DslDefinition> rangeDefinitions = xdefinition.getChildDefinitions("range");
final MessageText labelMsg = MessageText.of(label);
final FacetDefinition facetDefinition;
if (rangeDefinitions.isEmpty()) {
facetDefinition = FacetDefinition.createFacetDefinitionByTerm(definitionName, dtField, labelMsg, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.count));
} else {
final List<FacetValue> facetValues = rangeDefinitions.stream().map(SearchDynamicRegistry::createFacetValue).collect(Collectors.toList());
facetDefinition = FacetDefinition.createFacetDefinitionByRange(definitionName, dtField, labelMsg, facetValues, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.definition));
}
return facetDefinition;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class BrokerBatchImpl method getList.
private DtList<E> getList(final DtDefinition dtDefinition, final String fieldName, final DtList<E> dtc) {
// On splitte la collection par paquet
final List<DtList<E>> paquet = new ArrayList<>();
DtList<E> tmp = null;
for (int i = 0; i < dtc.size(); i++) {
if (i % GET_LIST_PAQUET_SIZE == 0) {
tmp = new DtList<>(dtc.getDefinition());
paquet.add(tmp);
}
if (tmp != null) {
tmp.add(dtc.get(i));
}
}
// On génère la requête
// Corps de la requete
// On génère maintenant la requête proc batch
final DtDefinition dtDef = dtc.getDefinition();
final String dtcName = getDtcName(dtDef);
final String inDtcName = dtcName + "_IN";
final String request = new StringBuilder("select * from ").append(dtDef.getLocalName()).append(" where ").append(fieldName).append(" in (#").append(inDtcName).append(".ROWNUM.").append(fieldName).append("#)").toString();
// Exécution de la tache
final Domain dtcDomain = Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDef.getName() + "_DTC", Domain.class);
final String taskName = "TK_LOAD_BY_LST_" + fieldName + "_" + dtDef.getLocalName();
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dtDef.getDataSpace()).withRequest(request).addInRequired(inDtcName, dtcDomain).withOutRequired("out", dtcDomain).build();
// On exécute par paquet
final DtList<E> ret = new DtList<>(dtDefinition);
for (final DtList<E> paq : paquet) {
/* Création de la tache. */
final Task task = Task.builder(taskDefinition).addValue(inDtcName, paq).build();
// Exécution de la tache
final DtList<E> result = taskManager.execute(task).getResult();
ret.addAll(result);
}
return ret;
}
Aggregations