use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class AttachmentStreamConnectorTest method testGetConcatenatedStreamReadThrowsOnNonExistent.
@Test
public void testGetConcatenatedStreamReadThrowsOnNonExistent() 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);
when(connector.getAttachment(attachmentId, "fil_part2")).thenThrow(new DocumentNotFoundException(""));
when(part1.read()).thenReturn(1, -1);
InputStream attachmentStream = attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentId))));
assertThat(attachmentStream.read(), is(1));
try {
assertThat(attachmentStream.read(), is(2));
fail("expected Exception not thrown");
} catch (IOException ignored) {
}
verify(part1).close();
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class AttachmentStreamConnectorTest method testGetFullStream.
@Test
public void testGetFullStream() throws Exception {
AttachmentContent attachment = mock(AttachmentContent.class);
when(attachment.isOnlyRemote()).thenReturn(false);
when(attachment.isSetPartsCount()).thenReturn(false);
when(attachment.getFilename()).thenReturn("fil");
String attachmentId = "id";
when(attachment.getId()).thenReturn(attachmentId);
AttachmentInputStream full = mock(AttachmentInputStream.class);
when(connector.getAttachment(attachmentId, "fil")).thenReturn(full);
when(full.read()).thenReturn(1, 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))));
assertThat(attachmentStream.read(), is(1));
assertThat(attachmentStream.read(), is(2));
assertThat(attachmentStream.read(), is(-1));
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ModerationPortlet method renderProjectModeration.
public void renderProjectModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
final boolean requestDocumentDelete = moderationRequest.isRequestDocumentDelete();
Boolean is_used = false;
Project actual_project = null;
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
actual_project = client.getProjectById(moderationRequest.getDocumentId(), user);
actual_project = client.fillClearingStateSummary(Collections.singletonList(actual_project), user).get(0);
is_used = client.projectIsUsed(actual_project.getId());
request.setAttribute(PortalConstants.ACTUAL_PROJECT, actual_project);
request.setAttribute(PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT, getDefaultLicenseInfoHeaderText());
} catch (TException e) {
log.error("Could not retrieve project", e);
}
if (actual_project == null) {
renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
return;
}
if (refuseToDeleteUsedDocument(request, response, moderationRequest, user, requestDocumentDelete, is_used))
return;
prepareProject(request, user, actual_project);
if (moderationRequest.isRequestDocumentDelete()) {
include("/html/moderation/projects/delete.jsp", request, response);
} else {
// updateProjectFromModerationRequest and add updated project to request.
include("/html/moderation/projects/merge.jsp", request, response);
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project 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;
}
}
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectImportPortlet method updateImportables.
private void updateImportables(JSONObject responseData, LoginState loginState, RemoteCredentials remoteCredentials, String projectName) throws JsonProcessingException {
if (!nullToEmpty(remoteCredentials.getServerUrl()).isEmpty()) {
List<Project> importables = loadImportables(remoteCredentials, projectName);
JSONArray serializedProjects = JSONFactoryUtil.createJSONArray();
for (Project p : importables) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
if (p.isSetExternalIds() && !isNullOrEmpty(p.getExternalIds().get(getIdName())))
jsonObject.put("externalId", p.getExternalIds().get(getIdName()));
jsonObject.put("name", p.getName());
serializedProjects.put(jsonObject.toString());
}
responseData.put(ProjectImportConstants.RESPONSE__NEW_IMPORTABLES, serializedProjects);
}
responseData.put(ProjectImportConstants.RESPONSE__DB_URL, remoteCredentials.getServerUrl());
loginState.login(remoteCredentials.getServerUrl());
}
Aggregations