@Override public ApplicationDto getApplicationByApplicationToken(String applicationToken) throws ControlServiceException { return applicationService.findAppByApplicationToken(applicationToken); }
@Override public ApplicationDto getApplication(String applicationId) throws ControlServiceException { return applicationService.findAppById(applicationId); }
@Override public List<ApplicationDto> getApplicationsByTenantId(String tenantId) throws ControlServiceException { return applicationService.findAppsByTenantId(tenantId); }
@Override public ApplicationDto editApplication(ApplicationDto application) throws ControlServiceException { ApplicationDto storedApplication = applicationService .findAppByApplicationToken(application.getApplicationToken()); if (storedApplication != null) { application.setId(storedApplication.getId()); } boolean update = !isEmpty(application.getId()); ApplicationDto appDto = applicationService.saveApp(application); if (update) { LOG.info("[{}] Broadcasting notification about application {} update.", application.getId(), application.getApplicationToken()); Notification thriftNotification = new Notification(); thriftNotification.setAppId(appDto.getId()); thriftNotification.setAppSeqNumber(appDto.getSequenceNumber()); thriftNotification.setOp(Operation.APP_UPDATE); controlZkService.sendEndpointNotification(thriftNotification); } return appDto; }
@Test public void removeAppByIdTest() { ApplicationDto application = generateApplicationDto(); ApplicationDto foundApp = applicationService.findAppById(application.getId()); Assert.assertNotNull(foundApp); Assert.assertEquals(application.getId(), foundApp.getId()); applicationService.removeAppById(application.getId()); foundApp = applicationService.findAppById(application.getId()); Assert.assertNull(foundApp); }
@Test public void saveAppTest() { ApplicationDto app = generateApplicationDto(); applicationService.saveApp(app); } }
@Test public void testRemoveAppsByTenantId() { TenantDto tenant = generateTenantDto(); ApplicationDto application = generateApplicationDto(tenant.getId()); applicationService.removeAppsByTenantId(tenant.getId()); List<ApplicationDto> foundApplications = applicationService.findAppsByTenantId(tenant.getId()); Assert.assertTrue(foundApplications.isEmpty()); Assert.assertEquals(0, foundApplications.size()); TenantDto foundTenant = userService.findTenantById(tenant.getId()); Assert.assertNotNull(foundTenant); List<EndpointProfileSchemaDto> foundProfileSchemas = profileService.findProfileSchemasByAppId(application.getId()); Assert.assertEquals(0, foundProfileSchemas.size()); List<ConfigurationSchemaDto> foundConfigSchemas = configurationService.findConfSchemasByAppId(application.getId()); Assert.assertEquals(0, foundConfigSchemas.size()); }
@Override public void deleteApplication(String applicationId) throws ControlServiceException { applicationService.removeAppById(applicationId); }
protected ApplicationDto generateApplicationDto(String tenantId, String appName) { ApplicationDto app = new ApplicationDto(); if (isBlank(tenantId)) { app.setTenantId(generateTenantDto().getId()); } else { app.setTenantId(tenantId); } if (!isBlank(appName)) { app.setName(appName); } else { app.setName("Test app"); } return applicationService.saveApp(app); }
@Override public String compute(String key) { LOG.debug("Fetching result for token id"); ApplicationDto appDto = applicationService.findAppByApplicationToken(key); return appDto != null ? appDto.getTenantId() : null; }
@Override @Cacheable("apps") public ApplicationDto findAppById(String applicationId) { return applicationService.findAppById(applicationId); }
protected ApplicationDto generateApplication(String tenantId) { ApplicationDto application = new ApplicationDto(); if (isBlank(tenantId)) { application.setTenantId(generateTenant().getId()); } else { application.setTenantId(tenantId); } application.setName(APPLICATION_NAME); return applicationService.saveApp(application); }
@Test public void testFindAppsByTenantId() { List<ApplicationDto> applications = applicationService.findAppsByTenantId("423421421"); Assert.assertEquals(0, applications.size()); }
@Override public String compute(String key) { LOG.debug("Fetching result for token id"); ApplicationDto appDto = applicationService.findAppByApplicationToken(key); return appDto != null ? appDto.getId() : null; } });
@Override public void onNotification(Notification notification) { ApplicationDto applicationDto = context.getApplicationService() .findAppById(notification.getAppId()); if (applicationDto != null) { LOG.debug("Sending message {} to EPS actor", notification); opsActor.tell(new ThriftNotificationMessage( applicationDto.getApplicationToken(), notification), ActorRef.noSender()); } else { LOG.warn("Can't find corresponding application for: {}", notification); } }
@Before public void beforeTest() throws IOException { customer = new TenantDto(); customer.setName(CUSTOMER_ID); customer = userService.saveTenant(customer); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getId()); ApplicationDto applicationObject = new ApplicationDto(); applicationObject.setTenantId(customer.getId()); applicationObject.setName(APPLICATION_NAME); this.applicationDto = applicationService.saveApp(applicationObject); Assert.assertNotNull(applicationDto); Assert.assertNotNull(applicationDto.getId()); }
@Test public void findAppsByTenantIdTest() { TenantDto tenant = generateTenantDto(); String tenantId = tenant.getId(); ApplicationDto application = generateApplicationDto(tenantId); List<ApplicationDto> applications = applicationService.findAppsByTenantId(tenantId); Assert.assertEquals(1, applications.size()); Assert.assertEquals(application.getId(), applications.get(0).getId()); }
@Override @Cacheable("defaultGroups") public EndpointGroupDto getDefaultGroup(String applicationToken) { return defaultGroupMemorizer.compute(applicationToken, applicationToken1 -> { LOG.debug("Fetching result for token id"); ApplicationDto appDto = applicationService.findAppByApplicationToken(applicationToken1); return endpointService.findDefaultGroup(appDto.getId()); }); }
@Override public FileData getRecordStructureSchema(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!"); } Schema recordWrapperSchema = null; try { CTLSchemaDto logCtlSchema = getCtlSchemaById(logSchema.getCtlSchemaId()); recordWrapperSchema = RecordWrapperSchemaGenerator .generateRecordWrapperSchema(logCtlSchema.getBody()); } catch (IOException ex) { LOG.error("Unable to get Record Structure Schema", ex); throw new ControlServiceException(ex); } String libraryFileName = MessageFormatter .arrayFormat(SCHEMA_NAME_PATTERN, new Object[] {logSchemaVersion}).getMessage(); String schemaInJson = recordWrapperSchema.toString(true); byte[] schemaData = schemaInJson.getBytes(StandardCharsets.UTF_8); FileData schema = new FileData(); schema.setFileName(libraryFileName); schema.setFileData(schemaData); return schema; }
@Override public ConfigurationSchemaDto compute(AppVersionKey key) { LOG.debug("Fetching result for getConfSchemaByAppAndVersion"); ApplicationDto appDto = applicationService.findAppByApplicationToken( key.getApplicationToken()); ConfigurationSchemaDto value = configurationService.findConfSchemaByAppIdAndVersion( appDto.getId(), key.getVersion()); return value; } });