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; }
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."); } }
@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); } } }
ApplicationDto app = generateApplicationDto(); NotificationSchemaDto notificationSchemaDto = new NotificationSchemaDto(); notificationSchemaDto.setApplicationId(app.getId()); CTLSchemaDto ctlSchema = ctlService.saveCtlSchema(generateCTLSchemaDto(app.getTenantId())); notificationSchemaDto.setCtlSchemaId(ctlSchema.getId()); if (notificationSchemaDto == null) { throw new RuntimeException("Can't save default profile schema "); //NOSONAR notificationSchemaDto.setCtlSchemaId(ctlSchema.getId()); notificationSchemaDto.setType(NotificationTypeDto.USER); NotificationSchemaDto savedSchema = notificationService.saveNotificationSchema(notificationSchemaDto); dto.setSchemaId(savedSchema.getId()); dto.setTopicId(topicDto.getId()); dto.setBody("{\"notificationBody\":\"dummy\", \"systemNotificationParam1\":42, \"systemNotificationParam2\":43}".getBytes());
@Override public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchemaDto) { validateNotificationSchemaObject(notificationSchemaDto); String id = notificationSchemaDto.getId(); if (StringUtils.isBlank(id)) { notificationSchemaDto.setId(null); notificationSchemaDto.setCreatedTime(System.currentTimeMillis()); NotificationSchema foundSchema; NotificationTypeDto type = notificationSchemaDto.getType(); if (type != null) { foundSchema = notificationSchemaDao.findLatestNotificationSchemaByAppId( notificationSchemaDto.getApplicationId(), type); } else { throw new IncorrectParameterException( notificationSchemaDto.setVersion(++lastSchemaVersion); } else { notificationSchemaDto.incrementVersion(); oldNotificationSchemaDto.editFields(notificationSchemaDto); notificationSchemaDto = oldNotificationSchemaDto; } else {
@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); } }
@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); } }
@Test(expected = IncorrectParameterException.class) public void testSaveNotificationSchemaWithInvalidAppId() { NotificationSchemaDto schema = new NotificationSchemaDto(); schema.setApplicationId("Invalid Application id."); notificationService.saveNotificationSchema(schema); }
schema = notificationService.findNotificationSchemaById(schemaId); notification.setApplicationId(schema.getApplicationId()); notification.setSchemaId(schema.getId()); if (isBlank(topicId)) { topicId = generateTopicDto(schema.getApplicationId(), null).getId();
@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()); }
controlService.getNotificationSchemasByAppId(applicationId); for (NotificationSchemaDto dto : notificationSchemas) { if (dto.getVersion() == sdkProfile.getNotificationSchemaVersion()) { viewDto.setNotificationSchemaName(dto.getName() + " (v." + dto.getVersion() + ")"); viewDto.setNotificationSchemaId(dto.getId());
@Override protected NotificationSchemaDto createDto() { return new NotificationSchemaDto(); }
/** * 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); } }
@Override public NotificationSchemaDto toDto() { NotificationSchemaDto dto = super.toDto(); dto.setType(type); return dto; }
@Test public void testFindNotificationSchemaById() { NotificationSchemaDto schema = generateNotificationSchemaDto(null, null); Assert.assertNotNull(schema); NotificationSchemaDto found = notificationService.findNotificationSchemaById(schema.getId()); Assert.assertEquals(schema, found); }
/** * Instantiates the NotificationSchema. */ public NotificationSchema(NotificationSchemaDto dto) { super(dto); if (dto != null) { this.type = dto.getType(); } }
@Test(expected = IncorrectParameterException.class) public void testSaveNotificationSchemaWithEmptyType() { NotificationSchemaDto schema = new NotificationSchemaDto(); schema.setApplicationId(new ObjectId().toString()); notificationService.saveNotificationSchema(schema); }
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 protected NotificationSchemaDto createEmptySchema() { return new NotificationSchemaDto(); } }
@Test public void testFindNotificationSchemasByAppId() { NotificationSchemaDto schema = generateNotificationSchemaDto(null, null); Assert.assertNotNull(schema); NotificationSchemaDto found = notificationService.findNotificationSchemasByAppId(schema.getApplicationId()).get(1); Assert.assertEquals(schema, found); }