Search in sources :

Example 91 with Project

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

the class ProjectPortlet method getSourceCodeBundleName.

private String getSourceCodeBundleName(ResourceRequest request) throws TException {
    User user = UserCacheHolder.getUserFromRequest(request);
    ProjectService.Iface projectClient = thriftClients.makeProjectClient();
    String projectId = request.getParameter(PROJECT_ID);
    Project project = projectClient.getProjectById(projectId, user);
    String timestamp = SW360Utils.getCreatedOn();
    return "SourceCodeBundle-" + project.getName() + "-" + timestamp + ".zip";
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 92 with Project

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

the class FossologyAwarePortlet method serveProjectSendToFossology.

protected void serveProjectSendToFossology(ResourceRequest request, ResourceResponse response) {
    String projectId = request.getParameter(PROJECT_ID);
    String[] releaseIdArray = request.getParameterValues(RELEASE_ID);
    if (projectId == null || releaseIdArray == null) {
        renderRequestStatus(request, response, RequestStatus.FAILURE);
        return;
    }
    String clearingTeam = request.getParameter(CLEARING_TEAM);
    if (isNullOrEmpty(clearingTeam)) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(projectId, user);
            clearingTeam = project.getClearingTeam();
        } catch (TException e) {
            renderRequestStatus(request, response, RequestStatus.FAILURE);
            log.error("Problem with project client", e);
        }
    }
    if (!isNullOrEmpty(clearingTeam) && !CLEARING_TEAM_UNKNOWN.equals(clearingTeam)) {
        List<String> releaseIds = Arrays.asList(releaseIdArray);
        try {
            FossologyService.Iface fossologyClient = thriftClients.makeFossologyClient();
            renderRequestStatus(request, response, fossologyClient.sendReleasesToFossology(releaseIds, UserCacheHolder.getUserFromRequest(request), clearingTeam));
        } catch (TException e) {
            renderRequestStatus(request, response, RequestStatus.FAILURE);
            log.error("Problem with fossology client", e);
        }
    } else {
        renderRequestStatus(request, response, RequestStatus.FAILURE);
        log.error("Cannot decide on a clearing team for project " + projectId);
    }
}
Also used : TException(org.apache.thrift.TException) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) FossologyService(org.eclipse.sw360.datahandler.thrift.fossology.FossologyService)

Example 93 with Project

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

the class RemoteAttachmentDownloaderTest method testWithBrokenURL.

@Test
public void testWithBrokenURL() throws Exception {
    AttachmentContent attachmentContent = saveRemoteAttachment(TestUtils.BLACK_HOLE_ADDRESS);
    AttachmentContent attachmentGood = saveRemoteAttachment(url);
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(2));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(1));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    assertThat(attachmentConnector.getAttachmentStream(attachmentGood, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentGood.getId())))), hasLength(greaterThan(0l)));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(0));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    try {
        assertThat(attachmentConnector.getAttachmentStream(attachmentContent, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentContent.getId())))), hasLength(greaterThan(0l)));
        fail("expected exception not thrown");
    } catch (SW360Exception e) {
        assertThat(e.getWhy(), containsString(attachmentContent.getId()));
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 94 with Project

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

the class RemoteAttachmentDownloaderTest method testIntegration.

@Test
public void testIntegration() throws Exception {
    AttachmentContent attachmentContent = saveRemoteAttachment(url);
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(1));
    assertThat(attachmentConnector.getAttachmentStream(attachmentContent, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentContent.getId())))), hasLength(greaterThan(0l)));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(0));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 95 with Project

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

the class CombinedCLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.

@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
    AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
    assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) 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