use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ComponentHandlerTest method testGetByUploadId.
@Test
public void testGetByUploadId() throws Exception {
Component originalComponent = new Component("name").setDescription("a desc");
String componentId = componentHandler.addComponent(originalComponent, adminUser).getId();
Release release = new Release("name", "version", componentId).setFossologyId("id");
String releaseId = componentHandler.addRelease(release, adminUser).getId();
Component component = componentHandler.getComponentForReportFromFossologyUploadId("id");
assertThat(component, is(not(nullValue())));
assertThat(component, is(equalTo(originalComponent, restrictedToFields(ID, NAME, DESCRIPTION))));
assertThat(componentHandler.getReleaseById(releaseId, adminUser), is(not(nullValue())));
assertThat(componentHandler.getComponentById(componentId, adminUser), is(not(nullValue())));
assertThat(componentHandler.deleteRelease(releaseId, adminUser), is(RequestStatus.SUCCESS));
assertThat(componentHandler.deleteComponent(componentId, adminUser), is(RequestStatus.SUCCESS));
try {
componentHandler.getReleaseById(releaseId, adminUser);
fail("expected exception not thrown");
} catch (SW360Exception e) {
assertThat(e.getWhy(), containsString("Could not fetch"));
}
try {
componentHandler.getComponentById(componentId, adminUser);
fail("expected exception not thrown");
} catch (SW360Exception e) {
assertThat(e.getWhy(), containsString("Could not fetch"));
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ProjectDatabaseHandler method releaseIdToProjects.
private void releaseIdToProjects(Project project, User user, Set<String> visitedProjectIds, Multimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects) throws SW360Exception {
if (nothingTodo(project, visitedProjectIds))
return;
nullToEmptyMap(project.getReleaseIdToUsage()).forEach((releaseId, relation) -> {
releaseIdToProjects.put(releaseId, new ProjectWithReleaseRelationTuple(project, relation));
});
Map<String, ProjectRelationship> linkedProjects = project.getLinkedProjects();
if (linkedProjects != null) {
for (String projectId : linkedProjects.keySet()) {
if (visitedProjectIds.contains(projectId))
continue;
Project linkedProject = getProjectById(projectId, user);
releaseIdToProjects(linkedProject, user, visitedProjectIds, releaseIdToProjects);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class AttachmentConnector method getSha1FromAttachmentContentId.
public String getSha1FromAttachmentContentId(String attachmentContentId) {
InputStream attachmentStream = null;
try {
AttachmentContent attachmentContent = getAttachmentContent(attachmentContentId);
attachmentStream = readAttachmentStream(attachmentContent);
return sha1Hex(attachmentStream);
} catch (SW360Exception e) {
log.error("Problem retrieving content of attachment", e);
return "";
} catch (IOException e) {
log.error("Problem computing the sha1 checksum", e);
return "";
} finally {
closeQuietly(attachmentStream, log);
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class ProjectPortlet method exportExcel.
private void exportExcel(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);
try {
boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
List<Project> projects = getFilteredProjectList(request);
ProjectExporter exporter = new ProjectExporter(thriftClients.makeComponentClient(), thriftClients.makeProjectClient(), user, projects, extendedByReleases);
PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), CONTENT_TYPE_OPENXML_SPREADSHEET);
} catch (IOException | SW360Exception e) {
log.error("An error occurred while generating the Excel export", e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
}
use of org.eclipse.sw360.datahandler.thrift.SW360Exception in project sw360portal by sw360.
the class UserPortlet method getCurrentUser.
private User getCurrentUser(PortletRequest request) throws SW360Exception {
User user;
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
if (themeDisplay.isSignedIn())
user = themeDisplay.getUser();
else {
throw new SW360Exception("Broken portlet!");
}
return user;
}
Aggregations