use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method initRequest.
/**
* Init new request (without save)
*
* @param request
* @param dto
*/
private <R extends Requestable> void initRequest(IdmRequestDto request, R dto) {
request.setState(RequestState.CONCEPT);
request.setOwnerId((UUID) dto.getId());
request.setOwnerType(dto.getClass().getName());
request.setExecuteImmediately(false);
request.setRequestType(dto.getClass().getSimpleName());
request.setResult(new OperationResultDto(OperationState.CREATED));
if (dto instanceof Codeable && ((Codeable) dto).getCode() != null) {
request.setName(((Codeable) dto).getCode());
}
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method accountManagement.
@Override
public boolean accountManagement(DTO dto) {
SystemEntityType entityType = SystemEntityType.getByClass(dto.getClass());
List<SysSystemMappingDto> systemMappings = findSystemMappingsForEntityType(dto, entityType);
systemMappings.forEach(mapping -> {
SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
UUID systemId = schemaObjectClassDto.getSystem();
UUID accountId = this.getAccountByEntity(dto.getId(), systemId);
if (accountId != null) {
// We already have account for this system -> next
return;
}
SysSystemDto system = DtoUtils.getEmbedded(schemaObjectClassDto, SysSchemaObjectClass_.system);
List<SysSystemAttributeMappingDto> mappedAttributes = attributeMappingService.findBySystemMapping(mapping);
SysSystemAttributeMappingDto uidAttribute = attributeMappingService.getUidAttribute(mappedAttributes, system);
String uid = attributeMappingService.generateUid(dto, uidAttribute);
// Account management - can be the account created? - execute the script on the system mapping
if (!this.canBeAccountCreated(uid, dto, mapping, system)) {
String entityStr = dto.toString();
if (dto instanceof Codeable) {
entityStr = ((Codeable) dto).getCode();
}
LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", entityStr, entityType, system.getName()));
return;
}
// Create AccAccount and relation between account and entity
createEntityAccount(uid, dto.getId(), systemId);
});
return true;
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testFindByCodeable.
/**
* Test search by external identifier, if DTO implements {@link ExternalIdentifiable}
*
* @throws Exception
*/
@Test
public void testFindByCodeable() {
if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
LOG.warn("Controller [{}] doesn't support DataFilter. Find by codeable will not be tested.", getController().getClass());
return;
}
//
DTO dto = prepareDto();
if (!(dto instanceof Codeable)) {
// ignore test
return;
}
Codeable codeable = (Codeable) dto;
if (StringUtils.isEmpty(codeable.getCode())) {
throw new CoreException("Code has to be set by #prepareDto method, its required by default");
}
//
DTO createdDto = createDto(dto);
// mock dto
createDto(prepareDto());
//
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set(DataFilter.PARAMETER_CODEABLE_IDENTIFIER, codeable.getCode());
//
List<DTO> results = find(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
//
if (supportsAutocomplete()) {
results = autocomplete(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
} else {
LOG.info("Controller [{}] doesn't support autocomplete method. Method will not be tested.", getController().getClass());
}
//
Assert.assertEquals(1, count(parameters));
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method changeRevisionDto.
private void changeRevisionDto(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAuditDto revisionEntity, RevisionType revisionType) {
// List<String> changedColumns;
// name of entity class - full name.
revisionEntity.setType(entityName);
// revision type - MOD, DEL, ADD
revisionEntity.setModification(revisionType.name());
// action executer identity
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentModifierIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalModifierIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
revisionEntity.setModifier(securityService.getUsername());
revisionEntity.setModifierId(currentModifierIdentity == null ? null : currentModifierIdentity.getId());
// original action executer identity (before switch)
revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
revisionEntity.setOriginalModifierId(originalModifierIdentity == null ? null : originalModifierIdentity.getId());
// entity id
revisionEntity.setEntityId((UUID) entityId);
//
// get entity in new transaction if revision type is delete
AbstractEntity currentEntity = null;
if (revisionType == RevisionType.DEL) {
currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
} else {
currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
}
//
if (currentEntity instanceof AuditSearchable) {
AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
revisionEntity.setOwnerId(searchableEntity.getOwnerId());
revisionEntity.setOwnerType(searchableEntity.getOwnerType());
revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
} else if (currentEntity instanceof Codeable) {
revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
}
// transaction id
revisionEntity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
use of eu.bcvsolutions.idm.core.api.domain.Codeable in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method testCreateForm.
@Test
@Transactional
public void testCreateForm() {
Codeable owner = helper.createIdentity();
IdmFormAttributeDto attribute = createDefinition();
IdmFormValueDto formValue = new IdmFormValueDto(attribute);
formValue.setValue("testOne");
IdmFormDto formOne = new IdmFormDto();
formOne.setName("test");
formOne.setFormDefinition(attribute.getFormDefinition());
formOne.setValues(Lists.newArrayList(formValue));
formOne.setOwnerCode(owner.getCode());
//
commonFormService.saveForm(owner, formOne);
formOne = commonFormService.getForms(owner).get(0);
//
Assert.assertNotNull(formOne.getId());
Assert.assertEquals(owner.getCode(), formOne.getOwnerCode());
Assert.assertEquals(lookupService.lookupEntity(owner.getClass(), owner.getId()).getClass().getCanonicalName(), formOne.getOwnerType());
Assert.assertEquals(owner.getId(), formOne.getOwnerId());
Assert.assertEquals(formValue.getValue(), formOne.getValues().get(0).getValue());
//
commonFormService.deleteForms(owner);
Assert.assertTrue(commonFormService.getForms(owner).isEmpty());
}
Aggregations