use of com.walmartlabs.concord.server.jooq.tables.JsonStores in project concord by walmartlabs.
the class JsonStoreDao method list.
public List<JsonStoreEntry> list(UUID orgId, UUID currentUserId, int offset, int limit, String filter) {
Organizations o = ORGANIZATIONS.as("o");
JsonStores j = JSON_STORES.as("j");
Users u = USERS.as("u");
SelectJoinStep<Record10<UUID, String, UUID, String, String, UUID, String, String, String, String>> q = buildSelect(dsl(), o, j, u);
if (currentUserId != null) {
// public stores are visible for anyone
Condition isPublic = j.VISIBILITY.eq(JsonStoreVisibility.PUBLIC.toString());
// check if the user belongs to a team in the org
SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId));
Condition isInATeam = exists(selectOne().from(Tables.V_USER_TEAMS).where(Tables.V_USER_TEAMS.USER_ID.eq(currentUserId).and(Tables.V_USER_TEAMS.TEAM_ID.in(teamIds))));
// check if the user owns stores in the org
Condition ownsStores = j.OWNER_ID.eq(currentUserId);
// check if the user owns the org
Condition ownsOrg = o.OWNER_ID.eq(currentUserId);
// if any of those conditions true then the store must be visible
q.where(or(isPublic, isInATeam, ownsStores, ownsOrg));
}
if (filter != null) {
q.where(j.JSON_STORE_NAME.containsIgnoreCase(filter));
}
if (offset >= 0) {
q.offset(offset);
}
if (limit > 0) {
q.limit(limit);
}
return q.where(j.ORG_ID.eq(orgId)).orderBy(j.JSON_STORE_NAME).fetch(JsonStoreDao::toEntity);
}
use of com.walmartlabs.concord.server.jooq.tables.JsonStores in project concord by walmartlabs.
the class InventoryDataDao method get.
private List<InventoryDataItem> get(DSLContext tx, UUID inventoryId, String path) {
Table<Record> nodes = table("nodes");
JsonStores i1 = JSON_STORES.as("i1");
JsonStores i2 = JSON_STORES.as("i2");
SelectConditionStep<Record3<UUID, UUID, Integer>> s1 = select(i1.JSON_STORE_ID, i1.PARENT_INVENTORY_ID, value(1)).from(i1).where(i1.JSON_STORE_ID.eq(inventoryId));
Field<Integer> levelField = field("level", Integer.class);
SelectConditionStep<Record3<UUID, UUID, Integer>> s2 = select(i2.JSON_STORE_ID, i2.PARENT_INVENTORY_ID, levelField.add(1)).from(i2, nodes).where(i2.JSON_STORE_ID.eq(JSON_STORES.as("nodes").PARENT_INVENTORY_ID));
SelectConditionStep<Record3<String, JSONB, Integer>> s = tx.withRecursive("nodes", JSON_STORES.JSON_STORE_ID.getName(), JSON_STORES.PARENT_INVENTORY_ID.getName(), levelField.getName()).as(s1.unionAll(s2)).select(JSON_STORE_DATA.ITEM_PATH, JSON_STORE_DATA.ITEM_DATA, levelField.add(1)).from(JSON_STORE_DATA, nodes).where(JSON_STORE_DATA.JSON_STORE_ID.eq(JSON_STORES.as("nodes").JSON_STORE_ID).and(JSON_STORE_DATA.ITEM_PATH.startsWith(path)));
return s.fetch(this::toEntry);
}
Aggregations