Search in sources :

Example 6 with ProjectReleaseRelationship

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

the class ProjectSpecTest method before.

@Before
public void before() throws TException {
    Map<String, ProjectReleaseRelationship> linkedReleases = new HashMap<>();
    Map<String, ProjectRelationship> linkedProjects = new HashMap<>();
    ProjectReleaseRelationship projectReleaseRelationship = new ProjectReleaseRelationship(CONTAINED, MAINLINE);
    List<Project> projectList = new ArrayList<>();
    List<Project> projectListByName = new ArrayList<>();
    project = new Project();
    project.setId("376576");
    project.setName("Emerald Web");
    project.setProjectType(ProjectType.PRODUCT);
    project.setVersion("1.0.2");
    project.setDescription("Emerald Web provides a suite of components for Critical Infrastructures.");
    project.setCreatedOn("2016-12-15");
    project.setCreatedBy("admin@sw360.org");
    project.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    project.setBusinessUnit("sw360 AR");
    project.setExternalIds(Collections.singletonMap("mainline-id-project", "515432"));
    project.setOwnerAccountingUnit("4822");
    project.setOwnerCountry("DE");
    project.setOwnerGroup("AA BB 123 GHV2-DE");
    project.setTag("project test tag 1");
    project.setPreevaluationDeadline("2018-07-17");
    project.setSystemTestStart("2017-01-01");
    project.setSystemTestEnd("2018-03-01");
    linkedReleases.put("3765276512", projectReleaseRelationship);
    project.setReleaseIdToUsage(linkedReleases);
    linkedProjects.put("376576", ProjectRelationship.CONTAINED);
    project.setLinkedProjects(linkedProjects);
    projectList.add(project);
    projectListByName.add(project);
    Project project2 = new Project();
    project2.setId("376570");
    project2.setName("Orange Web");
    project2.setVersion("2.0.1");
    project2.setProjectType(ProjectType.PRODUCT);
    project2.setDescription("Orange Web provides a suite of components for documentation.");
    project2.setCreatedOn("2016-12-17");
    project2.setCreatedBy("john@sw360.org");
    project2.setBusinessUnit("sw360 EX DF");
    project2.setOwnerAccountingUnit("5661");
    project2.setOwnerCountry("FR");
    project2.setOwnerGroup("SIM-KA12");
    project2.setTag("project test tag 2");
    project2.setPreevaluationDeadline("2018-07-17");
    project2.setSystemTestStart("2017-01-01");
    project2.setSystemTestEnd("2018-03-01");
    project2.setExternalIds(Collections.singletonMap("mainline-id-project", "7657"));
    linkedReleases = new HashMap<>();
    linkedReleases.put("5578999", projectReleaseRelationship);
    project2.setReleaseIdToUsage(linkedReleases);
    projectList.add(project2);
    Set<String> releaseIds = new HashSet<>(Arrays.asList("3765276512"));
    Set<String> releaseIdsTransitive = new HashSet<>(Arrays.asList("3765276512", "5578999"));
    given(this.projectServiceMock.getProjectsForUser(anyObject())).willReturn(projectList);
    given(this.projectServiceMock.getProjectForUserById(eq(project.getId()), anyObject())).willReturn(project);
    given(this.projectServiceMock.searchProjectByName(eq(project.getName()), anyObject())).willReturn(projectListByName);
    given(this.projectServiceMock.getReleaseIds(eq(project.getId()), anyObject(), eq("false"))).willReturn(releaseIds);
    given(this.projectServiceMock.getReleaseIds(eq(project.getId()), anyObject(), eq("true"))).willReturn(releaseIdsTransitive);
    Release release = new Release();
    release.setId("3765276512");
    release.setName("Angular 2.3.0");
    release.setCpeid("cpe:/a:Google:Angular:2.3.0:");
    release.setReleaseDate("2016-12-07");
    release.setVersion("2.3.0");
    release.setCreatedOn("2016-12-18");
    EccInformation eccInformation = new EccInformation();
    eccInformation.setEccStatus(ECCStatus.APPROVED);
    release.setEccInformation(eccInformation);
    release.setCreatedBy("admin@sw360.org");
    release.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    release.setComponentId("12356115");
    release.setClearingState(ClearingState.APPROVED);
    release.setExternalIds(Collections.singletonMap("mainline-id-component", "1432"));
    Release release2 = new Release();
    release2.setId("5578999");
    release2.setName("Spring 1.4.0");
    release2.setCpeid("cpe:/a:Spring:1.4.0:");
    release2.setReleaseDate("2017-05-06");
    release2.setVersion("1.4.0");
    release2.setCreatedOn("2017-11-19");
    eccInformation.setEccStatus(ECCStatus.APPROVED);
    release2.setEccInformation(eccInformation);
    release2.setCreatedBy("admin@sw360.org");
    release2.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
    release2.setComponentId("12356115");
    release2.setClearingState(ClearingState.APPROVED);
    release2.setExternalIds(Collections.singletonMap("mainline-id-component", "1771"));
    given(this.releaseServiceMock.getReleaseForUserById(eq(release.getId()), anyObject())).willReturn(release);
    given(this.releaseServiceMock.getReleaseForUserById(eq(release2.getId()), anyObject())).willReturn(release2);
    User user = new User();
    user.setId("admin@sw360.org");
    user.setEmail("admin@sw360.org");
    user.setFullname("John Doe");
    user.setDepartment("sw360");
    given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
}
Also used : EccInformation(org.eclipse.sw360.datahandler.thrift.components.EccInformation) User(org.eclipse.sw360.datahandler.thrift.users.User) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 7 with ProjectReleaseRelationship

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

the class JsonReleaseRelationSerializer method serialize.

@Override
public void serialize(Map<String, ProjectReleaseRelationship> releaseRelationMap, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
    List<Map<String, String>> linkedReleases = new ArrayList<>();
    for (Map.Entry<String, ProjectReleaseRelationship> releaseRelation : releaseRelationMap.entrySet()) {
        String releaseLink = linkTo(ProjectController.class).slash("api" + ReleaseController.RELEASES_URL + "/" + releaseRelation.getKey()).withSelfRel().getHref();
        Map<String, String> linkedRelease = new HashMap<>();
        ProjectReleaseRelationship projectReleaseRelationship = releaseRelation.getValue();
        linkedRelease.put("relation", projectReleaseRelationship.getReleaseRelation().name());
        linkedRelease.put("mainlineState", projectReleaseRelationship.getMainlineState().name());
        linkedRelease.put("release", releaseLink);
        linkedReleases.add(linkedRelease);
    }
    gen.writeObject(linkedReleases);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) HashMap(java.util.HashMap) Map(java.util.Map) ProjectController(org.eclipse.sw360.rest.resourceserver.project.ProjectController)

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