use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentController method getComponents.
@RequestMapping(value = COMPONENTS_URL, method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Component>>> getComponents(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "type", required = false) String componentType, OAuth2Authentication oAuth2Authentication) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
List<Component> sw360Components = new ArrayList<>();
if (name != null && !name.isEmpty()) {
sw360Components.addAll(componentService.searchComponentByName(name));
} else {
sw360Components.addAll(componentService.getComponentsForUser(sw360User));
}
List<Resource<Component>> componentResources = new ArrayList<>();
sw360Components.stream().filter(component -> componentType == null || componentType.equals(component.componentType.name())).forEach(c -> {
Component embeddedComponent = restControllerHelper.convertToEmbeddedComponent(c);
componentResources.add(new Resource<>(embeddedComponent));
});
Resources<Resource<Component>> resources = new Resources<>(componentResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentController method createComponent.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = COMPONENTS_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<Component>> createComponent(OAuth2Authentication oAuth2Authentication, @RequestBody Component component) throws URISyntaxException, TException {
User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
if (component.getVendorNames() != null) {
Set<String> vendors = new HashSet<>();
for (String vendorUriString : component.getVendorNames()) {
URI vendorURI = new URI(vendorUriString);
String path = vendorURI.getPath();
String vendorId = path.substring(path.lastIndexOf('/') + 1);
Vendor vendor = vendorService.getVendorById(vendorId);
String vendorFullName = vendor.getFullname();
vendors.add(vendorFullName);
}
component.setVendorNames(vendors);
}
Component sw360Component = componentService.createComponent(component, user);
HalResource<Component> halResource = createHalComponent(sw360Component, user);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(sw360Component.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class Sw360ComponentService method createComponent.
public Component createComponent(Component component, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
AddDocumentRequestSummary documentRequestSummary = sw360ComponentClient.addComponent(component, sw360User);
if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.SUCCESS) {
component.setId(documentRequestSummary.getId());
return component;
} else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE) {
throw new DataIntegrityViolationException("sw360 component with name '" + component.getName() + "' already exists.");
}
return null;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentImportUtils method getFlattenedView.
@NotNull
public static List<Iterable<String>> getFlattenedView(List<Component> componentDetailedSummaryForExport) {
List<Iterable<String>> csvRows = new ArrayList<>();
Set<String> exportedReleaseIdentifiers = new HashSet<>();
Set<String> exportedComponentIdentifiers = new HashSet<>();
if (componentDetailedSummaryForExport != null) {
for (Component component : componentDetailedSummaryForExport) {
final List<Release> releases = component.getReleases();
if (releases != null && releases.size() > 0) {
for (Release release : releases) {
if (isNotProcessed(exportedReleaseIdentifiers, release)) {
final ComponentCSVRecordBuilder componentCSVRecordBuilder = ComponentCSVRecord.builder();
componentCSVRecordBuilder.fill(component);
componentCSVRecordBuilder.fill(release);
csvRows.add(componentCSVRecordBuilder.build().getCSVIterable());
}
}
} else {
if (isNotProcessed(exportedComponentIdentifiers, component)) {
final ComponentCSVRecordBuilder componentCSVRecordBuilder = ComponentCSVRecord.builder();
componentCSVRecordBuilder.fill(component);
csvRows.add(componentCSVRecordBuilder.build().getCSVIterable());
}
}
}
}
return csvRows;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component 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;
}
Aggregations