Search in sources :

Example 6 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerIntegrationTest method testUpdateAttachment.

@Test
@Transactional
public void testUpdateAttachment() {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String contentOne = "test data 1";
    IdmAttachmentDto attachment = prepareAttachment(contentOne);
    attachment = attachmentManager.saveAttachment(owner, attachment);
    // 
    String updatedContent = "update";
    attachment.setInputData(IOUtils.toInputStream(updatedContent));
    attachment.setDescription(updatedContent);
    attachment = attachmentManager.updateAttachment(attachment);
    // 
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachmentVersions(attachment.getId());
    // 
    Assert.assertEquals(1, attachments.size());
    IdmAttachmentDto createdAttachment = attachments.get(0);
    Assert.assertEquals(attachment.getName(), createdAttachment.getName());
    Assert.assertEquals(attachment.getMimetype(), createdAttachment.getMimetype());
    Assert.assertEquals(owner.getClass().getCanonicalName(), createdAttachment.getOwnerType());
    Assert.assertEquals(owner.getId(), createdAttachment.getOwnerId());
    Assert.assertNotNull(createdAttachment.getContentId());
    Assert.assertNotNull(createdAttachment.getContentPath());
    Assert.assertNull(createdAttachment.getParent());
    Assert.assertNull(createdAttachment.getNextVersion());
    Assert.assertEquals(Integer.valueOf(1), createdAttachment.getVersionNumber());
    Assert.assertEquals("1.0", createdAttachment.getVersionLabel());
    Assert.assertEquals(AttachableEntity.DEFAULT_ENCODING, createdAttachment.getEncoding());
    Assert.assertEquals(Long.valueOf(updatedContent.getBytes(AttachableEntity.DEFAULT_CHARSET).length), createdAttachment.getFilesize());
    Assert.assertEquals(updatedContent, createdAttachment.getDescription());
    // 
    attachmentManager.deleteAttachment(attachment);
    // 
    Assert.assertEquals(0, attachmentManager.getAttachmentVersions(attachment.getId()).size());
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class CodeableEvaluator method lookupEntity.

/**
 * Find entity by identifiable object ... this is little strange (we find entity only for adding it to other search)
 *
 * @param policy
 * @return
 */
@SuppressWarnings("unchecked")
private BaseEntity lookupEntity(AuthorizationPolicy policy) {
    Object identifier = policy.getEvaluatorProperties().get(PARAMETER_IDENTIFIER);
    if (identifier == null || StringUtils.isEmpty(policy.getAuthorizableType())) {
        return null;
    }
    // find entity by identifiable object ... this is little strange (we find entity only for adding it to other search)
    BaseEntity entity;
    try {
        entity = lookupService.lookupEntity((Class<? extends Identifiable>) Class.forName(policy.getAuthorizableType()), identifier.toString());
    } catch (ClassNotFoundException ex) {
        LOG.warn("Class for name [{}] not found - skipping", policy.getAuthorizableType());
        return null;
    } catch (IllegalArgumentException ex) {
        LOG.warn("Authorizable type [{}] does not support entity lookup - skipping", policy.getAuthorizableType(), ex);
        return null;
    }
    if (entity == null) {
        LOG.debug("Entity for type [{}] and code [{}] wasn't found - skipping", policy.getAuthorizableType(), identifier);
        return null;
    }
    return entity;
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Example 8 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersions.

@Test
@Transactional
public void testAttachmentVersions() throws IOException {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String contentOne = "test data 1";
    IdmAttachmentDto attachmentOne = prepareAttachment(contentOne);
    attachmentOne = attachmentManager.saveAttachment(owner, attachmentOne);
    String contentTwo = "test data 2";
    IdmAttachmentDto attachmentTwo = prepareAttachment(contentTwo);
    attachmentTwo = attachmentManager.saveAttachmentVersion(owner, attachmentTwo, attachmentOne);
    String contentThree = "test data 3";
    IdmAttachmentDto attachmentThree = prepareAttachment(contentThree);
    attachmentThree = attachmentManager.saveAttachmentVersion(owner, attachmentThree, attachmentTwo);
    // 
    Assert.assertNotNull(attachmentManager.get(attachmentOne));
    Assert.assertNotNull(attachmentManager.get(attachmentTwo));
    Assert.assertNotNull(attachmentManager.get(attachmentThree));
    // 
    // last version only
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(owner, null).getContent();
    Assert.assertEquals(1, attachments.size());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // 
    attachments = attachmentManager.getAttachmentVersions(attachmentOne.getId());
    Assert.assertEquals(3, attachments.size());
    // three
    Assert.assertEquals(Integer.valueOf(3), attachments.get(0).getVersionNumber());
    Assert.assertEquals("3.0", attachments.get(0).getVersionLabel());
    Assert.assertNull(attachments.get(0).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(0).getParent());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // two
    Assert.assertEquals(Integer.valueOf(2), attachments.get(1).getVersionNumber());
    Assert.assertEquals("2.0", attachments.get(1).getVersionLabel());
    Assert.assertEquals(attachmentThree.getId(), attachments.get(1).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(1).getParent());
    Assert.assertEquals(contentTwo, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(1).getId())));
    // one
    Assert.assertEquals(Integer.valueOf(1), attachments.get(2).getVersionNumber());
    Assert.assertEquals("1.0", attachments.get(2).getVersionLabel());
    Assert.assertEquals(attachmentTwo.getId(), attachments.get(2).getNextVersion());
    Assert.assertNull(attachments.get(2).getParent());
    Assert.assertEquals(contentOne, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(2).getId())));
    // 
    attachmentManager.deleteAttachment(attachmentThree);
    // 
    Assert.assertNull(attachmentManager.get(attachmentOne));
    Assert.assertNull(attachmentManager.get(attachmentTwo));
    Assert.assertNull(attachmentManager.get(attachmentThree));
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method testResurrectEventWithLoadedContent.

@Test
public void testResurrectEventWithLoadedContent() {
    IdmIdentityDto mockOwner = new IdmIdentityDto(UUID.randomUUID());
    IdmEntityEventDto entityEvent = new IdmEntityEventDto(UUID.randomUUID());
    entityEvent.setOwnerType(IdmIdentity.class.getCanonicalName());
    entityEvent.setOwnerId((UUID) mockOwner.getId());
    entityEvent.setEventType(CoreEventType.NOTIFY.name());
    // 
    when(lookupService.lookupDto(IdmIdentity.class, mockOwner.getId())).thenReturn(mockOwner);
    // 
    EntityEvent<Identifiable> event = eventManager.toEvent(entityEvent);
    // 
    Assert.assertEquals(mockOwner, event.getContent());
    Assert.assertEquals(CoreEventType.NOTIFY.name(), event.getType().name());
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 10 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method putToQueue.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void putToQueue(IdmEntityEventDto entityEvent) {
    if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
        executeEvent(entityEvent);
        return;
    }
    if (!eventConfiguration.isAsynchronous()) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously, asynchronous event processing [{}] is disabled.", entityEvent.getEventType(), entityEvent.getOwnerId(), EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED);
        executeEvent(entityEvent);
        return;
    }
    // 
    // get enabled processors
    final EntityEvent<Identifiable> event = toEvent(entityEvent);
    List<EntityEventProcessor> registeredProcessors = context.getBeansOfType(EntityEventProcessor.class).values().stream().filter(enabledEvaluator::isEnabled).filter(processor -> !processor.isDisabled()).filter(processor -> processor.supports(event)).filter(processor -> processor.conditional(event)).sorted(new AnnotationAwareOrderComparator()).collect(Collectors.toList());
    if (registeredProcessors.isEmpty()) {
        LOG.debug("Event type [{}] for owner with id [{}] will not be executed, no enabled processor is registered.", entityEvent.getEventType(), entityEvent.getOwnerId());
        return;
    }
    // 
    // evaluate event priority by registered processors
    PriorityType priority = evaluatePriority(event, registeredProcessors);
    if (priority != null && priority.getPriority() < entityEvent.getPriority().getPriority()) {
        entityEvent.setPriority(priority);
    }
    // registered processors voted about event will be processed synchronously
    if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
        LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
        executeEvent(entityEvent);
        return;
    }
    // 
    // notification - info about registered (asynchronous) processors
    Map<String, Object> parameters = new LinkedHashMap<>();
    parameters.put("eventType", entityEvent.getEventType());
    parameters.put("ownerId", entityEvent.getOwnerId());
    parameters.put("instanceId", entityEvent.getInstanceId());
    parameters.put("processors", registeredProcessors.stream().map(DefaultEntityEventManager.this::toDto).collect(Collectors.toList()));
    notificationManager.send(CoreModuleDescriptor.TOPIC_EVENT, new IdmMessageDto.Builder().setLevel(NotificationLevel.INFO).setModel(new DefaultResultModel(CoreResultCode.EVENT_ACCEPTED, parameters)).build());
    // 
    // persist event - asynchronous processing
    entityEventService.save(entityEvent);
}
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) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) LinkedHashMap(java.util.LinkedHashMap) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor)

Aggregations

Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)11 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)4 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)3 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)3 EventContentDeletedException (eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException)3 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Serializable (java.io.Serializable)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2 DefaultEventContext (eu.bcvsolutions.idm.core.api.event.DefaultEventContext)2 EntityEventType (eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType)2 EventType (eu.bcvsolutions.idm.core.api.event.EventType)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Objects (com.google.common.base.Objects)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)1