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