Search in sources :

Example 1 with RequestSummary

use of org.eclipse.sw360.datahandler.thrift.RequestSummary 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 RequestSummary

use of org.eclipse.sw360.datahandler.thrift.RequestSummary in project sw360portal by sw360.

the class AttachmentHandlerTest method testVacuum_AllIdsUsedIsNoop.

@Test
public void testVacuum_AllIdsUsedIsNoop() throws Exception {
    final RequestSummary requestSummary = handler.vacuumAttachmentDB(new User("a", "a", "a").setUserGroup(UserGroup.ADMIN), ImmutableSet.of("A1", "A2"));
    assertThat(requestSummary.requestStatus, is(RequestStatus.SUCCESS));
    assertThat(requestSummary.totalElements, is(2));
    assertThat(requestSummary.totalAffectedElements, is(0));
    final AttachmentContent a1 = handler.getAttachmentContent("A1");
    assertNotNull(a1);
    final AttachmentContent a2 = handler.getAttachmentContent("A2");
    assertNotNull(a2);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 3 with RequestSummary

use of org.eclipse.sw360.datahandler.thrift.RequestSummary 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)

Example 4 with RequestSummary

use of org.eclipse.sw360.datahandler.thrift.RequestSummary in project sw360portal by sw360.

the class DatabaseSanitation method importLicensesFromSPDX.

private void importLicensesFromSPDX(ResourceRequest request, ResourceResponse response) throws TException {
    User user = UserCacheHolder.getUserFromRequest(request);
    LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
    RequestSummary requestSummary = licenseClient.importAllSpdxLicenses(user);
    renderRequestSummary(request, response, requestSummary);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 5 with RequestSummary

use of org.eclipse.sw360.datahandler.thrift.RequestSummary in project sw360portal by sw360.

the class ScheduleAdminPortlet method scheduleCveSearch.

@UsedAsLiferayAction
public void scheduleCveSearch(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(ThriftClients.CVESEARCH_SERVICE);
        setSessionMessage(request, requestSummary.getRequestStatus(), "Task", "schedule");
    } catch (TException e) {
        log.error(e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Aggregations

RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)17 User (org.eclipse.sw360.datahandler.thrift.users.User)11 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 Component (org.eclipse.sw360.datahandler.thrift.components.Component)4 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)4 CSVRecord (org.apache.commons.csv.CSVRecord)3 TException (org.apache.thrift.TException)3 AttachmentService (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentService)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)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 ReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ReleaseRelationship)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1