Search in sources :

Example 16 with Component

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

the class ComponentTest method before.

@Before
public void before() throws TException {
    List<Component> componentList = new ArrayList<>();
    Component component = new Component();
    component.setName("Component name");
    component.setDescription("Component description");
    componentList.add(component);
    given(this.componentServiceMock.getComponentsForUser(anyObject())).willReturn(componentList);
    User user = new User();
    user.setId("admin@sw360.org");
    user.setEmail("admin@sw360.org");
    user.setFullname("John Doe");
    given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ArrayList(java.util.ArrayList) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Before(org.junit.Before)

Example 17 with Component

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

the class RestControllerHelper method convertToEmbeddedComponent.

public Component convertToEmbeddedComponent(Component component) {
    Component embeddedComponent = new Component();
    embeddedComponent.setId(component.getId());
    embeddedComponent.setName(component.getName());
    embeddedComponent.setComponentType(component.getComponentType());
    embeddedComponent.setType(null);
    return embeddedComponent;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 18 with Component

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

the class RestControllerHelper method createHalReleaseResource.

public HalResource<Release> createHalReleaseResource(Release release, boolean verbose) {
    HalResource<Release> halRelease = new HalResource<>(release);
    Link componentLink = linkTo(ReleaseController.class).slash("api" + ComponentController.COMPONENTS_URL + "/" + release.getComponentId()).withRel("component");
    halRelease.add(componentLink);
    release.setComponentId(null);
    if (verbose) {
        if (release.getModerators() != null) {
            Set<String> moderators = release.getModerators();
            this.addEmbeddedModerators(halRelease, moderators);
            release.setModerators(null);
        }
        if (release.getAttachments() != null) {
            Set<Attachment> attachments = release.getAttachments();
            this.addEmbeddedAttachments(halRelease, attachments);
            release.setAttachments(null);
        }
        if (release.getVendor() != null) {
            Vendor vendor = release.getVendor();
            HalResource<Vendor> vendorHalResource = this.addEmbeddedVendor(vendor.getFullname());
            halRelease.addEmbeddedResource("sw360:vendors", vendorHalResource);
            release.setVendor(null);
        }
        if (release.getMainLicenseIds() != null) {
            this.addEmbeddedLicenses(halRelease, release.getMainLicenseIds());
            release.setMainLicenseIds(null);
        }
    }
    return halRelease;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Link(org.springframework.hateoas.Link)

Example 19 with Component

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

the class ComponentSpecTest method before.

@Before
public void before() throws TException {
    List<Component> componentList = new ArrayList<>();
    List<Component> componentListByName = new ArrayList<>();
    angularComponent = new Component();
    angularComponent.setId("17653524");
    angularComponent.setName("Angular");
    angularComponent.setComponentOwner("John");
    angularComponent.setDescription("Angular is a development platform for building mobile and desktop web applications.");
    angularComponent.setCreatedOn("2016-12-15");
    angularComponent.setCreatedBy("admin@sw360.org");
    angularComponent.setComponentType(ComponentType.OSS);
    angularComponent.setVendorNames(new HashSet<>(Collections.singletonList("Google")));
    angularComponent.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "john@sw360.org")));
    angularComponent.setOwnerAccountingUnit("4822");
    angularComponent.setOwnerCountry("DE");
    angularComponent.setOwnerGroup("AA BB 123 GHV2-DE");
    angularComponent.setCategories(ImmutableSet.of("java", "javascript", "sql"));
    angularComponent.setLanguages(ImmutableSet.of("EN", "DE"));
    angularComponent.setOperatingSystems(ImmutableSet.of("Windows", "Linux"));
    componentList.add(angularComponent);
    componentListByName.add(angularComponent);
    Component springComponent = new Component();
    springComponent.setId("678dstzd8");
    springComponent.setName("Spring Framework");
    springComponent.setComponentOwner("Jane");
    springComponent.setDescription("The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications.");
    springComponent.setCreatedOn("2016-12-18");
    springComponent.setCreatedBy("jane@sw360.org");
    springComponent.setComponentType(ComponentType.OSS);
    springComponent.setVendorNames(new HashSet<>(Collections.singletonList("Pivotal")));
    springComponent.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    springComponent.setOwnerAccountingUnit("5661");
    springComponent.setOwnerCountry("FR");
    springComponent.setOwnerGroup("SIM-KA12");
    springComponent.setCategories(ImmutableSet.of("jdbc", "java"));
    springComponent.setLanguages(ImmutableSet.of("EN", "DE"));
    springComponent.setOperatingSystems(ImmutableSet.of("Windows", "Linux"));
    componentList.add(springComponent);
    when(this.componentServiceMock.createComponent(anyObject(), anyObject())).then(invocation -> {
        springComponent.setType("component");
        springComponent.setCreatedOn("2016-12-20");
        springComponent.setModerators(null);
        springComponent.setVendorNames(null);
        return springComponent;
    });
    given(this.componentServiceMock.getComponentsForUser(anyObject())).willReturn(componentList);
    given(this.componentServiceMock.getComponentForUserById(eq("17653524"), anyObject())).willReturn(angularComponent);
    given(this.componentServiceMock.searchComponentByName(eq(angularComponent.getName()))).willReturn(componentListByName);
    User user = new User();
    user.setId("admin@sw360.org");
    user.setEmail("admin@sw360.org");
    user.setFullname("John Doe");
    user.setDepartment("sw360");
    given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
    List<Release> releaseList = new ArrayList<>();
    Release release = new Release();
    release.setId("3765276512");
    release.setName("Angular 2.3.0");
    release.setCpeid("cpe:/a:Google:Angular:2.3.0:");
    release.setReleaseDate("2016-12-07");
    release.setVersion("2.3.0");
    release.setCreatedOn("2016-12-18");
    release.setCreatedBy("admin@sw360.org");
    release.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    release.setComponentId(springComponent.getId());
    releaseList.add(release);
    Release release2 = new Release();
    release2.setId("3765276512");
    release2.setName("Angular 2.3.1");
    release2.setCpeid("cpe:/a:Google:Angular:2.3.1:");
    release2.setReleaseDate("2016-12-15");
    release2.setVersion("2.3.1");
    release2.setCreatedOn("2016-12-18");
    release2.setCreatedBy("admin@sw360.org");
    release2.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    release2.setComponentId(springComponent.getId());
    releaseList.add(release2);
    angularComponent.setReleases(releaseList);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 20 with Component

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

the class ModerationPortlet method renderEditViewForId.

private void renderEditViewForId(RenderRequest request, RenderResponse response, String id) throws IOException, PortletException, TException {
    if (id != null) {
        ModerationRequest moderationRequest = null;
        User user = UserCacheHolder.getUserFromRequest(request);
        try {
            ModerationService.Iface client = thriftClients.makeModerationClient();
            moderationRequest = client.getModerationRequestById(id);
            boolean actionsAllowed = moderationRequest.getModerators().contains(user.getEmail()) && ModerationPortletUtils.isOpenModerationRequest(moderationRequest);
            request.setAttribute(PortalConstants.MODERATION_ACTIONS_ALLOWED, actionsAllowed);
            if (actionsAllowed) {
                SessionMessages.add(request, "request_processed", "You have assigned yourself to this moderation request.");
                client.setInProgress(id, user);
            }
            request.setAttribute(PortalConstants.MODERATION_REQUEST, moderationRequest);
            addModerationBreadcrumb(request, response, moderationRequest);
        } catch (TException e) {
            log.error("Error fetching moderation  details from backend", e);
        }
        if (moderationRequest != null) {
            switch(moderationRequest.getDocumentType()) {
                case COMPONENT:
                    renderComponentModeration(request, response, moderationRequest, user);
                    break;
                case RELEASE:
                    VendorService.Iface vendorClient = thriftClients.makeVendorClient();
                    Release additions = moderationRequest.getReleaseAdditions();
                    if (additions.isSetVendorId()) {
                        additions.setVendor(vendorClient.getByID(additions.getVendorId()));
                    }
                    Release deletions = moderationRequest.getReleaseDeletions();
                    if (deletions.isSetVendorId()) {
                        deletions.setVendor(vendorClient.getByID(deletions.getVendorId()));
                    }
                    renderReleaseModeration(request, response, moderationRequest, user);
                    break;
                case PROJECT:
                    renderProjectModeration(request, response, moderationRequest, user);
                    break;
                case LICENSE:
                    renderLicenseModeration(request, response, moderationRequest, user);
                    break;
                case USER:
                    renderUserModeration(request, response, moderationRequest, user);
                    break;
            }
        }
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) 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