Search in sources :

Example 1 with ProjectReleaseRelationship

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);
}
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 2 with ProjectReleaseRelationship

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);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 3 with ProjectReleaseRelationship

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));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Test(org.junit.Test)

Example 4 with ProjectReleaseRelationship

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 5 with ProjectReleaseRelationship

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

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 ProjectReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 URI (java.net.URI)2 Before (org.junit.Before)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TException (org.apache.thrift.TException)1 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 Component (org.eclipse.sw360.datahandler.thrift.components.Component)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1 EccInformation (org.eclipse.sw360.datahandler.thrift.components.EccInformation)1 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)1 ProjectController (org.eclipse.sw360.rest.resourceserver.project.ProjectController)1 Test (org.junit.Test)1