@Override public EndpointProfileSchemaDto findProfileSchemaByAppIdAndVersion( String appId, int schemaVersion) { validateId(appId, "Can't find profile schema. Invalid application id: " + appId); return getDto(profileSchemaDao.findByAppIdAndVersion(appId, schemaVersion)); }
@Override public List<VersionDto> findProfileSchemaVersionsByAppId(String applicationId) { validateSqlId(applicationId, "Can't find profile schemas. Invalid application id: " + applicationId); List<EndpointProfileSchema> endpointProfileSchemas = profileSchemaDao.findByApplicationId(applicationId); List<VersionDto> schemas = new ArrayList<>(); for (EndpointProfileSchema endpointProfileSchema : endpointProfileSchemas) { schemas.add(endpointProfileSchema.toVersionDto()); } return schemas; }
@Override public EndpointProfileSchemaDto findProfileSchemaById(String id) { validateSqlId(id, "Can't find profile schema. Invalid profile schema id: " + id); return getDto(profileSchemaDao.findById(id)); }
String id = profileSchemaDto.getId(); if (StringUtils.isBlank(id)) { EndpointProfileSchema endpointProfileSchema = profileSchemaDao.findLatestByAppId(appId); int version = -1; if (endpointProfileSchema != null) { profileSchemaDto.setCreatedTime(System.currentTimeMillis()); } else { EndpointProfileSchemaDto oldProfileSchemaDto = getDto(profileSchemaDao.findById(id)); if (oldProfileSchemaDto != null) { oldProfileSchemaDto.editFields(profileSchemaDto); profileSchemaDto = oldProfileSchemaDto; return getDto(profileSchemaDao.save(new EndpointProfileSchema(profileSchemaDto))); } else { LOG.error("Can't find profile schema with given id [{}].", id); return getDto(profileSchemaDao.save(new EndpointProfileSchema(profileSchemaDto))); } else { throw new IncorrectParameterException("Invalid profile schema object. "
@Test public void findLatestByAppId() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 4); Assert.assertEquals(4, schemas.size()); EndpointProfileSchema schema = schemas.get(0); Application app = schema.getApplication(); EndpointProfileSchema found = profileSchemaDao.findLatestByAppId(app.getId().toString()); Assert.assertNotNull(found); Assert.assertEquals(4, found.getVersion()); }
protected List<EndpointProfileSchema> generateProfSchema(Application app, int count) { List<EndpointProfileSchema> schemas = Collections.emptyList(); try { if (app == null) { app = generateApplication(null); } CtlSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, 1, app.getTenant(), null); EndpointProfileSchema schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchema(); schemaDto.setApplication(app); schemaDto.setCreatedUsername("Test User"); schemaDto.setCtlSchema(ctlSchema); schemaDto.setVersion(i + 1); schemaDto.setName("Test Name"); schemaDto = profileSchemaDao.save(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate profile schema {}", e); Assert.fail("Can't generate profile schema." + e.getMessage()); } return schemas; }
@Override public void removeProfileSchemaById(String id) { validateSqlId(id, "Can't remove profile schema. Invalid profile schema id: " + id); profileSchemaDao.removeById(id); LOG.debug("Removed profile schema [{}] with filters.", id); }
@Override public void removeProfileSchemasByAppId(String applicationId) { validateSqlId(applicationId, "Can't remove profile schema. Invalid application id: " + applicationId); List<EndpointProfileSchema> schemas = profileSchemaDao.findByApplicationId(applicationId); if (schemas != null && !schemas.isEmpty()) { LOG.debug("Remove profile shemas by application id {}", applicationId); for (EndpointProfileSchema schema : schemas) { removeProfileSchemaById(schema.getId().toString()); } } }
@Test public void findByAppIdAndVersion() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 4); Assert.assertEquals(4, schemas.size()); EndpointProfileSchema schema = schemas.get(2); Application app = schema.getApplication(); EndpointProfileSchema found = profileSchemaDao.findByAppIdAndVersion(app.getId().toString(), schema.getVersion()); Assert.assertNotNull(found); Assert.assertEquals(3, found.getVersion()); }
@Override public List<EndpointProfileSchemaDto> findProfileSchemasByAppId(String applicationId) { validateSqlId(applicationId, "Can't find profile schema. Invalid application id: " + applicationId); return convertDtoList(profileSchemaDao.findByApplicationId(applicationId)); }
@Test public void findByApplicationId() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 3); Assert.assertEquals(3, schemas.size()); EndpointProfileSchema schema = schemas.get(0); Application app = schema.getApplication(); List<EndpointProfileSchema> found = profileSchemaDao.findByApplicationId(app.getId().toString()); Assert.assertEquals(3, found.size()); Assert.assertEquals(schemas, found); }