Search in sources :

Example 1 with DefaultWorkflowHistoricProcessInstanceService

use of eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricProcessInstanceService 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);
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) HashMap(java.util.HashMap) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ConfigurationDisabledException(eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) ModelMapperServiceInitException(eu.bcvsolutions.idm.core.exception.ModelMapperServiceInitException) ConfigurationDisabledException(eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(javax.persistence.EntityNotFoundException) MappingException(org.modelmapper.MappingException) ModelMapperServiceInitException(eu.bcvsolutions.idm.core.exception.ModelMapperServiceInitException) MappingException(org.modelmapper.MappingException) DefaultWorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricTaskInstanceService) DefaultWorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricProcessInstanceService)

Aggregations

BaseFilter (eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter)1 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ReadDtoService (eu.bcvsolutions.idm.core.api.service.ReadDtoService)1 ModelMapperServiceInitException (eu.bcvsolutions.idm.core.exception.ModelMapperServiceInitException)1 ConfigurationDisabledException (eu.bcvsolutions.idm.core.security.api.exception.ConfigurationDisabledException)1 DefaultWorkflowHistoricProcessInstanceService (eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricProcessInstanceService)1 DefaultWorkflowHistoricTaskInstanceService (eu.bcvsolutions.idm.core.workflow.service.impl.DefaultWorkflowHistoricTaskInstanceService)1 HashMap (java.util.HashMap)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 MappingException (org.modelmapper.MappingException)1