Search in sources :

Example 1 with MetadataFilter

use of com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter in project concord by walmartlabs.

the class ProcessResourceV2 method createProcessFilter.

private ProcessFilter createProcessFilter(UUID orgId, String orgName, UUID projectId, String projectName, UUID repoId, String repoName, OffsetDateTimeParam afterCreatedAt, OffsetDateTimeParam beforeCreatedAt, Set<String> tags, ProcessStatus processStatus, String initiator, UUID parentId, Set<ProcessDataInclude> processData, Integer limit, Integer offset, UriInfo uriInfo) {
    UUID effectiveOrgId = orgId;
    Set<UUID> orgIds = null;
    if (orgId != null) {
        // we got an org ID, use it as it is
        orgIds = Collections.singleton(effectiveOrgId);
    } else if (orgName != null) {
        // we got an org name, validate it first by resolving its ID
        OrganizationEntry org = orgManager.assertExisting(null, orgName);
        effectiveOrgId = org.getId();
        orgIds = Collections.singleton(effectiveOrgId);
    } else {
        // we got a query that is not limited to any specific org
        // let's check if we can return all processes from all orgs or if we should limit it to the user's orgs
        boolean canSeeAllOrgs = Roles.isAdmin() || Permission.isPermitted(Permission.GET_PROCESS_QUEUE_ALL_ORGS);
        if (!canSeeAllOrgs) {
            // non-admin users can only see their org's processes or processes w/o projects
            orgIds = getCurrentUserOrgIds();
        }
    }
    UUID effectiveProjectId = projectId;
    if (effectiveProjectId == null && projectName != null) {
        if (effectiveOrgId == null) {
            throw new ValidationErrorsException("Organization name or ID is required");
        }
        effectiveProjectId = projectDao.getId(effectiveOrgId, projectName);
        if (effectiveProjectId == null) {
            throw new ConcordApplicationException("Project not found: " + projectName, Response.Status.NOT_FOUND);
        }
    }
    if (effectiveProjectId != null) {
        projectAccessManager.assertAccess(effectiveProjectId, effectiveProjectId, null, ResourceAccessLevel.READER, false);
    } else if (effectiveOrgId != null) {
        orgManager.assertAccess(effectiveOrgId, null, false);
    } else {
    // we don't have to do the permissions check when neither the org or the project are specified
    // it is done implicitly by calling getCurrentUserOrgIds for all non-admin users (see above)
    }
    UUID effectiveRepoId = repoId;
    if (effectiveRepoId == null && repoName != null && effectiveProjectId != null) {
        effectiveRepoId = repositoryDao.getId(effectiveProjectId, repoName);
    }
    // collect all metadata filters, we assume that they have "meta." prefix in their query parameter names
    List<MetadataFilter> metaFilters = MetadataUtils.parseMetadataFilters(uriInfo);
    // can't allow seq scans, we don't index PROCESS_QUEUE.META (yet?)
    if (!metaFilters.isEmpty() && effectiveProjectId == null) {
        throw new ValidationErrorsException("Process metadata filters require a project name or an ID to be included in the query.");
    }
    return ProcessFilter.builder().parentId(parentId).projectId(effectiveProjectId).orgIds(orgIds).includeWithoutProject(effectiveOrgId == null && effectiveProjectId == null).afterCreatedAt(unwrap(afterCreatedAt)).beforeCreatedAt(unwrap(beforeCreatedAt)).repoId(effectiveRepoId).repoName(repoName).tags(tags).status(processStatus).initiator(initiator).metaFilters(metaFilters).requirements(FilterUtils.parseJson("requirements", uriInfo)).startAt(FilterUtils.parseDate("startAt", uriInfo)).includes(processData != null ? processData : Collections.emptySet()).limit(limit).offset(offset).build();
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) MetadataFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter) UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

Aggregations

OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)1 MetadataFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 UUID (java.util.UUID)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1