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