private void validateConfiguration(ConfigurationDto dto) { validateSqlObject(dto, "Can't save configuration, object is invalid."); validateSqlId(dto.getSchemaId(), "Configuration object invalid. " + "Incorrect configuration schema id : " + dto.getSchemaId()); validateSqlId(dto.getEndpointGroupId(), "Configuration object invalid. " + "Incorrect endpoint group id : " + dto.getEndpointGroupId()); }
private ConfigurationRecordFormDto toConfigurationRecordFormDto(ConfigurationDto configuration) throws KaaAdminServiceException, IOException { ConfigurationSchemaDto schemaDto = this.getConfigurationSchema(configuration.getSchemaId()); EndpointGroupDto endpointGroup = groupService.getEndpointGroup( configuration.getEndpointGroupId()); String rawSchema = endpointGroup.getWeight() == 0 ? schemaDto.getBaseSchema() : schemaDto.getOverrideSchema(); Schema schema = new Schema.Parser().parse(rawSchema); return toConfigurationRecordFormDto(configuration, schema); }
private ChangeNotificationDto createNotification(ConfigurationDto configurationDto, HistoryDto historyDto) { LOG.debug("Create notification after configuration update."); ChangeNotificationDto changeNotificationDto = null; if (historyDto != null) { changeNotificationDto = new ChangeNotificationDto(); changeNotificationDto.setAppId(configurationDto.getApplicationId()); changeNotificationDto.setAppSeqNumber(historyDto.getSequenceNumber()); String endpointGroupId = configurationDto.getEndpointGroupId(); if (isValidId(endpointGroupId)) { EndpointGroup group = endpointGroupDao.findById(endpointGroupId); if (group != null) { changeNotificationDto.setGroupId(idToString(group)); changeNotificationDto.setGroupSeqNumber(group.getSequenceNumber()); } else { LOG.debug("Can't find endpoint group by id [{}].", endpointGroupId); } } else { LOG.debug("Incorrect endpoint group id [{}].", endpointGroupId); } } else { LOG.debug("Can't save history information."); } return changeNotificationDto; }
boolean endpointGroupFound = false; for (ConfigurationDto configuration : configurations) { if (configuration.getEndpointGroupId().equals(endpointGroup.getId())) { if (endpointGroup.getWeight() != 0) { overrideConfigs.add(new OverrideData(overrideSchema, configuration.getBody()));
private HistoryDto addHistory(ConfigurationDto dto, ChangeType type) { LOG.debug("Add history information about configuration update"); HistoryDto history = new HistoryDto(); history.setApplicationId(dto.getApplicationId()); ChangeDto change = new ChangeDto(); change.setConfigurationId(dto.getId()); change.setCfVersion(dto.getSchemaVersion()); change.setEndpointGroupId(dto.getEndpointGroupId()); change.setType(type); history.setChange(change); return historyService.saveHistory(history); }
@Override public ConfigurationDto deactivateConfiguration(String configurationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ConfigurationDto storedConfiguration = controlService.getConfiguration(configurationId); Utils.checkNotNull(storedConfiguration); checkEndpointGroupId(storedConfiguration.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.deactivateConfiguration(configurationId, username); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public ConfigurationDto activateConfiguration(String configurationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ConfigurationDto storedConfiguration = controlService.getConfiguration(configurationId); Utils.checkNotNull(storedConfiguration); checkEndpointGroupId(storedConfiguration.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.activateConfiguration(configurationId, username); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public ConfigurationDto editConfiguration(ConfigurationDto configuration) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { String username = getCurrentUser().getUsername(); if (isEmpty(configuration.getId())) { configuration.setCreatedUsername(username); checkEndpointGroupId(configuration.getEndpointGroupId()); } else { configuration.setModifiedUsername(username); ConfigurationDto storedConfiguration = controlService.getConfiguration( configuration.getId()); Utils.checkNotNull(storedConfiguration); checkEndpointGroupId(storedConfiguration.getEndpointGroupId()); } return controlService.editConfiguration(configuration); } catch (StaleObjectStateException ex) { LOG.error( "Someone has already updated the configuration. Reload page to be able to edit it. ", ex); throw new KaaAdminServiceException( "Someone has already updated the configuration. Reload page to be able to edit it.", ServiceErrorCode.GENERAL_ERROR); } catch (Exception ex) { throw Utils.handleException(ex); } }
try { EndpointGroup endpointGroup = endpointGroupDao.findById( currentConfiguration.getEndpointGroupId()); GenericAvroConverter<GenericRecord> avroConverter; Schema avroSchema;
} else { String schemaId = configurationDto.getSchemaId(); String groupId = configurationDto.getEndpointGroupId(); configurationSchemaDto = findConfSchemaById(schemaId); if (configurationSchemaDto != null) {
@Test public void editConfigurationObjectTest() { List<ConfigurationDto> configs = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto saved = configurationService.findConfigurationById(configs.get(0).getId()); ConfigurationDto configurationToEdit = new ConfigurationDto(); configurationToEdit.setId(saved.getId()); configurationToEdit.setApplicationId(saved.getApplicationId()); configurationToEdit.setEndpointGroupId(saved.getEndpointGroupId()); configurationToEdit.setSchemaId(saved.getSchemaId()); configurationToEdit.setVersion(saved.getVersion()); configurationToEdit.setBody(saved.getBody()); ConfigurationDto updated = configurationService.saveConfiguration(configurationToEdit); Assert.assertNotNull(saved); Assert.assertNotNull(updated); Assert.assertEquals(saved.getSchemaVersion(), updated.getSchemaVersion()); Assert.assertEquals(saved.getCreatedTime(), updated.getCreatedTime()); Assert.assertEquals(saved.getCreatedUsername(), updated.getCreatedUsername()); }