use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseController method getLicense.
@RequestMapping(value = LICENSES_URL + "/{id:.+}", method = RequestMethod.GET)
public ResponseEntity<Resource<License>> getLicense(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
License sw360License = licenseService.getLicenseById(id);
HalResource<License> licenseHalResource = createHalLicense(sw360License);
return new ResponseEntity<>(licenseHalResource, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseController method createLicense.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = LICENSES_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<License>> createLicense(OAuth2Authentication oAuth2Authentication, @RequestBody License license) throws URISyntaxException, TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
license = licenseService.createLicense(license, sw360User);
HalResource<License> halResource = createHalLicense(license);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(license.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ProjectController method getLicensesOfReleases.
@RequestMapping(value = PROJECTS_URL + "/{id}/licenses", method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<License>>> getLicensesOfReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Project project = projectService.getProjectForUserById(id, sw360User);
final List<Resource<License>> licenseResources = new ArrayList<>();
final Set<String> allLicenseIds = new HashSet<>();
final Set<String> releaseIdToUsage = project.getReleaseIdToUsage().keySet();
for (final String releaseId : releaseIdToUsage) {
final Release sw360Release = releaseService.getReleaseForUserById(releaseId, sw360User);
final Set<String> licenseIds = sw360Release.getMainLicenseIds();
if (licenseIds != null && !licenseIds.isEmpty()) {
allLicenseIds.addAll(licenseIds);
}
}
for (final String licenseId : allLicenseIds) {
final License sw360License = licenseService.getLicenseById(licenseId);
final License embeddedLicense = restControllerHelper.convertToEmbeddedLicense(sw360License);
final Resource<License> licenseResource = new Resource<>(embeddedLicense);
licenseResources.add(licenseResource);
}
final 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 RestControllerHelper method convertToEmbeddedLicense.
public License convertToEmbeddedLicense(License license) {
License embeddedLicense = new License();
embeddedLicense.setId(license.getId());
embeddedLicense.setFullname(license.getFullname());
embeddedLicense.setType(null);
return embeddedLicense;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseSpecTest method before.
@Before
public void before() throws TException {
license = new License();
license.setId("apache20");
license.setFullname("Apache License 2.0");
license.setShortname("Apache 2.0");
license.setText("placeholder for the Apache 2.0 license text");
License license2 = new License();
license2.setId("mit");
license2.setFullname("The MIT License (MIT)");
license2.setShortname("MIT");
license2.setText("placeholder for the MIT license text");
List<License> licenseList = new ArrayList<>();
licenseList.add(license);
licenseList.add(license2);
given(this.licenseServiceMock.getLicenses()).willReturn(licenseList);
given(this.licenseServiceMock.getLicenseById(eq(license.getId()))).willReturn(license);
}
Aggregations