Search in sources :

Example 1 with User

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

the class AttachmentRepository method vacuumAttachmentDB.

public RequestSummary vacuumAttachmentDB(User user, final Set<String> usedIds) {
    final RequestSummary requestSummary = new RequestSummary();
    if (!PermissionUtils.isAdmin(user))
        return requestSummary.setRequestStatus(RequestStatus.FAILURE);
    final List<AttachmentContent> allAttachmentContents = getAll();
    final Set<AttachmentContent> unusedAttachmentContents = allAttachmentContents.stream().filter(input -> !usedIds.contains(input.getId())).collect(Collectors.toSet());
    requestSummary.setTotalElements(allAttachmentContents.size());
    requestSummary.setTotalAffectedElements(unusedAttachmentContents.size());
    final List<DocumentOperationResult> documentOperationResults = deleteBulk(unusedAttachmentContents);
    if (documentOperationResults.isEmpty()) {
        requestSummary.setRequestStatus(RequestStatus.SUCCESS);
    } else {
        requestSummary.setRequestStatus(RequestStatus.FAILURE);
    }
    return requestSummary;
}
Also used : DatabaseRepository(org.eclipse.sw360.datahandler.couchdb.DatabaseRepository) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) ViewQuery(org.ektorp.ViewQuery) DocumentOperationResult(org.ektorp.DocumentOperationResult) Set(java.util.Set) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) Collectors(java.util.stream.Collectors) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Views(org.ektorp.support.Views) List(java.util.List) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) View(org.ektorp.support.View) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) DocumentOperationResult(org.ektorp.DocumentOperationResult)

Example 2 with User

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

the class AttachmentHandlerTest method testVacuum_AllIdsUsedIsNoop.

@Test
public void testVacuum_AllIdsUsedIsNoop() throws Exception {
    final RequestSummary requestSummary = handler.vacuumAttachmentDB(new User("a", "a", "a").setUserGroup(UserGroup.ADMIN), ImmutableSet.of("A1", "A2"));
    assertThat(requestSummary.requestStatus, is(RequestStatus.SUCCESS));
    assertThat(requestSummary.totalElements, is(2));
    assertThat(requestSummary.totalAffectedElements, is(0));
    final AttachmentContent a1 = handler.getAttachmentContent("A1");
    assertNotNull(a1);
    final AttachmentContent a2 = handler.getAttachmentContent("A2");
    assertNotNull(a2);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 3 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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 4 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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 5 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11