use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method duplicate.
@Override
@Transactional
public SysSystemDto duplicate(UUID id) {
SysSystemDto originalSystem = this.get(id);
Asserts.notNull(originalSystem, "System must be found!");
// Clone and save system
SysSystemDto clone = this.clone(id);
String name = MessageFormat.format("{0}{1}", "Copy-of-", clone.getName());
name = this.duplicateName(name, 0);
clone.setName(name);
// Set as inactive system
clone.setDisabled(true);
SysSystemDto system = this.save(clone);
// Cache old and new IDs
Map<UUID, UUID> schemaAttributesCache = new HashMap<UUID, UUID>();
Map<UUID, UUID> mappedAttributesCache = new HashMap<UUID, UUID>();
// Duplicate connector configuration values in EAV
IcConnectorInstance connectorInstance = originalSystem.getConnectorInstance();
if (connectorInstance != null && connectorInstance.getConnectorKey() != null && connectorInstance.getConnectorKey().getFramework() != null) {
IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(connectorInstance);
List<IdmFormValueDto> originalFormValues = this.getFormService().getValues(id, SysSystem.class, formDefinition);
SysSystem systemEntity = getEntity(system.getId());
originalFormValues.stream().forEach(value -> {
systemFormValueService.duplicate(value.getId(), systemEntity);
});
}
// Duplicate schema
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(id);
objectClassService.find(objectClassFilter, null).getContent().stream().forEach(schema -> {
UUID originalSchemaId = schema.getId();
SysSchemaObjectClassDto duplicatedSchema = this.duplicateSchema(originalSchemaId, system, schemaAttributesCache);
// Duplicate mapped attributes
SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
systemMappingFilter.setSystemId(id);
systemMappingService.find(systemMappingFilter, null).getContent().stream().filter(mapping -> {
// Find mapping for this schema
return mapping.getObjectClass().equals(originalSchemaId);
}).forEach(mapping -> {
final UUID originalMappingId = mapping.getId();
SysSystemMappingDto duplicatedMapping = this.duplicateMapping(originalMappingId, duplicatedSchema, schemaAttributesCache, mappedAttributesCache);
// Duplicate sync configs
List<AbstractSysSyncConfigDto> syncConfigs = findSyncConfigs(id);
syncConfigs.stream().filter(syncConfig -> {
// Find configuration of sync for this mapping
return syncConfig.getSystemMapping().equals(originalMappingId);
}).forEach(syncConfig -> {
UUID syncConfigId = syncConfig.getId();
duplicateSyncConf(syncConfigId, duplicatedMapping, mappedAttributesCache);
});
});
});
return system;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method setEavValue.
@Override
public void setEavValue(Identifiable owner, IdmFormAttributeDto attribute, Class<? extends Identifiable> clazz, Serializable value, PersistentType type) {
UUID ownerId = UUID.fromString(owner.getId().toString());
IdmFormDefinitionDto main = formDefinitionService.findOneByMain(clazz.getName());
List<IdmFormValueDto> values = formService.getValues(ownerId, clazz, attribute);
if (values.isEmpty()) {
IdmFormValueDto newValue = new IdmFormValueDto();
newValue.setPersistentType(type);
newValue.setValue(value);
newValue.setFormAttribute(attribute.getId());
newValue.setOwnerId(owner.getId());
values.add(newValue);
} else {
values.get(0).setValue(value);
}
formService.saveFormInstance(owner, main, values);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportServiceIntegrationTest method testReportReferentialIntegrity.
@Test
public void testReportReferentialIntegrity() throws IOException {
RptReportDto report = new RptReportDto();
report.setExecutorName(TestFilterReportExecutor.REPORT_NAME);
IdmFormDto filter = new IdmFormDto();
TestFilterReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestFilterReportExecutor.class);
IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
IdmFormValueDto username = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentity_.username.getName()));
username.setValue(TestReportExecutor.identities.get(0).getUsername());
filter.getValues().add(username);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
//
report = reportManager.generate(report);
final UUID reportId = report.getId();
Assert.assertNotNull(reportId);
helper.waitForResult(res -> {
return OperationState.isRunnable(reportService.get(reportId).getResult().getState());
});
Assert.assertNotNull(report.getData());
Assert.assertNotNull(report.getFilter());
Assert.assertFalse(commonFormService.getForms(report).isEmpty());
Assert.assertFalse(attachmentManager.getAttachments(report, null).getTotalElements() == 0);
//
// delete report
reportService.delete(report);
// check report is deleted
Assert.assertNull(reportService.get(report.getId()));
// check attachment was deleted
Assert.assertTrue(attachmentManager.getAttachments(report, null).getTotalElements() == 0);
// check filter is deleted
Assert.assertTrue(commonFormService.getForms(report).isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultVsAccountService method getIcAttribute.
/**
* Load data from extended attribute and create IcAttribute
*
* @param accountId
* @param name
* @return
*/
@Override
public IcAttribute getIcAttribute(UUID accountId, String name, IdmFormDefinitionDto formDefinition) {
IdmFormAttributeDto attributeDefinition = this.formAttributeService.findAttribute(formDefinition.getType(), formDefinition.getCode(), name);
List<IdmFormValueDto> values = this.formService.getValues(accountId, VsAccount.class, formDefinition, name);
IcAttributeImpl attribute = new IcAttributeImpl();
attribute.setMultiValue(attributeDefinition.isMultiple());
attribute.setName(name);
if (CollectionUtils.isEmpty(values)) {
return attribute;
}
List<Object> valuesObject = values.stream().map(IdmFormValueDto::getValue).collect(Collectors.toList());
attribute.setValues(valuesObject);
return attribute;
}
Aggregations