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 Aug 30, 2024
1 parent 54dd905 commit 28f8c64
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package ch.puzzle.itc.mobiliar.business.domain.applist;

import java.util.Collections;
import java.util.List;

import javax.ejb.Stateless;
Expand All @@ -38,21 +37,16 @@ public class ApplistScreenDomainService {
@Inject
private ApplistScreenDomainServiceQueries queries;

List<ResourceEntity> getApplicationServerResources(String filter, Integer maxResults, List<Integer> myAMW) {
if (myAMW != null && myAMW.isEmpty()) {
//there is a myAMW-filter, but it doesn't contain any values - so we don't have to ask the db - we know that there is an empty result
return Collections.emptyList();
}
return queries.doFetchApplicationServersWithApplicationsOrderedByAppServerNameCaseInsensitive(filter, myAMW, maxResults);
List<ResourceEntity> getApplicationServerResources(String filter, Integer maxResults) {
return queries.doFetchApplicationServersWithApplicationsOrderedByAppServerNameCaseInsensitive(filter, maxResults);
}


public List<ResourceEntity> getAppServerResourcesWithApplications(String filter, Integer maxResults,
List<Integer> myAmw, boolean withAppServerContainer) {
List<ResourceEntity> appServerList = getApplicationServerResources(filter, maxResults, myAmw);
public List<ResourceEntity> getAppServerResourcesWithApplications(String filter, Integer maxResults, boolean withAppServerContainer) {
List<ResourceEntity> appServerList = getApplicationServerResources(filter, maxResults);
for (ResourceEntity as : appServerList) {
if (as.getName().equals(ApplicationServerContainer.APPSERVERCONTAINER.getDisplayName())) {
if (!withAppServerContainer || as.getConsumedMasterRelations().size() == 0) {
if (!withAppServerContainer || as.getConsumedMasterRelations().isEmpty()) {
appServerList.remove(as);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ApplistScreenDomainServiceQueries {
@Inject
private DatabaseUtil dbUtil;

List<ResourceEntity> doFetchApplicationServersWithApplicationsOrderedByAppServerNameCaseInsensitive(String nameFilter, List<Integer> myAmwIds, Integer maxResult) {
List<ResourceEntity> doFetchApplicationServersWithApplicationsOrderedByAppServerNameCaseInsensitive(String nameFilter, Integer maxResult) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Predicate p;
boolean nameFilterIsEmpty = nameFilter == null || nameFilter.trim().isEmpty();
Expand All @@ -64,13 +64,6 @@ List<ResourceEntity> doFetchApplicationServersWithApplicationsOrderedByAppServer
cb.like(cb.lower(appServer.<String>get("name")), nameFilterLower, JpaWildcardConverter.ESCAPE_CHARACTER),
cb.like(cb.lower(app.<String>get("name")), nameFilterLower, JpaWildcardConverter.ESCAPE_CHARACTER)));
}
if (myAmwIds != null) {
p = cb.and(p,
cb.or(
appServer.get("resourceGroup").get("id").in(myAmwIds),
app.get("resourceGroup").get("id").in(myAmwIds)));
}

q.where(p);

q.distinct(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,10 @@ public void setLog(Logger log) {
this.log = log;
}


public static final String MY_AMW = "myAmw";

protected static final String SPACE_STRING = " ";

private static final String WHERE = "where";

public void appendWhereAndMyAmwParameter(List<Integer> myAmw, StringBuilder stringQuery, String entityDependantMyAmwParameterQl) {
if (myAmw != null && !myAmw.isEmpty()) {
appendWhereIfNotAlreadyExists(stringQuery);
stringQuery.append(entityDependantMyAmwParameterQl);
}
}

/**
*
* @param stringQuery
Expand All @@ -88,7 +78,7 @@ public Query addFilterAndCreateQuery(StringBuilder stringQuery, List<CustomFilte
}

if (filterQuery.length() > 0) {
setzeWhereUndAndStatementsZuQuery(stringQuery);
appendWhereIfNotAlreadyExists(stringQuery);
stringQuery.append('(').append(filterQuery).append(')');
}
}
Expand Down Expand Up @@ -183,16 +173,6 @@ private String extractJoiningtableForFilter(List<CustomFilter> filters) {
return (uniqueJoiningString.length() == 0) ? "" : (SPACE_STRING + uniqueJoiningString);
}

private void setzeWhereUndAndStatementsZuQuery(StringBuilder stringQuery) {
appendWhereIfNotAlreadyExists(stringQuery);
// Wenn die query bereits mit einer Klammer endet, bedeutet dies,
// dass ein myAmw-Filter gesetzt ist und die zusätzlichen Filter
// über ein "and" hinzugefügt werden müssen.
if (stringQuery.toString().endsWith(") ")) {
stringQuery.append("and ");
}
}

private void appendWhereIfNotAlreadyExists(StringBuilder stringQuery) {
if (!stringQuery.toString().contains(WHERE)) {
stringQuery.append(WHERE + SPACE_STRING);
Expand Down Expand Up @@ -289,10 +269,7 @@ protected void createQueryForBooleanTypeWithoutAddingParameterToParameterMap(Str
}
}

public Query setParameterToQuery(Integer startIndex, Integer maxResults, List<Integer> myAmw, Query query) {
if (myAmw != null && !myAmw.isEmpty()) {
query.setParameter(MY_AMW, myAmw);
}
public Query setParameterToQuery(Integer startIndex, Integer maxResults, Query query) {
if (startIndex != null) {
query.setFirstResult(startIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public class ResourceRelations {

public List<ResourceWithRelations> getAppServersWithApplications(String filter, Integer maxResults, ReleaseEntity release) {
UserSettingsEntity userSettings = userSettingsService.getUserSettings(permissionService.getCurrentUserName());
List<Integer> myAMWFilter = null;
List<ResourceEntity> appServersWithAllApplications = applistScreenDomainService.getAppServerResourcesWithApplications(filter, maxResults, myAMWFilter, true);
return filterAppServersByRelease(release, appServersWithAllApplications, myAMWFilter);
List<ResourceEntity> appServersWithAllApplications = applistScreenDomainService.getAppServerResourcesWithApplications(filter, maxResults, true);
return filterAppServersByRelease(release, appServersWithAllApplications);
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
List<ResourceWithRelations> filterAppServersByRelease(ReleaseEntity release,
List<ResourceEntity> appServersWithAllApplications, List<Integer> myAMWFilter) {
List<ResourceWithRelations> filterAppServersByRelease(ReleaseEntity release, List<ResourceEntity> appServersWithAllApplications) {
// filter app server releases
Set<Integer> idLookup = new HashSet<>();
List<ResourceWithRelations> result = new ArrayList<>();
Expand All @@ -74,7 +72,7 @@ List<ResourceWithRelations> filterAppServersByRelease(ReleaseEntity release,
idLookup.add(as.getResourceGroup().getId());

ResourceWithRelations asWithApps = new ResourceWithRelations(asForRelease);
filterApplicationsByRelease(release, asForRelease, asWithApps, myAMWFilter);
filterApplicationsByRelease(release, asForRelease, asWithApps);
result.add(asWithApps);
}
}
Expand All @@ -83,18 +81,15 @@ List<ResourceWithRelations> filterAppServersByRelease(ReleaseEntity release,
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
void filterApplicationsByRelease(ReleaseEntity release, ResourceEntity as,
ResourceWithRelations asWithApps, List<Integer> myAMWFilter) {
void filterApplicationsByRelease(ReleaseEntity release, ResourceEntity as, ResourceWithRelations asWithApps) {
List<ResourceEntity> list = as.getConsumedRelatedResourcesByResourceType(DefaultResourceTypeDefinition.APPLICATION);

for (ResourceEntity r : list) {
if(myAMWFilter==null || myAMWFilter.contains(r.getResourceGroup().getId())) {
ResourceEntity rel = dependencyResolverService
.getResourceEntityForRelease(r.getResourceGroup(), release);
if (rel != null && !asWithApps.getRelatedResources().contains(rel)) {
asWithApps.getRelatedResources().add(rel);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public ResourceGroupEntity getById(int id) {

/**
* @param resourceTypeName
* @param myAmw
* @return
*/
public List<ResourceGroupEntity> loadGroupsForTypeName(String resourceTypeName, List<Integer> myAmw) {
public List<ResourceGroupEntity> loadGroupsForTypeName(String resourceTypeName) {
List<ResourceGroupEntity> result = new ArrayList<>();

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expand All @@ -76,21 +75,12 @@ public List<ResourceGroupEntity> loadGroupsForTypeName(String resourceTypeName,
r.fetch("resources");
Join<ResourceGroupEntity, ResourceEntity> resources = r.join("resources");
Predicate typeNamePred = cb.equal(resources.get("resourceType").get("name"), resourceTypeName);
Predicate asContainerPred = cb.notEqual(resources.get("name"),
ApplicationServerContainer.APPSERVERCONTAINER.getDisplayName());

if (myAmw != null && !myAmw.isEmpty()) {
Predicate myAmwPred = r.get("id").in(myAmw);
q.where(cb.and(cb.and(typeNamePred, asContainerPred), myAmwPred));
}
else {
q.where(cb.and(typeNamePred, asContainerPred));
}
Predicate asContainerPred = cb.notEqual(resources.get("name"), ApplicationServerContainer.APPSERVERCONTAINER.getDisplayName());

q.where(cb.and(typeNamePred, asContainerPred));
q.distinct(true);

result = entityManager.createQuery(q).getResultList();

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public ResourceGroupEntity getResourceGroupForCreateDeploy(Integer groupId) {

/**
* @param resourceTypeName
* @param myAmw
* @param fetchResources determines if resources fetched
* @return a list of Groups
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,14 @@ public List<ResourceGroupEntity> getAllApplications(){


public Tuple<Set<ShakedownTestEntity>, Integer> getFilteredShakedownTests(boolean doPageingCalculation, Integer startIndex, Integer maxResults,
List<CustomFilter> filter, String colToSort, Sort.SortingDirectionType sortingDirection, List<Integer> myAMWFilter) {
List<CustomFilter> filter, String colToSort, Sort.SortingDirectionType sortingDirection) {

Integer totalItemsForCurrentFilter = null;
StringBuilder stringQuery = new StringBuilder();
String baseQuery;
String baseQuery = null;

stringQuery.append("from " + SHAKEDOWN_ENTITY_QL + " " + SHAKEDOWN_TEST_QL_ALIAS + " ");

commonFilterService.appendWhereAndMyAmwParameter(myAMWFilter, stringQuery, getEntityDependantMyAmwParameterQl());
baseQuery = stringQuery.toString();

boolean lowerSortCol = ShakedownTestFilterTypes.APPSERVER_NAME.getFilterTabColumnName().equals(colToSort);

Sort.SortBuilder builder = Sort.builder();
Expand All @@ -125,7 +122,7 @@ public Tuple<Set<ShakedownTestEntity>, Integer> getFilteredShakedownTests(boolea

Query query = commonFilterService.addFilterAndCreateQuery(stringQuery, filter, builder.build(), false, false);

query = commonFilterService.setParameterToQuery(startIndex, maxResults, myAMWFilter, query);
query = commonFilterService.setParameterToQuery(startIndex, maxResults, query);

// some stuff may be lazy loaded
List<ShakedownTestEntity> resultList = query.getResultList();
Expand All @@ -137,17 +134,13 @@ public Tuple<Set<ShakedownTestEntity>, Integer> getFilteredShakedownTests(boolea
String countQueryString = "select count(" + SHAKEDOWN_TEST_QL_ALIAS + ".id) " + baseQuery;
Query countQuery = commonFilterService.addFilterAndCreateQuery(new StringBuilder(countQueryString), filter, Sort.nothing(), false, false);

commonFilterService.setParameterToQuery(null, null, myAMWFilter, countQuery);
commonFilterService.setParameterToQuery(null, null, countQuery);
totalItemsForCurrentFilter = ((Long) countQuery.getSingleResult()).intValue();
}

return new Tuple<>(shakedownTests, totalItemsForCurrentFilter);

}

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

@HasPermission(permission = Permission.SHAKEDOWNTEST, action = Action.CREATE)
public Integer createShakedownTestOrderReturnsTrackingId(List<ShakedownTestOrder> shakedownTestOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;

import java.util.Collections;
import java.util.List;

public class ApplistScreenDomainServiceTest {
Expand All @@ -42,24 +41,22 @@ public void before() {
}

/**
* Ensure, that there is an empty list resulting when asking with an empty myamw-filter (which means "my amw filter on, but no favorite resources available")
* @throws Exception
*/
@Test
public void testGetApplicationServersWithEmptyMyAMWFilter() throws Exception {
public void testGetApplicationServers() throws Exception {
List<ResourceEntity> applicationServers = applistScreenDomainService
.getAppServerResourcesWithApplications("*", 42, Collections.<Integer>emptyList(), true);
.getAppServerResourcesWithApplications("*", 42, true);
Assert.assertTrue(applicationServers.isEmpty());
}

/**
* Ensure, that there is an empty list resulting when asking with an empty myamw-filter (which means "my amw filter on, but no favorite resources available")
* @throws Exception
*/
@Test
public void testGetApplicationServerResourcesWithNull() throws Exception {
public void testGetApplicationServerResources() throws Exception {
List<ResourceEntity> applicationServers = applistScreenDomainService
.getApplicationServerResources("*", 42, Collections.<Integer>emptyList());
.getApplicationServerResources("*", 42);
Assert.assertTrue(applicationServers.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void before() {
entityManager.persist(asRel2.addConsumedResourceRelation(appRel1, resRelType, null, ForeignableOwner.AMW));
entityManager.persist(asRel2.addConsumedResourceRelation(appRel2, resRelType, null, ForeignableOwner.AMW));
Mockito.when(applistScreenDomainService.getAppServerResourcesWithApplications(Mockito.anyString(),
Mockito.anyInt(), Mockito.anyList(), Mockito.anyBoolean())).thenReturn(
Mockito.anyInt(), Mockito.anyBoolean())).thenReturn(
Arrays.asList(asRel1,asRel2));
service.dependencyResolverService = dependencyResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public void testGetAppServersWithApplications() throws Exception {
Mockito.when(userSettingsService.getUserSettings(Mockito.anyString())).thenReturn(userSettings);
List<ResourceEntity> aslist = Arrays.asList(as);
Mockito.when(applistScreenDomainService.getAppServerResourcesWithApplications(Mockito.isNull(),
Mockito.isNull(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(aslist);
Mockito.isNull(), Mockito.anyBoolean())).thenReturn(aslist);
service.getAppServersWithApplications(null, null, release);
Mockito.verify(service).filterAppServersByRelease(release, aslist, null);
Mockito.verify(service).filterAppServersByRelease(release, aslist);
}

@Test
Expand All @@ -104,12 +104,10 @@ public Void answer(InvocationOnMock invocation) {
return null;
}
}).when(service).filterApplicationsByRelease(Mockito.any(ReleaseEntity.class),
Mockito.any(ResourceEntity.class), Mockito.any(ResourceWithRelations.class),
Mockito.any(List.class));
Mockito.any(ResourceEntity.class), Mockito.any(ResourceWithRelations.class));

//when
List<ResourceWithRelations> resources = service.filterAppServersByRelease(release, applicationServers,
null);
List<ResourceWithRelations> resources = service.filterAppServersByRelease(release, applicationServers);

//then
Assert.assertEquals(1, resources.size());
Expand All @@ -118,32 +116,15 @@ public Void answer(InvocationOnMock invocation) {
}

@Test
public void testFilterApplicationsByReleaseNoMyAmw() throws Exception {
ResourceWithRelations resourceWithRelations = doTestFilterApplicationsByRelease(5, null);
public void testFilterApplicationsByRelease() throws Exception {
ResourceWithRelations resourceWithRelations = doTestFilterApplicationsByRelease(5);

//then
Assert.assertEquals(1, resourceWithRelations.getRelatedResources().size());
Assert.assertEquals(resourceWithRelations.getRelatedResources().get(0), app);
}

@Test
public void testFilterApplicationsByReleaseWithMyAMWFilterOK() throws Exception {
ResourceWithRelations resourceWithRelations = doTestFilterApplicationsByRelease(5, Arrays.asList(5));

//then
Assert.assertEquals(1, resourceWithRelations.getRelatedResources().size());
Assert.assertEquals(resourceWithRelations.getRelatedResources().get(0), app);
}

@Test
public void testFilterApplicationsByReleaseWithMyAMWFilterNOK() throws Exception {
ResourceWithRelations resourceWithRelations = doTestFilterApplicationsByRelease(5, Arrays.asList(6));

//then
Assert.assertTrue(resourceWithRelations.getRelatedResources().isEmpty());
}

private ResourceWithRelations doTestFilterApplicationsByRelease(int appId, List<Integer> myAmw)
private ResourceWithRelations doTestFilterApplicationsByRelease(int appId)
throws Exception {
//given
Mockito.when(as.getConsumedRelatedResourcesByResourceType(Mockito.any(
Expand All @@ -157,7 +138,7 @@ private ResourceWithRelations doTestFilterApplicationsByRelease(int appId, List<
Mockito.when(appGrp.getId()).thenReturn(appId);

//when
service.filterApplicationsByRelease(release, as, resourceWithRelations, myAmw);
service.filterApplicationsByRelease(release, as, resourceWithRelations);
return resourceWithRelations;
}
}
Loading

0 comments on commit 28f8c64

Please sign in to comment.