@Override public String compute(String key) { LOG.debug("Fetching result for ctl schemas"); CTLSchemaDto ctlSchema = ctlService.findCtlSchemaById(key); return ctlService.flatExportAsString(ctlSchema); } });
@Override public CTLSchemaDto saveCtlSchema(CTLSchemaDto schema) throws ControlServiceException { return ctlService.saveCtlSchema(schema); }
@Override public CTLSchemaDto getCtlSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException { return ctlService.findCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); }
appDto = generateApplicationDto(tenant.getId(), "The app 1"); appDto2 = generateApplicationDto(tenant.getId(), "The app 2"); List<CTLSchemaDto> ctlSchemas = ctlService.findSystemCtlSchemas(); defaultSystemSchema = ctlSchemas.get(0); firstSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 1, tenant.getId(), null, 1)); dependency.add(firstSchema); secondSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 2, tenant.getId(), null, 2)); dependency.add(secondSchema); thirdSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 3, tenant.getId(), null, 3)); dependency.add(thirdSchema); fourthSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 4, tenant.getId(), null, 4)); dependency.add(fourthSchema); mainSchema = generateCTLSchemaDto(DEFAULT_FQN + 5, tenant.getId(), null, 7); mainSchema.setDependencySet(dependency); mainSchema = ctlService.saveCtlSchema(mainSchema); systemSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 6, null, null, 50)); tenantSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 7, tenant.getId(), null, 77)); tenantSchema2 = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN + 7, tenant.getId(), null, 78)); CTLSchemaDto unsaved = generateCTLSchemaDto(DEFAULT_FQN + 8, tenant.getId(), appDto.getId(), 80); appSchema = ctlService.saveCtlSchema(unsaved); unsaved = generateCTLSchemaDto(DEFAULT_FQN + 8, tenant.getId(), appDto.getId(), 81); appSchema2 = ctlService.saveCtlSchema(unsaved); unsaved = generateCTLSchemaDto(DEFAULT_FQN + 9, tenant.getId(), appDto.getId(), 2); appSchema3 = ctlService.saveCtlSchema(unsaved); unsaved = generateCTLSchemaDto(DEFAULT_FQN + 8, tenant.getId(), appDto2.getId(), 11); app2Schema = ctlService.saveCtlSchema(unsaved); gamma.setVersion(1);
@Test public void testRemoveCTLSchemaByFqnAndVerAndWithoutTenantId() { String schemaId = systemSchema.getId(); ctlService.removeCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(systemSchema.getMetaInfo().getFqn(), systemSchema.getVersion(), systemSchema.getMetaInfo().getTenantId(), systemSchema.getMetaInfo().getApplicationId()); Assert.assertNull(ctlService.findCtlSchemaById(schemaId)); }
CTLSchemaDto ctlSchema = null; try { ctlSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(app.getTenantId())); } catch (DatabaseProcessingException e) { ctlSchema = ctlService.getOrCreateEmptySystemSchema(USER_NAME);
@Test public void testSaveFlatCtlSchema() throws IOException { CTLSchemaDto testCtl = new CTLSchemaDto(); CtlSchemaMetaInfoDto ctlMetaInfo = new CtlSchemaMetaInfoDto("org.kaaproject.kaa.NoDependenciesCtlExample", tenant.getId()); testCtl.setMetaInfo(ctlMetaInfo); testCtl.setVersion(1); testCtl.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_FLAT)); testCtl = ctlService.saveCtlSchema(testCtl); CTLSchemaDto foundCtl = ctlService.findCtlSchemaById(testCtl.getId()); String defaultRecord = foundCtl.getDefaultRecord(); Assert.assertNotNull(foundCtl); Assert.assertTrue(defaultRecord.contains("\"bytesField\":\"\"")); Assert.assertTrue(defaultRecord.contains("\"booleanField\":false")); Assert.assertTrue(defaultRecord.contains("\"intField\":0")); Assert.assertTrue(defaultRecord.contains("\"longField\":0")); Assert.assertTrue(defaultRecord.contains("\"floatField\":0.0")); Assert.assertTrue(defaultRecord.contains("\"doubleField\":0.0")); Assert.assertTrue(defaultRecord.contains("\"stringField\":\"\"")); Assert.assertTrue(defaultRecord.contains("\"enumField\":\"SPADES\"")); Assert.assertTrue(defaultRecord.contains("\"arrayField\":[]")); Assert.assertTrue(defaultRecord.contains("\"recordsArrayField\":[]")); Assert.assertTrue(defaultRecord.contains("\"recordField\":{\"bytesFieldInRecord\":\"\",\"booleanFieldInRecord\":false,\"intFieldInRecord\":0,\"floatFieldInRecord\":0.0}")); }
@Override public CTLSchemaDto compute(String key) { LOG.debug("Fetching result for ctl schemas"); return ctlService.findCtlSchemaById(key); } });
@Override public Schema findEndpointConfigurationSchemaByEndpointKeyHash(String endpointKeyHash) throws KaaAdminServiceException { EndpointProfileDto endpointProfileDto = profileService .findEndpointProfileByEndpointKeyHash(endpointKeyHash); ConfigurationSchemaDto configurationSchemaDto = configurationService .findConfSchemaByAppIdAndVersion( endpointProfileDto.getApplicationId(), endpointProfileDto.getConfigurationVersion() ); CTLSchemaDto ctlSchemaDto = ctlService .findCtlSchemaById(configurationSchemaDto.getCtlSchemaId()); return ctlService.flatExportAsSchema(ctlSchemaDto); }
@Test public void testScopeUpdate() { CtlSchemaMetaInfoDto metaInfo = appSchema3.getMetaInfo(); metaInfo.setApplicationId(null); ctlService.updateCtlSchemaMetaInfoScope(metaInfo); CTLSchemaDto found = ctlService.findCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(metaInfo.getFqn(), appSchema3.getVersion(), metaInfo.getTenantId(), null); Assert.assertEquals(appSchema3, found); }
private EndpointProfileSchemaDto createDefaultProfileSchema(String appId, String createdUsername) { EndpointProfileSchemaDto profileSchemaDto = new EndpointProfileSchemaDto(); profileSchemaDto.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); profileSchemaDto.setCtlSchemaId(ctlSchema.getId()); profileSchemaDto.setName(DEFAULT_SCHEMA_NAME); profileSchemaDto.setCreatedUsername(createdUsername); profileSchemaDto = profileService.saveProfileSchema(profileSchemaDto); if (profileSchemaDto == null) { throw new RuntimeException("Can't save default profile schema "); //NOSONAR } return profileSchemaDto; }
@Override public List<CtlSchemaMetaInfoDto> getSystemCtlSchemasMetaInfo() throws ControlServiceException { return ctlService.findSystemCtlSchemasMetaInfo(); }
@Override public List<CTLSchemaDto> getCtlSchemaDependents(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException { return ctlService.findCtlSchemaDependents(fqn, version, tenantId, applicationId); }
@Override public String exportCtlSchemaFlatAsString(CTLSchemaDto schema) throws ControlServiceException { return ctlService.flatExportAsString(schema); }
@Override public CTLSchemaDto getLatestCtlSchemaByFqnTenantIdAndApplicationId( String fqn, String tenantId, String applicationId) throws ControlServiceException { return ctlService.findLatestCtlSchemaByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId); }
@Override public List<CtlSchemaMetaInfoDto> getSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { return ctlService.findSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId); }
@Override public FileData exportCtlSchemaFlat(CTLSchemaDto schema) throws ControlServiceException { return ctlService.flatExport(schema); }
@Test public void testRemoveCTLSchemaByFqnAndVerAndTenantIdAndApplicationId() { String schemaId = tenantSchema.getId(); ctlService.removeCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(tenantSchema.getMetaInfo().getFqn(), tenantSchema.getVersion(), tenantSchema.getMetaInfo().getTenantId(), tenantSchema.getMetaInfo().getApplicationId()); Assert.assertNull(ctlService.findCtlSchemaById(schemaId)); }
protected NotificationSchemaDto generateNotificationSchemaDto(String appId, NotificationTypeDto type) { NotificationSchemaDto schema = new NotificationSchemaDto(); ApplicationDto app = null; if (isBlank(appId)) { app = generateApplicationDto(); appId = app.getId(); } else { app = applicationService.findAppById(appId); } schema.setApplicationId(appId); schema.setName(NOTIFICATION_SCHEMA_NAME); schema.setType(type != null ? type : NotificationTypeDto.USER); CTLSchemaDto ctlSchema = null; try { ctlSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(app.getTenantId())); } catch (DatabaseProcessingException e) { ctlSchema = ctlService.getOrCreateEmptySystemSchema(USER_NAME); } schema.setCtlSchemaId(ctlSchema.getId()); return notificationService.saveNotificationSchema(schema); }
@Override public CTLSchemaDto getCtlSchemaById(String schemaId) throws ControlServiceException { CTLSchemaDto ctlSchemaDto = ctlService.findCtlSchemaById(schemaId); if (ctlSchemaDto == null) { LOG.error("CTL schema with Id [{}] not found!", schemaId); throw new NotFoundException("CTL schema not found!"); } return ctlSchemaDto; }