Search in sources :

Example 16 with RequestSummary

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

the class ComponentUploadPortlet method updateReleaseLinks.

@UsedAsLiferayAction
public void updateReleaseLinks(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    List<CSVRecord> releaseLinkRecords = getCSVFromRequest(request, "file");
    FluentIterable<ReleaseLinkCSVRecord> csvRecords = convertCSVRecordsToReleaseLinkCSVRecords(releaseLinkRecords);
    log.trace("read records <" + Joiner.on("\n").join(csvRecords) + ">");
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    User user = UserCacheHolder.getUserFromRequest(request);
    final RequestSummary requestSummary = writeReleaseLinksToDatabase(csvRecords, componentClient, user);
    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) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 17 with RequestSummary

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

the class ComponentUploadPortlet method updateComponents.

@UsedAsLiferayAction
public void updateComponents(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    List<CSVRecord> releaseRecords = getCSVFromRequest(request, "file");
    FluentIterable<ComponentCSVRecord> compCSVRecords = convertCSVRecordsToCompCSVRecords(releaseRecords);
    log.trace("read records <" + Joiner.on("\n").join(compCSVRecords) + ">");
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    final VendorService.Iface vendorClient = thriftClients.makeVendorClient();
    final AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
    User user = UserCacheHolder.getUserFromRequest(request);
    final RequestSummary requestSummary = writeToDatabase(compCSVRecords, componentClient, vendorClient, attachmentClient, user);
    renderRequestSummary(request, response, requestSummary);
}
Also used : VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) 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 18 with RequestSummary

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

the class ComponentImportUtils method writeAttachmentsToDatabase.

public static RequestSummary writeAttachmentsToDatabase(FluentIterable<ComponentAttachmentCSVRecord> compCSVRecords, User user, ComponentService.Iface componentClient, AttachmentService.Iface attachmentClient) throws TException {
    final List<Component> componentDetailedSummaryForExport = componentClient.getComponentDetailedSummaryForExport();
    final ImmutableMap<String, Component> componentsByName = getComponentsByName(componentDetailedSummaryForExport);
    final Map<String, Release> releasesByIdentifier = getReleasesByIdentifier(componentDetailedSummaryForExport);
    final Set<String> usedAttachmentContentIds = componentClient.getUsedAttachmentContentIds();
    final Set<String> releaseIdentifiersToUpdate = new HashSet<>();
    final Set<String> componentsToUpdate = new HashSet<>();
    final Set<Attachment> attachmentStubsToDelete = new HashSet<>();
    for (ComponentAttachmentCSVRecord compCSVRecord : compCSVRecords) {
        if (compCSVRecord.isSaveableAttachment()) {
            final Attachment attachment = compCSVRecord.getAttachment();
            if (usedAttachmentContentIds.contains(attachment.getAttachmentContentId()))
                continue;
            if (compCSVRecord.isForComponent()) {
                final Component component = componentsByName.get(compCSVRecord.getComponentName());
                if (component != null) {
                    component.addToAttachments(attachment);
                    componentsToUpdate.add(component.getName());
                }
            } else if (compCSVRecord.isForRelease()) {
                final Release release = releasesByIdentifier.get(compCSVRecord.getReleaseIdentifier());
                if (release != null) {
                    attachmentStubsToDelete.addAll(removeAutogeneratedAttachments(attachmentClient, attachment, release));
                    release.addToAttachments(attachment);
                    releaseIdentifiersToUpdate.add(compCSVRecord.getReleaseIdentifier());
                }
            }
        }
    }
    final HashSet<Release> updatedReleases = getUpdatedReleases(releasesByIdentifier, releaseIdentifiersToUpdate);
    final RequestSummary releaseRequestSummary = componentClient.updateReleases(updatedReleases, user);
    final HashSet<Component> updatedComponents = Sets.newHashSet(Maps.filterKeys(componentsByName, new Predicate<String>() {

        @Override
        public boolean apply(String input) {
            return componentsToUpdate.contains(input);
        }
    }).values());
    final RequestSummary componentRequestSummary = componentClient.updateComponents(updatedComponents, user);
    RequestSummary attachmentSummary = null;
    if (!attachmentStubsToDelete.isEmpty()) {
        attachmentSummary = attachmentClient.bulkDelete(Lists.transform(Lists.newArrayList(attachmentStubsToDelete), new Function<Attachment, String>() {

            @Override
            public String apply(Attachment input) {
                return input.getAttachmentContentId();
            }
        }));
    }
    RequestSummary requestSummary = CommonUtils.addRequestSummaries(releaseRequestSummary, "release", componentRequestSummary, "component");
    if (attachmentSummary != null) {
        requestSummary = CommonUtils.addToMessage(requestSummary, attachmentSummary, "attachment deletion");
    }
    return requestSummary;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Component(org.eclipse.sw360.datahandler.thrift.components.Component) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 19 with RequestSummary

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

the class ComponentImportUtils method writeReleaseLinksToDatabase.

public static RequestSummary writeReleaseLinksToDatabase(FluentIterable<ReleaseLinkCSVRecord> csvRecords, ComponentService.Iface componentClient, User user) throws TException {
    final List<Component> componentDetailedSummaryForExport = componentClient.getComponentDetailedSummaryForExport();
    final Map<String, Release> releasesByIdentifier = getReleasesByIdentifier(componentDetailedSummaryForExport);
    final Set<String> releasesIdentifiersToBeUpdated = new HashSet<>();
    for (ReleaseLinkCSVRecord csvRecord : csvRecords) {
        final String releaseIdentifier = csvRecord.getReleaseIdentifier();
        final String linkedReleaseIdentifier = csvRecord.getLinkedReleaseIdentifier();
        final ReleaseRelationship relationship = csvRecord.getRelationship();
        if (releaseIdentifier != null && linkedReleaseIdentifier != null && relationship != null) {
            final Release release = releasesByIdentifier.get(releaseIdentifier);
            final Release linkedRelease = releasesByIdentifier.get(linkedReleaseIdentifier);
            if (release != null && linkedRelease != null) {
                final Map<String, ReleaseRelationship> releaseIdToRelationship = getRelationshipMap(release);
                releaseIdToRelationship.put(linkedRelease.getId(), relationship);
                release.setReleaseIdToRelationship(releaseIdToRelationship);
                releasesIdentifiersToBeUpdated.add(releaseIdentifier);
            }
        }
    }
    final HashSet<Release> updatedReleases = getUpdatedReleases(releasesByIdentifier, releasesIdentifiersToBeUpdated);
    return componentClient.updateReleases(updatedReleases, user);
}
Also used : ReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ReleaseRelationship) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 20 with RequestSummary

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

the class CommonUtils method addRequestSummaries.

public static RequestSummary addRequestSummaries(RequestSummary left, RequestSummary right) {
    RequestSummary result = new RequestSummary();
    result.requestStatus = left.isSetRequestStatus() && left.requestStatus.equals(RequestStatus.SUCCESS) && right.isSetRequestStatus() && right.requestStatus.equals(RequestStatus.SUCCESS) ? RequestStatus.SUCCESS : RequestStatus.FAILURE;
    result.setTotalElements(left.getTotalElements() + right.getTotalElements());
    result.setTotalAffectedElements(left.getTotalAffectedElements() + right.getTotalAffectedElements());
    return result;
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

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