Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jun 13, 2024
1 parent a8b0166 commit a77af65
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public ObjectiveMapper(TeamBusinessService teamBusinessService, QuarterBusinessS
this.quarterBusinessService = quarterBusinessService;
}

// TODO: Adjust Unit Tests of ObjectiveMapper after merge of multitenancy-main

public ObjectiveDto toDto(Objective objective) {
return new ObjectiveDto(objective.getId(), objective.getVersion(), objective.getTitle(),
objective.getTeam().getId(), objective.getQuarter().getId(), objective.getQuarter().getLabel(),
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/java/ch/puzzle/okr/models/Objective.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public void setWriteable(boolean writeable) {

@Override
public String toString() {
return "Objective{" + "id=" + id + ", version=" + version + ", title='" + title + '\'' + ", state=" + state
+ ", description='" + description + '\'' + ", team=" + team + ", quarter=" + quarter + ", createdBy="
+ createdBy + ", createdOn=" + createdOn + ", modifiedOn=" + modifiedOn + ", modifiedBy=" + modifiedBy
+ ", archived=" + archived + ", writeable=" + writeable + '}';
return "Objective{" + "id=" + id + ", version=" + version + ", title='" + title + '\'' + ", createdBy="
+ createdBy + ", team=" + team + ", quarter=" + quarter + ", description='" + description + '\''
+ ", modifiedOn=" + modifiedOn + ", state=" + state + ", createdOn=" + createdOn + ", modifiedBy="
+ modifiedBy + ", archived=" + archived + ", writeable=" + writeable + '\'' + '}';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ public List<Overview> getFilteredOverview(Long quarterId, List<Long> teamIds, St
return List.of();
}

List<Overview> overviews;
if (quarterId == 998) {
overviews = overviewPersistenceService.getArchiveOverview(teamIds, objectiveQuery, authorizationUser);
overviews.forEach(overview -> overview.setWriteable(false));
} else {
overviews = overviewPersistenceService.getFilteredOverview(quarterId, teamIds, objectiveQuery,
authorizationUser);
}
List<Overview> overviews = overviewPersistenceService.getFilteredOverview(quarterId, teamIds, objectiveQuery,
authorizationUser);
return sortOverview(overviews, authorizationUser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,16 @@ public OverviewPersistenceService(EntityManager entityManager,

public List<Overview> getFilteredOverview(Long quarterId, List<Long> teamIds, String objectiveQuery,
AuthorizationUser authorizationUser) {
String queryString = SELECT_OVERVIEW
boolean isArchive = quarterId == 998;
String queryString = (isArchive ? SELECT_ARCHIVE : SELECT_OVERVIEW)
+ authorizationCriteria.appendOverview(teamIds, objectiveQuery, authorizationUser);
logger.debug("select overview by quarterId={} and teamIds={}: {}", quarterId, teamIds, queryString);
TypedQuery<Overview> typedQuery = entityManager.createQuery(queryString, Overview.class);
typedQuery.setParameter("quarterId", quarterId);
authorizationCriteria.setParameters(typedQuery, teamIds, objectiveQuery, authorizationUser);
return typedQuery.getResultList();
}

public List<Overview> getArchiveOverview(List<Long> teamIds, String objectiveQuery,
AuthorizationUser authorizationUser) {
String queryString = SELECT_ARCHIVE
+ authorizationCriteria.appendOverview(teamIds, objectiveQuery, authorizationUser);
logger.debug("select overview by teamIds={}: {}", teamIds, queryString);
TypedQuery<Overview> typedQuery = entityManager.createQuery(queryString, Overview.class);
if (isArchive) {
logger.debug("select overview by teamIds={}: {}", teamIds, queryString);
} else {
logger.debug("select overview by quarterId={} and teamIds={}: {}", quarterId, teamIds, queryString);
typedQuery.setParameter("quarterId", quarterId);
}
authorizationCriteria.setParameters(typedQuery, teamIds, objectiveQuery, authorizationUser);
return typedQuery.getResultList();
}
Expand Down

0 comments on commit a77af65

Please sign in to comment.