use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorType method load.
@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
super.load(connectorType);
if (!connectorType.isReopened()) {
return connectorType;
}
// Load the system.
SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
Assert.notNull(systemDto, "System must exists!");
connectorType.getMetadata().put(SYSTEM_NAME, systemDto.getName());
Map<String, String> metadata = connectorType.getMetadata();
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
// Find attribute with port.
metadata.put(PORT, getValueFromConnectorInstance(PORT, systemDto, connectorFormDef));
// Find attribute with host.
metadata.put(HOST, getValueFromConnectorInstance(HOST, systemDto, connectorFormDef));
// Find attribute with user.
metadata.put(USER, getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef));
// Find attribute with ssl switch.
metadata.put(SSL_SWITCH, getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
// Find group container.
List<String> containers = getValuesFromConnectorInstance(BASE_CONTEXT_GROUP_KEY, systemDto, connectorFormDef);
metadata.put(GROUP_CONTAINER_KEY, containersToString(containers));
// Load the sync mapping.
SysSystemMappingFilter syncMappingFilter = new SysSystemMappingFilter();
syncMappingFilter.setSystemId(systemDto.getId());
syncMappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
SysSystemMappingDto syncMappingDto = getSystemMappingService().find(syncMappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
if (syncMappingDto != null) {
connectorType.getMetadata().put(MAPPING_SYNC_ID, syncMappingDto.getId().toString());
// Load the sync.
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(systemDto.getId());
syncFilter.setSystemMappingId(syncMappingDto.getId());
AbstractSysSyncConfigDto syncDto = getSyncConfigService().find(syncFilter, null).getContent().stream().min(Comparator.comparing(AbstractDto::getCreated)).orElse(null);
if (syncDto != null) {
connectorType.getMetadata().put(GROUP_SYNC_ID, syncDto.getId().toString());
if (syncDto instanceof SysSyncRoleConfigDto) {
SysSyncRoleConfigDto roleConfigDto = (SysSyncRoleConfigDto) syncDto;
if (roleConfigDto.getMemberSystemMapping() != null) {
connectorType.getMetadata().put(MEMBER_SYSTEM_MAPPING, roleConfigDto.getMemberSystemMapping().toString());
}
// Load setting of group sync.
connectorType.getMetadata().put(SysSyncRoleConfig_.membershipSwitch.getName(), String.valueOf(roleConfigDto.isMembershipSwitch()));
connectorType.getMetadata().put(SysSyncRoleConfig_.assignCatalogueSwitch.getName(), String.valueOf(roleConfigDto.isAssignCatalogueSwitch()));
connectorType.getMetadata().put(SysSyncRoleConfig_.assignRoleSwitch.getName(), String.valueOf(roleConfigDto.isAssignRoleSwitch()));
connectorType.getMetadata().put(SysSyncRoleConfig_.assignRoleRemoveSwitch.getName(), String.valueOf(roleConfigDto.isAssignRoleRemoveSwitch()));
connectorType.getMetadata().put(SysSyncRoleConfig_.removeCatalogueRoleSwitch.getName(), String.valueOf(roleConfigDto.isRemoveCatalogueRoleSwitch()));
connectorType.getMetadata().put(MAIN_ROLE_CATALOG, roleConfigDto.getMainCatalogueRoleNode() != null ? roleConfigDto.getMainCatalogueRoleNode().toString() : null);
}
}
}
return connectorType;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class AbstractJdbcConnectorType method load.
@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
super.load(connectorType);
if (!connectorType.isReopened()) {
return connectorType;
}
// Load the system.
SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
Assert.notNull(systemDto, "System must exists!");
connectorType.getMetadata().put(SYSTEM_NAME, systemDto.getName());
Map<String, String> metadata = connectorType.getMetadata();
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
// Find attribute with port.
metadata.put(PORT, getValueFromConnectorInstance(PORT, systemDto, connectorFormDef));
// Find attribute with host.
metadata.put(HOST, getValueFromConnectorInstance(HOST, systemDto, connectorFormDef));
// Find attribute with database.
metadata.put(DATABASE, getValueFromConnectorInstance(DATABASE, systemDto, connectorFormDef));
// Find attribute with table.
metadata.put(TABLE, getValueFromConnectorInstance(TABLE, systemDto, connectorFormDef));
// Find attribute with key column.
metadata.put(KEY_COLUMN, getValueFromConnectorInstance(KEY_COLUMN, systemDto, connectorFormDef));
// Find attribute with user.
metadata.put(USER, getValueFromConnectorInstance(USER, systemDto, connectorFormDef));
// Load the mapping.
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setSystemId(systemDto.getId());
SysSystemMappingDto mappingDto = systemMappingService.find(mappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
// Load the sync.
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(systemDto.getId());
if (mappingDto != null) {
syncFilter.setSystemMappingId(mappingDto.getId());
}
AbstractSysSyncConfigDto syncDto = syncConfigService.find(syncFilter, null).getContent().stream().min(Comparator.comparing(AbstractDto::getCreated)).orElse(null);
connectorType.getEmbedded().put(DefaultConnectorType.SYNC_DTO_KEY, syncDto);
return connectorType;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findRelatedAddedItems.
/**
* Find related added DTOs by given parents. !!Searching of added DTOs are very
* naive!! We use all UUID value in the filter and try to find it in the DTOs.
* It means only equals is implemented.
*
* @param request
* @param predicates
* @param items
* @param dtoClass
* @return
*/
private <R extends Requestable> List<R> findRelatedAddedItems(IdmRequestDto request, List<RequestPredicate> predicates, List<IdmRequestItemDto> items, Class<? extends R> dtoClass) {
List<R> requestables = new ArrayList<>();
//
items.stream().filter(//
i -> RequestOperationType.ADD == i.getOperation()).forEach(item -> {
//
try {
R requestedDto = this.convertItemToDto(item, dtoClass);
AbstractDto requested = (AbstractDto) requestedDto;
addEmbedded(requested, request.getId());
addRequestItemToDto((Requestable) requested, item);
requestables.add((R) requestedDto);
return;
} catch (IOException | ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.JSON_CANNOT_BE_CONVERT_TO_DTO, ImmutableMap.of("json", item.getData()), e);
}
});
return filterDtosByPredicates(requestables, dtoClass, predicates);
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method addEmbedded.
/**
* Loads and adds DTOs by embedded annotation
*
* @param dto
* @param requestId
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
* @throws IntrospectionException
* @throws InstantiationException
*/
private void addEmbedded(AbstractDto dto, UUID requestId) throws ReflectiveOperationException, IllegalArgumentException, IntrospectionException {
Assert.notNull(dto, "DTO is required!");
Field[] fields = dto.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(Embedded.class)) {
Embedded embeddedAnnotation = field.getAnnotation(Embedded.class);
if (embeddedAnnotation.enabled()) {
// If DTO class is abstract then continue
if (Modifier.isAbstract(embeddedAnnotation.dtoClass().getModifiers())) {
continue;
}
Object value = EntityUtils.getEntityValue(dto, field.getName());
if (value instanceof UUID) {
// Create mock instance of embedded DTO only with ID
UUID id = (UUID) value;
AbstractDto embeddedDto = null;
if (Requestable.class.isAssignableFrom(embeddedAnnotation.dtoClass())) {
embeddedDto = embeddedAnnotation.dtoClass().getDeclaredConstructor().newInstance();
embeddedDto.setId(id);
Requestable originalEmbeddedDto = this.getDtoService((Requestable) embeddedDto).get(embeddedDto.getId());
if (originalEmbeddedDto != null) {
// Call standard method for load request's DTO with original DTO
embeddedDto = (AbstractDto) this.get(requestId, originalEmbeddedDto);
} else {
// Call standard method for load request's DTO with mock DTO (only with ID)
embeddedDto = (AbstractDto) this.get(requestId, (Requestable) embeddedDto);
}
} else {
// If embedded DTO is not Requestable, then standard service is using
embeddedDto = (AbstractDto) lookupService.getDtoService(embeddedAnnotation.dtoClass()).get(id);
}
if (embeddedDto == null) {
continue;
}
embeddedDto.setTrimmed(true);
dto.getEmbedded().put(field.getName(), embeddedDto);
}
}
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManager method baseCheckDeferredResult.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void baseCheckDeferredResult(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber, ModifiedFromFilter filter, ReadDtoService service, boolean checkCount) {
Assert.notNull(deferredResult, "Deferred result is required to check.");
Assert.notNull(subscriber.getEntityId(), "Subscriber is required to check deferred result.");
LOG.debug("Start baseCheckDeferredResult for deferred-result [{}] and subscriber [{}]", deferredResult, subscriber);
if (checkCount) {
long countOfentities = service.count(filter);
Long lastNumberOfEntities = subscriber.getLastNumberOfEntities();
subscriber.setLastNumberOfEntities(countOfentities);
if (lastNumberOfEntities != null && countOfentities != lastNumberOfEntities) {
// Notify FE -> Some of an entities were changed (refresh must be executed)
deferredResult.setResult(new OperationResultDto(OperationState.RUNNING));
return;
}
}
ZonedDateTime timeStamp = subscriber.getLastTimeStamp();
if (timeStamp == null) {
List<AbstractDto> entities = service.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (entities.isEmpty()) {
subscriber.setLastTimeStamp(ZonedDateTime.now());
return;
}
ZonedDateTime lastModified = this.getLastTimeStamp(entities.get(0));
subscriber.setLastTimeStamp(lastModified);
return;
}
// Try to find, if some from not finished entities were changed
// TODO: For search SysSyncLogs the filter by modifiedFrom didn't work properly.
// I didn't found reason why, but I hope using sort by created and modified fields will be works better.
// filter.setModifiedFrom(timeStamp);
List<AbstractDto> changedRequestsFromLastChecks = service.find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (!changedRequestsFromLastChecks.isEmpty()) {
AbstractDto changedRequestsFromLastCheck = changedRequestsFromLastChecks.get(0);
ZonedDateTime lastModified = this.getLastTimeStamp(changedRequestsFromLastCheck);
if (lastModified.isAfter(timeStamp)) {
// Notify FE -> Some of the entity was changed (refresh must be executed).
// Notified will be all suspended request for same entity ID!
this.suspendedRequests.stream().filter(request -> request.getEntityId().equals(subscriber.getEntityId())).forEach(request -> {
request.getResult().setResult(new OperationResultDto(OperationState.RUNNING));
});
subscriber.setLastTimeStamp(lastModified);
return;
}
}
// Nothing was changed
}
Aggregations