Search in sources :

Example 16 with Project

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

the class ProjectController method createReleases.

@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = PROJECTS_URL + "/{id}/releases", method = RequestMethod.POST)
public ResponseEntity createReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication, @RequestBody List<String> releaseURIs) throws URISyntaxException, TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    Project project = projectService.getProjectForUserById(id, sw360User);
    Map<String, ProjectReleaseRelationship> releaseIdToUsage = new HashMap<>();
    for (String releaseURIString : releaseURIs) {
        URI releaseURI = new URI(releaseURIString);
        String path = releaseURI.getPath();
        String releaseId = path.substring(path.lastIndexOf('/') + 1);
        releaseIdToUsage.put(releaseId, new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE));
    }
    project.setReleaseIdToUsage(releaseIdToUsage);
    projectService.updateProject(project, sw360User);
    return new ResponseEntity<>(HttpStatus.CREATED);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 18 with Project

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

the class RestControllerHelper method addEmbeddedProject.

private void addEmbeddedProject(HalResource halResource, Project project) {
    Project embeddedProject = convertToEmbeddedProject(project);
    HalResource<Project> halProject = new HalResource<>(embeddedProject);
    Link projectLink = linkTo(ProjectController.class).slash("api" + ProjectController.PROJECTS_URL + "/" + project.getId()).withSelfRel();
    halProject.add(projectLink);
    halResource.addEmbeddedResource("sw360:projects", halProject);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Link(org.springframework.hateoas.Link)

Example 19 with Project

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

the class ProjectResourceProcessor method process.

@Override
public Resource<Project> process(Resource<Project> resource) {
    Project project = resource.getContent();
    Link selfLink = linkTo(ProjectController.class).slash("api" + ProjectController.PROJECTS_URL + "/" + project.getId()).withSelfRel();
    resource.add(selfLink);
    return resource;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Link(org.springframework.hateoas.Link)

Example 20 with Project

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

the class Sw360ProjectService method deleteProject.

public RequestStatus deleteProject(Project project, User sw360User) throws TException {
    ProjectService.Iface sw360ProjectClient = getThriftProjectClient();
    RequestStatus requestStatus = sw360ProjectClient.deleteProject(project.getId(), sw360User);
    if (requestStatus != RequestStatus.SUCCESS) {
        throw new RuntimeException("sw360 project with name '" + project.getName() + " cannot be deleted.");
    }
    return requestStatus;
}
Also used : ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) AddDocumentRequestStatus(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

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