use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class ExceptionUtilsUnitTest method testLogModelLevelDebug.
@Test
public void testLogModelLevelDebug() {
ExceptionUtils.log(LOG, new DefaultErrorModel(CoreResultCode.ACCEPTED), new CoreException("mock"));
// error is logged without model is specified
verify(LOG).debug(any(String.class), any(Exception.class));
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultFormService method convertConfigurationToFormDefinition.
/**
* Create instance form definition from the given configuration class
*
* @param configurationClass
* @return
*/
@Override
public IdmFormDefinitionDto convertConfigurationToFormDefinition(Class<? extends ConfigurationClass> configurationClass) {
Assert.notNull(configurationClass, "Class with the configuration is required.");
try {
ConfigurationClass configurationClassInstance = configurationClass.getDeclaredConstructor().newInstance();
List<IdmFormAttributeDto> properties = new ArrayList<>();
PropertyDescriptor[] descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
Method readMethod = descriptor.getReadMethod();
String propertyName = descriptor.getName();
ConfigurationClassProperty property = readMethod.getAnnotation(ConfigurationClassProperty.class);
if (property != null) {
IdmFormAttributeDto formAttribute = this.convertConfigurationProperty(property);
formAttribute.setCode(propertyName);
// TODO: Better convertors (move from IC and ACC module to the Core)!
initPersistentType(readMethod, formAttribute);
try {
formAttribute.setDefaultValue(this.convertDefaultValue(readMethod.invoke(configurationClassInstance), formAttribute.isMultiple()));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new CoreException("Cannot read value of connector configuration property!", e);
}
properties.add(formAttribute);
}
});
IdmFormDefinitionDto definition = new IdmFormDefinitionDto();
definition.setFormAttributes(properties);
return definition;
} catch (ReflectiveOperationException | IntrospectionException ex) {
throw new CoreException("Cannot read configuration property!", ex);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class ApproveRoleByManagerDelegationType method findDelegation.
@Override
public List<IdmDelegationDefinitionDto> findDelegation(UUID delegatorId, UUID contractId, BaseDto owner) {
Assert.isTrue(owner instanceof WorkflowTaskInstanceDto, "Owner must be workflow task for this delegation type!");
WorkflowTaskInstanceDto task = (WorkflowTaskInstanceDto) owner;
Object conceptRoleObj = taskInstanceService.getProcessVariable(task.getId(), ROLE_CONCEPT_PROPERTY);
if (conceptRoleObj instanceof VariableInstance) {
VariableInstance variableInstance = (VariableInstance) conceptRoleObj;
conceptRoleObj = variableInstance.getValue();
}
if (!(conceptRoleObj instanceof IdmConceptRoleRequestDto)) {
throw new CoreException(MessageFormat.format("For this delegation type [{0}], must workflow task contains '{1}' [WorkflowTaskInstanceDto] variable", NAME, ROLE_CONCEPT_PROPERTY));
}
IdmConceptRoleRequestDto conceptRole = (IdmConceptRoleRequestDto) conceptRoleObj;
UUID contractFromRequest = conceptRole.getIdentityContract();
Assert.notNull(contractFromRequest, "Contract ID from the concept of the request cannot be null!");
// Filtering managers contracts by subordinates contract.
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(delegatorId);
contractFilter.setManagersByContract(contractFromRequest);
List<IdmIdentityContractDto> managersContracts = identityContractService.find(contractFilter, null).getContent();
if (managersContracts.isEmpty()) {
return null;
}
Set<IdmDelegationDefinitionDto> resultDelegations = Sets.newHashSet();
// Find all valid delegation definitions for manager's contract.
managersContracts.stream().map((managersContract) -> super.findDelegation(delegatorId, managersContract.getId(), owner)).filter((delegations) -> (!CollectionUtils.isEmpty(delegations))).forEachOrdered((delegations) -> {
resultDelegations.addAll(delegations);
});
return Lists.newArrayList(resultDelegations);
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startRequest.
@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
IdmAutomaticRoleRequestDto request = get(requestId);
Assert.notNull(request, "Request is required!");
// Validation on exist some rule
if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
ruleFilter.setRoleRequestId(requestId);
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
if (ruleConcepts.isEmpty()) {
throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
}
}
try {
IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
}
return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
request = get(requestId);
Throwable exceptionToLog = ExceptionUtils.resolveException(ex);
// TODO: I set only cause of exception, not code and properties. If are
// properties set, then request cannot be save!
request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
request.setState(RequestState.EXCEPTION);
return save(request);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAttachment.
@Test
public void testAttachment() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeByte = new SysSystemAttributeMappingDto();
attributeByte.setUid(false);
attributeByte.setEntityAttribute(false);
attributeByte.setExtendedAttribute(true);
attributeByte.setIdmPropertyName(getHelper().createName());
attributeByte.setName(descriptionSchemaAttribute.getName());
attributeByte.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeByte.setSystemMapping(defaultMapping.getId());
// Transformation data to string
attributeByte.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " return new String(attributeValue.getData());");
schemaAttributeMappingService.save(attributeByte);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
// Set type of attribute to attachment
IdmFormAttributeDto eavAttributeByte = formService.getAttribute(IdmIdentityDto.class, attributeByte.getIdmPropertyName());
eavAttributeByte.setPersistentType(PersistentType.ATTACHMENT);
eavAttributeByte = formService.saveAttribute(eavAttributeByte);
// Create attachment with content
String originalContent = getHelper().createName();
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setName("test.txt");
attachment.setMimetype("text/plain");
attachment.setInputData(IOUtils.toInputStream(originalContent));
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment = attachmentManager.saveAttachment(null, attachment);
InputStream inputStream = attachmentManager.getAttachmentData(attachment.getId());
try {
String content = IOUtils.toString(inputStream);
assertEquals(originalContent, content);
// Create form value with attachment
IdmIdentityDto identity = helper.createIdentity();
formService.saveValues(identity, eavAttributeByte, Lists.newArrayList(attachment.getId()));
// Assign the system
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
InputStream is = attachmentManager.getAttachmentData(attachment.getId());
try {
String data = new String(IOUtils.toByteArray(is));
assertEquals(data, valueOnResource);
} finally {
IOUtils.closeQuietly(is);
}
} catch (IOException e) {
throw new CoreException(e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
Aggregations