From 5ecf6d642ffa84b85af785e8ff30c224d2c60947 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 18 Feb 2016 15:52:31 +0200 Subject: [PATCH] KAA-603: CTL feature implementation. --- .../avro/default_system_empty_schema.avsc | 2 + .../kaa/server/common/admin/AdminClient.java | 65 +- .../kaa/server/common/dao/CTLService.java | 161 +++-- .../kaa/server/common/dao/DaoConstants.java | 31 +- .../server/common/dao/impl/CTLSchemaDao.java | 90 ++- .../common/dao/impl/CTLSchemaMetaInfoDao.java | 80 ++- .../dao/impl/sql/HibernateCTLSchemaDao.java | 301 ++++++--- .../sql/HibernateCTLSchemaMetaInfoDao.java | 167 +++-- .../common/dao/model/sql/CTLSchema.java | 199 +++--- .../dao/model/sql/CTLSchemaMetaInfo.java | 183 +++--- .../common/dao/service/CTLServiceImpl.java | 329 +++++----- .../kaa/server/common/dao/AbstractTest.java | 34 +- .../dao/impl/sql/HibernateAbstractTest.java | 35 +- .../impl/sql/HibernateCTLSchemaDaoTest.java | 46 +- .../dao/model/sql/CTLSchemaMetaInfoTest.java | 24 +- .../dao/service/AbstractServiceImplTest.java | 20 +- .../dao/service/CTLServiceImplTest.java | 162 +++-- .../kaa/common/dto/admin/AuthResultDto.java | 9 + .../common/dto/ctl/AbstractCTLSchemaDto.java | 110 ---- .../kaa/common/dto/ctl/CTLSchemaDto.java | 195 +++--- .../kaa/common/dto/ctl/CTLSchemaInfoDto.java | 161 ----- .../common/dto/ctl/CTLSchemaMetaInfoDto.java | 161 +++-- .../kaa/common/dto/ctl/CTLSchemaScopeDto.java | 2 +- .../admin/client/mvp/ClientFactory.java | 13 +- .../admin/client/mvp/ClientFactoryImpl.java | 52 +- .../AbstractBaseCtlSchemaActivity.java | 61 +- .../mvp/activity/AbstractDetailsActivity.java | 2 +- .../mvp/activity/AbstractListActivity.java | 6 +- .../client/mvp/activity/AefMapsActivity.java | 4 +- .../mvp/activity/AppActivityMapper.java | 6 + .../ApplicationCtlSchemasActivity.java | 67 ++ .../mvp/activity/ApplicationsActivity.java | 4 +- .../ConfigurationSchemasActivity.java | 4 +- .../mvp/activity/CtlSchemaActivity.java | 190 +++++- .../mvp/activity/CtlSchemasActivity.java | 71 +++ .../client/mvp/activity/EcfsActivity.java | 4 +- .../mvp/activity/EndpointGroupsActivity.java | 4 +- .../mvp/activity/LogAppendersActivity.java | 2 +- .../mvp/activity/LogSchemasActivity.java | 4 +- .../activity/NotificationSchemasActivity.java | 4 +- .../mvp/activity/ProfileSchemaActivity.java | 10 +- .../mvp/activity/ProfileSchemasActivity.java | 4 +- .../mvp/activity/SdkProfilesActivity.java | 2 +- .../activity/ServerProfileSchemaActivity.java | 8 +- .../ServerProfileSchemasActivity.java | 4 +- .../activity/SystemCtlSchemasActivity.java | 67 ++ .../activity/TenantCtlSchemasActivity.java | 30 +- .../client/mvp/activity/TenantsActivity.java | 4 +- .../client/mvp/activity/TopicsActivity.java | 4 +- .../mvp/activity/UserVerifiersActivity.java | 2 +- .../client/mvp/activity/UsersActivity.java | 4 +- .../activity/grid/AbstractDataProvider.java | 48 +- .../client/mvp/activity/grid/DataFilter.java | 23 + .../client/mvp/data/AefMapsDataProvider.java | 4 +- .../mvp/data/AppendersDataProvider.java | 4 +- .../ApplicationCtlSchemasDataProvider.java | 61 ++ .../mvp/data/ApplicationsDataProvider.java | 4 +- .../ConfigurationSchemasDataProvider.java | 4 +- .../mvp/data/ConfigurationsDataProvider.java | 5 +- .../admin/client/mvp/data/DataSource.java | 117 +++- .../mvp/data/EcfSchemasDataProvider.java | 4 +- .../client/mvp/data/EcfsDataProvider.java | 4 +- .../mvp/data/EndpointGroupsDataProvider.java | 4 +- .../mvp/data/EndpointProfileDataProvider.java | 6 +- .../client/mvp/data/EventMapDataProvider.java | 4 +- .../mvp/data/LogSchemasDataProvider.java | 6 +- .../data/NotificationSchemasDataProvider.java | 4 +- .../mvp/data/ProfileFiltersDataProvider.java | 5 +- .../mvp/data/ProfileSchemasDataProvider.java | 4 +- .../mvp/data/SdkProfilesDataProvider.java | 4 +- .../ServerProfileSchemasDataProvider.java | 4 +- .../data/SystemCtlSchemasDataProvider.java | 51 ++ .../data/TenantCtlSchemasDataProvider.java | 12 +- .../client/mvp/data/TenantsDataProvider.java | 4 +- .../client/mvp/data/TopicsDataProvider.java | 4 +- .../mvp/data/UserVerifiersDataProvider.java | 4 +- .../client/mvp/data/UsersDataProvider.java | 4 +- .../mvp/place/ApplicationCtlSchemasPlace.java | 85 +++ .../client/mvp/place/ApplicationPlace.java | 1 + .../client/mvp/place/CtlSchemaPlace.java | 176 ++++-- .../mvp/place/KaaAdminPlaceHistoryMapper.java | 4 +- .../client/mvp/place/PlaceConstants.java | 8 +- .../mvp/place/SystemCtlSchemasPlace.java | 65 ++ .../place/TenantAdminPlaceHistoryMapper.java | 4 +- .../mvp/place/TenantCtlSchemasPlace.java | 4 +- .../TenantDeveloperPlaceHistoryMapper.java | 1 + .../place/TenantUserPlaceHistoryMapper.java | 1 + .../client/mvp/view/BaseCtlSchemaView.java | 9 +- .../admin/client/mvp/view/BaseListView.java | 2 +- .../admin/client/mvp/view/CtlSchemaView.java | 11 +- .../admin/client/mvp/view/CtlSchemasView.java | 29 + .../mvp/view/appender/LogAppenderGrid.java | 2 +- .../view/appender/LogAppenderViewImpl.java | 2 +- .../mvp/view/base/BaseDetailsViewImpl.java | 146 ++++- .../mvp/view/base/BaseDetailsViewImpl.ui.xml | 31 +- .../mvp/view/base/BaseListViewImpl.java | 12 +- .../mvp/view/base/BaseListViewImpl.ui.xml | 2 +- .../ctl/ApplicationCtlSchemaViewImpl.java | 30 + .../ctl/ApplicationCtlSchemasViewImpl.java | 38 ++ .../admin/client/mvp/view/ctl/CtlGrid.java | 78 ++- .../mvp/view/ctl/CtlSchemaViewImpl.java | 256 ++++++-- .../mvp/view/ctl/CtlSchemasViewImpl.java | 34 +- .../view/ctl/SystemCtlSchemasViewImpl.java | 28 + .../view/ctl/TenantCtlSchemasViewImpl.java | 33 + .../endpoint/EndpointProfileViewImpl.java | 4 +- .../endpoint/EndpointProfilesViewImpl.ui.xml | 2 +- .../enduser/UpdateUserConfigViewImpl.java | 4 +- .../navigation/NavigationTreeViewModel.java | 3 + .../view/schema/BaseCtlSchemaViewImpl.java | 23 +- .../mvp/view/sdk/AddSdkProfileViewImpl.java | 4 +- .../mvp/view/sdk/SdkProfileViewImpl.java | 4 +- .../mvp/view/struct/BaseRecordViewImpl.java | 6 +- .../view/topic/SendNotificationViewImpl.java | 4 +- .../client/mvp/view/topic/TopicViewImpl.java | 2 +- .../view/widget/CtlSchemaReferenceBox.java | 30 +- .../client/mvp/view/widget/RecordPanel.java | 42 +- .../kaa/server/admin/client/util/Utils.java | 28 + .../admin/controller/KaaAdminController.java | 125 ++-- .../admin/services/KaaAdminServiceImpl.java | 597 +++++++++++------- .../admin/services/KaaAuthServiceImpl.java | 1 + .../services/schema/CTLSchemaParser.java | 105 +-- .../shared/schema/BaseSchemaViewDto.java | 7 +- .../admin/shared/schema/CtlSchemaFormDto.java | 90 +-- .../shared/schema/CtlSchemaReferenceDto.java | 84 +++ .../admin/shared/schema/SchemaFqnDto.java | 61 -- .../shared/services/KaaAdminService.java | 51 +- .../control/service/ControlService.java | 145 +++-- .../service/DefaultControlService.java | 108 ++-- .../kaa/server/admin/client/KaaAdminTheme.css | 12 + .../client/i18n/KaaAdminConstants.properties | 44 +- .../client/i18n/KaaAdminMessages.properties | 8 +- .../control/AbstractTestControlServer.java | 57 +- .../control/ControlServerCTLSchemaIT.java | 138 +++- .../control/ControlServerProfileFilterIT.java | 5 +- .../control/ControlServerProfileSchemaIT.java | 7 +- .../service/OperationsServiceIT.java | 14 +- .../service/delta/DeltaServiceIT.java | 45 +- .../service/profile/ProfileServiceIT.java | 23 +- 138 files changed, 4171 insertions(+), 2406 deletions(-) delete mode 100644 server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/AbstractCTLSchemaDto.java delete mode 100644 server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaInfoDto.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationCtlSchemasActivity.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemasActivity.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SystemCtlSchemasActivity.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/DataFilter.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationCtlSchemasDataProvider.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SystemCtlSchemasDataProvider.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SystemCtlSchemasPlace.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemasView.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemaViewImpl.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemasViewImpl.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/SystemCtlSchemasViewImpl.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/TenantCtlSchemasViewImpl.java create mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaReferenceDto.java delete mode 100644 server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/SchemaFqnDto.java diff --git a/common/endpoint-shared/src/main/avro/default_system_empty_schema.avsc b/common/endpoint-shared/src/main/avro/default_system_empty_schema.avsc index 5c9a0b2db8..3ae0a41cd6 100644 --- a/common/endpoint-shared/src/main/avro/default_system_empty_schema.avsc +++ b/common/endpoint-shared/src/main/avro/default_system_empty_schema.avsc @@ -4,5 +4,7 @@ "namespace": "org.kaaproject.kaa.schema.system", "version": 1, "dependencies": [], + "displayName": "Empty Data", + "description": "Auto generated", "fields": [] } \ No newline at end of file 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 a985c94bce..7c4223b846 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 @@ -62,9 +62,8 @@ import org.kaaproject.kaa.common.dto.admin.SdkProfileDto; import org.kaaproject.kaa.common.dto.admin.TenantUserDto; import org.kaaproject.kaa.common.dto.admin.UserDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.EcfInfoDto; @@ -953,49 +952,77 @@ public String getFilename() { return bar; } - public CTLSchemaInfoDto saveCTLSchema(String body, CTLSchemaScopeDto scope, String applicationId) { + public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicationId) { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("body", body); - if (scope != null) { - params.add("scope", scope.name()); + if (tenantId != null) { + params.add("tenantId", tenantId); } if (applicationId != null) { params.add("applicationId", applicationId); } - return restTemplate.postForObject(url + "CTL/saveSchema", params, CTLSchemaInfoDto.class); + return restTemplate.postForObject(url + "CTL/saveSchema", params, CTLSchemaDto.class); } - public void deleteCTLSchemaByFqnAndVersion(String fqn, Integer version) { + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, + Integer version, + String tenantId, + String applicationId) { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("fqn", fqn); params.add("version", version); + if (tenantId != null) { + params.add("tenantId", tenantId); + } + if (applicationId != null) { + params.add("applicationId", applicationId); + } restTemplate.postForLocation(url + "CTL/deleteSchema", params); } - public CTLSchemaInfoDto getCTLSchemaByFqnAndVersion(String fqn, Integer version) { - return restTemplate.getForObject(url + "CTL/getSchema?fqn={fqn}&version={version}", CTLSchemaInfoDto.class, fqn, version); + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { + if (tenantId != null && applicationId != null) { + return restTemplate.getForObject(url + "CTL/getSchema?fqn={fqn}&version={version}&tenantId={tenantId}&applicationId={applicationId}", CTLSchemaDto.class, fqn, version, tenantId, applicationId); + }else if (tenantId != null) { + return restTemplate.getForObject(url + "CTL/getSchema?fqn={fqn}&version={version}&tenantId={tenantId}", CTLSchemaDto.class, fqn, version, tenantId); + } else { + return restTemplate.getForObject(url + "CTL/getSchema?fqn={fqn}&version={version}", CTLSchemaDto.class, fqn, version); + } + } + + public boolean checkFqnExists(String fqn, String tenantId, String applicationId) { + if (tenantId != null && applicationId != null) { + return restTemplate.getForObject(url + "CTL/checkFqn?fqn={fqn}&tenantId={tenantId}&applicationId={applicationId}", + Boolean.class, fqn, tenantId, applicationId); + } else if (tenantId != null) { + return restTemplate.getForObject(url + "CTL/checkFqn?fqn={fqn}&tenantId={tenantId}", Boolean.class, fqn, tenantId); + } else { + return restTemplate.getForObject(url + "CTL/checkFqn?fqn={fqn}", Boolean.class, fqn); + } + } + + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) { + return restTemplate.postForObject(url + "CTL/updateScope", ctlSchemaMetaInfo, CTLSchemaMetaInfoDto.class); } - public List getCTLSchemasAvailable() { + public List getSystemLevelCTLSchemas() { ParameterizedTypeReference> typeRef = new ParameterizedTypeReference>() { }; - ResponseEntity> entity = restTemplate.exchange(url + "CTL/getSchemas", HttpMethod.GET, null, typeRef); + ResponseEntity> entity = restTemplate.exchange(url + "CTL/getSystemSchemas", HttpMethod.GET, null, typeRef); return entity.getBody(); } - - public List getCTLSchemasByScope(String scopeName) { + + public List getTenantLevelCTLSchemas() { ParameterizedTypeReference> typeRef = new ParameterizedTypeReference>() { }; - ResponseEntity> entity = restTemplate.exchange(url + "CTL/getSchemas?scope=" + scopeName, - HttpMethod.GET, null, typeRef); + ResponseEntity> entity = restTemplate.exchange(url + "CTL/getTenantSchemas", HttpMethod.GET, null, typeRef); return entity.getBody(); } - - public List getCTLSchemasByApplicationId(String applicationId) { + + public List getApplicationLevelCTLSchemas(String applicationId) { ParameterizedTypeReference> typeRef = new ParameterizedTypeReference>() { }; - ResponseEntity> entity = restTemplate.exchange(url + "CTL/getSchemas?applicationId=" + applicationId, - HttpMethod.GET, null, typeRef); + ResponseEntity> entity = restTemplate.exchange(url + "CTL/getApplicationSchemas/" + applicationId, HttpMethod.GET, null, typeRef); return entity.getBody(); } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/CTLService.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/CTLService.java index 8df53ccb66..0ada9b313c 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/CTLService.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/CTLService.java @@ -16,13 +16,13 @@ package org.kaaproject.kaa.server.common.dao; +import java.util.List; + import org.apache.avro.Schema; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.file.FileData; -import java.util.List; - /** * Common type library service. */ @@ -48,9 +48,29 @@ public interface CTLService { * @return CTLSchemaDto the updated object. */ CTLSchemaDto updateCTLSchema(CTLSchemaDto ctlSchema); + + /** + * Update existing CTL schema meta info scope by the given CTL schema meta info object. + * + * @param ctlSchemaMetaInfo + * the CTL schema meta info object. + * @return CTLSchemaMetaInfoDto the updated CTL schema meta info object. + */ + CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo); /** - * Remove a CTL schema of the given tenant with the given fully qualified + * Find CTL schema meta infos which are the application level siblings to the CTL + * of the given fully qualified name, tenant and application identifiers. + * + * @param fqn the fully qualified. + * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the CTL schema meta information objects which are the siblings to the given CTL. + */ + List findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + + /** + * Remove a CTL schema of the given tenant or application with the given fully qualified * name and version number. * * @param fqn @@ -59,8 +79,10 @@ public interface CTLService { * the schema version. * @param tenantId * the tenant identifier. + * @param applicationId + * the application identifier. */ - void removeCTLSchemaByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId); + void removeCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId); /** * Find a CTL schema with the given identifier. @@ -81,15 +103,16 @@ public interface CTLService { CTLSchemaDto saveCTLSchema(CTLSchemaDto ctlSchemaDto); /** - * Remove a CTL schema with the given identifier. + * Find CTL schema with the given meta info id and version. * - * @param schemaId - * the CTL schema identifier. - */ - void removeCTLSchemaById(String schemaId); - + * @param metaInfoId the id of meta info object. + * @param version the schema version. + * @return the CTL schema with the given meta info id and version. + */ + CTLSchemaDto findByMetaInfoIdAndVer(String metaInfoId, Integer version); + /** - * Find a CTL schema of the given tenant with the given fully qualified name + * Find a CTL schema of the given tenant or application with the given fully qualified name * and version number. * * @param fqn @@ -98,75 +121,111 @@ public interface CTLService { * the CTL schema version. * @param tenantId * the tenant identifier. + * @param applicationId + * the application identifier. * @return the CTL schema with the given fully qualified name and version * number. */ - CTLSchemaDto findCTLSchemaByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId); + CTLSchemaDto findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId); + /** + * Find any CTL schema of the given tenant or application with the given fully qualified name + * and version number. + * + * @param fqn + * the fully qualified name. + * @param version + * the CTL schema version. + * @param tenantId + * the tenant identifier. + * @param applicationId + * the application identifier. + * @return the any CTL schema with the given fully qualified name and version + * number. + */ + CTLSchemaDto findAnyCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId); + /** * Find system CTL schemas available in the database. * * @return the list of available system CTL schemas in the database. */ List findSystemCTLSchemas(); - + /** - * Find system meta information of CTL schemas available in the database. + * Find system CTL schemas meta info available in the database. * - * @return the list of available system CTL meta information in the - * database. + * @return the list of available system CTL schemas meta info in the database. */ List findSystemCTLSchemasMetaInfo(); - + /** - * Find the last version of CTL schema with the given fully qualified name. + * Find available CTL schemas meta info for tenant(include + * system scope) with the given tenant identifier. * - * @param fqn - * the fully qualified name. - * @return the latest version of CTL schema with the given fully qualified - * name. + * @param tenantId + * the tenant identifier. + * @return the list of available CTL schemas meta info for tenant + * with given identifier. */ - CTLSchemaDto findLatestCTLSchemaByFqn(String fqn); - + List findAvailableCTLSchemasMetaInfoForTenant(String tenantId); + /** - * Find CTL schemas available in the database. + * Find available CTL schemas meta info for application(include + * system and tenant scope) with the given tenant and application identifier. * - * @return the list of available CTL schemas in the database. + * @param tenantId + * the tenant identifier. + * @param applicationId + * the application identifier. + * @return the list of available CTL schemas meta info for application + * with given identifier. */ - List findCTLSchemas(); + List findAvailableCTLSchemasMetaInfoForApplication(String tenantId, String applicationId); /** - * Find meta information of CTL schemas with the given application - * identifier. + * Find the last version of CTL schema with the given fully qualified name, tenant and application identifier. * - * @param appId + * @param fqn + * the fully qualified name. + * @param tenantId + * the tenant identifier. + * @param applicationId * the application identifier. - * @return the list of meta information of CTL schemas with application - * identifier. + * @return the latest version of CTL schema with the given fully qualified + * name, tenant and application identifier. */ - List findCTLSchemasMetaInfoByApplicationId(String appId); + CTLSchemaDto findLatestCTLSchemaByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); /** - * Find meta information of CTL schemas with the given tenant identifier with tenant scope. + * Find the last version of CTL schema with the given meta info id. * - * @param tenantId - * the tenant identifier. - * @return the list of meta information of CTL schemas with tenant - * identifier. - */ - List findTenantCTLSchemasMetaInfoByTenantId(String tenantId); + * @param metaInfoId the id of meta info object. + * @return the latest version of CTL schema with the given meta info id. + */ + CTLSchemaDto findLatestByMetaInfoId(String metaInfoId); /** - * Find available CTL schemas meta information schemas for tenant(include - * system scope) with the given tenant identifier. + * Find all available versions of CTL schema with the given fully qualified name, tenant and application identifier. * + * @param fqn + * the fully qualified name. * @param tenantId * the tenant identifier. - * @return the list of available meta information of CTL schemas for tenant - * with given identifier. + * @param applicationId + * the application identifier. + * @return the list of available versions of CTL schema with the given fully qualified + * name, tenant and application identifier. */ - List findAvailableCTLSchemasMetaInfo(String tenantId); - + List findAllCTLSchemasByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + + /** + * Find CTL schemas available in the database. + * + * @return the list of available CTL schemas in the database. + */ + List findCTLSchemas(); + /** * Find the dependents CTL schemas from CTL schema with the given schema * identifier @@ -179,8 +238,8 @@ public interface CTLService { List findCTLSchemaDependents(String schemaId); /** - * Find the dependents CTL schemas from CTL schema with the given tenant, - * given fully qualified name and version number. + * Find the dependents CTL schemas from CTL schema with the given tenant, application, + * fully qualified name and version number. * * @param fqn * the fully qualified name. @@ -188,10 +247,12 @@ public interface CTLService { * the schema version. * @param tenantId * the tenant identifier. + * @param applicationId + * the application identifier. * @return the list of dependents CTL schemas from CTL schema with the given - * tenant identifier, fully qualified name and version. + * tenant, application, fully qualified name and version. */ - List findCTLSchemaDependents(String fqn, Integer version, String tenantId); + List findCTLSchemaDependents(String fqn, Integer version, String tenantId, String applicationId); /** * Exports the body of a CTL schema. diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/DaoConstants.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/DaoConstants.java index bde3e5ae51..9187d2bd21 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/DaoConstants.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/DaoConstants.java @@ -369,18 +369,13 @@ public class DaoConstants { * CTL schema constants */ public static final String CTL_SCHEMA_TABLE_NAME = "ctl"; - public static final String CTL_SCHEMA_APPLICATION_ID = APPLICATION_ID; - public static final String CTL_SCHEMA_TENANT_ID = TENANT_ID; public static final String CTL_SCHEMA_META_INFO_ID = "metainfo_id"; + public static final String CTL_SCHEMA_VERSION = VERSION; public static final String CTL_SCHEMA_BODY = "body"; public static final String CTL_SCHEMA_DEFAULT_RECORD = "default_record"; - public static final String CTL_SCHEMA_NAME = NAME; - public static final String CTL_SCHEMA_DESCRIPTION = DESCRIPTION; public static final String CTL_SCHEMA_CREATED_USERNAME = CREATED_USERNAME; public static final String CTL_SCHEMA_CREATED_TIME = CREATED_TIME; // CTL schema foreign keys - public static final String CTL_SCHEMA_APPLICATION_FK = "fk_ctl_app_id"; - public static final String CTL_SCHEMA_TENANT_FK = "fk_ctl_tenant_id"; public static final String CTL_SCHEMA_META_INFO_FK = "fk_ctl_metainfo_id"; public static final String CTL_SCHEMA_JOIN_TABLE_PARENT_FK = "fk_ctl_pr_id"; public static final String CTL_SCHEMA_JOIN_TABLE_CHILD_FK = "fk_ctl_ch_id"; @@ -390,29 +385,35 @@ public class DaoConstants { public static final String CTL_SCHEMA_JOIN_TABLE_PARENT_ID = "parent_id"; public static final String CTL_SCHEMA_JOIN_TABLE_CHILD_ID = "child_id"; // Properties and alias constants - public static final String CTL_SCHEMA_TENANT_ID_ALIAS = "tenant.id"; - public static final String CTL_SCHEMA_APPLICATION_ID_ALIAS = "application.id"; public static final String CTL_SCHEMA_DEPENDENCY_PROP = "dependencySet"; public static final String CTL_SCHEMA_DEPENDENCY_ALIAS = "dep"; public static final String CTL_SCHEMA_DEPENDENCY_ID_ALIAS = CTL_SCHEMA_DEPENDENCY_ALIAS + "." + ID; - /** * CTL schema meta info constants */ public static final String CTL_SCHEMA_META_INFO_TABLE_NAME = "ctl_metainfo"; public static final String CTL_SCHEMA_META_INFO_FQN = FQN; - public static final String CTL_SCHEMA_META_INFO_VERSION = VERSION; - public static final String CTL_SCHEMA_META_INFO_SCOPE = "scope"; + public static final String CTL_SCHEMA_META_INFO_TENANT_ID = TENANT_ID; + public static final String CTL_SCHEMA_META_INFO_APPLICATION_ID = APPLICATION_ID; public static final String CTL_SCHEMA_META_INFO_UNIQUE_CONSTRAINT = "ctl_metainfo_unique_constraint"; + + // CTL schema meta info foreign keys + public static final String CTL_SCHEMA_META_INFO_TENANT_FK = "fk_ctl_metainfo_tenant_id"; + public static final String CTL_SCHEMA_META_INFO_APPLICATION_FK = "fk_ctl_metainfo_app_id"; + + // Properties and alias constants + // Properties and alias constants + public static final String CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS = TENANT_REFERENCE; + public static final String CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS = APPLICATION_REFERENCE; public static final String CTL_SCHEMA_META_INFO_PROPERTY = "metaInfo"; public static final String CTL_SCHEMA_META_INFO_ALIAS = "mi"; - public static final String CTL_SCHEMA_META_INFO_ALIAS_VERSION = CTL_SCHEMA_META_INFO_ALIAS + "." + CTL_SCHEMA_META_INFO_VERSION; public static final String CTL_SCHEMA_META_INFO_ALIAS_FQN = CTL_SCHEMA_META_INFO_ALIAS + "." + CTL_SCHEMA_META_INFO_FQN; - public static final String CTL_SCHEMA_META_INFO_ALIAS_SCOPE = CTL_SCHEMA_META_INFO_ALIAS + "." + CTL_SCHEMA_META_INFO_SCOPE; - - + public static final String CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID = CTL_SCHEMA_META_INFO_ALIAS + "." + TENANT_REFERENCE; + public static final String CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID = CTL_SCHEMA_META_INFO_ALIAS + "." + APPLICATION_REFERENCE; + public static final String CTL_SCHEMA_META_INFO_ALIAS_ID = CTL_SCHEMA_META_INFO_ALIAS + "." + ID_PROPERTY; + public static final String LAST_PAGE_MESSAGE = "It is the last page"; public static final String PROFILE = "profile"; diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaDao.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaDao.java index 56a551f0a1..5df7082db8 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaDao.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaDao.java @@ -31,64 +31,100 @@ public interface CTLSchemaDao extends SqlDao { * @return the list of CTL schemas available in the database. */ List findSystemSchemas(); - + /** - * Find CTL schemas with the given tenant identifier with tenant scope. + * Find available for tenant(include system scope) CTL schemas by given tenant identifier. * * @param tenantId the tenant identifier. - * @return the list of CTL schemas with given tenant identifier. + * @return the list of available schemas. */ - List findTenantSchemasByTenantId(String tenantId); - + List findAvailableSchemasForTenant(String tenantId); + /** - * Find CTL schemas with the given application identifier. - * + * Find available for application(include system and tenant scope) CTL schemas by given tenant and application identifier. + * + * @param tenantId the tenant identifier. * @param appId the application identifier. - * @return the list of CTL schemas with given application identifier. + * @return the list of available schemas. */ - List findByApplicationId(String appId); + List findAvailableSchemasForApplication(String tenantId, String appId); /** - * Find the last version of CTL schema with the given fully qualified name. + * Find CTL schema with the given meta info id and version. * - * @param fqn the qualified name. - * @return the latest version of CTL schema with the given fully qualified name. + * @param metaInfoId the id of meta info object. + * @param version the schema version. + * @return the CTL schema with the given meta info id and version. */ - T findLatestByFqn(String fqn); - + + T findByMetaInfoIdAndVer(String metaInfoId, Integer version); + /** - * Find CTL schema with the given fully qualified name, version and tenant identifier. + * Find CTL schema with the given fully qualified name, version, tenant and application identifiers. * * @param fqn the fully qualified name. * @param version the schema version. * @param tenantId the tenant identifier. - * @return the CTL schema with the given fully qualified name, version and tenant identifier. + * @param applicationId the application identifier. + * @return the CTL schema with the given fully qualified name, version, tenant and application identifiers. */ - T findByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId); + T findByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId); + /** - * Remove CTL schemas with the given fully qualified name, version and tenant identifier. + * Find any CTL schema with the given fully qualified name, version, tenant and application identifiers. * * @param fqn the fully qualified name. * @param version the schema version. * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the any CTL schema with the given fully qualified name, version, tenant and application identifiers. */ - void removeByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId); + T findAnyByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId); /** - * Find dependents CTL schemas from the schema with the given schema identifier. + * Find the last version of CTL schema with the given fully qualified name, tenant and application identifiers. * - * @param schemaId the schema identifier. - * @return the list of dependents schemas from schema with given identifier. + * @param fqn the qualified name. + * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the latest version of CTL schema with the given fully qualified name, tenant and application identifiers. */ - List findDependentSchemas(String schemaId); - + T findLatestByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + /** - * Find available for tenant(include system scope) CTL schemas by given tenant identifier. + * Find the last version of CTL schema with the given meta info id. * + * @param metaInfoId the id of meta info object. + * @return the latest version of CTL schema with the given meta info id. + */ + + T findLatestByMetaInfoId(String metaInfoId); + + /** + * Find all available versions of CTL schema with the given fully qualified name, tenant and application identifiers. + * + * @param fqn the qualified name. * @param tenantId the tenant identifier. - * @return the list of available schemas. + * @param applicationId the application identifier. + * @return the list of available versions of CTL schema with the given fully qualified name, tenant and application identifiers. */ - List findAvailableSchemas(String tenantId); + List findAllByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + + /** + * Find all available versions of CTL schema with the given meta info id. + * + * @param metaInfoId the id of meta info object. + * @return the list of available versions of CTL schema with the given meta info id. + */ + List findAllByMetaInfoId(String metaInfoId); + + /** + * Find dependents CTL schemas from the schema with the given schema identifier. + * + * @param schemaId the schema identifier. + * @return the list of dependents schemas from schema with given identifier. + */ + List findDependentSchemas(String schemaId); } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaMetaInfoDao.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaMetaInfoDao.java index cb52185dc7..bffbfd12e9 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaMetaInfoDao.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaMetaInfoDao.java @@ -1,23 +1,21 @@ -/* - * Copyright 2015 CyberVision, Inc. +/** + * Copyright 2014-2016 CyberVision, Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.kaaproject.kaa.server.common.dao.impl; -import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchemaMetaInfo; - import java.util.List; /** @@ -28,36 +26,56 @@ public interface CTLSchemaMetaInfoDao extends SqlDao { /** - * Increment count of the given CTL schema meta information. - * This is number of CTL schemas used the same meta information. + * Find a CTL schema meta info of the given fully qualified name, tenant and application identifiers. * - * @param metaInfo the CTL schema meta information object - * @return the CTL schema meta information with incremented count. + * @param fqn the fully qualified. + * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the CTL schema meta information object with given + * fully qualified name, tenant and application identifiers. */ - T incrementCount(T metaInfo); - + T findByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + /** - * Find a CTL schema of the given fully qualified name and version number. + * Find CTL schema meta infos which are the application level siblings to the CTL + * of the given fully qualified name, tenant and application identifiers. * * @param fqn the fully qualified. - * @param version the schema version. - * @return the CTL schema meta information object with given . + * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the CTL schema meta information objects which are the siblings to the given CTL. */ - T findByFqnAndVersion(String fqn, Integer version); - + List findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + /** - * Find a CTL schema meta information - * by the given fully qualified name and version number. + * Find a list of CTL schema meta infos of the given fully qualified name + * which is not in specified tenant or application scope. * - * @return the list of system CTL schema meta information. + * @param fqn the fully qualified. + * @param excludingTenantId the tenant identifier. + * @param excludingApplicationId the application identifier. + * @return the list of CTL schemas meta information object with given fully qualified name. */ - List findSystemSchemaMetaInfo(); - + List findExistingFqns(String fqn, String excludingTenantId, String excludingApplicationId); + + /** + * Find others CTL schema meta infos with the given fully qualified name and tenant, excluding meta info id. + * + * @param fqn the fully qualified name. + * @param tenantId the tenant identifier. + * @param excludingId the ctl schema meta info identifier to exclude. + * @return the others CTL schema meta infos with the given fully qualified name and tenant identifier. + */ + List findOthersByFqnAndTenantId(String fqn, String tenantId, String excludingId); + /** * Update scope of the given CTL schema meta information. * * @param ctlSchema the CTL schema meta information object. * @return the saved the CTL schema meta information object. */ - T updateScope(CTLSchemaMetaInfo ctlSchema); -} + T updateScope(T ctlSchema); + + + +} \ No newline at end of file diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDao.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDao.java index e7a729514f..02542445dd 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDao.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 CyberVision, Inc. + * Copyright 2015-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,33 +16,34 @@ package org.kaaproject.kaa.server.common.dao.impl.sql; +import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_ALIAS; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_ID_ALIAS; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_PROP; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_FQN; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_ID; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_PROPERTY; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_VERSION; + +import java.util.Arrays; +import java.util.List; + import org.hibernate.Criteria; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.hibernate.sql.JoinType; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaDao; import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.apache.commons.lang.StringUtils.isNotBlank; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_APPLICATION_ID_ALIAS; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_ALIAS; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_ID_ALIAS; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEPENDENCY_PROP; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_FQN; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_SCOPE; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ALIAS_VERSION; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_PROPERTY; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_TENANT_ID_ALIAS; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; @Repository public class HibernateCTLSchemaDao extends HibernateAbstractDao implements CTLSchemaDao { @@ -54,46 +55,51 @@ protected Class getEntityClass() { return CTLSchema.class; } - private Criterion buildScopeCriterion(CTLSchemaScopeDto... scopes) { - List scopeCriterions = new ArrayList<>(); - for (CTLSchemaScopeDto scope : scopes) { - scopeCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_SCOPE, scope)); - } - if (scopeCriterions.size() == 1) { - return scopeCriterions.get(0); + private Criterion buildScopeCriterion(String tenantId, String applicationId) { + if (isBlank(tenantId)) { + // SYSTEM - tenantId=null && appId=null + return Restrictions.and(Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID), + Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)); } else { - return Restrictions.or(scopeCriterions.toArray(new Criterion[scopeCriterions.size()])); + if (isBlank(applicationId)) { + // TENANT - (tenantId=id or tenantId=null) && appId=null + return Restrictions.and(Restrictions.or( + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)), + Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID) + ), + Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)); + } else { + // APPLICATION - (tenantId=id or tenantId=null) && (appId=id or appId=null) + return Restrictions.and(Restrictions.or( + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)), + Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID) + ), + Restrictions.or( + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID, Long.valueOf(applicationId)), + Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID))); + } } } + + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public CTLSchema save(CTLSchema o) { + return super.save(o); + } @Override - public CTLSchema findByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId) { - CTLSchema ctlSchema = null; - LOG.debug("Searching ctl schema by fqn [{}] and version [{}]", fqn, version); - if (isNotBlank(fqn) && version != null) { - ctlSchema = findOneByCriterionWithAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, Restrictions.and( - Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_VERSION, version), - Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn), - Restrictions.or( - tenantId != null - ? Restrictions.eq(CTL_SCHEMA_TENANT_ID_ALIAS, Long.valueOf(tenantId)) - : Restrictions.isNull(CTL_SCHEMA_TENANT_ID_ALIAS), - buildScopeCriterion(CTLSchemaScopeDto.SYSTEM)) - )); - } - if (LOG.isTraceEnabled()) { - LOG.trace("[{},{}] Search result: [{}].", fqn, version, ctlSchema); - } else { - LOG.debug("[{},{}] Search result: [{}].", fqn, version, ctlSchema != null); - } - return ctlSchema; + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public CTLSchema save(CTLSchema o, boolean flush) { + // TODO Auto-generated method stub + return super.save(o, flush); } @Override public List findSystemSchemas() { LOG.debug("Searching system ctl metadata"); - List schemas = findListByCriterionWithAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, - buildScopeCriterion(CTLSchemaScopeDto.SYSTEM)); + List schemas = findListByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + buildScopeCriterion(null, null)); if (LOG.isTraceEnabled()) { LOG.trace("Search result: [{}].", Arrays.toString(schemas.toArray())); } else { @@ -101,13 +107,13 @@ public List findSystemSchemas() { } return schemas; } - + @Override - public List findTenantSchemasByTenantId(String tenantId) { - LOG.debug("Searching ctl schemas by tenant id [{}]", tenantId); - List availableSchemas = findListByCriterionWithAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, - Restrictions.and(Restrictions.eq(CTL_SCHEMA_TENANT_ID_ALIAS, Long.valueOf(tenantId)), - buildScopeCriterion(CTLSchemaScopeDto.TENANT))); + public List findAvailableSchemasForTenant(String tenantId) { + LOG.debug("Searching available ctl schemas for tenant with id [{}]", tenantId); + List availableSchemas = findListByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + buildScopeCriterion(tenantId, null)); if (LOG.isTraceEnabled()) { LOG.trace("[{}] Search result: [{}].", tenantId, Arrays.toString(availableSchemas.toArray())); } else { @@ -117,41 +123,165 @@ public List findTenantSchemasByTenantId(String tenantId) { } @Override - public List findByApplicationId(String appId) { - LOG.debug("Searching ctl schemas by application id [{}]", appId); - List schemas = findListByCriterion(Restrictions.eq(CTL_SCHEMA_APPLICATION_ID_ALIAS, Long.valueOf(appId))); + public List findAvailableSchemasForApplication(String tenantId, String appId) { + LOG.debug("Searching available ctl schemas for application by tenant id [{}] and application id [{}]", tenantId, appId); + List availableSchemas = findListByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + buildScopeCriterion(tenantId, appId)); if (LOG.isTraceEnabled()) { - LOG.trace("[{}] Search result: [{}].", appId, Arrays.toString(schemas.toArray())); + LOG.trace("[{}][{}] Search result: [{}].", tenantId, appId, Arrays.toString(availableSchemas.toArray())); } else { - LOG.debug("[{}] Search result: [{}].", appId, schemas.size()); + LOG.debug("[{}][{}] Search result: [{}].", tenantId, appId, availableSchemas.size()); } - return schemas; + return availableSchemas; } - + + @Override + public CTLSchema findByFqnAndVerAndTenantIdAndApplicationId(String fqn, + Integer version, String tenantId, String applicationId) { + CTLSchema ctlSchema = null; + LOG.debug("Searching ctl schema by fqn [{}], version [{}], tenant [{}] and applicationId [{}]", + fqn, version, tenantId, applicationId); + if (isNotBlank(fqn) && version != null) { + ctlSchema = findOneByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + Restrictions.and(Restrictions.eq(CTL_SCHEMA_VERSION, version), + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn), + tenantId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID), + applicationId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID, Long.valueOf(applicationId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID))); + } + if (LOG.isTraceEnabled()) { + LOG.trace("[{},{},{},{}] Search result: [{}].", fqn, version, tenantId, applicationId, ctlSchema); + } else { + LOG.debug("[{},{},{},{}] Search result: [{}].", fqn, version, tenantId, applicationId, ctlSchema != null); + } + return ctlSchema; + } + + @Override + public CTLSchema findByMetaInfoIdAndVer(String metaInfoId, Integer version) { + CTLSchema ctlSchema = null; + LOG.debug("Searching ctl schema by meta info id [{}] and version [{}]", + metaInfoId, version); + if (isNotBlank(metaInfoId) && version != null) { + ctlSchema = findOneByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + Restrictions.and(Restrictions.eq(CTL_SCHEMA_VERSION, version), + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_ID, Long.valueOf(metaInfoId)))); + } + if (LOG.isTraceEnabled()) { + LOG.trace("[{},{}] Search result: [{}].", metaInfoId, version, ctlSchema); + } else { + LOG.debug("[{},{}] Search result: [{}].", metaInfoId, version, ctlSchema != null); + } + return ctlSchema; + } + + @Override + public CTLSchema findAnyByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, + String applicationId) { + CTLSchema ctlSchema = null; + LOG.debug("Searching any ctl schema by fqn [{}], version [{}], tenant [{}] and applicationId [{}]", + fqn, version, tenantId, applicationId); + if (isNotBlank(fqn) && version != null) { + ctlSchema = findOneByCriterionWithAlias( + CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, + Restrictions.and(Restrictions.eq(CTL_SCHEMA_VERSION, version), + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn), + buildScopeCriterion(tenantId, applicationId))); + } + if (LOG.isTraceEnabled()) { + LOG.trace("[{},{},{},{}] Search result: [{}].", fqn, version, tenantId, applicationId, ctlSchema); + } else { + LOG.debug("[{},{},{},{}] Search result: [{}].", fqn, version, tenantId, applicationId, ctlSchema != null); + } + return ctlSchema; + } + @Override - public CTLSchema findLatestByFqn(String fqn) { - LOG.debug("Searching latest ctl schema by fqn [{}]", fqn); + public CTLSchema findLatestByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + LOG.debug("Searching latest ctl schema by fqn [{}], tenantId [{}] and applicationId [{}]", fqn, tenantId, applicationId); Criteria criteria = getCriteria().createAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS) - .add(Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn)).addOrder(Order.desc(CTL_SCHEMA_META_INFO_ALIAS_VERSION)) + .add(Restrictions.and( + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn), + tenantId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID), + applicationId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID, Long.valueOf(applicationId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)) + ).addOrder(Order.desc(CTL_SCHEMA_VERSION)) .setMaxResults(FIRST); CTLSchema latestSchema = findOneByCriteria(criteria); if (LOG.isTraceEnabled()) { - LOG.trace("[{}] Search result: [{}].", fqn, latestSchema); + LOG.trace("[{},{},{}] Search result: [{}].", fqn, tenantId, applicationId, latestSchema); } else { - LOG.debug("[{}] Search result: [{}].", fqn, latestSchema != null); + LOG.debug("[{},{},{}] Search result: [{}].", fqn, tenantId, applicationId, latestSchema != null); } return latestSchema; } - + @Override - public void removeByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId) { - CTLSchema ctlSchema = findByFqnAndVerAndTenantId(fqn, version, tenantId); - if (ctlSchema != null) { - remove(ctlSchema); + public CTLSchema findLatestByMetaInfoId(String metaInfoId) { + CTLSchema latestSchema = null; + LOG.debug("Searching latest version of ctl schema by meta info id [{}]", + metaInfoId); + if (isNotBlank(metaInfoId)) { + Criteria criteria = getCriteria().createAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS) + .add(Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_ID, Long.valueOf(metaInfoId))) + .addOrder(Order.desc(CTL_SCHEMA_VERSION)) + .setMaxResults(FIRST); + latestSchema = findOneByCriteria(criteria); } - LOG.debug("Removed ctl schema by fqn [{}], version [{}] tenant id [{}]", fqn, version, tenantId); + if (LOG.isTraceEnabled()) { + LOG.trace("[{}] Search result: [{}].", metaInfoId, latestSchema); + } else { + LOG.debug("[{}] Search result: [{}].", metaInfoId, latestSchema != null); + } + return latestSchema; } - + + @Override + public List findAllByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + LOG.debug("Searching available version of ctl schema by fqn [{}], tenantId [{}] and applicationId [{}]", fqn, tenantId, applicationId); + Criteria criteria = getCriteria().createAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS) + .add(Restrictions.and( + Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_FQN, fqn), + tenantId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID, Long.valueOf(tenantId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_TENANT_ID), + applicationId != null + ? Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID, Long.valueOf(applicationId)) + : Restrictions.isNull(CTL_SCHEMA_META_INFO_ALIAS_APPLICATION_ID)) + ).addOrder(Order.asc(CTL_SCHEMA_VERSION)); + List schemas = findListByCriteria(criteria); + if (LOG.isTraceEnabled()) { + LOG.trace("Search result: [{}].", Arrays.toString(schemas.toArray())); + } else { + LOG.debug("Search result: [{}].", schemas.size()); + } + return schemas; + } + + @Override + public List findAllByMetaInfoId(String metaInfoId) { + LOG.debug("Searching available version of ctl schema by meta info id [{}]", metaInfoId); + Criteria criteria = getCriteria().createAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS) + .add(Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_ID, Long.valueOf(metaInfoId)) + ).addOrder(Order.asc(CTL_SCHEMA_VERSION)); + List schemas = findListByCriteria(criteria); + if (LOG.isTraceEnabled()) { + LOG.trace("Search result: [{}].", Arrays.toString(schemas.toArray())); + } else { + LOG.debug("Search result: [{}].", schemas.size()); + } + return schemas; + } + @Override public List findDependentSchemas(String schemaId) { LOG.debug("Searching dependents ctl schemas for schema with id [{}]", schemaId); @@ -165,29 +295,4 @@ public List findDependentSchemas(String schemaId) { return dependentsList; } - @Override - public List findAvailableSchemas(String tenantId) { - LOG.debug("Searching available ctl schemas for tenant with id [{}]", tenantId); - List availableSchemas; - if (tenantId != null) { - availableSchemas = this.findListByCriterionWithAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS, - Restrictions.and( - Restrictions.or( - Restrictions.eq(CTL_SCHEMA_TENANT_ID_ALIAS, Long.valueOf(tenantId)), - Restrictions.isNull(CTL_SCHEMA_TENANT_ID_ALIAS) - ), - buildScopeCriterion(CTLSchemaScopeDto.SYSTEM, CTLSchemaScopeDto.TENANT) - ) - ); - } else { - availableSchemas = this.findSystemSchemas(); - } - if (LOG.isTraceEnabled()) { - LOG.trace("[{}] Search result: [{}].", tenantId, Arrays.toString(availableSchemas.toArray())); - } else { - LOG.debug("[{}] Search result: [{}].", tenantId, availableSchemas.size()); - } - return availableSchemas; - } - } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaMetaInfoDao.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaMetaInfoDao.java index d27ebc8cd9..adbe44a72e 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaMetaInfoDao.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaMetaInfoDao.java @@ -1,23 +1,34 @@ -/* - * Copyright 2015 CyberVision, Inc. +/** + * Copyright 2014-2016 CyberVision, Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.kaaproject.kaa.server.common.dao.impl.sql; +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_FQN; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.ID_PROPERTY; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaMetaInfoDao; import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchemaMetaInfo; import org.slf4j.Logger; @@ -26,13 +37,6 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; -import java.util.List; - -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_FQN; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_SCOPE; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_VERSION; - @Repository public class HibernateCTLSchemaMetaInfoDao extends HibernateAbstractDao implements CTLSchemaMetaInfoDao { @@ -49,8 +53,11 @@ protected Class getEntityClass() { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) public CTLSchemaMetaInfo save(CTLSchemaMetaInfo metaInfo) { - LOG.debug("Try to save or find meta info with fqn [{}] and version [{}]", metaInfo.getFqn(), metaInfo.getVersion()); - CTLSchemaMetaInfo uniqueMetaInfo = findByFqnAndVersion(metaInfo.getFqn(), metaInfo.getVersion()); + String tenantId = metaInfo.getTenant() != null ? metaInfo.getTenant().getStringId() : null; + String applicationId = metaInfo.getApplication() != null ? metaInfo.getApplication().getStringId() : null; + LOG.debug("Try to save or find meta info with fqn [{}], tenantId [{}] and applicationId [{}]", metaInfo.getFqn(), + tenantId, applicationId); + CTLSchemaMetaInfo uniqueMetaInfo = findByFqnTenantIdAndApplicationId(metaInfo.getFqn(), tenantId, applicationId); if (uniqueMetaInfo == null) { uniqueMetaInfo = super.save(metaInfo, true); LOG.debug("Save result: {}", uniqueMetaInfo); @@ -59,53 +66,121 @@ public CTLSchemaMetaInfo save(CTLSchemaMetaInfo metaInfo) { } return uniqueMetaInfo; } - + + private Criterion buildSearchCriterion(String fqn, String tenantId, String applicationId) { + List searchCriterions = new ArrayList<>(); + searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn)); + if (isNotBlank(tenantId)) { + searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(tenantId))); + } else { + searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)); + } + if (isNotBlank(applicationId)) { + searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS, Long.valueOf(applicationId))); + } else { + searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS)); + } + return Restrictions.and(searchCriterions.toArray(new Criterion[searchCriterions.size()])); + } + @Override @Transactional(propagation = Propagation.REQUIRED) - public CTLSchemaMetaInfo incrementCount(CTLSchemaMetaInfo metaInfo) { - CTLSchemaMetaInfo uniqueMetaInfo = findById(metaInfo.getStringId()); - if (uniqueMetaInfo != null) { - uniqueMetaInfo.incrementCount(); + public CTLSchemaMetaInfo findByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + LOG.debug("Searching ctl metadata by fqn [{}], tenantId [{}] and applicationId [{}]", fqn, tenantId, applicationId); + CTLSchemaMetaInfo ctlSchemaMetaInfo = findOneByCriterion(buildSearchCriterion(fqn, tenantId, applicationId)); + if (LOG.isTraceEnabled()) { + LOG.trace("[{},{},{}] Search result: {}.", fqn, tenantId, applicationId, ctlSchemaMetaInfo); + } else { + LOG.debug("[{},{},{}] Search result: {}.", fqn, tenantId, applicationId, ctlSchemaMetaInfo != null); } - return super.save(uniqueMetaInfo, true); + return ctlSchemaMetaInfo; } - + @Override - @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) - public CTLSchemaMetaInfo findByFqnAndVersion(String fqn, Integer version) { - LOG.debug("Searching ctl metadata by fqn [{}] and version [{}]", fqn, version); - CTLSchemaMetaInfo ctlSchema = findOneByCriterion(Restrictions.and( - Restrictions.eq(CTL_SCHEMA_META_INFO_VERSION, version), - Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn))); + public List findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, + String applicationId) { + LOG.debug("Searching siblings of ctl by fqn [{}], tenantId [{}] and applicationId [{}]", fqn, tenantId, applicationId); + List ctlSchemaMetaInfos; + if (isNotBlank(fqn) && isNotBlank(tenantId) && isNotBlank(applicationId)) { + ctlSchemaMetaInfos = findListByCriterion( + Restrictions.and( + Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn), + Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(tenantId)), + Restrictions.isNotNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS), + Restrictions.ne(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS, Long.valueOf(applicationId)) + )); + } else { + ctlSchemaMetaInfos = Collections.emptyList(); + } if (LOG.isTraceEnabled()) { - LOG.trace("[{},{}] Search result: {}.", fqn, version, ctlSchema); + LOG.trace("[{}][{}][{}] Search result: [{}].", fqn, tenantId, applicationId, Arrays.toString(ctlSchemaMetaInfos.toArray())); + } else { + LOG.debug("[{}][{}][{}] Search result: [{}].", fqn, tenantId, applicationId, ctlSchemaMetaInfos.size()); + } + return ctlSchemaMetaInfos; + } + + private Criterion buildExludingSearchCriterion(String fqn, String excludingTenantId, String excludingApplicationId) { + List searchCriterions = new ArrayList<>(); + if (isNotBlank(excludingTenantId)) { + searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)); + if (isNotBlank(excludingApplicationId)) { + searchCriterions.add(Restrictions.and( + Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)), + Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS))); + } else { + searchCriterions.add(Restrictions.and( + Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(excludingTenantId)), + Restrictions.isNotNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS))); + } } else { - LOG.debug("[{},{}] Search result: {}.", fqn, version, ctlSchema != null); + searchCriterions.add(Restrictions.isNotNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)); } - return ctlSchema; + return Restrictions.and(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn), + Restrictions.or(searchCriterions.toArray(new Criterion[searchCriterions.size()]))); } @Override - public List findSystemSchemaMetaInfo() { - LOG.debug("Searching system ctl metadata"); - List metaInfoList = findListByCriterion(Restrictions.eq(CTL_SCHEMA_META_INFO_SCOPE, CTLSchemaScopeDto.SYSTEM)); + public List findExistingFqns(String fqn, String excludingTenantId, String excludingApplicationId) { + LOG.debug("Searching ctl metadata by fqn [{}], excludingTenantId [{}] and excludingApplicationId [{}]", fqn, excludingTenantId, excludingApplicationId); + List ctlSchemasMetaInfos = findListByCriterion(buildExludingSearchCriterion(fqn, excludingTenantId, excludingApplicationId)); if (LOG.isTraceEnabled()) { - LOG.trace("Search result: {}.", Arrays.toString(metaInfoList.toArray())); + LOG.trace("[{},{},{}] Search result: {}.", fqn, excludingTenantId, excludingApplicationId, Arrays.toString(ctlSchemasMetaInfos.toArray())); } else { - LOG.debug("Search result: {}.", metaInfoList.size()); + LOG.debug("[{},{},{}] Search result: {}.", fqn, excludingTenantId, excludingApplicationId, ctlSchemasMetaInfos.size()); } - return metaInfoList; + return ctlSchemasMetaInfos; } - + + @Override + public List findOthersByFqnAndTenantId(String fqn, String tenantId, String excludingId) { + LOG.debug("Searching other ctl schema meta infos by fqn [{}], tenant id [{}] and excluding id [{}]", + fqn, tenantId, excludingId); + List availableSchemas = findListByCriterion( + Restrictions.and(Restrictions.ne(ID_PROPERTY, Long.valueOf(excludingId)), + Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn), + Restrictions.or( + Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS, Long.valueOf(tenantId)), + Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS)))); + if (LOG.isTraceEnabled()) { + LOG.trace("[{}][{}][{}] Search result: [{}].", fqn, tenantId, excludingId, Arrays.toString(availableSchemas.toArray())); + } else { + LOG.debug("[{}][{}][{}] Search result: [{}].", fqn, tenantId, excludingId, availableSchemas.size()); + } + return availableSchemas; + } + @Override public CTLSchemaMetaInfo updateScope(CTLSchemaMetaInfo ctlSchemaMetaInfo) { LOG.debug("Updating ctl meta info scope {}", ctlSchemaMetaInfo); CTLSchemaMetaInfo metaInfo = findById(ctlSchemaMetaInfo.getStringId()); if (metaInfo != null) { - metaInfo.setScope(ctlSchemaMetaInfo.getScope()); + metaInfo.setTenant(ctlSchemaMetaInfo.getTenant()); + metaInfo.setApplication(ctlSchemaMetaInfo.getApplication()); metaInfo = super.save(metaInfo); } LOG.debug("Update result: {}", metaInfo != null); return metaInfo; } -} + +} \ No newline at end of file diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchema.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchema.java index ca3f0e6e29..ddc79c5e98 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchema.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchema.java @@ -16,13 +16,10 @@ package org.kaaproject.kaa.server.common.dao.model.sql; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_APPLICATION_FK; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_APPLICATION_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_BODY; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEFAULT_RECORD; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_CREATED_TIME; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_CREATED_USERNAME; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DESCRIPTION; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_DEFAULT_RECORD; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_JOIN_TABLE_CHILD_FK; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_JOIN_TABLE_CHILD_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_JOIN_TABLE_NAME; @@ -30,11 +27,9 @@ import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_JOIN_TABLE_PARENT_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_FK; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_ID; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_NAME; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_TABLE_NAME; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_TENANT_FK; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_TENANT_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_UNIQUE_CONSTRAINT; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_VERSION; import static org.kaaproject.kaa.server.common.dao.model.sql.ModelUtils.getLongId; import java.io.Serializable; @@ -58,7 +53,7 @@ @Entity @Table(name = CTL_SCHEMA_TABLE_NAME, uniqueConstraints = -@UniqueConstraint(columnNames = {CTL_SCHEMA_META_INFO_ID, CTL_SCHEMA_TENANT_ID}, name = CTL_SCHEMA_UNIQUE_CONSTRAINT)) +@UniqueConstraint(columnNames = {CTL_SCHEMA_META_INFO_ID, CTL_SCHEMA_VERSION}, name = CTL_SCHEMA_UNIQUE_CONSTRAINT)) public class CTLSchema extends GenericModel implements Serializable { private static final long serialVersionUID = -1179381742235545494L; @@ -66,22 +61,14 @@ public class CTLSchema extends GenericModel implements Serializabl @ManyToOne(optional = true, fetch = FetchType.EAGER) @JoinColumn(nullable = false, name = CTL_SCHEMA_META_INFO_ID, foreignKey = @ForeignKey(name = CTL_SCHEMA_META_INFO_FK)) private CTLSchemaMetaInfo metaInfo; - @ManyToOne(optional = true, fetch = FetchType.LAZY) - @JoinColumn(nullable = true, name = CTL_SCHEMA_TENANT_ID, foreignKey = @ForeignKey(name = CTL_SCHEMA_TENANT_FK)) - private Tenant tenant; - @ManyToOne(optional = true, fetch = FetchType.LAZY) - @JoinColumn(nullable = true, name = CTL_SCHEMA_APPLICATION_ID, foreignKey = @ForeignKey(name = CTL_SCHEMA_APPLICATION_FK)) - private Application application; + @Column(name = CTL_SCHEMA_VERSION) + private Integer version; @Lob @Column(name = CTL_SCHEMA_BODY) private String body; @Lob @Column(name = CTL_SCHEMA_DEFAULT_RECORD) private String defaultRecord; - @Column(name = CTL_SCHEMA_NAME) - private String name; - @Column(length = 1000, name = CTL_SCHEMA_DESCRIPTION) - private String description; @Column(name = CTL_SCHEMA_CREATED_USERNAME) private String createdUsername; @Column(name = CTL_SCHEMA_CREATED_TIME) @@ -103,31 +90,23 @@ public CTLSchema(Long id) { public CTLSchema(CTLSchemaDto dto) { this.id = getLongId(dto.getId()); this.metaInfo = new CTLSchemaMetaInfo(dto.getMetaInfo()); - - Long tenantId = getLongId(dto.getTenantId()); - this.tenant = tenantId != null ? new Tenant(tenantId) : null; - - Long appId = getLongId(dto.getApplicationId()); - this.application = appId != null ? new Application(appId) : null; - this.body = dto.getBody(); - this.defaultRecord = dto.getDefaultRecord(); - this.name = dto.getName(); - this.description = dto.getDescription(); + this.version = dto.getVersion(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); - + update(dto); + } + + public void update(CTLSchemaDto dto) { + this.body = dto.getBody(); + this.defaultRecord = dto.getDefaultRecord(); Set dependencies = dto.getDependencySet(); if (dependencies != null && !dependencies.isEmpty()) { for (CTLSchemaDto dependency : dependencies) { dependencySet.add(new CTLSchema(dependency)); } } - - this.name = dto.getName(); - this.createdUsername = dto.getCreatedUsername(); - this.description = dto.getDescription(); } - + public CTLSchemaMetaInfo getMetaInfo() { return metaInfo; } @@ -136,20 +115,12 @@ public void setMetaInfo(CTLSchemaMetaInfo metaInfo) { this.metaInfo = metaInfo; } - public Tenant getTenant() { - return tenant; - } - - public void setTenant(Tenant tenant) { - this.tenant = tenant; - } - - public Application getApplication() { - return application; + public Integer getVersion() { + return version; } - public void setApplication(Application application) { - this.application = application; + public void setVersion(Integer version) { + this.version = version; } public String getBody() { @@ -176,22 +147,6 @@ public void setDependencySet(Set dependencySet) { this.dependencySet = dependencySet; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - public String getCreatedUsername() { return createdUsername; } @@ -222,69 +177,93 @@ protected GenericModel newInstance(Long id) { public CTLSchemaDto toDto() { CTLSchemaDto ctlSchemaDto = createDto(); ctlSchemaDto.setId(getStringId()); - ctlSchemaDto.setApplicationId(application != null ? application.getStringId() : null); - ctlSchemaDto.setTenantId(tenant != null ? tenant.getStringId() : null); + ctlSchemaDto.setMetaInfo(metaInfo.toDto()); + ctlSchemaDto.setVersion(version); ctlSchemaDto.setCreatedTime(createdTime); ctlSchemaDto.setCreatedUsername(createdUsername); - ctlSchemaDto.setName(name); - ctlSchemaDto.setDescription(description); - ctlSchemaDto.setMetaInfo(metaInfo.toDto()); ctlSchemaDto.setBody(body); ctlSchemaDto.setDefaultRecord(defaultRecord); ctlSchemaDto.setDependencySet(DaoUtil.convertDtoSet(dependencySet)); - ctlSchemaDto.setName(name); - ctlSchemaDto.setCreatedUsername(createdUsername); - ctlSchemaDto.setDescription(description); return ctlSchemaDto; } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CTLSchema schema = (CTLSchema) o; - - if (createdTime != schema.createdTime) return false; - if (metaInfo != null ? !metaInfo.equals(schema.metaInfo) : schema.metaInfo != null) return false; - if (tenant != null ? !tenant.equals(schema.tenant) : schema.tenant != null) return false; - if (application != null ? !application.equals(schema.application) : schema.application != null) return false; - if (body != null ? !body.equals(schema.body) : schema.body != null) return false; - if (name != null ? !name.equals(schema.name) : schema.name != null) return false; - if (description != null ? !description.equals(schema.description) : schema.description != null) return false; - if (createdUsername != null ? !createdUsername.equals(schema.createdUsername) : schema.createdUsername != null) - return false; - return dependencySet != null ? dependencySet.equals(schema.dependencySet) : schema.dependencySet == null; - + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((body == null) ? 0 : body.hashCode()); + result = prime * result + (int) (createdTime ^ (createdTime >>> 32)); + result = prime * result + ((createdUsername == null) ? 0 : createdUsername.hashCode()); + result = prime * result + ((defaultRecord == null) ? 0 : defaultRecord.hashCode()); + result = prime * result + ((dependencySet == null) ? 0 : dependencySet.hashCode()); + result = prime * result + ((metaInfo == null) ? 0 : metaInfo.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; } @Override - public int hashCode() { - int result = metaInfo != null ? metaInfo.hashCode() : 0; - result = 31 * result + (tenant != null ? tenant.hashCode() : 0); - result = 31 * result + (application != null ? application.hashCode() : 0); - result = 31 * result + (body != null ? body.hashCode() : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (description != null ? description.hashCode() : 0); - result = 31 * result + (createdUsername != null ? createdUsername.hashCode() : 0); - result = 31 * result + (int) (createdTime ^ (createdTime >>> 32)); - result = 31 * result + (dependencySet != null ? dependencySet.hashCode() : 0); - return result; + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CTLSchema other = (CTLSchema) obj; + if (body == null) { + if (other.body != null) + return false; + } else if (!body.equals(other.body)) + return false; + if (createdTime != other.createdTime) + return false; + if (createdUsername == null) { + if (other.createdUsername != null) + return false; + } else if (!createdUsername.equals(other.createdUsername)) + return false; + if (defaultRecord == null) { + if (other.defaultRecord != null) + return false; + } else if (!defaultRecord.equals(other.defaultRecord)) + return false; + if (dependencySet == null) { + if (other.dependencySet != null) + return false; + } else if (!dependencySet.equals(other.dependencySet)) + return false; + if (metaInfo == null) { + if (other.metaInfo != null) + return false; + } else if (!metaInfo.equals(other.metaInfo)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; } @Override public String toString() { - return "CTLSchema{" + - "id=" + id + - ", metaInfo=" + metaInfo + - ", tenant=" + tenant + - ", application=" + application + - ", body='" + body + '\'' + - ", name='" + name + '\'' + - ", description='" + description + '\'' + - ", createdUsername='" + createdUsername + '\'' + - ", createdTime=" + createdTime + - ", dependencySet=" + dependencySet + - '}'; + StringBuilder builder = new StringBuilder(); + builder.append("CTLSchema [metaInfo="); + builder.append(metaInfo); + builder.append(", version="); + builder.append(version); + builder.append(", body="); + builder.append(body); + builder.append(", defaultRecord="); + builder.append(defaultRecord); + builder.append(", createdUsername="); + builder.append(createdUsername); + builder.append(", createdTime="); + builder.append(createdTime); + builder.append(", dependencySet="); + builder.append(dependencySet); + builder.append("]"); + return builder.toString(); } + } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfo.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfo.java index 8fdca21ce2..b8da9c42c6 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfo.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfo.java @@ -1,33 +1,38 @@ -/* - * Copyright 2015 CyberVision, Inc. +/** + * Copyright 2014-2016 CyberVision, Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.kaaproject.kaa.server.common.dao.model.sql; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_APPLICATION_FK; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_APPLICATION_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_FQN; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_SCOPE; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_TABLE_NAME; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_TENANT_FK; +import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_TENANT_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_UNIQUE_CONSTRAINT; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.CTL_SCHEMA_META_INFO_VERSION; +import static org.kaaproject.kaa.server.common.dao.model.sql.ModelUtils.getLongId; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.UniqueConstraint; @@ -36,40 +41,60 @@ @Entity @Table(name = CTL_SCHEMA_META_INFO_TABLE_NAME, uniqueConstraints = -@UniqueConstraint(columnNames = {CTL_SCHEMA_META_INFO_VERSION, CTL_SCHEMA_META_INFO_FQN}, name = CTL_SCHEMA_META_INFO_UNIQUE_CONSTRAINT)) +@UniqueConstraint(columnNames = {CTL_SCHEMA_META_INFO_FQN, CTL_SCHEMA_META_INFO_TENANT_ID, CTL_SCHEMA_META_INFO_APPLICATION_ID}, name = CTL_SCHEMA_META_INFO_UNIQUE_CONSTRAINT)) public class CTLSchemaMetaInfo extends GenericModel implements Serializable { private static final long serialVersionUID = 3185049875063895954L; @Column(name = CTL_SCHEMA_META_INFO_FQN) private String fqn; - @Column(name = CTL_SCHEMA_META_INFO_VERSION) - private Integer version; - @Column(name = CTL_SCHEMA_META_INFO_SCOPE, nullable = false) - @Enumerated(EnumType.STRING) - private CTLSchemaScopeDto scope; - @Column(name = "count") - private Long count = 0L; + @ManyToOne(optional = true, fetch = FetchType.LAZY) + @JoinColumn(nullable = true, name = CTL_SCHEMA_META_INFO_TENANT_ID, foreignKey = @ForeignKey(name = CTL_SCHEMA_META_INFO_TENANT_FK)) + private Tenant tenant; + @ManyToOne(optional = true, fetch = FetchType.LAZY) + @JoinColumn(nullable = true, name = CTL_SCHEMA_META_INFO_APPLICATION_ID, foreignKey = @ForeignKey(name = CTL_SCHEMA_META_INFO_APPLICATION_FK)) + private Application application; public CTLSchemaMetaInfo() { } public CTLSchemaMetaInfo(CTLSchemaMetaInfoDto dto) { this.id = ModelUtils.getLongId(dto.getId()); - this.fqn = dto.getFqn(); - this.version = dto.getVersion(); - this.scope = dto.getScope(); - this.count = dto.getCount(); + this.fqn = dto.getFqn(); + Long tenantId = getLongId(dto.getTenantId()); + this.tenant = tenantId != null ? new Tenant(tenantId) : null; + Long appId = getLongId(dto.getApplicationId()); + this.application = appId != null ? new Application(appId) : null; + } + + public CTLSchemaMetaInfo(String fqn) { + this.fqn = fqn; + } + + public CTLSchemaMetaInfo(String fqn, String tenantId, String applicationId) { + this.fqn = fqn; + Long tenId = getLongId(tenantId); + this.tenant = tenId != null ? new Tenant(tenId) : null; + Long appId = getLongId(applicationId); + this.application = appId != null ? new Application(appId) : null; } - public CTLSchemaMetaInfo(String fqn, Integer version) { + public CTLSchemaMetaInfo(String fqn, Tenant tenant, Application application) { this.fqn = fqn; - this.version = version; + this.tenant = tenant; + this.application = application; } public CTLSchemaMetaInfo(Long id) { this.id = id; } + + public void updateScope(String tenantId, String applicationId) { + Long tenId = getLongId(tenantId); + this.tenant = tenId != null ? new Tenant(tenId) : null; + Long appId = getLongId(applicationId); + this.application = appId != null ? new Application(appId) : null; + } public String getFqn() { return fqn; @@ -79,20 +104,20 @@ public void setFqn(String fqn) { this.fqn = fqn; } - public Integer getVersion() { - return version; + public Tenant getTenant() { + return tenant; } - public void setVersion(Integer version) { - this.version = version; + public void setTenant(Tenant tenant) { + this.tenant = tenant; } - public CTLSchemaScopeDto getScope() { - return scope; + public Application getApplication() { + return application; } - public void setScope(CTLSchemaScopeDto scope) { - this.scope = scope; + public void setApplication(Application application) { + this.application = application; } @Override @@ -110,54 +135,60 @@ public CTLSchemaMetaInfoDto toDto() { CTLSchemaMetaInfoDto ctlSchemaMetaInfoDto = createDto(); ctlSchemaMetaInfoDto.setId(getStringId()); ctlSchemaMetaInfoDto.setFqn(fqn); - ctlSchemaMetaInfoDto.setVersion(version); - ctlSchemaMetaInfoDto.setScope(scope); - ctlSchemaMetaInfoDto.setCount(count); + ctlSchemaMetaInfoDto.setApplicationId(application != null ? application.getStringId() : null); + ctlSchemaMetaInfoDto.setTenantId(tenant != null ? tenant.getStringId() : null); return ctlSchemaMetaInfoDto; } - public Long getCount() { - return count; - } - - public Long incrementCount() { - return count++; - } - - public void setCount(Long count) { - this.count = count; - } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CTLSchemaMetaInfo metaInfo = (CTLSchemaMetaInfo) o; - - if (fqn != null ? !fqn.equals(metaInfo.fqn) : metaInfo.fqn != null) return false; - if (version != null ? !version.equals(metaInfo.version) : metaInfo.version != null) return false; - if (scope != metaInfo.scope) return false; - return count != null ? count.equals(metaInfo.count) : metaInfo.count == null; - + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((application == null) ? 0 : application.hashCode()); + result = prime * result + ((fqn == null) ? 0 : fqn.hashCode()); + result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); + return result; } @Override - public int hashCode() { - int result = fqn != null ? fqn.hashCode() : 0; - result = 31 * result + (version != null ? version.hashCode() : 0); - result = 31 * result + (scope != null ? scope.hashCode() : 0); - result = 31 * result + (count != null ? count.hashCode() : 0); - return result; + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CTLSchemaMetaInfo other = (CTLSchemaMetaInfo) obj; + if (application == null) { + if (other.application != null) + return false; + } else if (!application.equals(other.application)) + return false; + if (fqn == null) { + if (other.fqn != null) + return false; + } else if (!fqn.equals(other.fqn)) + return false; + if (tenant == null) { + if (other.tenant != null) + return false; + } else if (!tenant.equals(other.tenant)) + return false; + return true; } @Override public String toString() { - return "CTLSchemaMetaInfo{" + - "fqn='" + fqn + '\'' + - ", version=" + version + - ", scope=" + scope + - ", count=" + count + - '}'; - } -} + StringBuilder builder = new StringBuilder(); + builder.append("CTLSchemaMetaInfo [fqn="); + builder.append(fqn); + builder.append(", tenant="); + builder.append(tenant); + builder.append(", application="); + builder.append(application); + builder.append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImpl.java index ead27da54a..64d5cf990b 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImpl.java @@ -18,7 +18,6 @@ import static org.apache.commons.lang.StringUtils.isBlank; import static org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto.SYSTEM; -import static org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto.TENANT; import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.convertDtoList; import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getDto; import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getStringFromFile; @@ -31,8 +30,10 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -46,7 +47,6 @@ import org.hibernate.LockOptions; import org.kaaproject.kaa.common.avro.GenericAvroConverter; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.file.FileData; @@ -81,7 +81,6 @@ public class CTLServiceImpl implements CTLService { private static final String FQN = "fqn"; private static final Logger LOG = LoggerFactory.getLogger(CTLServiceImpl.class); private static final String DEPENDENCIES = "dependencies"; - private static final String GENERATED = "Generated"; private static final String DEFAULT_SYSTEM_EMPTY_SCHEMA_FILE = "/default_system_empty_schema.avsc"; private final LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_WRITE); @@ -108,28 +107,27 @@ public class CTLServiceImpl implements CTLService { @Autowired private CTLSchemaDao ctlSchemaDao; + @Autowired - private CTLSchemaMetaInfoDao schemaMetaInfoDao; + private CTLSchemaMetaInfoDao ctlSchemaMetaInfoDao; @Override public CTLSchemaDto getOrCreateEmptySystemSchema(String createdUsername) { - CTLSchemaDto ctlSchema = findCTLSchemaByFqnAndVerAndTenantId(DEFAULT_SYSTEM_EMPTY_SCHEMA_FQN, DEFAULT_SYSTEM_EMPTY_SCHEMA_VERSION, - null); + CTLSchemaDto ctlSchema = findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(DEFAULT_SYSTEM_EMPTY_SCHEMA_FQN, DEFAULT_SYSTEM_EMPTY_SCHEMA_VERSION, + null, null); if (ctlSchema == null) { - CTLSchemaInfoDto schema = new CTLSchemaInfoDto(); - schema.setName(GENERATED); - schema.setCreatedUsername(createdUsername); - schema.setScope(CTLSchemaScopeDto.SYSTEM); - schema.setFqn(DEFAULT_SYSTEM_EMPTY_SCHEMA_FQN); - schema.setVersion(DEFAULT_SYSTEM_EMPTY_SCHEMA_VERSION); - schema.setDependencies(new HashSet()); + ctlSchema = new CTLSchemaDto(); + CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(DEFAULT_SYSTEM_EMPTY_SCHEMA_FQN); + ctlSchema.setMetaInfo(metaInfo); + ctlSchema.setVersion(DEFAULT_SYSTEM_EMPTY_SCHEMA_VERSION); + ctlSchema.setCreatedUsername(createdUsername); + ctlSchema.setDependencySet(new HashSet()); String body = getStringFromFile(DEFAULT_SYSTEM_EMPTY_SCHEMA_FILE, CTLServiceImpl.class); if (!body.isEmpty()) { - schema.setBody(body); + ctlSchema.setBody(body); } else { throw new RuntimeException("Can't read default system schema."); // NOSONAR } - ctlSchema = new CTLSchemaDto(schema, new HashSet()); ctlSchema = saveCTLSchema(ctlSchema); } return ctlSchema; @@ -145,51 +143,23 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto unSavedSchema) { } if (isBlank(unSavedSchema.getId())) { CTLSchemaMetaInfoDto metaInfo = unSavedSchema.getMetaInfo(); - CTLSchemaScopeDto currentScope = metaInfo.getScope(); CTLSchemaDto dto; synchronized (this) { - boolean existing = false; - CTLSchemaMetaInfo uniqueMetaInfo; - try { - uniqueMetaInfo = schemaMetaInfoDao.save(new CTLSchemaMetaInfo(metaInfo)); - } catch (Exception e) { - existing = true; - uniqueMetaInfo = schemaMetaInfoDao.findByFqnAndVersion(metaInfo.getFqn(), metaInfo.getVersion()); - } - if (uniqueMetaInfo == null) { - throw new DatabaseProcessingException("Can't save or find ctl meta information. Please check database state."); - } - schemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(uniqueMetaInfo); - - switch (uniqueMetaInfo.getScope()) { - case SYSTEM: - if (existing) { - throw new DatabaseProcessingException("Disable to store system ctl schema with same fqn and version."); - } - case TENANT: - if (currentScope == SYSTEM && existing) { - throw new DatabaseProcessingException( - "Disable to store system ctl schema. Tenant's scope schema already exists with the same fqn and version."); - } - break; - case APPLICATION: - break; - default: - break; - + List existingFqns = ctlSchemaMetaInfoDao.findExistingFqns(metaInfo.getFqn(), metaInfo.getTenantId(), metaInfo.getApplicationId()); + if (existingFqns != null && !existingFqns.isEmpty()) { + throw new DatabaseProcessingException("Can't save common type due to an FQN conflict."); } + metaInfo.setId(null); + CTLSchemaMetaInfo uniqueMetaInfo = ctlSchemaMetaInfoDao.save(new CTLSchemaMetaInfo(metaInfo)); + ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(uniqueMetaInfo); CTLSchema ctlSchema = new CTLSchema(unSavedSchema); ctlSchema.setMetaInfo(uniqueMetaInfo); ctlSchema.setCreatedTime(System.currentTimeMillis()); - if (isBlank(unSavedSchema.getDescription())) { - ctlSchema.setDescription(GENERATED); - } - schemaMetaInfoDao.refresh(uniqueMetaInfo); - schemaMetaInfoDao.incrementCount(uniqueMetaInfo); + ctlSchemaMetaInfoDao.refresh(uniqueMetaInfo); try { dto = getDto(ctlSchemaDao.save(ctlSchema, true)); } catch (DataIntegrityViolationException ex) { - throw new DatabaseProcessingException("Can't save cql schema with same fqn, version and tenant id."); + throw new DatabaseProcessingException("Can't save common type: such FQN and version already exist."); } catch (Exception ex) { throw new DatabaseProcessingException(ex); } @@ -229,50 +199,117 @@ private CTLSchemaDto generateDefaultRecord(CTLSchemaDto unSavedSchema) { @Override public CTLSchemaDto updateCTLSchema(CTLSchemaDto ctlSchema) { validateCTLSchemaObject(ctlSchema); - LOG.debug("Set new scope {} for ctl schema with id [{}]", ctlSchema.getId(), ctlSchema.getMetaInfo().getScope()); - CTLSchemaMetaInfoDto newMetaInfo = ctlSchema.getMetaInfo(); - CTLSchemaScopeDto newScope = newMetaInfo.getScope(); - if (!SYSTEM.equals(newScope)) { - CTLSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); - if (schema != null) { + LOG.debug("Update ctl schema with id [{}]", ctlSchema.getId()); + CTLSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); + if (schema != null) { + synchronized (this) { + if (ctlSchema.getVersion() != schema.getVersion()) { + throw new DatabaseProcessingException("Can't change version of existing common type version."); + } CTLSchemaMetaInfo metaInfo = schema.getMetaInfo(); - if (metaInfo.getScope().getLevel() <= newScope.getLevel()) { - CTLSchemaMetaInfo updated = schemaMetaInfoDao.updateScope(new CTLSchemaMetaInfo(newMetaInfo)); - if (updated != null) { - schema.setMetaInfo(updated); - } else { - throw new DatabaseProcessingException("Can't update scope for ctl meta info."); - } - } else if (metaInfo.getScope().getLevel() > newScope.getLevel()) { - throw new DatabaseProcessingException("Forbidden to update scope to lower level."); + if (!ctlSchema.getMetaInfo().equals(metaInfo.toDto())) { + throw new DatabaseProcessingException("Can't update scope of existing common type version within update procedure."); } - updateEditableFields(ctlSchema, schema); - return DaoUtil.getDto(ctlSchemaDao.save(schema)); - } else { - throw new DatabaseProcessingException("Can't find ctl schema by id."); + ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); + schema.update(ctlSchema); + return DaoUtil.getDto(ctlSchemaDao.save(schema, true)); } } else { - throw new DatabaseProcessingException("Forbidden to update existing scope to system."); + throw new DatabaseProcessingException("Can't find common type version by id."); + } + } + + @Override + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) { + validateObject(ctlSchemaMetaInfo, "Incorrect ctl schema meta info object"); + LOG.debug("Update ctl schema meta info scope with id [{}]", ctlSchemaMetaInfo.getId()); + CTLSchemaMetaInfo schemaMetaInfo = ctlSchemaMetaInfoDao.findById(ctlSchemaMetaInfo.getId()); + if (schemaMetaInfo != null) { + synchronized (this) { + ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(schemaMetaInfo); + if (checkScopeUpdate(ctlSchemaMetaInfo, schemaMetaInfo.toDto())) { + List others = ctlSchemaMetaInfoDao.findOthersByFqnAndTenantId(ctlSchemaMetaInfo.getFqn(), ctlSchemaMetaInfo.getTenantId(), ctlSchemaMetaInfo.getId()); + if (others != null && !others.isEmpty()) { + throw new DatabaseProcessingException("Can't update scope of the common type due to an FQN conflict."); + } + schemaMetaInfo = ctlSchemaMetaInfoDao.updateScope(new CTLSchemaMetaInfo(ctlSchemaMetaInfo)); + } + return DaoUtil.getDto(schemaMetaInfo); + } + } else { + throw new DatabaseProcessingException("Can't find common type by id."); } } + + @Override + public List findSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + if (isBlank(fqn)) { + throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); + } + LOG.debug("Find sibling ctl schemas by fqn {}, tenant id {} and application id {}", fqn, tenantId, applicationId); + return convertDtoList(ctlSchemaMetaInfoDao.findSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId)); + } + + private boolean checkScopeUpdate(CTLSchemaMetaInfoDto newSchemaMetaInfo, CTLSchemaMetaInfoDto prevSchemaMetaInfo) { + if (!newSchemaMetaInfo.equals(prevSchemaMetaInfo)) { + if (isBlank(newSchemaMetaInfo.getFqn())) { + throw new DatabaseProcessingException("FQN can't be empty."); + } + if (!newSchemaMetaInfo.getFqn().equals(prevSchemaMetaInfo.getFqn())) { + throw new DatabaseProcessingException("Can't change FQN of the existing common type."); + } + CTLSchemaScopeDto newScope = newSchemaMetaInfo.getScope(); + CTLSchemaScopeDto prevScope = prevSchemaMetaInfo.getScope(); + if (newScope != prevScope) { + if (SYSTEM.equals(newScope)) { + throw new DatabaseProcessingException("Can't update scope to system."); + } + if (newScope.getLevel() > prevScope.getLevel()) { + throw new DatabaseProcessingException("Can't update scope to lower."); + } + } + if (!isBlank(newSchemaMetaInfo.getTenantId()) && + !newSchemaMetaInfo.getTenantId().equals(prevSchemaMetaInfo.getTenantId())) { + throw new DatabaseProcessingException("Can't change tenant reference for the existing common type."); + } + if (!isBlank(newSchemaMetaInfo.getApplicationId()) && + !newSchemaMetaInfo.getApplicationId().equals(prevSchemaMetaInfo.getApplicationId())) { + throw new DatabaseProcessingException("Can't change application reference for the existing common type."); + } + return true; + } + return false; + } @Override - public void removeCTLSchemaByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId) { + public void removeCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } - LOG.debug("Remove ctl schema by fqn {} version {} and tenant id {}", fqn, version, tenantId); - CTLSchema ctlSchema = ctlSchemaDao.findByFqnAndVerAndTenantId(fqn, version, tenantId); + LOG.debug("Remove ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); + CTLSchema ctlSchema = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); if (ctlSchema != null) { List dependsList = ctlSchemaDao.findDependentSchemas(ctlSchema.getStringId()); if (dependsList.isEmpty()) { - ctlSchemaDao.removeById(ctlSchema.getStringId()); + synchronized (this) { + CTLSchemaMetaInfo metaInfo = ctlSchema.getMetaInfo(); + ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); + try { + ctlSchemaDao.removeById(ctlSchema.getStringId()); + List schemas = ctlSchemaDao.findAllByMetaInfoId(metaInfo.getStringId()); + if (schemas == null || schemas.isEmpty()) { + ctlSchemaMetaInfoDao.removeById(metaInfo.getStringId()); + } + } catch (DataIntegrityViolationException ex) { + throw new DatabaseProcessingException("Common type version can't be deleted because it is referenced by system modules."); + } + } } else { - throw new DatabaseProcessingException("Forbidden to delete ctl schema with relations."); + throw new DatabaseProcessingException("Common type version can't be deleted because it is referenced by other types."); } } } - + @Override public CTLSchemaDto findCTLSchemaById(String schemaId) { validateSqlId(schemaId, "Incorrect schema id for ctl request " + schemaId); @@ -281,21 +318,33 @@ public CTLSchemaDto findCTLSchemaById(String schemaId) { } @Override - public void removeCTLSchemaById(String schemaId) { - validateSqlId(schemaId, "Incorrect schema id for ctl request " + schemaId); - LOG.debug("Remove ctl schema by id [{}]", schemaId); - ctlSchemaDao.removeById(schemaId); + public CTLSchemaDto findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { + if (isBlank(fqn) || version == null) { + throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); + } + LOG.debug("Find ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); + return DaoUtil.getDto(ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId)); + } + + @Override + public CTLSchemaDto findByMetaInfoIdAndVer(String metaInfoId, Integer version) { + if (isBlank(metaInfoId) || version == null) { + throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); + } + LOG.debug("Find ctl schema by meta info id {} and version {}", metaInfoId, version); + return DaoUtil.getDto(ctlSchemaDao.findByMetaInfoIdAndVer(metaInfoId, version)); } @Override - public CTLSchemaDto findCTLSchemaByFqnAndVerAndTenantId(String fqn, Integer version, String tenantId) { + public CTLSchemaDto findAnyCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, + String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } - LOG.debug("Find ctl schema by fqn {} version {} and tenant id {}", fqn, version, tenantId); - return DaoUtil.getDto(ctlSchemaDao.findByFqnAndVerAndTenantId(fqn, version, tenantId)); + LOG.debug("Find any ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); + return DaoUtil.getDto(ctlSchemaDao.findAnyByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId)); } - + @Override public List findSystemCTLSchemas() { LOG.debug("Find system ctl schemas"); @@ -304,41 +353,47 @@ public List findSystemCTLSchemas() { @Override public List findSystemCTLSchemasMetaInfo() { - LOG.debug("Find meta info for system ctl schemas"); - return convertDtoList(schemaMetaInfoDao.findSystemSchemaMetaInfo()); + LOG.debug("Find system ctl schemas"); + return getMetaInfoFromCTLSchema(ctlSchemaDao.findSystemSchemas()); } @Override - public CTLSchemaDto findLatestCTLSchemaByFqn(String fqn) { - validateString(fqn, "Incorrect fqn for ctl schema request."); - LOG.debug("Find latest ctl schema by fqn {}", fqn); - return DaoUtil.getDto(ctlSchemaDao.findLatestByFqn(fqn)); + public List findAvailableCTLSchemasMetaInfoForTenant(String tenantId) { + LOG.debug("Find system and tenant scopes ctl schemas by tenant id {}", tenantId); + return getMetaInfoFromCTLSchema(ctlSchemaDao.findAvailableSchemasForTenant(tenantId)); } - + @Override - public List findCTLSchemas() { - LOG.debug("Find all ctl schemas"); - return convertDtoList(ctlSchemaDao.find()); + public List findAvailableCTLSchemasMetaInfoForApplication(String tenantId, String applicationId) { + LOG.debug("Find system, tenant and application scopes ctl schemas by application id {}", applicationId); + return getMetaInfoFromCTLSchema(ctlSchemaDao.findAvailableSchemasForApplication(tenantId, applicationId)); } @Override - public List findCTLSchemasMetaInfoByApplicationId(String appId) { - validateSqlId(appId, "Incorrect application id for ctl schema request."); - LOG.debug("Find meta info for ctl schemas by application id {}", appId); - return getMetaInfoFromCTLSchema(ctlSchemaDao.findByApplicationId(appId)); + public CTLSchemaDto findLatestCTLSchemaByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + validateString(fqn, "Incorrect fqn for ctl schema request."); + LOG.debug("Find latest ctl schema by fqn {}, tenantId {} and applicationId {}", fqn, tenantId, applicationId); + return DaoUtil.getDto(ctlSchemaDao.findLatestByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId)); } - + @Override - public List findTenantCTLSchemasMetaInfoByTenantId(String tenantId) { - validateSqlId(tenantId, "Incorrect tenant id for ctl schema request."); - LOG.debug("Find meta info for ctl schemas by tenant id {}", tenantId); - return getMetaInfoFromCTLSchema(ctlSchemaDao.findTenantSchemasByTenantId(tenantId)); + public CTLSchemaDto findLatestByMetaInfoId(String metaInfoId) { + validateString(metaInfoId, "Incorrect meta info id for ctl schema request."); + LOG.debug("Find latest ctl schema by meta info id {}", metaInfoId); + return DaoUtil.getDto(ctlSchemaDao.findLatestByMetaInfoId(metaInfoId)); + } + + @Override + public List findAllCTLSchemasByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + validateString(fqn, "Incorrect fqn for ctl schema request."); + LOG.debug("Find all ctl schemas by fqn {}, tenantId {} and applicationId {}", fqn, tenantId, applicationId); + return convertDtoList(ctlSchemaDao.findAllByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId)); } @Override - public List findAvailableCTLSchemasMetaInfo(String tenantId) { - LOG.debug("Find system and tenant scopes ctl schemas by tenant id {}", tenantId); - return getMetaInfoFromCTLSchema(ctlSchemaDao.findAvailableSchemas(tenantId)); + public List findCTLSchemas() { + LOG.debug("Find all ctl schemas"); + return convertDtoList(ctlSchemaDao.find()); } @Override @@ -354,13 +409,13 @@ public List findCTLSchemaDependents(String schemaId) { } @Override - public List findCTLSchemaDependents(String fqn, Integer version, String tenantId) { + public List findCTLSchemaDependents(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } - LOG.debug("Find dependents schemas for schema with fqn {} version {} and tenantId {}", fqn, version, tenantId); + LOG.debug("Find dependents schemas for schema with fqn {} version {}, tenantId {} and applicationId ()", fqn, version, tenantId, applicationId); List schemas = Collections.emptyList(); - CTLSchema schema = ctlSchemaDao.findByFqnAndVerAndTenantId(fqn, version, tenantId); + CTLSchema schema = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); if (schema != null) { schemas = convertDtoList(ctlSchemaDao.findDependentSchemas(schema.getStringId())); } @@ -373,50 +428,40 @@ private void validateCTLSchemaObject(CTLSchemaDto ctlSchema) { if (metaInfo == null) { throw new RuntimeException("Incorrect ctl schema object. CTLSchemaMetaInfoDto is mandatory information."); } else { - if (isBlank(metaInfo.getFqn()) || metaInfo.getVersion() == null) { - throw new RuntimeException("Incorrect CTL meta information, please add correct version and fqn."); + if (isBlank(metaInfo.getFqn()) || ctlSchema.getVersion() == null) { + throw new RuntimeException("Incorrect CTL schema, please add correct version and fqn."); } } } private List getMetaInfoFromCTLSchema(List schemas) { - List metaInfoDtoList = Collections.emptyList(); + Map metaInfoMap = new HashMap<>(); if (!schemas.isEmpty()) { - metaInfoDtoList = new ArrayList<>(schemas.size()); for (CTLSchema schema : schemas) { - CTLSchemaMetaInfoDto metaInfoDto = getDto(schema.getMetaInfo()); - metaInfoDto.setName(schema.getName()); - metaInfoDtoList.add(metaInfoDto); - } - } - return metaInfoDtoList; - } - - private void updateEditableFields(CTLSchemaDto src, CTLSchema dst) { - CTLSchemaScopeDto scope = src.getMetaInfo().getScope(); - dst.setDescription(src.getDescription()); - dst.setName(src.getName()); - dst.setCreatedUsername(src.getCreatedUsername()); - String tenantId = src.getTenantId(); - if (isBlank(tenantId)) { - if (SYSTEM.equals(scope)) { - dst.setTenant(null); - } - } - String appId = src.getApplicationId(); - if (isBlank(appId)) { - if (SYSTEM.equals(scope) || TENANT.equals(scope)) { - dst.setApplication(null); + String metaInfoId = schema.getMetaInfo().getStringId(); + CTLSchemaMetaInfoDto metaInfoDto = metaInfoMap.get(metaInfoId); + if (metaInfoDto == null) { + metaInfoDto = getDto(schema.getMetaInfo()); + metaInfoMap.put(metaInfoId, metaInfoDto); + } + List versions = metaInfoDto.getVersions(); + if (versions == null) { + versions = new ArrayList<>(); + metaInfoDto.setVersions(versions); + } + versions.add(schema.getVersion()); } } + List result = new ArrayList<>(metaInfoMap.values()); + return result; } - + @Override public FileData shallowExport(CTLSchemaDto schema) { try { FileData result = new FileData(); result.setContentType(JSON); - result.setFileName(MessageFormat.format(CTL_EXPORT_TEMPLATE, schema.getMetaInfo().getFqn(), schema.getMetaInfo().getVersion())); + result.setFileName(MessageFormat.format(CTL_EXPORT_TEMPLATE, schema.getMetaInfo().getFqn(), schema.getVersion())); // Format schema body Object json = FORMATTER.readValue(schema.getBody(), Object.class); @@ -443,7 +488,7 @@ public FileData flatExport(CTLSchemaDto schema) { try { FileData result = new FileData(); result.setContentType(JSON); - result.setFileName(MessageFormat.format(CTL_EXPORT_TEMPLATE, schema.getMetaInfo().getFqn(), schema.getMetaInfo().getVersion())); + result.setFileName(MessageFormat.format(CTL_EXPORT_TEMPLATE, schema.getMetaInfo().getFqn(), schema.getVersion())); // Get schema body String body = flatExportAsString(schema); @@ -499,11 +544,11 @@ private List recursiveShallowExport(List files, CTLSchemaDto ObjectNode dependency = (ObjectNode) node; String fqn = dependency.get(FQN).getTextValue(); Integer version = dependency.get(VERSION).getIntValue(); - CTLSchemaDto child = this.findCTLSchemaByFqnAndVerAndTenantId(fqn, version, parent.getTenantId()); + CTLSchemaDto child = this.findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId( + fqn, version, parent.getMetaInfo().getTenantId(), parent.getMetaInfo().getApplicationId()); this.recursiveShallowExport(files, child); } } return files; } - } 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 85ebc96d77..6193388ac6 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 @@ -69,7 +69,6 @@ import org.kaaproject.kaa.common.dto.UserDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.logs.LogAppenderDto; import org.kaaproject.kaa.common.dto.logs.LogHeaderStructureDto; import org.kaaproject.kaa.common.dto.logs.LogSchemaDto; @@ -219,7 +218,7 @@ public class AbstractTest { @Autowired protected SdkProfileDao sdkProfileDao; @Autowired - protected CTLSchemaDao ctlSchemaDao; + protected CTLSchemaDao ctlSchemaDao; @Autowired protected CTLSchemaMetaInfoDao ctlSchemaMetaInfoDao; @Autowired @@ -279,15 +278,23 @@ protected String readSchemaFileAsString(String filePath) throws IOException { protected ApplicationDto generateApplicationDto() { return generateApplicationDto(null); } - + protected ApplicationDto generateApplicationDto(String tenantId) { + return generateApplicationDto(tenantId, null); + } + + protected ApplicationDto generateApplicationDto(String tenantId, String appName) { ApplicationDto app = new ApplicationDto(); if (isBlank(tenantId)) { app.setTenantId(generateTenantDto().getId()); } else { app.setTenantId(tenantId); } - app.setName("Test app"); + if (!isBlank(appName)) { + app.setName(appName); + } else { + app.setName("Test app"); + } return applicationService.saveApp(app); } @@ -747,21 +754,13 @@ protected EndpointProfileDto generateEndpointProfileWithGroupIdDto(String endpoi } protected CTLSchemaDto generateCTLSchemaDto(String tenantId) { - return generateCTLSchemaDto(DEFAULT_FQN, tenantId, 100, CTLSchemaScopeDto.TENANT); + return generateCTLSchemaDto(DEFAULT_FQN, tenantId, null, 100); } - protected CTLSchemaDto generateCTLSchemaDto(String fqn, String tenantId, int version, CTLSchemaScopeDto scopeDto) { + protected CTLSchemaDto generateCTLSchemaDto(String fqn, String tenantId, String applicationId, int version) { CTLSchemaDto ctlSchema = new CTLSchemaDto(); - CTLSchemaMetaInfoDto metaInfoDto = new CTLSchemaMetaInfoDto(fqn, version); - if (scopeDto == null) { - if (isBlank(tenantId)) { - scopeDto = CTLSchemaScopeDto.SYSTEM; - } else { - scopeDto = CTLSchemaScopeDto.TENANT; - } - } - metaInfoDto.setScope(scopeDto); - ctlSchema.setMetaInfo(metaInfoDto); + ctlSchema.setMetaInfo(new CTLSchemaMetaInfoDto(fqn, tenantId, applicationId)); + ctlSchema.setVersion(version); String name = fqn.substring(fqn.lastIndexOf(".") + 1); String namespace = fqn.substring(0, fqn.lastIndexOf(".")); StringBuilder body = new StringBuilder("{\"type\": \"record\","); @@ -770,7 +769,6 @@ protected CTLSchemaDto generateCTLSchemaDto(String fqn, String tenantId, int ver body = body.append("\"version\": ").append(version).append(","); body = body.append("\"dependencies\": [], \"fields\": []}"); ctlSchema.setBody(body.toString()); - ctlSchema.setTenantId(tenantId); return ctlSchema; } @@ -787,7 +785,7 @@ protected ServerProfileSchemaDto generateServerProfileSchema(String appId, Strin } schemaDto.setApplicationId(appId); schemaDto.setCreatedTime(System.currentTimeMillis()); - schemaDto.setCtlSchemaId(ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, version, CTLSchemaScopeDto.SERVER_PROFILE_SCHEMA)).getId()); + schemaDto.setCtlSchemaId(ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, appId, version)).getId()); return serverProfileService.saveServerProfileSchema(schemaDto); } 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 4afc2cf51c..96af892ff9 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 @@ -16,6 +16,20 @@ package org.kaaproject.kaa.server.common.dao.impl.sql; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + import org.junit.Assert; import org.kaaproject.kaa.common.dto.KaaAuthorityDto; import org.kaaproject.kaa.common.dto.NotificationTypeDto; @@ -53,20 +67,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - public abstract class HibernateAbstractTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(HibernateAbstractTest.class); @@ -246,15 +246,14 @@ protected CTLSchema generateCTLSchema(String fqn, int version, Tenant tenant, CT } } CTLSchemaMetaInfo metaInfo = new CTLSchemaMetaInfo(); - metaInfo.setVersion(version); metaInfo.setFqn(fqn); - metaInfo.setScope(scope); + metaInfo.setTenant(tenant); metaInfo = ctlSchemaMetaInfoDao.save(metaInfo); CTLSchema ctlSchema = new CTLSchema(); - ctlSchema.setTenant(tenant); + ctlSchema.setMetaInfo(metaInfo); + ctlSchema.setVersion(version); ctlSchema.setBody(UUID.randomUUID().toString()); ctlSchema.setDependencySet(new HashSet()); - ctlSchema.setMetaInfo(metaInfo); ctlSchema = ctlSchemaDao.save(ctlSchema); return ctlSchema; } diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDaoTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDaoTest.java index 3404d7d20e..b342ad8df9 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDaoTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDaoTest.java @@ -76,18 +76,18 @@ public void before() { } } Set dependency = new HashSet<>(); - firstSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 1, tenant.getId(), 1, null)); + firstSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 1, tenant.getId(), null, 1)); dependency.add(firstSchema); - secondSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 2, tenant.getId(), 2, null)); + secondSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 2, tenant.getId(), null, 2)); dependency.add(secondSchema); - thirdSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 3, tenant.getId(), 3, null)); + thirdSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 3, tenant.getId(), null, 3)); dependency.add(thirdSchema); - fourthSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 4, tenant.getId(), 4, null)); + fourthSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN + 4, tenant.getId(), null, 4)); dependency.add(fourthSchema); - mainSchema = generateCTLSchemaDto(DEFAULT_FQN + 5, tenant.getId(), 7, null); + mainSchema = generateCTLSchemaDto(DEFAULT_FQN + 5, tenant.getId(), null, 7); mainSchema.setDependencySet(dependency); mainSchema = ctlService.saveCTLSchema(mainSchema); - systemSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(SYSTEM_FQN, null, 50, null)); + systemSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(SYSTEM_FQN, null, null, 50)); } @Test(expected = Exception.class) @@ -98,15 +98,15 @@ public void saveCTLSchemaWithSameFqnAndVersion() { private CTLSchema generateCTLSchema(String fqn, Tenant tenant, int version, String body) { CTLSchema ctlSchema = new CTLSchema(); - ctlSchema.setMetaInfo(new CTLSchemaMetaInfo(fqn, version)); + if (tenant == null) { + tenant = generateTenant(); + } + ctlSchema.setMetaInfo(new CTLSchemaMetaInfo(fqn, tenant, null)); + ctlSchema.setVersion(version); if (isBlank(body)) { body = UUID.randomUUID().toString(); } ctlSchema.setBody(body); - if (tenant == null) { - tenant = generateTenant(); - } - ctlSchema.setTenant(tenant); return ctlSchema; } @@ -127,14 +127,18 @@ public void saveCTLSchemaWithDependency() throws InterruptedException { @Test - public void testFindByFqnAndVerAndTenantId() { - CTLSchema found = ctlSchemaDao.findByFqnAndVerAndTenantId(firstSchema.getMetaInfo().getFqn(), firstSchema.getMetaInfo().getVersion(), firstSchema.getTenantId()); + public void testFindByFqnAndVerAndTenantIdAndApplicationId() { + CTLSchema found = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(firstSchema.getMetaInfo().getFqn(), + firstSchema.getVersion(), + firstSchema.getMetaInfo().getTenantId(), + firstSchema.getMetaInfo().getApplicationId()); Assert.assertEquals(firstSchema, found.toDto()); } @Test - public void testFindSystemByFqnAndVerAndTenantId() { - CTLSchema found = ctlSchemaDao.findByFqnAndVerAndTenantId(systemSchema.getMetaInfo().getFqn(), systemSchema.getMetaInfo().getVersion(), tenant.getId()); + public void testFindSystemByFqnAndVerAndTenantIdAndApplicationId() { + CTLSchema found = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(systemSchema.getMetaInfo().getFqn(), + systemSchema.getVersion(), null, null); Assert.assertEquals(systemSchema, found.toDto()); } @@ -146,19 +150,13 @@ public void testFindSystemSchemas() { @Test public void testFindLatestByFqn() { - CTLSchema latest = ctlSchemaDao.findLatestByFqn(SYSTEM_FQN); + CTLSchema latest = ctlSchemaDao.findLatestByFqnAndTenantIdAndApplicationId(SYSTEM_FQN, null, null); Assert.assertEquals(systemSchema, latest.toDto()); } @Test - public void testRemoveByFqnAndVerAndTenantId() { - ctlSchemaDao.removeByFqnAndVerAndTenantId(systemSchema.getMetaInfo().getFqn(), systemSchema.getMetaInfo().getVersion(), systemSchema.getTenantId()); - Assert.assertNull(ctlSchemaDao.findById(systemSchema.getId())); - } - - @Test - public void testFindAvailableSchemas() { - List found = ctlSchemaDao.findAvailableSchemas(tenant.getId()); + public void testFindAvailableSchemasForTenant() { + List found = ctlSchemaDao.findAvailableSchemasForTenant(tenant.getId()); Assert.assertEquals(getIdsDto(Arrays.asList(firstSchema, secondSchema, thirdSchema, fourthSchema, mainSchema, systemSchema)), getIds(found)); } } diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfoTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfoTest.java index 84111f8f00..6dd883d1ca 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfoTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaMetaInfoTest.java @@ -1,17 +1,17 @@ -/* - * Copyright 2015 CyberVision, Inc. +/** + * Copyright 2014-2016 CyberVision, Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.kaaproject.kaa.server.common.dao.model.sql; @@ -25,4 +25,4 @@ public class CTLSchemaMetaInfoTest { public void hashCodeEqualsTest() { EqualsVerifier.forClass(CTLSchemaMetaInfo.class).usingGetClass().verify(); } -} +} \ No newline at end of file diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/AbstractServiceImplTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/AbstractServiceImplTest.java index c8a900076f..9e74eb4e8a 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/AbstractServiceImplTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/AbstractServiceImplTest.java @@ -30,11 +30,9 @@ import org.junit.Assert; import org.kaaproject.kaa.common.dto.ApplicationDto; -import org.kaaproject.kaa.common.dto.ChangeProfileFilterNotification; import org.kaaproject.kaa.common.dto.EndpointGroupDto; -import org.kaaproject.kaa.common.dto.KaaAuthorityDto; -import org.kaaproject.kaa.common.dto.ProfileFilterDto; import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; +import org.kaaproject.kaa.common.dto.KaaAuthorityDto; import org.kaaproject.kaa.common.dto.TenantAdminDto; import org.kaaproject.kaa.common.dto.TenantDto; import org.kaaproject.kaa.common.dto.UserDto; @@ -136,20 +134,12 @@ protected String readSchemaFileAsString(String filePath) throws IOException { return null; } - protected CTLSchemaDto generateCTLSchemaDto(String fqn, String tenantId, int version, CTLSchemaScopeDto scopeDto) { + protected CTLSchemaDto generateCTLSchemaDto(String fqn, String tenantId, int version) { CTLSchemaDto ctlSchema = new CTLSchemaDto(); - CTLSchemaMetaInfoDto metaInfoDto = new CTLSchemaMetaInfoDto(fqn, version); - if (scopeDto == null) { - if (isBlank(tenantId)) { - scopeDto = CTLSchemaScopeDto.SYSTEM; - } else { - scopeDto = CTLSchemaScopeDto.TENANT; - } - } - metaInfoDto.setScope(scopeDto); + CTLSchemaMetaInfoDto metaInfoDto = new CTLSchemaMetaInfoDto(fqn, tenantId); ctlSchema.setMetaInfo(metaInfoDto); + ctlSchema.setVersion(version); ctlSchema.setBody(UUID.randomUUID().toString()); - ctlSchema.setTenantId(tenantId); return ctlSchema; } @@ -162,7 +152,7 @@ protected List generateProfSchema(String tenantId, Str if (isBlank(applicationId)) { applicationId = generateApplication(tenantId).getId(); } - CTLSchemaDto ctlSchemaDto = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, 1, null)); + CTLSchemaDto ctlSchemaDto = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, 1)); EndpointProfileSchemaDto schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImplTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImplTest.java index 74cea8a844..ccfaf67643 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImplTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/CTLServiceImplTest.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -35,12 +37,12 @@ import org.junit.Ignore; import org.junit.Test; import org.kaaproject.kaa.common.dto.ApplicationDto; +import org.kaaproject.kaa.common.dto.HasId; import org.kaaproject.kaa.common.dto.TenantDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.common.dao.AbstractTest; -import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException; +import org.kaaproject.kaa.server.common.dao.exception.DatabaseProcessingException; @Ignore("This test should be extended and initialized with proper context in each NoSQL submodule") public class CTLServiceImplTest extends AbstractTest { @@ -49,6 +51,7 @@ public class CTLServiceImplTest extends AbstractTest { private TenantDto tenant; private ApplicationDto appDto; + private ApplicationDto appDto2; private CTLSchemaDto firstSchema; private CTLSchemaDto secondSchema; private CTLSchemaDto thirdSchema; @@ -57,7 +60,11 @@ public class CTLServiceImplTest extends AbstractTest { private CTLSchemaDto defaultSystemSchema; private CTLSchemaDto systemSchema; private CTLSchemaDto tenantSchema; + private CTLSchemaDto tenantSchema2; private CTLSchemaDto appSchema; + private CTLSchemaDto app2Schema; + private CTLSchemaDto appSchema2; + private CTLSchemaDto appSchema3; private static final String TEST_CTL_SCHEMA_ALPHA = "dao/ctl/alpha.json"; private static final String TEST_CTL_SCHEMA_ALPHA_FLAT = "dao/ctl/alphaFlat.json"; @@ -77,44 +84,51 @@ public void before() throws Exception { TenantDto tn = new TenantDto(); tn.setName(SUPER_TENANT); tenant = userService.saveTenant(tn); - appDto = generateApplicationDto(tenant.getId()); + appDto = generateApplicationDto(tenant.getId(), "The app 1"); + appDto2 = generateApplicationDto(tenant.getId(), "The app 2"); List ctlSchemas = ctlService.findSystemCTLSchemas(); defaultSystemSchema = ctlSchemas.get(0); } } Set dependency = new HashSet<>(); - firstSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+1, tenant.getId(), 1, null)); + firstSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+1, tenant.getId(), null, 1)); dependency.add(firstSchema); - secondSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+2, tenant.getId(), 2, null)); + secondSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+2, tenant.getId(), null, 2)); dependency.add(secondSchema); - thirdSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+3, tenant.getId(), 3, null)); + thirdSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+3, tenant.getId(), null, 3)); dependency.add(thirdSchema); - fourthSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+4, tenant.getId(), 4, null)); + fourthSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+4, tenant.getId(), null, 4)); dependency.add(fourthSchema); - mainSchema = generateCTLSchemaDto(DEFAULT_FQN, tenant.getId(), 7, null); + mainSchema = generateCTLSchemaDto(DEFAULT_FQN+5, tenant.getId(), null, 7); mainSchema.setDependencySet(dependency); mainSchema = ctlService.saveCTLSchema(mainSchema); - systemSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, null, 50, null)); - tenantSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN, tenant.getId(), 77, null)); - CTLSchemaDto unsaved = generateCTLSchemaDto(DEFAULT_FQN, tenant.getId(), 80, CTLSchemaScopeDto.APPLICATION); - unsaved.setApplicationId(appDto.getId()); + systemSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+6, null, null, 50)); + tenantSchema = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+7, tenant.getId(), null, 77)); + tenantSchema2 = ctlService.saveCTLSchema(generateCTLSchemaDto(DEFAULT_FQN+7, tenant.getId(), null, 78)); + CTLSchemaDto unsaved = generateCTLSchemaDto(DEFAULT_FQN+8, tenant.getId(), appDto.getId(), 80); appSchema = ctlService.saveCTLSchema(unsaved); + unsaved = generateCTLSchemaDto(DEFAULT_FQN+8, tenant.getId(), appDto.getId(), 81); + appSchema2 = ctlService.saveCTLSchema(unsaved); + unsaved = generateCTLSchemaDto(DEFAULT_FQN+9, tenant.getId(), appDto.getId(), 2); + appSchema3 = ctlService.saveCTLSchema(unsaved); + unsaved = generateCTLSchemaDto(DEFAULT_FQN+8, tenant.getId(), appDto2.getId(), 11); + app2Schema = ctlService.saveCTLSchema(unsaved); gamma = new CTLSchemaDto(); - CTLSchemaMetaInfoDto gammaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Gamma", 1); - gammaMetaInfo.setScope(CTLSchemaScopeDto.TENANT); + CTLSchemaMetaInfoDto gammaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Gamma", tenant.getId()); gamma.setMetaInfo(gammaMetaInfo); + gamma.setVersion(1); gamma.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_GAMMA)); gamma = ctlService.saveCTLSchema(gamma); gamma = ctlService.findCTLSchemaById(gamma.getId()); beta = new CTLSchemaDto(); - CTLSchemaMetaInfoDto betaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Beta", 1); - betaMetaInfo.setScope(CTLSchemaScopeDto.TENANT); + CTLSchemaMetaInfoDto betaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Beta", tenant.getId()); + beta.setMetaInfo(betaMetaInfo); + beta.setVersion(1); Set betaDependencies = new HashSet<>(); betaDependencies.add(gamma); - beta.setMetaInfo(betaMetaInfo); beta.setDependencySet(betaDependencies); beta.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_BETA)); beta = ctlService.saveCTLSchema(beta); @@ -122,11 +136,11 @@ public void before() throws Exception { beta = ctlService.findCTLSchemaById(beta.getId()); alpha = new CTLSchemaDto(); - CTLSchemaMetaInfoDto alphaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Alpha", 1); - alphaMetaInfo.setScope(CTLSchemaScopeDto.TENANT); + CTLSchemaMetaInfoDto alphaMetaInfo = new CTLSchemaMetaInfoDto("org.kaaproject.kaa.Alpha", tenant.getId()); + alpha.setMetaInfo(alphaMetaInfo); + alpha.setVersion(1); Set alphaDependencies = new HashSet<>(); alphaDependencies.add(beta); - alpha.setMetaInfo(alphaMetaInfo); alpha.setDependencySet(alphaDependencies); alpha.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_ALPHA)); @@ -136,49 +150,26 @@ public void before() throws Exception { } @Test - public void testUpdateCTLSchema() { - } - - @Test - public void testFindCTLSchemasMetaInfoByApplicationId() { - } - - @Test - public void testFindCTLSchemasMetaInfoByTenantId() { - } - - @Test - public void testRemoveCTLSchemaByFqnAndVerAndTenantId() { + public void testRemoveCTLSchemaByFqnAndVerAndTenantIdAndApplicationId() { String schemaId = tenantSchema.getId(); - ctlService.removeCTLSchemaByFqnAndVerAndTenantId(tenantSchema.getMetaInfo().getFqn(), tenantSchema.getMetaInfo().getVersion(), - tenantSchema.getTenantId()); + ctlService.removeCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(tenantSchema.getMetaInfo().getFqn(), tenantSchema.getVersion(), + tenantSchema.getMetaInfo().getTenantId(), tenantSchema.getMetaInfo().getApplicationId()); Assert.assertNull(ctlService.findCTLSchemaById(schemaId)); } @Test public void testRemoveCTLSchemaByFqnAndVerAndWithoutTenantId() { String schemaId = systemSchema.getId(); - ctlService.removeCTLSchemaByFqnAndVerAndTenantId(systemSchema.getMetaInfo().getFqn(), systemSchema.getMetaInfo().getVersion(), - systemSchema.getTenantId()); + ctlService.removeCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(systemSchema.getMetaInfo().getFqn(), systemSchema.getVersion(), + systemSchema.getMetaInfo().getTenantId(), systemSchema.getMetaInfo().getApplicationId()); Assert.assertNull(ctlService.findCTLSchemaById(schemaId)); } @Test - public void testRemoveCTLSchemaById() { - String schemaId = mainSchema.getId(); - ctlService.removeCTLSchemaById(schemaId); - Assert.assertNull(ctlService.findCTLSchemaById(schemaId)); - } - - @Test(expected = IncorrectParameterException.class) - public void testRemoveCTLSchemaByIdWithNull() { - ctlService.removeCTLSchemaById(null); - } - - @Test - public void testFindCTLSchemaByFqnAndVerAndTenantId() { + public void testFindCTLSchemaByFqnAndVerAndTenantIdAndApplicationId() { CTLSchemaMetaInfoDto metaInfo = firstSchema.getMetaInfo(); - CTLSchemaDto found = ctlService.findCTLSchemaByFqnAndVerAndTenantId(metaInfo.getFqn(), metaInfo.getVersion(), firstSchema.getTenantId()); + CTLSchemaDto found = ctlService.findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(metaInfo.getFqn(), + firstSchema.getVersion(), metaInfo.getTenantId(), metaInfo.getApplicationId()); Assert.assertEquals(firstSchema, found); } @@ -190,39 +181,75 @@ public void testFindSystemCTLSchemas() { @Test public void testFindSystemCTLSchemasMetaInfo() { - List appSchemas = ctlService.findSystemCTLSchemasMetaInfo(); - Assert.assertEquals(Arrays.asList(defaultSystemSchema.getMetaInfo(), systemSchema.getMetaInfo()), appSchemas); + List appSchemas = ctlService.findSystemCTLSchemasMetaInfo(); + Comparator comparator = new Comparator() { + @Override + public int compare(HasId o1, HasId o2) { + return o1.getId().compareTo(o2.getId()); + } + }; + Collections.sort(appSchemas, comparator); + List expectedSchemas = Arrays.asList(defaultSystemSchema.getMetaInfo(), systemSchema.getMetaInfo()); + Collections.sort(expectedSchemas, comparator); + Assert.assertEquals(expectedSchemas, appSchemas); } @Test public void testFindLatestCTLSchemaByFqn() { - CTLSchemaDto latest = ctlService.findLatestCTLSchemaByFqn(DEFAULT_FQN); - Assert.assertEquals(Integer.valueOf(80), latest.getMetaInfo().getVersion()); + CTLSchemaDto latestTenantScope = ctlService.findLatestCTLSchemaByFqnAndTenantIdAndApplicationId(DEFAULT_FQN+7, tenant.getId(), null); + Assert.assertEquals(Integer.valueOf(78), latestTenantScope.getVersion()); + CTLSchemaDto latestAppScope = ctlService.findLatestCTLSchemaByFqnAndTenantIdAndApplicationId(DEFAULT_FQN+8, tenant.getId(), appDto.getId()); + Assert.assertEquals(Integer.valueOf(81), latestAppScope.getVersion()); + } + + @Test + public void testScopeUpdate() { + CTLSchemaMetaInfoDto metaInfo = appSchema3.getMetaInfo(); + metaInfo.setApplicationId(null); + ctlService.updateCTLSchemaMetaInfoScope(metaInfo); + CTLSchemaDto found = ctlService.findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(metaInfo.getFqn(), appSchema3.getVersion(), metaInfo.getTenantId(), null); + Assert.assertEquals(appSchema3, found); + } + + @Test(expected = DatabaseProcessingException.class) + public void testScopeUpdateForbidden() { + CTLSchemaMetaInfoDto metaInfo = appSchema.getMetaInfo(); + metaInfo.setApplicationId(null); + ctlService.updateCTLSchemaMetaInfoScope(metaInfo); + } + + @Test + public void testFindSiblingsFqns() { + List siblingSchemas = + ctlService.findSiblingsByFqnTenantIdAndApplicationId(appSchema.getMetaInfo().getFqn(), appSchema.getMetaInfo().getTenantId(), appSchema.getMetaInfo().getApplicationId()); + + Assert.assertNotNull(siblingSchemas); + Assert.assertEquals(1, siblingSchemas.size()); + Assert.assertEquals(app2Schema.getMetaInfo(), siblingSchemas.get(0)); } @Test public void testFindCTLSchemaDependentsByFqnVersionTenantId() { - List appSchemas = ctlService.findCTLSchemaDependents(firstSchema.getMetaInfo().getFqn(), firstSchema.getMetaInfo().getVersion(), - tenant.getId()); + List appSchemas = ctlService.findCTLSchemaDependents(firstSchema.getMetaInfo().getFqn(), firstSchema.getVersion(), + tenant.getId(), null); Assert.assertEquals(Arrays.asList(mainSchema), appSchemas); - appSchemas = ctlService.findCTLSchemaDependents(secondSchema.getMetaInfo().getFqn(), secondSchema.getMetaInfo().getVersion(), tenant.getId()); + appSchemas = ctlService.findCTLSchemaDependents(secondSchema.getMetaInfo().getFqn(), secondSchema.getVersion(), tenant.getId(), null); Assert.assertEquals(Arrays.asList(mainSchema), appSchemas); - appSchemas = ctlService.findCTLSchemaDependents(thirdSchema.getMetaInfo().getFqn(), thirdSchema.getMetaInfo().getVersion(), tenant.getId()); + appSchemas = ctlService.findCTLSchemaDependents(thirdSchema.getMetaInfo().getFqn(), thirdSchema.getVersion(), tenant.getId(), null); Assert.assertEquals(Arrays.asList(mainSchema), appSchemas); - appSchemas = ctlService.findCTLSchemaDependents(fourthSchema.getMetaInfo().getFqn(), fourthSchema.getMetaInfo().getVersion(), tenant.getId()); + appSchemas = ctlService.findCTLSchemaDependents(fourthSchema.getMetaInfo().getFqn(), fourthSchema.getVersion(), tenant.getId(), null); Assert.assertEquals(Arrays.asList(mainSchema), appSchemas); - appSchemas = ctlService.findCTLSchemaDependents(mainSchema.getMetaInfo().getFqn(), mainSchema.getMetaInfo().getVersion(), tenant.getId()); + appSchemas = ctlService.findCTLSchemaDependents(mainSchema.getMetaInfo().getFqn(), mainSchema.getVersion(), tenant.getId(), null); Assert.assertTrue(appSchemas.isEmpty()); } @Test public void multiThreadCTLSchemaSaveTest() throws InterruptedException, ExecutionException { - String tenantId = null; List> list = new ArrayList<>(); for (int i = 0; i < 100; i++) { list.add(executorService.submit(new Callable() { @@ -239,15 +266,20 @@ public CTLSchemaDto call() { })); } Iterator> iterator = list.iterator(); + List schemas = new ArrayList<>(); while (iterator.hasNext()) { Future f = iterator.next(); while (!f.isDone()) { } - tenantId = f.get().getTenantId(); + schemas.add(f.get()); iterator.remove(); } - CTLSchemaDto schemaDto = ctlService.findCTLSchemaByFqnAndVerAndTenantId(DEFAULT_FQN, 100, tenantId); - Assert.assertEquals(Long.valueOf(100L), schemaDto.getMetaInfo().getCount()); + Assert.assertEquals(100, schemas.size()); + for (CTLSchemaDto schema : schemas) { + CTLSchemaDto savedSchema = ctlService.findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(DEFAULT_FQN, 100, schema.getMetaInfo().getTenantId(), null); + Assert.assertNotNull(savedSchema); + Assert.assertEquals(schema, savedSchema); + } } @Test diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/admin/AuthResultDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/admin/AuthResultDto.java index 602232055b..f03a24bb10 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/admin/AuthResultDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/admin/AuthResultDto.java @@ -27,6 +27,7 @@ public class AuthResultDto implements Serializable { private String username; private String displayName; private KaaAuthorityDto authority; + private String tenantId; private Result authResult; public AuthResultDto() { @@ -62,6 +63,14 @@ public KaaAuthorityDto getAuthority() { public void setAuthority(KaaAuthorityDto authority) { this.authority = authority; } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } public Result getAuthResult() { return authResult; diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/AbstractCTLSchemaDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/AbstractCTLSchemaDto.java deleted file mode 100644 index c3785a6435..0000000000 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/AbstractCTLSchemaDto.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2015 CyberVision, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kaaproject.kaa.common.dto.ctl; - -import org.kaaproject.kaa.common.dto.HasId; - -import java.io.Serializable; - -public abstract class AbstractCTLSchemaDto implements Serializable, HasId { - - private static final long serialVersionUID = -3623332405545906155L; - - protected String id; - protected String tenantId; - protected String applicationId; - protected String body; - protected String defaultRecord; - protected String name; - protected String description; - protected String createdUsername; - protected long createdTime; - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - public String getTenantId() { - return tenantId; - } - - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getApplicationId() { - return applicationId; - } - - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public String getDefaultRecord() { - return defaultRecord; - } - - public void setDefaultRecord(String defaultRecord) { - this.defaultRecord = defaultRecord; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCreatedUsername() { - return createdUsername; - } - - public void setCreatedUsername(String createdUsername) { - this.createdUsername = createdUsername; - } - - public long getCreatedTime() { - return createdTime; - } - - public void setCreatedTime(long createdTime) { - this.createdTime = createdTime; - } -} diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaDto.java index 4fabd308e3..459c768ecd 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaDto.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 CyberVision, Inc. + * Copyright 2015-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,45 +16,32 @@ package org.kaaproject.kaa.common.dto.ctl; -import org.kaaproject.kaa.common.dto.HasId; - import java.io.Serializable; -import java.util.HashSet; -import java.util.Objects; import java.util.Set; +import org.kaaproject.kaa.common.dto.HasId; + /** * A Common Type Library schema. * * @since v0.8.0 */ -public class CTLSchemaDto extends AbstractCTLSchemaDto implements HasId, Serializable { +public class CTLSchemaDto implements HasId, Serializable { private static final long serialVersionUID = -7601241323233814152L; + private String id; private CTLSchemaMetaInfoDto metaInfo; + private Integer version; + private String body; + private String defaultRecord; + private String createdUsername; + private long createdTime; private Set dependencySet; public CTLSchemaDto() { } - public CTLSchemaDto(CTLSchemaInfoDto infoDto, Set dependencySet) { - Objects.requireNonNull(infoDto); - if (infoDto != null) { - this.dependencySet = dependencySet; - this.metaInfo = new CTLSchemaMetaInfoDto(infoDto.getFqn(), infoDto.getVersion(), infoDto.getScope()); - this.metaInfo.setId(infoDto.getMetaInfoId()); - id = infoDto.getId(); - applicationId = infoDto.getApplicationId(); - tenantId = infoDto.getTenantId(); - body = infoDto.getBody(); - createdTime = infoDto.getCreatedTime(); - createdUsername = infoDto.getCreatedUsername(); - name = infoDto.getName(); - description = infoDto.getDescription(); - } - } - @Override public String getId() { return id; @@ -64,7 +51,7 @@ public String getId() { public void setId(String id) { this.id = id; } - + public CTLSchemaMetaInfoDto getMetaInfo() { return metaInfo; } @@ -73,6 +60,46 @@ public void setMetaInfo(CTLSchemaMetaInfoDto metaInfo) { this.metaInfo = metaInfo; } + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getDefaultRecord() { + return defaultRecord; + } + + public void setDefaultRecord(String defaultRecord) { + this.defaultRecord = defaultRecord; + } + + public String getCreatedUsername() { + return createdUsername; + } + + public void setCreatedUsername(String createdUsername) { + this.createdUsername = createdUsername; + } + + public long getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(long createdTime) { + this.createdTime = createdTime; + } + public Set getDependencySet() { return dependencySet; } @@ -80,91 +107,65 @@ public Set getDependencySet() { public void setDependencySet(Set dependencySet) { this.dependencySet = dependencySet; } - - public CTLSchemaInfoDto toCTLSchemaInfoDto() { - CTLSchemaInfoDto infoDto = new CTLSchemaInfoDto(); - infoDto.setId(id); - infoDto.setFqn(metaInfo.getFqn()); - infoDto.setVersion(metaInfo.getVersion()); - infoDto.setScope(metaInfo.getScope()); - infoDto.setMetaInfoId(metaInfo.getId()); - infoDto.setApplicationId(applicationId); - infoDto.setTenantId(tenantId); - infoDto.setBody(body); - infoDto.setCreatedTime(createdTime); - infoDto.setCreatedUsername(createdUsername); - infoDto.setName(name); - infoDto.setDescription(description); - if (dependencySet != null && !dependencySet.isEmpty()) { - Set dependencies = new HashSet<>(); - for (CTLSchemaDto dep : dependencySet) { - CTLSchemaMetaInfoDto mi = dep.getMetaInfo(); - dependencies.add(new CTLSchemaMetaInfoDto(mi.getFqn(), mi.getVersion())); - } - infoDto.setDependencies(dependencies); - } - return infoDto; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((dependencySet == null) ? 0 : dependencySet.hashCode()); + result = prime * result + ((metaInfo == null) ? 0 : metaInfo.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; } @Override - public boolean equals(Object o) { - if (this == o) + public boolean equals(Object obj) { + if (this == obj) return true; - if (o == null || getClass() != o.getClass()) - return false; - - CTLSchemaDto that = (CTLSchemaDto) o; - - if (createdTime != that.createdTime) + if (obj == null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) + if (getClass() != obj.getClass()) return false; - if (metaInfo != null ? !metaInfo.equals(that.metaInfo) : that.metaInfo != null) + CTLSchemaDto other = (CTLSchemaDto) obj; + if (dependencySet == null) { + if (other.dependencySet != null) + return false; + } else if (!dependencySet.equals(other.dependencySet)) return false; - if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) + if (metaInfo == null) { + if (other.metaInfo != null) + return false; + } else if (!metaInfo.equals(other.metaInfo)) return false; - if (applicationId != null ? !applicationId.equals(that.applicationId) : that.applicationId != null) + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) return false; - if (body != null ? !body.equals(that.body) : that.body != null) - return false; - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - if (description != null ? !description.equals(that.description) : that.description != null) - return false; - if (createdUsername != null ? !createdUsername.equals(that.createdUsername) : that.createdUsername != null) - return false; - return !(dependencySet != null ? !dependencySet.equals(that.dependencySet) : that.dependencySet != null); - - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (metaInfo != null ? metaInfo.hashCode() : 0); - result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0); - result = 31 * result + (applicationId != null ? applicationId.hashCode() : 0); - result = 31 * result + (body != null ? body.hashCode() : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (description != null ? description.hashCode() : 0); - result = 31 * result + (createdUsername != null ? createdUsername.hashCode() : 0); - result = 31 * result + (int) (createdTime ^ (createdTime >>> 32)); - result = 31 * result + (dependencySet != null ? dependencySet.hashCode() : 0); - return result; + return true; } @Override public String toString() { - return "CTLSchemaDto{" + - "id='" + id + '\'' + - ", metaInfo=" + metaInfo + - ", tenantId='" + tenantId + '\'' + - ", appId='" + applicationId + '\'' + - ", body='" + body + '\'' + - ", name='" + name + '\'' + - ", description='" + description + '\'' + - ", createdUsername='" + createdUsername + '\'' + - ", createdTime=" + createdTime + - ", dependencySet=" + dependencySet + - '}'; + StringBuilder builder = new StringBuilder(); + builder.append("CTLSchemaDto [id="); + builder.append(id); + builder.append(", metaInfo="); + builder.append(metaInfo); + builder.append(", version="); + builder.append(version); + builder.append(", body="); + builder.append(body); + builder.append(", defaultRecord="); + builder.append(defaultRecord); + builder.append(", createdUsername="); + builder.append(createdUsername); + builder.append(", createdTime="); + builder.append(createdTime); + builder.append(", dependencySet="); + builder.append(dependencySet); + builder.append("]"); + return builder.toString(); } + } diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaInfoDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaInfoDto.java deleted file mode 100644 index b913fd3152..0000000000 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaInfoDto.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2015 CyberVision, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kaaproject.kaa.common.dto.ctl; - -import org.kaaproject.kaa.common.dto.HasId; - -import java.io.Serializable; -import java.util.Set; - -/** - * An object of this class represents - * {@link org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto} for REST API calls. - * - * @author Igor Khanenko - * - * @since v0.8.0 - */ -public class CTLSchemaInfoDto extends AbstractCTLSchemaDto implements HasId, Serializable { - - private static final long serialVersionUID = 3509310026130071994L; - - private String fqn; - private Integer version; - private CTLSchemaScopeDto scope; - private String metaInfoId; - private Set dependencies; - - public Set getDependencies() { - return dependencies; - } - - public void setDependencies(Set dependencies) { - this.dependencies = dependencies; - } - - public String getFqn() { - return fqn; - } - - public void setFqn(String fqn) { - this.fqn = fqn; - } - - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public CTLSchemaScopeDto getScope() { - return scope; - } - - public void setScope(CTLSchemaScopeDto scope) { - this.scope = scope; - } - - public String getMetaInfoId() { - return metaInfoId; - } - - public void setMetaInfoId(String metaInfoId) { - this.metaInfoId = metaInfoId; - } - - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((dependencies == null) ? 0 : dependencies.hashCode()); - result = prime * result + ((fqn == null) ? 0 : fqn.hashCode()); - result = prime * result - + ((metaInfoId == null) ? 0 : metaInfoId.hashCode()); - result = prime * result + ((scope == null) ? 0 : scope.hashCode()); - result = prime * result + ((version == null) ? 0 : version.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - CTLSchemaInfoDto other = (CTLSchemaInfoDto) obj; - if (dependencies == null) { - if (other.dependencies != null) { - return false; - } - } else if (!dependencies.equals(other.dependencies)) { - return false; - } - if (fqn == null) { - if (other.fqn != null) { - return false; - } - } else if (!fqn.equals(other.fqn)) { - return false; - } - if (metaInfoId == null) { - if (other.metaInfoId != null) { - return false; - } - } else if (!metaInfoId.equals(other.metaInfoId)) { - return false; - } - if (scope != other.scope) { - return false; - } - if (version == null) { - if (other.version != null) { - return false; - } - } else if (!version.equals(other.version)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("CTLSchemaInfoDto [fqn="); - builder.append(fqn); - builder.append(", version="); - builder.append(version); - builder.append(", scope="); - builder.append(scope); - builder.append(", metaInfoId="); - builder.append(metaInfoId); - builder.append(", dependencies="); - builder.append(dependencies); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaMetaInfoDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaMetaInfoDto.java index c382922639..811e9d30cd 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaMetaInfoDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaMetaInfoDto.java @@ -1,51 +1,54 @@ -/* - * Copyright 2015 CyberVision, Inc. +/** + * Copyright 2014-2016 CyberVision, Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.kaaproject.kaa.common.dto.ctl; +import java.io.Serializable; +import java.util.List; + import org.kaaproject.kaa.common.dto.HasId; import com.fasterxml.jackson.annotation.JsonIgnore; -import java.io.Serializable; - public class CTLSchemaMetaInfoDto implements HasId, Serializable { private static final long serialVersionUID = 365372783241958657L; private String id; - private String name; private String fqn; - private Integer version; - private CTLSchemaScopeDto scope; - @JsonIgnore - private Long count = 0L; + private String tenantId; + private String applicationId; + private List versions; public CTLSchemaMetaInfoDto() { } - public CTLSchemaMetaInfoDto(String fqn, Integer version) { + public CTLSchemaMetaInfoDto(String fqn) { this.fqn = fqn; - this.version = version; } - public CTLSchemaMetaInfoDto(String fqn, Integer version, CTLSchemaScopeDto scope) { + public CTLSchemaMetaInfoDto(String fqn, String tenantId) { + this.fqn = fqn; + this.tenantId = tenantId; + } + + public CTLSchemaMetaInfoDto(String fqn, String tenantId, String applicationId) { this.fqn = fqn; - this.version = version; - this.scope = scope; + this.tenantId = tenantId; + this.applicationId = applicationId; } @Override @@ -58,14 +61,6 @@ public void setId(String id) { this.id = id; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getFqn() { return fqn; } @@ -73,59 +68,93 @@ public String getFqn() { public void setFqn(String fqn) { this.fqn = fqn; } - - public Integer getVersion() { - return version; + + public String getTenantId() { + return tenantId; } - public void setVersion(Integer version) { - this.version = version; + public void setTenantId(String tenantId) { + this.tenantId = tenantId; } - public CTLSchemaScopeDto getScope() { - return scope; + public String getApplicationId() { + return applicationId; } - public void setScope(CTLSchemaScopeDto scope) { - this.scope = scope; + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; } - public Long getCount() { - return count; + @JsonIgnore + public CTLSchemaScopeDto getScope() { + if (tenantId != null && !tenantId.isEmpty()) { + if (applicationId != null && !applicationId.isEmpty()) { + return CTLSchemaScopeDto.APPLICATION; + } else { + return CTLSchemaScopeDto.TENANT; + } + } + return CTLSchemaScopeDto.SYSTEM; } - public void setCount(Long count) { - this.count = count; + public List getVersions() { + return versions; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CTLSchemaMetaInfoDto that = (CTLSchemaMetaInfoDto) o; - - if (fqn != null ? !fqn.equals(that.fqn) : that.fqn != null) return false; - if (version != null ? !version.equals(that.version) : that.version != null) return false; - return scope == that.scope; - + public void setVersions(List versions) { + this.versions = versions; } @Override public int hashCode() { - int result = fqn != null ? fqn.hashCode() : 0; - result = 31 * result + (version != null ? version.hashCode() : 0); - result = 31 * result + (scope != null ? scope.hashCode() : 0); + final int prime = 31; + int result = 1; + result = prime * result + ((applicationId == null) ? 0 : applicationId.hashCode()); + result = prime * result + ((fqn == null) ? 0 : fqn.hashCode()); + result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); return result; } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CTLSchemaMetaInfoDto other = (CTLSchemaMetaInfoDto) obj; + if (applicationId == null) { + if (other.applicationId != null) + return false; + } else if (!applicationId.equals(other.applicationId)) + return false; + if (fqn == null) { + if (other.fqn != null) + return false; + } else if (!fqn.equals(other.fqn)) + return false; + if (tenantId == null) { + if (other.tenantId != null) + return false; + } else if (!tenantId.equals(other.tenantId)) + return false; + return true; + } + @Override public String toString() { - return "CTLSchemaMetaInfoDto{" + - "id='" + id + '\'' + - ", fqn='" + fqn + '\'' + - ", version=" + version + - ", scope=" + scope + - '}'; - } -} + StringBuilder builder = new StringBuilder(); + builder.append("CTLSchemaMetaInfoDto [id="); + builder.append(id); + builder.append(", fqn="); + builder.append(fqn); + builder.append(", tenantId="); + builder.append(tenantId); + builder.append(", applicationId="); + builder.append(applicationId); + builder.append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaScopeDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaScopeDto.java index da0c7bb234..f28c65cbca 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaScopeDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/ctl/CTLSchemaScopeDto.java @@ -17,7 +17,7 @@ package org.kaaproject.kaa.common.dto.ctl; public enum CTLSchemaScopeDto { - SYSTEM(0), TENANT(1), APPLICATION(2), APPLICATION_LOCAL(3), PLUGIN_LOCAL(3), SERVER_PROFILE_SCHEMA(3), PROFILE_SCHEMA(3); + SYSTEM(0), TENANT(1), APPLICATION(2); private int level; 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 1ec16799bf..1ed89a6e22 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 @@ -40,6 +40,7 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.BaseSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.ConfigurationView; import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemaView; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; import org.kaaproject.kaa.server.admin.client.mvp.view.EcfSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.EcfView; import org.kaaproject.kaa.server.admin.client.mvp.view.EndpointGroupView; @@ -48,8 +49,8 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.HeaderView; import org.kaaproject.kaa.server.admin.client.mvp.view.LogAppenderView; import org.kaaproject.kaa.server.admin.client.mvp.view.NavigationView; -import org.kaaproject.kaa.server.admin.client.mvp.view.SdkProfileView; import org.kaaproject.kaa.server.admin.client.mvp.view.ProfileFilterView; +import org.kaaproject.kaa.server.admin.client.mvp.view.SdkProfileView; import org.kaaproject.kaa.server.admin.client.mvp.view.SendNotificationView; import org.kaaproject.kaa.server.admin.client.mvp.view.TenantView; import org.kaaproject.kaa.server.admin.client.mvp.view.TopicView; @@ -57,7 +58,6 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.UserProfileView; import org.kaaproject.kaa.server.admin.client.mvp.view.UserVerifierView; import org.kaaproject.kaa.server.admin.client.mvp.view.UserView; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; import com.google.gwt.place.shared.Place; import com.google.gwt.place.shared.PlaceController; @@ -155,8 +155,13 @@ public interface ClientFactory { UpdateUserConfigView getUpdateUserConfigView(); - BaseListView getCtlSchemasView(); + CtlSchemasView getSystemCtlSchemasView(); + CtlSchemasView getTenantCtlSchemasView(); + CtlSchemasView getApplicationCtlSchemasView(); + CtlSchemaView getCreateCtlSchemaView(); - CtlSchemaView getCtlSchemaView(); + CtlSchemaView getEditCtlSchemaView(); + CtlSchemaView getEditApplicationCtlSchemaView(); + CtlSchemaView getViewCtlSchemaView(); } 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 d7ec8f4dd1..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 @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 CyberVision, Inc. + * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,7 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.BaseSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.ConfigurationView; import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemaView; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; import org.kaaproject.kaa.server.admin.client.mvp.view.EcfSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.EcfView; import org.kaaproject.kaa.server.admin.client.mvp.view.EndpointGroupView; @@ -66,8 +67,11 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.config.ConfigurationSchemaViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.config.ConfigurationSchemasViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.config.ConfigurationViewImpl; +import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.ApplicationCtlSchemaViewImpl; +import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.ApplicationCtlSchemasViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.CtlSchemaViewImpl; -import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.CtlSchemasViewImpl; +import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.SystemCtlSchemasViewImpl; +import org.kaaproject.kaa.server.admin.client.mvp.view.ctl.TenantCtlSchemasViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.endpoint.EndpointGroupViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.endpoint.EndpointGroupsViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.endpoint.EndpointProfileViewImpl; @@ -104,7 +108,6 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.user.UsersViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.verifier.UserVerifierViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.verifier.UserVerifiersViewImpl; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; import com.google.gwt.place.shared.Place; import com.google.gwt.place.shared.PlaceController; @@ -201,9 +204,14 @@ public class ClientFactoryImpl implements ClientFactory { private final UpdateUserConfigView updateUserConfigView = new UpdateUserConfigViewImpl(); - private final BaseListView ctlSchemasView = new CtlSchemasViewImpl(); - private final CtlSchemaView createCtlSchemaView = new CtlSchemaViewImpl(true); - private final CtlSchemaView ctlSchemaView = new CtlSchemaViewImpl(false); + private final CtlSchemasView systemCtlSchemasView = new SystemCtlSchemasViewImpl(); + private final CtlSchemasView tenantCtlSchemasView = new TenantCtlSchemasViewImpl(); + private final CtlSchemasView applicationCtlSchemasView = new ApplicationCtlSchemasViewImpl(); + + private final CtlSchemaView createCtlSchemaView = new CtlSchemaViewImpl(true, true); + private final CtlSchemaView editCtlSchemaView = new CtlSchemaViewImpl(false, true); + private final CtlSchemaView editApplicationCtlSchemaView = new ApplicationCtlSchemaViewImpl(false, true); + private final CtlSchemaView viewCtlSchemaView = new CtlSchemaViewImpl(false, false); private Place homePlace; @@ -528,18 +536,38 @@ public UpdateUserConfigView getUpdateUserConfigView() { } @Override - public BaseListView getCtlSchemasView() { - return ctlSchemasView; + public CtlSchemaView getCreateCtlSchemaView() { + return createCtlSchemaView; } @Override - public CtlSchemaView getCreateCtlSchemaView() { - return createCtlSchemaView; + public CtlSchemaView getEditCtlSchemaView() { + return editCtlSchemaView; + } + + @Override + public CtlSchemaView getEditApplicationCtlSchemaView() { + return editApplicationCtlSchemaView; + } + + @Override + public CtlSchemaView getViewCtlSchemaView() { + return viewCtlSchemaView; + } + + @Override + public CtlSchemasView getSystemCtlSchemasView() { + return systemCtlSchemasView; + } + + @Override + public CtlSchemasView getTenantCtlSchemasView() { + return tenantCtlSchemasView; } @Override - public CtlSchemaView getCtlSchemaView() { - return ctlSchemaView; + public CtlSchemasView getApplicationCtlSchemasView() { + return applicationCtlSchemasView; } } \ No newline at end of file diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractBaseCtlSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractBaseCtlSchemaActivity.java index 4db05a2a7b..ca3343c703 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractBaseCtlSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractBaseCtlSchemaActivity.java @@ -20,10 +20,12 @@ import org.kaaproject.avro.ui.gwt.client.util.BusyAsyncCallback; import org.kaaproject.kaa.common.dto.BaseSchemaDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; 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.AbstractSchemaPlace; +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.view.BaseCtlSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel.FormDataLoader; import org.kaaproject.kaa.server.admin.client.util.ErrorMessageCustomizer; @@ -31,7 +33,10 @@ import org.kaaproject.kaa.server.admin.client.util.Utils; import org.kaaproject.kaa.server.admin.shared.schema.BaseSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.EventBus; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -80,35 +85,36 @@ protected void bind(final EventBus eventBus) { @Override protected void onEntityRetrieved() { if (create) { - createEmptyCtlSchemaForm(new BusyAsyncCallback() { + registrations.add(detailsView.getNewCtlButton().addClickHandler(new ClickHandler() { @Override - public void onSuccessImpl(CtlSchemaFormDto result) { - entity.setCtlSchemaForm(result); - KaaAdmin.getDataSource().getAvailableCtlSchemaReferences(new BusyAsyncCallback>() { - @Override - public void onFailureImpl(Throwable caught) { - Utils.handleException(caught, detailsView); - } - - @Override - public void onSuccessImpl( - List result) { - detailsView.getCtlSchemaReference().setAcceptableValues(result); - bindDetailsView(true); - } - }); - } - @Override - public void onFailureImpl(Throwable caught) { - Utils.handleException(caught, detailsView); + public void onClick(ClickEvent event) { + CtlSchemaPlace newCtlPlace = new CtlSchemaPlace("", null, CTLSchemaScopeDto.APPLICATION, place.getApplicationId(), true, true); + newCtlPlace.setSchemaType(getPlaceSchemaType()); + newCtlPlace.setPreviousPlace(place); + canceled = true; + goTo(newCtlPlace); } - }); - detailsView.getSchemaForm().setFormDataLoader(this); + })); + KaaAdmin.getDataSource().getAvailableApplicationCTLSchemaReferences(applicationId, + new BusyAsyncCallback>() { + @Override + public void onFailureImpl(Throwable caught) { + Utils.handleException(caught, detailsView); + } + @Override + public void onSuccessImpl(List result) { + detailsView.getCtlSchemaReference().setAcceptableValues(result); + bindDetailsView(true); + } + }); + detailsView.getSchemaForm().setFormDataLoader(this); } else { bindDetailsView(false); } } + protected abstract SchemaType getPlaceSchemaType(); + private void bindDetailsView(boolean fireChanged) { S schema = entity.getSchema(); String version = schema.getVersion() + ""; @@ -117,7 +123,9 @@ private void bindDetailsView(boolean fireChanged) { detailsView.getDescription().setValue(schema.getDescription()); detailsView.getCreatedUsername().setValue(schema.getCreatedUsername()); detailsView.getCreatedDateTime().setValue(Utils.millisecondsToDateTimeString(schema.getCreatedTime())); - detailsView.getSchemaForm().setValue(entity.getCtlSchemaForm().getSchema(), fireChanged); + if (entity.getCtlSchemaForm() != null) { + detailsView.getSchemaForm().setValue(entity.getCtlSchemaForm().getSchema(), fireChanged); + } } @Override @@ -149,10 +157,7 @@ protected void onSave() { entity.setUseExistingCtlSchema(detailsView.useExistingCtlSchema()); if (detailsView.useExistingCtlSchema()) { entity.setExistingMetaInfo(detailsView.getCtlSchemaReference().getValue()); - } else { - entity.getCtlSchemaForm().setSchema(detailsView.getSchemaForm().getValue()); - } - entity.getCtlSchemaForm().setApplicationId(applicationId); + } } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractDetailsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractDetailsActivity.java index ac058da3e7..825fe3ec46 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractDetailsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractDetailsActivity.java @@ -48,7 +48,7 @@ public abstract class AbstractDetailsActivity registrations = new ArrayList(); - private boolean canceled = false; + protected boolean canceled = false; public AbstractDetailsActivity(P place, ClientFactory clientFactory) { this.place = place; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractListActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractListActivity.java index a17daeb921..d98393b66c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractListActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AbstractListActivity.java @@ -46,9 +46,9 @@ public abstract class AbstractListActivity protected final ClientFactory clientFactory; private final Class dataClass; - private AbstractDataProvider dataProvider; + protected AbstractDataProvider dataProvider; - private List registrations = new ArrayList(); + protected List registrations = new ArrayList(); protected BaseListView listView; protected P place; @@ -70,7 +70,7 @@ public void start(AcceptsOneWidget containerWidget, EventBus eventBus) { protected abstract BaseListView getView(); - protected abstract AbstractDataProvider getDataProvider(AbstractGrid dataGrid); + protected abstract AbstractDataProvider getDataProvider(AbstractGrid dataGrid); protected abstract Place newEntityPlace(); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AefMapsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AefMapsActivity.java index 74c0514589..bf01a35d0f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AefMapsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AefMapsActivity.java @@ -43,8 +43,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new AefMapsDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AppActivityMapper.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AppActivityMapper.java index d5e31dc881..e051439a5f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AppActivityMapper.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/AppActivityMapper.java @@ -19,6 +19,7 @@ import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; import org.kaaproject.kaa.server.admin.client.mvp.place.AefMapPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.AefMapsPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.ApplicationCtlSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ApplicationPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ApplicationsPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ConfigurationPlace; @@ -49,6 +50,7 @@ import org.kaaproject.kaa.server.admin.client.mvp.place.SendNotificationPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ServerProfileSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ServerProfileSchemasPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.SystemCtlSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantCtlSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantsPlace; @@ -161,8 +163,12 @@ public Activity getActivity(Place place) { return new UserVerifierActivity((UserVerifierPlace) place, clientFactory); } else if (clazz == UpdateUserConfigPlace.class) { return new UpdateUserConfigActivity((UpdateUserConfigPlace) place, clientFactory); + } else if (clazz == SystemCtlSchemasPlace.class) { + return new SystemCtlSchemasActivity((SystemCtlSchemasPlace) place, clientFactory); } else if (clazz == TenantCtlSchemasPlace.class) { return new TenantCtlSchemasActivity((TenantCtlSchemasPlace) place, clientFactory); + } else if (clazz == ApplicationCtlSchemasPlace.class) { + return new ApplicationCtlSchemasActivity((ApplicationCtlSchemasPlace) place, clientFactory); } else if (clazz == CtlSchemaPlace.class) { return new CtlSchemaActivity((CtlSchemaPlace) place, clientFactory); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationCtlSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationCtlSchemasActivity.java new file mode 100644 index 0000000000..bec74781be --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationCtlSchemasActivity.java @@ -0,0 +1,67 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.activity; + +import java.util.Collections; + +import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; +import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; +import org.kaaproject.kaa.server.admin.client.mvp.data.ApplicationCtlSchemasDataProvider; +import org.kaaproject.kaa.server.admin.client.mvp.place.ApplicationCtlSchemasPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; + +import com.google.gwt.place.shared.Place; + +public class ApplicationCtlSchemasActivity extends CtlSchemasActivity { + + public ApplicationCtlSchemasActivity(ApplicationCtlSchemasPlace place, ClientFactory clientFactory) { + super(place, CTLSchemaMetaInfoDto.class, clientFactory); + } + + @Override + protected CtlSchemasView getView() { + return clientFactory.getApplicationCtlSchemasView(); + } + + @Override + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { + return new ApplicationCtlSchemasDataProvider(dataGrid, listView, place.getApplicationId()); + } + + @Override + protected Place newEntityPlace() { + return new CtlSchemaPlace("", null, getCurrentScope(), place.getApplicationId(), true, true); + } + + @Override + protected Place existingEntityPlace(String id) { + CTLSchemaMetaInfoDto schema = dataProvider.getRowData(id); + return new CtlSchemaPlace(id, Collections.max(schema.getVersions()), schema.getScope(), + place.getApplicationId(), schema.getScope() == getCurrentScope(), false); + } + + @Override + protected CTLSchemaScopeDto getCurrentScope() { + return CTLSchemaScopeDto.APPLICATION; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationsActivity.java index a6c766d2c2..b6fc8afd8b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ApplicationsActivity.java @@ -40,8 +40,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new ApplicationsDataProvider(dataGrid, listView); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ConfigurationSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ConfigurationSchemasActivity.java index c3a3140eb3..41c7bf4309 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ConfigurationSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ConfigurationSchemasActivity.java @@ -49,8 +49,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new ConfigurationSchemasDataProvider(dataGrid, listView, applicationId); } 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 9005a8e8a9..b8c2b9848a 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 @@ -16,6 +16,7 @@ package org.kaaproject.kaa.server.admin.client.mvp.activity; +import java.util.Collections; import java.util.List; import org.kaaproject.avro.ui.gwt.client.util.BusyAsyncCallback; @@ -23,10 +24,14 @@ import org.kaaproject.avro.ui.gwt.client.widget.dialog.ConfirmDialog; import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; 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.CtlSchemaPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace.SchemaType; +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; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel.FormDataLoader; import org.kaaproject.kaa.server.admin.client.servlet.ServletHelper; @@ -34,6 +39,8 @@ 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.ProfileSchemaViewDto; +import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -57,7 +64,7 @@ public CtlSchemaActivity(CtlSchemaPlace place, @Override protected String getEntityId(CtlSchemaPlace place) { - return place.getFqn(); + return place.isCreate() ? null : place.getMetaInfoId(); } @Override @@ -74,38 +81,60 @@ protected void bind(final EventBus eventBus) { @Override public void onValueChange(ValueChangeEvent event) { detailsView.getVersion().setValue(version); - goTo(new CtlSchemaPlace(place.getFqn(), event.getValue(), false)); + goTo(new CtlSchemaPlace(place.getMetaInfoId(), event.getValue(), place.getScope(), place.getApplicationId(), place.isEditable(), false)); } })); registrations.add(detailsView.getCreateNewSchemaVersionButton().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Integer version = detailsView.getVersion().getValue(); - CtlSchemaPlace newPlace = new CtlSchemaPlace(place.getFqn(), version, true); + CtlSchemaPlace newPlace = new CtlSchemaPlace(place.getMetaInfoId(), version, place.getScope(), place.getApplicationId(), true, true); newPlace.setPreviousPlace(place); goTo(newPlace); } })); + + registrations.add(detailsView.getUpdateSchemaScopeButton().addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + CTLSchemaMetaInfoDto metaInfo = entity.getMetaInfo(); + metaInfo.setApplicationId(null); + KaaAdmin.getDataSource().updateCtlSchemaScope(metaInfo, new BusyAsyncCallback() { + @Override + public void onFailureImpl(Throwable caught) { + Utils.handleException(caught, detailsView); + } + @Override + public void onSuccessImpl(CTLSchemaMetaInfoDto result) { + CtlSchemaPlace place = new CtlSchemaPlace(result.getId(), version, result.getScope(), + CtlSchemaActivity.this.place.getApplicationId(), result.getScope() == CTLSchemaScopeDto.APPLICATION, false); + goTo(place); + } + }); + } + })); + registrations.add(detailsView.getDeleteSchemaVersionButton().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { final Integer version = detailsView.getVersion().getValue(); - final String fqn = place.getFqn(); + final String fqn = entity.getMetaInfo().getFqn(); ConfirmDialog.ConfirmListener listener = new ConfirmDialog.ConfirmListener() { @Override public void onNo() {} @Override public void onYes() { - KaaAdmin.getDataSource().deleteCTLSchema(fqn, version, new BusyAsyncCallback() { + KaaAdmin.getDataSource().deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, + entity.getMetaInfo().getTenantId(), place.getApplicationId(), new BusyAsyncCallback() { @Override public void onSuccessImpl(Void result) { - List versions = entity.getAvailableVersions(); + List versions = entity.getMetaInfo().getVersions(); versions.remove(version); if (versions.isEmpty()) { goTo(place.getPreviousPlace()); } else { - goTo(new CtlSchemaPlace(place.getFqn(), versions.get(versions.size()-1), false)); + goTo(new CtlSchemaPlace(place.getMetaInfoId(), versions.get(versions.size()-1), place.getScope(), place.getApplicationId(), true, false)); } } @Override @@ -129,12 +158,15 @@ public void onFailureImpl(Throwable caught) { @Override protected void onEntityRetrieved() { if (create) { - KaaAdmin.getDataSource().createNewCTLSchemaFormInstance(place.getSourceFqn(), - place.getSourceVersion(), CTLSchemaScopeDto.TENANT, null, + KaaAdmin.getDataSource().createNewCTLSchemaFormInstance(place.getMetaInfoId(), + place.getVersion(), place.getApplicationId(), new BusyAsyncCallback() { @Override public void onSuccessImpl(CtlSchemaFormDto result) { entity = result; + if (place.getSchemaType() != null) { + entity.getSchema().setDisplayNameFieldOptional(false); + } bindDetailsView(true); } @Override @@ -153,7 +185,8 @@ public void onFailureImpl(Throwable caught) { private void bindDetailsView(boolean fireChanged) { if (!create) { - List schemaVersions = entity.getAvailableVersions(); + List schemaVersions = entity.getMetaInfo().getVersions(); + Collections.sort(schemaVersions); if (version == null && !schemaVersions.isEmpty()) { version = schemaVersions.get(schemaVersions.size()-1); @@ -162,28 +195,28 @@ private void bindDetailsView(boolean fireChanged) { detailsView.getVersion().setValue(version); } detailsView.getVersion().setAcceptableValues(schemaVersions); - detailsView.setTitle(entity.getFqnString()); + detailsView.setTitle(entity.getMetaInfo().getFqn()); + registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.shallow(), new ActionMenuItemListener() { + @Override + public void onMenuItemSelected() { + exportSchema(CTLSchemaExportMethod.SHALLOW); + } + })); if (entity.hasDependencies()) { - registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.shallow(), new ActionMenuItemListener() { + registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.deep(), new ActionMenuItemListener() { @Override public void onMenuItemSelected() { - exportSchema(CTLSchemaExportMethod.SHALLOW); + exportSchema(CTLSchemaExportMethod.DEEP); } })); - registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.deep(), new ActionMenuItemListener() { + registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.flat(), new ActionMenuItemListener() { @Override public void onMenuItemSelected() { - exportSchema(CTLSchemaExportMethod.DEEP); + exportSchema(CTLSchemaExportMethod.FLAT); } })); } - registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.flat(), new ActionMenuItemListener() { - @Override - public void onMenuItemSelected() { - exportSchema(CTLSchemaExportMethod.FLAT); - } - })); registrations.add(detailsView.getExportActionsButton().addMenuItem(Utils.constants.javaLibrary(), new ActionMenuItemListener() { @Override public void onMenuItemSelected() { @@ -191,8 +224,7 @@ public void onMenuItemSelected() { } })); } - detailsView.getName().setValue(entity.getSchemaName()); - detailsView.getDescription().setValue(entity.getDescription()); + detailsView.getScope().setText(Utils.getCtlScopeTitleString(entity.getMetaInfo().getScope())); detailsView.getCreatedUsername().setValue(entity.getCreatedUsername()); detailsView.getCreatedDateTime().setValue(Utils.millisecondsToDateTimeString(entity.getCreatedTime())); detailsView.getSchemaForm().setValue(entity.getSchema(), fireChanged); @@ -209,7 +241,7 @@ public void onSuccess(String key) { ServletHelper.exportCtlSchema(key); } }; - KaaAdmin.getDataSource().prepareCTLSchemaExport(entity.getCtlSchemaId(), method, schemaExportCallback); + KaaAdmin.getDataSource().prepareCTLSchemaExport(entity.getId(), method, schemaExportCallback); } @Override @@ -220,7 +252,13 @@ protected void doSave(final EventBus eventBus) { new BusyAsyncCallback() { public void onSuccessImpl(CtlSchemaFormDto result) { if (!create) { - goTo(new CtlSchemaPlace(place.getFqn(), place.getVersion(), false)); + goTo(new CtlSchemaPlace(place.getMetaInfoId(), place.getVersion(), place.getScope(), place.getApplicationId(), true, false)); + } else if (place.getSchemaType() != null) { + if (place.getSchemaType() == SchemaType.ENDPOINT_PROFILE) { + goTo(new ProfileSchemasPlace(place.getApplicationId())); + } else { + goTo(new ServerProfileSchemasPlace(place.getApplicationId())); + } } else if (place.getPreviousPlace() != null) { goTo(place.getPreviousPlace()); } @@ -234,8 +272,6 @@ public void onFailureImpl(Throwable caught) { @Override protected void onSave() { - entity.setSchemaName(detailsView.getName().getValue()); - entity.setDescription(detailsView.getDescription().getValue()); entity.setSchema(detailsView.getSchemaForm().getValue()); } @@ -250,8 +286,20 @@ public String customizeErrorMessage(Throwable caught) { @Override public void loadFormData(String fileItemName, - AsyncCallback callback) { - KaaAdmin.getDataSource().generateCtlSchemaForm(fileItemName, callback); + final AsyncCallback callback) { + KaaAdmin.getDataSource().generateCtlSchemaForm(fileItemName, place.getApplicationId(), new AsyncCallback() { + @Override + public void onSuccess(RecordField result) { + if (place.getSchemaType() != null) { + result.setDisplayNameFieldOptional(false); + } + callback.onSuccess(result); + } + @Override + public void onFailure(Throwable caught) { + callback.onFailure(caught); + } + }); } @Override @@ -259,20 +307,94 @@ protected CtlSchemaView getView(boolean create) { if (create) { return clientFactory.getCreateCtlSchemaView(); } else { - return clientFactory.getCtlSchemaView(); + if (place.isEditable()) { + if (place.getScope() == CTLSchemaScopeDto.APPLICATION) { + return clientFactory.getEditApplicationCtlSchemaView(); + } else { + return clientFactory.getEditCtlSchemaView(); + } + } else { + return clientFactory.getViewCtlSchemaView(); + } } } @Override protected void getEntity(String id, AsyncCallback callback) { - KaaAdmin.getDataSource().getCTLSchemaForm(id, place.getVersion(), callback); + if (version == null) { + KaaAdmin.getDataSource().getLatestCTLSchemaForm(id, callback); + } else { + KaaAdmin.getDataSource().getCTLSchemaFormByMetaInfoIdAndVer(id, version, callback); + } } @Override - protected void editEntity(CtlSchemaFormDto entity, - AsyncCallback callback) { - KaaAdmin.getDataSource().editCTLSchemaForm(entity, callback); + protected void editEntity(final CtlSchemaFormDto entity, + final AsyncCallback callback) { + if (place.getScope().getLevel() > CTLSchemaScopeDto.SYSTEM.getLevel()) { + KaaAdmin.getDataSource().checkFqnExists(entity, new BusyAsyncCallback() { + @Override + public void onFailureImpl(Throwable caught) { + Utils.handleException(caught, detailsView); + } + @Override + public void onSuccessImpl(Boolean result) { + if (!result) { + editSchema(entity, callback); + } else { + ConfirmDialog.ConfirmListener listener = new ConfirmDialog.ConfirmListener() { + @Override + public void onNo() { + } + + @Override + public void onYes() { + editSchema(entity, callback); + } + }; + ConfirmDialog dialog = new ConfirmDialog(listener, Utils.messages.commonTypeFqnAlreadyExistTitle(), + Utils.messages.commonTypeFqnAlreadyExistsQuestion()); + dialog.center(); + dialog.show(); + } + } + }); + } else { + editSchema(entity, callback); + } + } + + private void editSchema(CtlSchemaFormDto entity, final AsyncCallback callback) { + if (create && place.getSchemaType() != null) { + if (place.getSchemaType() == SchemaType.ENDPOINT_PROFILE) { + KaaAdmin.getDataSource().createProfileSchemaFormCtlSchema(entity, + new BusyAsyncCallback() { + @Override + public void onFailureImpl(Throwable caught) { + callback.onFailure(caught); + } + @Override + public void onSuccessImpl(ProfileSchemaViewDto result) { + callback.onSuccess(null); + } + }); + } else { + KaaAdmin.getDataSource().createServerProfileSchemaFormCtlSchema(entity, + new BusyAsyncCallback() { + @Override + public void onFailureImpl(Throwable caught) { + callback.onFailure(caught); + } + @Override + public void onSuccessImpl(ServerProfileSchemaViewDto result) { + 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/CtlSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemasActivity.java new file mode 100644 index 0000000000..69d3d05e02 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemasActivity.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.activity; + +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; +import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.DataFilter; +import org.kaaproject.kaa.server.admin.client.mvp.place.TreePlace; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; + +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.event.shared.EventBus; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public abstract class CtlSchemasActivity

extends AbstractListActivity { + + public CtlSchemasActivity(P place, Class dataClass, ClientFactory clientFactory) { + super(place, dataClass, clientFactory); + } + + protected abstract CtlSchemasView getView(); + + private CtlSchemasView ctlSchemaView() { + return (CtlSchemasView) listView; + } + + @Override + public void bind(final EventBus eventBus) { + super.bind(eventBus); + if (ctlSchemaView().displayShowHigherLevelScopeCheckBox()) { + DataFilter dataFilter = new DataFilter() { + @Override + public boolean accept(CTLSchemaMetaInfoDto value) { + return ctlSchemaView().getShowHigherScopeCheckBox().getValue() + || value.getScope() == getCurrentScope(); + } + }; + dataProvider.setDataFilter(dataFilter); + registrations.add(ctlSchemaView().getShowHigherScopeCheckBox().addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent event) { + dataProvider.updateData(); + } + })); + } + } + + @Override + protected void deleteEntity(String id, AsyncCallback callback) { + callback.onSuccess((Void) null); + } + + protected abstract CTLSchemaScopeDto getCurrentScope(); + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfsActivity.java index d90694797f..573947199e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfsActivity.java @@ -40,8 +40,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new EcfsDataProvider(dataGrid, listView); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointGroupsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointGroupsActivity.java index eead910111..fad24acc30 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointGroupsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EndpointGroupsActivity.java @@ -44,8 +44,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new EndpointGroupsDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogAppendersActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogAppendersActivity.java index a948f1ba61..a30a9f117e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogAppendersActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogAppendersActivity.java @@ -54,7 +54,7 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { return new AppendersDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogSchemasActivity.java index 8a5bbd4386..69ace1cfe0 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/LogSchemasActivity.java @@ -49,8 +49,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new LogSchemasDataProvider(dataGrid, listView, applicationId); } 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 99a9bd89b4..cdcfb045f4 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 @@ -50,8 +50,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new NotificationSchemasDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemaActivity.java index 29ef933f5c..3ce95e30e2 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemaActivity.java @@ -18,9 +18,9 @@ import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; 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.CtlSchemaPlace.SchemaType; import org.kaaproject.kaa.server.admin.client.mvp.place.ProfileSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; @@ -66,8 +66,7 @@ protected void editEntity(ProfileSchemaViewDto entity, @Override protected void createEmptyCtlSchemaForm(AsyncCallback callback) { KaaAdmin.getDataSource().createNewCTLSchemaFormInstance(null, - null, - CTLSchemaScopeDto.PROFILE_SCHEMA, + null, applicationId, callback); } @@ -84,4 +83,9 @@ protected ProfileSchemaPlace existingSchemaPlace( return new ProfileSchemaPlace(applicationId, schemaId); } + @Override + protected SchemaType getPlaceSchemaType() { + return SchemaType.ENDPOINT_PROFILE; + } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemasActivity.java index 1647bb6b77..6e3304958b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ProfileSchemasActivity.java @@ -42,8 +42,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new ProfileSchemasDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SdkProfilesActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SdkProfilesActivity.java index d7c7594a3a..e29a5abda3 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SdkProfilesActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SdkProfilesActivity.java @@ -57,7 +57,7 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { return new SdkProfilesDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemaActivity.java index 9724058cb6..e6383dce50 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemaActivity.java @@ -18,9 +18,9 @@ import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; 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.CtlSchemaPlace.SchemaType; import org.kaaproject.kaa.server.admin.client.mvp.place.ServerProfileSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; @@ -67,7 +67,6 @@ protected void editEntity(ServerProfileSchemaViewDto entity, protected void createEmptyCtlSchemaForm(AsyncCallback callback) { KaaAdmin.getDataSource().createNewCTLSchemaFormInstance(null, null, - CTLSchemaScopeDto.SERVER_PROFILE_SCHEMA, applicationId, callback); } @@ -84,4 +83,9 @@ protected ServerProfileSchemaPlace existingSchemaPlace( return new ServerProfileSchemaPlace(applicationId, schemaId); } + @Override + protected SchemaType getPlaceSchemaType() { + return SchemaType.SERVER_PROFILE; + } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemasActivity.java index c85f9d7ab0..3b15bd21a7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/ServerProfileSchemasActivity.java @@ -42,8 +42,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new ServerProfileSchemasDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SystemCtlSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SystemCtlSchemasActivity.java new file mode 100644 index 0000000000..399a958b59 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/SystemCtlSchemasActivity.java @@ -0,0 +1,67 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.activity; + +import java.util.Collections; + +import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; +import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; +import org.kaaproject.kaa.server.admin.client.mvp.data.SystemCtlSchemasDataProvider; +import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.SystemCtlSchemasPlace; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; + +import com.google.gwt.place.shared.Place; + +public class SystemCtlSchemasActivity extends CtlSchemasActivity { + + public SystemCtlSchemasActivity(SystemCtlSchemasPlace place, ClientFactory clientFactory) { + super(place, CTLSchemaMetaInfoDto.class, clientFactory); + } + + @Override + protected CtlSchemasView getView() { + return clientFactory.getSystemCtlSchemasView(); + } + + @Override + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { + return new SystemCtlSchemasDataProvider(dataGrid, listView); + } + + @Override + protected Place newEntityPlace() { + return new CtlSchemaPlace("", null, getCurrentScope(), null, true, true); + } + + @Override + protected Place existingEntityPlace(String id) { + CTLSchemaMetaInfoDto schema = dataProvider.getRowData(id); + return new CtlSchemaPlace(id, Collections.max(schema.getVersions()), schema.getScope(), null, + schema.getScope() == getCurrentScope(), false); + } + + @Override + protected CTLSchemaScopeDto getCurrentScope() { + return CTLSchemaScopeDto.SYSTEM; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantCtlSchemasActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantCtlSchemasActivity.java index 36f2552193..f9b8c9167a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantCtlSchemasActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantCtlSchemasActivity.java @@ -16,48 +16,52 @@ package org.kaaproject.kaa.server.admin.client.mvp.activity; +import java.util.Collections; + import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.admin.client.mvp.ClientFactory; import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; import org.kaaproject.kaa.server.admin.client.mvp.data.TenantCtlSchemasDataProvider; import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantCtlSchemasPlace; -import org.kaaproject.kaa.server.admin.client.mvp.view.BaseListView; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; import com.google.gwt.place.shared.Place; -import com.google.gwt.user.client.rpc.AsyncCallback; -public class TenantCtlSchemasActivity extends AbstractListActivity { +public class TenantCtlSchemasActivity extends CtlSchemasActivity { public TenantCtlSchemasActivity(TenantCtlSchemasPlace place, ClientFactory clientFactory) { - super(place, SchemaFqnDto.class, clientFactory); + super(place, CTLSchemaMetaInfoDto.class, clientFactory); } @Override - protected BaseListView getView() { - return clientFactory.getCtlSchemasView(); + protected CtlSchemasView getView() { + return clientFactory.getTenantCtlSchemasView(); } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new TenantCtlSchemasDataProvider(dataGrid, listView); } @Override protected Place newEntityPlace() { - return new CtlSchemaPlace("", null, true); + return new CtlSchemaPlace("", null, getCurrentScope(), null, true, true); } @Override protected Place existingEntityPlace(String id) { - return new CtlSchemaPlace(id, null, false); + CTLSchemaMetaInfoDto schema = dataProvider.getRowData(id); + return new CtlSchemaPlace(id, Collections.max(schema.getVersions()), schema.getScope(), null, + schema.getScope() == getCurrentScope(), false); } @Override - protected void deleteEntity(String id, AsyncCallback callback) { - callback.onSuccess((Void) null); + protected CTLSchemaScopeDto getCurrentScope() { + return CTLSchemaScopeDto.TENANT; } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantsActivity.java index bba4c01b07..4c09557f94 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TenantsActivity.java @@ -42,8 +42,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new TenantsDataProvider(dataGrid, listView); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TopicsActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TopicsActivity.java index cdd0043688..25f3e2486c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TopicsActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/TopicsActivity.java @@ -47,8 +47,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new TopicsDataProvider(dataGrid, listView, applicationId, null); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UserVerifiersActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UserVerifiersActivity.java index 2687c98e7e..bfe5b2becb 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UserVerifiersActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UserVerifiersActivity.java @@ -50,7 +50,7 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider(AbstractGrid dataGrid) { return new UserVerifiersDataProvider(dataGrid, listView, applicationId); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UsersActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UsersActivity.java index a852d02e1c..072f4f6895 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UsersActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/UsersActivity.java @@ -41,8 +41,8 @@ protected BaseListView getView() { } @Override - protected AbstractDataProvider getDataProvider( - AbstractGrid dataGrid) { + protected AbstractDataProvider getDataProvider( + AbstractGrid dataGrid) { return new UsersDataProvider(dataGrid, listView); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/AbstractDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/AbstractDataProvider.java index 63156ea253..1ee74b6641 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/AbstractDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/AbstractDataProvider.java @@ -16,8 +16,11 @@ package org.kaaproject.kaa.server.admin.client.mvp.activity.grid; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; import org.kaaproject.avro.ui.gwt.client.widget.grid.ColumnFilterEvent; @@ -31,22 +34,26 @@ import com.google.gwt.view.client.AsyncDataProvider; import com.google.gwt.view.client.HasData; -public abstract class AbstractDataProvider extends AsyncDataProvider implements ColumnSortEvent.Handler, ColumnFilterEvent.Handler { +public abstract class AbstractDataProvider extends AsyncDataProvider implements ColumnSortEvent.Handler, ColumnFilterEvent.Handler { protected List data; + + private Map dataMap = new HashMap<>(); private boolean loaded = false; private LoadCallback callback; - private AbstractGrid dataGrid; + private AbstractGrid dataGrid; + + private DataFilter dataFilter; - public AbstractDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) + public AbstractDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { this(dataGrid, hasErrorMessage, true); } - public AbstractDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, boolean addDisplay) + public AbstractDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, boolean addDisplay) { this.dataGrid = dataGrid; callback = new LoadCallback(hasErrorMessage); @@ -60,9 +67,19 @@ public AbstractDataProvider(AbstractGrid dataGrid, HasErrorMessage hasError protected void addDataDisplay() { addDataDisplay(dataGrid.getDataGrid()); } + + @SuppressWarnings("unchecked") + private K getObjectId(T value) { + return (K) dataGrid.getDataGrid().getKeyProvider().getKey(value); + } + + public void setDataFilter(DataFilter dataFilter) { + this.dataFilter = dataFilter; + } public void addRow(T row) { data.add(row); + dataMap.put(getObjectId(row), row); updateRowCount(data.size(), true); updateRowData(data.size()-1, data.subList(data.size()-1, data.size())); } @@ -75,6 +92,10 @@ public void updateRow(T row) { public List getData() { return data; } + + public T getRowData(K key) { + return dataMap.get(key); + } public void setLoaded(boolean loaded) { this.loaded = loaded; @@ -105,11 +126,19 @@ public void onColumnSort(ColumnSortEvent event) { @Override public void onColumnFilter(ColumnFilterEvent event) { updateData(); - } - + } - private void updateData () { + public void updateData () { List filteredData = dataGrid.filter(data); + if (dataFilter != null) { + List newFilteredData = new ArrayList<>(); + for (T value : filteredData) { + if (dataFilter.accept(value)) { + newFilteredData.add(value); + } + } + filteredData = newFilteredData; + } updateRowCount(filteredData.size(), true); ColumnSortList sortList = dataGrid.getDataGrid().getColumnSortList(); Column column = (sortList == null || sortList.size() == 0) ? null @@ -141,9 +170,14 @@ public void onSuccess(List result) { if (data == null) { data = Collections.emptyList(); } + dataMap.clear(); + for (T row : data) { + dataMap.put(getObjectId(row), row); + } updateData(); loaded = true; hasErrorMessage.clearError(); } } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/DataFilter.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/DataFilter.java new file mode 100644 index 0000000000..938ec5d803 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/grid/DataFilter.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.activity.grid; + +public interface DataFilter { + + boolean accept(T value); + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AefMapsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AefMapsDataProvider.java index 9262a11b97..f517b9a0a3 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AefMapsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AefMapsDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class AefMapsDataProvider extends AbstractDataProvider{ +public class AefMapsDataProvider extends AbstractDataProvider{ private String applicationId; - public AefMapsDataProvider(AbstractGrid dataGrid, + public AefMapsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AppendersDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AppendersDataProvider.java index feac75fb45..fe81a57c84 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AppendersDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/AppendersDataProvider.java @@ -28,10 +28,10 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class AppendersDataProvider extends AbstractDataProvider{ +public class AppendersDataProvider extends AbstractDataProvider{ private String applicationId; - public AppendersDataProvider(AbstractGrid dataGrid, + public AppendersDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationCtlSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationCtlSchemasDataProvider.java new file mode 100644 index 0000000000..524c1a2b91 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationCtlSchemasDataProvider.java @@ -0,0 +1,61 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.data; + +import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty; + +import java.util.List; + +import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.server.admin.client.KaaAdmin; +import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; +import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +public class ApplicationCtlSchemasDataProvider extends AbstractDataProvider{ + + private String applicationId; + + public ApplicationCtlSchemasDataProvider(AbstractGrid dataGrid, + HasErrorMessage hasErrorMessage, + String applicationId) { + super(dataGrid, hasErrorMessage, false); + this.applicationId = applicationId; + addDataDisplay(); + } + + @Override + protected void loadData(final LoadCallback callback) { + if (!isEmpty(applicationId)) { + KaaAdmin.getDataSource().getApplicationLevelCTLSchemas(applicationId, + new AsyncCallback>() { + @Override + public void onFailure(Throwable caught) { + callback.onFailure(caught); + + } + @Override + public void onSuccess(List result) { + callback.onSuccess(result); + } + }); + } + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationsDataProvider.java index 6e8de4d354..8d181b5c4c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ApplicationsDataProvider.java @@ -26,9 +26,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class ApplicationsDataProvider extends AbstractDataProvider{ +public class ApplicationsDataProvider extends AbstractDataProvider{ - public ApplicationsDataProvider(AbstractGrid dataGrid, + public ApplicationsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationSchemasDataProvider.java index ff13f92aed..49d640332b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationSchemasDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class ConfigurationSchemasDataProvider extends AbstractDataProvider{ +public class ConfigurationSchemasDataProvider extends AbstractDataProvider{ private String applicationId; - public ConfigurationSchemasDataProvider(AbstractGrid dataGrid, + public ConfigurationSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationsDataProvider.java index de128cd8c7..d7c42f51b9 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ConfigurationsDataProvider.java @@ -23,15 +23,16 @@ import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; +import org.kaaproject.kaa.server.admin.shared.config.ConfigRecordKey; import com.google.gwt.user.client.rpc.AsyncCallback; -public class ConfigurationsDataProvider extends AbstractDataProvider{ +public class ConfigurationsDataProvider extends AbstractDataProvider{ private String endpointGroupId; private boolean includeDeprecated = false; - public ConfigurationsDataProvider(AbstractGrid dataGrid, + public ConfigurationsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String endpointGroupId, boolean includeDeprecated) { super(dataGrid, hasErrorMessage, false); 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 8521c7882d..03e1aa3556 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 @@ -46,7 +46,6 @@ import org.kaaproject.kaa.common.dto.admin.UserDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.EcfInfoDto; @@ -64,8 +63,8 @@ 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.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.SchemaFqnDto; 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; @@ -529,6 +528,17 @@ protected void onResult(ProfileSchemaViewDto result) { } }); } + + public void createProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm, + final AsyncCallback callback) { + rpcService.createProfileSchemaFormCtlSchema(ctlSchemaForm, + new DataCallback(callback) { + @Override + protected void onResult(ProfileSchemaViewDto result) { + eventBus.fireEvent(new DataEvent(EndpointProfileSchemaDto.class)); + } + }); + } public void getProfileSchemaView(String profileSchemaId, final AsyncCallback callback) { @@ -591,6 +601,17 @@ protected void onResult(ServerProfileSchemaViewDto result) { }); } + public void createServerProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm, + final AsyncCallback callback) { + rpcService.createServerProfileSchemaFormCtlSchema(ctlSchemaForm, + new DataCallback(callback) { + @Override + protected void onResult(ServerProfileSchemaViewDto result) { + eventBus.fireEvent(new DataEvent(ServerProfileSchemaViewDto.class)); + } + }); + } + public void getEndpointProfileSchemaInfo(String endpointProfileSchemaId, final AsyncCallback callback) { rpcService.getEndpointProfileSchemaInfo(endpointProfileSchemaId, @@ -622,11 +643,12 @@ protected void onResult(Boolean result) { }); } - public void getAvailableCtlSchemaReferences(final AsyncCallback> callback) { - rpcService.getAvailableTenantCTLSchemaReferences( - new DataCallback>(callback) { + public void getAvailableApplicationCTLSchemaReferences(String applicationId, + final AsyncCallback> callback) { + rpcService.getAvailableApplicationCTLSchemaReferences(applicationId, + new DataCallback>(callback) { @Override - protected void onResult(List result) { + protected void onResult(List result) { } }); } @@ -741,19 +763,49 @@ protected void onResult(LogSchemaDto result) { }); } - public void getTenantCTLSchemaFqns( - final AsyncCallback> callback) { - rpcService.getTenantCTLSchemaFqns( - new DataCallback>(callback) { + public void getSystemLevelCTLSchemas( + final AsyncCallback> callback) { + rpcService.getSystemLevelCTLSchemas( + new DataCallback>(callback) { + @Override + protected void onResult(List result) { + } + }); + } + + public void getTenantLevelCTLSchemas( + final AsyncCallback> callback) { + rpcService.getTenantLevelCTLSchemas( + new DataCallback>(callback) { + @Override + protected void onResult(List result) { + } + }); + } + + public void getApplicationLevelCTLSchemas(String applicationId, + final AsyncCallback> callback) { + rpcService.getApplicationLevelCTLSchemas(applicationId, + new DataCallback>(callback) { + @Override + protected void onResult(List result) { + } + }); + } + + public void getLatestCTLSchemaForm(String metaInfoId, + final AsyncCallback callback) { + rpcService.getLatestCTLSchemaForm(metaInfoId, + new DataCallback(callback) { @Override - protected void onResult(List result) { + protected void onResult(CtlSchemaFormDto result) { } }); } - public void getCTLSchemaForm(String fqn, Integer version, + public void getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, Integer version, final AsyncCallback callback) { - rpcService.getCTLSchemaForm(fqn, version, + rpcService.getCTLSchemaFormByMetaInfoIdAndVer(metaInfoId, version, new DataCallback(callback) { @Override protected void onResult(CtlSchemaFormDto result) { @@ -761,10 +813,10 @@ protected void onResult(CtlSchemaFormDto result) { }); } - public void createNewCTLSchemaFormInstance(String sourceFqn, Integer sourceVersion, CTLSchemaScopeDto scope, + public void createNewCTLSchemaFormInstance(String metaInfoId, Integer sourceVersion, String applicationId, final AsyncCallback callback) { - rpcService.createNewCTLSchemaFormInstance(sourceFqn, sourceVersion, scope, applicationId, + rpcService.createNewCTLSchemaFormInstance(metaInfoId, sourceVersion, applicationId, new DataCallback(callback) { @Override protected void onResult(CtlSchemaFormDto result) { @@ -772,9 +824,9 @@ protected void onResult(CtlSchemaFormDto result) { }); } - public void generateCtlSchemaForm(String fileItemName, + public void generateCtlSchemaForm(String fileItemName, String applicationId, final AsyncCallback callback) { - rpcService.generateCtlSchemaForm(fileItemName, + rpcService.generateCtlSchemaForm(fileItemName, applicationId, new DataCallback(callback) { @Override protected void onResult(RecordField result) { @@ -788,18 +840,41 @@ public void editCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, new DataCallback(callback) { @Override protected void onResult(CtlSchemaFormDto result) { - eventBus.fireEvent(new DataEvent(SchemaFqnDto.class)); + eventBus.fireEvent(new DataEvent(CTLSchemaMetaInfoDto.class)); + } + }); + } + + public void checkFqnExists(CtlSchemaFormDto ctlSchemaForm, + final AsyncCallback callback) { + rpcService.checkFqnExists(ctlSchemaForm, + new DataCallback(callback) { + @Override + protected void onResult(Boolean result) { + } + }); + } + + public void updateCtlSchemaScope(CTLSchemaMetaInfoDto metaInfo, + final AsyncCallback callback) { + rpcService.updateCTLSchemaMetaInfoScope(metaInfo, + new DataCallback(callback) { + @Override + protected void onResult(CTLSchemaMetaInfoDto result) { + eventBus.fireEvent(new DataEvent(CTLSchemaMetaInfoDto.class)); } }); } - public void deleteCTLSchema(String fqn, Integer version, + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, + String tenantId, String applicationId, final AsyncCallback callback) { - rpcService.deleteCTLSchemaByFqnAndVersion(fqn, version, + rpcService.deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, + tenantId, applicationId, new DataCallback(callback) { @Override protected void onResult(Void result) { - eventBus.fireEvent(new DataEvent(SchemaFqnDto.class)); + eventBus.fireEvent(new DataEvent(CTLSchemaMetaInfoDto.class)); } }); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfSchemasDataProvider.java index 1364a3f013..05814d6fb7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfSchemasDataProvider.java @@ -26,11 +26,11 @@ import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; -public class EcfSchemasDataProvider extends AbstractDataProvider{ +public class EcfSchemasDataProvider extends AbstractDataProvider{ private List schemas = new ArrayList<>(); - public EcfSchemasDataProvider(AbstractGrid dataGrid, + public EcfSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfsDataProvider.java index 3124f56c42..96d7f1f0eb 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EcfsDataProvider.java @@ -26,9 +26,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class EcfsDataProvider extends AbstractDataProvider{ +public class EcfsDataProvider extends AbstractDataProvider{ - public EcfsDataProvider(AbstractGrid dataGrid, + public EcfsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointGroupsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointGroupsDataProvider.java index 1b27415c9d..7049dcb359 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointGroupsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointGroupsDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class EndpointGroupsDataProvider extends AbstractDataProvider{ +public class EndpointGroupsDataProvider extends AbstractDataProvider{ private String applicationId; - public EndpointGroupsDataProvider(AbstractGrid dataGrid, + public EndpointGroupsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointProfileDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointProfileDataProvider.java index 35ac99da46..169f401933 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointProfileDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EndpointProfileDataProvider.java @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.List; -public class EndpointProfileDataProvider extends AbstractDataProvider { +public class EndpointProfileDataProvider extends AbstractDataProvider { public static final String DEFAULT_OFFSET = "0"; private String limit = "20"; // took from AbstractGrid<...>.class see AvroUI @@ -42,7 +42,7 @@ public class EndpointProfileDataProvider extends AbstractDataProvider dataGrid, HasErrorMessage hasErrorMessage) { + private EndpointProfileDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage, true); this.groupID = ""; endpointProfilesList = new ArrayList<>(); @@ -96,7 +96,7 @@ private void reset() { offset = DEFAULT_OFFSET; } - public static synchronized EndpointProfileDataProvider getInstance(AbstractGrid dataGrid, + public static synchronized EndpointProfileDataProvider getInstance(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { if (instance == null) { instance = new EndpointProfileDataProvider(dataGrid, hasErrorMessage); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EventMapDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EventMapDataProvider.java index 946ee32f4c..57745ae3ec 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EventMapDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/EventMapDataProvider.java @@ -32,12 +32,12 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class EventMapDataProvider extends AbstractDataProvider{ +public class EventMapDataProvider extends AbstractDataProvider{ private EcfInfoDto ecf; private List eventMaps; - public EventMapDataProvider(AbstractGrid dataGrid, + public EventMapDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/LogSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/LogSchemasDataProvider.java index 5096eacb01..26c5057f05 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/LogSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/LogSchemasDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class LogSchemasDataProvider extends AbstractDataProvider{ +public class LogSchemasDataProvider extends AbstractDataProvider{ private String applicationId; - - public LogSchemasDataProvider(AbstractGrid dataGrid, + + public LogSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/NotificationSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/NotificationSchemasDataProvider.java index 35621978a4..116d100421 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/NotificationSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/NotificationSchemasDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class NotificationSchemasDataProvider extends AbstractDataProvider{ +public class NotificationSchemasDataProvider extends AbstractDataProvider{ private String applicationId; - public NotificationSchemasDataProvider(AbstractGrid dataGrid, + public NotificationSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileFiltersDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileFiltersDataProvider.java index a8e6cb98ba..45ca302f36 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileFiltersDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileFiltersDataProvider.java @@ -23,15 +23,16 @@ import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; +import org.kaaproject.kaa.server.admin.shared.profile.ProfileFilterRecordKey; import com.google.gwt.user.client.rpc.AsyncCallback; -public class ProfileFiltersDataProvider extends AbstractDataProvider{ +public class ProfileFiltersDataProvider extends AbstractDataProvider{ private String endpointGroupId; private boolean includeDeprecated = false; - public ProfileFiltersDataProvider(AbstractGrid dataGrid, + public ProfileFiltersDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String endpointGroupId, boolean includeDeprecated) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileSchemasDataProvider.java index 9ca56e083b..8af6a4d756 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ProfileSchemasDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class ProfileSchemasDataProvider extends AbstractDataProvider{ +public class ProfileSchemasDataProvider extends AbstractDataProvider{ private String applicationId; - public ProfileSchemasDataProvider(AbstractGrid dataGrid, + public ProfileSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SdkProfilesDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SdkProfilesDataProvider.java index 3e4d7cbe7a..07364d0874 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SdkProfilesDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SdkProfilesDataProvider.java @@ -32,11 +32,11 @@ * * @since v0.8.0 */ -public class SdkProfilesDataProvider extends AbstractDataProvider { +public class SdkProfilesDataProvider extends AbstractDataProvider { private final String applicationId; - public SdkProfilesDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { + public SdkProfilesDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); this.applicationId = applicationId; this.addDataDisplay(); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ServerProfileSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ServerProfileSchemasDataProvider.java index 66f2b7aed0..d801294f57 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ServerProfileSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/ServerProfileSchemasDataProvider.java @@ -26,11 +26,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class ServerProfileSchemasDataProvider extends AbstractDataProvider { +public class ServerProfileSchemasDataProvider extends AbstractDataProvider { private String applicationId; - public ServerProfileSchemasDataProvider(AbstractGrid dataGrid, + public ServerProfileSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SystemCtlSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SystemCtlSchemasDataProvider.java new file mode 100644 index 0000000000..e5be77f952 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/SystemCtlSchemasDataProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.data; + +import java.util.List; + +import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.server.admin.client.KaaAdmin; +import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; +import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +public class SystemCtlSchemasDataProvider extends AbstractDataProvider{ + + public SystemCtlSchemasDataProvider(AbstractGrid dataGrid, + HasErrorMessage hasErrorMessage) { + super(dataGrid, hasErrorMessage); + } + + @Override + protected void loadData(final LoadCallback callback) { + KaaAdmin.getDataSource().getSystemLevelCTLSchemas(new AsyncCallback>() { + @Override + public void onFailure(Throwable caught) { + callback.onFailure(caught); + + } + @Override + public void onSuccess(List result) { + callback.onSuccess(result); + } + }); + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantCtlSchemasDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantCtlSchemasDataProvider.java index 077932f61b..2803578af6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantCtlSchemasDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantCtlSchemasDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 CyberVision, Inc. + * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,30 +19,30 @@ import java.util.List; import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.mvp.activity.grid.AbstractDataProvider; import org.kaaproject.kaa.server.admin.client.util.HasErrorMessage; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; import com.google.gwt.user.client.rpc.AsyncCallback; -public class TenantCtlSchemasDataProvider extends AbstractDataProvider{ +public class TenantCtlSchemasDataProvider extends AbstractDataProvider{ - public TenantCtlSchemasDataProvider(AbstractGrid dataGrid, + public TenantCtlSchemasDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } @Override protected void loadData(final LoadCallback callback) { - KaaAdmin.getDataSource().getTenantCTLSchemaFqns(new AsyncCallback>() { + KaaAdmin.getDataSource().getTenantLevelCTLSchemas(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } @Override - public void onSuccess(List result) { + public void onSuccess(List result) { callback.onSuccess(result); } }); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantsDataProvider.java index 089fcd95ac..648e67683f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TenantsDataProvider.java @@ -26,9 +26,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class TenantsDataProvider extends AbstractDataProvider{ +public class TenantsDataProvider extends AbstractDataProvider{ - public TenantsDataProvider(AbstractGrid dataGrid, + public TenantsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TopicsDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TopicsDataProvider.java index 2667541b09..39b0b422e0 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TopicsDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/TopicsDataProvider.java @@ -28,12 +28,12 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class TopicsDataProvider extends AbstractDataProvider{ +public class TopicsDataProvider extends AbstractDataProvider{ private String applicationId; private String endpointGroupId; - public TopicsDataProvider(AbstractGrid dataGrid, + public TopicsDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId, String endpointGroupId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UserVerifiersDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UserVerifiersDataProvider.java index 6195eae513..0d33e3db85 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UserVerifiersDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UserVerifiersDataProvider.java @@ -27,10 +27,10 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class UserVerifiersDataProvider extends AbstractDataProvider{ +public class UserVerifiersDataProvider extends AbstractDataProvider{ private String applicationId; - public UserVerifiersDataProvider(AbstractGrid dataGrid, + public UserVerifiersDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage, String applicationId) { super(dataGrid, hasErrorMessage, false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UsersDataProvider.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UsersDataProvider.java index 6778a29f86..20e0d3addf 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UsersDataProvider.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/UsersDataProvider.java @@ -26,9 +26,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -public class UsersDataProvider extends AbstractDataProvider{ +public class UsersDataProvider extends AbstractDataProvider{ - public UsersDataProvider(AbstractGrid dataGrid, + public UsersDataProvider(AbstractGrid dataGrid, HasErrorMessage hasErrorMessage) { super(dataGrid, hasErrorMessage); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java new file mode 100644 index 0000000000..8a17d9b783 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java @@ -0,0 +1,85 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.place; + +import org.kaaproject.kaa.server.admin.client.util.Utils; + +import com.google.gwt.place.shared.PlaceTokenizer; +import com.google.gwt.place.shared.Prefix; + +public class ApplicationCtlSchemasPlace extends TreePlace { + + protected String applicationId; + + public ApplicationCtlSchemasPlace(String applicationId) { + this.applicationId = applicationId; + } + + public String getApplicationId() { + return applicationId; + } + + @Override + public String getName() { + return Utils.constants.applicationCtl(); + } + + @Prefix(value = "appCtlSchemas") + public static class Tokenizer implements PlaceTokenizer, PlaceConstants { + + @Override + public ApplicationCtlSchemasPlace getPlace(String token) { + PlaceParams.paramsFromToken(token); + return new ApplicationCtlSchemasPlace(PlaceParams.getParam(APPLICATION_ID)); + } + + @Override + public String getToken(ApplicationCtlSchemasPlace place) { + PlaceParams.clear(); + PlaceParams.putParam(APPLICATION_ID, place.getApplicationId()); + return PlaceParams.generateToken(); + } + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ApplicationCtlSchemasPlace other = (ApplicationCtlSchemasPlace) obj; + if (applicationId == null) { + if (other.applicationId != null) + return false; + } else if (!applicationId.equals(other.applicationId)) + return false; + return true; + } + + @Override + public boolean isLeaf() { + return true; + } + + @Override + public TreePlace createDefaultPreviousPlace() { + return new ApplicationPlace(applicationId); + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java index 8ab21cb547..757445f807 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java @@ -113,6 +113,7 @@ protected void loadData(LoadCallback callback, result.add(new UserVerifiersPlace(applicationId)); result.add(new EndpointUsersPlace(applicationId)); result.add(new EndpointProfilesPlace(applicationId)); + result.add(new ApplicationCtlSchemasPlace(applicationId)); callback.onSuccess(result, display); } 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 fe6d6400c0..354af05cd8 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 @@ -16,6 +16,9 @@ package org.kaaproject.kaa.server.admin.client.mvp.place; +import org.kaaproject.kaa.common.dto.KaaAuthorityDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.util.Utils; import com.google.gwt.place.shared.PlaceTokenizer; @@ -23,35 +26,58 @@ public class CtlSchemaPlace extends TreePlace { - private String fqn; + private String metaInfoId; private Integer version; - private String sourceFqn; - private Integer sourceVersion; - - public CtlSchemaPlace(String fqn, Integer version, boolean create) { - if (create) { - this.sourceFqn = fqn; - this.sourceVersion = version; - } else { - this.fqn = fqn; - this.version = version; - } + private CTLSchemaScopeDto scope; + private String applicationId; + private SchemaType schemaType; + private boolean editable; + private boolean create; + + public CtlSchemaPlace(String metaInfoId, + Integer version, + CTLSchemaScopeDto scope, + String applicationId, + boolean editable, + boolean create) { + this.metaInfoId = metaInfoId; + this.version = version; + this.scope = scope; + this.applicationId = applicationId; + this.editable = editable; + this.create = create; } - public String getFqn() { - return fqn; + public String getMetaInfoId() { + return metaInfoId; } - + public Integer getVersion() { return version; } + + public CTLSchemaScopeDto getScope() { + return scope; + } + + public String getApplicationId() { + return applicationId; + } + + public boolean isEditable() { + return editable; + } - public String getSourceFqn() { - return sourceFqn; + public boolean isCreate() { + return create; + } + + public SchemaType getSchemaType() { + return schemaType; } - public Integer getSourceVersion() { - return sourceVersion; + public void setSchemaType(SchemaType schemaType) { + this.schemaType = schemaType; } @Prefix(value = "ctlSchema") @@ -60,79 +86,83 @@ public static class Tokenizer implements PlaceTokenizer, PlaceCo @Override public CtlSchemaPlace getPlace(String token) { PlaceParams.paramsFromToken(token); - String sourceFqn = PlaceParams.getParam(SOURCE_FQN); - int sourceVersion = PlaceParams.getIntParam(SOURCE_VERSION); - String fqn = PlaceParams.getParam(FQN); + String metaInfoId = PlaceParams.getParam(META_INFO_ID); Integer version = null; if (PlaceParams.hasParam(VERSION)) { version = PlaceParams.getIntParam(VERSION); } - if (sourceFqn != null && sourceVersion > 0) { - return new CtlSchemaPlace(sourceFqn, sourceVersion, true); - } else { - return new CtlSchemaPlace(fqn, version, false); + CTLSchemaScopeDto scope = null; + if (PlaceParams.hasParam(SCOPE)) { + scope = CTLSchemaScopeDto.valueOf(PlaceParams.getParam(SCOPE)); + } + SchemaType schemaType = null; + if (PlaceParams.hasParam(SCHEMA_TYPE)) { + schemaType = SchemaType.valueOf(PlaceParams.getParam(SCHEMA_TYPE)); } + String applicationId = PlaceParams.getParam(APPLICATION_ID); + boolean editable = PlaceParams.getBooleanParam(EDITABLE); + boolean create = PlaceParams.getBooleanParam(CREATE); + CtlSchemaPlace place = new CtlSchemaPlace(metaInfoId, version, scope, applicationId, editable, create); + place.setSchemaType(schemaType); + return place; } @Override public String getToken(CtlSchemaPlace place) { PlaceParams.clear(); - if (Utils.isNotBlank(place.getSourceFqn())) { - PlaceParams.putParam(SOURCE_FQN, place.getSourceFqn()); - } - if (place.getSourceVersion() != null) { - PlaceParams.putIntParam(SOURCE_VERSION, place.getSourceVersion()); - } - if (Utils.isNotBlank(place.getFqn())) { - PlaceParams.putParam(FQN, place.getFqn()); + if (Utils.isNotBlank(place.getMetaInfoId())) { + PlaceParams.putParam(META_INFO_ID, place.getMetaInfoId()); } if (place.getVersion() != null) { PlaceParams.putIntParam(VERSION, place.getVersion()); } + if (place.getScope() != null) { + PlaceParams.putParam(SCOPE, place.getScope().name()); + } + if (place.getSchemaType() != null) { + PlaceParams.putParam(SCHEMA_TYPE, place.getSchemaType().name()); + } + if (Utils.isNotBlank(place.getApplicationId())) { + PlaceParams.putParam(APPLICATION_ID, place.getApplicationId()); + } + PlaceParams.putBooleanParam(EDITABLE, place.isEditable()); + PlaceParams.putBooleanParam(CREATE, place.isCreate()); return PlaceParams.generateToken(); } } @Override public boolean equals(Object obj) { - if (this == obj) { + if (this == obj) return true; - } - if (obj == null) { + if (obj == null) return false; - } - if (getClass() != obj.getClass()) { + if (getClass() != obj.getClass()) return false; - } CtlSchemaPlace other = (CtlSchemaPlace) obj; - if (fqn == null) { - if (other.fqn != null) { + if (applicationId == null) { + if (other.applicationId != null) return false; - } - } else if (!fqn.equals(other.fqn)) { + } else if (!applicationId.equals(other.applicationId)) return false; - } - if (sourceFqn == null) { - if (other.sourceFqn != null) { - return false; - } - } else if (!sourceFqn.equals(other.sourceFqn)) { + if (create != other.create) return false; - } - if (sourceVersion == null) { - if (other.sourceVersion != null) { + if (editable != other.editable) + return false; + if (metaInfoId == null) { + if (other.metaInfoId != null) return false; - } - } else if (!sourceVersion.equals(other.sourceVersion)) { + } else if (!metaInfoId.equals(other.metaInfoId)) return false; - } + if (scope != other.scope) + return false; + if (schemaType != other.schemaType) + return false; if (version == null) { - if (other.version != null) { + if (other.version != null) return false; - } - } else if (!version.equals(other.version)) { + } else if (!version.equals(other.version)) return false; - } return true; } @@ -148,8 +178,30 @@ public String getName() { @Override public TreePlace createDefaultPreviousPlace() { - return new TenantCtlSchemasPlace(); + if (Utils.isNotBlank(applicationId)) { + if (schemaType != null) { + if (schemaType == SchemaType.ENDPOINT_PROFILE) { + return new ProfileSchemasPlace(applicationId); + } else { + return new ServerProfileSchemasPlace(applicationId); + } + } else { + return new ApplicationCtlSchemasPlace(applicationId); + } + } else { + if (KaaAdmin.getAuthInfo().getAuthority() == KaaAuthorityDto.KAA_ADMIN) { + return new SystemCtlSchemasPlace(); + } else { + return new TenantCtlSchemasPlace(); + } + } + } + + public static enum SchemaType { + + ENDPOINT_PROFILE, + SERVER_PROFILE + } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/KaaAdminPlaceHistoryMapper.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/KaaAdminPlaceHistoryMapper.java index 19ff48a2f4..b2a8f663ae 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/KaaAdminPlaceHistoryMapper.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/KaaAdminPlaceHistoryMapper.java @@ -23,7 +23,9 @@ GeneralPropertiesPlace.Tokenizer.class, MailPropertiesPlace.Tokenizer.class, TenantsPlace.Tokenizer.class, - TenantPlace.Tokenizer.class}) + TenantPlace.Tokenizer.class, + SystemCtlSchemasPlace.Tokenizer.class, + CtlSchemaPlace.Tokenizer.class}) public interface KaaAdminPlaceHistoryMapper extends PlaceHistoryMapper { } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/PlaceConstants.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/PlaceConstants.java index ae8b6a79e8..d82ca88f0c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/PlaceConstants.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/PlaceConstants.java @@ -37,7 +37,9 @@ public interface PlaceConstants { public static final String RANDOM = "random"; public static final String PLUGIN_ID = "pluginId"; public static final String SDK_ID = "sdkId"; - public static final String FQN = "fqn"; - public static final String SOURCE_FQN = "srcFqn"; - public static final String SOURCE_VERSION = "srcVer"; + public static final String META_INFO_ID = "metaInfoId"; + public static final String SCOPE = "scope"; + public static final String EDITABLE = "editable"; + public static final String SCHEMA_TYPE = "schemaType"; + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SystemCtlSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SystemCtlSchemasPlace.java new file mode 100644 index 0000000000..f639bb185f --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SystemCtlSchemasPlace.java @@ -0,0 +1,65 @@ +/* + * Copyright 2014-2015 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.place; + +import org.kaaproject.kaa.server.admin.client.util.Utils; + +import com.google.gwt.place.shared.PlaceTokenizer; +import com.google.gwt.place.shared.Prefix; + +public class SystemCtlSchemasPlace extends TreePlace { + + public SystemCtlSchemasPlace() { + } + + @Prefix(value = "sysCtlSchemas") + public static class Tokenizer implements PlaceTokenizer { + + @Override + public SystemCtlSchemasPlace getPlace(String token) { + return new SystemCtlSchemasPlace(); + } + + @Override + public String getToken(SystemCtlSchemasPlace place) { + PlaceParams.clear(); + return PlaceParams.generateToken(); + } + + } + + @Override + public boolean equals(Object obj) { + return obj != null && (obj instanceof SystemCtlSchemasPlace); + } + + @Override + public String getName() { + return Utils.constants.systemCtl(); + } + + @Override + public boolean isLeaf() { + return true; + } + + @Override + public TreePlace createDefaultPreviousPlace() { + return null; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantAdminPlaceHistoryMapper.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantAdminPlaceHistoryMapper.java index 5718f3d247..798f591507 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantAdminPlaceHistoryMapper.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantAdminPlaceHistoryMapper.java @@ -26,7 +26,9 @@ UserPlace.Tokenizer.class, EcfsPlace.Tokenizer.class, EcfPlace.Tokenizer.class, - EcfSchemaPlace.Tokenizer.class}) + EcfSchemaPlace.Tokenizer.class, + TenantCtlSchemasPlace.Tokenizer.class, + CtlSchemaPlace.Tokenizer.class}) public interface TenantAdminPlaceHistoryMapper extends PlaceHistoryMapper { } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantCtlSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantCtlSchemasPlace.java index f64d0a8b2e..df7636bb76 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantCtlSchemasPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantCtlSchemasPlace.java @@ -26,7 +26,7 @@ public class TenantCtlSchemasPlace extends TreePlace { public TenantCtlSchemasPlace() { } - @Prefix(value = "ctlSchemas") + @Prefix(value = "tenantCtlSchemas") public static class Tokenizer implements PlaceTokenizer { @Override @@ -49,7 +49,7 @@ public boolean equals(Object obj) { @Override public String getName() { - return Utils.constants.ctl(); + return Utils.constants.tenantCtl(); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantDeveloperPlaceHistoryMapper.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantDeveloperPlaceHistoryMapper.java index 23c355a5d3..1c29affb6c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantDeveloperPlaceHistoryMapper.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantDeveloperPlaceHistoryMapper.java @@ -52,6 +52,7 @@ UserVerifierPlace.Tokenizer.class, UpdateUserConfigPlace.Tokenizer.class, TenantCtlSchemasPlace.Tokenizer.class, + ApplicationCtlSchemasPlace.Tokenizer.class, CtlSchemaPlace.Tokenizer.class}) public interface TenantDeveloperPlaceHistoryMapper extends PlaceHistoryMapper { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantUserPlaceHistoryMapper.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantUserPlaceHistoryMapper.java index 1a25aae715..662b4925c6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantUserPlaceHistoryMapper.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TenantUserPlaceHistoryMapper.java @@ -52,6 +52,7 @@ UserVerifierPlace.Tokenizer.class, UpdateUserConfigPlace.Tokenizer.class, TenantCtlSchemasPlace.Tokenizer.class, + ApplicationCtlSchemasPlace.Tokenizer.class, CtlSchemaPlace.Tokenizer.class}) public interface TenantUserPlaceHistoryMapper extends PlaceHistoryMapper { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseCtlSchemaView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseCtlSchemaView.java index 5b6f32d0fe..a2c94c4f3d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseCtlSchemaView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseCtlSchemaView.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 CyberVision, Inc. + * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,10 @@ package org.kaaproject.kaa.server.admin.client.mvp.view; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; +import com.google.gwt.event.dom.client.HasClickHandlers; import com.google.gwt.user.client.ui.HasConstrainedValue; import com.google.gwt.user.client.ui.HasValue; @@ -36,8 +37,10 @@ public interface BaseCtlSchemaView extends BaseDetailsView { public boolean useExistingCtlSchema(); - public HasConstrainedValue getCtlSchemaReference(); + public HasConstrainedValue getCtlSchemaReference(); public RecordPanel getSchemaForm(); + + public HasClickHandlers getNewCtlButton(); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseListView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseListView.java index 6c82978eb8..3016c249fa 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseListView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/BaseListView.java @@ -34,7 +34,7 @@ public interface BaseListView extends IsWidget, HasErrorMessage void setBackEnabled(boolean enabled); MultiSelectionModel getSelectionModel(); - AbstractGrid getListWidget(); + AbstractGrid getListWidget(); HasRowActionEventHandlers getRowActionsSource(); void clearError(); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemaView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemaView.java index db499843f3..1ef495b950 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemaView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemaView.java @@ -21,6 +21,7 @@ import com.google.gwt.event.dom.client.HasClickHandlers; import com.google.gwt.user.client.ui.HasValue; +import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ValueListBox; public interface CtlSchemaView extends BaseDetailsView { @@ -28,20 +29,20 @@ public interface CtlSchemaView extends BaseDetailsView { public HasClickHandlers getCreateNewSchemaVersionButton(); public ActionsButton getExportActionsButton(); + + public HasClickHandlers getUpdateSchemaScopeButton(); public HasClickHandlers getDeleteSchemaVersionButton(); + + public Label getScope(); public ValueListBox getVersion(); - public HasValue getName(); - - public HasValue getDescription(); - public HasValue getCreatedUsername(); public HasValue getCreatedDateTime(); public RecordPanel getSchemaForm(); - + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemasView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemasView.java new file mode 100644 index 0000000000..4f3b492a07 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/CtlSchemasView.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.view; + +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; + +import com.google.gwt.user.client.ui.HasValue; + +public interface CtlSchemasView extends BaseListView { + + HasValue getShowHigherScopeCheckBox(); + + boolean displayShowHigherLevelScopeCheckBox(); + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderGrid.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderGrid.java index fab234f081..8ceafd4d14 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderGrid.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderGrid.java @@ -32,7 +32,7 @@ public LogAppenderGrid(boolean embedded) { protected float constructColumnsImpl(DataGrid table) { float prefWidth = super.constructColumnsImpl(table); - prefWidth += constructStringColumn(table, Utils.constants.minVersion(), + prefWidth += constructStringColumn(table, Utils.constants.minSchemaVersion(), new StringValueProvider() { @Override public String getValue(LogAppenderDto item) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderViewImpl.java index f7be8bcab3..32da2fa71a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/appender/LogAppenderViewImpl.java @@ -53,7 +53,7 @@ public LogAppenderViewImpl(boolean create) { @Override protected int initPluginDetails(int idx) { - Label minSchemaVersionLabel = new Label(Utils.constants.minVersion()); + Label minSchemaVersionLabel = new Label(Utils.constants.minSchemaVersion()); minSchemaVersionLabel.addStyleName(REQUIRED); minSchemaVersion = new IntegerListBox(); minSchemaVersion.setWidth("30%"); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseDetailsViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseDetailsViewImpl.java index 81fdd75fba..7f72e0f47a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseDetailsViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseDetailsViewImpl.java @@ -36,6 +36,7 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.DockLayoutPanel; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTMLPanel; @@ -43,6 +44,7 @@ import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; public abstract class BaseDetailsViewImpl extends Composite implements InputEventHandler, ChangeHandler, BaseDetailsView { @@ -53,14 +55,11 @@ interface BaseDetailsViewImplUiBinder extends UiBinder - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.java index 8a80c1d621..43e481f50d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.java @@ -33,6 +33,8 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DockLayoutPanel; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ResizeComposite; @@ -48,6 +50,7 @@ interface BaseListViewImplUiBinder extends UiBinder> @UiField public HorizontalPanel backButtonPanel; @UiField public Button backButton; @UiField public Label titleLabel; + @UiField public HorizontalPanel buttonsPanel; @UiField (provided=true) public final ImageTextButton addButton; @UiField (provided=true) public final AlertPanel errorPanel; @UiField (provided=true) public final KaaAdminStyle kaaAdminStyle; @@ -77,6 +80,13 @@ public BaseListViewImpl(boolean editable) { clearError(); } + + protected void appendToolbarWidget(Widget widget) { + buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + buttonsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + buttonsPanel.add(widget); + buttonsPanel.setCellHeight(widget, "100%"); + } protected Widget createAndBindUi() { return uiBinder.createAndBindUi(this); @@ -103,7 +113,7 @@ public MultiSelectionModel getSelectionModel() { } @Override - public AbstractGrid getListWidget() { + public AbstractGrid getListWidget() { return grid; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.ui.xml b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.ui.xml index e3880dd100..c3b32aacbb 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.ui.xml +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/base/BaseListViewImpl.ui.xml @@ -42,7 +42,7 @@ - + diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemaViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemaViewImpl.java new file mode 100644 index 0000000000..b576c4670b --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemaViewImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; + +public class ApplicationCtlSchemaViewImpl extends CtlSchemaViewImpl{ + + public ApplicationCtlSchemaViewImpl(boolean create, boolean editable) { + super(create, editable); + } + + @Override + protected boolean hasUpdateScopeOption() { + return true; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemasViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemasViewImpl.java new file mode 100644 index 0000000000..511a67b2e4 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/ApplicationCtlSchemasViewImpl.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; + +import org.kaaproject.kaa.server.admin.client.util.Utils; + +public class ApplicationCtlSchemasViewImpl extends CtlSchemasViewImpl { + + @Override + protected String titleString() { + return Utils.constants.applicationCtlTitle(); + } + + @Override + public boolean displayShowHigherLevelScopeCheckBox() { + return true; + } + + @Override + protected boolean defaultShowHigherLevelScopes() { + return false; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlGrid.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlGrid.java index 967248727d..d33cc4c173 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlGrid.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlGrid.java @@ -16,16 +16,17 @@ package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; +import java.util.Collections; import java.util.Comparator; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.server.admin.client.mvp.view.grid.AbstractKaaGrid; import org.kaaproject.kaa.server.admin.client.util.Utils; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.user.cellview.client.DataGrid; -public class CtlGrid extends AbstractKaaGrid { +public class CtlGrid extends AbstractKaaGrid { private static final int DEFAULT_PAGE_SIZE = 12; @@ -34,44 +35,81 @@ public CtlGrid(Unit unit) { } @Override - protected float constructColumnsImpl(DataGrid table) { + protected float constructColumnsImpl(DataGrid table) { float prefWidth = 0; prefWidth += constructStringColumn(table, - Utils.constants.name(), - new StringValueProvider() { + Utils.constants.fqn(), + new StringValueProvider() { @Override - public String getValue(SchemaFqnDto item) { - return item.getSchemaName(); + public String getValue(CTLSchemaMetaInfoDto item) { + return item.getFqn(); } }, - new Comparator() { + new Comparator() { @Override - public int compare(SchemaFqnDto o1, SchemaFqnDto o2) { - return o1.getSchemaName().compareTo(o2.getSchemaName()); + public int compare(CTLSchemaMetaInfoDto o1, CTLSchemaMetaInfoDto o2) { + return o1.getFqn().compareTo(o2.getFqn()); } }, Boolean.TRUE, true, - 80); - + 200); + prefWidth += constructStringColumn(table, - Utils.constants.fqn(), - new StringValueProvider() { + Utils.constants.scope(), + new StringValueProvider() { @Override - public String getValue(SchemaFqnDto item) { - return item.getFqnString(); + public String getValue(CTLSchemaMetaInfoDto item) { + return Utils.getCtlScopeString(item.getScope()); } }, - new Comparator() { + new Comparator() { @Override - public int compare(SchemaFqnDto o1, SchemaFqnDto o2) { - return o1.compareTo(o2); + public int compare(CTLSchemaMetaInfoDto o1, CTLSchemaMetaInfoDto o2) { + return Utils.getCtlScopeString(o1.getScope()).compareTo( + Utils.getCtlScopeString(o2.getScope())); } }, Boolean.TRUE, true, - 160); + 40); + + prefWidth += constructStringColumn(table, + Utils.constants.versionsCount(), + new StringValueProvider() { + @Override + public String getValue(CTLSchemaMetaInfoDto item) { + return item.getVersions().size() + ""; + } + }, + new Comparator() { + @Override + public int compare(CTLSchemaMetaInfoDto o1, CTLSchemaMetaInfoDto o2) { + return o1.getVersions().size() - o2.getVersions().size(); + } + }, + Boolean.TRUE, + false, + 40); + + prefWidth += constructStringColumn(table, + Utils.constants.maxVersion(), + new StringValueProvider() { + @Override + public String getValue(CTLSchemaMetaInfoDto item) { + return Collections.max(item.getVersions()) + ""; + } + }, + new Comparator() { + @Override + public int compare(CTLSchemaMetaInfoDto o1, CTLSchemaMetaInfoDto o2) { + return Collections.max(o1.getVersions()) - Collections.max(o2.getVersions()); + } + }, + Boolean.TRUE, + false, + 40); return prefWidth; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemaViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemaViewImpl.java index 922bfb715f..ee4190d6ea 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemaViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemaViewImpl.java @@ -18,7 +18,6 @@ import org.kaaproject.avro.ui.gwt.client.widget.ActionsButton; import org.kaaproject.avro.ui.gwt.client.widget.AvroWidgetsConfig; -import org.kaaproject.avro.ui.gwt.client.widget.SizedTextArea; import org.kaaproject.avro.ui.gwt.client.widget.SizedTextBox; import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemaView; @@ -28,33 +27,38 @@ import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel; import org.kaaproject.kaa.server.admin.client.util.Utils; +import com.google.gwt.dom.client.Style.FontWeight; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.HasClickHandlers; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ValueListBox; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; public class CtlSchemaViewImpl extends BaseDetailsViewImpl implements CtlSchemaView, ValueChangeHandler { + private Label scope; private IntegerListBox version; private Button createNewSchemaVersionButton; + private Button updateSchemaScopeButton; private Button deleteSchemaVersionButton; private ActionsButton exportActionsButton; - private SizedTextBox name; - private SizedTextArea description; private SizedTextBox createdUsername; private SizedTextBox createdDateTime; private RecordPanel schemaForm; - public CtlSchemaViewImpl(boolean create) { - super(create, true); + public CtlSchemaViewImpl(boolean create, boolean editable) { + super(create, editable); } @Override @@ -71,35 +75,199 @@ protected String getViewTitle() { protected String getSubTitle() { return Utils.constants.commonTypeDetails(); } + + @Override + protected Widget getBackButtonPanelWidget() { + return backButtonPanelWidget; + } + + @Override + protected Button getBackButtonWidget() { + return backButtonWidget; + } + + @Override + protected Label getTitileLabelWidget() { + return titleLabelWidget; + } @Override - protected void initDetailsTable() { + protected Button getSaveButtonWidget() { + return saveButtonWidget; + } + + @Override + protected Button getCancelButtonWidget() { + return cancelButtonWidget; + } + + private Widget backButtonPanelWidget; + private Button backButtonWidget; + private Label titleLabelWidget; + private Button saveButtonWidget; + private Button cancelButtonWidget; + + @Override + protected void constructTopPanel() { + FlexTable flexTable = new FlexTable(); + flexTable.setCellSpacing(0); + flexTable.setCellPadding(0); + flexTable.setHeight("100%"); + topPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + topPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + topPanel.add(flexTable); + topPanel.setCellHeight(flexTable, "100%"); + + HorizontalPanel backButtonPanel = new HorizontalPanel(); + backButtonPanel.setHeight("100%"); + backButtonPanel.addStyleName(Utils.kaaAdminStyle.bAppPaddedPanel()); + backButtonPanel.setVisible(false); + + flexTable.setWidget(0, 0, backButtonPanel); + flexTable.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE); + + backButtonPanelWidget = backButtonPanel; + + Button backButton = new Button(); + backButton.addStyleName(Utils.kaaAdminStyle.bAppBackButton()); + backButtonPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + backButtonPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + backButtonPanel.add(backButton); + backButtonPanel.setCellHeight(backButton, "100%"); + + backButtonWidget = backButton; + + VerticalPanel verticalPanel = new VerticalPanel(); + verticalPanel.setHeight("100%"); + flexTable.setWidget(0, 1, verticalPanel); + flexTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE); + + HorizontalPanel firstRowPanel = new HorizontalPanel(); + firstRowPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + firstRowPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + verticalPanel.add(firstRowPanel); + + HorizontalPanel secondRowPanel = new HorizontalPanel(); + secondRowPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + secondRowPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + + if (!create) { + backButton.getElement().getStyle().setPaddingTop(25, Unit.PX); + backButton.getElement().getStyle().setPaddingBottom(25, Unit.PX); + firstRowPanel.setHeight("45px"); + firstRowPanel.getElement().getStyle().setPaddingBottom(5, Unit.PX); + secondRowPanel.setHeight("45px"); + topPanel.setHeight("105px"); + topPanel.getElement().getStyle().setPaddingTop(10, Unit.PX); + updateNorthSize(185); + } else { + firstRowPanel.setHeight("70px"); + secondRowPanel.setHeight("100%"); + topPanel.setHeight("80px"); + updateNorthSize(175); + } + verticalPanel.add(secondRowPanel); + Label titleLabel = new Label(); + titleLabel.addStyleName(Utils.kaaAdminStyle.bAppContentTitle()); + firstRowPanel.add(titleLabel); + firstRowPanel.setCellHeight(titleLabel, "100%"); + + titleLabelWidget = titleLabel; + + int horizontalMargin = 15; + + scope = new Label(); + scope.getElement().getStyle().setFontSize(16, Unit.PX); + scope.getElement().getStyle().setFontWeight(FontWeight.NORMAL); + scope.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + firstRowPanel.add(scope); + firstRowPanel.setCellHeight(scope, "100%"); + + updateSchemaScopeButton = new Button(Utils.constants.promote()); + updateSchemaScopeButton.setVisible(!create && editable); + updateSchemaScopeButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + if (hasUpdateScopeOption()) { + firstRowPanel.add(updateSchemaScopeButton); + firstRowPanel.setCellHeight(updateSchemaScopeButton, "100%"); + } + Label versionLabel = new Label(Utils.constants.version()); versionLabel.addStyleName(Utils.kaaAdminStyle.bAppContentTitle()); + versionLabel.getElement().getStyle().setFontSize(16, Unit.PX); + versionLabel.getElement().getStyle().setFontWeight(FontWeight.NORMAL); version = new IntegerListBox(); version.getElement().getStyle().setPadding(5, Unit.PX); - version.getElement().getStyle().setMarginLeft(5, Unit.PX); - - createNewSchemaVersionButton = new Button(Utils.constants.createNewVersion()); - exportActionsButton = new ActionsButton(Utils.resources.export(), Utils.constants.export()); - deleteSchemaVersionButton = new Button(Utils.constants.delete()); - + version.getElement().getStyle().setMarginLeft(10, Unit.PX); HorizontalPanel versionPanel = new HorizontalPanel(); versionPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); versionPanel.add(versionLabel); versionPanel.add(version); + versionPanel.setVisible(!create); - prependToolbarWidget(versionPanel); - appendToolbarWidget(createNewSchemaVersionButton); - appendToolbarWidget(exportActionsButton); - appendToolbarWidget(deleteSchemaVersionButton); + secondRowPanel.add(versionPanel); + secondRowPanel.setCellHeight(versionPanel, "100%"); - versionPanel.setVisible(!create); - createNewSchemaVersionButton.setVisible(!create); - deleteSchemaVersionButton.setVisible(!create); + createNewSchemaVersionButton = new Button(Utils.constants.createNewVersion()); + createNewSchemaVersionButton.setVisible(!create && editable); + createNewSchemaVersionButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + if (!create && editable) { + secondRowPanel.add(createNewSchemaVersionButton); + secondRowPanel.setCellHeight(createNewSchemaVersionButton, "100%"); + } + + exportActionsButton = new ActionsButton(Utils.resources.export(), Utils.constants.export()); exportActionsButton.setVisible(!create); + exportActionsButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + if (!create) { + secondRowPanel.add(exportActionsButton); + secondRowPanel.setCellHeight(exportActionsButton, "100%"); + } + + Button saveButton = new Button(); + saveButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + if (create) { + firstRowPanel.add(saveButton); + firstRowPanel.setCellHeight(saveButton, "100%"); + } + + saveButtonWidget = saveButton; + + Button cancelButton = new Button(); + cancelButton.setVisible(false); + cancelButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + if (create) { + firstRowPanel.add(cancelButton); + firstRowPanel.setCellHeight(cancelButton, "100%"); + } + + cancelButtonWidget = cancelButton; + + deleteSchemaVersionButton = new Button(Utils.constants.delete()); + deleteSchemaVersionButton.addStyleName(Utils.kaaAdminStyle.deleteButton()); + deleteSchemaVersionButton.setVisible(!create && editable); + deleteSchemaVersionButton.getElement().getStyle().setMarginLeft(horizontalMargin, Unit.PX); + + if (!create && editable) { + secondRowPanel.add(deleteSchemaVersionButton); + secondRowPanel.setCellHeight(deleteSchemaVersionButton, "100%"); + } + } + + @Override + protected void initDetailsTable() { + if (create) { + requiredFieldsNoteLabel.setVisible(true); + } else { + requiredFieldsNoteLabel.setVisible(false); + requiredFieldsNoteLabel.getElement().getParentElement().getStyle().setHeight(0, Unit.PX); + } Label authorLabel = new Label(Utils.constants.author()); createdUsername = new KaaAdminSizedTextBox(-1, false); createdUsername.setWidth("100%"); @@ -117,45 +285,27 @@ protected void initDetailsTable() { dateTimeCreatedLabel.setVisible(!create); createdDateTime.setVisible(!create); - - name = new KaaAdminSizedTextBox(DEFAULT_TEXTBOX_SIZE); - name.setWidth("100%"); - Label nameLabel = new Label(Utils.constants.name()); - detailsTable.setWidget(2, 0, nameLabel); - detailsTable.setWidget(2, 1, name); - name.addInputHandler(this); - - description = new SizedTextArea(1024); - description.setWidth("100%"); - description.getTextArea().getElement().getStyle().setPropertyPx("minHeight", 80); - - Label descriptionLabel = new Label(Utils.constants.description()); - detailsTable.setWidget(3, 0, descriptionLabel); - detailsTable.setWidget(3, 1, description); - description.addInputHandler(this); - - detailsTable.getCellFormatter().setVerticalAlignment(5, 0, HasVerticalAlignment.ALIGN_TOP); getFooter().addStyleName(Utils.kaaAdminStyle.bAppContentDetailsTable()); schemaForm = new RecordPanel(new AvroWidgetsConfig.Builder(). - recordPanelWidth(900).createConfig(), - Utils.constants.schema(), this, !create, !create); + recordPanelWidth(900).createConfig(), false, + null, this, !create, !create); if (create) { schemaForm.addValueChangeHandler(this); } getFooter().setWidth("1000px"); getFooter().add(schemaForm); - - name.setFocus(true); + } + + protected boolean hasUpdateScopeOption() { + return false; } @Override protected void resetImpl() { version.reset(); - name.setValue(""); - description.setValue(""); createdUsername.setValue(""); createdDateTime.setValue(""); schemaForm.reset(); @@ -182,16 +332,6 @@ public RecordPanel getSchemaForm() { return schemaForm; } - @Override - public HasValue getName() { - return name; - } - - @Override - public HasValue getDescription() { - return description; - } - @Override public HasValue getCreatedUsername() { return createdUsername; @@ -207,6 +347,11 @@ public HasClickHandlers getCreateNewSchemaVersionButton() { return createNewSchemaVersionButton; } + @Override + public HasClickHandlers getUpdateSchemaScopeButton() { + return updateSchemaScopeButton; + } + @Override public HasClickHandlers getDeleteSchemaVersionButton() { return deleteSchemaVersionButton; @@ -217,4 +362,9 @@ public ActionsButton getExportActionsButton() { return exportActionsButton; } + @Override + public Label getScope() { + return scope; + } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemasViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemasViewImpl.java index 4a8ddfe15b..406410281e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemasViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/CtlSchemasViewImpl.java @@ -17,20 +17,34 @@ package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; +import org.kaaproject.kaa.server.admin.client.mvp.view.CtlSchemasView; import org.kaaproject.kaa.server.admin.client.mvp.view.base.BaseListViewImpl; import org.kaaproject.kaa.server.admin.client.util.Utils; -import org.kaaproject.kaa.server.admin.shared.schema.SchemaFqnDto; +import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.HasValue; -public class CtlSchemasViewImpl extends BaseListViewImpl { +public class CtlSchemasViewImpl extends BaseListViewImpl implements CtlSchemasView { + private CheckBox showHigherScopeCheckBox; + public CtlSchemasViewImpl() { super(true); + if (displayShowHigherLevelScopeCheckBox()) { + showHigherScopeCheckBox = new CheckBox(Utils.constants.displayHigherScopes()); + showHigherScopeCheckBox.addStyleName(Utils.kaaAdminStyle.bAppContentTitle()); + Element.as(showHigherScopeCheckBox.getElement().getChild(0)). + getStyle().setMarginRight(10, Unit.PX); + showHigherScopeCheckBox.setValue(defaultShowHigherLevelScopes()); + appendToolbarWidget(showHigherScopeCheckBox); + } } @Override - protected AbstractGrid createGrid() { + protected AbstractGrid createGrid() { return new CtlGrid(Unit.PX); } @@ -43,5 +57,19 @@ protected String titleString() { protected String addButtonString() { return Utils.constants.addNewCtl(); } + + @Override + public boolean displayShowHigherLevelScopeCheckBox() { + return false; + } + + @Override + public HasValue getShowHigherScopeCheckBox() { + return showHigherScopeCheckBox; + } + + protected boolean defaultShowHigherLevelScopes() { + return true; + } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/SystemCtlSchemasViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/SystemCtlSchemasViewImpl.java new file mode 100644 index 0000000000..433b394c67 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/SystemCtlSchemasViewImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; + +import org.kaaproject.kaa.server.admin.client.util.Utils; + +public class SystemCtlSchemasViewImpl extends CtlSchemasViewImpl { + + @Override + protected String titleString() { + return Utils.constants.systemCtlTitle(); + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/TenantCtlSchemasViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/TenantCtlSchemasViewImpl.java new file mode 100644 index 0000000000..b13f1659c4 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/ctl/TenantCtlSchemasViewImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.client.mvp.view.ctl; + +import org.kaaproject.kaa.server.admin.client.util.Utils; + +public class TenantCtlSchemasViewImpl extends CtlSchemasViewImpl { + + @Override + protected String titleString() { + return Utils.constants.tenantCtlTitle(); + } + + @Override + public boolean displayShowHigherLevelScopeCheckBox() { + return true; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfileViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfileViewImpl.java index 286f1ec297..39ee09e3dc 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfileViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfileViewImpl.java @@ -91,8 +91,8 @@ protected void initDetailsTable() { detailsTable.getColumnFormatter().setWidth(1, "550px"); detailsTable.getColumnFormatter().setWidth(2, "0px"); - saveButton.removeFromParent(); - cancelButton.removeFromParent(); + getSaveButtonWidget().removeFromParent(); + getCancelButtonWidget().removeFromParent(); requiredFieldsNoteLabel.setVisible(false); int row = 0; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfilesViewImpl.ui.xml b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfilesViewImpl.ui.xml index 1022f97015..06dd3a2817 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfilesViewImpl.ui.xml +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/endpoint/EndpointProfilesViewImpl.ui.xml @@ -42,7 +42,7 @@ - + diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/enduser/UpdateUserConfigViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/enduser/UpdateUserConfigViewImpl.java index 2ab9847989..c2f8c70af4 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/enduser/UpdateUserConfigViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/enduser/UpdateUserConfigViewImpl.java @@ -137,8 +137,8 @@ public void onValueChange(ValueChangeEvent event) { @Override protected void updateSaveButton(boolean enabled, boolean invalid) { - saveButton.setText(Utils.constants.update()); - saveButton.setEnabled(enabled); + getSaveButtonWidget().setText(Utils.constants.update()); + getSaveButtonWidget().setEnabled(enabled); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/navigation/NavigationTreeViewModel.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/navigation/NavigationTreeViewModel.java index 4fe0f917bc..1741079364 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/navigation/NavigationTreeViewModel.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/navigation/NavigationTreeViewModel.java @@ -23,6 +23,7 @@ import org.kaaproject.kaa.server.admin.client.KaaAdmin; import org.kaaproject.kaa.server.admin.client.mvp.place.ApplicationsPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.EcfsPlace; +import org.kaaproject.kaa.server.admin.client.mvp.place.SystemCtlSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantCtlSchemasPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TenantsPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.TreePlace; @@ -47,11 +48,13 @@ public NavigationTreeViewModel() { switch (autority) { case KAA_ADMIN: nodes.add(new TenantsPlace()); + nodes.add(new SystemCtlSchemasPlace()); break; case TENANT_ADMIN: nodes.add(new ApplicationsPlace()); nodes.add(new UsersPlace()); nodes.add(new EcfsPlace()); + nodes.add(new TenantCtlSchemasPlace()); break; case TENANT_DEVELOPER: nodes.add(new ApplicationsPlace()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/schema/BaseCtlSchemaViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/schema/BaseCtlSchemaViewImpl.java index cd062c970d..abb3c32fe8 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/schema/BaseCtlSchemaViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/schema/BaseCtlSchemaViewImpl.java @@ -20,17 +20,18 @@ import org.kaaproject.avro.ui.gwt.client.widget.SizedTextArea; import org.kaaproject.avro.ui.gwt.client.widget.SizedTextBox; import org.kaaproject.avro.ui.shared.RecordField; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.base.BaseDetailsViewImpl; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.CtlSchemaReferenceBox; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.KaaAdminSizedTextBox; import org.kaaproject.kaa.server.admin.client.mvp.view.widget.RecordPanel; import org.kaaproject.kaa.server.admin.client.util.Utils; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.HasClickHandlers; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.layout.client.Layout.Alignment; @@ -143,16 +144,6 @@ public void onClick(ClickEvent event) { fireChanged(); } }); - newCtlButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - rootPanel.setHeight(SCHEMA_FORM_PANEL_HEIGHT); - ctlSchemaPanel.showWidget(1); - existingCtlButton.setValue(false); - newCtlButton.setValue(true); - fireChanged(); - } - }); ctlSchemaPanel.setAnimationCallback(new AnimationCallback() { @Override public void onAnimationComplete() { @@ -181,9 +172,9 @@ public void onValueChange(ValueChangeEvent event) { fireChanged(); } }); - ctlSchemaReferenceBox.addValueChangeHandler(new ValueChangeHandler() { + ctlSchemaReferenceBox.addValueChangeHandler(new ValueChangeHandler() { @Override - public void onValueChange(ValueChangeEvent event) { + public void onValueChange(ValueChangeEvent event) { fireChanged(); } }); @@ -271,7 +262,7 @@ public HasValue getCreatedDateTime() { } @Override - public HasConstrainedValue getCtlSchemaReference() { + public HasConstrainedValue getCtlSchemaReference() { return ctlSchemaReferenceBox; } @@ -280,6 +271,10 @@ public boolean useExistingCtlSchema() { return ctlSchemaPanel.getVisibleWidgetIndex() == 0; } + public HasClickHandlers getNewCtlButton() { + return newCtlButton; + } + private class FragmentLayoutPanel extends DeckLayoutPanel { private AnimationCallback animationCallback; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/AddSdkProfileViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/AddSdkProfileViewImpl.java index 0d52fab5d6..2bac8fd612 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/AddSdkProfileViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/AddSdkProfileViewImpl.java @@ -386,8 +386,8 @@ public int compare(AefMapInfoDto o1, AefMapInfoDto o2) { @Override protected void updateSaveButton(boolean enabled, boolean invalid) { - saveButton.setText(Utils.constants.add()); - saveButton.setEnabled(enabled); + getSaveButtonWidget().setText(Utils.constants.add()); + getSaveButtonWidget().setEnabled(enabled); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/SdkProfileViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/SdkProfileViewImpl.java index 51f2657997..00abd8a907 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/SdkProfileViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/sdk/SdkProfileViewImpl.java @@ -62,8 +62,8 @@ protected String getSubTitle() { @Override protected void initDetailsTable() { - saveButton.removeFromParent(); - cancelButton.removeFromParent(); + getSaveButtonWidget().removeFromParent(); + getCancelButtonWidget().removeFromParent(); requiredFieldsNoteLabel.setVisible(false); int row = 0; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseRecordViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseRecordViewImpl.java index 35cc04bdae..f54e6da350 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseRecordViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/struct/BaseRecordViewImpl.java @@ -31,9 +31,9 @@ public abstract class BaseRecordViewImpl exten public BaseRecordViewImpl(boolean create) { super(create); - saveButton.setVisible(false); - cancelButton.setVisible(false); - backButtonPanel.setVisible(true); + getSaveButtonWidget().setVisible(false); + getCancelButtonWidget().setVisible(false); + getBackButtonPanelWidget().setVisible(true); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/SendNotificationViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/SendNotificationViewImpl.java index 2ee3c4eacf..25bd7ab4cd 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/SendNotificationViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/SendNotificationViewImpl.java @@ -135,8 +135,8 @@ public void onValueChange(ValueChangeEvent event) { @Override protected void updateSaveButton(boolean enabled, boolean invalid) { - saveButton.setText(Utils.constants.send()); - saveButton.setEnabled(enabled); + getSaveButtonWidget().setText(Utils.constants.send()); + getSaveButtonWidget().setEnabled(enabled); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/TopicViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/TopicViewImpl.java index e7345db386..0dda280c49 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/TopicViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/topic/TopicViewImpl.java @@ -96,7 +96,7 @@ protected void initDetailsTable() { sendNotification.setVisible(!create); if (!create) { - saveButton.setVisible(false); + getSaveButtonWidget().setVisible(false); name.setEnabled(false); mandatory.setEnabled(false); description.getTextArea().setEnabled(false); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/CtlSchemaReferenceBox.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/CtlSchemaReferenceBox.java index c2e628b83e..5a383889a5 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/CtlSchemaReferenceBox.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/CtlSchemaReferenceBox.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 CyberVision, Inc. + * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ import org.kaaproject.avro.ui.shared.Fqn; import org.kaaproject.avro.ui.shared.FqnKey; import org.kaaproject.avro.ui.shared.FqnVersion; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.server.admin.client.util.Utils; +import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.logical.shared.ValueChangeEvent; @@ -38,15 +38,15 @@ import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.RequiresResize; -public class CtlSchemaReferenceBox extends HorizontalPanel implements HasConstrainedValue, RequiresResize { +public class CtlSchemaReferenceBox extends HorizontalPanel implements HasConstrainedValue, RequiresResize { - private CTLSchemaMetaInfoDto value; + private CtlSchemaReferenceDto value; private FqnReferenceBox fqnReferenceBox; private IntegerListBox versionsBox; private Map> fqnVersionsMap = new HashMap<>(); - private Map fqnVersionToReferenceMap = new HashMap<>(); + private Map fqnVersionToReferenceMap = new HashMap<>(); public CtlSchemaReferenceBox() { fqnReferenceBox = new FqnReferenceBox(Utils.constants.schemaReferencePrompt()); @@ -77,7 +77,7 @@ public void onValueChange(ValueChangeEvent event) { } private void updateValueByFqnKeyAndVersion(FqnKey fqnKey, Integer version) { - CTLSchemaMetaInfoDto newValue = null; + CtlSchemaReferenceDto newValue = null; if (fqnKey != null) { Fqn fqn = fqnKey.getFqn(); if (version == null) { @@ -91,22 +91,22 @@ private void updateValueByFqnKeyAndVersion(FqnKey fqnKey, Integer version) { } @Override - public CTLSchemaMetaInfoDto getValue() { + public CtlSchemaReferenceDto getValue() { return value; } @Override - public void setValue(CTLSchemaMetaInfoDto value) { + public void setValue(CtlSchemaReferenceDto value) { setValue(value, false); } @Override - public void setValue(CTLSchemaMetaInfoDto value, boolean fireEvents) { + public void setValue(CtlSchemaReferenceDto value, boolean fireEvents) { if (value == this.value || (this.value != null && this.value.equals(value))) { return; } - CTLSchemaMetaInfoDto before = this.value; + CtlSchemaReferenceDto before = this.value; this.value = value; updateBox(); @@ -118,18 +118,18 @@ public void setValue(CTLSchemaMetaInfoDto value, boolean fireEvents) { @Override public HandlerRegistration addValueChangeHandler( - ValueChangeHandler handler) { + ValueChangeHandler handler) { return addHandler(handler, ValueChangeEvent.getType()); } @Override - public void setAcceptableValues(Collection values) { + public void setAcceptableValues(Collection values) { fqnVersionsMap.clear(); fqnVersionToReferenceMap.clear(); Map declaredFqns = new HashMap<>(); - for (CTLSchemaMetaInfoDto ctlReference : values) { - Fqn fqn = new Fqn(ctlReference.getFqn()); + for (CtlSchemaReferenceDto ctlReference : values) { + Fqn fqn = new Fqn(ctlReference.getMetaInfo().getFqn()); FqnKey fqnKey = new FqnKey(fqn); declaredFqns.put(fqnKey, fqn); @@ -157,7 +157,7 @@ public void reset() { private void updateBox() { if (value != null) { - Fqn fqn = new Fqn(value.getFqn()); + Fqn fqn = new Fqn(value.getMetaInfo().getFqn()); fqnReferenceBox.setValue(new FqnKey(fqn)); List versions = fqnVersionsMap.get(fqn); Collections.sort(versions); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/RecordPanel.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/RecordPanel.java index 2134943ffa..74199196ee 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/RecordPanel.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/RecordPanel.java @@ -58,25 +58,37 @@ public class RecordPanel extends SimplePanel implements HasValue, C private HasErrorMessage hasErrorMessage; private FormDataLoader formDataLoader; private boolean optional; + private boolean showCaption; public RecordPanel(String title, HasErrorMessage hasErrorMessage, boolean optional, boolean readOnly) { this(null, title, hasErrorMessage, optional, readOnly); } - + public RecordPanel(AvroWidgetsConfig config, String title, HasErrorMessage hasErrorMessage, boolean optional, boolean readOnly) { + this(config, true, title, hasErrorMessage, optional, readOnly); + } + + public RecordPanel(AvroWidgetsConfig config, boolean showCaption, String title, HasErrorMessage hasErrorMessage, boolean optional, boolean readOnly) { + this.showCaption = showCaption; this.optional = optional; this.readOnly = readOnly; this.hasErrorMessage = hasErrorMessage; FlexTable table = new FlexTable(); table.setWidth("100%"); - recordCaption = new CaptionPanel(); - setTitle(title); if (config == null) { config = new AvroWidgetsConfig.Builder().createConfig(); } + recordFieldWidget = new RecordFieldWidget(config, readOnly); - recordCaption.setContentWidget(recordFieldWidget); - table.setWidget(0, 0, recordCaption); + if (showCaption) { + recordCaption = new CaptionPanel(); + setTitle(title); + recordCaption.setContentWidget(recordFieldWidget); + table.setWidget(0, 0, recordCaption); + } else { + table.setWidget(0, 0, recordFieldWidget); + } + Label uploadLabel = new Label(Utils.constants.uploadFromFile()); recordFileUpload = new FileUploadForm(); recordFileUpload.addSubmitCompleteHandler(new SubmitCompleteHandler() { @@ -124,15 +136,17 @@ public void setReadOnly(boolean readOnly) { } public void setTitle(String title) { - if (optional) { - recordCaption.setCaptionText(title); - } else { - SpanElement span = Document.get().createSpanElement(); - span.appendChild(Document.get().createTextNode(title)); - span.addClassName("gwt-Label"); - span.addClassName(REQUIRED); - recordCaption.setCaptionHTML(span.getString()); - } + if (showCaption) { + if (optional) { + recordCaption.setCaptionText(title); + } else { + SpanElement span = Document.get().createSpanElement(); + span.appendChild(Document.get().createTextNode(title)); + span.addClassName("gwt-Label"); + span.addClassName(REQUIRED); + recordCaption.setCaptionHTML(span.getString()); + } + } } private void setUploadVisible(boolean visible) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/util/Utils.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/util/Utils.java index e4c2569770..e5efa0d894 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/util/Utils.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/util/Utils.java @@ -24,6 +24,7 @@ import org.kaaproject.avro.ui.gwt.client.AvroUiResources.AvroUiStyle; import org.kaaproject.avro.ui.gwt.client.widget.AlertPanel; import org.kaaproject.kaa.common.dto.VersionDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.admin.client.KaaAdminResources; import org.kaaproject.kaa.server.admin.client.KaaAdminResources.KaaAdminStyle; import org.kaaproject.kaa.server.admin.client.KaaAdminResources.KaaTheme; @@ -194,4 +195,31 @@ public static boolean isNotBlank(String string) { public static boolean isBlank(String string) { return string == null || string.length() == 0; } + + public static String getCtlScopeString(CTLSchemaScopeDto scope) { + switch (scope) { + case APPLICATION: + return constants.scopeApplication(); + case SYSTEM: + return constants.scopeSystem(); + case TENANT: + return constants.scopeTenant(); + default: + return "Unknown"; + } + } + + public static String getCtlScopeTitleString(CTLSchemaScopeDto scope) { + switch (scope) { + case APPLICATION: + return constants.scopeApplicationTitle(); + case SYSTEM: + return constants.scopeSystemTitle(); + case TENANT: + return constants.scopeTenantTitle(); + default: + return "Unknown"; + } + } + } 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 3630d727a3..c7412da643 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 @@ -17,7 +17,6 @@ package org.kaaproject.kaa.server.admin.controller; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty; import java.io.IOException; import java.util.List; @@ -34,6 +33,7 @@ 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; @@ -43,7 +43,6 @@ 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.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.ProfileVersionPairDto; import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; import org.kaaproject.kaa.common.dto.TopicDto; @@ -56,10 +55,9 @@ import org.kaaproject.kaa.common.dto.admin.SdkProfileDto; import org.kaaproject.kaa.common.dto.admin.TenantUserDto; import org.kaaproject.kaa.common.dto.admin.UserDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.EcfInfoDto; @@ -738,10 +736,10 @@ public void flushSdkCache() throws KaaAdminServiceException { * * @param body * the ctl body - * @param scope - * the ctl schema scope * @param applicationId * id of the application + * @param tenantId + * id of the tenant * * @throws KaaAdminServiceException * the kaa admin service exception @@ -750,9 +748,9 @@ public void flushSdkCache() throws KaaAdminServiceException { */ @RequestMapping(value = "CTL/saveSchema", params = { "body" }, method = RequestMethod.POST) @ResponseBody - public CTLSchemaInfoDto saveCTLSchema(@RequestParam String body, @RequestParam(required = false) String scope, + public CTLSchemaDto saveCTLSchema(@RequestParam String body, @RequestParam(required = false) String tenantId, @RequestParam(required = false) String applicationId) throws KaaAdminServiceException { - return kaaAdminService.saveCTLSchema(body, isEmpty(scope) ? null : CTLSchemaScopeDto.valueOf(scope.toUpperCase()), applicationId); + return kaaAdminService.saveCTLSchema(body, tenantId, applicationId); } /** @@ -762,14 +760,20 @@ public CTLSchemaInfoDto saveCTLSchema(@RequestParam String body, @RequestParam(r * the fqn * @param version * the version - * + * @param tenantId + * id of the tenant + * @param applicationId + * id of the application + * * @throws KaaAdminServiceException * the kaa admin service exception */ @RequestMapping(value = "CTL/deleteSchema", params = { "fqn", "version" }, method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) - public void deleteCTLSchemaByFqnAndVersion(@RequestParam String fqn, @RequestParam int version) throws KaaAdminServiceException { - kaaAdminService.deleteCTLSchemaByFqnAndVersion(fqn, version); + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(@RequestParam String fqn, @RequestParam int version, + @RequestParam(required = false) String tenantId, + @RequestParam(required = false) String applicationId) throws KaaAdminServiceException { + kaaAdminService.deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); } /** @@ -779,6 +783,11 @@ public void deleteCTLSchemaByFqnAndVersion(@RequestParam String fqn, @RequestPar * the fqn * @param version * the version + * @param tenantId + * id of the tenant + * @param applicationId + * id of the application + * * @throws KaaAdminServiceException * the kaa admin service exception * @@ -786,57 +795,96 @@ public void deleteCTLSchemaByFqnAndVersion(@RequestParam String fqn, @RequestPar */ @RequestMapping(value = "CTL/getSchema", params = { "fqn", "version" }, method = RequestMethod.GET) @ResponseBody - public CTLSchemaInfoDto getCTLSchemaByFqnAndVersion(@RequestParam String fqn, @RequestParam int version) + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(@RequestParam String fqn, + @RequestParam int version, + @RequestParam(required = false) String tenantId, + @RequestParam(required = false) String applicationId) throws KaaAdminServiceException { - return kaaAdminService.getCTLSchemaByFqnAndVersion(fqn, version); + return kaaAdminService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + } + + /** + * Checks if CTL schema with same fqn is already exists in the sibling application. + * + * @param fqn + * the fqn + * @param tenantId + * id of the tenant + * @param applicationId + * id of the application + * + * @throws KaaAdminServiceException + * the kaa admin service exception + * + * @return true if CTL schema with same fqn is already exists in other scope + */ + @RequestMapping(value = "CTL/checkFqn", params = { "fqn" }, method = RequestMethod.GET) + @ResponseBody + public boolean checkFqnExists(@RequestParam String fqn, + @RequestParam(required = false) String tenantId, + @RequestParam(required = false) String applicationId) + throws KaaAdminServiceException { + return kaaAdminService.checkFqnExists(fqn, tenantId, applicationId); + } + + /** + * Update existing CTL schema meta info scope by the given CTL schema meta info object. + * + * @param ctlSchemaMetaInfo + * the CTL schema meta info object. + * + * @throws KaaAdminServiceException + * the kaa admin service exception + * + * @return CTLSchemaMetaInfoDto the updated CTL schema meta info object. + */ + @RequestMapping(value = "CTL/updateScope", method = RequestMethod.POST) + @ResponseBody + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(@RequestBody CTLSchemaMetaInfoDto ctlSchemaMetaInfo) + throws KaaAdminServiceException { + return kaaAdminService.updateCTLSchemaMetaInfoScope(ctlSchemaMetaInfo); } /** - * Retrieves a list of CTL schemas available for the current tenant. + * Retrieves a list of available system CTL schemas. * * @throws KaaAdminServiceException * the kaa admin service exception * @return CTL schema metadata list */ - @RequestMapping(value = "CTL/getSchemas", method = RequestMethod.GET) + @RequestMapping(value = "CTL/getSystemSchemas", method = RequestMethod.GET) @ResponseBody - public List getCTLSchemasAvailable() throws KaaAdminServiceException { - return kaaAdminService.getCTLSchemasAvailable(); + public List getSystemLevelCTLSchemas() throws KaaAdminServiceException { + return kaaAdminService.getSystemLevelCTLSchemas(); } - + /** - * Retrieves a list of CTL schemas available for the current user filtered - * by scope. - * - * @param scope - * - scope name + * Retrieves a list of available CTL schemas for tenant. * * @throws KaaAdminServiceException * the kaa admin service exception - * * @return CTL schema metadata list */ - @RequestMapping(value = "CTL/getSchemas", params = { "scope" }, method = RequestMethod.GET) + @RequestMapping(value = "CTL/getTenantSchemas", method = RequestMethod.GET) @ResponseBody - public List getCTLSchemasByScope(@RequestParam(value = "scope") String scope) throws KaaAdminServiceException { - return kaaAdminService.getCTLSchemasByScope(scope); + public List getTenantLevelCTLSchemas() throws KaaAdminServiceException { + return kaaAdminService.getTenantLevelCTLSchemas(); } - + /** - * Retrieves a list of CTL schemas by application identifier. + * Retrieves a list of available CTL schemas for application. * * @param applicationId - * - applicationId name - * + * id of the application + * * @throws KaaAdminServiceException * the kaa admin service exception - * * @return CTL schema metadata list */ - @RequestMapping(value = "CTL/getSchemas", params = { "applicationId" }, method = RequestMethod.GET) + @RequestMapping(value = "CTL/getApplicationSchemas/{applicationId}", method = RequestMethod.GET) @ResponseBody - public List getCTLSchemasByApplicationId(@RequestParam String applicationId) throws KaaAdminServiceException { - return kaaAdminService.getCTLSchemasByApplicationId(applicationId); + public List getApplicationLevelCTLSchemas(@PathVariable String applicationId) throws KaaAdminServiceException { + return kaaAdminService.getApplicationLevelCTLSchemas(applicationId); } /** @@ -849,6 +897,8 @@ public List getCTLSchemasByApplicationId(@RequestParam Str * - the schema version * @param method * - the schema export method + * @param applicationId + * id of the application * @param request * - the http request * @param response @@ -861,10 +911,11 @@ public List getCTLSchemasByApplicationId(@RequestParam Str */ @RequestMapping(value = "CTL/exportSchema", params = { "fqn", "version", "method" }, method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) - public void exportCTLSchema(@RequestParam String fqn, @RequestParam int version, @RequestParam String method, + public void exportCTLSchema(@RequestParam String fqn, @RequestParam int version, @RequestParam String method, + @RequestParam(required = false) String applicationId, HttpServletRequest request, HttpServletResponse response) throws KaaAdminServiceException { try { - FileData output = kaaAdminService.exportCTLSchema(fqn, version, CTLSchemaExportMethod.valueOf(method.toUpperCase())); + FileData output = kaaAdminService.exportCTLSchema(fqn, version, applicationId, CTLSchemaExportMethod.valueOf(method.toUpperCase())); ServletUtils.prepareDisposition(request, response, output.getFileName()); response.setContentType(output.getContentType()); response.setContentLength(output.getFileData().length); 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 a69043a57e..1d0860eb69 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 @@ -32,8 +32,6 @@ import java.util.Map; import java.util.Set; -import net.iharder.Base64; - import org.apache.avro.Schema; import org.apache.avro.SchemaParseException; import org.apache.avro.generic.GenericRecord; @@ -83,7 +81,6 @@ import org.kaaproject.kaa.common.dto.admin.TenantUserDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; @@ -119,8 +116,8 @@ import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; 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.SchemaFqnDto; 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; @@ -150,6 +147,8 @@ import com.google.common.base.Charsets; +import net.iharder.Base64; + @Service("kaaAdminService") public class KaaAdminServiceImpl implements KaaAdminService, InitializingBean { @@ -1057,12 +1056,15 @@ public ProfileSchemaViewDto saveProfileSchemaView(ProfileSchemaViewDto profileSc String ctlSchemaId = profileSchema.getCtlSchemaId(); if (isEmpty(ctlSchemaId)) { if (profileSchemaView.useExistingCtlSchema()) { - CTLSchemaMetaInfoDto metaInfo = profileSchemaView.getExistingMetaInfo(); - CTLSchemaInfoDto schemaInfo = getCTLSchemaByFqnAndVersion(metaInfo.getFqn(), metaInfo.getVersion()); - profileSchema.setCtlSchemaId(schemaInfo.getId()); + CtlSchemaReferenceDto metaInfo = profileSchemaView.getExistingMetaInfo(); + CTLSchemaDto schema = getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + metaInfo.getVersion(), + metaInfo.getMetaInfo().getTenantId(), + metaInfo.getMetaInfo().getApplicationId()); + profileSchema.setCtlSchemaId(schema.getId()); } else { CtlSchemaFormDto ctlSchemaForm = saveCTLSchemaForm(profileSchemaView.getCtlSchemaForm()); - profileSchema.setCtlSchemaId(ctlSchemaForm.getCtlSchemaId()); + profileSchema.setCtlSchemaId(ctlSchemaForm.getId()); } } EndpointProfileSchemaDto savedProfileSchema = saveProfileSchema(profileSchema); @@ -1071,6 +1073,25 @@ public ProfileSchemaViewDto saveProfileSchemaView(ProfileSchemaViewDto profileSc throw Utils.handleException(e); } } + + @Override + public ProfileSchemaViewDto createProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) + throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); + EndpointProfileSchemaDto profileSchema = new EndpointProfileSchemaDto(); + profileSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); + profileSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); + profileSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); + CtlSchemaFormDto savedCtlSchemaForm = saveCTLSchemaForm(ctlSchemaForm); + profileSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); + EndpointProfileSchemaDto savedProfileSchema = saveProfileSchema(profileSchema); + return getProfileSchemaView(savedProfileSchema.getId()); + } catch (Exception e) { + throw Utils.handleException(e); + } + } @Override public List getServerProfileSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { @@ -1181,12 +1202,15 @@ public ServerProfileSchemaViewDto saveServerProfileSchemaView(ServerProfileSchem String ctlSchemaId = serverProfileSchema.getCtlSchemaId(); if (isEmpty(ctlSchemaId)) { if (serverProfileSchemaView.useExistingCtlSchema()) { - CTLSchemaMetaInfoDto metaInfo = serverProfileSchemaView.getExistingMetaInfo(); - CTLSchemaInfoDto schemaInfo = getCTLSchemaByFqnAndVersion(metaInfo.getFqn(), metaInfo.getVersion()); - serverProfileSchema.setCtlSchemaId(schemaInfo.getId()); + CtlSchemaReferenceDto metaInfo = serverProfileSchemaView.getExistingMetaInfo(); + CTLSchemaDto schema = getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + metaInfo.getVersion(), + metaInfo.getMetaInfo().getTenantId(), + metaInfo.getMetaInfo().getApplicationId()); + serverProfileSchema.setCtlSchemaId(schema.getId()); } else { CtlSchemaFormDto ctlSchemaForm = saveCTLSchemaForm(serverProfileSchemaView.getCtlSchemaForm()); - serverProfileSchema.setCtlSchemaId(ctlSchemaForm.getCtlSchemaId()); + serverProfileSchema.setCtlSchemaId(ctlSchemaForm.getId()); } } ServerProfileSchemaDto savedServerProfileSchema = saveServerProfileSchema(serverProfileSchema); @@ -1196,6 +1220,25 @@ public ServerProfileSchemaViewDto saveServerProfileSchemaView(ServerProfileSchem } } + @Override + public ServerProfileSchemaViewDto createServerProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) + throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); + ServerProfileSchemaDto serverProfileSchema = new ServerProfileSchemaDto(); + serverProfileSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); + serverProfileSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); + serverProfileSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); + CtlSchemaFormDto savedCtlSchemaForm = saveCTLSchemaForm(ctlSchemaForm); + serverProfileSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); + ServerProfileSchemaDto savedServerProfileSchema = saveServerProfileSchema(serverProfileSchema); + return getServerProfileSchemaView(savedServerProfileSchema.getId()); + } catch (Exception e) { + throw Utils.handleException(e); + } + } + private void convertToSchemaForm(AbstractSchemaDto dto, SchemaFormAvroConverter converter) throws IOException { Schema schema = new Schema.Parser().parse(dto.getSchema()); RecordField schemaForm = converter.createSchemaFormFromSchema(schema); @@ -2862,26 +2905,76 @@ public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfi throw Utils.handleException(e); } } - - /** - * Checks whether the current user has permission to access the given CTL - * schema. The check passes if either the current user and the given CTL - * schema belong to the same tenant or the current user is a - * {@link org.kaaproject.kaa.common.dto.KaaAuthorityDto#KAA_ADMIN} and the - * given CTL schema is - * {@link org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto#SYSTEM}. - * - * @param schema - * A CTL schema to check - * - * @throws KaaAdminServiceException - * - if the check fails. - */ - private void checkCTLAuthority(CTLSchemaDto schema) throws KaaAdminServiceException { + + private CTLSchemaScopeDto detectScope(String tenantId, String applicationId) { + CTLSchemaScopeDto scope = CTLSchemaScopeDto.SYSTEM; + if (tenantId != null && !tenantId.isEmpty()) { + if (applicationId != null && !applicationId.isEmpty()) { + scope = CTLSchemaScopeDto.APPLICATION; + } else { + scope = CTLSchemaScopeDto.TENANT; + } + } + return scope; + } + + private void checkCTLSchemaReadScope(String tenantId, String applicationId) throws KaaAdminServiceException { AuthUserDto currentUser = getCurrentUser(); - if ((schema.getMetaInfo().getScope() != CTLSchemaScopeDto.SYSTEM || currentUser.getAuthority() != KaaAuthorityDto.KAA_ADMIN) - && (schema.getMetaInfo().getScope() == CTLSchemaScopeDto.SYSTEM || !schema.getTenantId().equals(currentUser.getTenantId()))) { - throw new KaaAdminServiceException("You do not have permission to perform this operation!", ServiceErrorCode.PERMISSION_DENIED); + CTLSchemaScopeDto scope = detectScope(tenantId, applicationId); + boolean allowed = false; + switch (currentUser.getAuthority()) { + case KAA_ADMIN: + allowed = scope == CTLSchemaScopeDto.SYSTEM; + break; + case TENANT_ADMIN: + if (scope == CTLSchemaScopeDto.TENANT) { + checkTenantId(tenantId); + } + allowed = scope.getLevel() <= CTLSchemaScopeDto.TENANT.getLevel(); + break; + case TENANT_DEVELOPER: + case TENANT_USER: + if (scope == CTLSchemaScopeDto.TENANT) { + checkTenantId(tenantId); + } + if (scope.getLevel() >= CTLSchemaScopeDto.APPLICATION.getLevel()) { + checkApplicationId(applicationId); + } + allowed = scope.getLevel() >= CTLSchemaScopeDto.SYSTEM.getLevel(); + break; + default: + break; + } + if (!allowed) { + throw new KaaAdminServiceException(ServiceErrorCode.PERMISSION_DENIED); + } + } + + private void checkCTLSchemaEditScope(String tenantId, String applicationId) throws KaaAdminServiceException { + AuthUserDto currentUser = getCurrentUser(); + CTLSchemaScopeDto scope = detectScope(tenantId, applicationId); + boolean allowed = false; + switch (currentUser.getAuthority()) { + case KAA_ADMIN: + allowed = scope == CTLSchemaScopeDto.SYSTEM; + break; + case TENANT_ADMIN: + checkTenantId(tenantId); + allowed = scope == CTLSchemaScopeDto.TENANT; + break; + case TENANT_DEVELOPER: + case TENANT_USER: + checkTenantId(tenantId); + if (scope.getLevel() >= CTLSchemaScopeDto.APPLICATION.getLevel()) { + checkApplicationId(applicationId); + } + allowed = scope.getLevel() >= CTLSchemaScopeDto.TENANT.getLevel(); + break; + default: + break; + } + if (!allowed) { + throw new KaaAdminServiceException(ServiceErrorCode.PERMISSION_DENIED); } } @@ -2890,6 +2983,12 @@ private void checkCTLSchemaId(String schemaId) throws KaaAdminServiceException { throw new IllegalArgumentException("Missing CTL schema ID!"); } } + + private void checkCTLSchemaMetaInfoId(String metaInfoId) throws KaaAdminServiceException { + if (metaInfoId == null || metaInfoId.isEmpty()) { + throw new IllegalArgumentException("Missing CTL schema meta info ID!"); + } + } private void checkCTLSchemaFqn(String fqn) throws KaaAdminServiceException { if (fqn == null || fqn.isEmpty()) { @@ -2905,16 +3004,6 @@ private void checkCTLSchemaVersion(Integer version) throws KaaAdminServiceExcept } } - private CTLSchemaScopeDto getCTLSchemaScopeByName(String name) { - name = name.toUpperCase(); - for (CTLSchemaScopeDto scope : CTLSchemaScopeDto.values()) { - if (name.equals(scope.name())) { - return scope; - } - } - throw new IllegalArgumentException("Invalid CTL schema scope name!"); - } - /** * Returns a string that contains fully qualified names and version numbers * of the given CTL schemas. @@ -2931,83 +3020,45 @@ private String asText(Collection types) { if (types != null) { for (CTLSchemaDto type : types) { CTLSchemaMetaInfoDto details = type.getMetaInfo(); - message.append("\n").append("FQN: ").append(details.getFqn()).append(", version: ").append(details.getVersion()); + message.append("\n").append("FQN: ").append(details.getFqn()).append(", version: ").append(type.getVersion()); } } return message.toString(); } @Override - public CTLSchemaInfoDto saveCTLSchema(String body, CTLSchemaScopeDto scope, String applicationId) throws KaaAdminServiceException { + public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicationId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - CTLSchemaParser parser = new CTLSchemaParser(controlService, getCurrentUser().getTenantId()); - - CTLSchemaInfoDto schema = parser.parse(body, scope, applicationId); - - if (schema.getScope() == CTLSchemaScopeDto.SYSTEM) { - if (schema.getTenantId() != null) { - throw new IllegalArgumentException("A system CTL schema cannot be tied to a tenant!"); - } else if (schema.getApplicationId() != null) { - throw new IllegalArgumentException("A system CTL schema cannot be tied to an application!"); - } - } else if (schema.getScope() == CTLSchemaScopeDto.TENANT) { - if (schema.getTenantId() == null) { - throw new IllegalArgumentException("A tenant CTL schema must include a tenant identifier!"); - } else if (schema.getApplicationId() != null) { - throw new IllegalArgumentException("A tenant CTL schema cannot be tied to an application!"); - } else { - checkTenantId(schema.getTenantId()); - } - } else { - checkApplicationId(schema.getApplicationId()); - } - - Set dependencies = parser.fetchDependencies(schema); - + checkCTLSchemaEditScope(tenantId, applicationId); + CTLSchemaParser parser = new CTLSchemaParser(controlService, tenantId); + CTLSchemaDto schema = parser.parse(body, applicationId); // Check if the schema body is valid parser.validate(schema); - - CTLSchemaDto result = controlService.saveCTLSchema(new CTLSchemaDto(schema, dependencies)); - return result != null ? result.toCTLSchemaInfoDto() : null; + CTLSchemaDto result = controlService.saveCTLSchema(schema); + return result; } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public CTLSchemaInfoDto saveCTLSchema(CTLSchemaInfoDto schema) throws KaaAdminServiceException { + public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { Utils.checkNotNull(schema); - - if (schema.getScope() == CTLSchemaScopeDto.SYSTEM) { - if (schema.getTenantId() != null) { - throw new IllegalArgumentException("A system CTL schema cannot be tied to a tenant!"); - } else if (schema.getApplicationId() != null) { - throw new IllegalArgumentException("A system CTL schema cannot be tied to an application!"); - } - } else if (schema.getScope() == CTLSchemaScopeDto.TENANT) { - if (schema.getTenantId() == null) { - throw new IllegalArgumentException("A tenant CTL schema must include a tenant identifier!"); - } else if (schema.getApplicationId() != null) { - throw new IllegalArgumentException("A tenant CTL schema cannot be tied to an application!"); - } else { - this.checkTenantId(schema.getTenantId()); - } - } else { - this.checkApplicationId(schema.getApplicationId()); - } - - // Check if the schema dependencies are present in the database - List missingDependencies = new ArrayList<>(); + checkCTLSchemaEditScope(schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId()); + // Check if the schema dependencies are present in the database + List missingDependencies = new ArrayList<>(); Set dependencies = new HashSet<>(); - if (schema.getDependencies() != null) { - for (CTLSchemaMetaInfoDto dependency : schema.getDependencies()) { - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionAndTenantId(dependency.getFqn(), dependency.getVersion(), - schema.getTenantId()); + if (schema.getDependencySet() != null) { + for (CTLSchemaDto dependency : schema.getDependencySet()) { + CTLSchemaDto schemaFound = + controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + dependency.getMetaInfo().getFqn(), dependency.getVersion(), + schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId()); if (schemaFound == null) { - missingDependencies.add(dependency); + missingDependencies.add(new FqnVersion(dependency.getMetaInfo().getFqn(), dependency.getVersion())); } else { dependencies.add(schemaFound); } @@ -3019,11 +3070,11 @@ public CTLSchemaInfoDto saveCTLSchema(CTLSchemaInfoDto schema) throws KaaAdminSe } // Check if the schema body is valid - CTLSchemaParser parser = new CTLSchemaParser(controlService, getCurrentUser().getTenantId()); + CTLSchemaParser parser = new CTLSchemaParser(controlService, schema.getMetaInfo().getTenantId()); parser.validate(schema); - CTLSchemaDto result = controlService.saveCTLSchema(new CTLSchemaDto(schema, dependencies)); - return result != null ? result.toCTLSchemaInfoDto() : null; + CTLSchemaDto result = controlService.saveCTLSchema(schema); + return result; } catch (Exception cause) { throw Utils.handleException(cause); } @@ -3036,11 +3087,11 @@ public void deleteCTLSchemaById(String schemaId) throws KaaAdminServiceException this.checkCTLSchemaId(schemaId); CTLSchemaDto schemaFound = controlService.getCTLSchemaById(schemaId); Utils.checkNotNull(schemaFound); - this.checkCTLAuthority(schemaFound); + checkCTLSchemaEditScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); List schemaDependents = controlService.getCTLSchemaDependents(schemaId); if (schemaDependents != null && !schemaDependents.isEmpty()) { - String message = "Unable to delete the CTL schema as it is referenced by the following common type(s): " + String message = "Can't delete the common type version as it is referenced by the following common type(s): " + this.asText(schemaDependents); throw new IllegalArgumentException(message); } @@ -3050,128 +3101,135 @@ public void deleteCTLSchemaById(String schemaId) throws KaaAdminServiceException } @Override - public void deleteCTLSchemaByFqnAndVersion(String fqn, Integer version) throws KaaAdminServiceException { + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { this.checkCTLSchemaFqn(fqn); this.checkCTLSchemaVersion(version); - String tenantId = getCurrentUser().getTenantId(); - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionAndTenantId(fqn, version, tenantId); + if (!isEmpty(applicationId)) { + this.checkApplicationId(applicationId); + } + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); Utils.checkNotNull(schemaFound); - this.checkCTLAuthority(schemaFound); - - List schemaDependents = controlService.getCTLSchemaDependents(fqn, version, tenantId); + checkCTLSchemaEditScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + List schemaDependents = controlService.getCTLSchemaDependents(fqn, version, tenantId, applicationId); if (schemaDependents != null && !schemaDependents.isEmpty()) { - String message = "Unable to delete the CTL schema as it is referenced by the following common type(s): " + String message = "Can't delete the common type version as it is referenced by the following common type(s): " + this.asText(schemaDependents); throw new IllegalArgumentException(message); } - controlService.deleteCTLSchemaByFqnAndVersionAndTenantId(fqn, version, tenantId); + controlService.deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public CTLSchemaInfoDto getCTLSchemaById(String schemaId) throws KaaAdminServiceException { + public CTLSchemaDto getCTLSchemaById(String schemaId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { this.checkCTLSchemaId(schemaId); CTLSchemaDto schemaFound = controlService.getCTLSchemaById(schemaId); Utils.checkNotNull(schemaFound); - if (schemaFound.getMetaInfo().getScope() != CTLSchemaScopeDto.SYSTEM) { - this.checkCTLAuthority(schemaFound); - } - return schemaFound != null ? schemaFound.toCTLSchemaInfoDto() : null; + checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + return schemaFound; } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public CTLSchemaInfoDto getCTLSchemaByFqnAndVersion(String fqn, Integer version) throws KaaAdminServiceException { + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { this.checkCTLSchemaFqn(fqn); this.checkCTLSchemaVersion(version); - String tenantId = getCurrentUser().getTenantId(); - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionAndTenantId(fqn, version, tenantId); - Utils.checkNotNull(schemaFound); - if (schemaFound.getMetaInfo().getScope() != CTLSchemaScopeDto.SYSTEM) { - this.checkCTLAuthority(schemaFound); + if (!isEmpty(applicationId)) { + this.checkApplicationId(applicationId); } - return schemaFound != null ? schemaFound.toCTLSchemaInfoDto() : null; + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + Utils.checkNotNull(schemaFound); + checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + return schemaFound; } catch (Exception cause) { throw Utils.handleException(cause); } } - + @Override - public List getCTLSchemasAvailable() throws KaaAdminServiceException { + public boolean checkFqnExists(String fqn, String tenantId, String applicationId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - String tenantId = getCurrentUser().getTenantId(); - return controlService.getAvailableCTLSchemasMetaInfoByTenantId(tenantId); + this.checkCTLSchemaFqn(fqn); + List result = controlService.getSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId); + return result != null && !result.isEmpty(); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public List getCTLSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkApplicationId(applicationId); - return controlService.getCTLSchemasMetaInfoByApplicationId(applicationId); + checkCTLSchemaEditScope(ctlSchemaMetaInfo.getTenantId(), ctlSchemaMetaInfo.getApplicationId()); + return controlService.updateCTLSchemaMetaInfoScope(ctlSchemaMetaInfo); } catch (Exception cause) { throw Utils.handleException(cause); } } - + @Override - public List getCTLSchemasByScope(String scopeName) throws KaaAdminServiceException { - this.checkAuthority(KaaAuthorityDto.values()); + public List getSystemLevelCTLSchemas() throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.values()); + try { + return controlService.getSystemCTLSchemasMetaInfo(); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + @Override + public List getTenantLevelCTLSchemas() throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { AuthUserDto currentUser = getCurrentUser(); - CTLSchemaScopeDto scope = this.getCTLSchemaScopeByName(scopeName); - if (scope == CTLSchemaScopeDto.TENANT && currentUser.getAuthority() != KaaAuthorityDto.KAA_ADMIN) { - return controlService.getTenantCTLSchemasMetaInfoByTenantId(currentUser.getTenantId()); - } else if (scope == CTLSchemaScopeDto.SYSTEM) { - return controlService.getSystemCTLSchemasMetaInfo(); - } else { - throw new IllegalArgumentException("You do not have permission to perform this operation!"); - } + return controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId()); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public List getTenantCTLSchemaFqns() throws KaaAdminServiceException { + public List getApplicationLevelCTLSchemas(String applicationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { + this.checkApplicationId(applicationId); AuthUserDto currentUser = getCurrentUser(); - List ctlSchemas = controlService.getTenantCTLSchemasMetaInfoByTenantId(currentUser.getTenantId()); - Set ctlSchemaFqns = new HashSet<>(); - for (CTLSchemaMetaInfoDto ctlSchema : ctlSchemas) { - ctlSchemaFqns.add(new SchemaFqnDto(ctlSchema.getFqn(), ctlSchema.getName())); - } - List ctlSchemaFqnsList = new ArrayList<>(); - ctlSchemaFqnsList.addAll(ctlSchemaFqns); - return ctlSchemaFqnsList; + return controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public List getAvailableTenantCTLSchemaReferences() + public List getAvailableApplicationCTLSchemaReferences(String applicationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { + this.checkApplicationId(applicationId); AuthUserDto currentUser = getCurrentUser(); - return controlService.getAvailableCTLSchemasMetaInfoByTenantId(currentUser.getTenantId()); + List result = new ArrayList<>(); + List availableMetaInfo = controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId); + for (CTLSchemaMetaInfoDto metaInfo : availableMetaInfo) { + for (int version : metaInfo.getVersions()) { + result.add(new CtlSchemaReferenceDto(metaInfo, version)); + } + } + return result; } catch (Exception cause) { throw Utils.handleException(cause); } @@ -3179,22 +3237,15 @@ public List getAvailableTenantCTLSchemaReferences() private CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema) throws KaaAdminServiceException { try { - String fqn = ctlSchema.getMetaInfo().getFqn(); - CtlSchemaFormDto ctlSchemaForm = new CtlSchemaFormDto(fqn); - ctlSchemaForm.setCtlSchemaId(ctlSchema.getId()); - ctlSchemaForm.setSchemaName(ctlSchema.getName()); - ctlSchemaForm.setDescription(ctlSchema.getDescription()); - ctlSchemaForm.setCreatedTime(ctlSchema.getCreatedTime()); - ctlSchemaForm.setCreatedUsername(ctlSchema.getCreatedUsername()); - ctlSchemaForm.setHasDependencies(ctlSchema.getDependencySet() != null && !ctlSchema.getDependencySet().isEmpty()); - ctlSchemaForm.setScope(ctlSchema.getMetaInfo().getScope()); - SchemaFormAvroConverter converter = getCtlSchemaConverterForTenantId(getCurrentUser().getTenantId()); + CtlSchemaFormDto ctlSchemaForm = new CtlSchemaFormDto(ctlSchema); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(ctlSchemaForm.getMetaInfo().getTenantId(), ctlSchemaForm.getMetaInfo().getApplicationId()); RecordField form = converter.createSchemaFormFromSchema(ctlSchema.getBody()); ctlSchemaForm.setSchema(form); - List availableVersions = form.getContext().getAvailableVersions(new Fqn(fqn)); + List availableVersions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId( + ctlSchema.getMetaInfo().getFqn(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); availableVersions = availableVersions == null ? Collections.emptyList() : availableVersions; Collections.sort(availableVersions); - ctlSchemaForm.setAvailableVersions(availableVersions); + ctlSchemaForm.getMetaInfo().setVersions(availableVersions); return ctlSchemaForm; } catch (Exception cause) { @@ -3203,49 +3254,63 @@ private CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema) throws KaaAdmin } @Override - public CtlSchemaFormDto getCTLSchemaForm(String fqn, Integer version) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.values()); try { - CtlSchemaFormDto ctlSchemaForm = null; - CTLSchemaDto ctlSchema = controlService.getLatestCTLSchemaByFqn(fqn); - if (ctlSchema != null) { - ctlSchemaForm = toCtlSchemaForm(ctlSchema); - } - return ctlSchemaForm; + this.checkCTLSchemaMetaInfoId(metaInfoId); + CTLSchemaDto ctlSchema = controlService.getLatestCTLSchemaByMetaInfoId(metaInfoId); + Utils.checkNotNull(ctlSchema); + checkCTLSchemaReadScope(ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); + return toCtlSchemaForm(ctlSchema); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public CtlSchemaFormDto createNewCTLSchemaFormInstance(String sourceFqn, - Integer sourceVersion, - CTLSchemaScopeDto scope, - String applicationId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, int version) throws KaaAdminServiceException { + this.checkAuthority(KaaAuthorityDto.values()); try { - AuthUserDto currentUser = getCurrentUser(); - SchemaFormAvroConverter converter = getCtlSchemaConverterForTenantId(currentUser.getTenantId()); - CTLSchemaInfoDto sourceCtlSchema = null; - if (!isEmpty(sourceFqn) && sourceVersion != null) { - sourceCtlSchema = getCTLSchemaByFqnAndVersion(sourceFqn, sourceVersion); + this.checkCTLSchemaMetaInfoId(metaInfoId); + this.checkCTLSchemaVersion(version); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByMetaInfoIdAndVer(metaInfoId, version); + Utils.checkNotNull(schemaFound); + checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + return toCtlSchemaForm(schemaFound); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + @Override + public CtlSchemaFormDto createNewCTLSchemaFormInstance(String metaInfoId, + Integer sourceVersion, String applicationId) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.values()); + try { + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(getCurrentUser().getTenantId(), applicationId); + CtlSchemaFormDto sourceCtlSchema = null; + if (!isEmpty(metaInfoId) && sourceVersion != null) { + sourceCtlSchema = getCTLSchemaFormByMetaInfoIdAndVer(metaInfoId, sourceVersion); + Utils.checkNotNull(sourceCtlSchema); } CtlSchemaFormDto ctlSchemaForm = null; if (sourceCtlSchema != null) { - ctlSchemaForm = new CtlSchemaFormDto(sourceFqn); - ctlSchemaForm.setSchemaName(sourceCtlSchema.getName()); - ctlSchemaForm.setDescription(sourceCtlSchema.getDescription()); - RecordField form = converter.createSchemaFormFromSchema(sourceCtlSchema.getBody()); - form.updateVersion(form.getContext().getMaxVersion(new Fqn(sourceFqn))+1); + checkCTLSchemaEditScope(sourceCtlSchema.getMetaInfo().getTenantId(), sourceCtlSchema.getMetaInfo().getApplicationId()); + ctlSchemaForm = new CtlSchemaFormDto(); + ctlSchemaForm.setMetaInfo(sourceCtlSchema.getMetaInfo()); + RecordField form = sourceCtlSchema.getSchema(); + form.updateVersion(form.getContext().getMaxVersion(new Fqn(sourceCtlSchema.getMetaInfo().getFqn()))+1); ctlSchemaForm.setSchema(form); } else { + checkCTLSchemaEditScope(getCurrentUser().getTenantId(), applicationId); ctlSchemaForm = new CtlSchemaFormDto(); RecordField form = converter.getEmptySchemaFormInstance(); form.updateVersion(1); ctlSchemaForm.setSchema(form); + CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(null, + getCurrentUser().getTenantId(), applicationId); + ctlSchemaForm.setMetaInfo(metaInfo); } - ctlSchemaForm.setScope(scope); - ctlSchemaForm.setApplicationId(applicationId); return ctlSchemaForm; } catch (Exception cause) { throw Utils.handleException(cause); @@ -3253,13 +3318,14 @@ public CtlSchemaFormDto createNewCTLSchemaFormInstance(String sourceFqn, } @Override - public RecordField generateCtlSchemaForm(String fileItemName) + public RecordField generateCtlSchemaForm(String fileItemName, String applicationId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority(KaaAuthorityDto.values()); try { + checkCTLSchemaReadScope(getCurrentUser().getTenantId(), applicationId); byte[] data = getFileContent(fileItemName); String avroSchema = new String(data); - SchemaFormAvroConverter converter = getCtlSchemaConverterForTenantId(getCurrentUser().getTenantId()); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(getCurrentUser().getTenantId(), applicationId); RecordField form = converter.createSchemaFormFromSchema(avroSchema); if (form.getVersion() == null) { form.updateVersion(1); @@ -3272,62 +3338,64 @@ public RecordField generateCtlSchemaForm(String fileItemName) @Override public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority(KaaAuthorityDto.values()); try { AuthUserDto currentUser = getCurrentUser(); - CTLSchemaInfoDto ctlSchemaInfo = null; - if (!isEmpty(ctlSchemaForm.getCtlSchemaId())) { - ctlSchemaInfo = getCTLSchemaById(ctlSchemaForm.getCtlSchemaId()); - if (ctlSchemaInfo == null) { + CTLSchemaDto ctlSchema = null; + if (!isEmpty(ctlSchemaForm.getId())) { + ctlSchema = getCTLSchemaById(ctlSchemaForm.getId()); + if (ctlSchema == null) { throw new KaaAdminServiceException( "Requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); } } else { - ctlSchemaInfo = new CTLSchemaInfoDto(); + ctlSchema = new CTLSchemaDto(); } - ctlSchemaInfo.setName(ctlSchemaForm.getSchemaName()); - ctlSchemaInfo.setDescription(ctlSchemaForm.getDescription()); - - if (isEmpty(ctlSchemaInfo.getId())) { - ctlSchemaInfo.setCreatedUsername(currentUser.getUsername()); + if (isEmpty(ctlSchema.getId())) { + ctlSchema.setCreatedUsername(currentUser.getUsername()); RecordField schemaForm = ctlSchemaForm.getSchema(); - ctlSchemaInfo.setFqn(schemaForm.getDeclaredFqn().getFqnString()); - ctlSchemaInfo.setVersion(schemaForm.getVersion()); + ctlSchema.setMetaInfo(ctlSchemaForm.getMetaInfo()); + ctlSchema.getMetaInfo().setFqn(schemaForm.getDeclaredFqn().getFqnString()); + ctlSchema.getMetaInfo().setTenantId(currentUser.getTenantId()); + ctlSchema.setVersion(schemaForm.getVersion()); List dependenciesList = schemaForm.getContext().getCtlDependenciesList(); - Set dependencies = new HashSet<>(); + Set dependencies = new HashSet<>(); + List missingDependencies = new ArrayList<>(); for (FqnVersion fqnVersion : dependenciesList) { - dependencies.add(new CTLSchemaMetaInfoDto(fqnVersion.getFqnString(), fqnVersion.getVersion())); + CTLSchemaDto dependency = controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqnVersion.getFqnString(), fqnVersion.getVersion(), + ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); + if (dependency != null) { + dependencies.add(dependency); + } else { + missingDependencies.add(fqnVersion); + } } - ctlSchemaInfo.setDependencies(dependencies); - ctlSchemaInfo.setTenantId(currentUser.getTenantId()); - ctlSchemaInfo.setApplicationId(ctlSchemaForm.getApplicationId()); - ctlSchemaInfo.setScope(ctlSchemaForm.getScope()); - - SchemaFormAvroConverter converter = getCtlSchemaConverterForTenantId(currentUser.getTenantId()); + if (!missingDependencies.isEmpty()) { + String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); + throw new IllegalArgumentException(message); + } + ctlSchema.setDependencySet(dependencies); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(ctlSchema.getMetaInfo().getTenantId(), + ctlSchema.getMetaInfo().getApplicationId()); Schema avroSchema = converter.createSchemaFromSchemaForm(schemaForm); String schemaBody = SchemaFormAvroConverter.createSchemaString(avroSchema, true); - ctlSchemaInfo.setBody(schemaBody); + ctlSchema.setBody(schemaBody); } - CTLSchemaInfoDto savedCtlSchemaInfo = saveCTLSchema(ctlSchemaInfo); - if (savedCtlSchemaInfo != null) { - CtlSchemaFormDto result = new CtlSchemaFormDto(savedCtlSchemaInfo.getFqn()); - result.setCtlSchemaId(savedCtlSchemaInfo.getId()); - result.setVersion(savedCtlSchemaInfo.getVersion()); - result.setSchemaName(savedCtlSchemaInfo.getName()); - result.setDescription(savedCtlSchemaInfo.getDescription()); - result.setCreatedTime(savedCtlSchemaInfo.getCreatedTime()); - result.setCreatedUsername(savedCtlSchemaInfo.getCreatedUsername()); - result.setScope(savedCtlSchemaInfo.getScope()); - result.setApplicationId(savedCtlSchemaInfo.getApplicationId()); - SchemaFormAvroConverter converter = getCtlSchemaConverterForTenantId(currentUser.getTenantId()); - RecordField form = converter.createSchemaFormFromSchema(savedCtlSchemaInfo.getBody()); + CTLSchemaDto savedCtlSchema = saveCTLSchema(ctlSchema); + if (savedCtlSchema != null) { + CtlSchemaFormDto result = new CtlSchemaFormDto(savedCtlSchema); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(savedCtlSchema.getMetaInfo().getTenantId(), + savedCtlSchema.getMetaInfo().getApplicationId()); + RecordField form = converter.createSchemaFormFromSchema(savedCtlSchema.getBody()); result.setSchema(form); - List availableVersions = form.getContext().getAvailableVersions(new Fqn(savedCtlSchemaInfo.getFqn())); + List availableVersions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId( + savedCtlSchema.getMetaInfo().getFqn(), savedCtlSchema.getMetaInfo().getTenantId(), savedCtlSchema.getMetaInfo().getApplicationId()); availableVersions = availableVersions == null ? Collections.emptyList() : availableVersions; Collections.sort(availableVersions); - result.setAvailableVersions(availableVersions); + result.getMetaInfo().setVersions(availableVersions); return result; } } catch (Exception cause) { @@ -3336,9 +3404,63 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm) throws return null; } - private SchemaFormAvroConverter getCtlSchemaConverterForTenantId(String tenantId) throws KaaAdminServiceException { + @Override + public boolean checkFqnExists(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.values()); + try { + if (isEmpty(ctlSchemaForm.getId())) { + AuthUserDto currentUser = getCurrentUser(); + RecordField schemaForm = ctlSchemaForm.getSchema(); + String fqn = schemaForm.getDeclaredFqn().getFqnString(); + String tenantId = currentUser.getTenantId(); + return checkFqnExists(fqn, tenantId, ctlSchemaForm.getMetaInfo().getApplicationId()); + } + } catch (Exception cause) { + throw Utils.handleException(cause); + } + return false; + } + + private SchemaFormAvroConverter getCtlSchemaConverterForScope(String tenantId, String applicationId) throws KaaAdminServiceException { + try { + if (isEmpty(tenantId)) { + return getCtlSchemaConverterForSystem(); + } + if (isEmpty(applicationId)) { + return getCtlSchemaConverterForTenant(tenantId); + } + return getCtlSchemaConverterForApplication(tenantId, applicationId); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + private SchemaFormAvroConverter getCtlSchemaConverterForSystem() throws KaaAdminServiceException { + try { + return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForSystem()); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + private SchemaFormAvroConverter getCtlSchemaConverterForTenant(String tenantId) throws KaaAdminServiceException { + try { + return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForTenant(tenantId)); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + private SchemaFormAvroConverter getCtlSchemaConverterForApplication(String tenantId, String applicationId) throws KaaAdminServiceException { + try { + return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForApplication(tenantId, applicationId)); + } catch (Exception cause) { + throw Utils.handleException(cause); + } + } + + private SchemaFormAvroConverter createSchemaConverterFromCtlTypes(final Map> ctlTypes) throws KaaAdminServiceException { try { - final Map> ctlTypes = controlService.getAvailableCTLSchemaVersionsByTenantId(tenantId); CtlSource ctlSource = new CtlSource() { @Override public Map> getCtlTypes() { @@ -3352,16 +3474,14 @@ public Map> getCtlTypes() { } @Override - public FileData exportCTLSchema(String fqn, int version, CTLSchemaExportMethod method) throws KaaAdminServiceException { + public FileData exportCTLSchema(String fqn, int version, String applicationId, CTLSchemaExportMethod method) throws KaaAdminServiceException { try { this.checkCTLSchemaFqn(fqn); this.checkCTLSchemaVersion(version); String tenantId = getCurrentUser().getTenantId(); - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionAndTenantId(fqn, version, tenantId); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); Utils.checkNotNull(schemaFound); - if (schemaFound.getMetaInfo().getScope() != CTLSchemaScopeDto.SYSTEM) { - this.checkCTLAuthority(schemaFound); - } + checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); switch (method) { case SHALLOW: return controlService.exportCTLSchemaShallow(schemaFound); @@ -3380,13 +3500,11 @@ public FileData exportCTLSchema(String fqn, int version, CTLSchemaExportMethod m @Override public String prepareCTLSchemaExport(String ctlSchemaId, CTLSchemaExportMethod method) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority(KaaAuthorityDto.values()); try { CTLSchemaDto schemaFound = controlService.getCTLSchemaById(ctlSchemaId); Utils.checkNotNull(schemaFound); - if (schemaFound.getMetaInfo().getScope() != CTLSchemaScopeDto.SYSTEM) { - this.checkCTLAuthority(schemaFound); - } + checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); CtlSchemaExportKey key = new CtlSchemaExportKey(ctlSchemaId, method); return Base64.encodeObject(key, Base64.URL_SAFE); } catch (Exception e) { @@ -3407,5 +3525,4 @@ public SdkProfileDto checkSdkProfileId(String sdkProfileId) throws KaaAdminServi } } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java index d58c8b859f..2f3b94cc44 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java @@ -78,6 +78,7 @@ public AuthResultDto checkAuth() throws Exception { AuthUserDto authUser = (AuthUserDto)authentication.getPrincipal(); result.setAuthResult(Result.OK); result.setAuthority(authUser.getAuthority()); + result.setTenantId(authUser.getTenantId()); result.setUsername(authUser.getUsername()); String displayName = authUser.getUsername(); if (!isEmpty(authUser.getFirstName()) || !isEmpty(authUser.getLastName())) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java index 252dec2086..ffb2e3942e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 CyberVision, Inc. + * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.node.ObjectNode; +import org.kaaproject.avro.ui.shared.FqnVersion; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.server.admin.services.util.Utils; @@ -59,12 +59,10 @@ public CTLSchemaParser(ControlService controlService, String tenantId) { this.tenantId = tenantId; } - public CTLSchemaInfoDto parse(String body, CTLSchemaScopeDto scope, String applicationId) throws JsonParseException, JsonMappingException, IOException { - CTLSchemaInfoDto schema = new CTLSchemaInfoDto(); - - schema.setTenantId(tenantId); - schema.setApplicationId(applicationId); - schema.setScope(detectScope(scope, applicationId)); + public CTLSchemaDto parse(String body, String applicationId) throws ControlServiceException, JsonParseException, JsonMappingException, IOException { + CTLSchemaDto schema = new CTLSchemaDto(); + CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(); + String fqn = null; ObjectNode object = new ObjectMapper().readValue(body, ObjectNode.class); @@ -77,17 +75,20 @@ public CTLSchemaInfoDto parse(String body, CTLSchemaScopeDto scope, String appli } else if (!object.has("name") || !object.get("name").isTextual()) { throw new IllegalArgumentException("No name specified!"); } else { - schema.setFqn(object.get("namespace").getTextValue() + "." + object.get("name").getTextValue()); + fqn = object.get("namespace").getTextValue() + "." + object.get("name").getTextValue(); } + metaInfo = new CTLSchemaMetaInfoDto(fqn, tenantId, applicationId); + schema.setMetaInfo(metaInfo); if (!object.has("version") || !object.get("version").isInt()) { object.put("version", 1); } schema.setVersion(object.get("version").asInt()); - Set dependencies = new HashSet<>(); + Set dependencies = new HashSet<>(); + List missingDependencies = new ArrayList<>(); if (!object.has("dependencies")) { - schema.setDependencies(dependencies); + schema.setDependencySet(dependencies); } else if (!object.get("dependencies").isArray()) { throw new IllegalArgumentException("Illegal dependencies format!"); } else { @@ -96,65 +97,27 @@ public CTLSchemaInfoDto parse(String body, CTLSchemaScopeDto scope, String appli || !child.get("version").isInt()) { throw new IllegalArgumentException("Illegal dependency format!"); } else { - dependencies.add(new CTLSchemaMetaInfoDto(child.get("fqn").asText(), child.get("version").asInt())); + String dependencyFqn = child.get("fqn").asText(); + int dependencyVersion = child.get("version").asInt(); + + CTLSchemaDto dependency = controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(dependencyFqn, dependencyVersion, tenantId, applicationId); + if (dependency != null) { + dependencies.add(dependency); + } else { + missingDependencies.add(new FqnVersion(dependencyFqn, dependencyVersion)); + } } - schema.setDependencies(dependencies); } + if (!missingDependencies.isEmpty()) { + String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); + throw new IllegalArgumentException(message); + } + schema.setDependencySet(dependencies); } body = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object); schema.setBody(body); return schema; } - - private CTLSchemaScopeDto detectScope(CTLSchemaScopeDto scope, String applicationId) { - if (scope != null) { - if (scope.getLevel() >= CTLSchemaScopeDto.APPLICATION.getLevel() && applicationId == null) { - throw new IllegalArgumentException("Missing application identifier for provided scope " + scope.name() + "!"); - } else if (scope.getLevel() < CTLSchemaScopeDto.APPLICATION.getLevel() && applicationId != null) { - throw new IllegalArgumentException("Application identifier can't be specified for provided scope " + scope.name() + "!"); - } - if (scope == CTLSchemaScopeDto.SYSTEM && tenantId != null) { - throw new IllegalArgumentException("You do not have permission to perform this operation!"); - } - return scope; - } else { - if (tenantId != null && applicationId != null) { - return CTLSchemaScopeDto.APPLICATION; - } else if (tenantId != null && applicationId == null) { - return CTLSchemaScopeDto.TENANT; - } else if (tenantId == null && applicationId == null) { - return CTLSchemaScopeDto.SYSTEM; - } else { - /* - * The Kaa administrator is trying to save an application CTL - * schema. - */ - throw new IllegalArgumentException("You do not have permission to perform this operation!"); - } - } - } - - public Set fetchDependencies(CTLSchemaInfoDto schema) throws ControlServiceException { - // Check if the schema dependencies are present in the database - List missingDependencies = new ArrayList<>(); - Set dependencies = new HashSet<>(); - if (schema.getDependencies() != null) { - for (CTLSchemaMetaInfoDto dependency : schema.getDependencies()) { - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionAndTenantId(dependency.getFqn(), dependency.getVersion(), - schema.getTenantId()); - if (schemaFound == null) { - missingDependencies.add(dependency); - } else { - dependencies.add(schemaFound); - } - } - } - if (!missingDependencies.isEmpty()) { - String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); - throw new IllegalArgumentException(message); - } - return dependencies; - } /** * Parses the given CTL schema along with its dependencies as an @@ -169,17 +132,17 @@ public Set fetchDependencies(CTLSchemaInfoDto schema) throws Contr * - if the given CTL schema is invalid and thus cannot be * parsed. */ - public Schema validate(CTLSchemaInfoDto schema) throws KaaAdminServiceException { - if (schema.getDependencies() != null) { - for (CTLSchemaMetaInfoDto dependency : schema.getDependencies()) { + public Schema validate(CTLSchemaDto schema) throws KaaAdminServiceException { + if (schema.getDependencySet() != null) { + for (CTLSchemaDto dependency : schema.getDependencySet()) { try { - CTLSchemaDto dependencySchema = controlService.getCTLSchemaByFqnVersionAndTenantId(dependency.getFqn(), - dependency.getVersion(), tenantId); + CTLSchemaDto dependencySchema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(dependency.getMetaInfo().getFqn(), + dependency.getVersion(), dependency.getMetaInfo().getTenantId(), dependency.getMetaInfo().getApplicationId()); if (dependencySchema == null) { - String message = "Unable to locate dependency \"" + dependency.getFqn() + "\" (version " + dependency.getVersion() + ")"; + String message = "Unable to locate dependency \"" + dependency.getMetaInfo().getFqn() + "\" (version " + dependency.getVersion() + ")"; throw new IllegalArgumentException(message); } - validate(dependencySchema.toCTLSchemaInfoDto()); + validate(dependencySchema); } catch (Exception cause) { throw Utils.handleException(cause); } @@ -193,7 +156,7 @@ public Schema validate(CTLSchemaInfoDto schema) throws KaaAdminServiceException */ return parser.parse(schema.getBody()); } catch (Exception cause) { - throw new IllegalArgumentException("Unable to parse CTL schema \"" + schema.getFqn() + "\" (version " + schema.getVersion() + "): " + cause.getMessage()); + throw new IllegalArgumentException("Unable to parse CTL schema \"" + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): " + cause.getMessage()); } } } \ No newline at end of file diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/BaseSchemaViewDto.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/BaseSchemaViewDto.java index b52e487a10..555867f5d7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/BaseSchemaViewDto.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/BaseSchemaViewDto.java @@ -20,7 +20,6 @@ import org.kaaproject.kaa.common.dto.BaseSchemaDto; import org.kaaproject.kaa.common.dto.HasId; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; public abstract class BaseSchemaViewDto implements Serializable, HasId { @@ -28,7 +27,7 @@ public abstract class BaseSchemaViewDto implements Seri private T schema; private CtlSchemaFormDto ctlSchemaForm; - private CTLSchemaMetaInfoDto existingMetaInfo; + private CtlSchemaReferenceDto existingMetaInfo; private boolean useExistingCtlSchema = false; public BaseSchemaViewDto() { @@ -75,11 +74,11 @@ public void setId(String id) { schema.setId(id); } - public CTLSchemaMetaInfoDto getExistingMetaInfo() { + public CtlSchemaReferenceDto getExistingMetaInfo() { return existingMetaInfo; } - public void setExistingMetaInfo(CTLSchemaMetaInfoDto existingMetaInfo) { + public void setExistingMetaInfo(CtlSchemaReferenceDto existingMetaInfo) { this.existingMetaInfo = existingMetaInfo; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaFormDto.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaFormDto.java index 4f6685c6a6..6d579921b1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaFormDto.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaFormDto.java @@ -16,68 +16,30 @@ package org.kaaproject.kaa.server.admin.shared.schema; -import java.util.List; - import org.kaaproject.avro.ui.shared.RecordField; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; -public class CtlSchemaFormDto extends SchemaFqnDto { +public class CtlSchemaFormDto extends CTLSchemaDto { private static final long serialVersionUID = -5383847121615543863L; - private String ctlSchemaId; - private Integer version; - private CTLSchemaScopeDto scope; - private String applicationId; private RecordField schema; private boolean hasDependencies; - private String description; - private String createdUsername; - private long createdTime; - - private List availableVersions; - public CtlSchemaFormDto() { super(); } - - public CtlSchemaFormDto(String fqnString) { - super(fqnString); - } - - public String getCtlSchemaId() { - return ctlSchemaId; - } - - public void setCtlSchemaId(String ctlSchemaId) { - this.ctlSchemaId = ctlSchemaId; - } - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public CTLSchemaScopeDto getScope() { - return scope; - } - - public void setScope(CTLSchemaScopeDto scope) { - this.scope = scope; + public CtlSchemaFormDto(CTLSchemaDto ctlSchema) { + super(); + setId(ctlSchema.getId()); + setMetaInfo(ctlSchema.getMetaInfo()); + setVersion(ctlSchema.getVersion()); + setCreatedTime(ctlSchema.getCreatedTime()); + setCreatedUsername(ctlSchema.getCreatedUsername()); + setHasDependencies(ctlSchema.getDependencySet() != null && !ctlSchema.getDependencySet().isEmpty()); } - public String getApplicationId() { - return applicationId; - } - - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } - public RecordField getSchema() { return schema; } @@ -94,36 +56,4 @@ public void setHasDependencies(boolean hasDependencies) { this.hasDependencies = hasDependencies; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCreatedUsername() { - return createdUsername; - } - - public void setCreatedUsername(String createdUsername) { - this.createdUsername = createdUsername; - } - - public long getCreatedTime() { - return createdTime; - } - - public void setCreatedTime(long createdTime) { - this.createdTime = createdTime; - } - - public List getAvailableVersions() { - return availableVersions; - } - - public void setAvailableVersions(List availableVersions) { - this.availableVersions = availableVersions; - } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaReferenceDto.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaReferenceDto.java new file mode 100644 index 0000000000..1db35e3e68 --- /dev/null +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/CtlSchemaReferenceDto.java @@ -0,0 +1,84 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.kaa.server.admin.shared.schema; + +import java.io.Serializable; + +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; + +public class CtlSchemaReferenceDto implements Serializable +{ + private static final long serialVersionUID = -6668598697779214725L; + + private CTLSchemaMetaInfoDto metaInfo; + private int version; + + public CtlSchemaReferenceDto() { + super(); + } + + public CtlSchemaReferenceDto(CTLSchemaMetaInfoDto metaInfo, int version) { + super(); + this.metaInfo = metaInfo; + this.version = version; + } + + public CTLSchemaMetaInfoDto getMetaInfo() { + return metaInfo; + } + + public void setMetaInfo(CTLSchemaMetaInfoDto metaInfo) { + this.metaInfo = metaInfo; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((metaInfo == null) ? 0 : metaInfo.hashCode()); + result = prime * result + version; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CtlSchemaReferenceDto other = (CtlSchemaReferenceDto) obj; + if (metaInfo == null) { + if (other.metaInfo != null) + return false; + } else if (!metaInfo.equals(other.metaInfo)) + return false; + if (version != other.version) + return false; + return true; + } + +} diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/SchemaFqnDto.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/SchemaFqnDto.java deleted file mode 100644 index df6bb88467..0000000000 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/schema/SchemaFqnDto.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014-2015 CyberVision, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kaaproject.kaa.server.admin.shared.schema; - -import org.kaaproject.avro.ui.shared.Fqn; -import org.kaaproject.kaa.common.dto.HasId; - -public class SchemaFqnDto extends Fqn implements HasId { - - private static final long serialVersionUID = 3962779315398811005L; - - private String schemaName; - - public SchemaFqnDto() { - super(); - } - - public SchemaFqnDto(Fqn fqn) { - super(fqn); - } - - public SchemaFqnDto(String fqnString) { - super(fqnString); - } - - public SchemaFqnDto(String fqnString, String schemaName) { - super(fqnString); - this.schemaName = schemaName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName(String schemaName) { - this.schemaName = schemaName; - } - - @Override - public String getId() { - return getFqnString(); - } - - @Override - public void setId(String id) {} - -} 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 248e5e2aad..10909fc764 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 @@ -46,10 +46,9 @@ import org.kaaproject.kaa.common.dto.admin.SdkProfileViewDto; import org.kaaproject.kaa.common.dto.admin.TenantUserDto; import org.kaaproject.kaa.common.dto.admin.UserDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaExportMethod; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.EcfInfoDto; @@ -66,8 +65,8 @@ 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.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.SchemaFqnDto; import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto; import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto; @@ -175,6 +174,8 @@ public interface KaaAdminService extends RemoteService { public ProfileSchemaViewDto saveProfileSchemaView(ProfileSchemaViewDto profileSchema) throws KaaAdminServiceException; + public ProfileSchemaViewDto createProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; + public List getConfigurationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException; public ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaId) throws KaaAdminServiceException; @@ -355,40 +356,44 @@ public interface KaaAdminService extends RemoteService { public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfiguration, String applicationId, RecordField configurationData) throws KaaAdminServiceException; - public CTLSchemaInfoDto saveCTLSchema(String body, CTLSchemaScopeDto scope, String applicationId) throws KaaAdminServiceException; + public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicationId) throws KaaAdminServiceException; - public CTLSchemaInfoDto saveCTLSchema(CTLSchemaInfoDto schema) throws KaaAdminServiceException; + public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceException; public void deleteCTLSchemaById(String schemaId) throws KaaAdminServiceException; - public void deleteCTLSchemaByFqnAndVersion(String fqn, Integer version) throws KaaAdminServiceException; - - public CTLSchemaInfoDto getCTLSchemaById(String schemaId) throws KaaAdminServiceException; - - public CTLSchemaInfoDto getCTLSchemaByFqnAndVersion(String fqn, Integer version) throws KaaAdminServiceException; + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) throws KaaAdminServiceException; - public List getCTLSchemasAvailable() throws KaaAdminServiceException; + public CTLSchemaDto getCTLSchemaById(String schemaId) throws KaaAdminServiceException; - public List getCTLSchemasByScope(String scopeName) throws KaaAdminServiceException; + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) throws KaaAdminServiceException; - public List getCTLSchemasByApplicationId(String applicationId) throws KaaAdminServiceException; + public boolean checkFqnExists(String fqn, String tenantId, String applicationId) throws KaaAdminServiceException; + + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) throws KaaAdminServiceException; + + public List getSystemLevelCTLSchemas() throws KaaAdminServiceException; - public List getTenantCTLSchemaFqns() throws KaaAdminServiceException; + public List getTenantLevelCTLSchemas() throws KaaAdminServiceException; - public List getAvailableTenantCTLSchemaReferences() throws KaaAdminServiceException; + public List getApplicationLevelCTLSchemas(String applicationId) throws KaaAdminServiceException; - public CtlSchemaFormDto getCTLSchemaForm(String fqn, Integer version) throws KaaAdminServiceException; + public List getAvailableApplicationCTLSchemaReferences(String applicationId) throws KaaAdminServiceException; - public CtlSchemaFormDto createNewCTLSchemaFormInstance(String sourceFqn, - Integer sourceVersion, - CTLSchemaScopeDto scope, - String applicationId) throws KaaAdminServiceException; + public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) throws KaaAdminServiceException; - public RecordField generateCtlSchemaForm(String fileItemName) throws KaaAdminServiceException; + public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, int version) throws KaaAdminServiceException; + + public CtlSchemaFormDto createNewCTLSchemaFormInstance(String metaInfoId, + Integer sourceVersion, String applicationId) throws KaaAdminServiceException; + + public RecordField generateCtlSchemaForm(String fileItemName, String applicationId) throws KaaAdminServiceException; public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; - public FileData exportCTLSchema(String fqn, int version, CTLSchemaExportMethod method) throws KaaAdminServiceException; + public boolean checkFqnExists(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; + + public FileData exportCTLSchema(String fqn, int version, String applicationId, CTLSchemaExportMethod method) throws KaaAdminServiceException; public String prepareCTLSchemaExport(String ctlSchemaId, CTLSchemaExportMethod method) throws KaaAdminServiceException; @@ -406,6 +411,8 @@ public CtlSchemaFormDto createNewCTLSchemaFormInstance(String sourceFqn, public ServerProfileSchemaViewDto saveServerProfileSchemaView(ServerProfileSchemaViewDto serverProfileSchema) throws KaaAdminServiceException; + public ServerProfileSchemaViewDto createServerProfileSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; + public SchemaInfoDto getEndpointProfileSchemaInfo(String endpointProfileSchemaId) throws KaaAdminServiceException; public SchemaInfoDto getServerProfileSchemaInfo(String serverProfileSchemaId) throws KaaAdminServiceException; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java index 90e1d25a3f..05dd223042 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java @@ -1352,20 +1352,9 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil */ CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws ControlServiceException; - /** - * Deletes a CTL schema from the database by its identifier. - * - * @param schemaId - * A CTL schema identifier - * - * @throws ControlServiceException - * - if an exception occures. - */ - void deleteCTLSchemaById(String schemaId) throws ControlServiceException; - /** * Deletes a CTL schema from the database by its fully qualified name, - * version number and tenant identifier. + * version number, tenant and application identifier. * * @param fqn * A fully qualified CTL schema name @@ -1373,11 +1362,13 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil * A CTL schema version number * @param tenantId * A tenant identifier + * @param applicationId + * An application identifier * * @throws ControlServiceException * - if an exception occures. */ - void deleteCTLSchemaByFqnAndVersionAndTenantId(String fqn, int version, String tenantId) throws ControlServiceException; + void deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException; /** * Returns a CTL schema by its identifier. @@ -1393,8 +1384,8 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil CTLSchemaDto getCTLSchemaById(String schemaId) throws ControlServiceException; /** - * Returns a CTL schema by its fully qualified name, version number and - * tenant identifier. + * Returns a CTL schema by its fully qualified name, version number, + * tenant and application identifier. * * @param fqn * A fully qualified CTL schema name @@ -1402,69 +1393,113 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil * A CTL schema version number * @param tenantId * A tenant identifier + * @param applicationId + * An application identifier * - * @return A CTL schema with the given fully qualified name, version number - * and tenant identifier + * @return A CTL schema with the given fully qualified name, version number, + * tenant and application identifier * * @throws ControlServiceException * - if an exception occures. */ - CTLSchemaDto getCTLSchemaByFqnVersionAndTenantId(String fqn, int version, String tenantId) throws ControlServiceException; - + CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException; + /** - * Returns meta information about CTL schemas that are available for use by - * a tenant with the given identifier + * Returns a CTL schema with the given meta info id and version. + * + * @param metaInfoId the id of meta info object. + * @param version the schema version. + * @return the CTL schema with the given meta info id and version. + */ + CTLSchemaDto getCTLSchemaByMetaInfoIdAndVer(String metaInfoId, Integer version); + + /** + * Returns any CTL schema by its fully qualified name, version number, + * tenant and application identifier. * + * @param fqn + * A fully qualified CTL schema name + * @param version + * A CTL schema version number * @param tenantId * A tenant identifier + * @param applicationId + * An application identifier * - * @return Meta information about CTL schemas that are available for use by - * a tenant with the given identifier + * @return Any CTL schema with the given fully qualified name, version number, + * tenant and application identifier * * @throws ControlServiceException * - if an exception occures. */ - List getAvailableCTLSchemasMetaInfoByTenantId(String tenantId) throws ControlServiceException; - + CTLSchemaDto getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException; + /** - * Returns meta information about CTL schemas that are tied to a tenant with - * the given tenant identifier and tenant scope. - * - * @param tenantId - * A tenant identifier + * Get CTL schema meta infos which are the application level siblings to the CTL + * of the given fully qualified name, tenant and application identifiers. + * + * @param fqn the fully qualified. + * @param tenantId the tenant identifier. + * @param applicationId the application identifier. + * @return the CTL schema meta information objects which are the siblings to the given CTL. + */ + List getSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId); + + /** + * Update existing CTL schema meta info scope by the given CTL schema meta info object. + * + * @param ctlSchemaMetaInfo + * the CTL schema meta info object. + * @return CTLSchemaMetaInfoDto the updated CTL schema meta info object. + */ + CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo); + + /** + * Returns meta information about system CTL schemas. * - * @return Meta information about CTL schemas that are tied to a tenant with - * the given tenant identifier + * @return Meta information about system CTL schemas * * @throws ControlServiceException * - if an exception occures. */ - List getTenantCTLSchemasMetaInfoByTenantId(String tenantId) throws ControlServiceException; + List getSystemCTLSchemasMetaInfo() throws ControlServiceException; + + Map> getAvailableCTLSchemaVersionsForSystem() throws ControlServiceException; /** - * Returns meta information about CTL schemas that are tied to an - * application with the given application identifier. + * Returns meta information about CTL schemas that are available for use by + * a tenant with the given identifier * - * @param applicationId - * An application identifier + * @param tenantId + * A tenant identifier * - * @return Meta information about CTL schemas that are tied to an - * application with the given application identifier + * @return Meta information about CTL schemas that are available for use by + * a tenant with the given identifier * * @throws ControlServiceException * - if an exception occures. */ - List getCTLSchemasMetaInfoByApplicationId(String applicationId) throws ControlServiceException; - + List getAvailableCTLSchemasMetaInfoForTenant(String tenantId) throws ControlServiceException; + + Map> getAvailableCTLSchemaVersionsForTenant(String tenantId) throws ControlServiceException; + /** - * Returns meta information about system CTL schemas. + * Returns meta information about CTL schemas that are available for use by + * an application with the given identifier * - * @return Meta information about system CTL schemas + * @param tenantId + * A tenant identifier + * @param appId + * An application identifier + * @return Meta information about CTL schemas that are available for use by + * a tenant with the given identifier * * @throws ControlServiceException * - if an exception occures. */ - List getSystemCTLSchemasMetaInfo() throws ControlServiceException; + List getAvailableCTLSchemasMetaInfoForApplication(String tenantId, String appId) throws ControlServiceException; + + Map> getAvailableCTLSchemaVersionsForApplication(String tenantId, String appId) throws ControlServiceException; /** * Returns CTL schemas that reference a CTL schema with the given @@ -1482,7 +1517,7 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil /** * Returns CTL schemas that reference a CTL schema with the given fully - * qualified name, version number and tenant identifier. + * qualified name, version number, tenant and application identifier. * * @param fqn * A fully qualified CTL schema name @@ -1490,19 +1525,29 @@ ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamil * A CTL schema version number * @param tenantId * A tenant identifier - * + * @param applicationId + * An application identifier + * * @return CTL schemas that reference a CTL schema with the given fully - * qualified name, version number and tenant identifier + * qualified name, version number, tenant and application identifier * * @throws ControlServiceException * - if an exception occures. */ - List getCTLSchemaDependents(String fqn, int version, String tenantId) throws ControlServiceException; + List getCTLSchemaDependents(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException; - CTLSchemaDto getLatestCTLSchemaByFqn(String fqn) throws ControlServiceException; + CTLSchemaDto getLatestCTLSchemaByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) throws ControlServiceException; - Map> getAvailableCTLSchemaVersionsByTenantId(String tenantId) throws ControlServiceException; + List getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) throws ControlServiceException; + /** + * Returns the last version of CTL schema with the given meta info id. + * + * @param metaInfoId the id of meta info object. + * @return the latest version of CTL schema with the given meta info id. + */ + CTLSchemaDto getLatestCTLSchemaByMetaInfoId(String metaInfoId); + /** * Exports the body of a CTL schema. * 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 f158504600..12cb92a9f8 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 @@ -2027,13 +2027,8 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws ControlServiceExce } @Override - public void deleteCTLSchemaById(String schemaId) throws ControlServiceException { - ctlService.removeCTLSchemaById(schemaId); - } - - @Override - public void deleteCTLSchemaByFqnAndVersionAndTenantId(String fqn, int version, String tenantId) throws ControlServiceException { - ctlService.removeCTLSchemaByFqnAndVerAndTenantId(fqn, version, tenantId); + public void deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException { + ctlService.removeCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); } @Override @@ -2042,62 +2037,99 @@ public CTLSchemaDto getCTLSchemaById(String schemaId) throws ControlServiceExcep } @Override - public CTLSchemaDto getCTLSchemaByFqnVersionAndTenantId(String fqn, int version, String tenantId) throws ControlServiceException { - return ctlService.findCTLSchemaByFqnAndVerAndTenantId(fqn, version, tenantId); + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException { + return ctlService.findCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); } - + @Override - public List getAvailableCTLSchemasMetaInfoByTenantId(String tenantId) throws ControlServiceException { - return ctlService.findAvailableCTLSchemasMetaInfo(tenantId); + public CTLSchemaDto getCTLSchemaByMetaInfoIdAndVer(String metaInfoId, Integer version) { + return ctlService.findByMetaInfoIdAndVer(metaInfoId, version); } @Override - public List getTenantCTLSchemasMetaInfoByTenantId(String tenantId) throws ControlServiceException { - return ctlService.findTenantCTLSchemasMetaInfoByTenantId(tenantId); + public CTLSchemaDto getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int version, String tenantId, + String applicationId) throws ControlServiceException { + return ctlService.findAnyCTLSchemaByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); } - + @Override - public List getCTLSchemasMetaInfoByApplicationId(String applicationId) throws ControlServiceException { - return ctlService.findCTLSchemasMetaInfoByApplicationId(applicationId); + public List getSiblingsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { + return ctlService.findSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId); + } + + @Override + public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) { + return ctlService.updateCTLSchemaMetaInfoScope(ctlSchemaMetaInfo); } @Override public List getSystemCTLSchemasMetaInfo() throws ControlServiceException { return ctlService.findSystemCTLSchemasMetaInfo(); } - + @Override - public List getCTLSchemaDependents(String schemaId) throws ControlServiceException { - return ctlService.findCTLSchemaDependents(schemaId); + public Map> getAvailableCTLSchemaVersionsForSystem() throws ControlServiceException { + return extractCtlSchemaVersionsInfo(ctlService.findSystemCTLSchemasMetaInfo()); } @Override - public List getCTLSchemaDependents(String fqn, int version, String tenantId) throws ControlServiceException { - return ctlService.findCTLSchemaDependents(fqn, version, tenantId); + public List getAvailableCTLSchemasMetaInfoForTenant(String tenantId) throws ControlServiceException { + return ctlService.findAvailableCTLSchemasMetaInfoForTenant(tenantId); } - + @Override - public CTLSchemaDto getLatestCTLSchemaByFqn(String fqn) throws ControlServiceException { - return ctlService.findLatestCTLSchemaByFqn(fqn); + public Map> getAvailableCTLSchemaVersionsForTenant(String tenantId) throws ControlServiceException { + return extractCtlSchemaVersionsInfo(ctlService.findAvailableCTLSchemasMetaInfoForTenant(tenantId)); } - + @Override - public Map> getAvailableCTLSchemaVersionsByTenantId( - String tenantId) throws ControlServiceException { + public List getAvailableCTLSchemasMetaInfoForApplication(String tenantId, String appId) throws ControlServiceException { + return ctlService.findAvailableCTLSchemasMetaInfoForApplication(tenantId, appId); + } + + @Override + public Map> getAvailableCTLSchemaVersionsForApplication(String tenantId, String appId) throws ControlServiceException { + return extractCtlSchemaVersionsInfo(ctlService.findAvailableCTLSchemasMetaInfoForApplication(tenantId, appId)); + } + + private Map> extractCtlSchemaVersionsInfo(List ctlSchemaInfos) { Map> ctlSchemaVersions = new HashMap<>(); - List ctlSchemaInfos = ctlService.findAvailableCTLSchemasMetaInfo(tenantId); for (CTLSchemaMetaInfoDto ctlSchemaInfo : ctlSchemaInfos) { - Fqn fqn = new Fqn(ctlSchemaInfo.getFqn()); - List schemaVersions = ctlSchemaVersions.get(fqn); - if (schemaVersions == null) { - schemaVersions = new ArrayList<>(); - ctlSchemaVersions.put(fqn, schemaVersions); - } - schemaVersions.add(ctlSchemaInfo.getVersion()); + ctlSchemaVersions.put(new Fqn(ctlSchemaInfo.getFqn()), ctlSchemaInfo.getVersions()); } return ctlSchemaVersions; } + + @Override + public List getCTLSchemaDependents(String schemaId) throws ControlServiceException { + return ctlService.findCTLSchemaDependents(schemaId); + } + + @Override + public List getCTLSchemaDependents(String fqn, int version, String tenantId, String applicationId) throws ControlServiceException { + return ctlService.findCTLSchemaDependents(fqn, version, tenantId, applicationId); + } + + @Override + public CTLSchemaDto getLatestCTLSchemaByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) throws ControlServiceException { + return ctlService.findLatestCTLSchemaByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId); + } + + @Override + public CTLSchemaDto getLatestCTLSchemaByMetaInfoId(String metaInfoId) { + return ctlService.findLatestByMetaInfoId(metaInfoId); + } + @Override + public List getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) throws ControlServiceException { + List schemas = ctlService.findAllCTLSchemasByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId); + List versions = new ArrayList<>(schemas.size()); + for (CTLSchemaDto schema : schemas) { + versions.add(schema.getVersion()); + } + return versions; + } + public FileData exportCTLSchemaShallow(CTLSchemaDto schema) throws ControlServiceException { return ctlService.shallowExport(schema); } @@ -2112,7 +2144,7 @@ public FileData exportCTLSchemaFlatAsLibrary(CTLSchemaDto schema) throws Control try { Schema avroSchema = ctlService.flatExportAsSchema(schema); String fileName = MessageFormat.format(CTL_LIBRARY_EXPORT_TEMPLATE, - schema.getMetaInfo().getFqn(), schema.getMetaInfo().getVersion()); + schema.getMetaInfo().getFqn(), schema.getVersion()); return SchemaLibraryGenerator.generateSchemaLibrary(avroSchema, fileName); } catch (Exception e) { LOG.error("Unable to export flat CTL schema as library", e); @@ -2145,6 +2177,4 @@ public SdkProfileDto findSdkProfileByToken(String sdkToken) throws ControlServic } } - - } diff --git a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/KaaAdminTheme.css b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/KaaAdminTheme.css index 24f3081c21..0d7668a135 100755 --- a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/KaaAdminTheme.css +++ b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/KaaAdminTheme.css @@ -342,6 +342,18 @@ text-shadow: 0 1px rgba(0, 0, 0, 0.3); } +.deleteButton { + background: #d94b4b; +} + +.deleteButton:hover { + background: #cc4b4b; +} + +.deleteButton:active { + background: #c47575; +} + .button-margin-left { margin-left: 300px; margin-right: 35px; diff --git a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminConstants.properties b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminConstants.properties index 2bf77f73cb..0e6156f001 100644 --- a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminConstants.properties +++ b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminConstants.properties @@ -29,7 +29,7 @@ addNewAefMap = Add event family mapping addNewApplication = Add application -addNewCtl = Add new common type +addNewCtl = Add new type addNewEcf = Add ECF @@ -85,7 +85,7 @@ applicationDetails = Application details applications = Applications -author = Author +author = Created by available = Available @@ -139,7 +139,19 @@ createNewType = Create new type createNewVersion = Create new version -ctl = Common types library +ctl = Common type library + +systemCtl = System CTL + +tenantCtl = Tenant CTL + +applicationCtl = Application CTL + +applicationCtlTitle = Application Common Type Library + +systemCtlTitle = System Common Type Library + +tenantCtlTitle = Tenant Common Type Library dateCreated = Date created @@ -307,9 +319,9 @@ login = Login mandatory = Mandatory -maxVersion = Max schema version +maxSchemaVersion = Max schema version -minVersion = Min schema version +minSchemaVersion = Min schema version name = Name @@ -552,3 +564,25 @@ filterMatched = Filter is matched filterNotMatched = Filter is not matched downloadJson = Download JSON + +scope = Scope + +scopeSystem = System + +scopeTenant = Tenant + +scopeApplication = Application + +scopeSystemTitle = System scope + +scopeTenantTitle = Tenant scope + +scopeApplicationTitle = Application scope + +versionsCount = Versions count + +maxVersion = Max version + +promote = Promote + +displayHigherScopes = Display higher scopes diff --git a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminMessages.properties b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminMessages.properties index 23c3d71839..b04e2454bc 100644 --- a/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminMessages.properties +++ b/server/node/src/main/resources/org/kaaproject/kaa/server/admin/client/i18n/KaaAdminMessages.properties @@ -1,15 +1,19 @@ -deleteCommonTypeVersionQuestion = Are you sure you want to delete common type ''{0}'' with version ''{1}''? +deleteCommonTypeVersionQuestion = Are you sure you want to delete version ''{1}'' of the common type ''{0}''? deleteCommonTypeVersionTitle = Delete common type version +commonTypeFqnAlreadyExistsQuestion = Common type with specified fqn already exists in system. Are you sure you want to create it? + +commonTypeFqnAlreadyExistTitle = Common type already exists + deleteSelectedEntryQuestion = Are you sure you want to delete the selected entry? deleteSelectedEntryTitle = Delete the entry detailsMayStopMessage = You have unsaved changes on this form. If you navigate away from this page without first saving, all the changes will be lost. -emptyEndpointKeyHash = Enter endpoint keyhash. +emptyEndpointKeyHash = Enter the endpoint keyhash emptyUsernameOrPassword = The username and the password cannot be empty! 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 abc20a0410..6543291082 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 @@ -44,19 +44,20 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.runner.RunWith; +import org.kaaproject.avro.ui.shared.FqnVersion; import org.kaaproject.kaa.common.avro.GenericAvroConverter; import org.kaaproject.kaa.common.dto.ApplicationDto; import org.kaaproject.kaa.common.dto.ConfigurationDto; 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.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.HasId; import org.kaaproject.kaa.common.dto.KaaAuthorityDto; 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.ProfileFilterDto; -import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; import org.kaaproject.kaa.common.dto.TopicDto; import org.kaaproject.kaa.common.dto.TopicTypeDto; @@ -64,9 +65,7 @@ import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.common.dto.admin.TenantUserDto; import org.kaaproject.kaa.common.dto.admin.UserDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventAction; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventMapDto; @@ -96,7 +95,7 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpStatusCodeException; import com.mongodb.DB; @@ -457,14 +456,7 @@ protected interface TestRestCall { * @throws Exception the exception */ protected void checkNotFound(TestRestCall restCall) throws Exception { - HttpStatus errorStatus = null; - try { - restCall.executeRestCall(); - } catch (HttpClientErrorException e) { - errorStatus = e.getStatusCode(); - } - Assert.assertNotNull(errorStatus); - Assert.assertEquals(HttpStatus.NOT_FOUND, errorStatus); + checkRestErrorStatusCode(restCall, HttpStatus.NOT_FOUND); } /** @@ -474,14 +466,7 @@ protected void checkNotFound(TestRestCall restCall) throws Exception { * @throws Exception the exception */ protected void checkBadRequest(TestRestCall restCall) throws Exception { - HttpStatus errorStatus = null; - try { - restCall.executeRestCall(); - } catch (HttpClientErrorException e) { - errorStatus = e.getStatusCode(); - } - Assert.assertNotNull(errorStatus); - Assert.assertEquals(HttpStatus.BAD_REQUEST, errorStatus); + checkRestErrorStatusCode(restCall, HttpStatus.BAD_REQUEST); } /** @@ -491,14 +476,18 @@ protected void checkBadRequest(TestRestCall restCall) throws Exception { * @throws Exception the exception */ protected void checkForbidden(TestRestCall restCall) throws Exception { + checkRestErrorStatusCode(restCall, HttpStatus.FORBIDDEN); + } + + protected void checkRestErrorStatusCode(TestRestCall restCall, HttpStatus expectedStatus) throws Exception { HttpStatus errorStatus = null; try { restCall.executeRestCall(); - } catch (HttpClientErrorException e) { + } catch (HttpStatusCodeException e) { errorStatus = e.getStatusCode(); } Assert.assertNotNull(errorStatus); - Assert.assertEquals(HttpStatus.FORBIDDEN, errorStatus); + Assert.assertEquals(expectedStatus, errorStatus); } /** @@ -704,7 +693,7 @@ protected EndpointProfileSchemaDto createEndpointProfileSchema(String applicatio profileSchema.setApplicationId(applicationId); } if (strIsEmpty(ctlSchemaId)) { - CTLSchemaInfoDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); + CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null); profileSchema.setCtlSchemaId(ctlSchema.getId()); } else { profileSchema.setCtlSchemaId(ctlSchemaId); @@ -734,7 +723,7 @@ protected ServerProfileSchemaDto createServerProfileSchema(String applicationId, profileSchema.setApplicationId(applicationId); } if (strIsEmpty(ctlSchemaId)) { - CTLSchemaInfoDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); + CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null); profileSchema.setCtlSchemaId(ctlSchema.getId()); } loginTenantDeveloper(tenantDeveloperDto.getUsername()); @@ -1262,8 +1251,8 @@ protected String ctlRandomFieldType() { return CTL_DEFAULT_TYPE + random.nextInt(100000); } - protected CTLSchemaInfoDto createCTLSchema(String name, String namespace, int version, - CTLSchemaScopeDto scope, String applicationId, Set dependencies, + protected CTLSchemaDto createCTLSchema(String name, String namespace, int version, + String tenantId, String applicationId, Set dependencies, Map fields) throws Exception { LOG.debug("Generating CTL schema..."); @@ -1276,19 +1265,11 @@ protected CTLSchemaInfoDto createCTLSchema(String name, String namespace, int ve body.put("namespace", namespace); body.put("version", version); - // The argument is left for readability only - if (scope == CTLSchemaScopeDto.APPLICATION) { - if (strIsEmpty(applicationId)) { - ApplicationDto application = this.createApplication(); - applicationId = application.getId(); - } - } - if (dependencies != null && !dependencies.isEmpty()) { ArrayNode array = factory.arrayNode(); - for (CTLSchemaMetaInfoDto dependency : dependencies) { + for (FqnVersion dependency : dependencies) { ObjectNode object = factory.objectNode(); - object.put("fqn", dependency.getFqn()); + object.put("fqn", dependency.getFqnString()); object.put("version", dependency.getVersion()); array.add(object); } @@ -1308,7 +1289,7 @@ protected CTLSchemaInfoDto createCTLSchema(String name, String namespace, int ve LOG.debug("CTL schema generated: " + body); - return client.saveCTLSchema(body.toString(), scope, scope == CTLSchemaScopeDto.APPLICATION ? applicationId : null); + return client.saveCTLSchema(body.toString(), tenantId, applicationId); } /** diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerCTLSchemaIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerCTLSchemaIT.java index 5dfc81f2a2..e14d4ca7e3 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerCTLSchemaIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerCTLSchemaIT.java @@ -23,9 +23,12 @@ import org.junit.Assert; import org.junit.Test; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; +import org.kaaproject.avro.ui.shared.FqnVersion; +import org.kaaproject.kaa.common.dto.ApplicationDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.springframework.http.HttpStatus; /** * @author Bohdan Khablenko @@ -42,11 +45,11 @@ public class ControlServerCTLSchemaIT extends AbstractTestControlServer { @Test public void saveCTLSchemaTest() throws Exception { this.loginKaaAdmin(); - CTLSchemaInfoDto beta = client.saveCTLSchema(getResourceAsString(TEST_CTL_SCHEMA_BETA), CTLSchemaScopeDto.SYSTEM, null); + CTLSchemaDto beta = client.saveCTLSchema(getResourceAsString(TEST_CTL_SCHEMA_BETA), null, null); Assert.assertNotNull(beta.getId()); this.loginTenantDeveloper(tenantDeveloperUser); - CTLSchemaInfoDto alpha = client.saveCTLSchema(getResourceAsString(TEST_CTL_SCHEMA_ALPHA), CTLSchemaScopeDto.TENANT, null); + CTLSchemaDto alpha = client.saveCTLSchema(getResourceAsString(TEST_CTL_SCHEMA_ALPHA), tenantDeveloperDto.getTenantId(), null); Assert.assertNotNull(alpha.getId()); } @@ -61,8 +64,8 @@ public void saveCTLSchemaWithMissingDependenciesTest() throws Exception { // Declare a dependency String dependencyFqn = CTL_DEFAULT_NAMESPACE + "." + this.ctlRandomFieldType(); Integer dependencyVersion = 1; - final Set dependencies = new HashSet<>(); - dependencies.add(new CTLSchemaMetaInfoDto(dependencyFqn, dependencyVersion)); + final Set dependencies = new HashSet<>(); + dependencies.add(new FqnVersion(dependencyFqn, dependencyVersion)); // Map a CTL schema field name to its type final Map fields = new HashMap<>(); @@ -72,7 +75,7 @@ public void saveCTLSchemaWithMissingDependenciesTest() throws Exception { this.checkBadRequest(new TestRestCall() { @Override public void executeRestCall() throws Exception { - createCTLSchema(ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, dependencies, fields); + createCTLSchema(ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, dependencies, fields); } }); } @@ -86,12 +89,12 @@ public void executeRestCall() throws Exception { @Test public void deleteCTLSchemaByFqnAndVersionTest() throws Exception { this.loginTenantDeveloper(tenantDeveloperUser); - final CTLSchemaInfoDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); - client.deleteCTLSchemaByFqnAndVersion(saved.getFqn(), saved.getVersion()); + final CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); + client.deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(saved.getMetaInfo().getFqn(), saved.getVersion(), tenantDeveloperDto.getTenantId(), null); this.checkNotFound(new TestRestCall() { @Override public void executeRestCall() throws Exception { - client.getCTLSchemaByFqnAndVersion(saved.getFqn(), saved.getVersion()).toString(); + client.getCTLSchemaByFqnVersionTenantIdAndApplicationId(saved.getMetaInfo().getFqn(), saved.getVersion(), tenantDeveloperDto.getTenantId(), null); } }); } @@ -103,19 +106,19 @@ public void executeRestCall() throws Exception { @Test public void deleteCTLSchemaWithDependents() throws Exception { this.loginTenantDeveloper(tenantDeveloperUser); - final CTLSchemaInfoDto dependency = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); + final CTLSchemaDto dependency = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); - Set dependencies = new HashSet<>(); - dependencies.add(new CTLSchemaMetaInfoDto(dependency.getFqn(), dependency.getVersion())); + Set dependencies = new HashSet<>(); + dependencies.add(new FqnVersion(dependency.getMetaInfo().getFqn(), dependency.getVersion())); Map fields = new HashMap<>(); - fields.put(this.ctlRandomFieldName(), dependency.getFqn()); - this.createCTLSchema(this.ctlRandomFieldName(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, dependencies, fields); + fields.put(this.ctlRandomFieldName(), dependency.getMetaInfo().getFqn()); + this.createCTLSchema(this.ctlRandomFieldName(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, dependencies, fields); this.checkBadRequest(new TestRestCall() { @Override public void executeRestCall() throws Exception { - client.deleteCTLSchemaByFqnAndVersion(dependency.getFqn(), dependency.getVersion()); + client.deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(dependency.getMetaInfo().getFqn(), dependency.getVersion(), tenantDeveloperDto.getTenantId(), null); } }); @@ -128,12 +131,12 @@ public void executeRestCall() throws Exception { @Test public void deleteSystemCTLSchemaByFqnAndVersionTest() throws Exception { this.loginKaaAdmin(); - final CTLSchemaInfoDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.SYSTEM, null, null, null); + final CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, null, null, null, null); this.loginTenantDeveloper(tenantDeveloperUser); this.checkForbidden(new TestRestCall() { @Override public void executeRestCall() throws Exception { - client.deleteCTLSchemaByFqnAndVersion(saved.getFqn(), saved.getVersion()); + client.deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(saved.getMetaInfo().getFqn(), saved.getVersion(), null, null); } }); } @@ -146,8 +149,8 @@ public void executeRestCall() throws Exception { @Test public void getCTLSchemaByFqnAndVersionTest() throws Exception { this.loginTenantDeveloper(tenantDeveloperUser); - CTLSchemaInfoDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); - CTLSchemaInfoDto loaded = client.getCTLSchemaByFqnAndVersion(saved.getFqn(), saved.getVersion()); + CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); + CTLSchemaDto loaded = client.getCTLSchemaByFqnVersionTenantIdAndApplicationId(saved.getMetaInfo().getFqn(), saved.getVersion(), tenantDeveloperDto.getTenantId(), null); Assert.assertNotNull(loaded); Assert.assertEquals(saved, loaded); } @@ -161,10 +164,103 @@ public void getCTLSchemaByFqnAndVersionTest() throws Exception { @Test public void getSystemCTLSchemaByFqnAndVersionTest() throws Exception { this.loginKaaAdmin(); - CTLSchemaInfoDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.SYSTEM, null, null, null); + CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, null, null, null, null); this.loginTenantDeveloper(tenantDeveloperUser); - CTLSchemaInfoDto loaded = client.getCTLSchemaByFqnAndVersion(saved.getFqn(), saved.getVersion()); + CTLSchemaDto loaded = client.getCTLSchemaByFqnVersionTenantIdAndApplicationId(saved.getMetaInfo().getFqn(), saved.getVersion(), null, null); Assert.assertNotNull(loaded); Assert.assertEquals(saved, loaded); } + + /** + * Check existence of CTL schema with same fqn and another scope + * + * @throws Exception + */ + @Test + public void checkCTLFqnExistsTest() throws Exception { + this.loginTenantDeveloper(tenantDeveloperUser); + CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); + String fqn = saved.getMetaInfo().getFqn(); + boolean result = client.checkFqnExists(fqn, tenantDeveloperDto.getTenantId(), null); + Assert.assertFalse(result); + result = client.checkFqnExists(fqn, tenantDeveloperDto.getTenantId(), "123"); + Assert.assertFalse(result); + result = client.checkFqnExists(fqn, null, null); + Assert.assertFalse(result); + + ApplicationDto application1 = createApplication(tenantAdminDto); + ApplicationDto application2 = createApplication(tenantAdminDto); + this.loginTenantDeveloper(tenantDeveloperUser); + CTLSchemaDto schema1 = this.createCTLSchema("TestAppFqn1", CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application1.getId(), null, null); + this.createCTLSchema("TestAppFqn1", CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application2.getId(), null, null); + + fqn = schema1.getMetaInfo().getFqn(); + + result = client.checkFqnExists(fqn, tenantDeveloperDto.getTenantId(), application1.getId()); + Assert.assertTrue(result); + + result = client.checkFqnExists(fqn, tenantDeveloperDto.getTenantId(), application2.getId()); + Assert.assertTrue(result); + + result = client.checkFqnExists(fqn, tenantDeveloperDto.getTenantId(), null); + Assert.assertFalse(result); + } + + @Test + public void updateCTLSchemaScopeTest() throws Exception { + ApplicationDto application = createApplication(tenantAdminDto); + this.loginTenantDeveloper(tenantDeveloperUser); + CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application.getId(), null, null); + CTLSchemaMetaInfoDto metaInfo = saved.getMetaInfo(); + metaInfo.setApplicationId(null); + CTLSchemaMetaInfoDto updatedMetaInfo = client.updateCTLSchemaMetaInfoScope(metaInfo); + Assert.assertNull(updatedMetaInfo.getApplicationId()); + Assert.assertNotNull(updatedMetaInfo.getTenantId()); + Assert.assertEquals(tenantDeveloperDto.getTenantId(), updatedMetaInfo.getTenantId()); + Assert.assertEquals(CTLSchemaScopeDto.TENANT, updatedMetaInfo.getScope()); + } + + @Test + public void updateCTLSchemaScopeForbiddenTest() throws Exception { + ApplicationDto application = createApplication(tenantAdminDto); + this.loginTenantDeveloper(tenantDeveloperUser); + CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application.getId(), null, null); + final CTLSchemaMetaInfoDto metaInfo = saved.getMetaInfo(); + metaInfo.setApplicationId(null); + metaInfo.setTenantId(null); + this.checkForbidden(new TestRestCall() { + @Override + public void executeRestCall() throws Exception { + client.updateCTLSchemaMetaInfoScope(metaInfo); + } + }); + saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); + final CTLSchemaMetaInfoDto metaInfo2 = saved.getMetaInfo(); + Assert.assertNull(metaInfo2.getApplicationId()); + metaInfo2.setApplicationId(application.getId()); + this.checkRestErrorStatusCode(new TestRestCall() { + @Override + public void executeRestCall() throws Exception { + client.updateCTLSchemaMetaInfoScope(metaInfo2); + } + }, HttpStatus.INTERNAL_SERVER_ERROR); + + this.loginTenantAdmin(tenantAdminUser); + saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null); + final CTLSchemaMetaInfoDto metaInfo3 = saved.getMetaInfo(); + Assert.assertNull(metaInfo3.getApplicationId()); + metaInfo3.setApplicationId(application.getId()); + this.checkForbidden(new TestRestCall() { + @Override + public void executeRestCall() throws Exception { + client.updateCTLSchemaMetaInfoScope(metaInfo3); + } + }); + + //Assert.assertNull(updatedMetaInfo.getApplicationId()); + //Assert.assertNotNull(updatedMetaInfo.getTenantId()); + //Assert.assertEquals(tenantDeveloperDto.getTenantId(), updatedMetaInfo.getTenantId()); + //Assert.assertEquals(CTLSchemaScopeDto.TENANT, updatedMetaInfo.getScope()); + } + } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileFilterIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileFilterIT.java index 5d71520a27..6cbe6e0ef2 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileFilterIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileFilterIT.java @@ -29,8 +29,7 @@ import org.kaaproject.kaa.common.dto.ProfileFilterRecordDto; import org.kaaproject.kaa.common.dto.ProfileVersionPairDto; import org.kaaproject.kaa.common.dto.UpdateStatus; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; /** * The Class ControlServerProfileFilterIT. @@ -148,7 +147,7 @@ public void testGetVacantSchemasByEndpointGroupId() throws Exception { EndpointGroupDto endpointGroup = createEndpointGroup(); - CTLSchemaInfoDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, + CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); EndpointProfileSchemaDto profileSchema1 = createEndpointProfileSchema(endpointGroup.getApplicationId(), ctlSchema.getId()); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileSchemaIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileSchemaIT.java index 50d3949f25..bec7ded70d 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileSchemaIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerProfileSchemaIT.java @@ -26,8 +26,7 @@ import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.common.dto.admin.SchemaVersions; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; /** * The Class ControlServerProfileSchemaIT. @@ -73,7 +72,7 @@ public void testGetProfileSchemasByApplicationId() throws Exception { loginTenantDeveloper(tenantDeveloperDto.getUsername()); - CTLSchemaInfoDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); + CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); List defaultProfileSchemas = client.getProfileSchemas(application.getId()); profileSchemas.addAll(defaultProfileSchemas); @@ -113,7 +112,7 @@ public void testGetProfileSchemaVersionsByApplicationId() throws Exception { List defaultProfileSchemas = client.getProfileSchemas(application.getId()); profileSchemas.addAll(defaultProfileSchemas); - CTLSchemaInfoDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, CTLSchemaScopeDto.TENANT, null, null, null); + CTLSchemaDto ctlSchema = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null); for (int i=0;i<10;i++) { EndpointProfileSchemaDto profileSchema = createEndpointProfileSchema(application.getId(), ctlSchema.getId()); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java index eed7dcceab..1d36f14bb2 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java @@ -45,16 +45,15 @@ import org.kaaproject.kaa.common.dto.ApplicationDto; import org.kaaproject.kaa.common.dto.EndpointGroupDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.EndpointUserDto; 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.ProfileFilterDto; -import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.TopicDto; import org.kaaproject.kaa.common.dto.TopicTypeDto; import org.kaaproject.kaa.common.dto.admin.SdkProfileDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.endpoint.gen.BasicEndpointProfile; import org.kaaproject.kaa.common.endpoint.security.KeyUtil; import org.kaaproject.kaa.common.hash.EndpointObjectHash; @@ -215,19 +214,16 @@ public void beforeTest() throws IOException, NoSuchAlgorithmException, SQLExcept EndpointGroup groupAll = endpointGroupDao.findByAppIdAndWeight(application.getStringId(), 0); - CTLSchemaMetaInfo metaInfo = new CTLSchemaMetaInfo(); - metaInfo.setVersion(1); - metaInfo.setFqn(BasicEndpointProfile.SCHEMA$.getFullName()); - metaInfo.setScope(CTLSchemaScopeDto.PROFILE_SCHEMA); + CTLSchemaMetaInfo metaInfo = new CTLSchemaMetaInfo(BasicEndpointProfile.SCHEMA$.getFullName(), + customer, application); metaInfo = ctlSchemaMetaInfoDao.save(metaInfo); CTLSchema ctlSchema = new CTLSchema(); - ctlSchema.setTenant(customer); - ctlSchema.setApplication(application); + ctlSchema.setMetaInfo(metaInfo); + ctlSchema.setVersion(1); ctlSchema.setBody(BasicEndpointProfile.SCHEMA$.toString()); ctlSchema.setDependencySet(new HashSet()); - ctlSchema.setMetaInfo(metaInfo); ctlSchema = ctlSchemaDao.save(ctlSchema); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java index 63492339f0..4ebcb2b42a 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java @@ -16,6 +16,21 @@ package org.kaaproject.kaa.server.operations.service.delta; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; + +import javax.transaction.Transactional; + import org.apache.avro.Schema; import org.apache.avro.generic.GenericContainer; import org.apache.avro.generic.GenericRecord; @@ -35,12 +50,11 @@ import org.kaaproject.kaa.common.dto.EndpointGroupDto; import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto; -import org.kaaproject.kaa.common.dto.ProfileFilterDto; import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; +import org.kaaproject.kaa.common.dto.ProfileFilterDto; import org.kaaproject.kaa.common.dto.TenantDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.endpoint.gen.BasicEndpointProfile; import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.server.common.core.algorithms.delta.DeltaCalculatorException; @@ -59,21 +73,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import javax.transaction.Transactional; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/operations/common-test-context.xml") @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) @@ -156,16 +155,14 @@ public void beforeTest() throws IOException, DeltaCalculatorException { EndpointGroupDto groupAll = endpointService.findEndpointGroupsByAppId(application.getId()).get(0); CTLSchemaDto profileCtlSchema = new CTLSchemaDto(); - profileCtlSchema.setTenantId(application.getTenantId()); - profileCtlSchema.setApplicationId(application.getId()); + CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(BasicEndpointProfile.SCHEMA$.getFullName(), + application.getTenantId(), + application.getId()); + profileCtlSchema.setMetaInfo(metaInfo); profileCtlSchema.setBody(BasicEndpointProfile.SCHEMA$.toString()); + profileCtlSchema.setVersion(1); profileCtlSchema.setDependencySet(new HashSet()); - CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(); - metaInfo.setVersion(1); - metaInfo.setFqn(BasicEndpointProfile.SCHEMA$.getFullName()); - metaInfo.setScope(CTLSchemaScopeDto.SERVER_PROFILE_SCHEMA); - profileCtlSchema.setMetaInfo(metaInfo); profileCtlSchema = ctlService.saveCTLSchema(profileCtlSchema); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java index 52fc09c536..dbc3bd919f 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java @@ -38,7 +38,6 @@ import org.kaaproject.kaa.common.dto.admin.SdkProfileDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.endpoint.gen.BasicEndpointProfile; import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.schema.system.EmptyData; @@ -129,15 +128,12 @@ public void beforeTest() throws IOException, SQLException { application.setTenantId(tenant.getId()); application = applicationService.saveApp(application); - CTLSchemaMetaInfoDto ctl1MetaDataDto = new CTLSchemaMetaInfoDto(); - ctl1MetaDataDto.setVersion(2); - ctl1MetaDataDto.setFqn(EmptyData.SCHEMA$.getFullName()); - ctl1MetaDataDto.setScope(CTLSchemaScopeDto.PROFILE_SCHEMA); - + CTLSchemaMetaInfoDto ctl1MetaDataDto = new CTLSchemaMetaInfoDto(EmptyData.SCHEMA$.getFullName(), + application.getTenantId(), application.getId()); CTLSchemaDto ctl1SchemaDto = new CTLSchemaDto(); - ctl1SchemaDto.setApplicationId(application.getId()); - ctl1SchemaDto.setBody(EmptyData.SCHEMA$.toString()); ctl1SchemaDto.setMetaInfo(ctl1MetaDataDto); + ctl1SchemaDto.setVersion(2); + ctl1SchemaDto.setBody(EmptyData.SCHEMA$.toString()); ctl1SchemaDto = ctlService.saveCTLSchema(ctl1SchemaDto); schema1Dto = new EndpointProfileSchemaDto(); @@ -146,15 +142,12 @@ public void beforeTest() throws IOException, SQLException { schema1Dto.setApplicationId(application.getId()); schema1Dto = daoProfileService.saveProfileSchema(schema1Dto); - CTLSchemaMetaInfoDto ctl2MetaDataDto = new CTLSchemaMetaInfoDto(); - ctl2MetaDataDto.setVersion(2); - ctl2MetaDataDto.setFqn(BasicEndpointProfile.SCHEMA$.getFullName()); - ctl2MetaDataDto.setScope(CTLSchemaScopeDto.PROFILE_SCHEMA); - + CTLSchemaMetaInfoDto ctl2MetaDataDto = new CTLSchemaMetaInfoDto(BasicEndpointProfile.SCHEMA$.getFullName(), + application.getTenantId(), application.getId()); CTLSchemaDto ctl2SchemaDto = new CTLSchemaDto(); - ctl2SchemaDto.setApplicationId(application.getId()); - ctl2SchemaDto.setBody(BasicEndpointProfile.SCHEMA$.toString()); ctl2SchemaDto.setMetaInfo(ctl2MetaDataDto); + ctl2SchemaDto.setVersion(2); + ctl2SchemaDto.setBody(BasicEndpointProfile.SCHEMA$.toString()); ctl2SchemaDto = ctlService.saveCTLSchema(ctl2SchemaDto); schema2Dto = new EndpointProfileSchemaDto();