use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.
the class IdmEntityStateController method toFilter.
@Override
protected IdmEntityStateFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmEntityStateFilter filter = new IdmEntityStateFilter(parameters);
filter.setCreatedFrom(getParameterConverter().toDateTime(parameters, "createdFrom"));
filter.setCreatedTill(getParameterConverter().toDateTime(parameters, "createdTill"));
filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
//
String ownerId = getParameterConverter().toString(parameters, "ownerId");
if (StringUtils.isNotEmpty(filter.getOwnerType()) && StringUtils.isNotEmpty(ownerId)) {
// try to find entity owner by Codeable identifier
AbstractDto owner = manager.findOwner(filter.getOwnerType(), ownerId);
if (owner != null) {
filter.setOwnerId(owner.getId());
} else {
throw new ResultCodeException(CoreResultCode.BAD_VALUE, "Entity type [%s] with identifier [%s] does not found", ImmutableMap.of("entityClass", filter.getOwnerType(), "identifier", ownerId));
}
} else {
filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
}
filter.setEventId(getParameterConverter().toUuid(parameters, "eventId"));
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmEntityEventService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmEntityEventDto dto) {
if (repository.countByParentId(dto.getId()) > 0) {
throw new EventDeleteFailedHasChildrenException(dto);
}
// delete states
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setEventId(dto.getId());
entityStateService.find(filter, null).forEach(state -> {
entityStateService.delete(state);
});
//
// TODO: delete confidential properties
//
super.deleteInternal(dto);
// delete parent if children count is one (=> removed dto only)
if (dto.getParent() != null) {
if (repository.countByParentId(dto.getParent()) == 0) {
// delete parent
deleteById(dto.getParent());
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method init.
/**
* Cancel all previously ran events
*/
@Override
public void init() {
LOG.info("Cancel unprocessed events - event was interrupt during instance restart");
//
String instanceId = configurationService.getInstanceId();
entityEventService.findByState(instanceId, OperationState.RUNNING).forEach(event -> {
LOG.info("Cancel unprocessed event [{}] - event was interrupt during instance [{}] restart", event.getId(), instanceId);
//
// cancel event
ResultModel resultModel = new DefaultResultModel(CoreResultCode.EVENT_CANCELED_BY_RESTART, ImmutableMap.of("eventId", event.getId(), "eventType", event.getEventType(), "ownerId", String.valueOf(event.getOwnerId()), "instanceId", event.getInstanceId()));
OperationResultDto result = new OperationResultDto.Builder(OperationState.CANCELED).setModel(resultModel).build();
event.setResult(result);
entityEventService.saveInternal(event);
//
// cancel event states
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setEventId(event.getId());
entityStateService.find(filter, null).getContent().stream().filter(state -> {
return OperationState.RUNNING == state.getResult().getState();
}).forEach(state -> {
event.setResult(result);
entityStateService.save(state);
});
});
}
Aggregations