Search in sources :

Example 6 with RequestSummary

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

the class AttachmentVacuum method cleanUpAttachments.

private RequestSummary cleanUpAttachments(ResourceRequest request) throws TException {
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    final AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
    final Set<String> usedAttachmentIds = componentClient.getUsedAttachmentContentIds();
    final User userFromRequest = UserCacheHolder.getUserFromRequest(request);
    return attachmentClient.vacuumAttachmentDB(userFromRequest, usedAttachmentIds);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) AttachmentService(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentService)

Example 7 with RequestSummary

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

the class ComponentUploadPortlet method updateComponentAttachments.

@UsedAsLiferayAction
public void updateComponentAttachments(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    List<CSVRecord> attachmentRecords = getCSVFromRequest(request, "file");
    FluentIterable<ComponentAttachmentCSVRecord> compCSVRecords = convertCSVRecordsToComponentAttachmentCSVRecords(attachmentRecords);
    log.trace("read records <" + Joiner.on("\n").join(compCSVRecords) + ">");
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    final AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
    User user = UserCacheHolder.getUserFromRequest(request);
    final RequestSummary requestSummary = writeAttachmentsToDatabase(compCSVRecords, user, componentClient, attachmentClient);
    renderRequestSummary(request, response, requestSummary);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) CSVRecord(org.apache.commons.csv.CSVRecord) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) AttachmentService(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentService) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 8 with RequestSummary

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

the class ScheduleHandler method scheduleService.

@Override
public RequestSummary scheduleService(String serviceName) throws TException {
    if (ScheduleConstants.invalidConfiguredServices.contains(serviceName)) {
        log.info("Could not schedule " + serviceName + " because of invalid configuration.");
        return new RequestSummary(RequestStatus.FAILURE);
    }
    Scheduler.cancelSyncJobOfService(serviceName);
    boolean successSync = false;
    switch(serviceName) {
        case ThriftClients.CVESEARCH_SERVICE:
            successSync = wrapSupplierException(() -> thriftClients.makeCvesearchClient().update(), serviceName);
            break;
        default:
            log.error("Could not schedule service: " + serviceName + ". Reason: service is not registered in ThriftClients.");
    }
    if (successSync) {
        RequestSummary summary = new RequestSummary(RequestStatus.SUCCESS);
        summary.setMessage(SW360Utils.getDateTimeString(Scheduler.getNextSync()));
        return summary;
    } else {
        return new RequestSummary(RequestStatus.FAILURE);
    }
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 9 with RequestSummary

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

the class CommonUtils method getRequestSummary.

@NotNull
public static RequestSummary getRequestSummary(List<String> ids, List<DocumentOperationResult> documentOperationResults) {
    final RequestSummary requestSummary = new RequestSummary();
    requestSummary.requestStatus = documentOperationResults.isEmpty() ? RequestStatus.SUCCESS : RequestStatus.FAILURE;
    requestSummary.setTotalElements(ids.size());
    requestSummary.setTotalAffectedElements(ids.size() - documentOperationResults.size());
    return requestSummary;
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with RequestSummary

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

the class ComponentImportUtils method writeToDatabase.

public static RequestSummary writeToDatabase(Iterable<ComponentCSVRecord> compCSVRecords, ComponentService.Iface componentClient, VendorService.Iface vendorClient, AttachmentService.Iface attachmentClient, User user) throws TException {
    Map<String, String> vendorNameToVendorId = getVendorNameToId(compCSVRecords, vendorClient);
    log.debug(format("Read vendors: (%d) %s ", vendorNameToVendorId.size(), vendorNameToVendorId));
    final RequestSummary componentRequestSummary = updateComponents(compCSVRecords, componentClient, user);
    Map<String, String> componentNameToId = new HashMap<>();
    final ArrayList<Release> releases = new ArrayList<>();
    for (Component component : componentClient.getComponentDetailedSummaryForExport()) {
        componentNameToId.put(component.getName(), component.getId());
        final List<Release> componentReleases = component.getReleases();
        if (componentReleases != null && componentReleases.size() > 0)
            releases.addAll(componentReleases);
    }
    Set<String> knownReleaseIdentifiers = Sets.newHashSet(getReleaseIdentifiers(releases));
    List<ComponentCSVRecord> relevantCSVRecords = new ArrayList<>();
    final HashMap<String, List<String>> releaseIdentifierToDownloadURL = new HashMap<>();
    List<AttachmentContent> attachmentContentsToUpdate = new ArrayList<>();
    filterRelevantCSVRecordsAndGetAttachmentContents(compCSVRecords, componentNameToId, knownReleaseIdentifiers, relevantCSVRecords, releaseIdentifierToDownloadURL, attachmentContentsToUpdate);
    attachmentContentsToUpdate = attachmentClient.makeAttachmentContents(attachmentContentsToUpdate);
    final ImmutableMap<String, AttachmentContent> URLtoAttachment = Maps.uniqueIndex(attachmentContentsToUpdate, new Function<AttachmentContent, String>() {

        @Override
        public String apply(AttachmentContent input) {
            return input.getRemoteUrl();
        }
    });
    Set<Release> releasesToUpdate = new HashSet<>();
    // I do not need so many checks here because I only iterate over the relevant CSV records
    for (ComponentCSVRecord componentCSVRecord : relevantCSVRecords) {
        String releaseIdentifier = componentCSVRecord.getReleaseIdentifier();
        String vendorName = componentCSVRecord.getVendorName();
        String vendorId = vendorNameToVendorId.get(vendorName);
        String componentId = componentNameToId.get(componentCSVRecord.getComponentName());
        List<AttachmentContent> attachmentContents = getAttachmentContents(releaseIdentifierToDownloadURL, URLtoAttachment, releaseIdentifier);
        Release releaseToAdd = componentCSVRecord.getRelease(vendorId, componentId, attachmentContents);
        knownReleaseIdentifiers.add(releaseIdentifier);
        if (releaseToAdd != null) {
            releasesToUpdate.add(releaseToAdd);
        }
    }
    final RequestSummary releaseRequestSummary = componentClient.updateReleases(releasesToUpdate, user);
    return CommonUtils.addRequestSummaries(componentRequestSummary, "component", releaseRequestSummary, "release");
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Component(org.eclipse.sw360.datahandler.thrift.components.Component) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

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