use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class AbstractESSearchServicesPlugin method updateTypeMapping.
/**
* Update template definition of this type.
* @param indexDefinition Index concerné
*/
private void updateTypeMapping(final SearchIndexDefinition indexDefinition) {
Assertion.checkNotNull(indexDefinition);
// -----
try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
/* 3 : Les champs du dto index */
final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
for (final DtField dtField : indexDtDefinition.getFields()) {
final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
typeMapping.startObject(dtField.getName());
appendIndexTypeMapping(typeMapping, indexType);
if (copyFromFields.contains(dtField)) {
appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
}
typeMapping.endObject();
}
// end properties
typeMapping.endObject().endObject();
final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ENGLISH)).setSource(typeMapping).get();
putMappingResponse.isAcknowledged();
} catch (final IOException e) {
throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
}
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class TaskGeneratorPlugin method builDtDefinitiondMap.
private static Map<DtDefinition, List<TaskDefinition>> builDtDefinitiondMap() {
final Collection<TaskDefinition> taskDefinitions = Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class);
final Map<DtDefinition, List<TaskDefinition>> taskDefinitionsMap = new LinkedHashMap<>();
// ---
// Par défaut, On crée pour chaque DT une liste vide des taches lui étant associées.
final Collection<DtDefinition> dtDefinitions = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class);
for (final DtDefinition dtDefinition : dtDefinitions) {
taskDefinitionsMap.put(dtDefinition, new ArrayList<TaskDefinition>());
}
// ---
for (final TaskDefinition taskDefinition : taskDefinitions) {
final TaskDefinitionModel templateTaskDefinition = new TaskDefinitionModel(taskDefinition);
final DtDefinition dtDefinition = getDtDefinition(templateTaskDefinition);
final boolean dao = dtDefinition != null;
if (dao) {
// Dans le cas d'un DTO ou DTC en sortie on considère que la tache est liée au DAO.
taskDefinitionsMap.get(dtDefinition).add(taskDefinition);
}
}
return taskDefinitionsMap;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class JpaAnnotationWriter method getSequenceName.
/**
* Nom de la séquence utilisée lors des inserts
* @param dtDefinition Définition du DT mappé
* @return String Nom de la sequence
*/
private static String getSequenceName(final DtField field) {
final DtDefinition dtDefinition = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class).stream().filter(definition -> definition.getFields().contains(field)).findFirst().orElseThrow(NoSuchElementException::new);
// oracle n'autorise pas de sequence de plus de 30 char.
String seqName = SEQUENCE_PREFIX + getTableName(dtDefinition);
if (seqName.length() > 30) {
seqName = seqName.substring(0, 30);
}
return seqName;
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SqlGeneratorPlugin method generateSql.
private void generateSql(final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
final Map<String, List<SqlDtDefinitionModel>> mapListDtDef = new HashMap<>();
for (final DtDefinition dtDefinition : DomainUtil.sortDefinitionCollection(DomainUtil.getDtDefinitions())) {
if (dtDefinition.isPersistent()) {
final SqlDtDefinitionModel templateDef = new SqlDtDefinitionModel(dtDefinition);
final String dataSpace = dtDefinition.getDataSpace();
final List<SqlDtDefinitionModel> listDtDef = obtainListDtDefinitionPerDataSpace(mapListDtDef, dataSpace);
listDtDef.add(templateDef);
}
}
//
final Collection<AssociationSimpleDefinition> collectionSimpleAll = DomainUtil.getSimpleAssociations();
final Collection<AssociationNNDefinition> collectionNNAll = DomainUtil.getNNAssociations();
//
for (final Entry<String, List<SqlDtDefinitionModel>> entry : mapListDtDef.entrySet()) {
final String dataSpace = entry.getKey();
final Collection<AssociationSimpleDefinition> associationSimpleDefinitions = filterAssociationSimple(collectionSimpleAll, dataSpace);
final Collection<AssociationNNDefinition> associationNNDefinitions = filterAssociationNN(collectionNNAll, dataSpace);
generateSqlByDataSpace(fileGeneratorConfig, mdaResultBuilder, associationSimpleDefinitions, associationNNDefinitions, dataSpace, entry.getValue());
}
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class JpaDataStorePlugin method doFindAll.
private <E extends Entity> DtList<E> doFindAll(final ProcessAnalyticsTracer tracer, final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
final Class<E> resultClass = (Class<E>) ClassUtil.classForName(dtDefinition.getClassCanonicalName());
// PK de la DtList recherchée
final String idFieldName = dtDefinition.getIdField().get().getName();
// FK dans la table nn correspondant à la collection recherchée. (clé de jointure ).
final AssociationNNDefinition associationNNDefinition = dtcUri.getAssociationDefinition();
final String joinTableName = associationNNDefinition.getTableName();
final DtDefinition joinDtDefinition = AssociationUtil.getAssociationNode(associationNNDefinition, dtcUri.getRoleName()).getDtDefinition();
final DtField joinDtField = joinDtDefinition.getIdField().get();
// La condition s'applique sur l'autre noeud de la relation (par rapport à la collection attendue)
final AssociationNode associationNode = AssociationUtil.getAssociationNodeTarget(associationNNDefinition, dtcUri.getRoleName());
final DtField fkField = associationNode.getDtDefinition().getIdField().get();
final String fkFieldName = fkField.getName();
final String request = new StringBuilder(" select t.* from ").append(dtDefinition.getLocalName()).append(" t").append(" join ").append(joinTableName).append(" j on j.").append(joinDtField.getName()).append(" = t.").append(idFieldName).append(" where j.").append(fkFieldName).append(" = :").append(fkFieldName).toString();
final URI uri = dtcUri.getSource();
final Query q = getEntityManager().createNativeQuery(request, resultClass);
q.setParameter(fkFieldName, uri.getId());
final List<E> results = q.getResultList();
final DtList<E> dtc = new DtList<>(dtDefinition);
dtc.addAll(results);
tracer.setMeasure("nbSelectedRow", dtc.size());
return dtc;
}
Aggregations