use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method updateReporter.
private void updateReporter(String reporterId, ReporterEvent reporterEvent) {
final String eventType = reporterEvent.toString().toLowerCase();
logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
}, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method deployReporter.
private void deployReporter(String reporterId, ReporterEvent reporterEvent) {
final String eventType = reporterEvent.toString().toLowerCase();
logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
if (reporters.containsKey(reporterId)) {
updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
} else {
startReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
}
logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
}, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.
the class MongoReporterRepository method convert.
private Reporter convert(ReporterMongo reporterMongo) {
if (reporterMongo == null) {
return null;
}
Reporter reporter = new Reporter();
reporter.setId(reporterMongo.getId());
reporter.setEnabled(reporterMongo.isEnabled());
reporter.setDomain(reporterMongo.getDomain());
reporter.setName(reporterMongo.getName());
reporter.setSystem(reporterMongo.isSystem());
reporter.setType(reporterMongo.getType());
reporter.setDataType(reporterMongo.getDataType());
reporter.setConfiguration(reporterMongo.getConfiguration());
reporter.setCreatedAt(reporterMongo.getCreatedAt());
reporter.setUpdatedAt(reporterMongo.getUpdatedAt());
return reporter;
}
use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.
the class ReporterServiceImpl method checkReporterConfiguration.
/**
* This method check if the configuration attribute of a Reporter is valid
*
* @param reporter to check
* @return
*/
private Single<Reporter> checkReporterConfiguration(Reporter reporter) {
Single<Reporter> result = Single.just(reporter);
if (REPORTER_AM_FILE.equalsIgnoreCase(reporter.getType())) {
// for FileReporter we have to check if the filename isn't used by another reporter
final JsonObject configuration = (JsonObject) Json.decodeValue(reporter.getConfiguration());
final String reporterId = reporter.getId();
result = reporterRepository.findByDomain(reporter.getDomain()).filter(r -> r.getType().equalsIgnoreCase(REPORTER_AM_FILE)).filter(// exclude 'self' in case of update
r -> reporterId == null || !r.getId().equals(reporterId)).map(r -> (JsonObject) Json.decodeValue(r.getConfiguration())).filter(cfg -> cfg.containsKey(REPORTER_CONFIG_FILENAME) && cfg.getString(REPORTER_CONFIG_FILENAME).equals(configuration.getString(REPORTER_CONFIG_FILENAME))).count().flatMap(reporters -> {
if (reporters > 0) {
// more than one reporter use the same filename
return Single.error(new ReporterConfigurationException("Filename already defined"));
} else {
return Single.just(reporter);
}
});
}
return result;
}
use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.
the class DefaultReporterUpgraderTest method createDefaultTestReporter.
private Reporter createDefaultTestReporter(boolean system) {
Reporter reporter = new Reporter();
reporter.setName("Default test Reporter");
reporter.setSystem(system);
reporter.setId("test-reporter-id");
reporter.setConfiguration("configuration-test-reporter");
reporter.setDomain("domain-id");
return reporter;
}
Aggregations