Search in sources :

Example 16 with ResultModel

use of eu.bcvsolutions.idm.core.api.dto.ResultModel in project CzechIdMng by bcvsolutions.

the class IdmMessageDtoUnitTest method testModelError.

@Test
public void testModelError() {
    ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR);
    IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
    Assert.assertEquals(model.getStatusEnum(), message.getSubject());
    Assert.assertEquals(model.getMessage(), message.getTextMessage());
    Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
    Assert.assertEquals(NotificationLevel.ERROR, message.getLevel());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 17 with ResultModel

use of eu.bcvsolutions.idm.core.api.dto.ResultModel in project CzechIdMng by bcvsolutions.

the class IdmMessageDtoUnitTest method testModelWarning.

@Test
public void testModelWarning() {
    ResultModel model = new DefaultResultModel(CoreResultCode.BAD_VALUE);
    IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
    Assert.assertEquals(model.getStatusEnum(), message.getSubject());
    Assert.assertEquals(model.getMessage(), message.getTextMessage());
    Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
    Assert.assertEquals(NotificationLevel.WARNING, message.getLevel());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 18 with ResultModel

use of eu.bcvsolutions.idm.core.api.dto.ResultModel 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);
        });
    });
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Sort(org.springframework.data.domain.Sort) Objects(com.google.common.base.Objects) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) CreatedComparator(eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) DateTime(org.joda.time.DateTime) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Example 19 with ResultModel

use of eu.bcvsolutions.idm.core.api.dto.ResultModel in project CzechIdMng by bcvsolutions.

the class DefaultProvisioningExecutor method persistOperation.

/**
 * Persist new operation
 *
 * @param provisioningOperation
 * @return
 */
private SysProvisioningOperationDto persistOperation(SysProvisioningOperationDto provisioningOperation) {
    Assert.notNull(provisioningOperation);
    Assert.notNull(provisioningOperation.getSystemEntity());
    Assert.notNull(provisioningOperation.getProvisioningContext());
    // get system from service, in provisioning operation may not exist
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    Assert.notNull(system);
    // make sure system will be in embedded
    provisioningOperation.getEmbedded().put(SysProvisioningOperation_.system.getName(), system);
    // 
    // save new operation to provisioning log / queue
    String uid = systemEntityService.getByProvisioningOperation(provisioningOperation).getUid();
    SysProvisioningBatchDto batch = batchService.findBatch(system.getId(), provisioningOperation.getEntityIdentifier(), provisioningOperation.getSystemEntity());
    if (batch == null) {
        batch = batchService.save(new SysProvisioningBatchDto());
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
    } else {
        // put to queue, if previous
        ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_IS_IN_QUEUE, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass()));
        LOG.debug(resultModel.toString());
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
        if (securityService.getCurrentId() != null) {
            // TODO: check logged identity and account owner
            notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder(NotificationLevel.WARNING).setModel(provisioningOperation.getResult().getModel()).build());
        }
    }
    provisioningOperation.setBatch(batch.getId());
    provisioningOperation = provisioningOperationService.save(provisioningOperation);
    // 
    return provisioningOperation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 20 with ResultModel

use of eu.bcvsolutions.idm.core.api.dto.ResultModel in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method handleSuccessful.

@Override
@Transactional
public SysProvisioningOperationDto handleSuccessful(SysProvisioningOperationDto operation) {
    SysSystemDto system = systemService.get(operation.getSystem());
    String uid = this.getByProvisioningOperation(operation).getUid();
    ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SUCCEED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
    operation.setResult(new OperationResult.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    operation = save(operation);
    // 
    LOG.debug(resultModel.toString());
    if (securityService.getCurrentId() != null) {
        // TODO: check account owner
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
    }
    return operation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)20 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)20 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)13 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)6 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)5 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)4 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)3 SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 PageRequest (org.springframework.data.domain.PageRequest)2 Objects (com.google.common.base.Objects)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1