private void validateNotificationSchemaObject(NotificationSchemaDto dto) { validateObject(dto, "Invalid notification schema object"); if (isBlank(dto.getApplicationId()) && !isValidId(dto.getApplicationId()) || dto.getType() == null) { throw new IncorrectParameterException( "Invalid notification schema object. Check type or applicationId."); } }
/** * Get notification schema. * * @param notificationSchemaId the id of notification schema * @return notification schema */ public NotificationSchemaDto getNotificationSchema(String notificationSchemaId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { NotificationSchemaDto notificationSchema = controlService.getNotificationSchema( notificationSchemaId); Utils.checkNotNull(notificationSchema); checkApplicationId(notificationSchema.getApplicationId()); return notificationSchema; } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void testFindNotificationSchemasByAppId() { NotificationSchemaDto schema = generateNotificationSchemaDto(null, null); Assert.assertNotNull(schema); NotificationSchemaDto found = notificationService.findNotificationSchemasByAppId(schema.getApplicationId()).get(1); Assert.assertEquals(schema, found); }
@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); } }
schema = notificationService.findNotificationSchemaById(schemaId); notification.setApplicationId(schema.getApplicationId()); notification.setSchemaId(schema.getId()); if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId();
if (type != null) { foundSchema = notificationSchemaDao.findLatestNotificationSchemaByAppId( notificationSchemaDto.getApplicationId(), type); } else { throw new IncorrectParameterException(
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 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); } }