@Override public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchema) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(notificationSchema.getId())) { notificationSchema.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(notificationSchema.getApplicationId()); } else { NotificationSchemaDto storedNotificationSchema = controlService.getNotificationSchema( notificationSchema.getId()); Utils.checkNotNull(storedNotificationSchema); checkApplicationId(storedNotificationSchema.getApplicationId()); } notificationSchema.setType(NotificationTypeDto.USER); return controlService.saveNotificationSchema(notificationSchema); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void testFindNotificationSchemaById() { NotificationSchemaDto schema = generateNotificationSchemaDto(null, null); Assert.assertNotNull(schema); NotificationSchemaDto found = notificationService.findNotificationSchemaById(schema.getId()); Assert.assertEquals(schema, found); }
@Test public void testSaveNotificationSchema() { NotificationSchemaDto schema = generateNotificationSchemaDto(null, null); Assert.assertNotNull(schema); Assert.assertTrue(isNotBlank(schema.getId())); Assert.assertEquals(2, schema.getVersion()); Assert.assertEquals(NotificationTypeDto.USER, schema.getType()); }
@Override public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchemaDto) { validateNotificationSchemaObject(notificationSchemaDto); String id = notificationSchemaDto.getId(); if (StringUtils.isBlank(id)) { notificationSchemaDto.setId(null);
notification.setSchemaId(schema.getId()); if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId();
protected EndpointNotificationDto generateUnicastNotificationDto(String schemaId, String topicId, byte[] keyHash) { EndpointNotificationDto endpointNotification = new EndpointNotificationDto(); endpointNotification.setEndpointKeyHash(keyHash); NotificationDto notification = new NotificationDto(); NotificationSchemaDto schema; if (isBlank(schemaId)) { schema = generateNotificationSchemaDto(null, NotificationTypeDto.USER); } else { schema = notificationService.findNotificationSchemaById(schemaId); } if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId(); } notification.setTopicId(topicId); notification.setApplicationId(schema.getApplicationId()); notification.setSchemaId(schema.getId()); notification.setType(NotificationTypeDto.USER); byte[] body = null; try { body = readSchemaFileAsString("dao/schema/testBaseData.json").getBytes(Charset.forName("UTF-8")); } catch (IOException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } notification.setBody(body); endpointNotification.setNotificationDto(notification); UpdateNotificationDto<EndpointNotificationDto> update = notificationService.saveUnicastNotification(endpointNotification); return update.getPayload(); }
@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); } } }
dto.setSchemaId(savedSchema.getId()); dto.setTopicId(topicDto.getId()); dto.setBody("{\"notificationBody\":\"dummy\", \"systemNotificationParam1\":42, \"systemNotificationParam2\":43}".getBytes());
if (dto.getVersion() == sdkProfile.getNotificationSchemaVersion()) { viewDto.setNotificationSchemaName(dto.getName() + " (v." + dto.getVersion() + ")"); viewDto.setNotificationSchemaId(dto.getId());
@Override public NotificationSchemaViewDto saveNotificationSchemaView( NotificationSchemaViewDto notificationSchemaView) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { NotificationSchemaDto notificationSchema = notificationSchemaView.getSchema(); String applicationId = notificationSchema.getApplicationId(); checkApplicationId(applicationId); String ctlSchemaId = notificationSchema.getCtlSchemaId(); if (isEmpty(ctlSchemaId)) { if (notificationSchemaView.useExistingCtlSchema()) { CtlSchemaReferenceDto metaInfo = notificationSchemaView.getExistingMetaInfo(); CTLSchemaDto schema = ctlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId( metaInfo.getMetaInfo().getFqn(), metaInfo.getVersion(), metaInfo.getMetaInfo().getTenantId(), metaInfo.getMetaInfo().getApplicationId()); notificationSchema.setCtlSchemaId(schema.getId()); } else { CtlSchemaFormDto ctlSchemaForm = ctlService.saveCtlSchemaForm( notificationSchemaView.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); notificationSchema.setCtlSchemaId(ctlSchemaForm.getId()); } } NotificationSchemaDto savedNotificationSchema = saveNotificationSchema(notificationSchema); return getNotificationSchemaView(savedNotificationSchema.getId()); } catch (Exception ex) { throw Utils.handleException(ex); } }