Search in sources :

Example 76 with DtDefinition

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;
}
Also used : Arrays(java.util.Arrays) ServerSideSave(io.vertigo.vega.webservice.stereotype.ServerSideSave) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) POST(io.vertigo.vega.webservice.stereotype.POST) Doc(io.vertigo.vega.webservice.stereotype.Doc) CriterionLimit(io.vertigo.dynamo.criteria.CriterionLimit) PathParam(io.vertigo.vega.webservice.stereotype.PathParam) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) Criterions(io.vertigo.dynamo.criteria.Criterions) Validate(io.vertigo.vega.webservice.stereotype.Validate) AccessTokenConsume(io.vertigo.vega.webservice.stereotype.AccessTokenConsume) MandatoryPkValidator(io.vertigo.vega.webservice.data.domain.MandatoryPkValidator) ContactValidator(io.vertigo.vega.webservice.data.domain.ContactValidator) Predicate(java.util.function.Predicate) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Collection(java.util.Collection) Set(java.util.Set) UiContext(io.vertigo.vega.engines.webservice.json.UiContext) Instant(java.time.Instant) QueryParam(io.vertigo.vega.webservice.stereotype.QueryParam) VFile(io.vertigo.dynamo.file.model.VFile) WebServices(io.vertigo.vega.webservice.WebServices) ExcludedFields(io.vertigo.vega.webservice.stereotype.ExcludedFields) Serializable(java.io.Serializable) GET(io.vertigo.vega.webservice.stereotype.GET) VUserException(io.vertigo.lang.VUserException) FileManager(io.vertigo.dynamo.file.FileManager) List(java.util.List) HeaderParam(io.vertigo.vega.webservice.stereotype.HeaderParam) DtObject(io.vertigo.dynamo.domain.model.DtObject) StringUtil(io.vertigo.util.StringUtil) Optional(java.util.Optional) ResourceManager(io.vertigo.core.resource.ResourceManager) DtField(io.vertigo.dynamo.domain.metamodel.DtField) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) AnonymousAccessAllowed(io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed) AccessTokenPublish(io.vertigo.vega.webservice.stereotype.AccessTokenPublish) ContactDao(io.vertigo.vega.webservice.data.domain.ContactDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InnerBodyParam(io.vertigo.vega.webservice.stereotype.InnerBodyParam) PathPrefix(io.vertigo.vega.webservice.stereotype.PathPrefix) DateUtil(io.vertigo.util.DateUtil) ServerSideRead(io.vertigo.vega.webservice.stereotype.ServerSideRead) PUT(io.vertigo.vega.webservice.stereotype.PUT) HttpServletResponse(javax.servlet.http.HttpServletResponse) AutoSortAndPagination(io.vertigo.vega.webservice.stereotype.AutoSortAndPagination) DtList(io.vertigo.dynamo.domain.model.DtList) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) ContactCriteria(io.vertigo.vega.webservice.data.domain.ContactCriteria) Entity(io.vertigo.dynamo.domain.model.Entity) EmptyPkValidator(io.vertigo.vega.webservice.data.domain.EmptyPkValidator) VCollectors(io.vertigo.dynamo.domain.util.VCollectors) Contact(io.vertigo.vega.webservice.data.domain.Contact) IncludedFields(io.vertigo.vega.webservice.stereotype.IncludedFields) AccessTokenMandatory(io.vertigo.vega.webservice.stereotype.AccessTokenMandatory) CollectionsManager(io.vertigo.dynamo.collections.CollectionsManager) Serializable(java.io.Serializable) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) HashSet(java.util.HashSet) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Predicate(java.util.function.Predicate)

Example 77 with DtDefinition

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);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 78 with DtDefinition

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);
}
Also used : SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 79 with DtDefinition

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;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 80 with DtDefinition

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;
}
Also used : Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) ArrayList(java.util.ArrayList) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DtList(io.vertigo.dynamo.domain.model.DtList)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5