Skip to content

Commit

Permalink
refactor: remove unused functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
llorentelemmc committed Sep 2, 2024
1 parent 28f8c64 commit 070d724
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import java.util.stream.Collectors;

import static ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentFilterTypes.QLConstants.DEPLOYMENT_QL_ALIAS;
import static ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentFilterTypes.QLConstants.GROUP_QL;


@Stateless
Expand Down Expand Up @@ -179,12 +178,9 @@ public ComparatorFilterOption[] getComparatorFilterOptions() {
* @param filters
* @param colToSort
* @param sortingDirection
* @param myAmw
* @return a Tuple containing the filter deployments and the total deployments for that filter if doPagingCalculation is true
*/
public Tuple<Set<DeploymentEntity>, Integer> getFilteredDeployments(Integer startIndex,
Integer maxResults, List<CustomFilter> filters, String colToSort,
Sort.SortingDirectionType sortingDirection, List<Integer> myAmw) {
public Tuple<Set<DeploymentEntity>, Integer> getFilteredDeployments(Integer startIndex, Integer maxResults, List<CustomFilter> filters, String colToSort, Sort.SortingDirectionType sortingDirection) {
Integer totalItemsForCurrentFilter;
boolean doPaging = maxResults != null && (maxResults > 0);

Expand Down Expand Up @@ -216,10 +212,8 @@ public Tuple<Set<DeploymentEntity>, Integer> getFilteredDeployments(Integer star
} else {
stringQuery.append("select " + DEPLOYMENT_QL_ALIAS + " from " + DEPLOYMENT_ENTITY_NAME + " " + DEPLOYMENT_QL_ALIAS + " ");
}
commonFilterService.appendWhereAndMyAmwParameter(myAmw, stringQuery, "and " + getEntityDependantMyAmwParameterQl());
} else {
stringQuery.append("select " + DEPLOYMENT_QL_ALIAS + " from " + DEPLOYMENT_ENTITY_NAME + " " + DEPLOYMENT_QL_ALIAS + " ");
commonFilterService.appendWhereAndMyAmwParameter(myAmw, stringQuery, getEntityDependantMyAmwParameterQl());
}

String baseQuery = stringQuery.toString();
Expand All @@ -239,7 +233,7 @@ public Tuple<Set<DeploymentEntity>, Integer> getFilteredDeployments(Integer star
sortBuilder.order(DeploymentOrder.of(DeploymentFilterTypes.ID.getFilterTabColumnName(), Sort.SortingDirectionType.DESC, false));

Query query = commonFilterService.addFilterAndCreateQuery(stringQuery, filters, sortBuilder.build(), hasLastDeploymentForAsEnvFilterSet, false);
query = commonFilterService.setParameterToQuery(startIndex, maxResults, myAmw, query);
query = commonFilterService.setParameterToQuery(startIndex, maxResults, query);

Set<DeploymentEntity> deployments = new LinkedHashSet<>();
// some stuff may be lazy loaded
Expand All @@ -265,7 +259,7 @@ public Tuple<Set<DeploymentEntity>, Integer> getFilteredDeployments(Integer star
// last param needs to be true if we are dealing with a combination of "State" and "Latest deployment job for App Server and Env"
Query countQuery = commonFilterService.addFilterAndCreateQuery(new StringBuilder(countQueryString), filters, Sort.nothing(), hasLastDeploymentForAsEnvFilterSet, lastDeploymentState != null);

commonFilterService.setParameterToQuery(null, null, myAmw, countQuery);
commonFilterService.setParameterToQuery(null, null, countQuery);
totalItemsForCurrentFilter = (lastDeploymentState == null) ? ((Long) countQuery.getSingleResult()).intValue() : countQuery.getResultList().size();
// fix for the special case of multiple deployments on the same environment with exactly the same deployment date
if (hasLastDeploymentForAsEnvFilterSet && lastDeploymentState == null && deployments.size() != allResults) {
Expand Down Expand Up @@ -437,10 +431,6 @@ public int compare(DeploymentEntity o1, DeploymentEntity o2) {
return deploymentsList;
}

private String getEntityDependantMyAmwParameterQl() {
return "(" + GROUP_QL + ".id in (:" + CommonFilterService.MY_AMW + ")) ";
}

private boolean isLastDeploymentForAsEnvFilterSet(List<CustomFilter> filter) {
if (filter != null) {
for (CustomFilter deploymentFilter : filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ public void test_getFilteredDeployments_sortByRelease() {
// when sorting by release ascending (releaseA - releaseC - releaseB)
String colToSort = DeploymentFilterTypes.RELEASE.getFilterTabColumnName();
Tuple<Set<DeploymentEntity>, Integer> result1 = deploymentBoundary.getFilteredDeployments(0, 10,
Collections.EMPTY_LIST, colToSort, Sort.SortingDirectionType.ASC, null);
Collections.EMPTY_LIST, colToSort, Sort.SortingDirectionType.ASC);

// then
assertNotNull(result1);
Expand All @@ -801,7 +801,7 @@ public void test_getFilteredDeployments_sortByRelease() {

// when sorting by release descending (releaseB - releaseC - releaseC)
Tuple<Set<DeploymentEntity>, Integer> result2 = deploymentBoundary.getFilteredDeployments(0, 10,
Collections.EMPTY_LIST, colToSort, Sort.SortingDirectionType.DESC, null);
Collections.EMPTY_LIST, colToSort, Sort.SortingDirectionType.DESC);

// then
assertNotNull(result2);
Expand Down Expand Up @@ -857,7 +857,7 @@ public void test_getFilteredDeployments_filterByRelease() {
.comparatorSelection(ComparatorFilterOption.gte).build();
filter.setValue(CustomFilter.convertDateToString(releaseA.getInstallationInProductionAt()));
result = deploymentBoundary.getFilteredDeployments(0, 10, Collections.singletonList(filter), null,
Sort.SortingDirectionType.ASC, null);
Sort.SortingDirectionType.ASC);

// then
assertNotNull(result);
Expand All @@ -870,7 +870,7 @@ public void test_getFilteredDeployments_filterByRelease() {
filter.setValue(CustomFilter.convertDateToString(releaseC.getInstallationInProductionAt()));
filter.setComparatorSelection(ComparatorFilterOption.lte);
result = deploymentBoundary.getFilteredDeployments(0, 10, Collections.singletonList(filter), null,
Sort.SortingDirectionType.ASC, null);
Sort.SortingDirectionType.ASC);

// then
assertNotNull(result);
Expand All @@ -883,7 +883,7 @@ public void test_getFilteredDeployments_filterByRelease() {
filter.setValue(CustomFilter.convertDateToString(releaseB.getInstallationInProductionAt()));
filter.setComparatorSelection(ComparatorFilterOption.eq);
result = deploymentBoundary.getFilteredDeployments(0, 10, Collections.singletonList(filter), null,
Sort.SortingDirectionType.ASC, null);
Sort.SortingDirectionType.ASC);

// then
assertNotNull(result);
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public void shouldReturnTheRightFilteredDeploymentsInTheRightOrderIfLatestDeploy

// when sorting by release ascending
String colToSort = DeploymentFilterTypes.RELEASE.getFilterTabColumnName();
Tuple<Set<DeploymentEntity>, Integer> result1 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC, null);
Tuple<Set<DeploymentEntity>, Integer> result1 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC);

// then
assertNotNull(result1);
Expand All @@ -1134,7 +1134,7 @@ public void shouldReturnTheRightFilteredDeploymentsInTheRightOrderIfLatestDeploy
assertThat(it.next().getRelease(), is(release2));

// when sorting by release descending
Tuple<Set<DeploymentEntity>, Integer> result2 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.DESC, null);
Tuple<Set<DeploymentEntity>, Integer> result2 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.DESC);

// then
assertNotNull(result2);
Expand Down Expand Up @@ -1210,7 +1210,7 @@ public void shouldReturnTheRightFilteredDeploymentsIfLatestDeploymentJobFilterAn
String colToSort = DeploymentFilterTypes.RELEASE.getFilterTabColumnName();

// when
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC, null);
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC);

// then
assertNotNull(result);
Expand Down Expand Up @@ -1286,7 +1286,7 @@ public void shouldReturnDeploymentWithHighestIdPerEnvironmentIfLatestDeploymentJ
String colToSort = DeploymentFilterTypes.RELEASE.getFilterTabColumnName();

// when
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC, null);
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC);

// then
assertNotNull(result);
Expand Down Expand Up @@ -1361,7 +1361,7 @@ public void shouldReturnDeploymentWithHighestIdPerEnvironmentIfLatestDeploymentJ

// when sorted by tracking id asc
String colToSort = DeploymentFilterTypes.TRACKING_ID.getFilterTabColumnName();
Tuple<Set<DeploymentEntity>, Integer> result1 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC, null);
Tuple<Set<DeploymentEntity>, Integer> result1 = deploymentBoundary.getFilteredDeployments(0, 10, filters, colToSort, Sort.SortingDirectionType.ASC);

// then
assertNotNull(result1);
Expand All @@ -1379,7 +1379,7 @@ public void shouldReturnDeploymentWithHighestIdPerEnvironmentIfLatestDeploymentJ

// when sorted by tracking id desc
colToSort = DeploymentFilterTypes.TRACKING_ID.getFilterTabColumnName();
Tuple<Set<DeploymentEntity>, Integer> result2 = deploymentBoundary.getFilteredDeployments( 0, 10, filters, colToSort, Sort.SortingDirectionType.DESC, null);
Tuple<Set<DeploymentEntity>, Integer> result2 = deploymentBoundary.getFilteredDeployments( 0, 10, filters, colToSort, Sort.SortingDirectionType.DESC);

// then
assertNotNull(result2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ public void shouldSetSortColumnIfColumnKnown() {
// given
Query query = mock(Query.class);
when(commonFilterService.addFilterAndCreateQuery(any(), any(), any(), anyBoolean(), anyBoolean())).thenReturn(query);
when(commonFilterService.setParameterToQuery(any(), any(), any(), any())).thenReturn(query);
when(commonFilterService.setParameterToQuery(any(), any(), any())).thenReturn(query);

// when
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), "d.trackingId", DESC, emptyList() );
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), "d.trackingId", DESC);

// then
ArgumentCaptor<Sort> sortCaptor = ArgumentCaptor.forClass(Sort.class);
Expand All @@ -283,10 +283,10 @@ public void shouldIgnoreSortColumnIfNull() {
// given
Query query = mock(Query.class);
when(commonFilterService.addFilterAndCreateQuery(any(), any(), any(), anyBoolean(), anyBoolean())).thenReturn(query);
when(commonFilterService.setParameterToQuery(any(), any(), any(), any())).thenReturn(query);
when(commonFilterService.setParameterToQuery(any(), any(), any())).thenReturn(query);

// when
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), null, DESC, emptyList() );
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), null, DESC);

// then
ArgumentCaptor<Sort> sortCaptor = ArgumentCaptor.forClass(Sort.class);
Expand All @@ -301,7 +301,7 @@ public void shouldIgnoreSortColumnIfNull() {
public void shouldThrowIfSortColumnUnknown() {
try {
// when
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), "unknown.column", DESC, emptyList());
deploymentBoundary.getFilteredDeployments(0, null, emptyList(), "unknown.column", DESC);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import java.net.URI;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static ch.puzzle.itc.mobiliar.business.deploy.entity.DeploymentFilterTypes.*;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
Expand Down Expand Up @@ -129,7 +128,7 @@ public Response getDeployments(@ApiParam("Filters") @QueryParam("filters") Strin
}
Sort.SortingDirectionType sortingDirectionType = getSortingDirectionType(sortDirection);
LinkedList<CustomFilter> filters = createCustomFilters(filterDTOs);
Tuple<Set<DeploymentEntity>, Integer> filteredDeployments = deploymentBoundary.getFilteredDeployments(offset, maxResults, filters, colToSort, sortingDirectionType, null);
Tuple<Set<DeploymentEntity>, Integer> filteredDeployments = deploymentBoundary.getFilteredDeployments(offset, maxResults, filters, colToSort, sortingDirectionType);
List<DeploymentDTO> deploymentDTOs = createDeploymentDTOs(filteredDeployments);
return Response.status(Status.OK).header("X-Total-Count", filteredDeployments.getB()).entity(new GenericEntity<List<DeploymentDTO>>(deploymentDTOs) {}).build();
}
Expand Down Expand Up @@ -288,7 +287,7 @@ public Response getDeployments(
if (deploymentParameterValues != null) {
createFiltersAndAddToList(DEPLOYMENT_PARAMETER, deploymentParameterValues, filters);
}
Tuple<Set<DeploymentEntity>, Integer> filteredDeployments = deploymentBoundary.getFilteredDeployments(offset, maxResults, filters, null, null, null);
Tuple<Set<DeploymentEntity>, Integer> filteredDeployments = deploymentBoundary.getFilteredDeployments(offset, maxResults, filters, null, null);

List<DeploymentDTO> deploymentDTOs = createDeploymentDTOs(filteredDeployments);

Expand Down Expand Up @@ -507,7 +506,7 @@ public Response addDeployment(@ApiParam("Deployment Request") DeploymentRequestD
CustomFilter trackingIdFilter = CustomFilter.builder(TRACKING_ID).build();
trackingIdFilter.setValue(trackingId.toString());
filters.add(trackingIdFilter);
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments( 0, 1, filters, null, null, null);
Tuple<Set<DeploymentEntity>, Integer> result = deploymentBoundary.getFilteredDeployments( 0, 1, filters, null, null);

DeploymentDTO deploymentDto = new DeploymentDTO(result.getA().iterator().next());

Expand Down
Loading

0 comments on commit 070d724

Please sign in to comment.