@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String schemaId = URLDecoder.decode(req.getParameter(CONFIGURATION_SCHEMA_ID), "UTF-8"); String endpointGroupId = URLDecoder.decode(req.getParameter(ENDPOINT_GROUP_ID), "UTF-8"); ConfigurationRecordDto dto = configurationService .findConfigurationRecordBySchemaIdAndEndpointGroupId(schemaId, endpointGroupId); String body = dto.getActiveStructureDto().getBody(); resp.setContentType("application/octet-stream"); resp.setHeader("Content-Disposition:", "attachment;filename=configurationSchema.txt"); resp.setBufferSize(buffer); resp.setContentLength(body.length()); resp.getOutputStream().print(body); } }
@RequestParam("endpointGroupId") String endpointGroupId) throws KaaAdminServiceException { String response = configurationService.getConfigurationRecord( schemaId, endpointGroupId).getActiveStructureDto().getBody(); String decodedResponse = new String(response.getBytes(), DECODING_CHARSET); return decodedResponse;
/** * Instantiates the Configuration. */ public Configuration(ConfigurationDto dto) { super(dto); if (dto != null) { Long schemaId = getLongId(dto.getSchemaId()); this.configurationSchema = schemaId != null ? new ConfigurationSchema(schemaId) : null; this.configurationBody = stringToBinary(dto.getBody()); this.schemaVersion = dto.getSchemaVersion(); } }
private ConfigurationRecordFormDto toConfigurationRecordFormDto(ConfigurationDto configuration, Schema schema) throws KaaAdminServiceException, IOException { String body = configuration.getBody(); RecordField configurationRecord; if (!isEmpty(body)) { GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(schema); GenericRecord record = converter.decodeJson(body); configurationRecord = FormAvroConverter.createRecordFieldFromGenericRecord(record); } else { configurationRecord = FormAvroConverter.createRecordFieldFromSchema(schema); } ConfigurationRecordFormDto configurationRecordForm = new ConfigurationRecordFormDto( configuration); configurationRecordForm.setConfigurationRecord(configurationRecord); return configurationRecordForm; }
json = new ObjectMapper().readTree(defaultConfiguration.getBody()); } catch (IOException ex) { LOG.error("Unable to convert default configuration data to json", ex);
@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()); }