use of eu.bcvsolutions.idm.core.api.service.ReadDtoService in project CzechIdMng by bcvsolutions.
the class DatabaseTableMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
String serviceName = getParameterConverter().toString(monitoring.getEvaluatorProperties(), PARAMETER_READ_SERVICE_BEAN_NAME);
Object bean;
try {
bean = context.getBean(serviceName);
if (bean == null || !(bean instanceof ReadDtoService<?, ?>)) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName));
}
} catch (BeansException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName), ex);
}
//
ReadDtoService<?, ?> readService = (ReadDtoService<?, ?>) bean;
long treshold = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_THRESHOLD, DEFAULT_THRESHOLD);
long count = readService.count(null);
ResultModel resultModel = new DefaultResultModel(CoreResultCode.MONITORING_DATABASE_TABLE, ImmutableMap.of("tableName", String.valueOf(getTableName(readService)), "dtoName", String.valueOf(getDtoName(readService)), "count", Long.toString(count)));
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setValue(Long.toString(count));
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
if (treshold < count) {
result.setLevel(NotificationLevel.WARNING);
}
//
return result;
}
use of eu.bcvsolutions.idm.core.api.service.ReadDtoService in project CzechIdMng by bcvsolutions.
the class DefaultLookupService method getDtoLookup.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <I extends BaseDto> DtoLookup<I> getDtoLookup(Class<? extends Identifiable> identifiableType) {
ReadDtoService service = getDtoService(identifiableType);
if (service == null) {
LOG.debug("Service for identifiable type [{}] is not found, lookup not found.", identifiableType);
return null;
}
//
DtoLookup<I> lookup = (DtoLookup<I>) dtoLookups.getPluginFor(service.getDtoClass());
if (lookup == null) {
if (service instanceof CodeableService) {
return new CodeableDtoLookup<I>((CodeableService<I>) service);
}
return new DefaultDtoLookup<I>(service);
}
return lookup;
}
use of eu.bcvsolutions.idm.core.api.service.ReadDtoService 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);
}
use of eu.bcvsolutions.idm.core.api.service.ReadDtoService in project CzechIdMng by bcvsolutions.
the class DefaultFilterManager method getRegisteredServiceFilters.
/**
* Returns filters processed directly by service predicates.
*
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private Map<FilterKey, FilterBuilderDto> getRegisteredServiceFilters() {
if (registeredServiceFilters == null) {
registeredServiceFilters = new HashMap<>();
// find field by recursion from registered services and filter dtos
Map<String, ReadDtoService> services = context.getBeansOfType(ReadDtoService.class);
services.forEach((beanName, service) -> {
Class<? extends BaseEntity> entityClass = service.getEntityClass();
Class<? extends BaseFilter> filterClass = service.getFilterClass();
if (entityClass == null || filterClass == null) {
LOG.trace("Service [{}], [{}] does not define controlled entity [{}] or filter[{}], skip to resolve available filter criteria.", beanName, service.getClass(), entityClass, filterClass);
} else {
registeredServiceFilters.putAll(getRegisteredFilters(entityClass, filterClass).entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> {
FilterBuilderDto dto = e.getValue();
// service and property is unique combination
dto.setId(String.format("%s-%s", beanName, dto.getName()));
// service - can be overriden - https://wiki.czechidm.com/tutorial/dev/override_service
dto.setModule(EntityUtils.getModule(service.getClass()));
//
if (service instanceof AbstractFormValueService<?, ?>) {
// eav value services are constructed dynamically (prevent to show cglib class)
dto.setFilterBuilderClass(AbstractFormValueService.class);
} else {
dto.setFilterBuilderClass(AutowireHelper.getTargetClass(service));
}
return dto;
})));
}
});
}
//
return registeredServiceFilters;
}
use of eu.bcvsolutions.idm.core.api.service.ReadDtoService in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManager method baseCheckDeferredResult.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void baseCheckDeferredResult(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber, ModifiedFromFilter filter, ReadDtoService service, boolean checkCount) {
Assert.notNull(deferredResult, "Deferred result is required to check.");
Assert.notNull(subscriber.getEntityId(), "Subscriber is required to check deferred result.");
LOG.debug("Start baseCheckDeferredResult for deferred-result [{}] and subscriber [{}]", deferredResult, subscriber);
if (checkCount) {
long countOfentities = service.count(filter);
Long lastNumberOfEntities = subscriber.getLastNumberOfEntities();
subscriber.setLastNumberOfEntities(countOfentities);
if (lastNumberOfEntities != null && countOfentities != lastNumberOfEntities) {
// Notify FE -> Some of an entities were changed (refresh must be executed)
deferredResult.setResult(new OperationResultDto(OperationState.RUNNING));
return;
}
}
ZonedDateTime timeStamp = subscriber.getLastTimeStamp();
if (timeStamp == null) {
List<AbstractDto> entities = service.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (entities.isEmpty()) {
subscriber.setLastTimeStamp(ZonedDateTime.now());
return;
}
ZonedDateTime lastModified = this.getLastTimeStamp(entities.get(0));
subscriber.setLastTimeStamp(lastModified);
return;
}
// Try to find, if some from not finished entities were changed
// TODO: For search SysSyncLogs the filter by modifiedFrom didn't work properly.
// I didn't found reason why, but I hope using sort by created and modified fields will be works better.
// filter.setModifiedFrom(timeStamp);
List<AbstractDto> changedRequestsFromLastChecks = service.find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (!changedRequestsFromLastChecks.isEmpty()) {
AbstractDto changedRequestsFromLastCheck = changedRequestsFromLastChecks.get(0);
ZonedDateTime lastModified = this.getLastTimeStamp(changedRequestsFromLastCheck);
if (lastModified.isAfter(timeStamp)) {
// Notify FE -> Some of the entity was changed (refresh must be executed).
// Notified will be all suspended request for same entity ID!
this.suspendedRequests.stream().filter(request -> request.getEntityId().equals(subscriber.getEntityId())).forEach(request -> {
request.getResult().setResult(new OperationResultDto(OperationState.RUNNING));
});
subscriber.setLastTimeStamp(lastModified);
return;
}
}
// Nothing was changed
}
Aggregations