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