use of eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingService method export.
@Override
public void export(UUID id, IdmExportImportDto batch) {
super.export(id, batch);
// Tree-type will be searching by code (advanced paring by treeType field)
ExportDescriptorDto descriptorDto = getExportManager().getDescriptor(batch, this.getDtoClass());
descriptorDto.getAdvancedParingFields().add(SysSystemMapping_.treeType.getName());
// Export mapped attributes
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setSystemMappingId(id);
List<SysSystemAttributeMappingDto> attributes = this.getAttributeMappingService().find(filter, null).getContent();
if (attributes.isEmpty()) {
this.getAttributeMappingService().export(ExportManager.BLANK_UUID, batch);
}
attributes.forEach(systemAttributeMapping -> {
this.getAttributeMappingService().export(systemAttributeMapping.getId(), batch);
});
// Set parent field -> set authoritative mode.
getExportManager().setAuthoritativeMode(SysSystemAttributeMapping_.systemMapping.getName(), "systemId", SysSystemAttributeMappingDto.class, batch);
}
use of eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleGuaranteeRoleService method export.
@Override
public void export(UUID id, IdmExportImportDto batch) {
Assert.notNull(batch, "Export batch must exist!");
super.export(id, batch);
// Advanced pairing
ExportDescriptorDto descriptorDto = getExportManager().getDescriptor(batch, this.getDtoClass());
descriptorDto.getAdvancedParingFields().add(IdmRoleGuaranteeRole_.guaranteeRole.getName());
}
use of eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto in project CzechIdMng by bcvsolutions.
the class DefaultImportManager method getParentDtoFromBatch.
/**
* Find parent DTO in the batch by parent field in given DTO.
*
* @param dto
* @param context
* @return
* @throws IOException
*/
private BaseDto getParentDtoFromBatch(BaseDto dto, ImportContext context) {
ExportDescriptorDto descriptor = this.getDescriptor(context, dto.getClass());
Assert.notNull(descriptor, "Descriptor cannot be null!");
Set<String> parentFields = descriptor.getParentFields();
if (parentFields.isEmpty()) {
return null;
}
for (String parentField : parentFields) {
try {
UUID parentId = this.getFieldUUIDValue(parentField, dto, dto.getClass());
Class<? extends AbstractDto> parentType = this.getDtoClassFromField(dto.getClass(), parentField);
Assert.notNull(parentType, "Parent type cannot be null!");
if (parentId == null) {
continue;
}
Path dtoTypePath = Paths.get(context.getTempDirectory().toString(), parentType.getSimpleName());
try (Stream<Path> paths = Files.walk(dtoTypePath)) {
BaseDto parentDto = //
paths.filter(//
Files::isRegularFile).map(//
path -> convertFileToDto(path.toFile(), parentType, context)).filter(//
d -> parentId.equals(d.getId())).findFirst().orElse(null);
if (parentDto != null) {
return parentDto;
}
}
} catch (IOException ex) {
throw new ResultCodeException(CoreResultCode.IMPORT_ZIP_EXTRACTION_FAILED, ex);
}
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto in project CzechIdMng by bcvsolutions.
the class DefaultImportManager method getSuperParentDtoClass.
private Class<? extends AbstractDto> getSuperParentDtoClass(ExportDescriptorDto descriptor, ImportContext context) {
Class<? extends BaseDto> dtoClass = descriptor.getDtoClass();
Set<String> parentFields = descriptor.getParentFields();
if (!CollectionUtils.isEmpty(parentFields)) {
String parentField = parentFields.toArray(new String[0])[0];
Class<? extends AbstractDto> superParentDtoClass = null;
while (superParentDtoClass == null) {
Class<? extends AbstractDto> parentDtoClass = this.getDtoClassFromField(dtoClass, parentField);
ExportDescriptorDto parentDescriptor = getDescriptor(context, parentDtoClass);
Assert.notNull(parentDescriptor, "Descriptor was not found!");
if (CollectionUtils.isEmpty(parentDescriptor.getParentFields())) {
superParentDtoClass = parentDtoClass;
} else {
dtoClass = parentDtoClass;
parentField = parentDescriptor.getParentFields().toArray(new String[0])[0];
}
}
return superParentDtoClass;
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto in project CzechIdMng by bcvsolutions.
the class DefaultImportManager method excludeFields.
/**
* Resolve excluded fields. If some fields for this DTO class are excluded,
* then will be sets to a value from the current DTO (or set to the null, if current DTO does not exist).
*
* @param dto
* @param currentDto
* @param context
* @return
*/
private BaseDto excludeFields(BaseDto dto, BaseDto currentDto, ImportContext context) {
if (dto == null) {
return null;
}
ExportDescriptorDto descriptor = this.getDescriptor(context, dto.getClass());
Assert.notNull(descriptor, "Descriptor cannot be null here!");
descriptor.getExcludedFields().forEach(excludedField -> {
Object currentFieldValue = null;
if (currentDto != null) {
currentFieldValue = this.getDtoFieldValue(currentDto, excludedField);
}
this.setDtoFieldValue(dto, excludedField, currentFieldValue);
});
return dto;
}
Aggregations