protected boolean resourceCheckInListIds(IPResource resource, List<Long> resourceIds) { return resourceIds.stream() // .map(it -> resourceService.resourceFind(it).get()) // .filter(it -> resourceService.resourceEqualsPk(resource, it)) // .findAny().isPresent(); }
protected boolean resourceCheckInList(IPResource resource, List<Tuple2<Long, IPResource>> resources) { return resources.stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it.getB())) // .findAny().isPresent(); }
public void resourceDelete(Long resourceId) { if (resourceId == null) { throw new IllegalUpdateException("Cannot delete a resource without id"); } resourcesToDelete.add(resourceId); // Remove in add and update Optional<IPResource> resourceOptional = resourceService.resourceFind(resourceId); if (resourceOptional.isPresent()) { IPResource resource = resourceOptional.get(); resourcesToAdd.removeIf(it -> resourceService.resourceEqualsPk(resource, it)); } resourcesToUpdate.removeIf(it -> it.getA() == resourceId); }
protected void linksClean(Tuple3<IPResource, String, IPResource> newTuple, List<Tuple3<IPResource, String, IPResource>> linksList) { linksList.removeIf(it -> // resourceService.resourceEqualsPk(newTuple.getA(), it.getA()) && // newTuple.getB().equals(it.getB()) && // resourceService.resourceEqualsPk(newTuple.getC(), it.getC()) // ); }
protected IPResource retrieveOrCreateResource(IPResourceService resourceService, ChangesContext changes, IPResource resource) { // Search in current changes Optional<IPResource> foundOptional = changes.getResourcesToAdd().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it)) // .findAny(); if (foundOptional.isPresent()) { return foundOptional.get(); } foundOptional = changes.getResourcesToUpdate().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it.getB())) // .map(it -> it.getB()) // .findAny(); if (foundOptional.isPresent()) { return foundOptional.get(); } // Search in repository foundOptional = resourceService.resourceFindByPk(resource); if (foundOptional.isPresent()) { return foundOptional.get(); } // Create new changes.resourceAdd(resource); return resource; }
@SuppressWarnings({ "unchecked" }) protected <T extends IPResource> T retrieveOrCreateResource(IPResourceService resourceService, ChangesContext changes, T resource, Class<T> resourceClass) { // Search in current changes Optional<T> foundOptional = changes.getResourcesToAdd().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it)) // .map(it -> (T) it) // .findAny(); if (foundOptional.isPresent()) { return foundOptional.get(); } foundOptional = changes.getResourcesToUpdate().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it.getB())) // .map(it -> (T) it.getB()) // .findAny(); if (foundOptional.isPresent()) { return foundOptional.get(); } // Search in repository foundOptional = resourceService.resourceFindByPk(resource); if (foundOptional.isPresent()) { return foundOptional.get(); } // Create new changes.resourceAdd(resource); return resource; }
protected void tagsClean(Tuple2<IPResource, String> newTuple, List<Tuple2<IPResource, String>> tagsList) { tagsList.removeIf(it -> // resourceService.resourceEqualsPk(newTuple.getA(), it.getA()) && // newTuple.getB().equals(it.getB()) // ); }
Optional<L> existingLink = currentToResources.stream().filter(it -> resourceService.resourceEqualsPk(toResource, it)).findAny(); if (existingLink.isPresent()) { currentToResources.remove(existingLink.get());
protected IPResource retrieveAndUpdateOrCreateResource(IPResourceService resourceService, ChangesContext changes, IPResource resource) { // Search in current changes Optional<IPResource> foundOptional = changes.getResourcesToAdd().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it)) // .findAny(); if (foundOptional.isPresent()) { updateResourceIfDifferent(resource, foundOptional.get()); return foundOptional.get(); } foundOptional = changes.getResourcesToUpdate().stream() // .filter(it -> resourceService.resourceEqualsPk(resource, it.getB())) // .map(it -> it.getB()) // .findAny(); if (foundOptional.isPresent()) { updateResourceIfDifferent(resource, foundOptional.get()); return foundOptional.get(); } // Search in repository foundOptional = resourceService.resourceFindByPk(resource); if (foundOptional.isPresent()) { IPResource foundResource = foundOptional.get(); if (updateResourceIfDifferent(resource, foundResource)) { changes.resourceUpdate(foundResource, foundResource); } return foundResource; } // Create new changes.resourceAdd(resource); return resource; }
Optional<L> existingLink = currentFromResources.stream().filter(it -> resourceService.resourceEqualsPk(fromResource, it)).findAny(); if (existingLink.isPresent()) { currentFromResources.remove(existingLink.get());
.filter(previous -> !desiredLinks.stream().anyMatch(desired -> resourceService.resourceEqualsPk(previous, desired))) // .forEach(previous -> { logger.debug("Removing link {}/{}/{}", desiredManagedResource, linkType, previous); .filter(desired -> !previousLinks.stream().anyMatch(previous -> resourceService.resourceEqualsPk(previous, desired))) // .forEach(desired -> { logger.debug("Adding link {}/{}/{}", desiredManagedResource, linkType, desired); .filter(previous -> !desiredLinks.stream().anyMatch(desired -> resourceService.resourceEqualsPk(previous, desired))) // .forEach(previous -> { logger.debug("Removing link {}/{}/{}", previous, linkType, desiredManagedResource); .filter(desired -> !previousLinks.stream().anyMatch(previous -> resourceService.resourceEqualsPk(previous, desired))) // .forEach(desired -> { logger.debug("Adding link {}/{}/{}", desired, linkType, desiredManagedResource);