Search in sources :

Example 31 with OrganizationEntry

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

the class JsonStoreQueryManager method createOrUpdate.

public OperationResult createOrUpdate(String orgName, String storeName, JsonStoreQueryRequest entry) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    UUID queryId = entry.id();
    String queryName = entry.name();
    String text = entry.text();
    validateQuery(text);
    if (queryId == null && queryName != null) {
        queryId = queryDao.getId(store.id(), queryName);
    }
    if (queryId == null) {
        policyManager.checkEntity(org.getId(), null, EntityType.JSON_STORE_QUERY, EntityAction.CREATE, null, PolicyUtils.jsonStoreQueryToMap(org, store, queryName, text));
        queryDao.insert(store.id(), queryName, text);
        addAuditLog(AuditAction.CREATE, org.getId(), store.id(), queryName, null, text);
        return OperationResult.CREATED;
    } else {
        policyManager.checkEntity(org.getId(), null, EntityType.JSON_STORE_QUERY, EntityAction.UPDATE, null, PolicyUtils.jsonStoreQueryToMap(org, store, queryName, text));
        JsonStoreQueryEntry prevEntry = queryDao.get(queryId);
        String prevText = prevEntry.text();
        if (Objects.equals(text, prevText)) {
            // no changes
            return OperationResult.ALREADY_EXISTS;
        }
        queryDao.update(queryId, text);
        addAuditLog(AuditAction.UPDATE, org.getId(), store.id(), queryName, prevEntry.text(), text);
        return OperationResult.UPDATED;
    }
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 32 with OrganizationEntry

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

the class JsonStoreQueryManager method exec.

public List<Object> exec(String orgName, String storeName, String queryName, Map<String, Object> params) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    return execDao.exec(store.id(), queryName, params);
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 33 with OrganizationEntry

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

the class JsonStoreQueryManager method exec.

public List<Object> exec(String orgName, String storeName, String text, int maxLimit) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    return execDao.execSql(store.id(), text, null, maxLimit);
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 34 with OrganizationEntry

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

the class JsonStoreQueryManager method list.

public List<JsonStoreQueryEntry> list(String orgName, String storeName, int offset, int limit, String filter) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    return queryDao.list(store.id(), offset, limit, filter);
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 35 with OrganizationEntry

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

the class JsonStoreQueryManager method delete.

public void delete(String orgName, String storeName, String queryName) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry store = jsonStoreAccessManager.assertAccess(org.getId(), null, storeName, ResourceAccessLevel.READER, true);
    UUID id = queryDao.getId(store.id(), queryName);
    if (id == null) {
        throw new ValidationErrorsException("Query not found: " + queryName);
    }
    queryDao.delete(store.id(), queryName);
    addAuditLog(AuditAction.DELETE, org.getId(), store.id(), queryName);
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

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