use of org.ektorp.DocumentOperationResult in project sw360portal by sw360.
the class AttachmentRepository method vacuumAttachmentDB.
public RequestSummary vacuumAttachmentDB(User user, final Set<String> usedIds) {
final RequestSummary requestSummary = new RequestSummary();
if (!PermissionUtils.isAdmin(user))
return requestSummary.setRequestStatus(RequestStatus.FAILURE);
final List<AttachmentContent> allAttachmentContents = getAll();
final Set<AttachmentContent> unusedAttachmentContents = allAttachmentContents.stream().filter(input -> !usedIds.contains(input.getId())).collect(Collectors.toSet());
requestSummary.setTotalElements(allAttachmentContents.size());
requestSummary.setTotalAffectedElements(unusedAttachmentContents.size());
final List<DocumentOperationResult> documentOperationResults = deleteBulk(unusedAttachmentContents);
if (documentOperationResults.isEmpty()) {
requestSummary.setRequestStatus(RequestStatus.SUCCESS);
} else {
requestSummary.setRequestStatus(RequestStatus.FAILURE);
}
return requestSummary;
}
use of org.ektorp.DocumentOperationResult in project sw360portal by sw360.
the class RepositoryUtils method doBulk.
// This works with any repository
public static RequestSummary doBulk(Collection<?> objects, User user, DatabaseRepository<?> repository) {
RequestSummary requestSummary = new RequestSummary();
if (PermissionUtils.isAdmin(user)) {
// Prepare component for database
final List<DocumentOperationResult> documentOperationResults = repository.executeBulk(objects);
requestSummary.setTotalElements(objects.size());
requestSummary.setTotalAffectedElements(objects.size() - documentOperationResults.size());
requestSummary.setRequestStatus(RequestStatus.SUCCESS);
} else {
requestSummary.setRequestStatus(RequestStatus.FAILURE);
}
return requestSummary;
}
Aggregations