Search in sources :

Example 21 with Project

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

the class Sw360ProjectService method createProject.

public Project createProject(Project project, User sw360User) throws TException {
    ProjectService.Iface sw360ProjectClient = getThriftProjectClient();
    AddDocumentRequestSummary documentRequestSummary = sw360ProjectClient.addProject(project, sw360User);
    if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.SUCCESS) {
        project.setId(documentRequestSummary.getId());
        return project;
    } else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE) {
        throw new DataIntegrityViolationException("sw360 project with name '" + project.getName() + "' already exists.");
    }
    return null;
}
Also used : AddDocumentRequestSummary(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 22 with Project

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

the class VendorResourceProcessor method process.

@Override
public Resource<Vendor> process(Resource<Vendor> resource) {
    Vendor project = resource.getContent();
    Link selfLink = linkTo(VendorController.class).slash("api" + VendorController.VENDORS_URL + "/" + project.getId()).withSelfRel();
    resource.add(selfLink);
    return resource;
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Link(org.springframework.hateoas.Link)

Example 23 with Project

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

the class WhenComputePermissions method the_highest_allowed_action_is_computed_for_user_$_with_user_group_$_and_department_$.

public WhenComputePermissions the_highest_allowed_action_is_computed_for_user_$_with_user_group_$_and_department_$(@Quoted String userEmail, @TEnumToString UserGroup userGroup, @Quoted String userDept) {
    final User user = new User(DUMMY_ID, userEmail, userDept).setUserGroup(userGroup);
    final DocumentPermissions<Project> projectDocumentPermissions = PermissionUtils.makePermission(project, user);
    allowedActions = projectDocumentPermissions.getAllAllowedActions();
    return self();
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 24 with Project

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

the class AttachmentStreamConnectorTest method testGetConcatenatedStream.

@Test
public void testGetConcatenatedStream() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.isOnlyRemote()).thenReturn(false);
    when(attachment.isSetPartsCount()).thenReturn(true);
    when(attachment.getPartsCount()).thenReturn("2");
    when(attachment.getFilename()).thenReturn("fil");
    String attachmentId = "id";
    when(attachment.getId()).thenReturn(attachmentId);
    AttachmentInputStream part1 = mock(AttachmentInputStream.class);
    when(connector.getAttachment(attachmentId, "fil_part1")).thenReturn(part1);
    AttachmentInputStream part2 = mock(AttachmentInputStream.class);
    when(connector.getAttachment(attachmentId, "fil_part2")).thenReturn(part2);
    when(part1.read()).thenReturn(1, -1);
    when(part2.read()).thenReturn(2, -1);
    InputStream attachmentStream = attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentId))));
    verifyZeroInteractions(part2);
    assertThat(attachmentStream.read(), is(1));
    assertThat(attachmentStream.read(), is(2));
    verify(part1).close();
    assertThat(attachmentStream.read(), is(-1));
    verify(part2).close();
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) AttachmentInputStream(org.ektorp.AttachmentInputStream) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 25 with Project

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

the class AttachmentStreamConnectorTest method testTryingToDownloadIfNotAvailable.

@Test
public void testTryingToDownloadIfNotAvailable() throws Exception {
    String id = "11";
    String filename = "filename";
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.isOnlyRemote()).thenReturn(true);
    when(attachment.getId()).thenReturn(id);
    when(attachment.getFilename()).thenReturn(filename);
    InputStream downloadUrlStream = mock(InputStream.class);
    InputStream returnedStream = mock(InputStream.class);
    AttachmentContent rereadAttachment = mock(AttachmentContent.class);
    when(rereadAttachment.getId()).thenReturn(id);
    when(rereadAttachment.getFilename()).thenReturn(filename);
    attachmentStreamConnector = spy(attachmentStreamConnector);
    doReturn(returnedStream).when(attachmentStreamConnector).readAttachmentStream(rereadAttachment);
    doNothing().when(attachmentStreamConnector).uploadAttachmentPart(attachment, 1, downloadUrlStream);
    when(attachmentContentDownloader.download(eq(attachment), Matchers.any(Duration.class))).thenReturn(downloadUrlStream);
    when(connector.get(AttachmentContent.class, id)).thenReturn(rereadAttachment);
    doReturn(rereadAttachment).when(rereadAttachment).setOnlyRemote(anyBoolean());
    assertThat(attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(id)))), sameInstance(returnedStream));
    verify(attachmentContentDownloader).download(eq(attachment), Matchers.any(Duration.class));
    verify(attachmentStreamConnector).uploadAttachment(attachment, downloadUrlStream);
    verify(attachmentStreamConnector).readAttachmentStream(rereadAttachment);
    verify(rereadAttachment).setOnlyRemote(false);
    verify(connector).update(rereadAttachment);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Duration(org.eclipse.sw360.datahandler.common.Duration) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5