use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractReadDtoService method toDtos.
/**
* Converts list of entities to list of DTOs.
* Method check returned value from method {@link AbstractReadDtoService#supportsToDtoWithFilter()}.
* If the method {@link AbstractReadDtoService#supportsToDtoWithFilter()} return true
* the method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto, BaseFilter)} will be called.
* Otherwise will be called method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto)}.
*
* @param entities
* @param trimmed
* @param filter
* @return
*/
protected List<DTO> toDtos(List<E> entities, boolean trimmed, F filter) {
if (entities == null) {
return null;
}
List<DTO> dtos = new ArrayList<>();
entities.forEach(entity -> {
try {
DTO newDto = this.getDtoClass(entity).getDeclaredConstructor().newInstance();
if (newDto instanceof AbstractDto) {
((AbstractDto) newDto).setTrimmed(trimmed);
}
DTO dto = null;
// Check if service support filter mapping and use it for transform entity to DTO
if (supportsToDtoWithFilter()) {
dto = this.toDto(entity, newDto, filter);
} else {
dto = this.toDto(entity, newDto);
}
dtos.add(dto);
} catch (ReflectiveOperationException ex) {
throw new CoreException(ex);
}
});
return dtos;
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class RequestApprovalProcessor method process.
@SuppressWarnings("unchecked")
@Override
public EventResult<IdmRequestDto> process(EntityEvent<IdmRequestDto> event) {
IdmRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
//
String ownerTyp = dto.getOwnerType();
Assert.notNull(ownerTyp, "Owner type is rquired for start approval process!");
Class<Requestable> ownerClass = null;
try {
ownerClass = (Class<Requestable>) Class.forName(ownerTyp);
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
String wfDefinition = requestConfiguration.getRequestApprovalProcessKey(ownerClass);
if (Strings.isNullOrEmpty(wfDefinition)) {
throw new ResultCodeException(CoreResultCode.REQUEST_NO_WF_DEF_FOUND, ImmutableMap.of("entityType", dto.getOwnerType()));
}
boolean approved = manager.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManager method getTask.
/**
* Returns task by given key
*
* @param jobKey
* @return task dto
*/
@SuppressWarnings("unchecked")
private Task getTask(JobKey jobKey) {
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
// job does not exists
return null;
}
Task task = new Task();
// task setting
task.setId(jobKey.getName());
// app context is needed here
SchedulableTaskExecutor<?> taskExecutor = (SchedulableTaskExecutor<?>) context.getAutowireCapableBeanFactory().createBean(jobDetail.getJobClass());
task.setTaskType((Class<? extends SchedulableTaskExecutor<?>>) AutowireHelper.getTargetClass(taskExecutor));
task.setDescription(jobDetail.getDescription());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
task.setInstanceId(jobDataMap.getString(SchedulableTaskExecutor.PARAMETER_INSTANCE_ID));
task.setModified((ZonedDateTime) jobDataMap.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
task.setTriggers(new ArrayList<>());
// task properties
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
task.getParameters().put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString());
}
task.setDisabled(taskExecutor.isDisabled());
if (!task.isDisabled()) {
task.setSupportsDryRun(taskExecutor.supportsDryRun());
task.setFormDefinition(taskExecutor.getFormDefinition());
task.setRecoverable(taskExecutor.isRecoverable());
} else {
LOG.warn("Task [{}] is disabled and cannot be executed, remove schedule for this task to hide this warning.", task.getTaskType().getSimpleName());
}
// scheduled triggers - native
for (Trigger trigger : scheduler.getTriggersOfJob(jobKey)) {
TriggerState state = scheduler.getTriggerState(trigger.getKey());
if (trigger instanceof CronTrigger) {
task.getTriggers().add(new CronTaskTrigger(task.getId(), (CronTrigger) trigger, TaskTriggerState.convert(state)));
} else if (trigger instanceof SimpleTrigger) {
task.getTriggers().add(new SimpleTaskTrigger(task.getId(), (SimpleTrigger) trigger, TaskTriggerState.convert(state)));
} else {
LOG.warn("Job '{}' ({}) has registered trigger of unsupported type {}", jobKey, jobDetail.getJobClass(), trigger);
}
}
// dependent tasks
dependentTaskTriggerRepository.findByDependentTaskId(jobKey.getName()).forEach(dependentTask -> {
task.getTriggers().add(new DependentTaskTrigger(task.getId(), dependentTask.getId(), dependentTask.getInitiatorTaskId()));
});
return task;
} catch (org.quartz.SchedulerException ex) {
if (ex.getCause() instanceof ClassNotFoundException) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
return null;
}
throw new CoreException(ex);
} catch (BeansException | IllegalArgumentException ex) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
return null;
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method resolveFormValue.
/**
* Resolve form value
*
* @param formValue
* @return
*/
private Object resolveFormValue(IdmFormValueDto formValue) {
if (formValue == null) {
return null;
}
Serializable value = formValue.getValue();
// IdmAttachmentWithDataDto.
if (PersistentType.ATTACHMENT == formValue.getPersistentType() && value instanceof UUID) {
IdmAttachmentDto attachmentDto = attachmentManager.get((UUID) value);
// Convert attachment to attachment with data
IdmAttachmentWithDataDto attachmentWithDataDto = this.convertAttachment(attachmentDto);
try (InputStream inputStream = attachmentManager.getAttachmentData((UUID) value)) {
if (inputStream != null) {
byte[] bytes = IOUtils.toByteArray(inputStream);
attachmentWithDataDto.setData(bytes);
}
} catch (IOException e) {
throw new CoreException(e);
}
return attachmentWithDataDto;
}
return value;
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method replaceGuardedStrings.
/**
* Replaces GuardedStrings as ConfidentialStrings in given {@link ProvisioningContext}.
*
* TODO: don't update accountObject in provisioningOperation (needs attribute defensive clone)
*
* @param context
* @return Returns values (key / value) to store in confidential storage.
*/
protected Map<String, Serializable> replaceGuardedStrings(ProvisioningContext context) {
try {
Map<String, Serializable> confidentialValues = new HashMap<>();
if (context == null) {
return confidentialValues;
}
//
Map<ProvisioningAttributeDto, Object> accountObject = context.getAccountObject();
if (accountObject != null) {
for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
if (entry.getValue() == null) {
continue;
}
Object idmValue = entry.getValue();
// single value
if (idmValue instanceof GuardedString) {
GuardedString guardedString = (GuardedString) entry.getValue();
// save value into confidential storage
String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), 0);
confidentialValues.put(confidentialStorageKey, guardedString.asString());
accountObject.put(entry.getKey(), new ConfidentialString(confidentialStorageKey));
} else // array
if (idmValue.getClass().isArray()) {
if (!idmValue.getClass().getComponentType().isPrimitive()) {
// objects only, we dont want pto proces byte, boolean etc.
Object[] idmValues = (Object[]) idmValue;
List<ConfidentialString> processedValues = new ArrayList<>();
for (int j = 0; j < idmValues.length; j++) {
Object singleValue = idmValues[j];
if (singleValue instanceof GuardedString) {
GuardedString guardedString = (GuardedString) singleValue;
// save value into confidential storage
String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), j);
confidentialValues.put(confidentialStorageKey, guardedString.asString());
processedValues.add(new ConfidentialString(confidentialStorageKey));
}
}
if (!processedValues.isEmpty()) {
accountObject.put(entry.getKey(), processedValues.toArray(new ConfidentialString[processedValues.size()]));
}
}
} else // collection
if (idmValue instanceof Collection) {
Collection<?> idmValues = (Collection<?>) idmValue;
List<ConfidentialString> processedValues = new ArrayList<>();
idmValues.forEach(singleValue -> {
if (singleValue instanceof GuardedString) {
GuardedString guardedString = (GuardedString) singleValue;
// save value into confidential storage
String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), processedValues.size());
confidentialValues.put(confidentialStorageKey, guardedString.asString());
processedValues.add(new ConfidentialString(confidentialStorageKey));
}
});
if (!processedValues.isEmpty()) {
accountObject.put(entry.getKey(), processedValues);
}
}
}
}
//
IcConnectorObject connectorObject = context.getConnectorObject();
if (connectorObject != null) {
for (IcAttribute attribute : connectorObject.getAttributes()) {
if (attribute.getValues() != null) {
for (int j = 0; j < attribute.getValues().size(); j++) {
Object attributeValue = attribute.getValues().get(j);
if (attributeValue instanceof GuardedString) {
GuardedString guardedString = (GuardedString) attributeValue;
String confidentialStorageKey = createConnectorObjectPropertyKey(attribute, j);
confidentialValues.put(confidentialStorageKey, guardedString.asString());
attribute.getValues().set(j, new ConfidentialString(confidentialStorageKey));
}
}
}
}
}
//
return confidentialValues;
} catch (Exception ex) {
throw new CoreException("Replace guarded strings for provisioning operation failed.", ex);
}
}
Aggregations