Search in sources :

Example 1 with DocumentOperationResult

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;
}
Also used : DatabaseRepository(org.eclipse.sw360.datahandler.couchdb.DatabaseRepository) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) ViewQuery(org.ektorp.ViewQuery) DocumentOperationResult(org.ektorp.DocumentOperationResult) Set(java.util.Set) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) Collectors(java.util.stream.Collectors) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Views(org.ektorp.support.Views) List(java.util.List) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) View(org.ektorp.support.View) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) DocumentOperationResult(org.ektorp.DocumentOperationResult)

Example 2 with DocumentOperationResult

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;
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) DocumentOperationResult(org.ektorp.DocumentOperationResult)

Aggregations

RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)2 DocumentOperationResult (org.ektorp.DocumentOperationResult)2 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 DatabaseRepository (org.eclipse.sw360.datahandler.couchdb.DatabaseRepository)1 PermissionUtils (org.eclipse.sw360.datahandler.permissions.PermissionUtils)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1 ViewQuery (org.ektorp.ViewQuery)1 View (org.ektorp.support.View)1 Views (org.ektorp.support.Views)1