/** * Get a list of entity and parents from a list of collections */ private List<EntityAndParent<Collection>> getEntityAndParents(List<Collection> collections) { List<EntityAndParent<Collection>> result = Lists.newArrayList(); for (Collection collection : collections) { List<Collection> chain = Lists.newArrayList(); chain.add(collection); Collection parent = collection; while (parent.getParentId() != null) { parent = this.findById(parent.getParentId()); chain.add(parent); } EntityAndParent<Collection> collectionChain = getCollectionChain(chain); result.add(collectionChain); } return result; }
/** * Compute the ltree path of a collection, which is the UUID chain (where dashes are replaced by underscores since * dashes are not allowed in ltree pathes) of parents leading to that collection (included). * * @param collection the collection for which to get the path * @return the computed path */ private String getPath(Collection collection) { Collection parent = collection; String path = collection.getId().toString().replace('-', '_'); while (parent.getParentId() != null) { parent = findById(parent.getParentId()); if (parent == null) { throw new RuntimeException("Broken collection path chain in database"); } path = parent.getId().toString().replace('-', '_') + '.' + path; } return path; }
public boolean apply(final CollectionPositionedEntity input) { return input.getEntity().getSlug().equals(slug) && input.getEntity().getParentId().equals(parentId); } }).first().orNull();
public Collection create(Collection collection) throws EntityAlreadyExistsException, InvalidEntityException { if (this.dao.findBySlug(collection.getSlug(), getTenant(), collection.getParentId()) != null) { throw new EntityAlreadyExistsException(); } getObservationManager().notify(new EntityCreatingEvent(), collection); this.dao.begin(); UUID entityId = UUID.randomUUID(); collection.setId(entityId); this.dao.createEntity(collection, COLLECTION_TABLE_NAME, getTenant()); Integer lastIndex = this.dao.lastPosition(getTenant()); this.dao.create(lastIndex == null ? 0 : ++lastIndex, collection); // this.dao.insertTranslations(entityId, collection.getTranslations()); this.dao.createOrUpdateAddons(collection); this.dao.commit(); getObservationManager().notify(new EntityCreatedEvent(), collection); return collection; }