Search in sources :

Example 56 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class ESDocumentCodec method index2XContentBuilder.

/**
 * Transformation d'un index en un document ElasticSearch.
 * @param <S> Type du sujet représenté par ce document
 * @param <I> Type d'object indexé
 * @param index Objet logique de recherche
 * @return Document SOLR
 * @throws IOException Json exception
 */
<S extends KeyConcept, I extends DtObject> XContentBuilder index2XContentBuilder(final SearchIndex<S, I> index) throws IOException {
    Assertion.checkNotNull(index);
    // -----
    final DtDefinition dtDefinition = index.getDefinition().getIndexDtDefinition();
    // on ne copie pas les champs not stored dans le domain
    final List<DtField> notStoredFields = getNotStoredFields(dtDefinition);
    // on ne copie pas les champs (copyTo)
    notStoredFields.addAll(index.getDefinition().getIndexCopyToFields());
    final I dtResult;
    if (notStoredFields.isEmpty()) {
        dtResult = index.getIndexDtObject();
    } else {
        dtResult = cloneDto(dtDefinition, index.getIndexDtObject(), notStoredFields);
    }
    /* 2: Result stocké */
    final String result = encode(dtResult);
    /* 1 : URI */
    try (final XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
        xContentBuilder.startObject().field(FULL_RESULT, result);
        /* 3 : Les champs du dto index */
        final DtObject dtIndex = index.getIndexDtObject();
        final DtDefinition indexDtDefinition = DtObjectUtil.findDtDefinition(dtIndex);
        final Set<DtField> copyToFields = index.getDefinition().getIndexCopyToFields();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            if (!copyToFields.contains(dtField)) {
                // On index pas les copyFields
                final Object value = dtField.getDataAccessor().getValue(dtIndex);
                if (value != null) {
                    // les valeurs null ne sont pas indexées => conséquence : on ne peut pas les rechercher
                    final String indexFieldName = dtField.getName();
                    if (value instanceof String) {
                        final String encodedValue = escapeInvalidUTF8Char((String) value);
                        xContentBuilder.field(indexFieldName, encodedValue);
                    } else {
                        xContentBuilder.field(indexFieldName, value);
                    }
                }
            }
        }
        return xContentBuilder.endObject();
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObject(io.vertigo.dynamo.domain.model.DtObject) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 57 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class CarSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Car, Car>> loadData(final SearchChunk<Car> searchChunk) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Car.class);
    try (final VTransactionWritable tx = getTransactionManager().createCurrentTransaction()) {
        final List<SearchIndex<Car, Car>> result = new ArrayList<>();
        final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Car.class);
        for (final Car car : loadCarList(searchChunk)) {
            final URI<Car> uri = new URI<>(dtDefinition, car.getId());
            result.add(SearchIndex.createIndex(indexDefinition, uri, car));
        }
        return result;
    }
}
Also used : Car(io.vertigo.dynamo.search_2_4.data.domain.Car) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) ArrayList(java.util.ArrayList) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) URI(io.vertigo.dynamo.domain.model.URI)

Example 58 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class TSGeneratorPlugin method generateTsMasterData.

private void generateTsMasterData(final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
    final MasterDataValues masterDataValues = masterDataManagerOpt.isPresent() ? masterDataManagerOpt.get().getValues() : new MasterDataValues();
    final List<TSMasterDataDefinitionModel> tsMasterDataDefinitionModels = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class).stream().filter(dtDefinition -> dtDefinition.getStereotype() == DtStereotype.StaticMasterData).map(dtDefinition -> new TSMasterDataDefinitionModel(dtDefinition, masterDataValues.getOrDefault(dtDefinition.getClassCanonicalName(), Collections.emptyMap()))).collect(Collectors.toList());
    final Map<String, Object> model = new MapBuilder<String, Object>().put("masterdatas", tsMasterDataDefinitionModels).build();
    FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName("masterdata.ts").withGenSubDir(targetSubDir).withPackageName("").withTemplateName("domain/ts/template/ts_masterdata.ftl").build().generateFile(mdaResultBuilder);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtStereotype(io.vertigo.dynamo.domain.metamodel.DtStereotype) MapBuilder(io.vertigo.util.MapBuilder) TSDtDefinitionModel(io.vertigo.studio.plugins.mda.domain.ts.model.TSDtDefinitionModel) HashMap(java.util.HashMap) FileGeneratorConfig(io.vertigo.studio.plugins.mda.FileGeneratorConfig) MasterDataValues(io.vertigo.studio.masterdata.MasterDataValues) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) TSMasterDataDefinitionModel(io.vertigo.studio.plugins.mda.domain.ts.model.TSMasterDataDefinitionModel) List(java.util.List) GeneratorPlugin(io.vertigo.studio.impl.mda.GeneratorPlugin) FileGenerator(io.vertigo.studio.plugins.mda.FileGenerator) MdaResultBuilder(io.vertigo.studio.mda.MdaResultBuilder) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Entry(java.util.Map.Entry) DomainUtil(io.vertigo.studio.plugins.mda.util.DomainUtil) Optional(java.util.Optional) Named(javax.inject.Named) MasterDataManager(io.vertigo.studio.masterdata.MasterDataManager) Collections(java.util.Collections) MapBuilder(io.vertigo.util.MapBuilder) MasterDataValues(io.vertigo.studio.masterdata.MasterDataValues) TSMasterDataDefinitionModel(io.vertigo.studio.plugins.mda.domain.ts.model.TSMasterDataDefinitionModel)

Example 59 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class TaskGeneratorPlugin method buildPackageMap.

private static Map<String, List<TaskDefinition>> buildPackageMap() {
    final Collection<TaskDefinition> taskDefinitions = Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class);
    final Map<String, List<TaskDefinition>> taskDefinitionsMap = new LinkedHashMap<>();
    // ---
    for (final TaskDefinition taskDefinition : taskDefinitions) {
        final TaskDefinitionModel templateTaskDefinition = new TaskDefinitionModel(taskDefinition);
        final DtDefinition dtDefinition = getDtDefinition(templateTaskDefinition);
        // Correction bug : task avec retour DtObject (non persistant) non générée
        // Les taches sont générées dans les pao
        // - si il n'esxiste pas de définition associées à la tache
        // - ou si la définition est considérée comme non persistante.
        final boolean pao = dtDefinition == null || !dtDefinition.isPersistent();
        if (pao) {
            // La tache est liée au package. (PAO)
            final List<TaskDefinition> list = taskDefinitionsMap.computeIfAbsent(taskDefinition.getPackageName(), k -> new ArrayList<>());
            // on ajoute la tache aux taches du package.
            list.add(taskDefinition);
        }
    }
    return taskDefinitionsMap;
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) TaskDefinitionModel(io.vertigo.studio.plugins.mda.task.model.TaskDefinitionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 60 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class SqlGeneratorPlugin method generateMasterDataInserts.

private void generateMasterDataInserts(final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
    final MasterDataValues masterDataValues = masterDataManagerOpt.isPresent() ? masterDataManagerOpt.get().getValues() : new MasterDataValues();
    final List<SqlMasterDataDefinitionModel> sqlMasterDataDefinitionModels = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class).stream().filter(dtDefinition -> dtDefinition.getStereotype() == DtStereotype.StaticMasterData).map(dtDefinition -> new SqlMasterDataDefinitionModel(dtDefinition, masterDataValues.getOrDefault(dtDefinition.getClassCanonicalName(), Collections.emptyMap()))).collect(Collectors.toList());
    final Map<String, Object> model = new MapBuilder<String, Object>().put("masterdatas", sqlMasterDataDefinitionModels).build();
    FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName("init_masterdata.sql").withGenSubDir(targetSubDir).withPackageName("").withTemplateName("domain/sql/template/init_masterdata.ftl").build().generateFile(mdaResultBuilder);
}
Also used : DtStereotype(io.vertigo.dynamo.domain.metamodel.DtStereotype) MapBuilder(io.vertigo.util.MapBuilder) HashMap(java.util.HashMap) MasterDataValues(io.vertigo.studio.masterdata.MasterDataValues) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) GeneratorPlugin(io.vertigo.studio.impl.mda.GeneratorPlugin) FileGenerator(io.vertigo.studio.plugins.mda.FileGenerator) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) DomainUtil(io.vertigo.studio.plugins.mda.util.DomainUtil) Named(javax.inject.Named) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Collection(java.util.Collection) FileGeneratorConfig(io.vertigo.studio.plugins.mda.FileGeneratorConfig) Collectors(java.util.stream.Collectors) SqlDtDefinitionModel(io.vertigo.studio.plugins.mda.domain.sql.model.SqlDtDefinitionModel) SqlMasterDataDefinitionModel(io.vertigo.studio.plugins.mda.domain.sql.model.SqlMasterDataDefinitionModel) List(java.util.List) StringUtil(io.vertigo.util.StringUtil) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) MdaResultBuilder(io.vertigo.studio.mda.MdaResultBuilder) Entry(java.util.Map.Entry) Optional(java.util.Optional) SqlMethodModel(io.vertigo.studio.plugins.mda.domain.sql.model.SqlMethodModel) MasterDataManager(io.vertigo.studio.masterdata.MasterDataManager) Collections(java.util.Collections) MapBuilder(io.vertigo.util.MapBuilder) MasterDataValues(io.vertigo.studio.masterdata.MasterDataValues) SqlMasterDataDefinitionModel(io.vertigo.studio.plugins.mda.domain.sql.model.SqlMasterDataDefinitionModel)

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