Search in sources :

Example 1 with License

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) License(org.eclipse.sw360.datahandler.thrift.licenses.License) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with License

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) License(org.eclipse.sw360.datahandler.thrift.licenses.License) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with License

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) Resource(org.springframework.hateoas.Resource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) License(org.eclipse.sw360.datahandler.thrift.licenses.License) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) Resources(org.springframework.hateoas.Resources) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 4 with License

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;
}
Also used : License(org.eclipse.sw360.datahandler.thrift.licenses.License)

Example 5 with License

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);
}
Also used : License(org.eclipse.sw360.datahandler.thrift.licenses.License) ArrayList(java.util.ArrayList) Before(org.junit.Before)

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