@Override public LogSchemaDto findLogSchemaById(String id) { validateId(id, "Can't find log schema. Invalid log schema id: " + id); return getDto(logSchemaDao.findById(id)); }
@Override public LogSchemaDto saveLogSchema(LogSchemaDto logSchemaDto) { String id = logSchemaDto.getId(); if (StringUtils.isBlank(id)) { LogSchema logSchema = logSchemaDao.findLatestLogSchemaByAppId( logSchemaDto.getApplicationId()); int version = 0; if (logSchema != null) { version = logSchema.getVersion(); } logSchemaDto.setId(null); logSchemaDto.setVersion(++version); logSchemaDto.setCreatedTime(System.currentTimeMillis()); } else { LogSchemaDto oldLogSchemaDto = getDto(logSchemaDao.findById(id)); if (oldLogSchemaDto != null) { oldLogSchemaDto.editFields(logSchemaDto); logSchemaDto = oldLogSchemaDto; } else { LOG.error("Can't find log schema with given id [{}].", id); throw new IncorrectParameterException("Invalid log schema id: " + id); } } LogSchemaDto savedSchema = getDto(logSchemaDao.save(new LogSchema(logSchemaDto))); if (savedSchema == null) { throw new RuntimeException("Can't save log schema"); } return savedSchema; }
@Test public void removeByIdTest() { LogSchema logSchema = generateLogSchema(null, 1, null, 1).get(0); Assert.assertNotNull(logSchema); logSchemaDao.removeById(logSchema.getStringId()); LogSchema schema = logSchemaDao.findById(logSchema.getStringId()); Assert.assertNull(schema); } }
@Test public void removeByApplicationIdTest() { LogSchema logSchema = generateLogSchema(null, 1, null, 1).get(0); Assert.assertNotNull(logSchema); logSchemaDao.removeByApplicationId(logSchema.getApplication().getStringId()); LogSchema schema = logSchemaDao.findById(logSchema.getStringId()); Assert.assertNull(schema); }