use of org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship 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.ProjectReleaseRelationship in project sw360portal by sw360.
the class ProjectPortlet method serveReleasesFromLinkedProjects.
private void serveReleasesFromLinkedProjects(ResourceRequest request, ResourceResponse response, String projectId) throws IOException, PortletException {
List<Release> searchResult;
Set<String> releaseIdsFromLinkedProjects = new HashSet<>();
User user = UserCacheHolder.getUserFromRequest(request);
try {
ComponentService.Iface componentClient = thriftClients.makeComponentClient();
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Project project = projectClient.getProjectById(projectId, user);
Map<String, ProjectRelationship> linkedProjects = CommonUtils.nullToEmptyMap(project.getLinkedProjects());
for (String linkedProjectId : linkedProjects.keySet()) {
Project linkedProject = projectClient.getProjectById(linkedProjectId, user);
if (linkedProject != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = CommonUtils.nullToEmptyMap(linkedProject.getReleaseIdToUsage());
releaseIdsFromLinkedProjects.addAll(releaseIdToUsage.keySet());
}
}
if (releaseIdsFromLinkedProjects.size() > 0) {
searchResult = componentClient.getReleasesById(releaseIdsFromLinkedProjects, user);
} else {
searchResult = Collections.emptyList();
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.RELEASE_SEARCH, searchResult);
include("/html/utils/ajax/searchReleasesAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method testSanityCheckSucceeds.
@Test
public void testSanityCheckSucceeds() throws Exception {
Project project = handler.getProjectById("P1", user1);
project.setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
RequestStatus status = handler.updateProject(project, user1);
assertThat(status, is(RequestStatus.SUCCESS));
Project project2 = handler.getProjectById("P2", user1);
project2.setReleaseIdToUsage(Collections.emptyMap());
RequestStatus status2 = handler.updateProject(project2, user1);
assertThat(status2, is(RequestStatus.SUCCESS));
}
use of org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method setUp.
@Before
public void setUp() throws Exception {
assertTestString(dbName);
assertTestString(attachmentsDbName);
List<Project> projects = new ArrayList<>();
Project p1 = new Project().setId("P1").setName("Project1").setBusinessUnit("AB CD EF").setCreatedBy("user1").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r4", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r5", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r6", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
projects.add(p1);
Project p2 = new Project().setId("P2").setName("Project2").setBusinessUnit("AB CD FE").setCreatedBy("user2").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
projects.add(p2);
projects.get(1).addToContributors("user1");
projects.add(new Project().setId("P3").setName("Project3").setBusinessUnit("AB CD EF").setCreatedBy("user3"));
Project p4 = new Project().setId("P4").setName("Project4").setBusinessUnit("AB CD EF").setCreatedBy("user1").setVisbility(Visibility.PRIVATE).setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build()).setLinkedProjects(ImmutableMap.<String, ProjectRelationship>builder().put("P5", ProjectRelationship.CONTAINED).build());
projects.add(p4);
projects.add(new Project().setId("P5").setName("Project5").setBusinessUnit("AB CD EF").setCreatedBy("user1"));
List<Release> releases = new ArrayList<>();
releases.add(new Release().setId("r1").setComponentId("c1"));
releases.add(new Release().setId("r2").setComponentId("c1"));
releases.add(new Release().setId("r3").setComponentId("c1"));
releases.add(new Release().setId("r4").setComponentId("c1"));
releases.add(new Release().setId("r5").setComponentId("c1"));
releases.add(new Release().setId("r6").setComponentId("c1"));
// Create the database
TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
for (Project project : projects) {
databaseConnector.add(project);
}
for (Release r : releases) {
databaseConnector.add(r);
}
databaseConnector.add(new Component("comp1").setId("c1"));
componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, componentHandler);
}
use of org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship in project sw360portal by sw360.
the class ProjectController method createProject.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = PROJECTS_URL, method = RequestMethod.POST)
public ResponseEntity createProject(OAuth2Authentication oAuth2Authentication, @RequestBody Project project) throws URISyntaxException, TException {
if (project.getReleaseIdToUsage() != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = new HashMap<>();
Map<String, ProjectReleaseRelationship> oriReleaseIdToUsage = project.getReleaseIdToUsage();
for (String releaseURIString : oriReleaseIdToUsage.keySet()) {
URI releaseURI = new URI(releaseURIString);
String path = releaseURI.getPath();
String releaseId = path.substring(path.lastIndexOf('/') + 1);
releaseIdToUsage.put(releaseId, oriReleaseIdToUsage.get(releaseURIString));
}
project.setReleaseIdToUsage(releaseIdToUsage);
}
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
project = projectService.createProject(project, sw360User);
HalResource<Project> halResource = createHalProject(project, sw360User);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(project.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
Aggregations