Search in sources :

Example 1 with DocumentGraph

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);
        }
    }
}
Also used : Entity(io.openk9.entity.manager.cache.model.Entity) EntityGraphService(io.openk9.entity.manager.service.graph.EntityGraphService) EntityKey(io.openk9.entity.manager.cache.model.EntityKey) DocumentKey(io.openk9.entity.manager.cache.model.DocumentKey) DocumentGraph(io.openk9.entity.manager.model.graph.DocumentGraph)

Aggregations

DocumentKey (io.openk9.entity.manager.cache.model.DocumentKey)1 Entity (io.openk9.entity.manager.cache.model.Entity)1 EntityKey (io.openk9.entity.manager.cache.model.EntityKey)1 DocumentGraph (io.openk9.entity.manager.model.graph.DocumentGraph)1 EntityGraphService (io.openk9.entity.manager.service.graph.EntityGraphService)1