@Override protected GenericModel<NotificationSchemaDto> newInstance(Long id) { return new NotificationSchema(id); }
protected List<NotificationSchema> generateNotificationSchema(Application app, int ctlVersion, int count, NotificationTypeDto type) { List<NotificationSchema> schemas = Collections.emptyList(); try { if (app == null) { app = generateApplication(null); } CtlSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, ctlVersion, app.getTenant(), null); NotificationSchema schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new NotificationSchema(); schemaDto.setApplication(app); schemaDto.setCreatedUsername("Test User"); schemaDto.setCtlSchema(ctlSchema); schemaDto.setVersion(i + 1); schemaDto.setName("Test Name"); schemaDto.setType(type); schemaDto = notificationSchemaDao.save(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception ex) { LOG.error("Can't generate profile schema {}", ex); Assert.fail("Can't generate profile schema." + ex.getMessage()); } return schemas; }
NotificationSchema schema = notificationSchemaDao.findById(schemaId); if (schema != null) { dto.setNfVersion(schema.getVersion()); dto.setApplicationId(schema.getApplicationId()); dto.setType(schema.getType()); } else { throw new DatabaseProcessingException("Can't find notification schema by id " + schemaId);
int lastSchemaVersion = foundSchema.getVersion(); notificationSchemaDto.setVersion(++lastSchemaVersion); } else { return getDto(notificationSchemaDao.save(new NotificationSchema(notificationSchemaDto)));
@Test public void testFindNotificationSchemasByAppIdAndTypeAndVersion() throws Exception { Application application = generateApplication(null); generateNotificationSchema(application, 1, 1, NotificationTypeDto.SYSTEM); List<NotificationSchema> userSchemas = generateNotificationSchema(application, 2, 3, NotificationTypeDto.USER); NotificationSchema expected = userSchemas.get(2); NotificationSchema found = notificationSchemaDao.findNotificationSchemasByAppIdAndTypeAndVersion(application.getStringId(), NotificationTypeDto.USER, expected.getVersion()); Assert.assertEquals(expected, found); }
private byte[] serializeNotificationBody(NotificationDto nf, NotificationSchema nfSchema) throws IOException { GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(nfSchema.getCtlSchema().getBody()); String notificationJson = new String(nf.getBody(), Charset.forName("UTF8")); GenericRecord notificationAvro = converter.decodeJson(notificationJson); return converter.encode(notificationAvro); }
NotificationSchema schema = notificationSchemaDao.findById(schemaId); if (schema != null) { notificationDto.setNfVersion(schema.getVersion()); notificationDto.setApplicationId(schema.getApplicationId()); notificationDto.setType(schema.getType()); try { notificationDto.setBody(serializeNotificationBody(notificationDto, schema));