use of eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException in project CzechIdMng by bcvsolutions.
the class ModelMapperChecker method verify.
/**
* Check registered services and their conversions to dto provided by model mapper.
* Throws Exception, if check does not pass.
*
* @throws ConfigurationDisabledException if check is disabled by configuration.
* @throws ResultCodeException if service check failed (referential integrity is broken or other IdM exception occurs).
* @throws ModelMapperServiceInitException if mapper is wrongly inited.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void verify() {
if (!configurationService.getBooleanValue(PROPERTY_ENABLED, DEFAULT_ENABLED)) {
LOG.warn("Init: check registered IdM services is disabled.");
//
throw new ConfigurationDisabledException(ModelMapperChecker.PROPERTY_ENABLED);
}
long start = System.currentTimeMillis();
int modelMapperUsed = 0;
Map<String, ReadDtoService> services = context.getBeansOfType(ReadDtoService.class);
for (ReadDtoService service : services.values()) {
if ((service instanceof DefaultWorkflowHistoricTaskInstanceService) || (service instanceof DefaultWorkflowHistoricProcessInstanceService)) {
LOG.debug("Workflow history service [{}] will not be checked - find method with pagination is not fully supported and took long time.", service.getClass());
continue;
}
//
LOG.trace("Service [{}] will be checked.", service.getClass());
try {
BaseFilter filter = null;
if (service.getFilterClass() != null) {
// some services could not define filter
try {
if (service.getFilterClass().equals(DataFilter.class)) {
filter = new DataFilter(service.getDtoClass());
} else {
filter = (BaseFilter) mapper.convertValue(new HashMap(), service.getFilterClass());
}
} catch (Exception ex) {
LOG.debug("Service [{}] filter [{}] cannot be constructed. Find method will be checked without filter.", service.getClass(), service.getFilterClass());
}
}
if (!service.find(filter, PageRequest.of(0, 1)).getContent().isEmpty()) {
modelMapperUsed++;
}
} catch (UnsupportedOperationException ex) {
LOG.debug("Service [{}] does not support find method. Check will be skipped.", service.getClass());
} catch (MappingException ex) {
throw new ModelMapperServiceInitException(AutowireHelper.getTargetType(service), ex);
} catch (EntityNotFoundException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getMessage())), ex);
} catch (ResultCodeException ex) {
throw ex;
} catch (Exception ex) {
if (ex.getCause() instanceof EntityNotFoundException) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", String.valueOf(ex.getCause().getMessage()), "service", service.getClass().getCanonicalName()), ex);
}
LOG.error("Service [{}] cannot be checked. Find method cannot be called.", service.getClass(), ex);
}
LOG.trace("Service [{}] was checked.", service.getClass());
}
LOG.info("Init: all registered IdM services [{}]. " + "Services usage were checked [{}] (agenda contains some records) [took: {}ms].", services.size(), modelMapperUsed, System.currentTimeMillis() - start);
}
Aggregations