Skip to content
Snippets Groups Projects
Commit 9f7f9fe5 authored by felmer's avatar felmer
Browse files

SSDM-7831: spaces-to-be-ignored feature implemented and tested

parent 0eefd052
No related branches found
No related tags found
No related merge requests found
......@@ -53,9 +53,12 @@ public class UsageGatherer
private IApplicationServerInternalApi service;
public UsageGatherer(IApplicationServerInternalApi service)
private Set<String> spacesToBeIgnored;
public UsageGatherer(IApplicationServerInternalApi service, Set<String> spacesToBeIgnored)
{
this.service = service;
this.spacesToBeIgnored = spacesToBeIgnored;
}
public UsageAndGroupsInfo gatherUsageAndGroups(Period period, List<String> groupsOrNull)
......@@ -170,13 +173,16 @@ public class UsageGatherer
if (usageBySpaces != null)
{
String space = spaceExtractor.apply(entity);
UsageInfo usageInfo = usageBySpaces.get(space);
if (usageInfo == null)
if (spacesToBeIgnored.contains(space) == false)
{
usageInfo = new UsageInfo();
usageBySpaces.put(space, usageInfo);
UsageInfo usageInfo = usageBySpaces.get(space);
if (usageInfo == null)
{
usageInfo = new UsageInfo();
usageBySpaces.put(space, usageInfo);
}
consumer.accept(usageInfo);
}
consumer.accept(usageInfo);
}
}
}
......
......@@ -104,6 +104,8 @@ public class UsageReportingTask extends AbstractMaintenanceTask
private boolean countAllEntities;
private Set<String> spacesToBeIgnored;
public UsageReportingTask()
{
super(false);
......@@ -115,6 +117,7 @@ public class UsageReportingTask extends AbstractMaintenanceTask
long interval = DateTimeUtils.getDurationInMillis(properties, MaintenanceTaskParameters.INTERVAL_KEY, DateUtils.MILLIS_PER_DAY);
periodType = PeriodType.getBestType(interval);
eMailAddresses = PluginUtils.getEMailAddresses(properties, ",");
spacesToBeIgnored = new HashSet<>(PropertyUtils.getList(properties, "spaces-to-be-ignored"));
userReportingType = UserReportingType.valueOf(properties.getProperty(USER_REPORTING_KEY, UserReportingType.ALL.name()));
countAllEntities = PropertyUtils.getBoolean(properties, COUNT_ALL_ENTITIES_KEY, false);
}
......@@ -147,7 +150,8 @@ public class UsageReportingTask extends AbstractMaintenanceTask
protected UsageAndGroupsInfo gatherUsageAndGroups(List<String> groups, Period period)
{
return new UsageGatherer(CommonServiceProvider.getApplicationServerApi()).gatherUsageAndGroups(period, groups);
UsageGatherer gatherer = new UsageGatherer(CommonServiceProvider.getApplicationServerApi(), spacesToBeIgnored);
return gatherer.gatherUsageAndGroups(period, groups);
}
protected IMailClient getMailClient()
......
......@@ -22,9 +22,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.jmock.Expectations;
import org.jmock.Mockery;
......@@ -84,6 +86,8 @@ public class UsageGathererTest
private UsageGatherer usageGatherer;
private Set<String> spacesToBeIgnored;
@BeforeMethod
public void setUp()
{
......@@ -119,7 +123,8 @@ public class UsageGathererTest
will(returnValue(map));
}
});
usageGatherer = new UsageGatherer(service);
spacesToBeIgnored = new HashSet<>();
usageGatherer = new UsageGatherer(service, spacesToBeIgnored);
}
@Test
......@@ -147,6 +152,30 @@ public class UsageGathererTest
context.assertIsSatisfied();
}
@Test
public void testWithGroupsIgnoringSpaceDefault()
{
// Given
spacesToBeIgnored.add("DEFAULT");
prepareSearchExperiments(experiment(USER_IN_A, space("A_STORAGE")), experiment(USER1, space("DEFAULT")),
experiment(USER1, space("DEFAULT")));
prepareSearchSamples(sample(USER_IN_A_AND_B, space("B_METHODS")), sample(USER_IN_A, space("B")), sample(USER2, space("A")));
prepareSearchDataSets(dataSet(sample(USER1, space("BETA"))), dataSet(experiment(INACTIVE_USER, space("DEFAULT"))));
// When
UsageAndGroupsInfo info = usageGatherer.gatherUsageAndGroups(PERIOD, Arrays.asList("A", "B"));
// Then
String renderedMap = renderUsageInfo(info.getUsageByUsersAndSpaces());
assertEquals(renderedMap, "user1 is active in space BETA, 1 new data sets\n"
+ "user2 is active in space A, 1 new samples\n"
+ "user_in_a is active in space A_STORAGE, 1 new experiments\n"
+ "user_in_a is active in space B, 1 new samples\n"
+ "user_in_a_and_b is active in space B_METHODS, 1 new samples\n");
assertEquals(info.getUsersByGroups().toString(), "{A=[user_in_a, user_in_a_and_b], B=[user_in_a_and_b, user_in_b]}");
context.assertIsSatisfied();
}
@Test
public void testWithoutGroups()
{
......@@ -171,6 +200,30 @@ public class UsageGathererTest
context.assertIsSatisfied();
}
@Test
public void testWithoutGroupsIgnoringSpaceA()
{
// Given
spacesToBeIgnored.add("A");
prepareSearchExperiments(experiment(USER_IN_A, space("A_STORAGE")), experiment(USER1, space("DEFAULT")));
prepareSearchSamples(sample(USER_IN_A_AND_B, space("B_METHODS")), sample(USER_IN_A, space("B")), sample(USER2, space("A")));
prepareSearchDataSets(dataSet(sample(USER1, space("BETA"))), dataSet(experiment(INACTIVE_USER, space("DEFAULT"))));
// When
UsageAndGroupsInfo info = usageGatherer.gatherUsageAndGroups(PERIOD, null);
// Then
String renderedMap = renderUsageInfo(info.getUsageByUsersAndSpaces());
assertEquals(renderedMap, "user1 is active in space BETA, 1 new data sets\n"
+ "user1 is active in space DEFAULT, 1 new experiments\n"
+ "user_in_a is active in space A_STORAGE, 1 new experiments\n"
+ "user_in_a is active in space B, 1 new samples\n"
+ "user_in_a_and_b is active in space B_METHODS, 1 new samples\n"
+ "user_inactive is active in space DEFAULT, 1 new data sets\n");
assertEquals(info.getUsersByGroups().toString(), "{}");
context.assertIsSatisfied();
}
private String renderUsageInfo(Map<String, Map<String, UsageInfo>> usageByUsersAndSpaces)
{
StringBuilder builder = new StringBuilder();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment