Skip to content

Commit

Permalink
fix tests by fixing view
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Feb 17, 2025
1 parent c041b82 commit b9da4c6
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
import java.util.List;

public interface ActionRepository extends DeleteRepository<Action, Long> {
// @Query("select Action from Action a where ")
// TODO rename this
List<Action> getActionsByKeyResultIdOrderByPriorityAsc(Long keyResultId);
List<Action> getActionsByKeyResultIdAndIsDeletedFalseOrderByPriorityAsc(Long keyResultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

public interface CheckInRepository extends DeleteRepository<CheckIn, Long> {
List<CheckIn> findCheckInsByKeyResultIdOrderByCreatedOnDesc(Long keyResultId);
List<CheckIn> findCheckInsByKeyResultIdAndIsDeletedFalseOrderByCreatedOnDesc(Long keyResultId);

CheckIn findFirstByKeyResultIdOrderByCreatedOnDesc(Long keyResultId);
CheckIn findFirstByKeyResultIdAndIsDeletedFalseOrderByCreatedOnDesc(Long keyResultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import java.util.List;

public interface KeyResultRepository extends DeleteRepository<KeyResult, Long> {
List<KeyResult> findByObjectiveId(Long objectiveId);
List<KeyResult> findByObjectiveIdAndIsDeletedFalse(Long objectiveId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Repository
public interface ObjectiveRepository extends DeleteRepository<Objective, Long> {

Integer countByTeamAndQuarter(Team team, Quarter quarter);
Integer countByTeamAndQuarterAndIsDeletedFalse(Team team, Quarter quarter);

List<Objective> findObjectivesByTeamId(Long id);
List<Objective> findObjectivesByTeamIdAndIsDeletedFalse(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface TeamRepository extends DeleteRepository<Team, Long> {

List<Team> findTeamsByName(String name);
List<Team> findTeamsByNameAndIsDeletedFalse(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@Repository
public interface UnitRepository extends DeleteRepository<Unit, Long> {

Optional<Unit> findUnitByUnitName(String name);
Optional<Unit> findUnitByUnitNameAndIsDeletedFalse(String name);

List<Unit> findAllByCreatedById(Long userId);
List<Unit> findAllByCreatedByIdAndIsDeletedFalse(Long userId);

boolean existsUnitByUnitName(String unitName);
boolean existsUnitByUnitNameAndIsDeletedFalse(String unitName);

boolean existsUnitByUnitNameAndIdNot(String unitName, Long id);
boolean existsUnitByUnitNameAndIsDeletedFalseAndIdNot(String unitName, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Optional;

public interface UserRepository extends DeleteRepository<User, Long> {
Optional<User> findByEmail(String email);
Optional<User> findByEmailAndIsDeletedFalse(String email);

List<User> findByOkrChampion(boolean isOkrChampion);
List<User> findByOkrChampionAndIsDeletedFalse(boolean isOkrChampion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public String getModelName() {
}

public List<Action> getActionsByKeyResultIdOrderByPriorityAsc(Long keyResultId) {
return getRepository().getActionsByKeyResultIdOrderByPriorityAsc(keyResultId);
return getRepository().getActionsByKeyResultIdAndIsDeletedFalseOrderByPriorityAsc(keyResultId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public String getModelName() {
}

public List<CheckIn> getCheckInsByKeyResultIdOrderByCheckInDateDesc(Long keyResultId) {
return getRepository().findCheckInsByKeyResultIdOrderByCreatedOnDesc(keyResultId);
return getRepository().findCheckInsByKeyResultIdAndIsDeletedFalseOrderByCreatedOnDesc(keyResultId);
}

public CheckIn getLastCheckInOfKeyResult(Long keyResultId) {
return getRepository().findFirstByKeyResultIdOrderByCreatedOnDesc(keyResultId);
return getRepository().findFirstByKeyResultIdAndIsDeletedFalseOrderByCreatedOnDesc(keyResultId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ public String getModelName() {
}

public List<KeyResult> getKeyResultsByObjective(Long objectiveId) {
return getRepository().findByObjectiveId(objectiveId);
return getRepository().findByObjectiveIdAndIsDeletedFalse(objectiveId);
}

@Transactional
public KeyResult recreateEntity(Long id, KeyResult keyResult) {
// delete entity in order to prevent duplicates in case of changed keyResultType
deleteById(id);
// deleteById(id, new HardDelete<>());

// reset id of key result, so it gets saved as a new entity
keyResult.resetId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String getModelName() {
* @return number of Objectives of team in quarter
*/
public Integer countByTeamAndQuarter(Team team, Quarter quarter) {
return getRepository().countByTeamAndQuarter(team, quarter);
return getRepository().countByTeamAndQuarterAndIsDeletedFalse(team, quarter);
}

public Objective findObjectiveById(Long objectiveId, AuthorizationUser authorizationUser,
Expand All @@ -62,7 +62,7 @@ public Objective findObjectiveById(Long objectiveId, AuthorizationUser authoriza
}

public List<Objective> findObjectiveByTeamId(Long teamId) {
return getRepository().findObjectivesByTeamId(teamId);
return getRepository().findObjectivesByTeamIdAndIsDeletedFalse(teamId);
}

public Objective findObjectiveByKeyResultId(Long keyResultId, AuthorizationUser authorizationUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public String getModelName() {
}

public List<Team> findTeamsByName(String name) {
return getRepository().findTeamsByName(name);
return getRepository().findTeamsByNameAndIsDeletedFalse(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public String getModelName() {

public Unit findUnitByUnitName(String unitName) {
return getRepository()
.findUnitByUnitName(unitName)
.findUnitByUnitNameAndIsDeletedFalse(unitName)
.orElseThrow(() -> new OkrResponseStatusException(HttpStatus.NOT_FOUND,
ErrorKey.MODEL_NOT_FOUND_BY_PROPERTY,
List.of(Constants.UNIT, "unit name", unitName)));
}

public boolean existsUnitByUnitName(String unitName) {
return getRepository().existsUnitByUnitName(unitName);
return getRepository().existsUnitByUnitNameAndIsDeletedFalse(unitName);
}

public boolean existsUnitByUnitNameAndIdNot(String unitName, Long id) {
return getRepository().existsUnitByUnitNameAndIdNot(unitName, id);
return getRepository().existsUnitByUnitNameAndIsDeletedFalseAndIdNot(unitName, id);
}

public List<Unit> findUnitsByUser(Long userId) {
return getRepository().findAllByCreatedById(userId);
return getRepository().findAllByCreatedByIdAndIsDeletedFalse(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public String getModelName() {
}

public synchronized User getOrCreateUser(User user) {
Optional<User> savedUser = getRepository().findByEmail(user.getEmail());
Optional<User> savedUser = getRepository().findByEmailAndIsDeletedFalse(user.getEmail());
return savedUser.orElseGet(() -> getRepository().save(user));
}

public Optional<User> findByEmail(String email) {
return getRepository().findByEmail(email);
return getRepository().findByEmailAndIsDeletedFalse(email);
}

@Override
Expand All @@ -38,7 +38,7 @@ public User save(User user) {
}

public List<User> findAllOkrChampions() {
return getRepository().findByOkrChampion(true);
return getRepository().findByOkrChampionAndIsDeletedFalse(true);
}

public Iterable<User> saveAll(List<User> userList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,39 +183,42 @@ create index if not exists idx_completed_objective

DROP VIEW IF EXISTS OVERVIEW;
CREATE VIEW OVERVIEW AS
SELECT tq.team_id AS "team_id",
tq.team_version AS "team_version",
tq.name AS "team_name",
tq.quater_id AS "quarter_id",
tq.label AS "quarter_label",
coalesce(o.id, -1) AS "objective_id",
o.title AS "objective_title",
o.state AS "objective_state",
o.created_on AS "objective_created_on",
coalesce(kr.id, -1) AS "key_result_id",
kr.title AS "key_result_title",
kr.key_result_type AS "key_result_type",
U.unit_name as "unit",
kr.baseline,
kr.stretch_goal,
kr.commit_zone,
kr.target_zone,
kr.stretch_zone,
coalesce(c.id, -1) AS "check_in_id",
c.value_metric AS "check_in_value",
c.zone AS "check_in_zone",
c.confidence,
c.created_on AS "check_in_created_on"
FROM (select t.id as team_id, t.version as team_version, t.name, q.id as quater_id, q.label
from team t,
quarter q) tq
LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUATER_ID = O.QUARTER_ID
SELECT TQ.TEAM_ID AS "TEAM_ID",
TQ.TEAM_VERSION AS "TEAM_VERSION",
TQ.NAME AS "TEAM_NAME",
TQ.QUARTER_ID AS "QUARTER_ID",
TQ.LABEL AS "QUARTER_LABEL",
COALESCE(O.ID, -1) AS "OBJECTIVE_ID",
O.TITLE AS "OBJECTIVE_TITLE",
O.STATE AS "OBJECTIVE_STATE",
O.CREATED_ON AS "OBJECTIVE_CREATED_ON",
COALESCE(KR.ID, -1) AS "KEY_RESULT_ID",
KR.TITLE AS "KEY_RESULT_TITLE",
KR.KEY_RESULT_TYPE AS "KEY_RESULT_TYPE",
U.unit_name as "UNIT",
KR.BASELINE,
KR.STRETCH_GOAL,
KR.COMMIT_ZONE,
KR.TARGET_ZONE,
KR.STRETCH_ZONE,
COALESCE(C.ID, -1) AS "CHECK_IN_ID",
C.VALUE_METRIC AS "CHECK_IN_VALUE",
C.ZONE AS "CHECK_IN_ZONE",
C.CONFIDENCE,
C.CREATED_ON AS "CHECK_IN_CREATED_ON"
FROM (SELECT T.ID AS TEAM_ID, T.VERSION AS TEAM_VERSION, T.NAME, Q.ID AS QUARTER_ID, Q.LABEL
FROM TEAM T,
QUARTER Q where T.is_deleted is not true) TQ
LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUARTER_ID = O.QUARTER_ID
LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID
LEFT JOIN unit U ON U.ID = KR.unit_id
LEFT JOIN CHECK_IN C ON KR.ID = C.KEY_RESULT_ID AND C.MODIFIED_ON = (SELECT MAX(CC.MODIFIED_ON)
FROM CHECK_IN CC
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted = false)
WHERE KR.is_deleted = false;
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID and CC.is_deleted is not true )

WHERE KR.is_deleted is not true
and O.is_deleted is not true
;


create table if not exists alignment
Expand Down Expand Up @@ -248,7 +251,10 @@ SELECT O.ID AS "OBJECTIVE_ID",
FROM OBJECTIVE O
LEFT JOIN TEAM T ON O.TEAM_ID = T.ID
LEFT JOIN QUARTER Q ON O.QUARTER_ID = Q.ID
LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID;
LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID
WHERE T.is_deleted is not true
and KR.is_deleted is not true
and O.is_deleted is not true;

create table if not exists organisation
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@

DROP VIEW IF EXISTS OVERVIEW;
CREATE VIEW OVERVIEW AS
SELECT tq.team_id AS "team_id",
tq.team_version AS "team_version",
tq.name AS "team_name",
tq.quater_id AS "quarter_id",
tq.label AS "quarter_label",
coalesce(o.id, -1) AS "objective_id",
o.title AS "objective_title",
o.state AS "objective_state",
o.created_on AS "objective_created_on",
coalesce(kr.id, -1) AS "key_result_id",
kr.title AS "key_result_title",
kr.key_result_type AS "key_result_type",
U.unit_name as "unit",
kr.baseline,
kr.stretch_goal,
kr.commit_zone,
kr.target_zone,
kr.stretch_zone,
coalesce(c.id, -1) AS "check_in_id",
c.value_metric AS "check_in_value",
c.zone AS "check_in_zone",
c.confidence,
c.created_on AS "check_in_created_on"
FROM (select t.id as team_id, t.version as team_version, t.name, q.id as quater_id, q.label
from team t,
quarter q) tq
LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUATER_ID = O.QUARTER_ID
LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID
LEFT JOIN unit U ON U.ID = KR.unit_id
LEFT JOIN CHECK_IN C ON KR.ID = C.KEY_RESULT_ID AND C.MODIFIED_ON = (SELECT MAX(CC.MODIFIED_ON)
FROM CHECK_IN CC
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted = false)
WHERE KR.is_deleted = false;
-- AND u.is_deleted = false
-- AND c.is_deleted = false;

DROP VIEW IF EXISTS OVERVIEW;
CREATE VIEW OVERVIEW AS
SELECT tq.team_id AS "team_id",
tq.team_version AS "team_version",
tq.name AS "team_name",
tq.quater_id AS "quarter_id",
tq.label AS "quarter_label",
coalesce(o.id, -1) AS "objective_id",
o.title AS "objective_title",
o.state AS "objective_state",
o.created_on AS "objective_created_on",
coalesce(kr.id, -1) AS "key_result_id",
kr.title AS "key_result_title",
kr.key_result_type AS "key_result_type",
U.unit_name as "unit",
kr.baseline,
kr.stretch_goal,
kr.commit_zone,
kr.target_zone,
kr.stretch_zone,
coalesce(c.id, -1) AS "check_in_id",
c.value_metric AS "check_in_value",
c.zone AS "check_in_zone",
c.confidence,
c.created_on AS "check_in_created_on"
FROM (select t.id as team_id, t.version as team_version, t.name, q.id as quater_id, q.label
from team t,
quarter q T.is_deleted) tq
LEFT JOIN OBJECTIVE O ON TQ.TEAM_ID = O.TEAM_ID AND TQ.QUATER_ID = O.QUARTER_ID
LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID
LEFT JOIN unit U ON U.ID = KR.unit_id
LEFT JOIN CHECK_IN C ON KR.ID = C.KEY_RESULT_ID AND C.MODIFIED_ON = (SELECT MAX(CC.MODIFIED_ON)
FROM CHECK_IN CC
WHERE CC.KEY_RESULT_ID = C.KEY_RESULT_ID AND CC.is_deleted is not true)
WHERE KR.is_deleted is not true
AND O.is_deleted = false;

drop view if exists alignment_selection;
create view alignment_selection as
select o.id as "objective_id",
o.title as "objective_title",
t.id as "team_id",
t.name as "team_name",
q.id as "quarter_id",
q.label as "quarter_label",
coalesce(kr.id, -1) as "key_result_id",
kr.title as "key_result_title"
from objective o
left join team t on o.team_id = t.id
left join quarter q on o.quarter_id = q.id
left join key_result kr on o.id = kr.objective_id
WHERE T.is_deleted is not true
and KR.is_deleted is not true
and O.is_deleted is not true;

Loading

0 comments on commit b9da4c6

Please sign in to comment.