Search in sources :

Example 71 with Component

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);
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URISyntaxException(java.net.URISyntaxException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) BasePathAwareController(org.springframework.data.rest.webmvc.BasePathAwareController) Sw360AttachmentService(org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Sw360VendorService(org.eclipse.sw360.rest.resourceserver.vendor.Sw360VendorService) URI(java.net.URI) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) NonNull(lombok.NonNull) MediaType(org.springframework.http.MediaType) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) IOException(java.io.IOException) Resource(org.springframework.hateoas.Resource) RestControllerHelper(org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) Sw360ReleaseService(org.eclipse.sw360.rest.resourceserver.release.Sw360ReleaseService) ResourceProcessor(org.springframework.hateoas.ResourceProcessor) ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Resource(org.springframework.hateoas.Resource) Resources(org.springframework.hateoas.Resources) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 72 with Component

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Component(org.eclipse.sw360.datahandler.thrift.components.Component) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 73 with Component

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;
}
Also used : AddDocumentRequestSummary(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 74 with Component

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;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with Component

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

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2