use of io.gravitee.am.model.analytics.AnalyticsQuery in project gravitee-access-management by gravitee-io.
the class AnalyticsResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find domain analytics", notes = "User must have DOMAIN_ANALYTICS[READ] permission on the specified domain " + "or DOMAIN_ANALYTICS[READ] permission on the specified environment " + "or DOMAIN_ANALYTICS[READ] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Analytics successfully fetched"), @ApiResponse(code = 500, message = "Internal server error") })
public void get(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @BeanParam AnalyticsParam param, @Suspended final AsyncResponse response) {
// validate param
param.validate();
AnalyticsQuery query = new AnalyticsQuery();
query.setType(param.getType());
query.setField(param.getField());
query.setFrom(param.getFrom());
query.setTo(param.getTo());
query.setDomain(domain);
query.setInterval(param.getInterval());
query.setSize(param.getSize());
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_ANALYTICS, Acl.READ).andThen(analyticsService.execute(query)).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.analytics.AnalyticsQuery in project gravitee-access-management by gravitee-io.
the class UserRepositoryTest method testStat_StatusRepartition.
@Test
public void testStat_StatusRepartition() throws TechnicalException {
final String domain = "domain_status";
// enabled used
User user = new User();
user.setReferenceType(ReferenceType.DOMAIN);
user.setReferenceId(domain);
user.setEnabled(true);
user.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user).blockingGet();
// disabled used
User user2 = new User();
user2.setReferenceType(ReferenceType.DOMAIN);
user2.setReferenceId(domain);
user2.setEnabled(false);
user2.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user2).blockingGet();
// locked used
User user3 = new User();
user3.setReferenceType(ReferenceType.DOMAIN);
user3.setReferenceId(domain);
user3.setAccountNonLocked(false);
user3.setAccountLockedUntil(new Date(Instant.now().plusSeconds(60).toEpochMilli()));
user3.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user3).blockingGet();
// expired locked user ==> so active one
User user4 = new User();
user4.setReferenceType(ReferenceType.DOMAIN);
user4.setReferenceId(domain);
user4.setAccountNonLocked(false);
user4.setAccountLockedUntil(new Date(Instant.now().minusSeconds(60).toEpochMilli()));
user4.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user4).blockingGet();
// inactive user
User user5 = new User();
user5.setReferenceType(ReferenceType.DOMAIN);
user5.setReferenceId(domain);
user5.setLoggedAt(new Date(Instant.now().minus(91, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user5).blockingGet();
// fetch user
AnalyticsQuery query = new AnalyticsQuery();
query.setField(Field.USER_STATUS);
query.setDomain(domain);
TestObserver<Map<Object, Object>> testObserver = userRepository.statistics(query).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(users -> users.size() == 4);
testObserver.assertValue(users -> ((Number) users.get("active")).intValue() == 2);
testObserver.assertValue(users -> ((Number) users.get("inactive")).intValue() == 1);
testObserver.assertValue(users -> ((Number) users.get("disabled")).intValue() == 1);
testObserver.assertValue(users -> ((Number) users.get("locked")).intValue() == 1);
}
use of io.gravitee.am.model.analytics.AnalyticsQuery in project gravitee-access-management by gravitee-io.
the class ApplicationAnalyticsResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find application analytics", notes = "User must have APPLICATION_ANALYTICS[READ] permission on the specified application " + "or APPLICATION_ANALYTICS[READ] permission on the specified domain " + "or APPLICATION_ANALYTICS[READ] permission on the specified environment " + "or APPLICATION_ANALYTICS[READ] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Analytics successfully fetched"), @ApiResponse(code = 500, message = "Internal server error") })
public void get(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("application") String application, @BeanParam AnalyticsParam param, @Suspended final AsyncResponse response) {
param.validate();
AnalyticsQuery query = new AnalyticsQuery();
query.setDomain(domain);
query.setApplication(application);
query.setType(param.getType());
query.setField(param.getField());
query.setFrom(param.getFrom());
query.setTo(param.getTo());
query.setInterval(param.getInterval());
query.setSize(param.getSize());
checkAnyPermission(organizationId, environmentId, domain, Permission.APPLICATION_ANALYTICS, Acl.READ).andThen(applicationAnalyticsService.execute(query)).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.analytics.AnalyticsQuery in project gravitee-access-management by gravitee-io.
the class UserRepositoryTest method testStat_StatusRepartition_byClient.
@Test
public void testStat_StatusRepartition_byClient() throws TechnicalException {
final String domain = "domain_status";
final String clientId1 = UUID.randomUUID().toString();
;
final String clientId2 = UUID.randomUUID().toString();
;
// enabled used
User user = new User();
user.setClient(clientId1);
user.setReferenceType(ReferenceType.DOMAIN);
user.setReferenceId(domain);
user.setEnabled(true);
user.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user).blockingGet();
// disabled used
User user2 = new User();
user2.setClient(clientId1);
user2.setReferenceType(ReferenceType.DOMAIN);
user2.setReferenceId(domain);
user2.setEnabled(false);
user2.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user2).blockingGet();
// locked used
User user3 = new User();
user3.setClient(clientId1);
user3.setReferenceType(ReferenceType.DOMAIN);
user3.setReferenceId(domain);
user3.setAccountNonLocked(false);
user3.setAccountLockedUntil(new Date(Instant.now().plusSeconds(60).toEpochMilli()));
user3.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user3).blockingGet();
// expired locked user ==> so active one
User user4 = new User();
user4.setClient(clientId2);
user4.setReferenceType(ReferenceType.DOMAIN);
user4.setReferenceId(domain);
user4.setAccountNonLocked(false);
user4.setAccountLockedUntil(new Date(Instant.now().minusSeconds(60).toEpochMilli()));
user4.setLoggedAt(new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user4).blockingGet();
// inactive user
User user5 = new User();
user5.setClient(clientId2);
user5.setReferenceType(ReferenceType.DOMAIN);
user5.setReferenceId(domain);
user5.setLoggedAt(new Date(Instant.now().minus(91, ChronoUnit.DAYS).toEpochMilli()));
userRepository.create(user5).blockingGet();
// fetch for clientId1
AnalyticsQuery query1 = new AnalyticsQuery();
query1.setField(Field.USER_STATUS);
query1.setDomain(domain);
query1.setApplication(clientId1);
TestObserver<Map<Object, Object>> testObserver1 = userRepository.statistics(query1).test();
testObserver1.awaitTerminalEvent();
testObserver1.assertComplete();
testObserver1.assertNoErrors();
testObserver1.assertValue(users -> users.size() == 4);
testObserver1.assertValue(users -> ((Number) users.get("active")).intValue() == 1);
testObserver1.assertValue(users -> ((Number) users.get("inactive")).intValue() == 0);
testObserver1.assertValue(users -> ((Number) users.get("disabled")).intValue() == 1);
testObserver1.assertValue(users -> ((Number) users.get("locked")).intValue() == 1);
// fetch for clientId2
AnalyticsQuery query2 = new AnalyticsQuery();
query2.setField(Field.USER_STATUS);
query2.setDomain(domain);
query2.setApplication(clientId2);
TestObserver<Map<Object, Object>> testObserver2 = userRepository.statistics(query2).test();
testObserver2.awaitTerminalEvent();
testObserver2.assertComplete();
testObserver2.assertNoErrors();
testObserver2.assertValue(users -> users.size() == 4);
testObserver2.assertValue(users -> ((Number) users.get("active")).intValue() == 1);
testObserver2.assertValue(users -> ((Number) users.get("inactive")).intValue() == 1);
testObserver2.assertValue(users -> ((Number) users.get("disabled")).intValue() == 0);
testObserver2.assertValue(users -> ((Number) users.get("locked")).intValue() == 0);
}
use of io.gravitee.am.model.analytics.AnalyticsQuery in project gravitee-access-management by gravitee-io.
the class UserRepositoryTest method testStat_UserRegistration.
@Test
public void testStat_UserRegistration() throws TechnicalException {
final String domain = "domain";
// create user
User user = new User();
user.setReferenceType(ReferenceType.DOMAIN);
user.setReferenceId(domain);
user.setPreRegistration(true);
user.setRegistrationCompleted(true);
userRepository.create(user).blockingGet();
User user2 = new User();
user2.setReferenceType(ReferenceType.DOMAIN);
user2.setReferenceId(domain);
user2.setPreRegistration(true);
user2.setRegistrationCompleted(false);
userRepository.create(user2).blockingGet();
User user3 = new User();
user3.setReferenceType(ReferenceType.DOMAIN);
user3.setReferenceId(domain);
user3.setPreRegistration(false);
userRepository.create(user3).blockingGet();
// fetch user
AnalyticsQuery query = new AnalyticsQuery();
query.setField(Field.USER_REGISTRATION);
query.setDomain(domain);
TestObserver<Map<Object, Object>> testObserver = userRepository.statistics(query).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(users -> users.size() == 2);
testObserver.assertValue(users -> ((Number) users.get("total")).intValue() == 2);
testObserver.assertValue(users -> ((Number) users.get("completed")).intValue() == 1);
}
Aggregations