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;
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations