public PropertyDescriptorEntity getPropertyDescriptor(Integer propertyDescriptorId) { return propertyDescriptorService.getPropertyDescriptorWithTags(propertyDescriptorId); }
/** * Deletes PropertyDescriptors and their PropertyTags PropertyDescriptors to be deleted must not have any Properties * The owner is ignored - therefore this method deletes the property descriptor regardless of the foreignable ownership! */ public void deletePropertyDescriptorByOwnerInResourceContext(PropertyDescriptorEntity descriptorToDelete, AbstractContext abstractContext, int resourceId) throws AMWException { auditService.setResourceIdInThreadLocal(resourceId); PropertyDescriptorEntity descriptorToDeleteWithTags = getPropertyDescriptorWithTags(descriptorToDelete.getId()); removePropertyDescriptorByOwner(descriptorToDeleteWithTags, abstractContext, false); }
/** * Deletes PropertyDescriptors and their PropertyTags PropertyDescriptors to be deleted must not have any * Properties * The owner is ignored - therefore this method deletes the property descriptor regardless of the foreignable ownership! */ public void deletePropertyDescriptorByOwnerInResourceTypeContext(PropertyDescriptorEntity descriptorToDelete, AbstractContext abstractContext, int resourceTypeId) throws AMWException { auditService.setResourceTypeIdInThreadLocal(resourceTypeId); PropertyDescriptorEntity descriptorToDeleteWithTags = getPropertyDescriptorWithTags(descriptorToDelete.getId()); removePropertyDescriptorByOwner(descriptorToDeleteWithTags, abstractContext, false); }
@Test public void shouldStoreResourceTypeIdInThreadLocalDuringPropertyUpdateInResourceTypeContext() throws AMWException { // given Integer resourceTypeIdForAuditLog = 1; ForeignableOwner deletingOwner = ForeignableOwner.AMW; Set<PropertyEntity> properties = new HashSet<>(); properties.add(new PropertyEntity()); PropertyDescriptorEntity descriptor = new PropertyDescriptorEntityBuilder().withOwner(deletingOwner).withId(1).withProperties(properties).build(); AbstractContext abstractContextMock = mock(AbstractContext.class); doNothing().when(service).removePropertyDescriptorByOwner(eq(descriptor), eq(abstractContextMock), anyBoolean()); doReturn(descriptor).when(service).getPropertyDescriptorWithTags(anyInt()); // when service.deletePropertyDescriptorByOwnerInResourceTypeContext(descriptor, abstractContextMock, resourceTypeIdForAuditLog); // then assertThat("The resourceTypeId Param must be stored as ThreadLocal variable for auditing (envers)", ThreadLocalUtil.getThreadVariable(ThreadLocalUtil.KEY_RESOURCE_TYPE_ID), is(CoreMatchers.notNullValue())); int resourceTypeId = (int) ThreadLocalUtil.getThreadVariable(ThreadLocalUtil.KEY_RESOURCE_TYPE_ID); assertThat(resourceTypeId, is(resourceTypeIdForAuditLog)); }
@Test public void shouldStoreResourceIdInThreadLocalForDuringPropertyUpdateInResourceContext() throws AMWException { // given Integer resourceIdForAuditLog = 200; ForeignableOwner deletingOwner = ForeignableOwner.AMW; Set<PropertyEntity> properties = new HashSet<>(); properties.add(new PropertyEntity()); PropertyDescriptorEntity descriptor = new PropertyDescriptorEntityBuilder().withOwner(deletingOwner).withId(1).withProperties(properties).build(); AbstractContext abstractContextMock = mock(AbstractContext.class); doNothing().when(service).removePropertyDescriptorByOwner(eq(descriptor), eq(abstractContextMock), anyBoolean()); doReturn(descriptor).when(service).getPropertyDescriptorWithTags(anyInt()); // when service.deletePropertyDescriptorByOwnerInResourceContext(descriptor, abstractContextMock, resourceIdForAuditLog); // then assertThat("The resourceId Param must be stored as ThreadLocal variable for auditing (envers)", ThreadLocalUtil.getThreadVariable(ThreadLocalUtil.KEY_RESOURCE_ID), is(CoreMatchers.notNullValue())); int resourceId = (int) ThreadLocalUtil.getThreadVariable(ThreadLocalUtil.KEY_RESOURCE_ID); assertThat(resourceId, is(resourceIdForAuditLog)); }
/** * Deletes PropertyDescriptors and their PropertyTags PropertyDescriptors including all its Properties * The owner is ignored - therefore this method deletes the property descriptor regardless of the foreignable ownership! */ public void deletePropertyDescriptorByOwnerIncludingPropertyValues(PropertyDescriptorEntity descriptorToDelete, AbstractContext abstractContext, HasContexts attachedResource) throws AMWException { PropertyDescriptorEntity descriptorToDeleteWithTags = getPropertyDescriptorWithTags(descriptorToDelete.getId()); Set<PropertyEntity> propertiesToBeDeleted = descriptorToDeleteWithTags.getProperties(); Set<ContextDependency> resourceContexts = attachedResource.getContexts(); auditService.storeIdInThreadLocalForAuditLog(attachedResource); for (ContextDependency context : resourceContexts) { if (context.getProperties().size() > 0) { for (PropertyEntity property : propertiesToBeDeleted) { context.removeProperty(property); } } if (context.getPropertyDescriptors().size() > 0) { context.removePropertyDescriptor(descriptorToDelete); } } if (attachedResource instanceof ResourceEntity) { removeRelationPropertyValues((ResourceEntity) attachedResource, propertiesToBeDeleted); } else if (attachedResource instanceof ResourceTypeEntity) { removeInstancePropertyValues((ResourceTypeEntity) attachedResource, propertiesToBeDeleted); removeRelationPropertyValues((ResourceTypeEntity) attachedResource, propertiesToBeDeleted); } removePropertyDescriptorByOwner(descriptorToDeleteWithTags, abstractContext, true); }