@Override protected GenericModel<LogSchemaDto> newInstance(Long id) { return new LogSchema(id); }
@Test public void basicLogSchemaTest() { LogSchema logSchema = new LogSchema(TEST_ID); Assert.assertEquals((Long) TEST_ID, logSchema.getId()); } }
@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; }
protected List<LogSchema> generateLogSchema(Tenant tenant, int ctlVersion, Application application, int count) { List<LogSchema> schemas = Collections.emptyList(); try { if (application == null) { application = generateApplication(tenant); } CtlSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, ctlVersion, application.getTenant(), null); LogSchema schema; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schema = new LogSchema(); schema.setApplication(application); schema.setCtlSchema(ctlSchema); schema.setCreatedUsername("Test User"); schema.setName("Test Name"); schema = logSchemaDao.save(schema); Assert.assertNotNull(schema); schemas.add(schema); } } catch (Exception ex) { LOG.error("Can't generate log schemas {}", ex); Assert.fail("Can't generate log schemas."); } return schemas; }