From c22a8b773f868405f738fbaabd74a45b2061792a Mon Sep 17 00:00:00 2001 From: Alexey Shmalko Date: Wed, 6 Jul 2016 14:24:45 +0300 Subject: [PATCH] Revert "KAA-1145: CTL in Notifications extension" --- .../kaa/server/common/admin/AdminClient.java | 8 +- .../dao/model/sql/NotificationSchema.java | 2 +- .../dao/service/ApplicationServiceImpl.java | 23 +++--- .../dao/service/NotificationServiceImpl.java | 2 +- .../kaa/server/common/dao/AbstractTest.java | 21 ++--- .../dao/impl/sql/HibernateAbstractTest.java | 31 ++++--- .../HibernateNotificationSchemaDaoTest.java | 18 ++--- .../kaa/common/dto/NotificationSchemaDto.java | 9 ++- .../dao/NotificationServiceImplTest.java | 32 ++++---- .../admin/client/mvp/ClientFactory.java | 4 +- .../admin/client/mvp/ClientFactoryImpl.java | 8 +- .../mvp/activity/CtlSchemaActivity.java | 20 +---- .../activity/EndpointProfilesActivity.java | 4 +- .../activity/NotificationSchemaActivity.java | 44 ++++------ .../activity/NotificationSchemasActivity.java | 18 ++++- .../admin/client/mvp/data/DataSource.java | 48 ++++------- .../client/mvp/place/CtlSchemaPlace.java | 7 +- .../NotificationSchemaViewImpl.java | 3 +- .../NotificationSchemasViewImpl.java | 3 +- .../mvp/view/struct/BaseStructView.java | 2 +- .../mvp/view/struct/ConfigFormStructView.java | 1 - .../admin/controller/KaaAdminController.java | 11 ++- .../admin/services/KaaAdminServiceImpl.java | 80 +++++++------------ .../schema/NotificationSchemaViewDto.java | 23 ------ .../shared/services/KaaAdminService.java | 14 ++-- .../service/DefaultControlService.java | 54 +++++++++---- .../control/AbstractTestControlServer.java | 12 +-- test-gh-pages-current | 1 - test-gh-pages.sh | 2 +- 29 files changed, 223 insertions(+), 282 deletions(-) delete mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/NotificationSchemaViewDto.java delete mode 160000 test-gh-pages-current diff --git a/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java b/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java index 4ee09d23b4..3586753f68 100644 --- a/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java +++ b/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java @@ -251,9 +251,15 @@ public ServerProfileSchemaDto saveServerProfileSchema(ServerProfileSchemaDto ser return restTemplate.postForObject(restTemplate.getUrl() + "saveServerProfileSchema", serverProfileSchema, ServerProfileSchemaDto.class); } - public NotificationSchemaDto createNotificationSchema(NotificationSchemaDto notificationSchema) throws Exception { + public NotificationSchemaDto createNotificationSchema(NotificationSchemaDto notificationSchema, String schemaResource) throws Exception { + return createNotificationSchema(notificationSchema, getFileResource(schemaResource)); + } + + public NotificationSchemaDto createNotificationSchema(NotificationSchemaDto notificationSchema, ByteArrayResource schemaResource) + throws Exception { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("notificationSchema", notificationSchema); + params.add("file", schemaResource); return restTemplate.postForObject(restTemplate.getUrl() + "createNotificationSchema", params, NotificationSchemaDto.class); } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/NotificationSchema.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/NotificationSchema.java index 67fd41a539..6ce52e0fc4 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/NotificationSchema.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/NotificationSchema.java @@ -30,7 +30,7 @@ @Entity @Table(name = NOTIFICATION_SCHEMA_TABLE_NAME) @OnDelete(action = OnDeleteAction.CASCADE) -public class NotificationSchema extends BaseSchema implements Serializable { +public class NotificationSchema extends Schema implements Serializable { private static final long serialVersionUID = 6585856417466958172L; diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ApplicationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ApplicationServiceImpl.java index 2fb6d26523..a934543935 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ApplicationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ApplicationServiceImpl.java @@ -270,18 +270,19 @@ private ServerProfileSchemaDto createDefaultServerProfileSchema(String appId, St } 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 profile schema "); //NOSONAR + NotificationSchemaDto schema = new NotificationSchemaDto(); + schema.setApplicationId(appId); + DataSchema defSchema = new KaaSchemaFactoryImpl().createDataSchema(getStringFromFile(DEFAULT_NOTIFICATION_SCHEMA_FILE, ApplicationServiceImpl.class)); + if (!defSchema.isEmpty()) { + schema.setSchema(defSchema.getRawSchema()); + } else { + throw new RuntimeException("Can't read default notification schema."); //NOSONAR } - return notificationSchemaDto; + schema.setType(NotificationTypeDto.USER); + schema.setName(DEFAULT_SCHEMA_NAME); + schema.setCreatedUsername(createdUsername); + + return notificationService.saveNotificationSchema(schema); } private LogSchemaDto createDefaultLogSchema(String appId, String createdUsername) { diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java index 415f093d49..b9876e694c 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java @@ -170,7 +170,7 @@ public NotificationDto saveNotificationAndIncTopicSecNum(NotificationDto dto) { } private byte[] serializeNotificationBody(NotificationDto nf, NotificationSchema nfSchema) throws IOException { - GenericAvroConverter converter = new GenericAvroConverter<>(nfSchema.getCtlSchema().getBody()); + GenericAvroConverter converter = new GenericAvroConverter<>(nfSchema.getSchema()); String notificationJson = new String(nf.getBody(), Charset.forName("UTF8")); GenericRecord notificationAvro = converter.decodeJson(notificationJson); return converter.encode(notificationAvro); diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java index 06b658771f..5e653a281d 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java @@ -83,7 +83,6 @@ import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl; import org.kaaproject.kaa.server.common.core.schema.OverrideSchema; import org.kaaproject.kaa.server.common.dao.exception.CredentialsServiceException; -import org.kaaproject.kaa.server.common.dao.exception.DatabaseProcessingException; import org.kaaproject.kaa.server.common.dao.impl.LogAppenderDao; import org.kaaproject.kaa.server.common.dao.impl.TenantDao; import org.kaaproject.kaa.server.common.dao.impl.UserDao; @@ -568,24 +567,20 @@ protected TopicDto generateTopicDto(String appId, TopicTypeDto type) { 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); + appId = generateApplicationDto().getId(); } schema.setApplicationId(appId); schema.setName(NOTIFICATION_SCHEMA_NAME); - schema.setType(type != null ? type : NotificationTypeDto.USER); - CTLSchemaDto ctlSchema = null; + String schemaBody = null; try { - ctlSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(app.getTenantId())); - } catch (DatabaseProcessingException e){ - ctlSchema = ctlService.getOrCreateEmptySystemSchema(USER_NAME); - + schemaBody = readSchemaFileAsString("dao/schema/testBaseSchema.json"); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); } - schema.setCtlSchemaId(ctlSchema.getId()); + schema.setSchema(new KaaSchemaFactoryImpl().createDataSchema(schemaBody).getRawSchema()); + schema.setType(type != null ? type : NotificationTypeDto.USER); return notificationService.saveNotificationSchema(schema); } diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateAbstractTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateAbstractTest.java index 2ae49dd739..8eddd68589 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateAbstractTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateAbstractTest.java @@ -258,30 +258,29 @@ protected CTLSchema generateCTLSchema(String fqn, int version, Tenant tenant, CT return ctlSchema; } - protected List generateNotificationSchema(Application app, int ctlVersion, int count, NotificationTypeDto type) { + protected List generateNotificationSchema(Application app, int count, NotificationTypeDto type) { List schemas = Collections.emptyList(); try { if (app == null) { app = generateApplication(null); } - CTLSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, ctlVersion, app.getTenant(), null); - NotificationSchema schemaDto; + NotificationSchema notificationSchema; 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); + notificationSchema = new NotificationSchema(); + notificationSchema.setApplication(app); + notificationSchema.setSchema(readSchemaFileAsString("dao/schema/testDataSchema.json")); + notificationSchema.setCreatedUsername("Test User"); + notificationSchema.setVersion(i + 1); + notificationSchema.setName("Test Name"); + notificationSchema.setType(type == null ? NotificationTypeDto.SYSTEM : type); + notificationSchema = notificationSchemaDao.save(notificationSchema); + Assert.assertNotNull(notificationSchema); + schemas.add(notificationSchema); } - } catch (Exception e) { - LOG.error("Can't generate profile schema {}", e); - Assert.fail("Can't generate profile schema." + e.getMessage()); + } catch (IOException e) { + LOG.error("Can't generate notification schema {}", e); + Assert.fail("Can't generate notification schema." + e.getMessage()); } return schemas; } diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateNotificationSchemaDaoTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateNotificationSchemaDaoTest.java index ee12a8a6bd..f186924e83 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateNotificationSchemaDaoTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateNotificationSchemaDaoTest.java @@ -16,7 +16,6 @@ package org.kaaproject.kaa.server.common.dao.impl.sql; -import org.junit.After; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,7 +31,6 @@ import javax.transaction.Transactional; import java.util.List; -import java.util.stream.Collectors; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/common-dao-test-context.xml") @@ -46,7 +44,7 @@ public class HibernateNotificationSchemaDaoTest extends HibernateAbstractTest { @Test public void testFindNotificationSchemasByAppId() throws Exception { Application application = generateApplication(null); - List schemas = generateNotificationSchema(application, 1, 1, null); + List schemas = generateNotificationSchema(application, 1, null); List found = notificationSchemaDao.findNotificationSchemasByAppId(application.getStringId()); Assert.assertEquals(schemas, found); } @@ -54,7 +52,7 @@ public void testFindNotificationSchemasByAppId() throws Exception { @Test public void testRemoveNotificationSchemasByAppId() throws Exception { Application application = generateApplication(null); - generateNotificationSchema(application, 1, 1, null); + generateNotificationSchema(application, 1, null); notificationSchemaDao.removeNotificationSchemasByAppId(application.getStringId()); List found = notificationSchemaDao.findNotificationSchemasByAppId(application.getStringId()); Assert.assertTrue(found.isEmpty()); @@ -63,8 +61,8 @@ public void testRemoveNotificationSchemasByAppId() throws Exception { @Test public void testFindNotificationSchemasByAppIdAndType() throws Exception { Application application = generateApplication(null); - List userSchemas = generateNotificationSchema(application, 1, 2, NotificationTypeDto.USER); - generateNotificationSchema(application, 2, 3, NotificationTypeDto.SYSTEM); + List userSchemas = generateNotificationSchema(application, 2, NotificationTypeDto.USER); + generateNotificationSchema(application, 3, NotificationTypeDto.SYSTEM); List found = notificationSchemaDao.findNotificationSchemasByAppIdAndType(application.getStringId(), NotificationTypeDto.USER); Assert.assertEquals(userSchemas, found); } @@ -72,8 +70,8 @@ public void testFindNotificationSchemasByAppIdAndType() throws Exception { @Test public void testFindNotificationSchemasByAppIdAndTypeAndVersion() throws Exception { Application application = generateApplication(null); - generateNotificationSchema(application, 1, 1, NotificationTypeDto.SYSTEM); - List userSchemas = generateNotificationSchema(application, 2, 3, NotificationTypeDto.USER); + generateNotificationSchema(application, 1, NotificationTypeDto.SYSTEM); + List userSchemas = generateNotificationSchema(application, 3, NotificationTypeDto.USER); NotificationSchema expected = userSchemas.get(2); NotificationSchema found = notificationSchemaDao.findNotificationSchemasByAppIdAndTypeAndVersion(application.getStringId(), NotificationTypeDto.USER, expected.getVersion()); Assert.assertEquals(expected, found); @@ -82,8 +80,8 @@ public void testFindNotificationSchemasByAppIdAndTypeAndVersion() throws Excepti @Test public void testFindLatestNotificationSchemaByAppId() throws Exception { Application application = generateApplication(null); - List userSchemas = generateNotificationSchema(application, 1, 3, NotificationTypeDto.USER); - List systemSchemas = generateNotificationSchema(application, 2, 3, NotificationTypeDto.SYSTEM); + List userSchemas = generateNotificationSchema(application, 3, NotificationTypeDto.USER); + List systemSchemas = generateNotificationSchema(application, 3, NotificationTypeDto.SYSTEM); NotificationSchema found = notificationSchemaDao.findLatestNotificationSchemaByAppId(application.getStringId(), NotificationTypeDto.USER); Assert.assertEquals(userSchemas.get(2), found); } diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/NotificationSchemaDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/NotificationSchemaDto.java index 8fbf5397eb..73e8c6f47e 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/NotificationSchemaDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/NotificationSchemaDto.java @@ -17,12 +17,13 @@ package org.kaaproject.kaa.common.dto; -public class NotificationSchemaDto extends BaseSchemaDto { +public class NotificationSchemaDto extends AbstractSchemaDto { private static final long serialVersionUID = -2514664251184915862L; private NotificationTypeDto type; + public NotificationTypeDto getType() { return type; } @@ -48,7 +49,7 @@ public boolean equals(Object o) { if (applicationId != null ? !applicationId.equals(that.applicationId) : that.applicationId != null) { return false; } - if (ctlSchemaId != null ? !ctlSchemaId.equals(that.ctlSchemaId) : that.ctlSchemaId != null) { + if (schema != null ? !schema.equals(that.schema) : that.schema != null) { return false; } if (type != that.type) { @@ -63,7 +64,7 @@ public int hashCode() { int result = applicationId != null ? applicationId.hashCode() : 0; result = 31 * result + version; result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (ctlSchemaId != null ? ctlSchemaId.hashCode() : 0); + result = 31 * result + (schema != null ? schema.hashCode() : 0); return result; } @@ -74,7 +75,7 @@ public String toString() { ", applicationId='" + applicationId + '\'' + ", majorVersion=" + version + ", type=" + type + - ", ctlSchemaId='" + ctlSchemaId + '\'' + + ", schema='" + schema + '\'' + '}'; } diff --git a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/NotificationServiceImplTest.java b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/NotificationServiceImplTest.java index fa1cad02ce..6301dcc68a 100644 --- a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/NotificationServiceImplTest.java +++ b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/NotificationServiceImplTest.java @@ -31,8 +31,15 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.kaaproject.kaa.common.dto.*; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointNotificationDto; +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.NotificationDto; +import org.kaaproject.kaa.common.dto.NotificationSchemaDto; +import org.kaaproject.kaa.common.dto.NotificationTypeDto; +import org.kaaproject.kaa.common.dto.TopicDto; +import org.kaaproject.kaa.common.dto.TopicTypeDto; +import org.kaaproject.kaa.common.dto.UpdateNotificationDto; +import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl; import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException; import org.slf4j.Logger; @@ -67,22 +74,17 @@ public void afterTest() { @Ignore @Test public void findNotificationsByIdWithExpiredTimeTest() { - 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 - } + String appId = generateApplicationDto().getId(); - notificationSchemaDto.setCtlSchemaId(ctlSchema.getId()); - notificationSchemaDto.setType(NotificationTypeDto.USER); - NotificationSchemaDto savedSchema = notificationService.saveNotificationSchema(notificationSchemaDto); + NotificationSchemaDto schema = new NotificationSchemaDto(); + schema.setApplicationId(appId); + String schemaBody = "{\"type\":\"record\",\"name\":\"BasicSystemNotification\",\"namespace\":\"org.kaaproject.kaa.common.endpoint.gen\",\"fields\":[{\"name\":\"notificationBody\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}},{\"name\":\"systemNotificationParam1\",\"type\":\"int\"},{\"name\":\"systemNotificationParam2\",\"type\":\"int\"}]}"; + schema.setSchema(new KaaSchemaFactoryImpl().createDataSchema(schemaBody).getRawSchema()); + schema.setType(NotificationTypeDto.USER); + NotificationSchemaDto savedSchema = notificationService.saveNotificationSchema(schema); TopicDto topicDto = new TopicDto(); - topicDto.setApplicationId(app.getId()); + topicDto.setApplicationId(appId); topicDto.setName("New Topic"); topicDto.setType(TopicTypeDto.MANDATORY); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactory.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactory.java index d472be7d33..aa9e2744e4 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactory.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactory.java @@ -105,8 +105,8 @@ public interface ClientFactory { BaseSchemaView getCreateConfigurationSchemaView(); BaseListView getNotificationSchemasView(); - BaseCtlSchemaView getNotificationSchemaView(); - BaseCtlSchemaView getCreateNotificationSchemaView(); + BaseSchemaView getNotificationSchemaView(); + BaseSchemaView getCreateNotificationSchemaView(); BaseListView getLogSchemasView(); BaseSchemaView getLogSchemaView(); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java index 96396db01e..d175449f5c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java @@ -157,8 +157,8 @@ public class ClientFactoryImpl implements ClientFactory { private final BaseSchemaView createConfigurationSchemaView = new ConfigurationSchemaViewImpl(true); private final BaseListView notificationSchemasView = new NotificationSchemasViewImpl(); - private final BaseCtlSchemaView notificationSchemaView = new NotificationSchemaViewImpl(false); - private final BaseCtlSchemaView createNotificationSchemaView = new NotificationSchemaViewImpl(true); + private final BaseSchemaView notificationSchemaView = new NotificationSchemaViewImpl(false); + private final BaseSchemaView createNotificationSchemaView = new NotificationSchemaViewImpl(true); private final BaseListView logSchemasView = new LogSchemasViewImpl(); private final BaseSchemaView logSchemaView = new LogSchemaViewImpl(false); @@ -361,12 +361,12 @@ public BaseListView getNotificationSchemasView() { } @Override - public BaseCtlSchemaView getNotificationSchemaView() { + public BaseSchemaView getNotificationSchemaView() { return notificationSchemaView; } @Override - public BaseCtlSchemaView getCreateNotificationSchemaView() { + public BaseSchemaView getCreateNotificationSchemaView() { return createNotificationSchemaView; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java index 54967d35c2..d3eaae29aa 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java @@ -30,7 +30,6 @@ import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace.SchemaType; -import org.kaaproject.kaa.server.admin.client.mvp.place.NotificationSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ProfileSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ServerProfileSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemaView; @@ -40,7 +39,6 @@ import org.kaaproject.kaa.server.admin.client.util.SchemaErrorMessageCustomizer; import org.kaaproject.kaa.server.admin.client.util.Utils; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; -import org.kaaproject.kaa.server.admin.shared.schema.NotificationSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; @@ -258,10 +256,8 @@ public void onSuccessImpl(CtlSchemaFormDto result) { } else if (place.getSchemaType() != null) { if (place.getSchemaType() == SchemaType.ENDPOINT_PROFILE) { goTo(new ProfileSchemasPlace(place.getApplicationId())); - } else if (place.getSchemaType() == SchemaType.SERVER_PROFILE){ - goTo(new ServerProfileSchemasPlace(place.getApplicationId())); } else { - goTo(new NotificationSchemasPlace(place.getApplicationId())); + goTo(new ServerProfileSchemasPlace(place.getApplicationId())); } } else if (place.getPreviousPlace() != null) { goTo(place.getPreviousPlace()); @@ -383,7 +379,7 @@ public void onSuccessImpl(ProfileSchemaViewDto result) { callback.onSuccess(null); } }); - } else if (place.getSchemaType() == SchemaType.SERVER_PROFILE){ + } else { KaaAdmin.getDataSource().createServerProfileSchemaFormCtlSchema(entity, new BusyAsyncCallback() { @Override @@ -395,18 +391,6 @@ public void onSuccessImpl(ServerProfileSchemaViewDto result) { callback.onSuccess(null); } }); - } else { - KaaAdmin.getDataSource().createNotificationSchemaFormCtlSchema(entity, new BusyAsyncCallback() { - @Override - public void onFailureImpl(Throwable caught) { - callback.onFailure(caught); - } - - @Override - public void onSuccessImpl(NotificationSchemaViewDto notificationSchemaViewDto) { - callback.onSuccess(null); - } - }); } } else { KaaAdmin.getDataSource().editCTLSchemaForm(entity, callback); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointProfilesActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointProfilesActivity.java index 9274403138..2ab9dbb8da 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointProfilesActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointProfilesActivity.java @@ -139,7 +139,7 @@ public void onValueChange(ValueChangeEvent event) { reset(); } - + private void findByEndpointGroup() { listView.getEndpointGroupButton().setValue(true); listView.getEndpointKeyHashButton().setValue(false); @@ -205,4 +205,4 @@ private void deleteEntity(String endpointKeyHash, AsyncCallback callback){ KaaAdmin.getDataSource().removeEndpointProfileByKeyHash(endpointKeyHash, callback); } -} \ No newline at end of file +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemaActivity.java index 0b8290898f..dd40b6510a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemaActivity.java @@ -21,14 +21,13 @@ import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; import org.kaaproject.kaa.server.admin.client.mvp.place.NotificationSchemaPlace; -import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView; +import org.kaaproject.kaa.server.admin.client.mvp.view.BaseSchemaView; import com.google.gwt.user.client.rpc.AsyncCallback; -import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; -import org.kaaproject.kaa.server.admin.shared.schema.NotificationSchemaViewDto; -import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace.SchemaType; -public class NotificationSchemaActivity extends AbstractBaseCtlSchemaActivity { +public class NotificationSchemaActivity + extends + AbstractSchemaActivity { public NotificationSchemaActivity(NotificationSchemaPlace place, ClientFactory clientFactory) { @@ -36,12 +35,12 @@ public NotificationSchemaActivity(NotificationSchemaPlace place, } @Override - protected NotificationSchemaViewDto newSchema() { - return new NotificationSchemaViewDto(); + protected NotificationSchemaDto newSchema() { + return new NotificationSchemaDto(); } @Override - protected BaseCtlSchemaView getView(boolean create) { + protected BaseSchemaView getView(boolean create) { if (create) { return clientFactory.getCreateNotificationSchemaView(); } else { @@ -51,38 +50,25 @@ protected BaseCtlSchemaView getView(boolean create) { @Override protected void getEntity(String id, - AsyncCallback callback) { - KaaAdmin.getDataSource().getNotificationSchemaView(id, callback); + AsyncCallback callback) { + KaaAdmin.getDataSource().getNotificationSchemaForm(id, callback); } @Override - protected void editEntity(NotificationSchemaViewDto entity, - AsyncCallback callback) { - KaaAdmin.getDataSource().saveNotificationSchemaView(entity, callback); + protected void editEntity(NotificationSchemaDto entity, + AsyncCallback callback) { + KaaAdmin.getDataSource().editNotificationSchemaForm(entity, callback); } @Override - protected void createEmptyCtlSchemaForm(AsyncCallback callback) { - KaaAdmin.getDataSource().createNewCTLSchemaFormInstance(null, - null, - applicationId, - callback); + protected void createEmptySchemaForm(AsyncCallback callback) { + KaaAdmin.getDataSource().createCommonEmptySchemaForm(callback); } @Override public void loadFormData(String fileItemName, - AsyncCallback callback) { + AsyncCallback callback) { KaaAdmin.getDataSource().generateCommonSchemaForm(fileItemName, callback); } - @Override - protected NotificationSchemaPlace existingSchemaPlace(String applicationId, String schemaId) { - return new NotificationSchemaPlace(applicationId, schemaId); - } - - @Override - protected SchemaType getPlaceSchemaType() { - return SchemaType.NOTIFICATION ; - } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemasActivity.java index 7b14c0ff95..031e108772 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/NotificationSchemasActivity.java @@ -35,7 +35,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class NotificationSchemasActivity extends AbstractBaseCtlSchemasActivity { +public class NotificationSchemasActivity extends AbstractListActivity { private String applicationId; @@ -70,4 +70,20 @@ protected void deleteEntity(String id, AsyncCallback callback) { callback.onSuccess((Void)null); } + @Override + protected void onCustomRowAction(RowActionEvent event) { + Integer schemaVersion = Integer.valueOf(event.getClickedId()); + if (event.getAction() == KaaRowAction.DOWNLOAD_SCHEMA) { + KaaAdmin.getDataSource().getRecordData(applicationId, schemaVersion, RecordFiles.NOTIFICATION_SCHEMA, new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + Utils.handleException(caught, listView); + } + @Override + public void onSuccess(String key) { + ServletHelper.downloadRecordLibrary(key); + } + }); + } + } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java index b7ae44caef..0b53797ec9 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java @@ -63,12 +63,15 @@ import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto; import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto; import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; -import org.kaaproject.kaa.server.admin.shared.schema.*; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; +import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto; +import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto; +import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceAsync; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; -import org.kaaproject.kaa.server.common.dao.model.sql.NotificationSchema; public class DataSource { @@ -696,43 +699,22 @@ protected void onResult(List result) { } - public void saveNotificationSchemaView( - NotificationSchemaViewDto notificationSchema, - final AsyncCallback callback) { - rpcService.saveNotificationSchemaView(notificationSchema, - new DataCallback(callback) { + public void editNotificationSchemaForm( + NotificationSchemaDto notificationSchema, + final AsyncCallback callback) { + rpcService.editNotificationSchemaForm(notificationSchema, + new DataCallback(callback) { @Override - protected void onResult(NotificationSchemaViewDto result) { + protected void onResult(NotificationSchemaDto result) { eventBus.fireEvent(new DataEvent( - NotificationSchemaViewDto.class)); - } - }); - } - - public void createNotificationSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm, - final AsyncCallback callback) { - rpcService.createNotificationSchemaFormCtlSchema(ctlSchemaForm, - new DataCallback(callback) { - @Override - protected void onResult(NotificationSchemaViewDto result) { - eventBus.fireEvent(new DataEvent(NotificationSchemaViewDto.class)); + NotificationSchemaDto.class)); } }); } - public void getNotificationSchemaView(String profileSchemaId, - final AsyncCallback callback) { - rpcService.getNotificationSchemaView(profileSchemaId, - new DataCallback(callback) { - @Override - protected void onResult(NotificationSchemaViewDto result) { - } - }); - } - - public void getNotificationSchema(String profileSchemaId, - final AsyncCallback callback) { - rpcService.getNotificationSchema(profileSchemaId, + public void getNotificationSchemaForm(String notificationSchemaId, + final AsyncCallback callback) { + rpcService.getNotificationSchemaForm(notificationSchemaId, new DataCallback(callback) { @Override protected void onResult(NotificationSchemaDto result) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java index 44f32f0770..f9b57a7786 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java @@ -182,10 +182,8 @@ public TreePlace createDefaultPreviousPlace() { if (schemaType != null) { if (schemaType == SchemaType.ENDPOINT_PROFILE) { return new ProfileSchemasPlace(applicationId); - } else if (schemaType == SchemaType.SERVER_PROFILE){ - return new ServerProfileSchemasPlace(applicationId); } else { - return new NotificationSchemasPlace(applicationId); + return new ServerProfileSchemasPlace(applicationId); } } else { return new ApplicationCtlSchemasPlace(applicationId); @@ -202,8 +200,7 @@ public TreePlace createDefaultPreviousPlace() { public static enum SchemaType { ENDPOINT_PROFILE, - SERVER_PROFILE, - NOTIFICATION + SERVER_PROFILE } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemaViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemaViewImpl.java index 7d27a2e275..91fac5c18d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemaViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemaViewImpl.java @@ -16,11 +16,10 @@ package org.kaaproject.kaa.server.admin.client.mvp.view.notification; -import org.kaaproject.kaa.server.admin.client.mvp.view.schema.BaseCtlSchemaViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.schema.BaseSchemaViewImpl; import org.kaaproject.kaa.server.admin.client.util.Utils; -public class NotificationSchemaViewImpl extends BaseCtlSchemaViewImpl { +public class NotificationSchemaViewImpl extends BaseSchemaViewImpl { public NotificationSchemaViewImpl(boolean create) { super(create); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemasViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemasViewImpl.java index f1950e94a8..084a30bdb6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemasViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/notification/NotificationSchemasViewImpl.java @@ -19,7 +19,6 @@ import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; import org.kaaproject.kaa.common.dto.NotificationSchemaDto; import org.kaaproject.kaa.server.admin.client.mvp.view.base.BaseListViewImpl; -import org.kaaproject.kaa.server.admin.client.mvp.view.schema.BaseCtlSchemasGrid; import org.kaaproject.kaa.server.admin.client.mvp.view.schema.BaseSchemasGrid; import org.kaaproject.kaa.server.admin.client.util.Utils; @@ -31,7 +30,7 @@ public NotificationSchemasViewImpl() { @Override protected AbstractGrid createGrid() { - return new BaseCtlSchemasGrid(); + return new BaseSchemasGrid(); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseStructView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseStructView.java index afd5fd85df..97355213f1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseStructView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseStructView.java @@ -394,4 +394,4 @@ private void updateSaveButton(boolean enabled, boolean invalid) { saveButton.setEnabled(enabled); activateButton.setEnabled(!invalid && !enabled); } -} \ No newline at end of file +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/ConfigFormStructView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/ConfigFormStructView.java index ae34e11fb3..79dd1a1b2a 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/ConfigFormStructView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/ConfigFormStructView.java @@ -1,4 +1,3 @@ - /* * Copyright 2014-2016 CyberVision, Inc. * diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/KaaAdminController.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/KaaAdminController.java index dc93f5d28c..c68bc8f419 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/KaaAdminController.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/KaaAdminController.java @@ -76,7 +76,6 @@ import org.kaaproject.kaa.server.admin.services.entity.CreateUserResult; import org.kaaproject.kaa.server.admin.services.util.Utils; import org.kaaproject.kaa.server.admin.servlet.ServletUtils; -import org.kaaproject.kaa.server.admin.shared.schema.NotificationSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.admin.shared.services.KaaAuthService; @@ -1153,14 +1152,18 @@ public NotificationSchemaDto getNotificationSchema(@PathVariable String notifica * * @param notificationSchema * the notification schema + * @param file + * the file * @return the notification schema dto * @throws KaaAdminServiceException * the kaa admin service exception */ @RequestMapping(value = "createNotificationSchema", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" }) @ResponseBody - public NotificationSchemaDto createNotificationSchema(@RequestPart("notificationSchema") NotificationSchemaDto notificationSchema) throws KaaAdminServiceException { - return kaaAdminService.editNotificationSchema(notificationSchema); + public NotificationSchemaDto createNotificationSchema(@RequestPart("notificationSchema") NotificationSchemaDto notificationSchema, + @RequestPart("file") MultipartFile file) throws KaaAdminServiceException { + byte[] data = getFileContent(file); + return kaaAdminService.editNotificationSchema(notificationSchema, data); } /** @@ -1176,7 +1179,7 @@ public NotificationSchemaDto createNotificationSchema(@RequestPart("notification @ResponseBody public NotificationSchemaDto editNotificationSchema(@RequestBody NotificationSchemaDto notificationSchema) throws KaaAdminServiceException { - return kaaAdminService.editNotificationSchema(notificationSchema); + return kaaAdminService.editNotificationSchema(notificationSchema, null); } /** diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAdminServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAdminServiceImpl.java index 0d7245f754..f031b9f2e4 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAdminServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAdminServiceImpl.java @@ -125,14 +125,17 @@ import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto; import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto; import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; -import org.kaaproject.kaa.server.admin.shared.schema.*; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaExportKey; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; +import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto; +import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto; +import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode; -import org.kaaproject.kaa.server.common.core.schema.BaseSchema; import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl; import org.kaaproject.kaa.server.common.dao.exception.NotFoundException; -import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchema; import org.kaaproject.kaa.server.common.plugin.KaaPluginConfig; import org.kaaproject.kaa.server.common.plugin.PluginConfig; import org.kaaproject.kaa.server.common.plugin.PluginType; @@ -1496,8 +1499,8 @@ public List getUserNotificationSchemaInfosByApplicationId(String List schemaInfos = new ArrayList<>(notificationSchemas.size()); for (NotificationSchemaDto notificationSchema : notificationSchemas) { SchemaInfoDto schemaInfo = new SchemaInfoDto(notificationSchema); - CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(notificationSchema.getCtlSchemaId()); - RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody(notificationSchema.getCtlSchemaId(), ctlSchemaDto.getBody()); + Schema schema = new Schema.Parser().parse(notificationSchema.getSchema()); + RecordField schemaForm = FormAvroConverter.createRecordFieldFromSchema(schema); schemaInfo.setSchemaForm(schemaForm); schemaInfos.add(schemaInfo); } @@ -1507,20 +1510,7 @@ public List getUserNotificationSchemaInfosByApplicationId(String } } - public NotificationSchemaViewDto getNotificationSchemaView(String notificationSchemaId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); - try { - NotificationSchemaDto notificationSchema = controlService.getNotificationSchema(notificationSchemaId); - Utils.checkNotNull(notificationSchema); - checkApplicationId(notificationSchema.getApplicationId()); - CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(notificationSchema.getCtlSchemaId()); - NotificationSchemaViewDto notificationSchemaViewDto = new NotificationSchemaViewDto(notificationSchema, toCtlSchemaForm(ctlSchemaDto)); - return notificationSchemaViewDto; - } catch (Exception e) { - throw Utils.handleException(e); - } - } - + @Override public NotificationSchemaDto getNotificationSchema(String notificationSchemaId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { @@ -1534,17 +1524,19 @@ public NotificationSchemaDto getNotificationSchema(String notificationSchemaId) } @Override - public NotificationSchemaDto editNotificationSchema(NotificationSchemaDto notificationSchema) + public NotificationSchemaDto editNotificationSchema(NotificationSchemaDto notificationSchema, byte[] schema) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(notificationSchema.getId())) { notificationSchema.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(notificationSchema.getApplicationId()); + setSchema(notificationSchema, schema); } else { NotificationSchemaDto storedNotificationSchema = controlService.getNotificationSchema(notificationSchema.getId()); Utils.checkNotNull(storedNotificationSchema); checkApplicationId(storedNotificationSchema.getApplicationId()); + notificationSchema.setSchema(storedNotificationSchema.getSchema()); } notificationSchema.setType(NotificationTypeDto.USER); return controlService.editNotificationSchema(notificationSchema); @@ -1554,47 +1546,33 @@ public NotificationSchemaDto editNotificationSchema(NotificationSchemaDto notifi } @Override - public NotificationSchemaViewDto saveNotificationSchemaView(NotificationSchemaViewDto notificationSchemaView) throws KaaAdminServiceException { + public NotificationSchemaDto getNotificationSchemaForm(String notificationSchemaId) 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 = getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), - metaInfo.getVersion(), - metaInfo.getMetaInfo().getTenantId(), - metaInfo.getMetaInfo().getApplicationId()); - notificationSchema.setCtlSchemaId(schema.getId()); - } else { - CtlSchemaFormDto ctlSchemaForm = saveCTLSchemaForm(notificationSchemaView.getCtlSchemaForm()); - notificationSchema.setCtlSchemaId(ctlSchemaForm.getId()); - } - } - NotificationSchemaDto savedNotificationSchema = editNotificationSchema(notificationSchema); - return getNotificationSchemaView(savedNotificationSchema.getId()); + NotificationSchemaDto notificationSchema = getNotificationSchema(notificationSchemaId); + convertToSchemaForm(notificationSchema, commonSchemaFormAvroConverter); + return notificationSchema; } catch (Exception e) { throw Utils.handleException(e); } } @Override - public NotificationSchemaViewDto createNotificationSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { - LOG.error("createNotificationSchemaFormCtlSchema [{}]", ctlSchemaForm.getSchema().getDisplayString()); + public NotificationSchemaDto editNotificationSchemaForm(NotificationSchemaDto notificationSchema) throws KaaAdminServiceException { 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 = saveCTLSchemaForm(ctlSchemaForm); - notificationSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); - NotificationSchemaDto savedNotificationSchema = editNotificationSchema(notificationSchema); - return getNotificationSchemaView(savedNotificationSchema.getId()); + if (isEmpty(notificationSchema.getId())) { + notificationSchema.setCreatedUsername(getCurrentUser().getUsername()); + checkApplicationId(notificationSchema.getApplicationId()); + convertToStringSchema(notificationSchema, commonSchemaFormAvroConverter); + } else { + NotificationSchemaDto storedNotificationSchema = controlService.getNotificationSchema(notificationSchema.getId()); + Utils.checkNotNull(storedNotificationSchema); + checkApplicationId(storedNotificationSchema.getApplicationId()); + notificationSchema.setSchema(storedNotificationSchema.getSchema()); + } + notificationSchema.setType(NotificationTypeDto.USER); + return controlService.editNotificationSchema(notificationSchema); } catch (Exception e) { throw Utils.handleException(e); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/NotificationSchemaViewDto.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/NotificationSchemaViewDto.java deleted file mode 100644 index 0b488e31ba..0000000000 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/NotificationSchemaViewDto.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.kaaproject.kaa.server.admin.shared.schema; - - -import org.kaaproject.kaa.common.dto.NotificationSchemaDto; - -public class NotificationSchemaViewDto extends BaseSchemaViewDto{ - - private static final long serialVersionUID = -5289268279407697111L; - - public NotificationSchemaViewDto() { - super(); - } - - public NotificationSchemaViewDto(NotificationSchemaDto schema, - CtlSchemaFormDto ctlSchemaForm) { - super(schema, ctlSchemaForm); - } - - @Override - protected NotificationSchemaDto createEmptySchema() { - return new NotificationSchemaDto(); - } -} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/KaaAdminService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/KaaAdminService.java index 8953992c46..5629631da9 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/KaaAdminService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/KaaAdminService.java @@ -65,7 +65,11 @@ import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto; import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto; import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; -import org.kaaproject.kaa.server.admin.shared.schema.*; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; +import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto; +import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto; +import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -205,13 +209,11 @@ public interface KaaAdminService extends RemoteService { NotificationSchemaDto getNotificationSchema(String notificationSchemaId) throws KaaAdminServiceException; - NotificationSchemaViewDto getNotificationSchemaView(String notificationSchemaId) throws KaaAdminServiceException; + NotificationSchemaDto editNotificationSchema(NotificationSchemaDto notificationSchema, byte[] schema) throws KaaAdminServiceException; - NotificationSchemaDto editNotificationSchema(NotificationSchemaDto notificationSchema) throws KaaAdminServiceException; + NotificationSchemaDto getNotificationSchemaForm(String notificationSchemaId) throws KaaAdminServiceException; - NotificationSchemaViewDto saveNotificationSchemaView(NotificationSchemaViewDto notificationSchema) throws KaaAdminServiceException; - - NotificationSchemaViewDto createNotificationSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; + NotificationSchemaDto editNotificationSchemaForm(NotificationSchemaDto notificationSchema) throws KaaAdminServiceException; List getLogSchemasByApplicationId(String applicationId) throws KaaAdminServiceException; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java index d13328d024..7bfa837237 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java @@ -37,7 +37,39 @@ import org.apache.thrift.TException; import org.kaaproject.avro.ui.shared.Fqn; import org.kaaproject.kaa.common.avro.GenericAvroConverter; -import org.kaaproject.kaa.common.dto.*; +import org.kaaproject.kaa.common.dto.AbstractSchemaDto; +import org.kaaproject.kaa.common.dto.ApplicationDto; +import org.kaaproject.kaa.common.dto.ChangeConfigurationNotification; +import org.kaaproject.kaa.common.dto.ChangeNotificationDto; +import org.kaaproject.kaa.common.dto.ChangeProfileFilterNotification; +import org.kaaproject.kaa.common.dto.ChangeType; +import org.kaaproject.kaa.common.dto.ConfigurationDto; +import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; +import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointGroupDto; +import org.kaaproject.kaa.common.dto.EndpointNotificationDto; +import org.kaaproject.kaa.common.dto.EndpointProfileBodyDto; +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointProfilesBodyDto; +import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto; +import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; +import org.kaaproject.kaa.common.dto.EndpointUserDto; +import org.kaaproject.kaa.common.dto.HasId; +import org.kaaproject.kaa.common.dto.NotificationDto; +import org.kaaproject.kaa.common.dto.NotificationSchemaDto; +import org.kaaproject.kaa.common.dto.NotificationTypeDto; +import org.kaaproject.kaa.common.dto.PageLinkDto; +import org.kaaproject.kaa.common.dto.ProfileFilterDto; +import org.kaaproject.kaa.common.dto.ProfileFilterRecordDto; +import org.kaaproject.kaa.common.dto.ProfileVersionPairDto; +import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; +import org.kaaproject.kaa.common.dto.TenantAdminDto; +import org.kaaproject.kaa.common.dto.TenantDto; +import org.kaaproject.kaa.common.dto.TopicDto; +import org.kaaproject.kaa.common.dto.UpdateNotificationDto; +import org.kaaproject.kaa.common.dto.UserDto; +import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.common.dto.admin.RecordKey; import org.kaaproject.kaa.common.dto.admin.RecordKey.RecordFiles; import org.kaaproject.kaa.common.dto.admin.SdkPlatform; @@ -84,7 +116,6 @@ import org.kaaproject.kaa.server.common.dao.exception.EndpointRegistrationServiceException; import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException; import org.kaaproject.kaa.server.common.dao.exception.NotFoundException; -import org.kaaproject.kaa.server.common.dao.model.sql.NotificationSchema; import org.kaaproject.kaa.server.common.log.shared.RecordWrapperSchemaGenerator; import org.kaaproject.kaa.server.common.thrift.KaaThriftService; import org.kaaproject.kaa.server.common.thrift.gen.operations.Notification; @@ -1060,14 +1091,8 @@ public FileData generateSdk(SdkProfileDto sdkProfile, SdkPlatform platform) thro } String profileSchemaBodyString = ctlService.flatExportAsString(profileCtlSchema); - CTLSchemaDto notificationCtlSchema = ctlService.findCTLSchemaById(notificationSchema.getCtlSchemaId()); - if (notificationCtlSchema == null) { - throw new NotFoundException("Profile CTL schema not found!"); - } - String notificationSchemaBodyString = ctlService.flatExportAsString(notificationCtlSchema); - DataSchema profileDataSchema = new DataSchema(profileSchemaBodyString); - DataSchema notificationDataSchema = new DataSchema(notificationSchemaBodyString); + DataSchema notificationDataSchema = new DataSchema(notificationSchema.getSchema()); ProtocolSchema protocolSchema = new ProtocolSchema(configurationSchema.getProtocolSchema()); DataSchema logDataSchema = new DataSchema(logSchema.getSchema()); @@ -1957,13 +1982,10 @@ public FileData getRecordStructureData(RecordKey key) throws ControlServiceExcep .arrayFormat(DATA_NAME_PATTERN, new Object[] { "configuration-override", key.getSchemaVersion() }).getMessage(); break; case NOTIFICATION_SCHEMA: - NotificationSchemaDto notificationSchemaDto = - notificationService.findNotificationSchemaByAppIdAndTypeAndVersion(key.getApplicationId(), NotificationTypeDto.USER, key.getSchemaVersion()); - if (notificationSchemaDto == null) { - throw new NotFoundException("Schema " + RecordFiles.NOTIFICATION_SCHEMA + " not found!"); - } - CTLSchemaDto ctlSchemaDto = ctlService.findCTLSchemaById(notificationSchemaDto.getCtlSchemaId()); - schema = ctlSchemaDto.getBody(); + schemaDto = notificationService.findNotificationSchemaByAppIdAndTypeAndVersion(key.getApplicationId(), + NotificationTypeDto.USER, key.getSchemaVersion()); + checkSchema(schemaDto, RecordFiles.NOTIFICATION_SCHEMA); + schema = schemaDto.getSchema(); fileName = MessageFormatter.arrayFormat(DATA_NAME_PATTERN, new Object[] { "notification", key.getSchemaVersion() }) .getMessage(); break; diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/control/AbstractTestControlServer.java b/server/node/src/test/java/org/kaaproject/kaa/server/control/AbstractTestControlServer.java index 48cfc0e26f..3c3fb7e184 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/control/AbstractTestControlServer.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/control/AbstractTestControlServer.java @@ -942,21 +942,19 @@ protected TopicDto createTopic(String appId, TopicTypeDto type) throws Exception */ protected NotificationSchemaDto createNotificationSchema(String appId, NotificationTypeDto type) throws Exception { NotificationSchemaDto notificationSchema = new NotificationSchemaDto(); + notificationSchema.setType(type); notificationSchema.setName(generateString("Test Schema")); notificationSchema.setDescription(generateString("Test Desc")); - notificationSchema.setType(type); if (strIsEmpty(appId)) { ApplicationDto applicationDto = createApplication(tenantAdminDto); notificationSchema.setApplicationId(applicationDto.getId()); } else { notificationSchema.setApplicationId(appId); } - CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null); - notificationSchema.setCtlSchemaId(ctlSchema.getId()); - loginTenantDeveloper(tenantDeveloperDto.getUsername()); NotificationSchemaDto savedSchema = client - .createNotificationSchema(notificationSchema); + .createNotificationSchema(notificationSchema, + AdminClient.getStringResource("BasicSystemNotification", BasicSystemNotification.SCHEMA$.toString())); return savedSchema; } @@ -976,11 +974,9 @@ protected NotificationSchemaDto createUserNotificationSchema(String appId) throw } else { notificationSchema.setApplicationId(appId); } - CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null); - notificationSchema.setCtlSchemaId(ctlSchema.getId()); loginTenantDeveloper(tenantDeveloperDto.getUsername()); NotificationSchemaDto savedSchema = client - .createNotificationSchema(notificationSchema); + .createNotificationSchema(notificationSchema, TEST_USER_NOTIFICATION_SCHEMA); return savedSchema; } diff --git a/test-gh-pages-current b/test-gh-pages-current deleted file mode 160000 index cbe7d24fed..0000000000 --- a/test-gh-pages-current +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cbe7d24fed3a971ce0ba80125b16d84e6f0389cf diff --git a/test-gh-pages.sh b/test-gh-pages.sh index c3a5fa5cb1..26df77ea11 100755 --- a/test-gh-pages.sh +++ b/test-gh-pages.sh @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -. ./gh-pages-stub/scripts/tst_deploy.sh \ No newline at end of file +. ./gh-pages-stub/scripts/tst_deploy.sh