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; }
@Test public void saveCTLSchemaWithDependency() throws InterruptedException { List<CTLSchemaDto> dep = convertDtoList(ctlSchemaDao.findDependentSchemas(mainSchema.getId())); Assert.assertTrue(dep.isEmpty()); List<CTLSchemaDto> expected = Arrays.asList(mainSchema); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(firstSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(secondSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(thirdSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(fourthSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); }
private NotificationSchemaDto createDefaultNotificationSchema(String appId, String createdUsername) { NotificationSchemaDto notificationSchemaDto = new NotificationSchemaDto(); notificationSchemaDto.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); notificationSchemaDto.setCtlSchemaId(ctlSchema.getId()); notificationSchemaDto.setName(DEFAULT_SCHEMA_NAME); notificationSchemaDto.setCreatedUsername(createdUsername); notificationSchemaDto.setType(NotificationTypeDto.USER); notificationSchemaDto = notificationService.saveNotificationSchema(notificationSchemaDto); if (notificationSchemaDto == null) { throw new RuntimeException("Can't save default notification schema "); //NOSONAR } return notificationSchemaDto; }
@Override public FileData generateRecordStructureLibrary(String applicationId, int logSchemaVersion) throws ControlServiceException { ApplicationDto application = applicationService.findAppById(applicationId); if (application == null) { throw new NotFoundException("Application not found!"); } LogSchemaDto logSchema = logSchemaService.findLogSchemaByAppIdAndVersion(applicationId, logSchemaVersion); if (logSchema == null) { throw new NotFoundException("Log schema not found!"); } try { CTLSchemaDto logCtlSchema = getCtlSchemaById(logSchema.getCtlSchemaId()); Schema recordWrapperSchema = RecordWrapperSchemaGenerator .generateRecordWrapperSchema(getFlatSchemaByCtlSchemaId(logCtlSchema.getId())); String fileName = MessageFormatter.arrayFormat(LOG_SCHEMA_LIBRARY_NAME_PATTERN, new Object[] {logSchemaVersion}).getMessage(); return SchemaLibraryGenerator.generateSchemaLibrary(recordWrapperSchema, fileName); } catch (Exception ex) { LOG.error("Unable to generate Record Structure Library", ex); throw new ControlServiceException(ex); } }
@Test public void testFindCTLSchemaById() { CTLSchemaDto found = ctlService.findCtlSchemaById(firstSchema.getId()); Assert.assertEquals(firstSchema, found); }
/** * Create instance of <code>CtlSchema</code>. * * @param dto data transfer object */ public CtlSchema(CTLSchemaDto dto) { this.id = getLongId(dto.getId()); this.metaInfo = new CtlSchemaMetaInfo(dto.getMetaInfo()); this.version = dto.getVersion(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); update(dto); }
private ServerProfileSchemaDto createDefaultServerProfileSchema(String appId, String createdUsername) { ServerProfileSchemaDto serverProfileSchemaDto = new ServerProfileSchemaDto(); serverProfileSchemaDto.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); serverProfileSchemaDto.setCtlSchemaId(ctlSchema.getId()); serverProfileSchemaDto.setName(DEFAULT_SCHEMA_NAME); serverProfileSchemaDto.setCreatedUsername(createdUsername); return serverProfileService.saveServerProfileSchema(serverProfileSchemaDto); }
private LogSchemaDto createDefaultLogSchema(String appId, String createdUsername) { LogSchemaDto schema = new LogSchemaDto(); schema.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); schema.setCtlSchemaId(ctlSchema.getId()); schema.setName(DEFAULT_SCHEMA_NAME); schema.setCreatedUsername(createdUsername); schema = logSchemaService.saveLogSchema(schema); return schema; }
/** * Create new instance of <code>CtlSchemaFormDto</code>. * * @param ctlSchema is ctl schema, get data from it and put to new instance of * <code>CtlSchemaFormDto</code> */ public CtlSchemaFormDto(CTLSchemaDto ctlSchema) { super(); setId(ctlSchema.getId()); setMetaInfo(ctlSchema.getMetaInfo()); setVersion(ctlSchema.getVersion()); setCreatedTime(ctlSchema.getCreatedTime()); setCreatedUsername(ctlSchema.getCreatedUsername()); setHasDependencies(ctlSchema.getDependencySet() != null && !ctlSchema.getDependencySet().isEmpty()); }
@Override public CTLSchemaDto updateCtlSchema(CTLSchemaDto ctlSchema) { validateCtlSchemaObject(ctlSchema); LOG.debug("Update ctl schema with id [{}]", ctlSchema.getId()); CtlSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); if (schema != null) { synchronized (this) { if (ctlSchema.getVersion() != schema.getVersion()) { throw new DatabaseProcessingException("Can't change version of existing common type " + "version."); } CtlSchemaMetaInfo metaInfo = schema.getMetaInfo(); if (!ctlSchema.getMetaInfo().equals(metaInfo.toDto())) { throw new DatabaseProcessingException("Can't update scope of existing common type " + "version within update procedure."); } ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); schema.update(ctlSchema); return DaoUtil.getDto(ctlSchemaDao.save(schema, true)); } } else { throw new DatabaseProcessingException("Can't find common type version by id."); } }
private ConfigurationDto createDefaultConfigurationWithSchema(String appId, String groupId, String createdUsername) { ConfigurationSchemaDto schema = new ConfigurationSchemaDto(); schema.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); schema.setCtlSchemaId(ctlSchema.getId()); schema.setName(DEFAULT_SCHEMA_NAME); schema.setCreatedUsername(createdUsername); ConfigurationSchemaDto savedSchema = configurationService.saveConfSchema(schema, groupId); ConfigurationDto config = configurationService.findConfigurationByAppIdAndVersion( savedSchema.getApplicationId(), savedSchema.getVersion()); if (config == null) { throw new RuntimeException("Can't find default configuration by schema id " + savedSchema.getId()); //NOSONAR } else { return config; } }
protected ServerProfileSchemaDto generateServerProfileSchema(String appId, String tenantId, int version) { ServerProfileSchemaDto schemaDto = new ServerProfileSchemaDto(); if (isBlank(tenantId)) { ApplicationDto applicationDto = generateApplicationDto(); appId = applicationDto.getId(); tenantId = applicationDto.getTenantId(); } schemaDto.setApplicationId(appId); schemaDto.setCreatedTime(System.currentTimeMillis()); CTLSchemaDto ctlSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(ctlRandomFqn(), tenantId, appId, version)); schemaDto.setCtlSchemaId(ctlSchema.getId()); return serverProfileService.saveServerProfileSchema(schemaDto); }
protected List<ConfigurationSchemaDto> generateConfSchemaDto(String tenantId, String appId, int count) { List<ConfigurationSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenantDto().getId(); } if (isBlank(appId)) { appId = generateApplicationDto().getId(); } ConfigurationSchemaDto schemaDto; CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(tenantId)); schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new ConfigurationSchemaDto(); schemaDto.setApplicationId(appId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = configurationService.saveConfSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate configs {}", e); Assert.fail("Can't generate configuration schemas." + e.getMessage()); } return schemas; }
@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}")); }
protected List<EndpointProfileSchemaDto> generateProfSchemaDto(String tenantId, String appId, int count) { List<EndpointProfileSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenantDto().getId(); } if (isBlank(appId)) { appId = generateApplicationDto(tenantId).getId(); } EndpointProfileSchemaDto schemaDto; CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(tenantId)); schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchemaDto(); schemaDto.setApplicationId(appId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = profileService.saveProfileSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate configs {}", e); Assert.fail("Can't generate configurations."); } return schemas; }
protected List<EndpointProfileSchemaDto> generateProfSchema(String tenantId, String applicationId, int count) { List<EndpointProfileSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenant().getId(); } if (isBlank(applicationId)) { applicationId = generateApplication(tenantId).getId(); } CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, 1)); EndpointProfileSchemaDto schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchemaDto(); schemaDto.setApplicationId(applicationId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = profileService.saveProfileSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate profile schemas {}", e); Assert.fail("Can't generate profile schemas."); } return schemas; }
@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)); }
@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 EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { EventClassDto eventClassDto = eventClassViewDto.getSchema(); String ctlSchemaId = eventClassDto.getCtlSchemaId(); CtlSchemaFormDto ctlSchemaForm = null; if (isEmpty(ctlSchemaId)) { if (eventClassViewDto.useExistingCtlSchema()) { CtlSchemaReferenceDto metaInfo = eventClassViewDto.getExistingMetaInfo(); CTLSchemaDto schema = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId( metaInfo.getMetaInfo().getFqn(), metaInfo.getVersion(), metaInfo.getMetaInfo().getTenantId(), metaInfo.getMetaInfo().getApplicationId()); eventClassDto.setCtlSchemaId(schema.getId()); } else { ctlSchemaForm = ctlService.saveCtlSchemaForm( eventClassViewDto.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); eventClassDto.setCtlSchemaId(ctlSchemaForm.getId()); } } return getEventClassViewByCtlSchemaId(eventClassDto); } catch (Exception ex) { throw Utils.handleException(ex); } }