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 NotificationSchemaViewDto createNotificationSchemaFormCtlSchema( CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { LOG.error("createNotificationSchemaFormCtlSchema [{}]", ctlSchemaForm.getSchema().getDisplayString()); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); NotificationSchemaDto notificationSchema = new NotificationSchemaDto(); notificationSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); notificationSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); notificationSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCtlSchemaForm( ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); notificationSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); NotificationSchemaDto savedNotificationSchema = saveNotificationSchema(notificationSchema); return getNotificationSchemaView(savedNotificationSchema.getId()); } catch (Exception ex) { throw Utils.handleException(ex); } } }
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); }