Search in sources :

Example 6 with Project

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

the class ProjectDatabaseHandlerTest method testDuplicateProjectIsFound.

@Ignore("One is no longer able to create duplicate projects in the db")
public void testDuplicateProjectIsFound() throws Exception {
    String originalProjectId = "P1";
    final Project tmp = handler.getProjectById(originalProjectId, user1);
    tmp.unsetId();
    tmp.unsetRevision();
    String newProjectId = handler.addProject(tmp, user1).getId();
    final Map<String, List<String>> duplicateProjects = handler.getDuplicateProjects();
    assertThat(duplicateProjects.size(), is(1));
    assertThat(duplicateProjects.get(printName(tmp)), containsInAnyOrder(newProjectId, originalProjectId));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) Ignore(org.junit.Ignore)

Example 7 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);
    vendors = new ArrayList<>();
    vendors.add(new Vendor().setId("V1").setShortname("vendor").setFullname("vendor").setUrl("http://vendor.example.com"));
    releases = new ArrayList<>();
    Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setVendorId("V1");
    releases.add(release1a);
    Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setVendorId("V1");
    releases.add(release1b);
    Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setVendorId("V1");
    releases.add(release2a);
    Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setVendorId("V1");
    releases.add(release2b);
    components = new ArrayList<>();
    Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setComponentType(ComponentType.OSS);
    components.add(component1);
    Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setComponentType(ComponentType.COTS);
    components.add(component2);
    projects = new ArrayList<>();
    Project project1 = new Project().setId("P1").setName("project1").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project1);
    Project project2 = new Project().setId("P2").setName("project2").setLinkedProjects(ImmutableMap.of("P3", ProjectRelationship.REFERRED, "P4", ProjectRelationship.CONTAINED)).setReleaseIdToUsage(ImmutableMap.of("R1A", newDefaultProjectReleaseRelationship(), "R1B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project2);
    Project project3 = new Project().setId("P3").setName("project3").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.UNKNOWN)).setReleaseIdToUsage(ImmutableMap.of("R2A", newDefaultProjectReleaseRelationship(), "R2B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project3);
    Project project4 = new Project().setId("P4").setName("project4").setLinkedProjects(ImmutableMap.of("P1", ProjectRelationship.UNKNOWN)).setVisbility(Visibility.EVERYONE);
    projects.add(project4);
    Project project5 = new Project().setId("P5").setName("project5").setLinkedProjects(ImmutableMap.of("P6", ProjectRelationship.CONTAINED, "P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project5);
    Project project6 = new Project().setId("P6").setName("project6").setLinkedProjects(ImmutableMap.of("P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project6);
    Project project7 = new Project().setId("P7").setName("project7").setVisbility(Visibility.EVERYONE);
    projects.add(project7);
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Vendor vendor : vendors) {
        databaseConnector.add(vendor);
    }
    for (Release release : releases) {
        databaseConnector.add(release);
    }
    for (Component component : components) {
        databaseConnector.add(component);
    }
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    ComponentDatabaseHandler componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
    handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, componentHandler);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) ProjectDatabaseHandler(org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 8 with Project

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

the class ProjectDatabaseHandler method releaseIdToProjects.

private void releaseIdToProjects(Project project, User user, Set<String> visitedProjectIds, Multimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects) throws SW360Exception {
    if (nothingTodo(project, visitedProjectIds))
        return;
    nullToEmptyMap(project.getReleaseIdToUsage()).forEach((releaseId, relation) -> {
        releaseIdToProjects.put(releaseId, new ProjectWithReleaseRelationTuple(project, relation));
    });
    Map<String, ProjectRelationship> linkedProjects = project.getLinkedProjects();
    if (linkedProjects != null) {
        for (String projectId : linkedProjects.keySet()) {
            if (visitedProjectIds.contains(projectId))
                continue;
            Project linkedProject = getProjectById(projectId, user);
            releaseIdToProjects(linkedProject, user, visitedProjectIds, releaseIdToProjects);
        }
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 9 with Project

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

the class ProjectDatabaseHandler method getReleaseIdsOfProjectTree.

private Set<String> getReleaseIdsOfProjectTree(Project project, Set<String> visitedProjectIds, Map<String, Project> allProjectsIdMap, User user, List<RequestedAction> permissionsFilter) {
    // no need to visit a project twice
    if (visitedProjectIds.contains(project.getId())) {
        return Collections.emptySet();
    }
    // we are now checking this project so no need for further examination in
    // recursion
    visitedProjectIds.add(project.getId());
    // container to aggregate results
    Set<String> releaseIds = Sets.newHashSet();
    // "DUPLICATE" and add the result to this result
    if (project.isSetLinkedProjects()) {
        project.getLinkedProjects().entrySet().stream().forEach(e -> {
            if (!ProjectRelationship.REFERRED.equals(e.getValue()) && !ProjectRelationship.DUPLICATE.equals(e.getValue())) {
                Project childProject = allProjectsIdMap.get(e.getKey());
                if (childProject != null) {
                    // so do it now
                    if (permissionsFilter == null || permissionsFilter.isEmpty() || makePermission(childProject, user).areActionsAllowed(permissionsFilter)) {
                        // recursion inside :-)
                        releaseIds.addAll(getReleaseIdsOfProjectTree(childProject, visitedProjectIds, allProjectsIdMap, user, permissionsFilter));
                    }
                }
            }
        });
    }
    // add own releases to result if they are not just "REFERRED"
    if (project.isSetReleaseIdToUsage()) {
        project.getReleaseIdToUsage().entrySet().stream().forEach(e -> {
            if (!ReleaseRelationship.REFERRED.equals(e.getValue().getReleaseRelation())) {
                releaseIds.add(e.getKey());
            }
        });
    }
    return releaseIds;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 10 with Project

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

the class ProjectDatabaseHandler method fillClearingStateSummary.

public List<Project> fillClearingStateSummary(List<Project> projects, User user) {
    Function<Project, Set<String>> extractReleaseIds = project -> CommonUtils.nullToEmptyMap(project.getReleaseIdToUsage()).keySet();
    Set<String> allReleaseIds = projects.stream().map(extractReleaseIds).reduce(Sets.newHashSet(), Sets::union);
    if (!allReleaseIds.isEmpty()) {
        Map<String, Release> releasesById = ThriftUtils.getIdMap(componentDatabaseHandler.getReleasesForClearingStateSummary(allReleaseIds));
        for (Project project : projects) {
            final Set<String> releaseIds = extractReleaseIds.apply(project);
            List<Release> releases = releaseIds.stream().map(releasesById::get).collect(Collectors.toList());
            final ReleaseClearingStateSummary releaseClearingStateSummary = ReleaseClearingStateSummaryComputer.computeReleaseClearingStateSummary(releases, project.getClearingTeam());
            project.setReleaseClearingStateSummary(releaseClearingStateSummary);
        }
    }
    return projects;
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Assert.fail(org.eclipse.sw360.datahandler.common.SW360Assert.fail) MailConstants(org.eclipse.sw360.mail.MailConstants) ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ReleaseClearingStateSummaryComputer(org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Logger(org.apache.log4j.Logger) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) HttpClient(org.ektorp.http.HttpClient) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) MailUtil(org.eclipse.sw360.mail.MailUtil) com.google.common.collect(com.google.common.collect) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) PermissionUtils.makePermission(org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission) MalformedURLException(java.net.MalformedURLException) SummaryType(org.eclipse.sw360.components.summary.SummaryType) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple) VisibleForTesting(com.google.common.annotations.VisibleForTesting) org.eclipse.sw360.datahandler.thrift.components(org.eclipse.sw360.datahandler.thrift.components) SW360Assert.assertNotNull(org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull) 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