@Override public ConfigurationSchemaDto editConfigurationSchema( ConfigurationSchemaDto configurationSchema) throws ControlServiceException { ConfigurationSchemaDto confSchema = null; try { confSchema = configurationService.saveConfSchema(configurationSchema); } catch (IncorrectParameterException ex) { LOG.error("Can't generate protocol schema. Can't save configuration schema."); throw new ControlServiceException(ex); } return confSchema; }
private ConfigurationDto createDefaultConfigurationWithSchema(String appId, String groupId, String createdUsername) { ConfigurationSchemaDto schema = new ConfigurationSchemaDto(); schema.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); schema.setCtlSchemaId(ctlSchema.getId()); schema.setName(DEFAULT_SCHEMA_NAME); schema.setCreatedUsername(createdUsername); ConfigurationSchemaDto savedSchema = configurationService.saveConfSchema(schema, groupId); ConfigurationDto config = configurationService.findConfigurationByAppIdAndVersion( savedSchema.getApplicationId(), savedSchema.getVersion()); if (config == null) { throw new RuntimeException("Can't find default configuration by schema id " + savedSchema.getId()); //NOSONAR } else { return config; } }
protected List<ConfigurationSchemaDto> generateConfSchemaDto(String tenantId, String appId, int count) { List<ConfigurationSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenantDto().getId(); } if (isBlank(appId)) { appId = generateApplicationDto().getId(); } ConfigurationSchemaDto schemaDto; CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(tenantId)); schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new ConfigurationSchemaDto(); schemaDto.setApplicationId(appId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = configurationService.saveConfSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate configs {}", e); Assert.fail("Can't generate configuration schemas." + e.getMessage()); } return schemas; }
@Test public void saveConfSchemaTest() throws SchemaCreationException, IOException { String id = generateConfSchemaDto(null, null, 1).get(0).getId(); ConfigurationSchemaDto schema = configurationService.findConfSchemaById(id); Assert.assertNotNull(schema); int version = schema.getVersion(); schema.setId(null); ConfigurationSchemaDto saved = configurationService.saveConfSchema(schema); Assert.assertNotNull(saved); Assert.assertNotEquals(version, saved.getVersion()); Assert.assertNotEquals(schema.getId(), saved.getId()); }