Search in sources :

Example 41 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class CLIParserTest 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(CLI_TESTFILE)));
    LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
    assertLicenseInfoParsingResult(res);
    assertThat(res.getStatus(), is(LicenseInfoRequestStatus.SUCCESS));
    assertThat(res.getLicenseInfo(), notNullValue());
    assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(1));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("jQuery projects are released under the terms of the MIT license."));
    assertThat(res.getLicenseInfo().getCopyrights().size(), is(2));
    assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyrights", "(c) jQuery Foundation, Inc. | jquery.org"));
}
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 42 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class LicenseController method getLicenses.

@RequestMapping(value = LICENSES_URL, method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<License>>> getLicenses(OAuth2Authentication oAuth2Authentication) throws TException {
    List<License> sw360Licenses = licenseService.getLicenses();
    List<Resource<License>> licenseResources = new ArrayList<>();
    for (License sw360License : sw360Licenses) {
        License embeddedLicense = restControllerHelper.convertToEmbeddedLicense(sw360License);
        Resource<License> licenseResource = new Resource<>(embeddedLicense);
        licenseResources.add(licenseResource);
    }
    Resources<Resource<License>> resources = new Resources<>(licenseResources);
    return new ResponseEntity<>(resources, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) License(org.eclipse.sw360.datahandler.thrift.licenses.License) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Resource(org.springframework.hateoas.Resource) ArrayList(java.util.ArrayList) Resources(org.springframework.hateoas.Resources) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class Sw360LicenseService method createLicense.

public License createLicense(License license, User sw360User) throws TException {
    LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
    license.setId(license.getShortname());
    List<License> licenses = sw360LicenseClient.addLicenses(Collections.singletonList(license), sw360User);
    for (License newLicense : licenses) {
        if (license.getFullname().equals(newLicense.getFullname())) {
            return newLicense;
        }
    }
    return null;
}
Also used : LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) License(org.eclipse.sw360.datahandler.thrift.licenses.License)

Example 44 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class RestControllerHelper method addEmbeddedLicense.

private HalResource<License> addEmbeddedLicense(String licenseId) {
    License embeddedLicense = convertToEmbeddedLicense(licenseId);
    HalResource<License> halLicense = new HalResource<>(embeddedLicense);
    try {
        License licenseById = licenseService.getLicenseById(licenseId);
        embeddedLicense.setFullname(licenseById.getFullname());
        Link licenseSelfLink = linkTo(UserController.class).slash("api" + LicenseController.LICENSES_URL + "/" + licenseById.getId()).withSelfRel();
        halLicense.add(licenseSelfLink);
        return halLicense;
    } catch (Exception e) {
        LOGGER.error("cannot create self link for license with id: " + licenseId);
    }
    return null;
}
Also used : License(org.eclipse.sw360.datahandler.thrift.licenses.License) Link(org.springframework.hateoas.Link) TException(org.apache.thrift.TException)

Example 45 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class RestControllerHelper method convertToEmbeddedLicense.

public License convertToEmbeddedLicense(String licenseId) {
    License embeddedLicense = new License();
    embeddedLicense.setId(licenseId);
    embeddedLicense.setType(null);
    return embeddedLicense;
}
Also used : License(org.eclipse.sw360.datahandler.thrift.licenses.License)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)20 TException (org.apache.thrift.TException)16 License (org.eclipse.sw360.datahandler.thrift.licenses.License)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)8 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Logger (org.apache.log4j.Logger)5 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)4 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)3 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)3 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3