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();
}
}
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;
}
}
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);
}
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;
}
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);
}
Aggregations