Search in sources :

Example 1 with SW360Exception

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"));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 2 with SW360Exception

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);
        }
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 3 with SW360Exception

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);
    }
}
Also used : InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 4 with SW360Exception

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));
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) IOException(java.io.IOException) ProjectExporter(org.eclipse.sw360.exporter.ProjectExporter)

Example 5 with SW360Exception

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;
}
Also used : User(com.liferay.portal.model.User) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Aggregations

SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)23 IOException (java.io.IOException)10 InputStream (java.io.InputStream)9 TException (org.apache.thrift.TException)9 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)8 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 Test (org.junit.Test)4 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)3 SW360Utils.fieldValueAsString (org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 PipedInputStream (java.io.PipedInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ConcatClosingInputStream (org.eclipse.sw360.datahandler.common.ConcatClosingInputStream)2 WrappedSW360Exception (org.eclipse.sw360.datahandler.common.WrappedException.WrappedSW360Exception)2