use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConfigurationService method initDefaultConfiguration.
/**
* Create instance of default connector configuration
*
* @param configurationClass
* @return
*/
private IcConnectorConfiguration initDefaultConfiguration(Class<? extends ConfigurationClass> configurationClass) {
try {
ConfigurationClass configurationClassInstance = configurationClass.getDeclaredConstructor().newInstance();
List<IcConfigurationProperty> 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) {
IcConfigurationPropertyImpl icProperty = (IcConfigurationPropertyImpl) CzechIdMIcConvertUtil.convertConfigurationProperty(property);
icProperty.setName(propertyName);
icProperty.setType(readMethod.getGenericReturnType().getTypeName());
try {
icProperty.setValue(readMethod.invoke(configurationClassInstance));
} catch (IllegalArgumentException | ReflectiveOperationException e) {
throw new CoreException("Cannot read value of connector configuration property!", e);
}
properties.add(icProperty);
}
});
// Sort by order
properties.sort(Comparator.comparing(IcConfigurationProperty::getOrder));
IcConfigurationPropertiesImpl icProperties = new IcConfigurationPropertiesImpl();
icProperties.setProperties(properties);
IcConnectorConfigurationImpl configuration = new IcConnectorConfigurationImpl();
configuration.setConnectorPoolingSupported(false);
configuration.setConfigurationProperties(icProperties);
return configuration;
} catch (IntrospectionException | ReflectiveOperationException e) {
throw new CoreException("Cannot read connector configuration property!", e);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractReportExecutor method generate.
@Override
public RptReportDto generate(RptReportDto report) {
try {
IdmAttachmentDto data = generateData(report);
report.setData(data.getId());
return report;
} catch (ResultCodeException ex) {
throw ex;
} catch (Exception ex) {
// TODO: better exception
throw new CoreException(ex);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractRemoveBulkAction method processDto.
@Override
protected OperationResult processDto(DTO dto) {
try {
if (dto instanceof Requestable && requestConfiguration.isRequestModeEnabled(dto.getClass())) {
// Request mode is enabled for that DTO
Requestable requestable = (Requestable) dto;
IdmRequestDto request = requestManager.deleteRequestable(requestable, false);
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(ExceptionUtils.resolveException(request.getResult().getException()));
}
return new OperationResult.Builder(request.getResult().getState()).setCause(request.getResult().getException()).build();
}
this.getService().delete(dto);
return new OperationResult.Builder(OperationState.EXECUTED).build();
} catch (AcceptedException ex) {
return new OperationResult.Builder(OperationState.RUNNING).setException(ex).build();
} catch (ResultCodeException ex) {
return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
} catch (Exception ex) {
Throwable resolvedException = ExceptionUtils.resolveException(ex);
if (resolvedException instanceof ResultCodeException) {
return //
new OperationResult.Builder(OperationState.EXCEPTION).setException(//
(ResultCodeException) resolvedException).build();
}
return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractBulkAction method internalProcess.
@SuppressWarnings("unchecked")
public OperationResult internalProcess() {
IdmBulkActionDto localAction = this.getAction();
if (localAction == null) {
// try to load bulk action from LRT persisted properties
localAction = (IdmBulkActionDto) super.getProperties().get(PARAMETER_BULK_ACTION);
// transform filter is needed
if (localAction.getFilter() != null) {
MultiValueMap<String, Object> multivaluedMap = new LinkedMultiValueMap<>();
Map<String, Object> properties = localAction.getFilter();
//
properties.entrySet().forEach((entry) -> {
Object value = entry.getValue();
if (value instanceof List<?>) {
multivaluedMap.put(entry.getKey(), (List<Object>) value);
} else {
multivaluedMap.add(entry.getKey(), entry.getValue());
}
});
//
Class<F> filterClass = getService().getFilterClass();
F filter;
if (DataFilter.class.isAssignableFrom(filterClass)) {
// All filter properties has to be controlled by data filter (=> static fields only).
try {
// data vs field properties
MultiValueMap<String, Object> fieldProperties = new LinkedMultiValueMap<>();
fieldProperties.addAll(multivaluedMap);
//
for (Field declaredField : filterClass.getDeclaredFields()) {
// TODO: refactor all filters to pure DataFilter
if (!Modifier.isStatic(declaredField.getModifiers())) {
throw new CoreException(String.format("Declared filter [%s] has to fully support DataFilter, " + "refactor field [%s] to data usage before action can be executed asynchronously.", filterClass.getCanonicalName(), declaredField.getName()));
}
}
filter = filterClass.getDeclaredConstructor(MultiValueMap.class).newInstance(multivaluedMap);
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException ex) {
throw new CoreException(String.format("Declared filter [%s] has to support constructor with parameters.", filterClass.getCanonicalName()), ex);
}
} else {
filter = mapper.convertValue(multivaluedMap, filterClass);
}
localAction.setTransformedFilter(filter);
}
}
Assert.notNull(localAction, "Bulk action is required.");
//
StringBuilder description = new StringBuilder();
IdmLongRunningTaskDto longRunningTask = this.getLongRunningTaskService().get(this.getLongRunningTaskId());
description.append(longRunningTask.getTaskDescription());
//
List<UUID> entities = getEntities(localAction, description);
//
this.count = Long.valueOf(entities.size());
this.counter = 0l;
//
// update description
longRunningTask.setTaskDescription(description.toString());
longRunningTask.setCount(this.count);
longRunningTask.setCounter(this.counter);
this.getLongRunningTaskService().save(longRunningTask);
//
return processEntities(entities);
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class UuidToUuidConverter method convert.
@Override
public UUID convert(MappingContext<UUID, UUID> context) {
if (context.getSource() == null) {
return null;
}
MappingContext<?, ?> parentContext = context.getParent();
if (parentContext != null && parentContext.getDestination() != null && AbstractDto.class.isAssignableFrom(parentContext.getDestinationType()) && parentContext.getSource() != null && BaseEntity.class.isAssignableFrom(parentContext.getSourceType())) {
try {
AbstractDto parentDto = (AbstractDto) parentContext.getDestination();
UUID entityId = context.getSource();
Map<String, BaseDto> embedded = parentDto.getEmbedded();
PropertyMapping propertyMapping = (PropertyMapping) context.getMapping();
// Find name of field by property mapping
String field = propertyMapping.getLastDestinationProperty().getName();
// Find field in DTO class
Field fieldTyp = getFirstFieldInClassHierarchy(parentContext.getDestinationType(), field);
if (fieldTyp.isAnnotationPresent(Embedded.class)) {
Embedded embeddedAnnotation = fieldTyp.getAnnotation(Embedded.class);
if (embeddedAnnotation.enabled()) {
// Load DTO service by dtoClass and get DTO by UUID
ReadDtoService<?, ?> lookup = getLookupService().getDtoService(embeddedAnnotation.dtoClass());
if (lookup != null) {
AbstractDto dto = (AbstractDto) lookup.get(entityId);
dto.setTrimmed(true);
embedded.put(field, dto);
// Add filled DTO to embedded map to parent DTO
parentDto.setEmbedded(embedded);
}
}
}
} catch (NoSuchFieldException | SecurityException e) {
throw new CoreException(e);
}
}
return context.getSource();
}
Aggregations