Skip to content

Commit

Permalink
nullable project, repo, ord for user cards
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Nov 13, 2023
1 parent 5a0c415 commit e722448
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ public interface ProcessCardEntry extends Serializable {
UUID id();

@ConcordKey
@Nullable
String orgName();

@ConcordKey
@Nullable
String projectName();

@ConcordKey
@Nullable
String repoName();

@Size(max = 256)
@Nullable
String entryPoint();

@Size(max = 128)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package com.walmartlabs.concord.server.console;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =====
*/

import com.walmartlabs.concord.common.IOUtils;
import com.walmartlabs.concord.common.validation.ConcordKey;
import com.walmartlabs.concord.db.AbstractDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ private static <T> Optional<T> getInputStream(DSLContext tx, String sql, UUID ca

public List<ProcessCardEntry> listCards(DSLContext tx, UUID userId) {
// TODO: V_USER_TEAMS
SelectConditionStep<Record1<UUID>> userTeams = tx.select(USER_TEAMS.TEAM_ID)
.from(USER_TEAMS)
.where(USER_TEAMS.USER_ID.eq(userId));
SelectConditionStep<Record1<UUID>> userTeams = tx.select(V_USER_TEAMS.TEAM_ID)
.from(V_USER_TEAMS)
.where(V_USER_TEAMS.USER_ID.eq(userId));

SelectConditionStep<Record1<UUID>> byUserFilter = tx.select(USER_UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.from(USER_UI_PROCESS_CARDS)
Expand All @@ -239,12 +239,18 @@ public List<ProcessCardEntry> listCards(DSLContext tx, UUID userId) {
.from(TEAM_UI_PROCESS_CARDS)
.where(TEAM_UI_PROCESS_CARDS.TEAM_ID.in(userTeams));

SelectOrderByStep<Record1<UUID>> userCards = byUserFilter.unionAll(byTeamFilter);

SelectJoinStep<Record1<UUID>> userCardsFilter = tx.select(userCards.field(TEAM_UI_PROCESS_CARDS.UI_PROCESS_CARD_ID))
.from(userCards);

SelectConditionStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean>> query =
buildSelect(tx)
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.in(byUserFilter)
.or(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.in(byTeamFilter)));
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.in(userCardsFilter));

return query.fetch(this::toEntry);
return query
.orderBy(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.fetch(this::toEntry);
}

private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean>> buildSelect(DSLContext tx) {
Expand All @@ -265,9 +271,9 @@ private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String,
UI_PROCESS_CARDS.ICON,
isCustomForm.as("isCustomForm"))
.from(UI_PROCESS_CARDS)
.join(REPOSITORIES, JoinType.JOIN).on(REPOSITORIES.REPO_ID.eq(UI_PROCESS_CARDS.REPO_ID))
.join(PROJECTS, JoinType.JOIN).on(PROJECTS.PROJECT_ID.eq(UI_PROCESS_CARDS.PROJECT_ID))
.join(ORGANIZATIONS, JoinType.JOIN).on(ORGANIZATIONS.ORG_ID.eq(PROJECTS.ORG_ID));
.leftJoin(REPOSITORIES).on(REPOSITORIES.REPO_ID.eq(UI_PROCESS_CARDS.REPO_ID))
.leftJoin(PROJECTS).on(PROJECTS.PROJECT_ID.eq(UI_PROCESS_CARDS.PROJECT_ID))
.leftJoin(ORGANIZATIONS).on(ORGANIZATIONS.ORG_ID.eq(PROJECTS.ORG_ID));
}

private ProcessCardEntry toEntry(Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean> r) {
Expand Down

0 comments on commit e722448

Please sign in to comment.