Search in sources :

Example 46 with Identifiable

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

the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersions.

@Test
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());
    InputStream is = attachmentManager.getAttachmentData(attachments.get(0).getId());
    try {
        Assert.assertEquals(contentThree, IOUtils.toString(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    // 
    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());
    is = attachmentManager.getAttachmentData(attachments.get(0).getId());
    try {
        Assert.assertEquals(contentThree, IOUtils.toString(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    // 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());
    is = attachmentManager.getAttachmentData(attachments.get(1).getId());
    try {
        Assert.assertEquals(contentTwo, IOUtils.toString(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    // 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());
    is = attachmentManager.getAttachmentData(attachments.get(2).getId());
    try {
        Assert.assertEquals(contentOne, IOUtils.toString(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    // 
    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) InputStream(java.io.InputStream) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 47 with Identifiable

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

the class AbstractReadDtoService method getEntity.

/**
 * Returns entity by given id. Returns null, if entity is not exists. For
 * AbstractEntity uuid or uuid as string could be given.
 */
protected E getEntity(Serializable id, BasePermission... permission) {
    if (id instanceof Identifiable) {
        // dto or entity could be given
        id = ((Identifiable) id).getId();
    }
    // resolve identifier
    UUID identifier;
    if (AbstractEntity.class.isAssignableFrom(getEntityClass()) && (id instanceof String)) {
        // different argument type
        try {
            identifier = UUID.fromString((String) id);
        } catch (IllegalArgumentException ex) {
            // simply not found
            LOG.trace("Identity cannot be found by given identifier [{}]", id);
            // 
            return null;
        }
    } else {
        identifier = (UUID) id;
    }
    // get entity
    E entity = getRepository().findById(identifier).orElse(null);
    // 
    LOG.trace("Entity found [{}], permissions [{}] will be evaluated ...", entity, permission);
    entity = checkAccess(entity, permission);
    // 
    LOG.trace("Entity [{}] passed permission check [{}]", entity, permission);
    return entity;
}
Also used : AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) UUID(java.util.UUID) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Example 48 with Identifiable

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

the class IdmLongRunningTaskItemController method loadEmbeddedEntity.

/**
 * Fills referenced entity to dto - prevent to load entity for each row
 *
 * @param dto
 */
@SuppressWarnings("unchecked")
private void loadEmbeddedEntity(Map<UUID, BaseDto> loadedDtos, IdmProcessedTaskItemDto dto) {
    UUID entityId = dto.getReferencedEntityId();
    try {
        BaseDto item = null;
        if (!loadedDtos.containsKey(entityId)) {
            String referencedDtoType = dto.getReferencedDtoType();
            item = getLookupService().lookupDto(referencedDtoType, entityId);
            // try to find in audit for deleted entities
            if (item == null) {
                dto.setDeleted(true);
                Object lastPersistedVersion = auditService.findLastPersistedVersion(getLookupService().getEntityClass((Class<? extends Identifiable>) Class.forName(referencedDtoType)), entityId);
                if (lastPersistedVersion != null) {
                    item = getLookupService().toDto((BaseEntity) lastPersistedVersion, null, null);
                }
            }
            loadedDtos.put(entityId, item);
        }
        dto.getEmbedded().put(IdmProcessedTaskItem_.referencedEntityId.getName(), loadedDtos.get(entityId));
    } catch (IllegalArgumentException | ClassNotFoundException ex) {
        LOG.debug("Class [{}] not found on classpath (e.g. module was uninstalled)", dto.getReferencedDtoType(), ex);
    }
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) UUID(java.util.UUID) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Example 49 with Identifiable

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

the class FormValueDeleteBulkActionIntegrationTest method processBulkActionByIds.

@Test
public void processBulkActionByIds() {
    Identifiable owner = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition with attribute
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attribute.getCode());
    attribute.setMultiple(true);
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    // 
    // fill values
    formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
    Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    // check value and persistent type
    Assert.assertEquals(2, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_ONE)));
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmFormValue.class, FormValueDeleteBulkAction.NAME);
    Set<UUID> ids = new HashSet<>();
    ids.add(m.get(attributeName).stream().filter(v -> v.getValue().equals(FORM_VALUE_ONE)).findFirst().get().getId());
    bulkAction.setIdentifiers(ids);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1l, null, null);
    m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    Assert.assertEquals(1, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
}
Also used : ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ObserveLongRunningTaskEndProcessor(eu.bcvsolutions.idm.core.scheduler.ObserveLongRunningTaskEndProcessor) IdmFormValue(eu.bcvsolutions.idm.core.eav.entity.IdmFormValue) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) After(org.junit.After) Before(org.junit.Before) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 50 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)

Aggregations

Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)51 Test (org.junit.Test)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)32 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)31 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)27 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)24 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)24 List (java.util.List)19 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 UUID (java.util.UUID)16 ArrayList (java.util.ArrayList)14 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)12 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Lists (com.google.common.collect.Lists)10 Serializable (java.io.Serializable)10 HashSet (java.util.HashSet)10 Map (java.util.Map)10 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)9