@Override public Set<BusinessService> getParentServices(Long id) { BusinessServiceEntity entity = getBusinessServiceEntity(id); return businessServiceDao.findParents(entity) .stream() .map(bs -> new BusinessServiceImpl(this, bs)) .collect(Collectors.toSet()); }
private BusinessServiceEntity getBusinessServiceEntity(Long serviceId) throws NoSuchElementException { Objects.requireNonNull(serviceId); final BusinessServiceEntity entity = getDao().get(serviceId); if (entity == null) { throw new NoSuchElementException("BusinessServiceEntity with id " + serviceId); } return entity; }
@Override public void deleteBusinessService(BusinessService businessService) { BusinessServiceEntity entity = getBusinessServiceEntity(businessService); // remove all parent -> child associations for(BusinessServiceEntity parent : getDao().findParents(entity)) { List<BusinessServiceChildEdgeEntity> collect = parent.getChildEdges().stream().filter(e -> entity.equals(e.getChild())).collect(Collectors.toList()); collect.forEach(x -> { parent.removeEdge(x); edgeDao.delete(x); // we need to delete this edge manually as they cannot be deleted automatically }); } // edges of the entity are deleted automatically by hibernate getDao().delete(entity); }
@Override public List<BusinessService> getAllBusinessServices() { return getDao().findAll().stream() .map(s -> new BusinessServiceImpl(this, s)) .collect(Collectors.toList()); }
@Override public List<BusinessService> findMatching(Criteria criteria) { criteria = transform(criteria); List<BusinessServiceEntity> all = getDao().findMatching(criteria); if (all == null) { return null; } return all.stream().map(e -> new BusinessServiceImpl(this, e)).collect(Collectors.toList()); }
@Override public int countMatching(Criteria criteria) { criteria = transform(criteria); return getDao().countMatching(criteria); }
@Override public void saveBusinessService(BusinessService service) { BusinessServiceEntity entity = getBusinessServiceEntity(service); getDao().saveOrUpdate(entity); }
@Override public Set<BusinessService> getFeasibleChildServices(final BusinessService service) { final BusinessServiceEntity entity = getBusinessServiceEntity(service); return getDao().findAll() .stream() .filter(s -> !this.checkDescendantForLoop(entity, s)) .map(s -> new BusinessServiceImpl(this, s)) .collect(Collectors.<BusinessService>toSet()); }