use of io.openk9.entity.manager.model.graph.DocumentGraph in project openk9 by smclab.
the class CreateDocumentEntitiesRunnable method run_.
@Override
public void run_() {
_log.info("start CreateEntitiesRunnable");
IMap<EntityKey, Entity> entityIMap = MapUtil.getEntityMap(_hazelcastInstance);
MultiMap<DocumentKey, String> documentEntityMapMap = MapUtil.getDocumentEntityMapMap(_hazelcastInstance);
EntityGraphService entityGraphService = CDI.current().select(EntityGraphService.class).get();
for (DocumentKey documentKey : documentEntityMapMap.localKeySet()) {
Collection<String> entityCacheIds = documentEntityMapMap.get(documentKey);
String[] arr = entityCacheIds.toArray(String[]::new);
Collection<Object> project = entityIMap.project(Projections.singleAttribute("indexable"), Predicates.and(Predicates.in("cacheId", arr), Predicates.notEqual("id", null), Predicates.notEqual("graphId", null)));
if (project.size() == entityCacheIds.size()) {
Collection<Entity> entities = entityIMap.values(Predicates.in("cacheId", arr));
DocumentGraph document = entityGraphService.insertDocument(DocumentGraph.of(null, documentKey.getDatasourceId(), documentKey.getTenantId(), documentKey.getContentId()));
for (Entity entity : entities) {
entityGraphService.createDocumentRelationship(entity.getId(), document.getId(), "related_to");
}
documentEntityMapMap.remove(documentKey);
}
}
}
Aggregations