diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGatherer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGatherer.java index 8a2e276e885de0d2ed18e9fba09f952fab924e22..33b4e40054bd3767555ac42e5fa3d6658bd85722 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGatherer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGatherer.java @@ -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); } } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageReportingTask.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageReportingTask.java index 95b4a3b76e7fe413e0b1b2486876850abdce1112..09e391c2cdc5e320d1c3fc34d06501d9c52148bc 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageReportingTask.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UsageReportingTask.java @@ -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() diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGathererTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGathererTest.java index 897e7ac95b1a008c4dc831e5a5ded3c98669eb85..ae4248e9b0e78af85911666fd77ecc82f7652eea 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGathererTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UsageGathererTest.java @@ -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();