Search in sources :

Example 71 with Project

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

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

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

the class ProjectDatabaseHandlerTest method testSanityCheckFails.

@Test
public void testSanityCheckFails() throws Exception {
    Project project = handler.getProjectById("P1", user1);
    project.setReleaseIdToUsage(Collections.emptyMap());
    RequestStatus status = handler.updateProject(project, user1);
    assertThat(status, is(RequestStatus.FAILED_SANITY_CHECK));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Test(org.junit.Test)

Example 74 with Project

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

the class ProjectDatabaseHandlerTest method testGetLinkedProjects.

@Test
public void testGetLinkedProjects() throws Exception {
    // we wrap the potentially infinite loop in an executor
    final ExecutorService service = Executors.newSingleThreadExecutor();
    Project project = handler.getProjectById("P1", user);
    final Future<List<ProjectLink>> completionFuture = service.submit(() -> handler.getLinkedProjects(project, true, user));
    service.shutdown();
    service.awaitTermination(10, TimeUnit.SECONDS);
    final List<ProjectLink> linkedProjects = completionFuture.get();
    ReleaseLink releaseLinkR1A = new ReleaseLink("R1A", "vendor", "component1", "releaseA", "vendor component1 releaseA", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R1A").setComponentType(ComponentType.OSS);
    ReleaseLink releaseLinkR1B = new ReleaseLink("R1B", "vendor", "component1", "releaseB", "vendor component1 releaseB", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R1B").setComponentType(ComponentType.OSS);
    ReleaseLink releaseLinkR2A = new ReleaseLink("R2A", "vendor", "component2", "releaseA", "vendor component2 releaseA", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R2A").setComponentType(ComponentType.COTS);
    ReleaseLink releaseLinkR2B = new ReleaseLink("R2B", "vendor", "component2", "releaseB", "vendor component2 releaseB", false).setReleaseRelationship(ReleaseRelationship.REFERRED).setMainlineState(MainlineState.MAINLINE).setNodeId("R2B").setComponentType(ComponentType.COTS);
    ProjectLink link3 = new ProjectLink("P3", "project3").setRelation(ProjectRelationship.REFERRED).setNodeId("P3").setParentNodeId("P2").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(2).setLinkedReleases(Arrays.asList(releaseLinkR2A, releaseLinkR2B)).setSubprojects(Collections.emptyList());
    ProjectLink link4 = new ProjectLink("P4", "project4").setRelation(ProjectRelationship.CONTAINED).setNodeId("P4").setParentNodeId("P2").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(2).setSubprojects(Collections.emptyList());
    ProjectLink link2 = new ProjectLink("P2", "project2").setRelation(ProjectRelationship.CONTAINED).setNodeId("P2").setParentNodeId("P1").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(1).setLinkedReleases(Arrays.asList(releaseLinkR1A, releaseLinkR1B)).setSubprojects(Arrays.asList(link3, link4));
    ProjectLink link1 = new ProjectLink("P1", "project1").setRelation(ProjectRelationship.UNKNOWN).setNodeId("P1").setProjectType(ProjectType.CUSTOMER).setState(ProjectState.ACTIVE).setTreeLevel(0).setSubprojects(Arrays.asList(link2));
    stripRandomPartsOfNodeIds(linkedProjects);
    assertThat(linkedProjects, contains(link1));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink) Test(org.junit.Test)

Example 75 with Project

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

the class ProjectDatabaseHandler method getProjectById.

// //////////////////////////
// GET INDIVIDUAL OBJECTS //
// //////////////////////////
public Project getProjectById(String id, User user) throws SW360Exception {
    Project project = repository.get(id);
    assertNotNull(project);
    if (!makePermission(project, user).isActionAllowed(RequestedAction.READ)) {
        throw fail("User " + user + " is not allowed to view the requested project " + project + "!");
    }
    return project;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

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