Search in sources :

Example 61 with Project

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

the class LicenseInfoHandler method getLicenseInfoFile.

@Override
public LicenseInfoFile getLicenseInfoFile(Project project, User user, String outputGenerator, Map<String, Set<String>> releaseIdsToSelectedAttachmentIds, Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachment) throws TException {
    assertNotNull(project);
    assertNotNull(user);
    assertNotNull(outputGenerator);
    assertNotNull(releaseIdsToSelectedAttachmentIds);
    assertNotNull(excludedLicensesPerAttachment);
    Map<Release, Set<String>> releaseToAttachmentId = mapKeysToReleases(releaseIdsToSelectedAttachmentIds, user);
    Collection<LicenseInfoParsingResult> projectLicenseInfoResults = getAllReleaseLicenseInfos(releaseToAttachmentId, user, excludedLicensesPerAttachment);
    String[] outputGeneratorClassnameAndVariant = outputGenerator.split("::");
    if (outputGeneratorClassnameAndVariant.length != 2) {
        throw new TException("Unsupported output generator value: " + outputGenerator);
    }
    String outputGeneratorClassName = outputGeneratorClassnameAndVariant[0];
    OutputFormatVariant outputGeneratorVariant = Enums.getIfPresent(OutputFormatVariant.class, outputGeneratorClassnameAndVariant[1]).orNull();
    OutputGenerator<?> generator = getOutputGeneratorByClassnameAndVariant(outputGeneratorClassName, outputGeneratorVariant);
    LicenseInfoFile licenseInfoFile = new LicenseInfoFile();
    licenseInfoFile.setOutputFormatInfo(generator.getOutputFormatInfo());
    String licenseInfoHeaderText = (project.isSetLicenseInfoHeaderText()) ? project.getLicenseInfoHeaderText() : getDefaultLicenseInfoHeaderText();
    Object output = generator.generateOutputFile(projectLicenseInfoResults, project.getName(), project.getVersion(), licenseInfoHeaderText);
    if (output instanceof byte[]) {
        licenseInfoFile.setGeneratedOutput((byte[]) output);
    } else if (output instanceof String) {
        licenseInfoFile.setGeneratedOutput(((String) output).getBytes());
    } else {
        throw new TException("Unsupported output generator result: " + output.getClass().getSimpleName());
    }
    return licenseInfoFile;
}
Also used : WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) CommonUtils.nullToEmptySet(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 62 with Project

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

the class CombinedCLIParserTest method testIsApplicableToFailsOnMalformedXML.

@Test
public void testIsApplicableToFailsOnMalformedXML() 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("this is not an xml file")));
    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)

Example 63 with Project

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

the class CombinedCLIParserTest method testIsApplicableTo.

@Test
public void testIsApplicableTo() throws Exception {
    when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(makeAttachmentContentStream(TEST_XML_FILENAME));
    assertTrue(parser.isApplicableTo(attachment, new User(), new Project()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User) Test(org.junit.Test)

Example 64 with Project

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

the class CombinedCLIParserTest method testGetCLI.

@Test
public void testGetCLI() throws Exception {
    Attachment cliAttachment = new Attachment("A1", "a.xml");
    when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(cliTestfile)));
    List<LicenseInfoParsingResult> results = parser.getLicenseInfos(cliAttachment, new User(), new Project());
    assertThat(results.size(), is(1));
    LicenseInfoParsingResult res = results.get(0);
    assertLicenseInfoParsingResult(res);
    assertThat(res.getLicenseInfo().getFilenames(), containsInAnyOrder("a.xml"));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(3));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("License1Text", "License2Text", "License3&'Text"));
    LicenseNameWithText l2 = res.getLicenseInfo().getLicenseNamesWithTexts().stream().filter(l -> l.getLicenseName().equals("License2")).findFirst().orElseThrow(AssertionError::new);
    assertThat(l2.getAcknowledgements(), is("License2Acknowledgements"));
    assertThat(res.getLicenseInfo().getCopyrights().size(), is(5));
    assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyright1", "Copyright2", "Copyright3", "Copyright4", "Copyright5"));
    assertThat(res.getVendor(), is("VendorA"));
    assertThat(res.getName(), is("r1"));
    assertThat(res.getVersion(), is("1.0"));
}
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) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) StringReader(java.io.StringReader) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) TestHelper.assertLicenseInfoParsingResult(org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult) Test(org.junit.Test)

Example 65 with Project

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

the class CLIParserTest method testIsApplicableTo.

@Test
public void testIsApplicableTo() throws Exception {
    when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE)));
    assertTrue(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) 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