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"));
}
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);
}
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;
}
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;
}
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;
}
Aggregations