use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormService method validate.
@Override
public List<InvalidFormAttributeDto> validate(IdmFormInstanceDto formInstance, boolean validateOnlySameOwnerType) {
Assert.notNull(formInstance, "Form instance cannot be null!");
IdmFormDefinitionDto formDefinition = formInstance.getFormDefinition();
Assert.notNull(formDefinition, "Form definition cannot be null!");
//
List<InvalidFormAttributeDto> results = Lists.newArrayList();
formDefinition.getFormAttributes().stream().forEach(formAttribute -> {
List<IdmFormValueDto> formValueForAttributes = formInstance.getValues().stream().filter(formValue -> formAttribute.getId().equals(formValue.getFormAttribute())).peek(formValue -> {
// we don't trust value persistent type - set current from attribute
formValue.setPersistentType(formAttribute.getPersistentType());
// we need owner type to perform validations
if (formValue.getOwnerType() == null && formInstance.getOwnerType() != null) {
formValue.setOwnerType(formDefinitionService.getFormableOwnerType(formInstance.getOwnerType()));
}
}).collect(//
Collectors.toList());
InvalidFormAttributeDto result = this.validateAttribute(formDefinition, formAttribute, formValueForAttributes, validateOnlySameOwnerType);
if (!result.isValid()) {
// Invalid attributes for owner => more owners can be saved together (e.g. from projection).
// ~ identifiable
result.setOwnerId(formInstance.getOwnerId());
Class<? extends Identifiable> ownerType = formInstance.getOwnerType();
if (ownerType != null) {
result.setOwnerType(lookupService.getOwnerType(ownerType));
}
results.add(result);
}
});
return results;
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormService method findFormInstances.
@Override
@Transactional(readOnly = true)
public List<IdmFormInstanceDto> findFormInstances(Identifiable owner, FormableFilter filter, BasePermission... permission) {
Assert.notNull(owner, "Form values owner is required.");
//
// filter form definitions and form attributes, if given
List<IdmFormDefinitionDto> formDefinitions;
if (filter == null || CollectionUtils.isEmpty(filter.getFormDefinitionAttributes())) {
// filter is not set => all form definitions
formDefinitions = getDefinitions(owner, !PermissionUtils.isEmpty(permission) ? IdmBasePermission.AUTOCOMPLETE : null);
} else {
// used filter definitions only.
IdmFormDefinitionFilter definitionFilter = new IdmFormDefinitionFilter();
definitionFilter.setType(getDefaultDefinitionType(owner.getClass()));
definitionFilter.setIds(filter.getFormDefinitionAttributes().stream().map(FormDefinitionAttributes::getDefinition).collect(Collectors.toList()));
//
formDefinitions = formDefinitionService.find(definitionFilter, getDefinitionPageable(), !PermissionUtils.isEmpty(permission) ? IdmBasePermission.AUTOCOMPLETE : null).getContent();
}
//
return formDefinitions.stream().map(definition -> {
return findFormInstance(owner, definition, filter, permission);
}).collect(Collectors.toList());
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method toEvent.
@Override
public EntityEvent<? extends Identifiable> toEvent(IdmEntityEventDto entityEvent) {
Identifiable content = null;
// only if type and id is the same as owner can be used
if (entityEvent.getContent() != null && Objects.equal(getOwnerType(entityEvent.getContent().getClass()), entityEvent.getOwnerType()) && Objects.equal(entityEvent.getContent().getId(), entityEvent.getOwnerId())) {
content = entityEvent.getContent();
}
if (content == null) {
// content is not persisted - try to find actual entity
content = findOwner(entityEvent);
}
if (content == null) {
throw new EventContentDeletedException(entityEvent);
}
//
Map<String, Serializable> eventProperties = entityEvent.getProperties().toMap();
eventProperties.put(EntityEvent.EVENT_PROPERTY_EVENT_ID, entityEvent.getId());
eventProperties.put(EntityEvent.EVENT_PROPERTY_PRIORITY, entityEvent.getPriority());
eventProperties.put(EntityEvent.EVENT_PROPERTY_EXECUTE_DATE, entityEvent.getExecuteDate());
eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_TYPE, entityEvent.getParentEventType());
eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_ID, entityEvent.getParent());
eventProperties.put(EntityEvent.EVENT_PROPERTY_ROOT_EVENT_ID, entityEvent.getRootId());
eventProperties.put(EntityEvent.EVENT_PROPERTY_SUPER_OWNER_ID, entityEvent.getSuperOwnerId());
eventProperties.put(EntityEvent.EVENT_PROPERTY_TRANSACTION_ID, entityEvent.getTransactionId());
final String type = entityEvent.getEventType();
DefaultEventContext<Identifiable> initContext = new DefaultEventContext<>();
initContext.setProcessedOrder(entityEvent.getProcessedOrder());
EventType eventType = (EventType) () -> type;
EntityEvent<Identifiable> resurectedEvent = new CoreEvent<>(eventType, content, eventProperties, initContext);
//
// prevent to mix content and original source types between new and parent event
Identifiable originalSource = entityEvent.getOriginalSource();
if (originalSource != null && !originalSource.getClass().equals(content.getClass())) {
// preset original source by current content -> content is already persisted in NOFIFY event
resurectedEvent.setOriginalSource(content);
} else {
resurectedEvent.setOriginalSource(originalSource);
}
//
return resurectedEvent;
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testDeleteNullValue.
@Test
public void testDeleteNullValue() {
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.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
// fill values
formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE));
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
// check value and persistent type
assertEquals(1, m.get(attributeName).size());
assertEquals(FORM_VALUE_ONE, (m.get(attributeName).get(0)).getValue());
assertEquals(attribute.getPersistentType(), (m.get(attributeName).get(0)).getPersistentType());
// update value
formService.saveValues(owner, attribute, Lists.newArrayList());
m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
//
assertNull(m.get(attributeName));
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testReadConfidentialFormValue.
@Test
public void testReadConfidentialFormValue() {
Identifiable owner = getHelper().createIdentity((GuardedString) null);
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
// save password
IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_PASSWORD));
value1.setValue(FORM_VALUE_ONE);
formService.saveValues(owner, formDefinition, Lists.newArrayList(value1));
IdmFormInstanceDto savedValues = formService.getFormInstance(owner);
assertEquals(1, savedValues.getValues().size());
assertEquals(GuardedString.SECRED_PROXY_STRING, savedValues.toSinglePersistentValue(InitDemoDataProcessor.FORM_ATTRIBUTE_PASSWORD));
}
Aggregations