use of eu.bcvsolutions.idm.acc.entity.SysSystem in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createSystem.
/**
* @param tableName
* @param systemName
* @return
*/
@Override
public SysSystemDto createSystem(String tableName, String systemName, String statusColumnName, String keyColumnName) {
// create owner
org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = ((org.apache.tomcat.jdbc.pool.DataSource) dataSource);
SysSystemDto system = new SysSystemDto();
system.setName(systemName == null ? tableName + "_" + System.currentTimeMillis() : systemName);
system.setConnectorKey(new SysConnectorKeyDto(systemService.getTestConnectorKey()));
system = systemService.save(system);
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system.getConnectorInstance());
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto jdbcUrlTemplate = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcUrlTemplate"));
jdbcUrlTemplate.setValue(tomcatDataSource.getUrl());
values.add(jdbcUrlTemplate);
IdmFormValueDto jdbcDriver = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcDriver"));
jdbcDriver.setValue(tomcatDataSource.getDriverClassName());
values.add(jdbcDriver);
IdmFormValueDto user = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("user"));
user.setValue(tomcatDataSource.getUsername());
values.add(user);
IdmFormValueDto password = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("password"));
password.setValue(tomcatDataSource.getPoolProperties().getPassword());
values.add(password);
IdmFormValueDto table = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("table"));
table.setValue(tableName);
values.add(table);
if (!Strings.isNullOrEmpty(keyColumnName)) {
IdmFormValueDto keyColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("keyColumn"));
keyColumn.setValue(keyColumnName);
values.add(keyColumn);
}
IdmFormValueDto passwordColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("passwordColumn"));
passwordColumn.setValue("password");
values.add(passwordColumn);
IdmFormValueDto allNative = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("allNative"));
allNative.setValue(true);
values.add(allNative);
IdmFormValueDto rethrowAllSQLExceptions = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("rethrowAllSQLExceptions"));
rethrowAllSQLExceptions.setValue(true);
values.add(rethrowAllSQLExceptions);
if (!Strings.isNullOrEmpty(statusColumnName)) {
IdmFormValueDto statusColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("statusColumn"));
statusColumn.setValue(statusColumnName);
values.add(statusColumn);
}
IdmFormValueDto disabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("disabledStatusValue"));
disabledStatusValue.setValue("disabled");
values.add(disabledStatusValue);
IdmFormValueDto enabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("enabledStatusValue"));
enabledStatusValue.setValue("enabled");
values.add(enabledStatusValue);
IdmFormValueDto changeLogColumnValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("changeLogColumn"));
changeLogColumnValue.setValue(null);
values.add(changeLogColumnValue);
// TODO: eav to dto
SysSystem systemEntity = systemRepository.findOne(system.getId());
formService.saveValues(systemEntity, savedFormDefinition, values);
return system;
}
use of eu.bcvsolutions.idm.acc.entity.SysSystem 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;
}
Aggregations