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 23c8805 commit 08a3231
Show file tree
Hide file tree
Showing 31 changed files with 180 additions and 182 deletions.
7 changes: 0 additions & 7 deletions backend/src/main/java/ch/puzzle/okr/OkrApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ch.puzzle.okr;

import ch.puzzle.okr.models.Deletable;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
Expand All @@ -15,9 +13,4 @@ public static void main(String[] args) {
.initializers(new OkrApplicationContextInitializer()) //
.run(args);
}

public static <E> Specification<E> isNotMarkedAsDeleted() {
return (root, query, criteriaBuilder) ->
criteriaBuilder.isFalse(root.get("isDeleted"));
}
}
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
@@ -1,11 +1,10 @@
package ch.puzzle.okr.repository;

import ch.puzzle.okr.models.checkin.CheckIn;

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 @@ -2,7 +2,6 @@

import ch.puzzle.okr.models.Deletable;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down
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 @@ -2,7 +2,6 @@

import static ch.puzzle.okr.Constants.OBJECTIVE;

import ch.puzzle.okr.OkrApplication;
import ch.puzzle.okr.exception.OkrResponseStatusException;
import ch.puzzle.okr.models.Objective;
import ch.puzzle.okr.models.Quarter;
Expand Down Expand Up @@ -54,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 @@ -63,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 @@ -4,10 +4,7 @@
import static org.springframework.http.HttpStatus.NOT_FOUND;

import ch.puzzle.okr.ErrorKey;
import ch.puzzle.okr.OkrApplication;
import ch.puzzle.okr.exception.OkrResponseStatusException;
import ch.puzzle.okr.models.Deletable;
import ch.puzzle.okr.repository.DeleteRepository;
import ch.puzzle.okr.service.persistence.customCrud.DeleteMethod;
import ch.puzzle.okr.service.persistence.customCrud.HardDelete;
import java.util.List;
Expand All @@ -17,7 +14,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -78,7 +74,7 @@ public T save(T model) throws OkrResponseStatusException {
}

public List<T> findAll() {
// TODO use instance of instead of method on deleteMethod
// TODO use instance of instead of method on deleteMethod

return iteratorToList(this.deleteMethod.findAll());
}
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
@@ -1,17 +1,17 @@
package ch.puzzle.okr.service.persistence.customCrud;

import ch.puzzle.okr.OkrApplication;
import ch.puzzle.okr.models.Deletable;
import ch.puzzle.okr.repository.DeleteRepository;
import ch.puzzle.okr.specifications.DeleteSpecifications;

public class SoftDelete<T extends Deletable, I, R extends DeleteRepository<T, I>> extends DeleteMethod<T, I, R> {
@Override
public void deleteById(I id) {
repo.markAsDeleted(id);
repo.markAsDeleted(id);
}

@Override
public Iterable<T> findAll() {
return repo.findAll(OkrApplication.isNotMarkedAsDeleted());
return repo.findAll(DeleteSpecifications.isNotMarkedAsDeleted());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ch.puzzle.okr.specifications;

import org.springframework.data.jpa.domain.Specification;

public class DeleteSpecifications {
private DeleteSpecifications() {
}

public static <E> Specification<E> isNotMarkedAsDeleted() {
return (root, query, criteriaBuilder) -> criteriaBuilder.isFalse(root.get("isDeleted"));
}

}
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
Loading

0 comments on commit 08a3231

Please sign in to comment.