Search in sources :

Example 26 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class ProjectManager method createOrUpdate.

public ProjectOperationResult createOrUpdate(DSLContext tx, String orgName, ProjectEntry entry) {
    entry = normalize(entry);
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID projectId = entry.getId();
    if (projectId == null) {
        assertName(entry);
        projectId = projectDao.getId(tx, org.getId(), entry.getName());
    }
    if (projectId == null) {
        projectId = insert(tx, org.getId(), org.getName(), entry);
        return ProjectOperationResult.builder().result(OperationResult.CREATED).projectId(projectId).build();
    } else {
        update(tx, projectId, entry);
        return ProjectOperationResult.builder().result(OperationResult.UPDATED).projectId(projectId).build();
    }
}
Also used : UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 27 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class PolicyResource method assertLink.

private PolicyLink assertLink(String policyName, String orgName, String projectName, String userName, String domain, UserType userType) {
    UUID policyId = policyManager.getId(policyName);
    if (policyId == null) {
        throw new ConcordApplicationException("Policy not found: " + policyName, Status.NOT_FOUND);
    }
    UUID orgId = null;
    if (orgName != null) {
        OrganizationEntry org = orgManager.assertAccess(orgName, true);
        orgId = org.getId();
    }
    UUID projectId = null;
    if (projectName != null) {
        if (orgId != null) {
            projectId = assertProject(orgId, projectName);
        } else {
            throw new ConcordApplicationException("Organization name is required", Status.BAD_REQUEST);
        }
    }
    if (projectId != null) {
        // projectId is enough to make a proper reference
        orgId = null;
    }
    UUID userId = null;
    if (userName != null && userType != null) {
        userId = assertUser(userName, domain, userType);
    }
    return new PolicyLink(policyId, orgId, projectId, userId);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 28 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class JsonStoreDataManager method createOrUpdate.

public OperationResult createOrUpdate(String orgName, String storeName, String itemPath, Object data) {
    if (data == null) {
        throw new ValidationErrorsException("JSON Store entries cannot be null.");
    }
    // we expect all entries to be proper JSON objects
    if (!(data instanceof Map)) {
        throw new ValidationErrorsException("All JSON Store entries must be valid JSON objects. Got: " + data.getClass());
    }
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.WRITER, true);
    String jsonData = objectMapper.toString(data);
    policyManager.checkEntity(org.getId(), null, EntityType.JSON_STORE_ITEM, EntityAction.UPDATE, null, PolicyUtils.jsonStoreItemToMap(org, store, itemPath, jsonData));
    Long currentItemSize = storeDataDao.getItemSize(store.id(), itemPath);
    assertStorageDataPolicy(org.getId(), store.id(), currentItemSize == null ? 0 : currentItemSize, jsonData);
    storeDataDao.upsert(store.id(), itemPath, jsonData);
    addAuditLog(currentItemSize != null ? AuditAction.UPDATE : AuditAction.CREATE, org.getId(), store.id(), itemPath);
    return currentItemSize != null ? OperationResult.UPDATED : OperationResult.CREATED;
}
Also used : ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) Map(java.util.Map) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 29 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class JsonStoreDataManager method delete.

public boolean delete(String orgName, String storeName, String itemPath) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.WRITER, true);
    boolean deleted = storeDataDao.delete(store.id(), itemPath);
    if (deleted) {
        addAuditLog(AuditAction.DELETE, org.getId(), store.id(), itemPath);
    }
    return deleted;
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 30 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class JsonStoreDataManager method getItem.

public Object getItem(String orgName, String storeName, String itemPath) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    return storeDataDao.get(store.id(), itemPath);
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Aggregations

OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)36 ApiOperation (io.swagger.annotations.ApiOperation)12 UUID (java.util.UUID)12 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)8 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)5 JsonStoreEntry (com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry)5 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)5 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)3 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)3 Validate (org.sonatype.siesta.Validate)3 Map (java.util.Map)2 OperationResult (com.walmartlabs.concord.server.OperationResult)1 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 MetadataFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter)1 InvalidRepositoryPathException (com.walmartlabs.concord.server.repository.InvalidRepositoryPathException)1 UserEntry (com.walmartlabs.concord.server.user.UserEntry)1