@Override public List<Account> getAccessibleProjects( Set<Identity> identities, boolean isAdmin, Long usingAccount) { List<Account> projects = new ArrayList<>(); if (identities == null) { return projects; } if (isAdmin) { projects.addAll( create() .selectFrom(ACCOUNT) .where(ACCOUNT.KIND.eq(ProjectConstants.TYPE).and(ACCOUNT.REMOVED.isNull())) .orderBy(ACCOUNT.ID.asc()) .fetch()); return projects; } if (usingAccount != null) { Account project = getAccountById(usingAccount); if (project != null && project.getKind().equalsIgnoreCase(ProjectConstants.TYPE)) { projects.add(project); return projects; } } // DSL.falseCondition is created so that we can dynamically build a or // Condition without caring what the external Ids are and still make one // Database call. Condition allMembers = DSL.falseCondition(); for (Identity id : identities) { allMembers = allMembers.or( PROJECT_MEMBER .EXTERNAL_ID .eq(id.getExternalId()) .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(id.getExternalIdType())) .and(PROJECT_MEMBER.REMOVED.isNull()) .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE))); } SelectQuery<Record> query = create().selectQuery(); query.addFrom(ACCOUNT); query.addJoin(PROJECT_MEMBER, PROJECT_MEMBER.PROJECT_ID.equal(ACCOUNT.ID)); query.addConditions(allMembers); query.setDistinct(true); projects.addAll(query.fetchInto(ACCOUNT)); Map<Long, Account> returnProjects = new HashMap<>(); for (Account project : projects) { returnProjects.put(project.getId(), project); } projects = new ArrayList<>(); projects.addAll(returnProjects.values()); return projects; }
public List<? extends ProjectMember> getProjectMembersByIdentity( long projectId, Set<Identity> identities) { Condition allMembers = DSL.falseCondition(); for (Identity identity : identities) { allMembers = allMembers.or( PROJECT_MEMBER .EXTERNAL_ID .eq(identity.getExternalId()) .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(identity.getExternalIdType())) .and(PROJECT_MEMBER.REMOVED.isNull()) .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE)) .and(PROJECT_MEMBER.PROJECT_ID.eq(projectId))); } SelectQuery<Record> query = create().selectQuery(); query.addFrom(PROJECT_MEMBER); query.addConditions(allMembers); query.setDistinct(true); return query.fetchInto(PROJECT_MEMBER); }