From 819c78dbcfc0b9c3784fc63985d74cbeb6c8c55f Mon Sep 17 00:00:00 2001 From: dseurotech Date: Tue, 14 Jan 2025 09:29:25 +0100 Subject: [PATCH] :boom: breaking KapuaQueries down to basic bits Signed-off-by: dseurotech --- .../rest/filters/CORSResponseFilter.java | 66 +-- .../eclipse/kapua/commons/CommonsModule.java | 3 - ...puaConfigurableResourceLimitedService.java | 5 +- .../AbstractKapuaConfigurableService.java | 5 +- .../ServiceConfigImplJpaRepository.java | 3 +- .../configuration/ServiceConfigQuery.java | 24 - .../configuration/ServiceConfigQueryImpl.java | 44 -- .../ServiceConfigurationManagerImpl.java | 3 +- .../UsedEntitiesCounterImpl.java | 4 +- .../event/ServiceEventHousekeeper.java | 16 +- .../ServiceEventTransactionalHousekeeper.java | 18 +- .../commons/jpa/KapuaEntityJpaRepository.java | 6 +- .../AbstractKapuaForwardableEntityQuery.java | 61 --- .../model/query/AbstractKapuaQuery.java | 206 -------- .../model/query/FieldSortCriteriaImpl.java | 66 --- .../commons/model/query/QueryFactoryImpl.java | 33 -- .../query/predicate/AndPredicateImpl.java | 73 --- .../predicate/AttributePredicateImpl.java | 70 --- .../query/predicate/OrPredicateImpl.java | 73 --- .../event/store/api/EventStoreFactory.java | 2 +- .../store/api/EventStoreRecordQuery.java | 30 +- .../store/api/EventStoreXmlRegistry.java | 5 - .../store/internal/EventStoreFactoryImpl.java | 6 - .../store/internal/EventStoreQueryImpl.java | 45 -- .../KapuaNamedEntityServiceUtils.java | 139 +++-- .../commons/service/internal/ServiceDAO.java | 484 ++++++++++-------- .../ServiceConfigQueryImplTest.java | 32 -- ...plTest.java => FieldSortCriteriaTest.java} | 29 +- ...apuaQueryTest.java => KapuaQueryTest.java} | 90 ++-- ...ateImplTest.java => AndPredicateTest.java} | 40 +- ...lTest.java => AttributePredicateTest.java} | 54 +- ...cateImplTest.java => OrPredicateTest.java} | 32 +- .../internal/EventStoreFactoryImplTest.java | 11 - .../internal/EventStoreQueryImplTest.java | 49 -- .../account/server/GwtAccountServiceImpl.java | 67 +-- .../util/GwtKapuaAccountModelConverter.java | 11 +- .../server/GwtCredentialServiceImpl.java | 26 +- .../GwtKapuaAuthenticationModelConverter.java | 29 +- .../GwtAccessPermissionServiceImpl.java | 19 +- .../server/GwtAccessRoleServiceImpl.java | 19 +- .../server/GwtDomainRegistryServiceImpl.java | 14 +- .../server/GwtGroupServiceImpl.java | 32 +- .../server/GwtRoleServiceImpl.java | 34 +- .../GwtKapuaAuthorizationModelConverter.java | 104 ++-- .../server/GwtCertificateInfoServiceImpl.java | 8 +- .../data/server/GwtDataServiceImpl.java | 41 +- .../GwtDeviceConnectionServiceImpl.java | 31 +- ...tDeviceManagementOperationServiceImpl.java | 15 +- .../device/server/GwtDeviceServiceImpl.java | 23 +- .../servlet/DeviceEventExporterServlet.java | 20 +- .../device/servlet/DeviceExporterServlet.java | 19 +- .../util/GwtKapuaDeviceModelConverter.java | 6 +- .../server/GwtEndpointServiceImpl.java | 30 +- .../job/server/GwtJobEngineServiceImpl.java | 8 +- .../module/job/server/GwtJobServiceImpl.java | 28 +- .../GwtJobStepDefinitionServiceImpl.java | 18 +- .../job/server/GwtJobStepServiceImpl.java | 21 +- .../job/server/GwtJobTargetServiceImpl.java | 27 +- .../GwtTriggerDefinitionServiceImpl.java | 16 +- .../job/server/GwtTriggerServiceImpl.java | 23 +- .../job/servlet/JobTargetExporterCsv.java | 11 +- .../job/servlet/JobTargetExporterServlet.java | 4 +- .../util/GwtKapuaJobModelConverter.java | 40 +- .../module/tag/server/GwtTagServiceImpl.java | 30 +- .../util/GwtKapuaTagModelConverter.java | 17 +- .../user/server/GwtUserServiceImpl.java | 37 +- .../util/GwtKapuaUserModelConverter.java | 15 +- .../api/AbstractEntityAttributeMigrator.java | 5 +- .../MfaOptionAttributeMigrator.java | 7 +- .../MfaOptionMigratorQueryImpl.java | 33 -- .../job/JobStepAttributeMigrator.java | 5 - .../job/JobStepMigratorQueryImpl.java | 33 -- .../queue/QueuedJobExecutionFactory.java | 2 +- .../engine/queue/QueuedJobExecutionQuery.java | 32 -- .../queue/QueuedJobExecutionXmlRegistry.java | 3 - .../jaxb/JobEngineJAXBContextProvider.java | 6 - .../operation/DefaultTargetReader.java | 3 +- .../engine/jbatch/JobEngineServiceJbatch.java | 35 +- .../engine/jbatch/driver/JbatchDriver.java | 4 +- .../jbatch/listener/KapuaJobListener.java | 6 +- .../listener/QueuedJobExecutionCheckTask.java | 18 +- .../jbatch/QueuedJobExecutionFactoryImpl.java | 6 - .../jbatch/QueuedJobExecutionQueryImpl.java | 35 -- .../misc/RolePermissionFactoryTest.java | 13 - .../resources/v1/resources/AccessInfos.java | 117 +++-- .../v1/resources/AccessPermissions.java | 145 +++--- .../resources/v1/resources/AccessRoles.java | 117 +++-- .../api/resources/v1/resources/Accounts.java | 20 +- .../resources/v1/resources/Credentials.java | 126 +++-- .../v1/resources/DeviceConnections.java | 97 ++-- .../resources/v1/resources/DeviceEvents.java | 119 +++-- ...eviceManagementOperationNotifications.java | 84 +-- .../resources/DeviceManagementOperations.java | 90 ++-- .../api/resources/v1/resources/Devices.java | 150 +++--- .../api/resources/v1/resources/Domains.java | 94 ++-- .../api/resources/v1/resources/Groups.java | 97 ++-- .../resources/v1/resources/JobExecutions.java | 83 +-- .../v1/resources/JobStepDefinitions.java | 94 ++-- .../api/resources/v1/resources/JobSteps.java | 164 +++--- .../resources/v1/resources/JobTargets.java | 145 +++--- .../v1/resources/JobTriggerDefinitions.java | 82 +-- .../resources/v1/resources/JobTriggers.java | 179 ++++--- .../v1/resources/JobTriggersFired.java | 84 +-- .../app/api/resources/v1/resources/Jobs.java | 135 +++-- .../app/api/resources/v1/resources/Roles.java | 124 +++-- .../v1/resources/RolesPermissions.java | 151 +++--- .../app/api/resources/v1/resources/Tags.java | 100 ++-- .../app/api/resources/v1/resources/Users.java | 138 +++-- .../v1/resources/UsersCredentials.java | 100 ++-- .../api/web/RestApiJAXBContextProvider.java | 26 - .../kapua/service/account/AccountFactory.java | 2 +- .../kapua/service/account/AccountQuery.java | 33 -- .../account/xml/AccountXmlRegistry.java | 11 - .../account/internal/AccountFactoryImpl.java | 6 - .../account/internal/AccountQueryImpl.java | 46 -- .../internal/AccountRelativeFinderImpl.java | 10 +- .../account/internal/AccountServiceImpl.java | 2 +- .../account/steps/AccountServiceSteps.java | 11 +- .../test/AccountLocatorConfiguration.java | 3 - .../kapua/model/KapuaEntityFactory.java | 18 +- .../model/query/AbstractKapuaNamedQuery.java | 13 +- .../kapua/model/query/FieldSortCriteria.java | 32 +- .../query/KapuaForwardableEntityQuery.java | 49 +- .../eclipse/kapua/model/query/KapuaQuery.java | 232 ++++++--- .../kapua/model/query/QueryFactory.java | 31 -- .../predicate/AbstractMatchPredicate.java | 4 +- .../model/query/predicate/AndPredicate.java | 63 ++- .../query/predicate/AttributePredicate.java | 79 ++- .../model/query/predicate/OrPredicate.java | 63 ++- .../authentication/AuthenticationLogic.java | 19 +- ...ndPredicateImpl.java => AndPredicate.java} | 21 +- .../StorablePredicateFactoryImpl.java | 6 +- .../JobDeviceManagementOperationFactory.java | 2 +- .../JobDeviceManagementOperationQuery.java | 32 -- ...bDeviceManagementOperationXmlRegistry.java | 3 - ...bDeviceManagementOperationFactoryImpl.java | 6 - ...JobDeviceManagementOperationQueryImpl.java | 35 -- ...bDeviceManagementOperationServiceImpl.java | 31 +- ...ManagementOperationManagerServiceImpl.java | 75 +-- ...ceManagementTriggerManagerServiceImpl.java | 20 +- .../DeviceManagementOperationFactory.java | 2 +- .../DeviceManagementOperationQuery.java | 39 +- .../DeviceManagementOperationXmlRegistry.java | 3 - ...anagementOperationNotificationFactory.java | 2 +- .../ManagementOperationNotificationQuery.java | 38 +- ...ementOperationNotificationXmlRegistry.java | 3 - ...eManagementRegistryManagerServiceImpl.java | 16 +- .../DeviceManagementOperationFactoryImpl.java | 6 - .../DeviceManagementOperationQueryImpl.java | 54 -- ...ementOperationNotificationFactoryImpl.java | 6 - ...agementOperationNotificationQueryImpl.java | 54 -- .../device/registry/DeviceFactory.java | 2 +- .../device/registry/DeviceMatchPredicate.java | 30 +- .../service/device/registry/DeviceQuery.java | 48 +- .../device/registry/DeviceXmlRegistry.java | 4 - .../connection/DeviceConnectionFactory.java | 2 +- .../connection/DeviceConnectionQuery.java | 38 +- .../DeviceConnectionXmlRegistry.java | 3 - .../option/DeviceConnectionOptionFactory.java | 2 +- .../option/DeviceConnectionOptionQuery.java | 33 -- .../DeviceConnectionOptionXmlRegistry.java | 4 - .../registry/event/DeviceEventFactory.java | 2 +- .../registry/event/DeviceEventQuery.java | 37 +- .../event/DeviceEventXmlRegistry.java | 3 - .../device/registry/DeviceRegistryModule.java | 2 - .../registry/common/DeviceValidationImpl.java | 113 ++-- .../internal/DeviceConnectionFactoryImpl.java | 6 - .../DeviceConnectionImplJpaRepository.java | 3 +- .../internal/DeviceConnectionQueryImpl.java | 53 -- .../internal/DeviceConnectionServiceImpl.java | 20 +- .../DeviceConnectionOptionFactoryImpl.java | 6 - .../DeviceConnectionOptionQueryImpl.java | 45 -- .../DeviceConnectionOptionServiceImpl.java | 15 +- .../internal/DeviceEventFactoryImpl.java | 6 - .../event/internal/DeviceEventQueryImpl.java | 53 -- .../registry/internal/DeviceFactoryImpl.java | 6 - .../internal/DeviceImplJpaRepository.java | 3 +- .../internal/DeviceMatchPredicateImpl.java | 48 -- .../registry/internal/DeviceQueryImpl.java | 59 --- .../internal/DeviceRegistryServiceImpl.java | 14 +- .../registry/steps/DeviceRegistrySteps.java | 104 ++-- .../DeviceRegistryLocatorConfiguration.java | 24 +- .../service/endpoint/EndpointInfoFactory.java | 6 +- .../endpoint/EndpointInfoMatchPredicate.java | 19 +- .../service/endpoint/EndpointInfoQuery.java | 29 +- .../internal/EndpointInfoFactoryImpl.java | 2 +- .../EndpointInfoMatchPredicateImpl.java | 37 -- .../internal/EndpointInfoQueryImpl.java | 41 -- .../internal/EndpointInfoServiceImpl.java | 65 ++- .../eclipse/kapua/service/job/JobFactory.java | 2 +- .../kapua/service/job/JobMatchPredicate.java | 20 +- .../eclipse/kapua/service/job/JobQuery.java | 31 +- .../kapua/service/job/JobXmlRegistry.java | 2 +- .../job/execution/JobExecutionFactory.java | 2 +- .../job/execution/JobExecutionQuery.java | 27 +- .../execution/JobExecutionXmlRegistry.java | 3 - .../service/job/step/JobStepFactory.java | 2 +- .../kapua/service/job/step/JobStepQuery.java | 32 -- .../service/job/step/JobStepXmlRegistry.java | 4 - .../definition/JobStepDefinitionFactory.java | 2 +- .../definition/JobStepDefinitionQuery.java | 32 +- .../JobStepDefinitionXmlRegistry.java | 4 - .../service/job/targets/JobTargetFactory.java | 2 +- .../service/job/targets/JobTargetQuery.java | 32 -- .../job/targets/JobTargetXmlRegistry.java | 3 - .../internal/JobExecutionFactoryImpl.java | 6 - .../JobExecutionImplJpaRepository.java | 2 +- .../internal/JobExecutionQueryImpl.java | 43 -- .../service/job/internal/JobFactoryImpl.java | 6 - .../job/internal/JobMatchPredicateImpl.java | 37 -- .../service/job/internal/JobQueryImpl.java | 41 -- .../internal/JobStepDefinitionAligner.java | 3 +- .../JobStepDefinitionFactoryImpl.java | 6 - .../internal/JobStepDefinitionQueryImpl.java | 48 -- .../JobStepDefinitionServiceImpl.java | 3 +- .../job/step/internal/JobStepFactoryImpl.java | 6 - .../job/step/internal/JobStepModule.java | 4 - .../job/step/internal/JobStepQueryImpl.java | 35 -- .../job/step/internal/JobStepServiceImpl.java | 59 +-- .../internal/JobTargetFactoryImpl.java | 6 - .../targets/internal/JobTargetQueryImpl.java | 35 -- .../internal/JobTargetServiceImpl.java | 16 +- .../job/steps/JobExecutionServiceSteps.java | 11 +- .../service/job/steps/JobServiceSteps.java | 18 +- .../service/job/steps/JobServiceTestBase.java | 2 +- .../steps/JobStepDefinitionServiceSteps.java | 6 +- .../job/steps/JobStepServiceSteps.java | 12 +- .../job/steps/JobTargetServiceSteps.java | 13 +- .../job/test/JobLocatorConfiguration.java | 3 - .../scheduler/trigger/TriggerFactory.java | 2 +- .../scheduler/trigger/TriggerQuery.java | 32 -- .../scheduler/trigger/TriggerXmlRegistry.java | 4 - .../definition/TriggerDefinitionFactory.java | 2 +- .../definition/TriggerDefinitionQuery.java | 21 +- .../TriggerDefinitionXmlRegistry.java | 3 - .../trigger/fired/FiredTriggerFactory.java | 2 +- .../trigger/fired/FiredTriggerQuery.java | 32 -- .../fired/FiredTriggerXmlRegistry.java | 3 - .../quartz/TriggerDefinitionAligner.java | 29 +- .../quartz/TriggerDefinitionFactoryImpl.java | 6 - .../quartz/TriggerDefinitionQueryImpl.java | 35 -- .../fired/quartz/FiredTriggerFactoryImpl.java | 6 - .../fired/quartz/FiredTriggerQueryImpl.java | 35 -- .../trigger/quartz/TriggerFactoryImpl.java | 6 - .../trigger/quartz/TriggerQueryImpl.java | 45 -- .../steps/JobScheduleServiceSteps.java | 54 +- .../test/SchedulerLocatorConfiguration.java | 5 - .../credential/CredentialFactory.java | 2 +- .../credential/CredentialQuery.java | 32 -- .../credential/CredentialXmlRegistry.java | 10 - .../credential/mfa/MfaOptionFactory.java | 2 +- .../credential/mfa/MfaOptionQuery.java | 32 -- .../credential/mfa/MfaOptionXmlRegistry.java | 10 - .../token/AccessTokenFactory.java | 2 +- .../token/AccessTokenQuery.java | 24 - .../access/AccessInfoFactory.java | 2 +- .../authorization/access/AccessInfoQuery.java | 32 -- .../access/AccessInfoXmlRegistry.java | 3 - .../access/AccessPermissionFactory.java | 2 +- .../access/AccessPermissionQuery.java | 32 -- .../access/AccessPermissionXmlRegistry.java | 4 - .../access/AccessRoleFactory.java | 2 +- .../authorization/access/AccessRoleQuery.java | 32 -- .../access/AccessRoleXmlRegistry.java | 3 - .../authorization/domain/DomainFactory.java | 2 +- .../authorization/domain/DomainQuery.java | 32 -- .../domain/DomainXmlRegistry.java | 27 - .../authorization/group/GroupFactory.java | 2 +- .../group/GroupMatchPredicate.java | 20 +- .../authorization/group/GroupQuery.java | 31 +- .../authorization/group/GroupXmlRegistry.java | 10 - .../authorization/role/RoleFactory.java | 2 +- .../role/RoleMatchPredicate.java | 19 +- .../role/RolePermissionFactory.java | 2 +- .../role/RolePermissionQuery.java | 32 -- .../role/RolePermissionXmlRegistry.java | 3 - .../service/authorization/role/RoleQuery.java | 41 +- .../authorization/role/RoleXmlRegistry.java | 10 - .../certificate/CertificateFactory.java | 3 +- .../service/certificate/CertificateQuery.java | 39 +- .../info/CertificateInfoFactory.java | 2 +- .../info/CertificateInfoMatchPredicate.java | 22 +- .../info/CertificateInfoQuery.java | 41 +- .../info/xml/CertificateInfoXmlRegistry.java | 4 - .../xml/CertificateXmlRegistry.java | 5 - .../internal/CertificateInfoFactoryImpl.java | 6 - .../CertificateInfoMatchPredicateImpl.java | 40 -- .../internal/CertificateInfoQueryImpl.java | 63 --- .../internal/CertificateInfoServiceImpl.java | 5 +- .../internal/CertificateFactoryImpl.java | 6 - .../internal/CertificateQueryImpl.java | 56 -- .../mfa/shiro/MfaOptionFactoryImpl.java | 6 - .../mfa/shiro/MfaOptionQueryImpl.java | 46 -- .../shiro/CredentialFactoryImpl.java | 6 - .../credential/shiro/CredentialQueryImpl.java | 44 -- .../shiro/CredentialServiceImpl.java | 58 +-- .../shiro/AuthenticationServiceShiroImpl.java | 54 +- .../realm/AccessTokenAuthenticatingRealm.java | 37 +- .../realm/AccessTokenCredentialsMatcher.java | 4 +- .../token/shiro/AccessTokenFactoryImpl.java | 6 - .../token/shiro/AccessTokenQueryImpl.java | 45 -- .../token/shiro/AccessTokenServiceImpl.java | 16 +- .../access/shiro/AccessInfoFactoryImpl.java | 6 - .../access/shiro/AccessInfoQueryImpl.java | 45 -- .../access/shiro/AccessInfoServiceImpl.java | 29 +- .../shiro/AccessPermissionFactoryImpl.java | 6 - .../AccessPermissionImplJpaRepository.java | 4 +- .../shiro/AccessPermissionQueryImpl.java | 45 -- .../shiro/AccessPermissionServiceImpl.java | 18 +- .../access/shiro/AccessRoleFactoryImpl.java | 6 - .../access/shiro/AccessRoleQueryImpl.java | 45 -- .../access/shiro/AccessRoleServiceImpl.java | 9 +- .../CachingAccessPermissionRepository.java | 5 +- .../domain/shiro/DomainFactoryImpl.java | 6 - .../domain/shiro/DomainQueryImpl.java | 44 -- .../shiro/DomainRegistryServiceImpl.java | 10 +- .../domain/shiro/DomainsAligner.java | 33 +- .../group/shiro/GroupFactoryImpl.java | 6 - .../group/shiro/GroupMatchPredicateImpl.java | 37 -- .../group/shiro/GroupQueryImpl.java | 41 -- .../group/shiro/GroupServiceImpl.java | 23 +- .../permission/shiro/PermissionValidator.java | 14 +- .../role/shiro/RoleFactoryImpl.java | 6 - .../role/shiro/RoleMatchPredicateImpl.java | 35 -- .../role/shiro/RolePermissionFactoryImpl.java | 6 - .../role/shiro/RolePermissionQueryImpl.java | 45 -- .../role/shiro/RolePermissionServiceImpl.java | 16 +- .../role/shiro/RoleQueryImpl.java | 52 -- .../role/shiro/RoleServiceImpl.java | 35 +- .../shiro/KapuaAuthorizingRealm.java | 4 +- .../mfa/shiro/MfaOptionFactoryImplTest.java | 9 - .../mfa/shiro/MfaOptionQueryImplTest.java | 44 -- .../shiro/CredentialFactoryImplTest.java | 4 +- .../shiro/CredentialQueryImplTest.java | 43 -- .../shiro/AccessTokenFactoryImplTest.java | 9 - .../token/shiro/AccessTokenQueryImplTest.java | 47 -- .../shiro/AccessInfoFactoryImplTest.java | 6 +- .../access/shiro/AccessInfoQueryImplTest.java | 45 -- .../AccessPermissionFactoryImplTest.java | 8 - .../shiro/AccessPermissionQueryImplTest.java | 48 -- .../shiro/AccessRoleFactoryImplTest.java | 13 - .../access/shiro/AccessRoleQueryImplTest.java | 40 -- .../domain/shiro/DomainFactoryImplTest.java | 17 - .../domain/shiro/DomainQueryImplTest.java | 42 -- .../group/shiro/GroupFactoryImplTest.java | 13 - .../group/shiro/GroupQueryImplTest.java | 40 -- .../role/shiro/RoleFactoryImplTest.java | 13 - .../shiro/RolePermissionQueryImplTest.java | 44 -- .../role/shiro/RoleQueryImplTest.java | 44 -- .../steps/AuthorizationServiceSteps.java | 69 ++- .../test/SecurityLocatorConfiguration.java | 25 +- .../test/SystemInfoLocatorConfiguration.java | 24 +- .../eclipse/kapua/service/tag/TagFactory.java | 2 +- .../kapua/service/tag/TagMatchPredicate.java | 21 +- .../eclipse/kapua/service/tag/TagQuery.java | 30 +- .../kapua/service/tag/TagXmlRegistry.java | 2 +- .../service/tag/internal/TagFactoryImpl.java | 6 - .../tag/internal/TagMatchPredicateImpl.java | 35 -- .../service/tag/internal/TagQueryImpl.java | 42 -- .../service/tag/steps/TagServiceSteps.java | 40 +- .../tag/test/TagLocatorConfiguration.java | 29 +- .../kapua/service/user/UserFactory.java | 2 +- .../service/user/UserMatchPredicate.java | 24 +- .../eclipse/kapua/service/user/UserQuery.java | 41 +- .../kapua/service/user/UserXmlRegistry.java | 2 +- .../user/internal/UserFactoryImpl.java | 6 - .../user/internal/UserMatchPredicateImpl.java | 42 -- .../service/user/internal/UserQueryImpl.java | 50 -- .../user/internal/UserServiceImpl.java | 11 +- .../service/user/steps/UserServiceSteps.java | 129 ++--- .../user/test/UserLocatorConfiguration.java | 4 - 371 files changed, 4605 insertions(+), 7152 deletions(-) delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQuery.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java delete mode 100644 commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java delete mode 100644 commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java rename commons/src/test/java/org/eclipse/kapua/commons/model/query/{FieldSortCriteriaImplTest.java => FieldSortCriteriaTest.java} (64%) rename commons/src/test/java/org/eclipse/kapua/commons/model/query/{AbstractKapuaQueryTest.java => KapuaQueryTest.java} (70%) rename commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/{AndPredicateImplTest.java => AndPredicateTest.java} (68%) rename commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/{AttributePredicateImplTest.java => AttributePredicateTest.java} (64%) rename commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/{OrPredicateImplTest.java => OrPredicateTest.java} (68%) delete mode 100644 commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImplTest.java delete mode 100644 extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionMigratorQueryImpl.java delete mode 100644 extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepMigratorQueryImpl.java delete mode 100644 job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionQuery.java delete mode 100644 job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionQueryImpl.java delete mode 100644 service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountQuery.java delete mode 100644 service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountQueryImpl.java rename {commons/src/main/java/org/eclipse/kapua/commons => service/api/src/main/java/org/eclipse/kapua}/model/query/AbstractKapuaNamedQuery.java (78%) delete mode 100644 service/api/src/main/java/org/eclipse/kapua/model/query/QueryFactory.java rename {commons/src/main/java/org/eclipse/kapua/commons => service/api/src/main/java/org/eclipse/kapua}/model/query/predicate/AbstractMatchPredicate.java (88%) rename service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/{AndPredicateImpl.java => AndPredicate.java} (87%) delete mode 100644 service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationQuery.java delete mode 100644 service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationQueryImpl.java delete mode 100644 service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationQueryImpl.java delete mode 100644 service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationQueryImpl.java delete mode 100644 service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionQuery.java delete mode 100644 service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionQueryImpl.java delete mode 100644 service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionQueryImpl.java delete mode 100644 service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventQueryImpl.java delete mode 100644 service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceMatchPredicateImpl.java delete mode 100644 service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceQueryImpl.java delete mode 100644 service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java delete mode 100644 service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java delete mode 100644 service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepQuery.java delete mode 100644 service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetQuery.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionQueryImpl.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobMatchPredicateImpl.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobQueryImpl.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionQueryImpl.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepQueryImpl.java delete mode 100644 service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetQueryImpl.java delete mode 100644 service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerQuery.java delete mode 100644 service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerQuery.java delete mode 100644 service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionQueryImpl.java delete mode 100644 service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerQueryImpl.java delete mode 100644 service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerQueryImpl.java delete mode 100644 service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialQuery.java delete mode 100644 service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionQuery.java delete mode 100644 service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenQuery.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoQuery.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionQuery.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleQuery.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainQuery.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainXmlRegistry.java delete mode 100644 service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionQuery.java delete mode 100644 service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java delete mode 100644 service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java delete mode 100644 service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupMatchPredicateImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleMatchPredicateImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImpl.java delete mode 100644 service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImpl.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImplTest.java delete mode 100644 service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImplTest.java delete mode 100644 service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagMatchPredicateImpl.java delete mode 100644 service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagQueryImpl.java delete mode 100644 service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserMatchPredicateImpl.java delete mode 100644 service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserQueryImpl.java diff --git a/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java b/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java index 83bc0c0b3dc..b12fc9687e4 100644 --- a/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java +++ b/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java @@ -12,10 +12,25 @@ *******************************************************************************/ package org.eclipse.kapua.commons.rest.filters; -import com.google.common.base.Strings; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.google.common.net.HttpHeaders; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.shiro.web.util.WebUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.rest.filters.settings.KapuaRestFiltersSetting; @@ -23,9 +38,9 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.endpoint.EndpointInfo; import org.eclipse.kapua.service.endpoint.EndpointInfoFactory; @@ -35,23 +50,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; +import com.google.common.base.Strings; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.net.HttpHeaders; /** * CORS {@link Filter} implementation. @@ -107,7 +109,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha String errorMessage = null; if (Strings.isNullOrEmpty(fetchSite)) { - logger.warn("Sec-Fetch-Site' header not present in request: {} {}. CORSResponseFilter may produce false positives for this request. User-Agent is: {}", httpRequest.getMethod(), httpRequest.getPathInfo(), httpRequest.getHeader(HttpHeaders.USER_AGENT)); + logger.warn("Sec-Fetch-Site' header not present in request: {} {}. CORSResponseFilter may produce false positives for this request. User-Agent is: {}", httpRequest.getMethod(), + httpRequest.getPathInfo(), httpRequest.getHeader(HttpHeaders.USER_AGENT)); } if (Strings.isNullOrEmpty(origin)) { logger.warn("'Origin' header not present in request: {} {}. User-Agent is: {}", httpRequest.getMethod(), httpRequest.getPathInfo(), httpRequest.getHeader(HttpHeaders.USER_AGENT)); @@ -130,7 +133,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha logger.error(errorMessage); } } else { - logger.debug("HTTP sec-fetch-site same-origin detected and allowed. Request: {} {}. User-Agent is: {}", httpRequest.getMethod(), httpRequest.getPathInfo(), httpRequest.getHeader(HttpHeaders.USER_AGENT)); + logger.debug("HTTP sec-fetch-site same-origin detected and allowed. Request: {} {}. User-Agent is: {}", httpRequest.getMethod(), httpRequest.getPathInfo(), + httpRequest.getHeader(HttpHeaders.USER_AGENT)); } } int errorCode = httpResponse.getStatus(); @@ -152,12 +156,12 @@ private String getExplicitOrigin(String origin) throws MalformedURLException { } switch (originUrl.getProtocol()) { - case "http": - return origin + ":80"; - case "https": - return origin + ":443"; - default: - return origin; + case "http": + return origin + ":80"; + case "https": + return origin + ":443"; + default: + return origin; } } @@ -191,7 +195,7 @@ private synchronized void refreshOrigins() { logger.info("Refreshing list of origins..."); Multimap newAllowedOrigins = HashMultimap.create(); - AccountQuery accounts = accountFactory.newQuery(null); + final KapuaQuery accounts = new KapuaQuery((KapuaId) null); AccountListResult accountListResult = KapuaSecurityUtils.doPrivileged(() -> accountService.query(accounts)); accountListResult.getItems().forEach(account -> { EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(account.getId()); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/CommonsModule.java b/commons/src/main/java/org/eclipse/kapua/commons/CommonsModule.java index 215ad405a8f..f5534b0a241 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/CommonsModule.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/CommonsModule.java @@ -32,7 +32,6 @@ import org.eclipse.kapua.commons.model.domains.Domains; import org.eclipse.kapua.commons.model.mappers.KapuaBaseMapper; import org.eclipse.kapua.commons.model.mappers.KapuaBaseMapperImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.api.EventStoreService; @@ -48,7 +47,6 @@ import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.domain.Domain; import org.eclipse.kapua.model.domain.DomainEntry; -import org.eclipse.kapua.model.query.QueryFactory; import com.google.inject.Provides; import com.google.inject.multibindings.Multibinder; @@ -63,7 +61,6 @@ public class CommonsModule extends AbstractKapuaModule { @Override protected void configureModule() { - bind(QueryFactory.class).to(QueryFactoryImpl.class).in(Singleton.class); bind(CryptoSettings.class).toInstance(new CryptoSettings()); bind(CryptoUtil.class).to(CryptoUtilImpl.class).in(Singleton.class); bind(QRCodeBuilder.class).to(QRCodeBuilderImpl.class).in(Singleton.class); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableResourceLimitedService.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableResourceLimitedService.java index 616290f3751..8642c881ad9 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableResourceLimitedService.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableResourceLimitedService.java @@ -68,8 +68,7 @@ public abstract class AbstractKapuaConfigurableResourceLimitedService< E extends KapuaEntity, C extends KapuaEntityCreator, S extends KapuaEntityService, - Q extends KapuaQuery, - F extends KapuaEntityFactory + F extends KapuaEntityFactory > extends AbstractKapuaConfigurableService implements KapuaEntityService { @@ -269,7 +268,7 @@ private long allowedChildEntities(KapuaId scopeId, KapuaId targetScopeId, Map { - Q countQuery = getFactory().newQuery(scopeId); + KapuaQuery countQuery = new KapuaQuery(scopeId); // Current used entities long currentUsedEntities = this.count(countQuery); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableService.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableService.java index 3ea4dda4a94..da5af63e3c1 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableService.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/AbstractKapuaConfigurableService.java @@ -59,6 +59,7 @@ import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.domain.Domain; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; @@ -527,7 +528,7 @@ protected Map getConfigValues(KapuaId scopeId, boolean excludeDi // Check access getAuthorizationService().checkPermission(getPermissionFactory().newPermission(Optional.ofNullable(domain).map(d -> d.getName()).orElse(null), Actions.read, scopeId)); // Get configuration values - ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( query.andPredicate( @@ -583,7 +584,7 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map, L extends KapuaListResult, Q extends KapuaQuery, - F extends KapuaEntityFactory + F extends KapuaEntityFactory > implements UsedEntitiesCounter { private final F factory; @@ -42,7 +42,7 @@ public UsedEntitiesCounterImpl(F factory, @Override public long countEntitiesInScope(TxContext tx, KapuaId scopeId) throws KapuaException { - final Q query = factory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); // Do count return entityRepository.count(tx, query); } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java index b6b6363879e..4ad90d127fc 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventHousekeeper.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.List; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.EntityManager; import org.eclipse.kapua.commons.jpa.EntityManagerFactory; @@ -22,7 +27,6 @@ import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.commons.service.event.store.api.EventStoreService; import org.eclipse.kapua.commons.service.event.store.api.ServiceEventUtil; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.KapuaDateUtils; @@ -35,11 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; - /** * Event bus housekeeper. It is responsible to send unsent messages or send again messages gone in error. * @@ -78,7 +77,8 @@ private enum EventsProcessType { * @param servicesEntryList * @throws KapuaException */ - public ServiceEventHousekeeper(EventStoreService eventStoreService, EntityManagerFactory entityManagerFactory, ServiceEventBus eventbus, List servicesEntryList) throws KapuaException { + public ServiceEventHousekeeper(EventStoreService eventStoreService, EntityManagerFactory entityManagerFactory, ServiceEventBus eventbus, List servicesEntryList) + throws KapuaException { this.eventbus = eventbus; this.servicesEntryList = servicesEntryList; manager = entityManagerFactory.createEntityManager(); @@ -161,7 +161,7 @@ private void findAndSendUnsentEvents(String serviceName, EventsProcessType event } private EventStoreRecordListResult getUnsentEvents(String serviceName, EventsProcessType eventsProcessType) throws KapuaException { - EventStoreRecordQuery query = new EventStoreFactoryImpl().newQuery(null); + EventStoreRecordQuery query = new EventStoreRecordQuery(null); AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(EventStoreRecordAttributes.SERVICE_NAME, serviceName)); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java index 3895e025656..048b37ea1d4 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalHousekeeper.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.JpaAwareTxContext; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; @@ -21,7 +29,6 @@ import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.commons.service.event.store.api.EventStoreService; import org.eclipse.kapua.commons.service.event.store.api.ServiceEventUtil; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.KapuaDateUtils; @@ -36,13 +43,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.List; - /** * Event bus housekeeper. It is responsible to send unsent messages or send again messages gone in error. * @@ -156,7 +156,7 @@ private void findAndSendUnsentEvents(String serviceName, EventsProcessType event } private EventStoreRecordListResult getUnsentEvents(String serviceName, EventsProcessType eventsProcessType) throws KapuaException { - EventStoreRecordQuery query = new EventStoreFactoryImpl().newQuery(null); + EventStoreRecordQuery query = new EventStoreRecordQuery(null); AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(EventStoreRecordAttributes.SERVICE_NAME, serviceName)); diff --git a/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java b/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java index 429bef059b9..65fa4a44808 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/jpa/KapuaEntityJpaRepository.java @@ -48,8 +48,6 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.AbstractKapuaEntity_; import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; @@ -373,9 +371,9 @@ private Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPr predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } else if (queryPredicate instanceof MatchPredicate) { MatchPredicate matchPredicate = (MatchPredicate) queryPredicate; - OrPredicate orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); for (String attributeName : matchPredicate.getAttributeNames()) { - orPredicate.getPredicates().add(new AttributePredicateImpl<>(attributeName, matchPredicate.getMatchTerm(), AttributePredicate.Operator.STARTS_WITH_IGNORE_CASE)); + orPredicate.getPredicates().add(new AttributePredicate<>(attributeName, matchPredicate.getMatchTerm(), AttributePredicate.Operator.STARTS_WITH_IGNORE_CASE)); } predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java deleted file mode 100644 index 40b0954c96c..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaForwardableEntityQuery.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2024, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaForwardableEntityQuery; -import org.eclipse.kapua.model.query.KapuaQuery; - -public class AbstractKapuaForwardableEntityQuery extends AbstractKapuaNamedQuery implements KapuaForwardableEntityQuery { - - protected Boolean includeInherited = Boolean.FALSE; - - /** - * Constructor. - * - */ - public AbstractKapuaForwardableEntityQuery() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - */ - public AbstractKapuaForwardableEntityQuery(KapuaId scopeId) { - super(scopeId); - } - - /** - * Clone constructor. - * - * @param query The {@link AbstractKapuaForwardableEntityQuery} to clone. - */ - public AbstractKapuaForwardableEntityQuery(KapuaQuery query) { - super(query); - if(query instanceof KapuaForwardableEntityQuery) { - this.includeInherited = ((KapuaForwardableEntityQuery) query).getIncludeInherited(); - } - } - - @Override - public Boolean getIncludeInherited() { - return includeInherited; - } - - @Override - public void setIncludeInherited(Boolean includeInherited) { - this.includeInherited = includeInherited; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java deleted file mode 100644 index bcbb7588a10..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQuery.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; -import org.eclipse.kapua.model.KapuaEntityAttributes; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.FieldSortCriteria; -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.model.query.predicate.AndPredicate; -import org.eclipse.kapua.model.query.predicate.AttributePredicate; -import org.eclipse.kapua.model.query.predicate.OrPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; - -/** - * {@link KapuaQuery} {@code abstract} implementation. - * - * @since 1.0.0 - */ -public abstract class AbstractKapuaQuery implements KapuaQuery { - - private KapuaId scopeId; - - private QueryPredicate predicate; - private KapuaSortCriteria sortCriteria; - private List fetchAttributes; - - private Integer offset; - private Integer limit; - private Boolean askTotalCount; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AbstractKapuaQuery() { - } - - /** - * Constructor. - * - * @param scopeId The scope {@link KapuaId} of the {@link KapuaQuery} - * @since 1.0.0 - */ - public AbstractKapuaQuery(KapuaId scopeId) { - this(); - - setScopeId(scopeId); - } - - /** - * Constructor. - *

- * It deeply clones the given {@link KapuaQuery} - * - * @param query the query to clone. - */ - public AbstractKapuaQuery(@NotNull KapuaQuery query) { - setFetchAttributes(query.getFetchAttributes()); - setPredicate(query.getPredicate()); - setLimit(query.getLimit()); - setOffset(query.getOffset()); - setSortCriteria(query.getSortCriteria()); - setAskTotalCount(query.getAskTotalCount()); - } - - @Override - public KapuaId getScopeId() { - return scopeId; - } - - @Override - public void setScopeId(KapuaId scopeId) { - this.scopeId = KapuaEid.parseKapuaId(scopeId); - } - - @Override - public void addFetchAttributes(String fetchAttribute) { - getFetchAttributes().add(fetchAttribute); - } - - @Override - public List getFetchAttributes() { - if (fetchAttributes == null) { - fetchAttributes = new ArrayList<>(); - } - - return fetchAttributes; - } - - @Override - public void setFetchAttributes(List fetchAttributes) { - this.fetchAttributes = fetchAttributes; - } - - @Override - public QueryPredicate getPredicate() { - return this.predicate; - } - - @Override - public void setPredicate(QueryPredicate queryPredicate) { - this.predicate = queryPredicate; - } - - @Override - public KapuaSortCriteria getSortCriteria() { - return sortCriteria; - } - - @Override - public void setSortCriteria(KapuaSortCriteria sortCriteria) { - this.sortCriteria = sortCriteria; - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(KapuaEntityAttributes.ENTITY_ID, SortOrder.ASCENDING); - } - - @Override - public Integer getOffset() { - return offset; - } - - @Override - public void setOffset(Integer offset) { - this.offset = offset; - } - - @Override - public Integer getLimit() { - return limit; - } - - @Override - public void setLimit(Integer limit) { - this.limit = limit; - } - - @Override - public Boolean getAskTotalCount() { - return askTotalCount; - } - - @Override - public void setAskTotalCount(Boolean askTotalCount) { - this.askTotalCount = askTotalCount; - } - - // Predicate factory - @Override - public AttributePredicate attributePredicate(String attributeName, T attributeValue) { - return new AttributePredicateImpl<>(attributeName, attributeValue); - } - - @Override - public AttributePredicate attributePredicate(String attributeName, T attributeValue, AttributePredicate.Operator operator) { - return new AttributePredicateImpl<>(attributeName, attributeValue, operator); - } - - @Override - public AndPredicate andPredicate() { - return new AndPredicateImpl(); - } - - @Override - public AndPredicate andPredicate(QueryPredicate... queryPredicates) { - return new AndPredicateImpl(queryPredicates); - } - - @Override - public OrPredicate orPredicate() { - return new OrPredicateImpl(); - } - - @Override - public OrPredicate orPredicate(QueryPredicate... queryPredicates) { - return new OrPredicateImpl(queryPredicates); - } - - @Override - public FieldSortCriteria fieldSortCriteria(String attributeName, SortOrder sortOrder) { - return new FieldSortCriteriaImpl(attributeName, sortOrder); - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java deleted file mode 100644 index b5f08a94f84..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.query.FieldSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; - -/** - * Field sort criteria. - * - * @since 1.0 - * - */ -public class FieldSortCriteriaImpl implements FieldSortCriteria { - - /** - * Field attribute name - */ - private String attributeName; - - /** - * Field sort order - */ - private SortOrder sortOrder; - - /** - * Constructor - * - * @param attributeName - * @param sortOrder - */ - public FieldSortCriteriaImpl(String attributeName, SortOrder sortOrder) { - this.attributeName = attributeName; - this.sortOrder = sortOrder; - } - - /** - * Get the sort attribute name - * - * @return - */ - @Override - public String getAttributeName() { - return attributeName; - } - - /** - * Get the sort attribute order - * - * @return - */ - @Override - public SortOrder getSortOrder() { - return sortOrder; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java deleted file mode 100644 index ee03bb26e2b..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/QueryFactoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query; - -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.QueryFactory; - -import javax.inject.Singleton; - -/** - * {@link QueryFactory} implementation. - * - * @since 2.0.0 - */ -@Singleton -public class QueryFactoryImpl implements QueryFactory { - - @Override - public KapuaQuery newQuery() { - return new AbstractKapuaQuery() { - }; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java deleted file mode 100644 index a07c30cc5a2..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import com.google.common.collect.Lists; -import org.eclipse.kapua.model.query.predicate.AndPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * {@link AndPredicate} implementation. - * - * @since 1.0.0 - */ -public class AndPredicateImpl implements AndPredicate { - - private List predicates; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AndPredicateImpl() { - setPredicates(new ArrayList<>()); - } - - /** - * Constructor which accepts a not null array of {@link QueryPredicate}s. - * - * @param predicates the {@link QueryPredicate}s to add. - * @throws NullPointerException if the given parameter is {@code null}. - * @since 1.0.0 - */ - public AndPredicateImpl(@NotNull QueryPredicate... predicates) { - Objects.requireNonNull(predicates); - - setPredicates(Lists.newArrayList(predicates)); - } - - @Override - public AndPredicateImpl and(@NotNull QueryPredicate predicate) { - Objects.requireNonNull(predicates); - - getPredicates().add(predicate); - - return this; - } - - @Override - public List getPredicates() { - return this.predicates; - } - - @Override - public void setPredicates(List predicates) { - this.predicates = predicates; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java deleted file mode 100644 index bca11012e26..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import org.eclipse.kapua.model.query.predicate.AttributePredicate; - -/** - * {@link AttributePredicate} implementation. - * - * @since 1.0.0 - */ -public class AttributePredicateImpl implements AttributePredicate { - - private String attributeName; - private T attributeValue; - private Operator operator; - - /** - * Constructor. - *

- * Defaults ot {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator#EQUAL} - * - * @param attributeName The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param attributeValue The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @since 1.0.0 - */ - public AttributePredicateImpl(String attributeName, T attributeValue) { - this(attributeName, attributeValue, Operator.EQUAL); - } - - /** - * Constructor. - * - * @param attributeName The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param attributeValue The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. - * @param operator The {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator} to set into the {@link AttributePredicate}. - * @since 1.0.0 - */ - public AttributePredicateImpl(String attributeName, T attributeValue, Operator operator) { - this.attributeName = attributeName; - this.attributeValue = attributeValue; - this.operator = operator; - } - - @Override - public String getAttributeName() { - return attributeName; - } - - @Override - public T getAttributeValue() { - return attributeValue; - } - - @Override - public Operator getOperator() { - return operator; - } - -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java deleted file mode 100644 index 579e51c40de..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; - -import com.google.common.collect.Lists; -import org.eclipse.kapua.model.query.predicate.OrPredicate; -import org.eclipse.kapua.model.query.predicate.QueryPredicate; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * {@link OrPredicate} implementation. - * - * @since 1.0.0 - */ -public class OrPredicateImpl implements OrPredicate { - - private List predicates; - - /** - * Constructor. - * - * @since 1.0.0 - */ - public OrPredicateImpl() { - setPredicates(new ArrayList<>()); - } - - /** - * Constructor which accepts a not {@code null} array of {@link QueryPredicate}s. - * - * @param predicates the {@link QueryPredicate}s to add. - * @throws NullPointerException if the given parameter is {@code null}. - * @since 1.0.0 - */ - public OrPredicateImpl(@NotNull QueryPredicate... predicates) { - Objects.requireNonNull(predicates); - - setPredicates(Lists.newArrayList(predicates)); - } - - @Override - public OrPredicateImpl or(@NotNull QueryPredicate predicate) { - Objects.requireNonNull(predicates); - - getPredicates().add(predicate); - - return this; - } - - @Override - public List getPredicates() { - return this.predicates; - } - - @Override - public void setPredicates(List predicates) { - this.predicates = predicates; - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java index 944d14d51db..b08e336761e 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface EventStoreFactory extends KapuaEntityFactory { +public interface EventStoreFactory extends KapuaEntityFactory { } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java index 9f359cf8d18..6f05c3403c3 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreRecordQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.api; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link EventStoreRecord} {@link KapuaQuery} definition. * @@ -27,6 +28,27 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = EventStoreXmlRegistry.class, factoryMethod = "newQuery") -public interface EventStoreRecordQuery extends KapuaQuery { +@XmlType +public class EventStoreRecordQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + public EventStoreRecordQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public EventStoreRecordQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java index 0ea0521588e..8969833f06e 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/api/EventStoreXmlRegistry.java @@ -38,9 +38,4 @@ public EventStoreRecord newEventStoreRecord() { public EventStoreRecordCreator newEventStoreRecordCreator() { return kapuaEventFactory.newCreator(null); } - - public EventStoreRecordQuery newQuery() { - return kapuaEventFactory.newQuery(null); - } - } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java index c6b25def06f..2c735c60922 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; import org.eclipse.kapua.model.id.KapuaId; /** @@ -39,11 +38,6 @@ public EventStoreRecordCreator newCreator(KapuaId scopeId) { return new EventStoreRecordCreatorImpl(scopeId); } - @Override - public EventStoreRecordQuery newQuery(KapuaId scopeId) { - return new EventStoreQueryImpl(scopeId); - } - @Override public EventStoreRecord clone(EventStoreRecord eventStoreRecord) { try { diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java deleted file mode 100644 index b50c177ccc4..00000000000 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.service.event.store.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * {@link EventStoreRecordQuery} implementation. - * - * @since 1.0.0 - */ -public class EventStoreQueryImpl extends AbstractKapuaQuery implements EventStoreRecordQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public EventStoreQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public EventStoreQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java index 47ab5ce0c2a..fc24cd38683 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/KapuaNamedEntityServiceUtils.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.internal; +import java.util.Collections; +import java.util.List; + +import javax.validation.constraints.NotNull; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaDuplicateNameInAnotherAccountError; import org.eclipse.kapua.KapuaException; @@ -21,16 +26,11 @@ import org.eclipse.kapua.model.KapuaNamedEntityAttributes; import org.eclipse.kapua.model.KapuaNamedEntityCreator; import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.model.query.predicate.QueryPredicate; import org.eclipse.kapua.service.KapuaEntityService; -import javax.validation.constraints.NotNull; -import java.util.Collections; -import java.util.List; - /** * Util class that offers checks on the {@link KapuaNamedEntity#getName()} uniqueness in different flavors. * @@ -41,7 +41,6 @@ public class KapuaNamedEntityServiceUtils { private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); - private static final QueryFactory QUERY_FACTORY = LOCATOR.getFactory(QueryFactory.class); /** * Constructor. @@ -56,36 +55,52 @@ private KapuaNamedEntityServiceUtils() { /** * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()}. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) throws KapuaException { + public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) + throws KapuaException { checkEntityNameUniqueness(kapuaNamedEntityService, creator, Collections.emptyList()); } /** - * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()} with additional {@link QueryPredicate}s to customize the check. + * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within the {@link KapuaNamedEntityCreator#getScopeId()} with additional {@link QueryPredicate}s to customize the + * check. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param additionalPredicates The additional {@link QueryPredicate}s to customize the check - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param additionalPredicates + * The additional {@link QueryPredicate}s to customize the check + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within the {@link KapuaNamedEntityCreator#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator, @NotNull List additionalPredicates) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static > void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator, + @NotNull List additionalPredicates) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setScopeId(creator.getScopeId()); AndPredicate andPredicate = query.andPredicate(); @@ -105,11 +120,16 @@ public static > /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within the {@link KapuaNamedEntity#getScopeId()}. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @@ -121,18 +141,25 @@ public static void checkEntityNameUniqueness(@NotNu /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within the {@link KapuaNamedEntity#getScopeId()} with additional {@link QueryPredicate}s to customize the check. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param additionalPredicates The additional {@link QueryPredicate}s to customize the check - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param additionalPredicates + * The additional {@link QueryPredicate}s to customize the check + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within the {@link KapuaNamedEntity#getScopeId()}. + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity, @NotNull List additionalPredicates) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static void checkEntityNameUniqueness(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity, + @NotNull List additionalPredicates) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setScopeId(entity.getScopeId()); AndPredicate andPredicate = query.andPredicate(); @@ -153,18 +180,25 @@ public static void checkEntityNameUniqueness(@NotNu /** * Checks that the given {@link KapuaNamedEntityCreator#getName()} is unique within all the scopes. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param creator The {@link KapuaNamedEntityCreator} to check. - * @param The {@link KapuaNamedEntity} type. - * @param The {@link KapuaNamedEntityCreator} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntityCreator#getName()} is duplicated within all the scopes - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param creator + * The {@link KapuaNamedEntityCreator} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @param + * The {@link KapuaNamedEntityCreator} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntityCreator#getName()} is duplicated within all the scopes + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated - public static > void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull C creator) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + public static > void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, + @NotNull C creator) throws KapuaException { + KapuaQuery query = new KapuaQuery(); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, creator.getName())); if (KapuaSecurityUtils.doPrivileged(() -> kapuaNamedEntityService.count(query) > 0)) { @@ -175,17 +209,22 @@ public static > /** * Checks that the given {@link KapuaNamedEntity#getName()} is unique within all the scopes. * - * @param kapuaNamedEntityService The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. - * @param entity The {@link KapuaNamedEntity} to check. - * @param The {@link KapuaNamedEntity} type. - * @throws KapuaDuplicateNameException if the {@link KapuaNamedEntity#getName()} is duplicated within all the scopes - * @throws KapuaException if any other error occurs. + * @param kapuaNamedEntityService + * The {@link KapuaEntityService} to use. Usually it is the same service that is using this utility. + * @param entity + * The {@link KapuaNamedEntity} to check. + * @param + * The {@link KapuaNamedEntity} type. + * @throws KapuaDuplicateNameException + * if the {@link KapuaNamedEntity#getName()} is duplicated within all the scopes + * @throws KapuaException + * if any other error occurs. * @since 2.0.0 * @deprecated since 2.0.0 - use {@link org.eclipse.kapua.storage.KapuaNamedEntityRepository} instead */ @Deprecated public static void checkEntityNameUniquenessInAllScopes(@NotNull KapuaEntityService kapuaNamedEntityService, @NotNull E entity) throws KapuaException { - KapuaQuery query = QUERY_FACTORY.newQuery(); + KapuaQuery query = new KapuaQuery(); query.setPredicate( query.andPredicate( query.attributePredicate(KapuaNamedEntityAttributes.NAME, entity.getName()), diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java index e3febf8c3da..ee179add2f1 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/internal/ServiceDAO.java @@ -12,7 +12,32 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.internal; -import com.google.common.base.MoreObjects; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.Embedded; +import javax.persistence.EntityExistsException; +import javax.persistence.NonUniqueResultException; +import javax.persistence.PersistenceException; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Order; +import javax.persistence.criteria.ParameterExpression; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.EntityType; +import javax.validation.constraints.Null; + import org.apache.commons.lang.ArrayUtils; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -23,8 +48,6 @@ import org.eclipse.kapua.commons.jpa.EntityManager; import org.eclipse.kapua.commons.model.AbstractKapuaUpdatableEntity; import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.commons.security.KapuaSession; import org.eclipse.kapua.commons.setting.system.SystemSetting; @@ -69,30 +92,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.persistence.Embedded; -import javax.persistence.EntityExistsException; -import javax.persistence.NonUniqueResultException; -import javax.persistence.PersistenceException; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.ParameterExpression; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.persistence.metamodel.Attribute; -import javax.persistence.metamodel.EntityType; -import javax.validation.constraints.Null; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.google.common.base.MoreObjects; /** * {@link ServiceDAO} utility methods. @@ -169,8 +169,10 @@ protected ServiceDAO() { *

* This method checks for the constraint violation and, in this case, it throws a specific exception ({@link KapuaEntityExistsException}). * - * @param em The {@link EntityManager} that holds the transaction. - * @param entity The {@link KapuaEntity} to be persisted. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param entity + * The {@link KapuaEntity} to be persisted. * @return The persisted {@link KapuaEntity}. * @since 1.0.0 */ @@ -199,11 +201,15 @@ public static E create(@NonNull EntityManager em, @NonNu /** * Updates the {@link KapuaUpdatableEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaUpdatableEntity} class. This must be the implementing {@code class}. - * @param entity The {@link KapuaUpdatableEntity} to be updated. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaUpdatableEntity} class. This must be the implementing {@code class}. + * @param entity + * The {@link KapuaUpdatableEntity} to be updated. * @return The updated {@link KapuaUpdatableEntity}. - * @throws KapuaEntityNotFoundException If the {@link KapuaEntity} does not exist. + * @throws KapuaEntityNotFoundException + * If the {@link KapuaEntity} does not exist. * @since 1.0.0 */ public static E update(@NonNull EntityManager em, @NonNull Class clazz, @NonNull E entity) throws KapuaEntityNotFoundException { @@ -231,10 +237,14 @@ public static E update(@NonNull EntityManager e /** * Finds a {@link KapuaEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} the entity to be found. - * @param entityId The {@link KapuaEntity#getId()} of the entity to be found. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} the entity to be found. + * @param entityId + * The {@link KapuaEntity#getId()} of the entity to be found. * @since 1.0.0 */ public static E find(@NonNull EntityManager em, @NonNull Class clazz, @Null KapuaId scopeId, @NonNull KapuaId entityId) { @@ -263,76 +273,96 @@ public static E find(@NonNull EntityManager em, @NonNull /** * Finds a {@link KapuaNamedEntity} by {@link KapuaNamedEntity#getName()}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. - * @param value The value of the {@link KapuaNamedEntity#getName()} to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. + * @param value + * The value of the {@link KapuaNamedEntity#getName()} to search. * @return The {@link KapuaNamedEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned + * @throws NonUniqueResultException + * When more than one result is returned * @since 2.0.0 */ @Nullable public static E findByName(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull Object value) { + @NonNull Class clazz, + @NonNull Object value) { return findByName(em, clazz, KapuaId.ANY, value); } /** * Finds a {@link KapuaNamedEntity} by {@link KapuaNamedEntity#getName()}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaNamedEntity#getScopeId()} in which to look for results. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaNamedEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaNamedEntity#getScopeId()} in which to look for results. + * @param value + * The value of the field from which to search. * @return The {@link KapuaNamedEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable public static E findByName(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull KapuaId scopeId, - @NonNull Object value) { + @NonNull Class clazz, + @NonNull KapuaId scopeId, + @NonNull Object value) { return findByField(em, clazz, scopeId, KapuaNamedEntityAttributes.NAME, value); } /** * Find a {@link KapuaEntity} by one of its fields. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param name The {@link KapuaEntity} name of the field from which to search. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param name + * The {@link KapuaEntity} name of the field from which to search. + * @param value + * The value of the field from which to search. * @return The {@link KapuaEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable public static E findByField(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull String name, - @NonNull Object value) { + @NonNull Class clazz, + @NonNull String name, + @NonNull Object value) { return findByField(em, clazz, KapuaId.ANY, name, value); } /** * Find a {@link KapuaEntity} by one of its fields. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} in which to look for results. - * @param name The {@link KapuaEntity} name of the field from which to search. - * @param value The value of the field from which to search. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} in which to look for results. + * @param name + * The {@link KapuaEntity} name of the field from which to search. + * @param value + * The value of the field from which to search. * @return The {@link KapuaEntity} found, or {@code null} if not found. - * @throws NonUniqueResultException When more than one result is returned. + * @throws NonUniqueResultException + * When more than one result is returned. * @since 1.0.0 */ @Nullable public static E findByField(@NonNull EntityManager em, - @NonNull Class clazz, - @NonNull KapuaId scopeId, - @NonNull String name, - @NonNull Object value) { + @NonNull Class clazz, + @NonNull KapuaId scopeId, + @NonNull String name, + @NonNull Object value) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(clazz); @@ -371,32 +401,38 @@ public static E findByField(@NonNull EntityManager em, // QUERY! List result = query.getResultList(); switch (result.size()) { - case 0: - return null; - case 1: - return result.get(0); - default: - throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", clazz.getName(), pName, value.toString())); + case 0: + return null; + case 1: + return result.get(0); + default: + throw new NonUniqueResultException(String.format("Multiple %s results found for field %s with value %s", clazz.getName(), pName, value.toString())); } } /** * Queries the {@link KapuaEntity}es. * - * @param em The {@link EntityManager} that holds the transaction. - * @param interfaceClass {@link KapuaQuery} result entity interface class - * @param implementingClass {@link KapuaQuery} result entity implementation class - * @param resultContainer The {@link KapuaListResult} in which load the result. It must be empty. - * @param kapuaQuery The {@link KapuaQuery} to perform. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param interfaceClass + * {@link KapuaQuery} result entity interface class + * @param implementingClass + * {@link KapuaQuery} result entity implementation class + * @param resultContainer + * The {@link KapuaListResult} in which load the result. It must be empty. + * @param kapuaQuery + * The {@link KapuaQuery} to perform. * @return The reference of the {@code resultContainer} parameter. Results are added to the given {@code resultContainer} parameter. - * @throws KapuaException If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. + * @throws KapuaException + * If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. * @since 1.0.0 */ public static > L query(@NonNull EntityManager em, - @NonNull Class interfaceClass, - @NonNull Class implementingClass, - @NonNull L resultContainer, - @NonNull KapuaQuery kapuaQuery) + @NonNull Class interfaceClass, + @NonNull Class implementingClass, + @NonNull L resultContainer, + @NonNull KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(implementingClass); @@ -506,18 +542,23 @@ public static > /** * Counts the {@link KapuaEntity}es. * - * @param em The {@link EntityManager} that holds the transaction. - * @param interfaceClass {@link KapuaQuery} result entity interface class - * @param implementingClass {@link KapuaQuery} result entity implementation class - * @param kapuaQuery The {@link KapuaQuery} to perform. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param interfaceClass + * {@link KapuaQuery} result entity interface class + * @param implementingClass + * {@link KapuaQuery} result entity implementation class + * @param kapuaQuery + * The {@link KapuaQuery} to perform. * @return The number of {@link KapuaEntity}es that matched the filter predicates. - * @throws KapuaException If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. + * @throws KapuaException + * If filter predicates in the {@link KapuaQuery} are incorrect. See {@link #handleKapuaQueryPredicates(QueryPredicate, Map, CriteriaBuilder, Root, EntityType)}. * @since 1.0.0 */ public static long count(@NonNull EntityManager em, - @NonNull Class interfaceClass, - @NonNull Class implementingClass, - @NonNull KapuaQuery kapuaQuery) + @NonNull Class interfaceClass, + @NonNull Class implementingClass, + @NonNull KapuaQuery kapuaQuery) throws KapuaException { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery criteriaSelectQuery = cb.createQuery(Long.class); @@ -573,12 +614,17 @@ public static long count(@NonNull EntityMan /** * Deletes a {@link KapuaEntity}. * - * @param em The {@link EntityManager} that holds the transaction. - * @param clazz The {@link KapuaEntity} class. This must be the implementing {@code class}. - * @param scopeId The {@link KapuaEntity#getScopeId()} of the entity to be deleted. - * @param entityId The {@link KapuaEntity#getId()} of the entity to be deleted. + * @param em + * The {@link EntityManager} that holds the transaction. + * @param clazz + * The {@link KapuaEntity} class. This must be the implementing {@code class}. + * @param scopeId + * The {@link KapuaEntity#getScopeId()} of the entity to be deleted. + * @param entityId + * The {@link KapuaEntity#getId()} of the entity to be deleted. * @return The deleted {@link KapuaEntity}. - * @throws KapuaEntityNotFoundException If the {@link KapuaEntity} does not exists. + * @throws KapuaEntityNotFoundException + * If the {@link KapuaEntity} does not exists. * @since 1.0.0 */ public static E delete(@NonNull EntityManager em, @NonNull Class clazz, @NonNull KapuaId scopeId, @NonNull KapuaId entityId) @@ -617,19 +663,25 @@ public static E delete(@NonNull EntityManager em, @NonNu *

* It can be invoked recursively (i.e. to handle {@link AttributePredicate}s of the {@link AndPredicate}. * - * @param queryPredicate The {@link QueryPredicate} to handle. - * @param binds The {@link Map}≶{@link String}, {@link Object}> of the query values. - * @param cb The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. - * @param userPermissionRoot The JPA {@link Root} of the {@link javax.persistence.Query}. - * @param entityType The JPA {@link EntityType} of the {@link javax.persistence.Query}. + * @param queryPredicate + * The {@link QueryPredicate} to handle. + * @param binds + * The {@link Map}≶{@link String}, {@link Object}> of the query values. + * @param cb + * The JPA {@link CriteriaBuilder} of the {@link javax.persistence.Query}. + * @param userPermissionRoot + * The JPA {@link Root} of the {@link javax.persistence.Query}. + * @param entityType + * The JPA {@link EntityType} of the {@link javax.persistence.Query}. * @return The handled {@link Predicate} - * @throws KapuaException If any problem occurs. + * @throws KapuaException + * If any problem occurs. */ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate queryPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root userPermissionRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root userPermissionRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate predicate = null; if (queryPredicate instanceof AttributePredicate) { @@ -643,9 +695,9 @@ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } else if (queryPredicate instanceof MatchPredicate) { MatchPredicate matchPredicate = (MatchPredicate) queryPredicate; - OrPredicate orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); for (String attributeName : matchPredicate.getAttributeNames()) { - orPredicate.getPredicates().add(new AttributePredicateImpl<>(attributeName, matchPredicate.getMatchTerm(), Operator.STARTS_WITH_IGNORE_CASE)); + orPredicate.getPredicates().add(new AttributePredicate<>(attributeName, matchPredicate.getMatchTerm(), Operator.STARTS_WITH_IGNORE_CASE)); } predicate = handleOrPredicate(orPredicate, binds, cb, userPermissionRoot, entityType); } @@ -653,10 +705,10 @@ private static Predicate handleKapuaQueryPredicates(@NonNull QueryPredicate } private static Predicate handleAndPredicate(@NonNull AndPredicate andPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaAndPredicates = @@ -672,10 +724,10 @@ private static Predicate handleAndPredicate(@NonNull AndPredicate andPredica } private static Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = @@ -690,10 +742,10 @@ private static Predicate handleOrPredicate(@NonNull OrPredicate orPredicate, } private static Predicate[] handlePredicate(@NonNull List orPredicates, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) throws KapuaException { + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate[] jpaOrPredicates = new Predicate[orPredicates.size()]; for (int i = 0; i < orPredicates.size(); i++) { @@ -704,10 +756,10 @@ private static Predicate[] handlePredicate(@NonNull List orP } private static Predicate handleAttributePredicate(@NonNull AttributePredicate attrPred, - @NonNull Map binds, - @NonNull CriteriaBuilder cb, - @NonNull Root entityRoot, - @NonNull EntityType entityType) + @NonNull Map binds, + @NonNull CriteriaBuilder cb, + @NonNull Root entityRoot, + @NonNull EntityType entityType) throws KapuaException { Predicate expr; String attrName = attrPred.getAttributeName(); @@ -753,88 +805,88 @@ private static Predicate handleAttributePredicate(@NonNull AttributePredicat } else { String strAttrValue; switch (attrPred.getOperator()) { - case LIKE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); - ParameterExpression pl = cb.parameter(String.class); - binds.put(pl, LIKE + strAttrValue + LIKE); - expr = cb.like(extractAttribute(entityRoot, attrName), pl); - break; - - case LIKE_IGNORE_CASE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); - ParameterExpression plci = cb.parameter(String.class); - binds.put(plci, LIKE + strAttrValue + LIKE); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); - break; - - case STARTS_WITH: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); - ParameterExpression psw = cb.parameter(String.class); - binds.put(psw, strAttrValue + LIKE); - expr = cb.like(extractAttribute(entityRoot, attrName), psw); - break; - - case STARTS_WITH_IGNORE_CASE: - strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); - ParameterExpression pswci = cb.parameter(String.class); - binds.put(pswci, strAttrValue + LIKE); - expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); - break; - - case IS_NULL: - expr = cb.isNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_NULL: - expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); - break; - - case NOT_EQUAL: - expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); - break; - - case GREATER_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Comparable comparableAttrValue = (Comparable) attributeValue; - Expression comparableExpression = extractAttribute(entityRoot, attrName); - expr = cb.greaterThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case GREATER_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - - case LESS_THAN: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThan(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; - case LESS_THAN_OR_EQUAL: - if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { - Expression comparableExpression = extractAttribute(entityRoot, attrName); - Comparable comparableAttrValue = (Comparable) attributeValue; - expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); - } else { - throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); - } - break; + case LIKE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); + ParameterExpression pl = cb.parameter(String.class); + binds.put(pl, LIKE + strAttrValue + LIKE); + expr = cb.like(extractAttribute(entityRoot, attrName), pl); + break; + + case LIKE_IGNORE_CASE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); + ParameterExpression plci = cb.parameter(String.class); + binds.put(plci, LIKE + strAttrValue + LIKE); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), plci); + break; + + case STARTS_WITH: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY); + ParameterExpression psw = cb.parameter(String.class); + binds.put(psw, strAttrValue + LIKE); + expr = cb.like(extractAttribute(entityRoot, attrName), psw); + break; + + case STARTS_WITH_IGNORE_CASE: + strAttrValue = attributeValue.toString().replace(LIKE, ESCAPE + LIKE).replace(ANY, ESCAPE + ANY).toLowerCase(); + ParameterExpression pswci = cb.parameter(String.class); + binds.put(pswci, strAttrValue + LIKE); + expr = cb.like(cb.lower(extractAttribute(entityRoot, attrName)), pswci); + break; + + case IS_NULL: + expr = cb.isNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_NULL: + expr = cb.isNotNull(extractAttribute(entityRoot, attrName)); + break; + + case NOT_EQUAL: + expr = cb.notEqual(extractAttribute(entityRoot, attrName), attributeValue); + break; + + case GREATER_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Comparable comparableAttrValue = (Comparable) attributeValue; + Expression comparableExpression = extractAttribute(entityRoot, attrName); + expr = cb.greaterThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case GREATER_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.greaterThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + + case LESS_THAN: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThan(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; + case LESS_THAN_OR_EQUAL: + if (attributeValue instanceof Comparable && ArrayUtils.contains(attribute.getJavaType().getInterfaces(), Comparable.class)) { + Expression comparableExpression = extractAttribute(entityRoot, attrName); + Comparable comparableAttrValue = (Comparable) attributeValue; + expr = cb.lessThanOrEqualTo(comparableExpression, comparableAttrValue); + } else { + throw new KapuaException(KapuaErrorCodes.ILLEGAL_ARGUMENT, COMPARE_ERROR_MESSAGE); + } + break; - case EQUAL: - default: - expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); + case EQUAL: + default: + expr = cb.equal(extractAttribute(entityRoot, attrName), attributeValue); } } return expr; @@ -847,8 +899,10 @@ private static Predicate handleAttributePredicate(@NonNull AttributePredicat *

* Filter predicates takes advantage of the dot notation to access {@link Embedded} attributes and nested {@link KapuaEntity}es. * - * @param entityRoot The {@link Root} entity from which extract the attribute. - * @param attributeName The full attribute name. + * @param entityRoot + * The {@link Root} entity from which extract the attribute. + * @param attributeName + * The full attribute name. * @return The {@link Path} expression that matches the given {@code attributeName} parameter. * @since 1.0.0 */ @@ -870,9 +924,12 @@ private static Path

extractAttribute(@NonNull Root entityRoot, @Non /** * Handles the {@link Groupable} property of the {@link KapuaEntity}. * - * @param query The {@link KapuaQuery} to manage. - * @param domain The {@link Domain} inside which the {@link KapuaQuery} param targets. - * @param groupPredicateName The name of the {@link Group} id field. + * @param query + * The {@link KapuaQuery} to manage. + * @param domain + * The {@link Domain} inside which the {@link KapuaQuery} param targets. + * @param groupPredicateName + * The name of the {@link Group} id field. * @since 1.0.0 */ protected static void handleKapuaQueryGroupPredicate(@NonNull KapuaQuery query, @NonNull Domain domain, @NonNull String groupPredicateName) throws KapuaException { @@ -971,7 +1028,8 @@ private static boolean checkGroupPermission(@NonNull Domain domain, @NonNull Lis /** * Check if the given {@link PersistenceException} is a SQL constraint violation error. * - * @param persistenceException {@link PersistenceException} to check. + * @param persistenceException + * {@link PersistenceException} to check. * @return {@code true} if it is a constraint validation error, {@code false} otherwise. * @since 1.0.0 */ diff --git a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java deleted file mode 100644 index 43e8195d15c..00000000000 --- a/commons/src/test/java/org/eclipse/kapua/commons/configuration/ServiceConfigQueryImplTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.configuration; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - - -@Category(JUnitTests.class) -public class ServiceConfigQueryImplTest { - - @Test - public void createInstanceTest() { - ServiceConfigQueryImpl query = new ServiceConfigQueryImpl(KapuaId.ONE); - Assert.assertEquals(query.getScopeId(), KapuaId.ONE); - } - -} diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaTest.java similarity index 64% rename from commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImplTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaTest.java index 0e93245f75e..64125803b90 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/query/FieldSortCriteriaTest.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model.query; +import java.util.Arrays; + +import org.eclipse.kapua.model.query.FieldSortCriteria; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; @@ -21,40 +24,38 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; - - @Category(JUnitTests.class) @RunWith(value = Parameterized.class) -public class FieldSortCriteriaImplTest { +public class FieldSortCriteriaTest { private final String attributeName; private SortOrder sortOrder; - public FieldSortCriteriaImplTest(String attributeName) { + public FieldSortCriteriaTest(String attributeName) { this.attributeName = attributeName; } @Parameters public static Iterable attributeNames() { return Arrays.asList( - new Object[]{""}, - new Object[]{"NAME"}, - new Object[]{"attributeName"}, - new Object[]{"attribute name"}, - new Object[]{"0123456789"}, - new Object[]{"!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ"}, - new Object[]{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg"}); + new Object[] { "" }, + new Object[] { "NAME" }, + new Object[] { "attributeName" }, + new Object[] { "attribute name" }, + new Object[] { "0123456789" }, + new Object[] { "!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ" }, + new Object[] { + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg" }); } @Test public void fieldSortCriteriaImplTest() { SortOrder sortOrderAscending = SortOrder.ASCENDING; - FieldSortCriteriaImpl fieldSortCriteriaAscending = new FieldSortCriteriaImpl(attributeName, sortOrderAscending); + FieldSortCriteria fieldSortCriteriaAscending = new FieldSortCriteria(attributeName, sortOrderAscending); Assert.assertEquals("Actual and expected values are not the same!", attributeName, fieldSortCriteriaAscending.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", sortOrderAscending, fieldSortCriteriaAscending.getSortOrder()); SortOrder sortOrderDescending = SortOrder.DESCENDING; - FieldSortCriteriaImpl fieldSortCriteriaDescending = new FieldSortCriteriaImpl(attributeName, sortOrderDescending); + FieldSortCriteria fieldSortCriteriaDescending = new FieldSortCriteria(attributeName, sortOrderDescending); Assert.assertEquals("Actual and expected values are not the same!", attributeName, fieldSortCriteriaDescending.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", sortOrderDescending, fieldSortCriteriaDescending.getSortOrder()); } diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQueryTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/query/KapuaQueryTest.java similarity index 70% rename from commons/src/test/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQueryTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/query/KapuaQueryTest.java index b04a8c0fb42..69c2958adef 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/query/AbstractKapuaQueryTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/query/KapuaQueryTest.java @@ -12,10 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model.query; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.FieldSortCriteria; import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.KapuaSortCriteria; import org.eclipse.kapua.model.query.SortOrder; @@ -32,60 +36,40 @@ import org.junit.runners.Parameterized.Parameters; import org.mockito.Mockito; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - - @Category(JUnitTests.class) @RunWith(value = Parameterized.class) -public class AbstractKapuaQueryTest { +public class KapuaQueryTest { private final String attributeName; private final AttributePredicate.Operator operator; - public AbstractKapuaQueryTest(String attributeName, AttributePredicate.Operator operator) { + public KapuaQueryTest(String attributeName, AttributePredicate.Operator operator) { this.attributeName = attributeName; this.operator = operator; } @Parameters public static Collection attributeNamesAndOperators() { - return Arrays.asList(new Object[][]{ - {"", AttributePredicate.Operator.EQUAL}, - {"NAME", AttributePredicate.Operator.NOT_EQUAL}, - {"attributeName", AttributePredicate.Operator.IS_NULL}, - {"attribute name", AttributePredicate.Operator.NOT_NULL}, - {"0123456789", AttributePredicate.Operator.GREATER_THAN}, - {"!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ", AttributePredicate.Operator.GREATER_THAN_OR_EQUAL}, - {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg", AttributePredicate.Operator.STARTS_WITH}, - {"ATTRIBUTE NAME", AttributePredicate.Operator.LIKE}, - {"name123", AttributePredicate.Operator.LESS_THAN}, - {"#$attribute", AttributePredicate.Operator.LESS_THAN_OR_EQUAL}, + return Arrays.asList(new Object[][] { + { "", AttributePredicate.Operator.EQUAL }, + { "NAME", AttributePredicate.Operator.NOT_EQUAL }, + { "attributeName", AttributePredicate.Operator.IS_NULL }, + { "attribute name", AttributePredicate.Operator.NOT_NULL }, + { "0123456789", AttributePredicate.Operator.GREATER_THAN }, + { "!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ", AttributePredicate.Operator.GREATER_THAN_OR_EQUAL }, + { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg", + AttributePredicate.Operator.STARTS_WITH }, + { "ATTRIBUTE NAME", AttributePredicate.Operator.LIKE }, + { "name123", AttributePredicate.Operator.LESS_THAN }, + { "#$attribute", AttributePredicate.Operator.LESS_THAN_OR_EQUAL }, }); } - private class ActualKapuaQuery extends AbstractKapuaQuery { - - public ActualKapuaQuery() { - super(); - } - - public ActualKapuaQuery(KapuaId scopeId) { - super(scopeId); - } - - public ActualKapuaQuery(KapuaQuery query) { - super(query); - } - } - @Test public void abstractKapuaQueryScopeIdTest() { KapuaId scopeId = new KapuaEid(); - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(scopeId); + KapuaQuery kapuaQuery = new KapuaQuery(scopeId); Assert.assertEquals("Actual and expected values are not the same!", scopeId, kapuaQuery.getScopeId()); } @@ -93,18 +77,18 @@ public void abstractKapuaQueryScopeIdTest() { public void abstractKapuaQueryQueryIdTest() { KapuaId scopeId = new KapuaEid(); List fetchAttributes = new ArrayList<>(); - QueryPredicate predicate = Mockito.mock(AndPredicateImpl.class); + QueryPredicate predicate = Mockito.mock(AndPredicate.class); SortOrder sortOrder = SortOrder.ASCENDING; - KapuaSortCriteria sortCriteria = new FieldSortCriteriaImpl(attributeName, sortOrder); + KapuaSortCriteria sortCriteria = new FieldSortCriteria(attributeName, sortOrder); Integer limit = 48; Integer offset = 56; - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(scopeId); + KapuaQuery kapuaQuery = new KapuaQuery(scopeId); kapuaQuery.setFetchAttributes(fetchAttributes); kapuaQuery.setPredicate(predicate); kapuaQuery.setLimit(limit); kapuaQuery.setOffset(offset); kapuaQuery.setSortCriteria(sortCriteria); - AbstractKapuaQuery kapuaCopyQuery = new ActualKapuaQuery(kapuaQuery); + KapuaQuery kapuaCopyQuery = new KapuaQuery(kapuaQuery); Assert.assertEquals("Actual and expected values are not the same!", kapuaQuery.getFetchAttributes(), kapuaCopyQuery.getFetchAttributes()); Assert.assertEquals("Actual and expected values are not the same!", kapuaQuery.getPredicate(), kapuaCopyQuery.getPredicate()); Assert.assertEquals("Actual and expected values are not the same!", kapuaQuery.getLimit(), kapuaCopyQuery.getLimit()); @@ -114,7 +98,7 @@ public void abstractKapuaQueryQueryIdTest() { @Test public void addFetchAttributesTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); String emptyFetchAttribute = ""; String fetchAttribute = "fetchAttribute"; kapuaQuery.addFetchAttributes(null); @@ -127,7 +111,7 @@ public void addFetchAttributesTest() { @Test public void attributePredicateTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); Object attributeValue = new Object(); AttributePredicate attributePredicate = kapuaQuery.attributePredicate(attributeName, attributeValue); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicate.getAttributeName()); @@ -136,7 +120,7 @@ public void attributePredicateTest() { @Test public void attributePredicateWithOperatorTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); Object attributeValue = new Object(); AttributePredicate attributePredicate = kapuaQuery.attributePredicate(attributeName, attributeValue, operator); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicate.getAttributeName()); @@ -146,7 +130,7 @@ public void attributePredicateWithOperatorTest() { @Test public void andPredicateTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); AndPredicate andPredicate = kapuaQuery.andPredicate(); ArrayList queryPredicateArray = new ArrayList<>(); Assert.assertEquals("Actual and expected values are not the same!", queryPredicateArray, andPredicate.getPredicates()); @@ -154,18 +138,18 @@ public void andPredicateTest() { @Test public void andPredicateWithQueryPredicatesTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); QueryPredicate[] queryPredicateArray = new QueryPredicate[10]; for (int i = 0; i < queryPredicateArray.length; i++) { - queryPredicateArray[i] = Mockito.mock(AndPredicateImpl.class); + queryPredicateArray[i] = Mockito.mock(AndPredicate.class); } - AndPredicate andPredicate = new AndPredicateImpl(queryPredicateArray); + AndPredicate andPredicate = new AndPredicate(queryPredicateArray); Assert.assertEquals("Actual and expected values are not the same!", andPredicate.getPredicates(), kapuaQuery.andPredicate(queryPredicateArray).getPredicates()); } @Test public void orPredicateTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); OrPredicate orPredicate = kapuaQuery.orPredicate(); ArrayList queryPredicateArray = new ArrayList<>(); Assert.assertEquals("Actual and expected values are not the same!", queryPredicateArray, orPredicate.getPredicates()); @@ -173,18 +157,18 @@ public void orPredicateTest() { @Test public void orPredicateWithQueryPredicatesTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); QueryPredicate[] queryPredicateArray = new QueryPredicate[5]; for (int i = 0; i < queryPredicateArray.length; i++) { - queryPredicateArray[i] = Mockito.mock(AndPredicateImpl.class); + queryPredicateArray[i] = Mockito.mock(AndPredicate.class); } - OrPredicate orPredicate = new OrPredicateImpl(queryPredicateArray); + OrPredicate orPredicate = new OrPredicate(queryPredicateArray); Assert.assertEquals("Actual and expected values are not the same!", orPredicate.getPredicates(), kapuaQuery.orPredicate(queryPredicateArray).getPredicates()); } @Test public void getAskTotalCountTest() { - AbstractKapuaQuery kapuaQuery = new ActualKapuaQuery(); + KapuaQuery kapuaQuery = new KapuaQuery(); kapuaQuery.setAskTotalCount(true); Assert.assertEquals("Actual and expected values are not the same!", true, kapuaQuery.getAskTotalCount()); kapuaQuery.setAskTotalCount(false); diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateTest.java similarity index 68% rename from commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImplTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateTest.java index 8fa95c35c37..8adc5a119df 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AndPredicateTest.java @@ -12,36 +12,36 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model.query.predicate; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.QueryPredicate; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; -import java.util.ArrayList; -import java.util.List; - - @Category(JUnitTests.class) -public class AndPredicateImplTest { +public class AndPredicateTest { @Test public void andPredicateImpl() { - AndPredicateImpl andPredicate = new AndPredicateImpl(); + AndPredicate andPredicate = new AndPredicate(); ArrayList array = new ArrayList<>(); Assert.assertEquals("Actual and expected values are not the same!", array, andPredicate.getPredicates()); } @Test public void andPredicateImplQueryPredicateId() { - QueryPredicate queryPredicate = new AndPredicateImpl(); - AndPredicateImpl andPredicate = new AndPredicateImpl(queryPredicate); + QueryPredicate queryPredicate = new AndPredicate(); + AndPredicate andPredicate = new AndPredicate(queryPredicate); Assert.assertEquals("Actual and expected values are not the same!", queryPredicate, andPredicate.getPredicates().get(0)); - QueryPredicate queryPredicate1 = new AndPredicateImpl(); - QueryPredicate queryPredicate2 = new AndPredicateImpl(); - QueryPredicate queryPredicate3 = new AndPredicateImpl(); - QueryPredicate[] queryPredicateArray = {queryPredicate1, queryPredicate2, queryPredicate3}; - AndPredicateImpl andPredicateWithMultiplePredicates = new AndPredicateImpl(queryPredicate1, queryPredicate2, queryPredicate3); + QueryPredicate queryPredicate1 = new AndPredicate(); + QueryPredicate queryPredicate2 = new AndPredicate(); + QueryPredicate queryPredicate3 = new AndPredicate(); + QueryPredicate[] queryPredicateArray = { queryPredicate1, queryPredicate2, queryPredicate3 }; + AndPredicate andPredicateWithMultiplePredicates = new AndPredicate(queryPredicate1, queryPredicate2, queryPredicate3); for (int i = 0; i < queryPredicateArray.length; i++) { Assert.assertEquals("Actual and expected values are not the same!", queryPredicateArray[i], andPredicateWithMultiplePredicates.getPredicates().get(i)); } @@ -49,26 +49,26 @@ public void andPredicateImplQueryPredicateId() { @Test public void andTest() { - AndPredicateImpl andPredicate = new AndPredicateImpl(); - QueryPredicate queryPredicate = new AndPredicateImpl(); + AndPredicate andPredicate = new AndPredicate(); + QueryPredicate queryPredicate = new AndPredicate(); andPredicate.and(queryPredicate); Assert.assertEquals("Actual and expected values are not the same!", queryPredicate, andPredicate.getPredicates().get(0)); } @Test public void andWithNullPredicateTest() { - AndPredicateImpl andPredicate = new AndPredicateImpl(); + AndPredicate andPredicate = new AndPredicate(); andPredicate.and(null); Assert.assertNull(andPredicate.getPredicates().get(0)); } @Test public void getPredicatesTest() { - AndPredicateImpl andPredicate = new AndPredicateImpl(); + AndPredicate andPredicate = new AndPredicate(); List predicates = new ArrayList<>(); - predicates.add(new AndPredicateImpl()); - predicates.add(new AndPredicateImpl()); - predicates.add(new AndPredicateImpl()); + predicates.add(new AndPredicate()); + predicates.add(new AndPredicate()); + predicates.add(new AndPredicate()); andPredicate.setPredicates(predicates); for (int i = 0; i < predicates.size(); i++) { Assert.assertEquals("Actual and expected values are not the same!", predicates.get(i), andPredicate.getPredicates().get(i)); diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateTest.java similarity index 64% rename from commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImplTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateTest.java index 7a5f9e41180..9a5f9977ed2 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/AttributePredicateTest.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model.query.predicate; +import java.util.Arrays; +import java.util.Collection; + import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; @@ -21,87 +24,84 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; -import java.util.Collection; - - @Category(JUnitTests.class) @RunWith(value = Parameterized.class) -public class AttributePredicateImplTest { +public class AttributePredicateTest { private final String attributeName; private final AttributePredicate.Operator operator; - public AttributePredicateImplTest(String attributeName, AttributePredicate.Operator operator) { + public AttributePredicateTest(String attributeName, AttributePredicate.Operator operator) { this.attributeName = attributeName; this.operator = operator; } @Parameters public static Collection attributeNamesAndOperators() { - return Arrays.asList(new Object[][]{ - {"", AttributePredicate.Operator.EQUAL}, - {"NAME", AttributePredicate.Operator.NOT_EQUAL}, - {"attributeName", AttributePredicate.Operator.IS_NULL}, - {"attribute name", AttributePredicate.Operator.NOT_NULL}, - {"0123456789", AttributePredicate.Operator.GREATER_THAN}, - {"!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ", AttributePredicate.Operator.GREATER_THAN_OR_EQUAL}, - {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg", AttributePredicate.Operator.STARTS_WITH}, - {"ATTRIBUTE NAME", AttributePredicate.Operator.LIKE}, - {"name123", AttributePredicate.Operator.LESS_THAN}, - {"#$attribute", AttributePredicate.Operator.LESS_THAN_OR_EQUAL}, + return Arrays.asList(new Object[][] { + { "", AttributePredicate.Operator.EQUAL }, + { "NAME", AttributePredicate.Operator.NOT_EQUAL }, + { "attributeName", AttributePredicate.Operator.IS_NULL }, + { "attribute name", AttributePredicate.Operator.NOT_NULL }, + { "0123456789", AttributePredicate.Operator.GREATER_THAN }, + { "!#$%&'()=?⁄@‹›€°·‚,.-;:_Èˇ¿<>«‘”’ÉØ∏{}|ÆæÒuF8FFÔÓÌÏÎÅ«»Ç◊ш¯Èˇ", AttributePredicate.Operator.GREATER_THAN_OR_EQUAL }, + { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefg", + AttributePredicate.Operator.STARTS_WITH }, + { "ATTRIBUTE NAME", AttributePredicate.Operator.LIKE }, + { "name123", AttributePredicate.Operator.LESS_THAN }, + { "#$attribute", AttributePredicate.Operator.LESS_THAN_OR_EQUAL }, }); } @Test public void attributePredicateImplTest() { String attributeValueStr = ""; - AttributePredicateImpl attributePredicateStr = new AttributePredicateImpl<>(attributeName, attributeValueStr); + AttributePredicate attributePredicateStr = new AttributePredicate<>(attributeName, attributeValueStr); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateStr.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueStr, attributePredicateStr.getAttributeValue()); Integer attributeValueInt = 1234567890; - AttributePredicateImpl attributePredicateInt = new AttributePredicateImpl<>(attributeName, attributeValueInt); + AttributePredicate attributePredicateInt = new AttributePredicate<>(attributeName, attributeValueInt); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateInt.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueInt, attributePredicateInt.getAttributeValue()); Double attributeValueDouble = 123.23d; - AttributePredicateImpl attributePredicateDouble = new AttributePredicateImpl<>(attributeName, attributeValueDouble); + AttributePredicate attributePredicateDouble = new AttributePredicate<>(attributeName, attributeValueDouble); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateDouble.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueDouble, attributePredicateDouble.getAttributeValue()); Character attributeValueChar = 'a'; - AttributePredicateImpl attributePredicateChar = new AttributePredicateImpl<>(attributeName, attributeValueChar); + AttributePredicate attributePredicateChar = new AttributePredicate<>(attributeName, attributeValueChar); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateChar.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueChar, attributePredicateChar.getAttributeValue()); Long attributeValueLong = 12345678910L; - AttributePredicateImpl attributePredicateLong = new AttributePredicateImpl<>(attributeName, attributeValueLong); + AttributePredicate attributePredicateLong = new AttributePredicate<>(attributeName, attributeValueLong); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateLong.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueLong, attributePredicateLong.getAttributeValue()); - AttributePredicateImpl attributePredicateBooleanTrue = new AttributePredicateImpl<>(attributeName, true); + AttributePredicate attributePredicateBooleanTrue = new AttributePredicate<>(attributeName, true); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateBooleanTrue.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", true, attributePredicateBooleanTrue.getAttributeValue()); - AttributePredicateImpl attributePredicateBooleanFalse = new AttributePredicateImpl<>(attributeName, false); + AttributePredicate attributePredicateBooleanFalse = new AttributePredicate<>(attributeName, false); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateBooleanFalse.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", false, attributePredicateBooleanFalse.getAttributeValue()); Short attributeValueShort = Short.MAX_VALUE; - AttributePredicateImpl attributePredicateShort = new AttributePredicateImpl<>(attributeName, attributeValueShort); + AttributePredicate attributePredicateShort = new AttributePredicate<>(attributeName, attributeValueShort); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateShort.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueShort, attributePredicateShort.getAttributeValue()); Float attributeValueFloat = 123.23f; - AttributePredicateImpl attributePredicateFloat = new AttributePredicateImpl<>(attributeName, attributeValueFloat); + AttributePredicate attributePredicateFloat = new AttributePredicate<>(attributeName, attributeValueFloat); Assert.assertEquals("Actual and expected values are not the same!", attributeName, attributePredicateFloat.getAttributeName()); Assert.assertEquals("Actual and expected values are not the same!", attributeValueFloat, attributePredicateFloat.getAttributeValue()); } @Test public void getOperatorTest() { - AttributePredicate attributePredicate = new AttributePredicateImpl<>(attributeName, 1234567890, operator); + AttributePredicate attributePredicate = new AttributePredicate<>(attributeName, 1234567890, operator); Assert.assertEquals("Actual and expected values are not the same!", operator, attributePredicate.getOperator()); } } diff --git a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateTest.java similarity index 68% rename from commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImplTest.java rename to commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateTest.java index 87bc1c4aa5d..61d5d7920d8 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/model/query/predicate/OrPredicateTest.java @@ -12,37 +12,37 @@ *******************************************************************************/ package org.eclipse.kapua.commons.model.query.predicate; +import java.util.ArrayList; + +import org.eclipse.kapua.model.query.predicate.OrPredicate; import org.eclipse.kapua.model.query.predicate.QueryPredicate; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; -import java.util.ArrayList; - - @Category(JUnitTests.class) -public class OrPredicateImplTest { +public class OrPredicateTest { @Test public void orPredicateImplGetPredicateTest() { - OrPredicateImpl orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); ArrayList array = new ArrayList<>(); Assert.assertEquals("Actual and expected values are not the same!", array, orPredicate.getPredicates()); } @Test(expected = NullPointerException.class) public void orPredicateImplQueryPredicateId() { - OrPredicateImpl orPredicateNull = new OrPredicateImpl(null); + OrPredicate orPredicateNull = new OrPredicate(null); Assert.assertNull(orPredicateNull.getPredicates().get(0)); - QueryPredicate queryPredicate = new OrPredicateImpl(); - OrPredicateImpl orPredicate = new OrPredicateImpl(queryPredicate); + QueryPredicate queryPredicate = new OrPredicate(); + OrPredicate orPredicate = new OrPredicate(queryPredicate); Assert.assertEquals("Actual and expected values are not the same!", queryPredicate, orPredicate.getPredicates().get(0)); - QueryPredicate queryPredicate1 = new OrPredicateImpl(); - QueryPredicate queryPredicate2 = new OrPredicateImpl(); - QueryPredicate queryPredicate3 = new OrPredicateImpl(); - QueryPredicate[] array = {queryPredicate1, queryPredicate2, queryPredicate3}; - OrPredicateImpl orPredicateWithMultiplePredicates = new OrPredicateImpl(queryPredicate1, queryPredicate2, queryPredicate3); + QueryPredicate queryPredicate1 = new OrPredicate(); + QueryPredicate queryPredicate2 = new OrPredicate(); + QueryPredicate queryPredicate3 = new OrPredicate(); + QueryPredicate[] array = { queryPredicate1, queryPredicate2, queryPredicate3 }; + OrPredicate orPredicateWithMultiplePredicates = new OrPredicate(queryPredicate1, queryPredicate2, queryPredicate3); for (int i = 0; i < array.length; i++) { Assert.assertEquals("Actual and expected values are not the same!", array[i], orPredicateWithMultiplePredicates.getPredicates().get(i)); } @@ -50,15 +50,15 @@ public void orPredicateImplQueryPredicateId() { @Test public void orTest() { - OrPredicateImpl orPredicate = new OrPredicateImpl(); - QueryPredicate queryPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); + QueryPredicate queryPredicate = new OrPredicate(); orPredicate.or(queryPredicate); Assert.assertEquals("Actual and expected values are not the same!", queryPredicate, orPredicate.getPredicates().get(0)); } @Test public void orWithNullPredicateTest() { - OrPredicateImpl orPredicate = new OrPredicateImpl(); + OrPredicate orPredicate = new OrPredicate(); orPredicate.or(null); Assert.assertNull(orPredicate.getPredicates().get(0)); } diff --git a/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImplTest.java index e112a27e521..8b70a247bed 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImplTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreFactoryImplTest.java @@ -50,17 +50,6 @@ public void newCreatorTest() { } } - @Test - public void newQueryTest() { - EventStoreFactoryImpl eventStoreFactoryImpl = new EventStoreFactoryImpl(); - KapuaId[] scopeIdList = { null, new KapuaEid(BigInteger.ONE) }; - - for (KapuaId scopeId : scopeIdList) { - Assert.assertNotNull("Null not expected.", eventStoreFactoryImpl.newQuery(scopeId)); - Assert.assertThat("EventStoreQueryImpl object expected.", eventStoreFactoryImpl.newQuery(scopeId), IsInstanceOf.instanceOf(EventStoreQueryImpl.class)); - } - } - @Test public void cloneTest() { EventStoreFactoryImpl eventStoreFactoryImpl = new EventStoreFactoryImpl(); diff --git a/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImplTest.java b/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImplTest.java deleted file mode 100644 index 4f5eaefa8bc..00000000000 --- a/commons/src/test/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreQueryImplTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.commons.service.event.store.internal; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.id.KapuaIdImpl; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.math.BigInteger; - - -@Category(JUnitTests.class) -public class EventStoreQueryImplTest { - - @Test - public void eventStoreQueryImplTest1() { - EventStoreQueryImpl eventStoreQueryImpl = new EventStoreQueryImpl(); - Assert.assertNull("query.sortCriteria", eventStoreQueryImpl.getSortCriteria()); - Assert.assertNotNull("query.defaultSortCriteria", eventStoreQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void eventStoreQueryImplTest2() { - KapuaId scopeId = new KapuaIdImpl(BigInteger.ONE); - - EventStoreQueryImpl eventStoreQueryImpl1 = new EventStoreQueryImpl(null); - Assert.assertNull("query.sortCriteria", eventStoreQueryImpl1.getSortCriteria()); - Assert.assertNotNull("query.defaultSortCriteria", eventStoreQueryImpl1.getDefaultSortCriteria()); - Assert.assertNull("Null expected.", eventStoreQueryImpl1.getScopeId()); - - EventStoreQueryImpl eventStoreQueryImpl2 = new EventStoreQueryImpl(scopeId); - Assert.assertNull("query.sortCriteria", eventStoreQueryImpl2.getSortCriteria()); - Assert.assertNotNull("query.defaultSortCriteria", eventStoreQueryImpl2.getDefaultSortCriteria()); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, eventStoreQueryImpl2.getScopeId()); - } -} diff --git a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java index 36184b8f23e..9323f407d0d 100644 --- a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java +++ b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java @@ -12,12 +12,26 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.account.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; -import com.google.common.collect.Sets; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.concurrent.Callable; + +import javax.xml.namespace.QName; + import org.apache.commons.codec.binary.Base64; import org.apache.commons.imaging.ImageFormat; import org.apache.commons.imaging.ImageFormats; @@ -52,11 +66,11 @@ import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaListResult; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountFactory; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException; @@ -73,28 +87,17 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.namespace.QName; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; +import com.google.common.collect.Sets; /** * The server side implementation of the RPC service. @@ -207,12 +210,12 @@ public ListLoadResult getAccountInfo(String scopeIdString, Str try { final Account account = ACCOUNT_SERVICE.find(scopeId, accountId); -//TODO: #LAYER_VIOLATION - user lookup should not be done here + //TODO: #LAYER_VIOLATION - user lookup should not be done here UserListResult userListResult = KapuaSecurityUtils.doPrivileged(new Callable() { @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -366,7 +369,7 @@ public ListLoadResult findAll(String scopeIdString) List gwtAccountList = new ArrayList(); KapuaId scopeId = KapuaEid.parseCompactId(scopeIdString); try { - AccountQuery query = ACCOUNT_FACTORY.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); KapuaListResult list = ACCOUNT_SERVICE.query(query); for (Account account : list.getItems()) { @@ -389,7 +392,7 @@ public ListLoadResult findChildren(String parentAccountId, boolean i if (includeSelf) { gwtAccountList.add(find(parentAccountId)); } - AccountQuery query = ACCOUNT_FACTORY.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); KapuaListResult list = ACCOUNT_SERVICE.query(query); for (Account account : list.getItems()) { @@ -490,7 +493,7 @@ public List findServiceConfigurations(String scopeId) throws strValues.add(v.toString()); } } - gwtParam.setValues(strValues.toArray(new String[]{})); + gwtParam.setValues(strValues.toArray(new String[] {})); } } } @@ -666,7 +669,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtAccoun int totalLength = 0; List gwtAccounts = new ArrayList(); try { - AccountQuery query = GwtKapuaAccountModelConverter.convertAccountQuery(loadConfig, gwtAccountQuery); + KapuaQuery query = GwtKapuaAccountModelConverter.convertAccountQuery(loadConfig, gwtAccountQuery); KapuaListResult accounts = ACCOUNT_SERVICE.query(query); totalLength = accounts.getTotalCount().intValue(); @@ -676,7 +679,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtAccoun @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); diff --git a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java index 646263ad66b..666c0b4ef43 100644 --- a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java +++ b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java @@ -12,30 +12,31 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.account.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.account.shared.model.GwtAccountQuery; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator; import org.eclipse.kapua.service.account.AccountAttributes; import org.eclipse.kapua.service.account.AccountFactory; -import org.eclipse.kapua.service.account.AccountQuery; + +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; public class GwtKapuaAccountModelConverter { private GwtKapuaAccountModelConverter() { } - public static AccountQuery convertAccountQuery(PagingLoadConfig loadConfig, GwtAccountQuery gwtAccountQuery) { + public static KapuaQuery convertAccountQuery(PagingLoadConfig loadConfig, GwtAccountQuery gwtAccountQuery) { KapuaLocator locator = KapuaLocator.getInstance(); AccountFactory factory = locator.getFactory(AccountFactory.class); - AccountQuery query = factory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtAccountQuery.getScopeId())); + KapuaQuery query = new KapuaQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtAccountQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); diff --git a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java index d17ec5c0d06..cf26b3cd876 100644 --- a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java +++ b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java @@ -12,9 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authentication.server; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.Callable; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.eclipse.kapua.KapuaException; @@ -32,6 +35,7 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authentication.AuthenticationService; import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; @@ -39,7 +43,6 @@ import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.shiro.utils.AuthenticationUtils; import org.eclipse.kapua.service.authentication.user.PasswordChangeRequest; @@ -49,13 +52,12 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtCredentialServiceImpl extends KapuaRemoteServiceServlet implements GwtCredentialService { @@ -87,7 +89,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, final try { // Convert from GWT entity - CredentialQuery credentialQuery = GwtKapuaAuthenticationModelConverter.convertCredentialQuery(loadConfig, gwtCredentialQuery); + KapuaQuery credentialQuery = GwtKapuaAuthenticationModelConverter.convertCredentialQuery(loadConfig, gwtCredentialQuery); // query CredentialListResult credentials = CREDENTIAL_SERVICE.query(credentialQuery); @@ -101,7 +103,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, final @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtCredentialQuery.getScopeId()))); + return USER_SERVICE.query(new UserQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtCredentialQuery.getScopeId()))); } }); @@ -223,7 +225,6 @@ public User call() throws Exception { } } - @Override public void resetPassword(GwtXSRFToken gwtXsrfToken, String stringScopeId, String gwtCredentialId, final String newPassword) throws GwtKapuaException { checkXSRFToken(gwtXsrfToken); @@ -240,7 +241,6 @@ public void resetPassword(GwtXSRFToken gwtXsrfToken, String stringScopeId, Strin } } - @Override public void unlock(GwtXSRFToken xsrfToken, String stringScopeId, String gwtCredentialId) throws GwtKapuaException { diff --git a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/shared/util/GwtKapuaAuthenticationModelConverter.java b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/shared/util/GwtKapuaAuthenticationModelConverter.java index d895a0d4cd9..c8c8372c718 100644 --- a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/shared/util/GwtKapuaAuthenticationModelConverter.java +++ b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/shared/util/GwtKapuaAuthenticationModelConverter.java @@ -12,9 +12,6 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authentication.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BaseModel; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; import org.eclipse.kapua.app.console.module.authentication.shared.model.GwtCredential; @@ -26,17 +23,21 @@ import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialAttributes; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionCreator; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionFactory; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BaseModel; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; + /** * Utility class for convertKapuaId {@link BaseModel}s to {@link KapuaEntity}ies and other Kapua models */ @@ -51,16 +52,18 @@ private GwtKapuaAuthenticationModelConverter() { } /** - * Converts a {@link GwtCredentialQuery} into a {@link CredentialQuery} object for backend usage + * Converts a {@link GwtCredentialQuery} into a {@link KapuaQuery} object for backend usage * - * @param loadConfig the load configuration - * @param gwtCredentialQuery the {@link GwtCredentialQuery} to convertKapuaId - * @return the converted {@link CredentialQuery} + * @param loadConfig + * the load configuration + * @param gwtCredentialQuery + * the {@link GwtCredentialQuery} to convertKapuaId + * @return the converted {@link KapuaQuery} */ - public static CredentialQuery convertCredentialQuery(PagingLoadConfig loadConfig, GwtCredentialQuery gwtCredentialQuery) { + public static KapuaQuery convertCredentialQuery(PagingLoadConfig loadConfig, GwtCredentialQuery gwtCredentialQuery) { // Convert query - CredentialQuery query = CREDENTIAL_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtCredentialQuery.getScopeId())); + KapuaQuery query = new KapuaQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtCredentialQuery.getScopeId())); AndPredicate andPredicate = query.andPredicate(); if (gwtCredentialQuery.getUserId() != null && !gwtCredentialQuery.getUserId().trim().isEmpty()) { @@ -93,7 +96,8 @@ public static CredentialQuery convertCredentialQuery(PagingLoadConfig loadConfig /** * Converts a {@link GwtCredentialCreator} into a {@link CredentialCreator} object for backend usage * - * @param gwtCredentialCreator the {@link GwtCredentialCreator} to convertKapuaId + * @param gwtCredentialCreator + * the {@link GwtCredentialCreator} to convertKapuaId * @return the converted {@link CredentialCreator} */ public static CredentialCreator convertCredentialCreator(GwtCredentialCreator gwtCredentialCreator) { @@ -114,7 +118,8 @@ public static CredentialCreator convertCredentialCreator(GwtCredentialCreator gw /** * Converts a {@link GwtCredential} into a {@link Credential} object for backend usage * - * @param gwtCredential the {@link GwtCredential} to convertKapuaId + * @param gwtCredential + * the {@link GwtCredential} to convertKapuaId * @return the converted {@link Credential} */ public static Credential convertCredential(GwtCredential gwtCredential) { diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessPermissionServiceImpl.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessPermissionServiceImpl.java index 37221902f34..b4d7e12d3ab 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessPermissionServiceImpl.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessPermissionServiceImpl.java @@ -12,10 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.server; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -32,6 +32,7 @@ import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountService; @@ -42,16 +43,16 @@ import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; import org.eclipse.kapua.service.authorization.group.Group; import org.eclipse.kapua.service.authorization.group.GroupService; import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtAccessPermissionServiceImpl extends KapuaRemoteServiceServlet implements GwtAccessPermissionService { @@ -124,7 +125,7 @@ public PagingLoadResult findByUserId(PagingLoadConfig loadC AccessInfo accessInfo = ACCESS_INFO_SERVICE.findByUserId(scopeId, userId); if (accessInfo != null) { - AccessPermissionQuery query = ACCESS_PERMISSION_FACTORY.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfo.getId())); query.setLimit(loadConfig.getLimit()); query.setOffset(loadConfig.getOffset()); diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessRoleServiceImpl.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessRoleServiceImpl.java index 54cf218c494..e71fa7d53f8 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessRoleServiceImpl.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtAccessRoleServiceImpl.java @@ -12,10 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.server; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -31,6 +31,7 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoService; @@ -40,16 +41,16 @@ import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.role.Role; import org.eclipse.kapua.service.authorization.role.RoleService; import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtAccessRoleServiceImpl extends KapuaRemoteServiceServlet implements GwtAccessRoleService { @@ -120,7 +121,7 @@ public PagingLoadResult findByUserId(PagingLoadConfig loadConfig, AccessInfo accessInfo = accessInfoService.findByUserId(scopeId, userId); if (accessInfo != null) { - AccessRoleQuery query = accessRoleFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfo.getId())); query.setLimit(loadConfig.getLimit()); query.setOffset(loadConfig.getOffset()); diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtDomainRegistryServiceImpl.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtDomainRegistryServiceImpl.java index 3e4e58861fa..a786f466122 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtDomainRegistryServiceImpl.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtDomainRegistryServiceImpl.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.server; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -21,16 +25,13 @@ import org.eclipse.kapua.app.console.module.authorization.shared.util.KapuaGwtAuthorizationModelConverter; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.domain.Actions; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.eclipse.kapua.service.authorization.domain.DomainRegistryService; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class GwtDomainRegistryServiceImpl extends KapuaRemoteServiceServlet implements GwtDomainRegistryService { private static final long serialVersionUID = -699492835893299489L; @@ -39,12 +40,11 @@ public class GwtDomainRegistryServiceImpl extends KapuaRemoteServiceServlet impl private final DomainRegistryService domainRegistryService = locator.getService(DomainRegistryService.class); private final DomainFactory domainFactory = locator.getFactory(DomainFactory.class); - @Override public List findAll() throws GwtKapuaException { List gwtDomainList = new ArrayList(); try { - DomainQuery query = domainFactory.newQuery(null); + KapuaQuery query = new KapuaQuery((KapuaId) null); DomainListResult list = domainRegistryService.query(query); for (Domain domain : list.getItems()) { diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtGroupServiceImpl.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtGroupServiceImpl.java index 0268f08bc7e..636179e9782 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtGroupServiceImpl.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtGroupServiceImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -42,13 +43,14 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtGroupServiceImpl extends KapuaRemoteServiceServlet implements GwtGroupService { @@ -123,7 +125,7 @@ public GwtGroup find(String scopeShortId, String groupShortId) throws GwtKapuaEx @Override public PagingLoadResult query(PagingLoadConfig loadConfig, - final GwtGroupQuery gwtGroupQuery) throws GwtKapuaException { + final GwtGroupQuery gwtGroupQuery) throws GwtKapuaException { int totalLength = 0; List gwtGroupList = new ArrayList(); try { @@ -136,7 +138,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -174,7 +176,7 @@ public void delete(String scopeIdString, String groupIdString) throws GwtKapuaEx @Override public ListLoadResult getGroupDescription(String scopeShortId, - String groupShortId) throws GwtKapuaException { + String groupShortId) throws GwtKapuaException { List gwtGroupDescription = new ArrayList(); try { final KapuaId scopeId = KapuaEid.parseCompactId(scopeShortId); @@ -187,7 +189,7 @@ public ListLoadResult getGroupDescription(String scopeShortId, @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -216,7 +218,7 @@ public UserListResult call() throws Exception { @Override public List findAll(String scopeId) throws GwtKapuaException { List groupList = new ArrayList(); - GroupQuery query = GROUP_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(scopeId)); + GroupQuery query = new GroupQuery(GwtKapuaCommonsModelConverter.convertKapuaId(scopeId)); try { GroupListResult result = GROUP_SERVICE.query(query); for (Group group : result.getItems()) { diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtRoleServiceImpl.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtRoleServiceImpl.java index b9b117893fe..280df1b2100 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtRoleServiceImpl.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/server/GwtRoleServiceImpl.java @@ -12,12 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.server; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -40,6 +40,7 @@ import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountService; @@ -54,20 +55,21 @@ import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionService; import org.eclipse.kapua.service.authorization.role.RoleQuery; import org.eclipse.kapua.service.authorization.role.RoleService; import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtRoleServiceImpl extends KapuaRemoteServiceServlet implements GwtRoleService { @@ -175,7 +177,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, final GwtRol @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -215,7 +217,7 @@ public ListLoadResult getRoleDescription(String scopeShortId, @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -252,7 +254,7 @@ public PagingLoadResult getRolePermissions(PagingLoadConfig l KapuaId roleId = GwtKapuaCommonsModelConverter.convertKapuaId(roleShortId); // Get permissions assigned to the Role - RolePermissionQuery query = ROLE_PERMISSION_FACTORY.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(RolePermissionAttributes.ROLE_ID, roleId)); query.setLimit(loadConfig.getLimit()); query.setOffset(loadConfig.getOffset()); @@ -372,7 +374,7 @@ public List findAll(String scopeIdString) throws GwtKapuaException { KapuaId scopeId = KapuaEid.parseCompactId(scopeIdString); List gwtRoleList = new ArrayList(); try { - RoleQuery query = ROLE_FACTORY.newQuery(scopeId); + RoleQuery query = new RoleQuery(scopeId); RoleListResult list = ROLE_SERVICE.query(query); for (Role role : list.getItems()) { diff --git a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/shared/util/GwtKapuaAuthorizationModelConverter.java b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/shared/util/GwtKapuaAuthorizationModelConverter.java index d692c1e08a5..8cef2834377 100644 --- a/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/shared/util/GwtKapuaAuthorizationModelConverter.java +++ b/console/module/authorization/src/main/java/org/eclipse/kapua/app/console/module/authorization/shared/util/GwtKapuaAuthorizationModelConverter.java @@ -12,9 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.authorization.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BaseModel; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import java.util.HashSet; +import java.util.Set; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.KapuaIllegalArgumentException; @@ -22,7 +22,6 @@ import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtAccessInfoCreator; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtAccessPermissionCreator; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtAccessRoleCreator; -import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtAccessRoleQuery; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtDomain; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtGroupQuery; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtPermission; @@ -31,13 +30,13 @@ import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtRoleCreator; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtRolePermission; import org.eclipse.kapua.app.console.module.authorization.shared.model.GwtRoleQuery; -import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.domain.Domain; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator; @@ -45,13 +44,10 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; -import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.eclipse.kapua.service.authorization.domain.DomainRegistryService; import org.eclipse.kapua.service.authorization.group.GroupAttributes; import org.eclipse.kapua.service.authorization.group.GroupFactory; @@ -66,8 +62,9 @@ import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RoleQuery; -import java.util.HashSet; -import java.util.Set; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BaseModel; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; /** * Utility class for convertKapuaId {@link BaseModel}s to {@link KapuaEntity}ies and other Kapua models @@ -83,11 +80,11 @@ private GwtKapuaAuthorizationModelConverter() { } public static GroupQuery convertGroupQuery(PagingLoadConfig loadConfig, - GwtGroupQuery gwtGroupQuery) { + GwtGroupQuery gwtGroupQuery) { KapuaLocator locator = KapuaLocator.getInstance(); GroupFactory groupFactory = locator.getFactory(GroupFactory.class); - GroupQuery query = groupFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtGroupQuery.getScopeId())); + GroupQuery query = new GroupQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtGroupQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); if (gwtGroupQuery.getName() != null && !gwtGroupQuery.getName().isEmpty()) { @@ -116,8 +113,10 @@ public static GroupQuery convertGroupQuery(PagingLoadConfig loadConfig, /** * Converts a {@link GwtRoleQuery} into a {@link Role} object for backend usage * - * @param loadConfig the load configuration - * @param gwtRoleQuery the {@link GwtRoleQuery} to convertKapuaId + * @param loadConfig + * the load configuration + * @param gwtRoleQuery + * the {@link GwtRoleQuery} to convertKapuaId * @return the converted {@link RoleQuery} */ public static RoleQuery convertRoleQuery(PagingLoadConfig loadConfig, GwtRoleQuery gwtRoleQuery) { @@ -127,7 +126,7 @@ public static RoleQuery convertRoleQuery(PagingLoadConfig loadConfig, GwtRoleQue RoleFactory roleFactory = locator.getFactory(RoleFactory.class); // Convert query - RoleQuery query = roleFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtRoleQuery.getScopeId())); + RoleQuery query = new RoleQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtRoleQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); @@ -154,25 +153,11 @@ public static RoleQuery convertRoleQuery(PagingLoadConfig loadConfig, GwtRoleQue return query; } - public static AccessRoleQuery convertAccessRoleQuery(PagingLoadConfig pagingLoadConfig, - GwtAccessRoleQuery gwtRoleQuery) { - - KapuaLocator locator = KapuaLocator.getInstance(); - AccessRoleFactory accessRoleFactory = locator.getFactory(AccessRoleFactory.class); - - AccessRoleQuery query = accessRoleFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtRoleQuery.getScopeId())); - query.setPredicate(query.attributePredicate(AccessRoleAttributes.ROLE_ID, KapuaEid.parseCompactId(gwtRoleQuery.getRoleId()))); - query.setOffset(pagingLoadConfig.getOffset()); - query.setLimit(pagingLoadConfig.getLimit()); - query.setAskTotalCount(gwtRoleQuery.getAskTotalCount()); - return query; - - } - /** * Converts a {@link GwtRole} into a {@link Role} object for backend usage * - * @param gwtRole the {@link GwtRole} to convertKapuaId + * @param gwtRole + * the {@link GwtRole} to convertKapuaId * @return the converted {@link Role} */ public static Role convertRole(GwtRole gwtRole) throws KapuaException { @@ -218,7 +203,8 @@ public static Role convertRole(GwtRole gwtRole) throws KapuaException { /** * Converts a {@link GwtRoleCreator} into a {@link RoleCreator} object for backend usage * - * @param gwtRoleCreator the {@link GwtRoleCreator} to convertKapuaId + * @param gwtRoleCreator + * the {@link GwtRoleCreator} to convertKapuaId * @return the converted {@link RoleCreator} */ public static RoleCreator convertRoleCreator(GwtRoleCreator gwtRoleCreator) throws KapuaException { @@ -251,7 +237,8 @@ public static RoleCreator convertRoleCreator(GwtRoleCreator gwtRoleCreator) thro /** * Converts a {@link GwtAccessRoleCreator} into a {@link AccessRoleCreator} object for backend usage * - * @param gwtAccessRoleCreator the {@link GwtAccessRoleCreator} to convertKapuaId + * @param gwtAccessRoleCreator + * the {@link GwtAccessRoleCreator} to convertKapuaId * @return the converted {@link AccessRoleCreator} * @since 1.0.0 */ @@ -277,7 +264,8 @@ public static AccessRoleCreator convertAccessRoleCreator(GwtAccessRoleCreator gw /** * Converts a {@link GwtAccessPermissionCreator} into a {@link AccessPermissionCreator} object for backend usage * - * @param gwtAccessPermissionCreator the {@link GwtAccessPermissionCreator} to convertKapuaId + * @param gwtAccessPermissionCreator + * the {@link GwtAccessPermissionCreator} to convertKapuaId * @return the converted {@link AccessPermissionCreator} * @since 1.0.0 */ @@ -318,7 +306,8 @@ public static AccessInfoCreator convertAccessInfoCreator(GwtAccessInfoCreator gw /** * Converts a {@link GwtPermission} into a {@link Permission} object for backend usage. * - * @param gwtPermission The {@link GwtPermission} to convertKapuaId. + * @param gwtPermission + * The {@link GwtPermission} to convertKapuaId. * @return The converted {@link Permission}. * @since 1.0.0 */ @@ -337,7 +326,8 @@ public static Permission convertPermission(GwtPermission gwtPermission) throws K /** * Converts a {@link GwtAction} into the related {@link Actions} * - * @param gwtAction the {@link GwtAction} to convertKapuaId + * @param gwtAction + * the {@link GwtAction} to convertKapuaId * @return the converted {@link Actions} * @since 1.0.0 */ @@ -346,24 +336,24 @@ public static Actions convertAction(GwtAction gwtAction) { Actions action = null; if (gwtAction != null) { switch (gwtAction) { - case connect: - action = Actions.connect; - break; - case delete: - action = Actions.delete; - break; - case execute: - action = Actions.execute; - break; - case read: - action = Actions.read; - break; - case write: - action = Actions.write; - break; - case ALL: - action = null; - break; + case connect: + action = Actions.connect; + break; + case delete: + action = Actions.delete; + break; + case execute: + action = Actions.execute; + break; + case read: + action = Actions.read; + break; + case write: + action = Actions.write; + break; + case ALL: + action = null; + break; } } return action; @@ -372,7 +362,8 @@ public static Actions convertAction(GwtAction gwtAction) { /** * Converts a {@link GwtDomain} into the related equivalent domain string * - * @param gwtDomain the {@link GwtDomain} to convertKapuaId + * @param gwtDomain + * the {@link GwtDomain} to convertKapuaId * @return the converted domain {@link String} * @since 1.0.0 */ @@ -384,8 +375,7 @@ public static Domain convertDomain(GwtDomain gwtDomain) throws KapuaException { return null; } - DomainQuery query = DOMAIN_FACTORY.newQuery(null); - DomainListResult list = DOMAIN_REGISTRY_SERVICE.query(query); + DomainListResult list = DOMAIN_REGISTRY_SERVICE.query(new KapuaQuery((KapuaId) null)); for (org.eclipse.kapua.service.authorization.domain.Domain domain : list.getItems()) { if (gwtDomainName.equals(domain.getName())) { diff --git a/console/module/certificate/src/main/java/org/eclipse/kapua/app/console/module/certificate/server/GwtCertificateInfoServiceImpl.java b/console/module/certificate/src/main/java/org/eclipse/kapua/app/console/module/certificate/server/GwtCertificateInfoServiceImpl.java index 5939b8a5214..8ac5802fc44 100644 --- a/console/module/certificate/src/main/java/org/eclipse/kapua/app/console/module/certificate/server/GwtCertificateInfoServiceImpl.java +++ b/console/module/certificate/src/main/java/org/eclipse/kapua/app/console/module/certificate/server/GwtCertificateInfoServiceImpl.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.certificate.server; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -29,9 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; - public class GwtCertificateInfoServiceImpl extends KapuaRemoteServiceServlet implements GwtCertificateInfoService { private static final Logger LOG = LoggerFactory.getLogger(GwtCertificateInfoServiceImpl.class); @@ -48,7 +48,7 @@ public List findAll(String scopeIdString) throws GwtKapuaExc List gwtCertificateInfos = new ArrayList(); - CertificateInfoQuery query = CERTIFICATE_INFO_FACTORY.newQuery(scopeId); + CertificateInfoQuery query = new CertificateInfoQuery(scopeId); query.setIncludeInherited(true); CertificateInfoListResult certificateInfos = CERTIFICATE_INFO_SERVICE.query(query); diff --git a/console/module/data/src/main/java/org/eclipse/kapua/app/console/module/data/server/GwtDataServiceImpl.java b/console/module/data/src/main/java/org/eclipse/kapua/app/console/module/data/server/GwtDataServiceImpl.java index 23b430d4a45..7830c55d437 100644 --- a/console/module/data/src/main/java/org/eclipse/kapua/app/console/module/data/server/GwtDataServiceImpl.java +++ b/console/module/data/src/main/java/org/eclipse/kapua/app/console/module/data/server/GwtDataServiceImpl.java @@ -12,15 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.data.server; -import com.extjs.gxt.ui.client.Style; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.LoadConfig; -import com.extjs.gxt.ui.client.data.ModelData; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; -import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaErrorCode; @@ -83,13 +82,15 @@ import org.eclipse.kapua.service.storable.model.query.predicate.StorablePredicate; import org.eclipse.kapua.service.storable.model.query.predicate.TermPredicate; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.extjs.gxt.ui.client.Style; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.LoadConfig; +import com.extjs.gxt.ui.client.data.ModelData; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; +import com.google.common.base.Strings; public class GwtDataServiceImpl extends KapuaRemoteServiceServlet implements GwtDataService { @@ -307,7 +308,7 @@ public PagingLoadResult findDevices(PagingLoadConfig config, for (ClientInfo client : result.getItems()) { clientIds.add(client.getClientId()); } - DeviceQuery deviceQuery = deviceFactory.newQuery(convertedScopeId); + DeviceQuery deviceQuery = new DeviceQuery(convertedScopeId); DeviceListResult deviceListResult = deviceRegistryService.query(deviceQuery); Map clientIdsMap = buildClientIdsMap(clientIds, deviceListResult); @@ -423,7 +424,8 @@ public PagingLoadResult findMessagesByDevice(PagingLoadConfig loadCo } @Override - public PagingLoadResult findMessagesByAssets(PagingLoadConfig loadConfig, String scopeId, GwtDatastoreDevice device, GwtDatastoreAsset asset, List headers, Date startDate, Date endDate) + public PagingLoadResult findMessagesByAssets(PagingLoadConfig loadConfig, String scopeId, GwtDatastoreDevice device, GwtDatastoreAsset asset, List headers, Date startDate, + Date endDate) throws GwtKapuaException { ChannelMatchPredicate assetPredicate = DATASTORE_PREDICATE_FACTORY.newChannelMatchPredicate(asset.getTopick()); TermPredicate devicePredicate = DATASTORE_PREDICATE_FACTORY.newTermPredicate(MessageField.CLIENT_ID, device.getDevice()); @@ -474,7 +476,8 @@ private PagingLoadResult findMessages(PagingLoadConfig loadConfig, S OrPredicate metricsPredicate = DATASTORE_PREDICATE_FACTORY.newOrPredicate(); for (GwtHeader header : headers) { try { - metricsPredicate.getPredicates().add(DATASTORE_PREDICATE_FACTORY.newMetricExistsPredicate(header.getName(), (Class) ObjectTypeConverter.fromString(header.getType().toLowerCase()))); + metricsPredicate.getPredicates() + .add(DATASTORE_PREDICATE_FACTORY.newMetricExistsPredicate(header.getName(), (Class) ObjectTypeConverter.fromString(header.getType().toLowerCase()))); } catch (ClassNotFoundException e) { throw new GwtKapuaException(GwtKapuaErrorCode.INTERNAL_ERROR, e); } diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceConnectionServiceImpl.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceConnectionServiceImpl.java index cd228fb84cf..1409f3ca7f9 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceConnectionServiceImpl.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceConnectionServiceImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.device.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -46,16 +47,17 @@ import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; /** * The server side implementation of the RPC service. */ public class GwtDeviceConnectionServiceImpl extends KapuaRemoteServiceServlet implements GwtDeviceConnectionService { + private static final long serialVersionUID = 3314502846487119577L; private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); @@ -83,9 +85,9 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, if (!deviceConnections.isEmpty()) { Map users = new HashMap(); - final UserQuery userQuery = USER_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtDeviceConnectionQuery.getScopeId())); + final UserQuery userQuery = new UserQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtDeviceConnectionQuery.getScopeId())); -//TODO: #LAYER_VIOLATION - user lookup logic should not be done here (fetching all users is incredibly inefficient anyway) + //TODO: #LAYER_VIOLATION - user lookup logic should not be done here (fetching all users is incredibly inefficient anyway) UserListResult userList = KapuaSecurityUtils.doPrivileged(new Callable() { @Override @@ -141,7 +143,7 @@ public ListLoadResult getConnectionInfo(String scopeIdString, List deviceConnectionPropertiesPairs = new ArrayList(); try { final DeviceConnection deviceConnection = DEVICE_CONNECTION_SERVICE.find(scopeId, deviceConnectionId); -//TODO: #LAYER_VIOLATION - user lookup logic should not be done here + //TODO: #LAYER_VIOLATION - user lookup logic should not be done here User connectionUser = KapuaSecurityUtils.doPrivileged(new Callable() { @Override @@ -190,7 +192,8 @@ public User call() throws Exception { gwtConnectionUserCouplingMode = GwtConnectionUserCouplingMode.valueOf(deviceConnection.getUserCouplingMode().name()); } deviceConnectionPropertiesPairs - .add(new GwtGroupedNVPair(CONNECTION_USER_COUPLING_MODE_INFO, "connectionUserCouplingMode", gwtConnectionUserCouplingMode != null ? gwtConnectionUserCouplingMode.getLabel() : null)); + .add(new GwtGroupedNVPair(CONNECTION_USER_COUPLING_MODE_INFO, "connectionUserCouplingMode", + gwtConnectionUserCouplingMode != null ? gwtConnectionUserCouplingMode.getLabel() : null)); if (AUTHORIZATION_SERVICE.isPermitted(PERMISSION_FACTORY.newPermission(Domains.USER, Actions.read, scopeId))) { deviceConnectionPropertiesPairs.add(new GwtGroupedNVPair(CONNECTION_USER_COUPLING_MODE_INFO, "connectionReservedUser", reservedUser != null ? reservedUser.getName() : null)); deviceConnectionPropertiesPairs.add(new GwtGroupedNVPair(CONNECTION_USER_COUPLING_MODE_INFO, "allowUserChange", deviceConnection.getAllowUserChange())); diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementOperationServiceImpl.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementOperationServiceImpl.java index 19615830b73..98cef3390a1 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementOperationServiceImpl.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementOperationServiceImpl.java @@ -12,10 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.device.server; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; -import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -37,8 +36,10 @@ import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationQuery; import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationService; -import java.util.ArrayList; -import java.util.List; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; +import com.google.common.base.Strings; /** * The server side implementation of the RPC service. @@ -69,7 +70,7 @@ public PagingLoadResult query(PagingLoadConfig loa if (dmo.getEndedOn() == null) { //TODO: #LAYER_VIOLATION - entity lookup should be done elsewhere - ManagementOperationNotificationQuery notificationQuery = MANAGEMENT_OPERATION_NOTIFICATION_FACTORY.newQuery(dmo.getScopeId()); + ManagementOperationNotificationQuery notificationQuery = new ManagementOperationNotificationQuery(dmo.getScopeId()); notificationQuery.setPredicate(notificationQuery.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, dmo.getId())); notificationQuery.setSortCriteria(notificationQuery.fieldSortCriteria(ManagementOperationNotificationAttributes.SENT_ON, SortOrder.ASCENDING)); diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceServiceImpl.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceServiceImpl.java index 7644fc0c4fe..926bb8eeec1 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceServiceImpl.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceServiceImpl.java @@ -18,12 +18,6 @@ import java.util.Set; import java.util.concurrent.Callable; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadConfig; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -78,6 +72,13 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserService; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadConfig; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; + /** * The server side implementation of the Device RPC service. */ @@ -265,7 +266,7 @@ public User call() throws Exception { // GPS infos retrieval if (AUTHORIZATION_SERVICE.isPermitted(PERMISSION_FACTORY.newPermission(Domains.DEVICE_EVENT, Actions.read, device.getScopeId()))) { DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class); - DeviceEventQuery query = deviceEventFactory.newQuery(device.getScopeId()); + DeviceEventQuery query = new DeviceEventQuery(device.getScopeId()); query.setLimit(1); query.setSortCriteria(query.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.DESCENDING)); @@ -534,9 +535,9 @@ public void deleteDeviceTag(GwtXSRFToken xsrfToken, String scopeIdString, String @Override public PagingLoadResult findDeviceEvents(PagingLoadConfig loadConfig, - GwtDevice gwtDevice, - Date startDate, - Date endDate) + GwtDevice gwtDevice, + Date startDate, + Date endDate) throws GwtKapuaException { ArrayList gwtDeviceEvents = new ArrayList(); BasePagingLoadResult gwtResults = null; @@ -549,7 +550,7 @@ public PagingLoadResult findDeviceEvents(PagingLoadConfig loadCo // prepare the query BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig; - DeviceEventQuery query = deviceEventFactory.newQuery(KapuaEid.parseCompactId(gwtDevice.getScopeId())); + DeviceEventQuery query = new DeviceEventQuery(KapuaEid.parseCompactId(gwtDevice.getScopeId())); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(DeviceEventAttributes.DEVICE_ID, KapuaEid.parseCompactId(gwtDevice.getId())), diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceEventExporterServlet.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceEventExporterServlet.java index 88d80d63547..4fff7386281 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceEventExporterServlet.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceEventExporterServlet.java @@ -12,6 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.device.servlet; +import java.io.IOException; +import java.util.Date; +import java.util.concurrent.Callable; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaIllegalAccessException; import org.eclipse.kapua.KapuaUnauthenticatedException; @@ -34,14 +43,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Date; -import java.util.concurrent.Callable; - public class DeviceEventExporterServlet extends HttpServlet { private static final long serialVersionUID = -2533869595709953567L; @@ -94,6 +95,7 @@ private void internalDoGet(HttpServletRequest request, HttpServletResponse respo final KapuaIdFactory kif = locator.getFactory(KapuaIdFactory.class); Device device = KapuaSecurityUtils.doPrivileged(new Callable() { + @Override public Device call() throws Exception { return deviceRegistryService.find(KapuaEid.parseCompactId(scopeId), KapuaEid.parseCompactId(deviceId)); @@ -113,7 +115,7 @@ public Account call() throws Exception { int offset = 0; // paginate through the matching message - DeviceEventQuery query = def.newQuery(KapuaEid.parseCompactId(scopeId)); + DeviceEventQuery query = new DeviceEventQuery(KapuaEid.parseCompactId(scopeId)); query.setLimit(250); // Inserting filter parameter if specified diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceExporterServlet.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceExporterServlet.java index bad21ee8e21..f5dd0e4b02e 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceExporterServlet.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/servlet/DeviceExporterServlet.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.device.servlet; +import java.io.IOException; +import java.util.concurrent.Callable; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaIllegalAccessException; import org.eclipse.kapua.KapuaUnauthenticatedException; @@ -36,13 +44,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.Callable; - public class DeviceExporterServlet extends HttpServlet { private static final long serialVersionUID = -2533869595709953567L; @@ -96,7 +97,7 @@ public Account call() throws Exception { int offset = 0; // paginate through the matching message - DeviceQuery query = drf.newQuery(KapuaEid.parseCompactId(scopeIdString)); + DeviceQuery query = new DeviceQuery(KapuaEid.parseCompactId(scopeIdString)); query.setLimit(250); // Inserting filter parameter if specified @@ -154,7 +155,7 @@ public Account call() throws Exception { String tagId = request.getParameter("tag"); if (tagId != null && !tagId.isEmpty()) { - andPred = andPred.and(query.attributePredicate(DeviceAttributes.TAG_IDS, new KapuaId[]{KapuaEid.parseCompactId(tagId)})); + andPred = andPred.and(query.attributePredicate(DeviceAttributes.TAG_IDS, new KapuaId[] { KapuaEid.parseCompactId(tagId) })); } String sortAttribute = request.getParameter("sortAttribute"); diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/shared/util/GwtKapuaDeviceModelConverter.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/shared/util/GwtKapuaDeviceModelConverter.java index b9c310f807d..e009281aa83 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/shared/util/GwtKapuaDeviceModelConverter.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/shared/util/GwtKapuaDeviceModelConverter.java @@ -69,7 +69,7 @@ private GwtKapuaDeviceModelConverter() { } public static DeviceConnectionQuery convertConnectionQuery(PagingLoadConfig loadConfig, GwtDeviceConnectionQuery gwtDeviceConnectionQuery) { - DeviceConnectionQuery query = DEVICE_CONNECTION_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtDeviceConnectionQuery.getScopeId())); + DeviceConnectionQuery query = new DeviceConnectionQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtDeviceConnectionQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); if (gwtDeviceConnectionQuery.getClientId() != null && !gwtDeviceConnectionQuery.getClientId().trim().isEmpty()) { @@ -163,7 +163,7 @@ public static DeviceAssetChannelMode convertDeviceAssetChannel(GwtDeviceAssetCha } public static DeviceQuery convertDeviceQuery(PagingLoadConfig loadConfig, GwtDeviceQuery gwtDeviceQuery) { - DeviceQuery query = DEVICE_FACTORY.newQuery(KapuaEid.parseCompactId(gwtDeviceQuery.getScopeId())); + DeviceQuery query = new DeviceQuery(KapuaEid.parseCompactId(gwtDeviceQuery.getScopeId())); if (loadConfig != null) { query.setLimit(loadConfig.getLimit()); @@ -243,7 +243,7 @@ public static DeviceQuery convertDeviceQuery(PagingLoadConfig loadConfig, GwtDev public static DeviceManagementOperationQuery convertDeviceManagementOperationQuery(PagingLoadConfig loadConfig, GwtDeviceManagementOperationQuery gwtQuery) { - DeviceManagementOperationQuery query = DEVICE_MANAGEMENT_OPERATION_FACTORY.newQuery(KapuaEid.parseCompactId(gwtQuery.getScopeId())); + DeviceManagementOperationQuery query = new DeviceManagementOperationQuery(KapuaEid.parseCompactId(gwtQuery.getScopeId())); String deviceId = gwtQuery.getDeviceId(); AndPredicate andPredicate = query.andPredicate(); diff --git a/console/module/endpoint/src/main/java/org/eclipse/kapua/app/console/module/endpoint/server/GwtEndpointServiceImpl.java b/console/module/endpoint/src/main/java/org/eclipse/kapua/app/console/module/endpoint/server/GwtEndpointServiceImpl.java index 23e8fd15552..6098643c90d 100644 --- a/console/module/endpoint/src/main/java/org/eclipse/kapua/app/console/module/endpoint/server/GwtEndpointServiceImpl.java +++ b/console/module/endpoint/src/main/java/org/eclipse/kapua/app/console/module/endpoint/server/GwtEndpointServiceImpl.java @@ -12,11 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.endpoint.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -45,15 +48,14 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtEndpointServiceImpl extends KapuaRemoteServiceServlet implements GwtEndpointService { @@ -153,7 +155,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, final Gw @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -205,7 +207,7 @@ public ListLoadResult getEndpointDescription(String scopeShort @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobEngineServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobEngineServiceImpl.java index 7788a431dc5..5d7da504de0 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobEngineServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobEngineServiceImpl.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; +import java.util.ArrayList; +import java.util.Collections; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaErrorCode; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; @@ -33,9 +36,6 @@ import org.eclipse.kapua.service.job.execution.JobExecutionQuery; import org.eclipse.kapua.service.job.execution.JobExecutionService; -import java.util.ArrayList; -import java.util.Collections; - public class GwtJobEngineServiceImpl extends KapuaRemoteServiceServlet implements GwtJobEngineService { private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); @@ -88,7 +88,7 @@ public void stopExecution(String gwtScopeId, String gwtJobId, String gwtJobExecu try { if (jobExecutionId == null) { //TODO: #LAYER_VIOLATION - job execution lookup should not be done here (horribly inefficient) - JobExecutionQuery query = JOB_EXECUTION_FACTORY.newQuery(scopeId); + JobExecutionQuery query = new JobExecutionQuery(scopeId); query.setPredicate( query.andPredicate( diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobServiceImpl.java index 2824b9d7f1b..94d523386ea 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobServiceImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -42,13 +43,14 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; +import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtJobServiceImpl extends KapuaRemoteServiceServlet implements GwtJobService { @@ -83,7 +85,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtJobQuery g @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -207,7 +209,7 @@ public void deleteForced(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJo @Override public ListLoadResult findJobDescription(String gwtScopeId, - String gwtJobId) throws GwtKapuaException { + String gwtJobId) throws GwtKapuaException { List gwtJobDescription = new ArrayList(); try { KapuaId scopeId = KapuaEid.parseCompactId(gwtScopeId); @@ -219,7 +221,7 @@ public ListLoadResult findJobDescription(String gwtScopeId, @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepDefinitionServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepDefinitionServiceImpl.java index 6ed918244e2..d6ff7662c18 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepDefinitionServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepDefinitionServiceImpl.java @@ -12,9 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -31,10 +31,12 @@ import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionListResult; +import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService; -import java.util.ArrayList; -import java.util.List; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.google.common.base.Strings; public class GwtJobStepDefinitionServiceImpl extends KapuaRemoteServiceServlet implements GwtJobStepDefinitionService { @@ -54,7 +56,7 @@ public ListLoadResult findAll(String scopeIdString) throws try { KapuaId scopeId = GwtKapuaCommonsModelConverter.convertKapuaId(scopeIdString); - JobStepDefinitionListResult result = JOB_STEP_DEFINITION_SERVICE.query(JOB_STEP_DEFINITION_FACTORY.newQuery(scopeId)); + JobStepDefinitionListResult result = JOB_STEP_DEFINITION_SERVICE.query(new JobStepDefinitionQuery(scopeId)); for (JobStepDefinition jsd : result.getItems()) { if (!Strings.isNullOrEmpty(JOB_STEP_DEFINITION_EXCLUDE_REGEX) && jsd.getName().matches(JOB_STEP_DEFINITION_EXCLUDE_REGEX)) { @@ -100,8 +102,8 @@ public GwtJobStepProperty trickGwt() { } /** - * Set the {@link GwtJobStepProperty#isEnum()} property. - * This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE Emulation library. + * Set the {@link GwtJobStepProperty#isEnum()} property. This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE + * Emulation library. * * @param jobStepProperties * @throws ClassNotFoundException diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepServiceImpl.java index adfc96ed4be..80a1a6c49c7 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobStepServiceImpl.java @@ -12,9 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -30,18 +30,19 @@ import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.job.step.JobStep; import org.eclipse.kapua.service.job.step.JobStepAttributes; import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepFactory; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService; -import java.util.ArrayList; -import java.util.List; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtJobStepServiceImpl extends KapuaRemoteServiceServlet implements GwtJobStepService { @@ -60,7 +61,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtJobSte List gwtJobStepList = new ArrayList(); try { // Convert from GWT entity - JobStepQuery jobStepQuery = GwtKapuaJobModelConverter.convertJobStepQuery(gwtJobStepQuery, loadConfig); + KapuaQuery jobStepQuery = GwtKapuaJobModelConverter.convertJobStepQuery(gwtJobStepQuery, loadConfig); // query JobStepListResult jobStepList = JOB_STEP_SERVICE.query(jobStepQuery); @@ -94,7 +95,7 @@ public Integer count(String scopeIdString, String jobIdString) throws GwtKapuaEx KapuaId jobId = GwtKapuaCommonsModelConverter.convertKapuaId(jobIdString); // query - JobStepQuery jobStepQuery = JOB_STEP_FACTORY.newQuery(scopeId); + KapuaQuery jobStepQuery = new KapuaQuery(scopeId); jobStepQuery.setPredicate(jobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobId)); return new Long(JOB_STEP_SERVICE.count(jobStepQuery)).intValue(); @@ -223,8 +224,8 @@ public int getJobStepPropertyLengthMax() throws GwtKapuaException { } /** - * Set the {@link GwtJobStepProperty#isEnum()} property. - * This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE Emulation library. + * Set the {@link GwtJobStepProperty#isEnum()} property. This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE + * Emulation library. * * @param jobStepProperties * @throws ClassNotFoundException diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobTargetServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobTargetServiceImpl.java index 4936241711e..6d33a9bf00b 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobTargetServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtJobTargetServiceImpl.java @@ -12,9 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.eclipse.kapua.KapuaErrorCodes; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; @@ -31,6 +33,7 @@ import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.device.registry.Device; import org.eclipse.kapua.service.device.registry.DeviceAttributes; import org.eclipse.kapua.service.device.registry.DeviceFactory; @@ -41,13 +44,11 @@ import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; public class GwtJobTargetServiceImpl extends KapuaRemoteServiceServlet implements GwtJobTargetService { @@ -70,7 +71,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtJobT List gwtJobTargetList = new ArrayList(); try { // Convert from GWT entity - JobTargetQuery jobTargetQuery = GwtKapuaJobModelConverter.convertJobTargetQuery(gwtJobTargetQuery, loadConfig); + KapuaQuery jobTargetQuery = GwtKapuaJobModelConverter.convertJobTargetQuery(gwtJobTargetQuery, loadConfig); // query JobTargetListResult jobTargetList = JOB_TARGET_SERVICE.query(jobTargetQuery); @@ -83,7 +84,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtJobT //TODO: #LAYER_VIOLATION - manual device lookup - DeviceQuery query = DEVICE_FACTORY.newQuery(jobTargetQuery.getScopeId()); + DeviceQuery query = new DeviceQuery(jobTargetQuery.getScopeId()); query.setPredicate(query.attributePredicate(DeviceAttributes.ENTITY_ID, deviceIds)); DeviceListResult deviceListResult = DEVICE_REGISTRY_SERVICE.query(query); @@ -192,8 +193,10 @@ public void delete(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJobTarge /** * For each item query clientId by its foreign key and insert it into existing list. * - * @param gwtJobTarget existing target that is updated - * @param device existing device + * @param gwtJobTarget + * existing target that is updated + * @param device + * existing device * @throws KapuaException */ private void insertClientId(GwtJobTarget gwtJobTarget, Device device) { diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerDefinitionServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerDefinitionServiceImpl.java index f91e4c39114..58faaa12171 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerDefinitionServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerDefinitionServiceImpl.java @@ -12,8 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; import org.eclipse.kapua.app.console.module.api.server.util.KapuaExceptionHandler; @@ -24,13 +25,14 @@ import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionListResult; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; -import java.util.ArrayList; -import java.util.List; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; public class GwtTriggerDefinitionServiceImpl extends KapuaRemoteServiceServlet implements GwtTriggerDefinitionService { @@ -43,7 +45,7 @@ public class GwtTriggerDefinitionServiceImpl extends KapuaRemoteServiceServlet i public ListLoadResult findAll() throws GwtKapuaException { List gwtTriggerDefinitionList = new ArrayList(); try { - TriggerDefinitionListResult result = TRIGGER_DEFINITION_SERVICE.query(TRIGGER_DEFINITION_FACTORY.newQuery(null)); + TriggerDefinitionListResult result = TRIGGER_DEFINITION_SERVICE.query(new KapuaQuery((KapuaId) null)); for (TriggerDefinition jsd : result.getItems()) { GwtTriggerDefinition gwtTriggerDefinition = KapuaGwtJobModelConverter.convertTriggerDefinition(jsd); @@ -84,8 +86,8 @@ public GwtTriggerProperty trickGwt() { } /** - * Set the {@link GwtTriggerProperty#isEnum()} property. - * This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE Emulation library. + * Set the {@link GwtTriggerProperty#isEnum()} property. This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE + * Emulation library. * * @param triggerProperties * @throws ClassNotFoundException diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerServiceImpl.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerServiceImpl.java index 9a58ca82bdb..dfccf56c7f2 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerServiceImpl.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/server/GwtTriggerServiceImpl.java @@ -12,10 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.server; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; -import com.google.common.base.Strings; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + import org.eclipse.kapua.app.console.module.api.client.GwtKapuaErrorCode; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -33,11 +34,11 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.scheduler.trigger.Trigger; import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerService; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory; @@ -46,10 +47,10 @@ import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; import org.quartz.CronExpression; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; +import com.google.common.base.Strings; public class GwtTriggerServiceImpl extends KapuaRemoteServiceServlet implements GwtTriggerService { @@ -80,7 +81,7 @@ public class GwtTriggerServiceImpl extends KapuaRemoteServiceServlet implements @Override public TriggerDefinitionListResult call() throws Exception { - TriggerDefinitionQuery query = TRIGGER_DEFINITION_FACTORY.newQuery(null); + TriggerDefinitionQuery query = new TriggerDefinitionQuery((KapuaId) null); return TRIGGER_DEFINITION_SERVICE.query(query); } }); @@ -115,7 +116,7 @@ public PagingLoadResult findByJobId(PagingLoadConfig loadConfig, Str gwtTriggerQuery.setScopeId(gwtScopeId); gwtTriggerQuery.setJobId(gwtJobId); - TriggerQuery triggerQuery = GwtKapuaJobModelConverter.convertTriggerQuery(gwtTriggerQuery, loadConfig); + KapuaQuery triggerQuery = GwtKapuaJobModelConverter.convertTriggerQuery(gwtTriggerQuery, loadConfig); // query TriggerListResult triggerListResult = TRIGGER_SERVICE.query(triggerQuery); diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterCsv.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterCsv.java index 6e85f445454..15aa2728f89 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterCsv.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterCsv.java @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.URLEncoder; @@ -26,6 +24,10 @@ import java.util.List; import java.util.Map; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.CharEncoding; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; @@ -40,7 +42,6 @@ import org.eclipse.kapua.service.job.targets.JobTarget; import com.opencsv.CSVWriter; -import org.apache.commons.lang3.CharEncoding; public class JobTargetExporterCsv extends JobTargetExporter { @@ -70,7 +71,7 @@ public void init(final String scopeId, String jobId) writer = new CSVWriter(outputWriter); List cols = new ArrayList(Arrays.asList(JOB_TARGET_PROPERTIES)); - writer.writeNext(cols.toArray(new String[]{ })); + writer.writeNext(cols.toArray(new String[] {})); } @Override @@ -81,7 +82,7 @@ public void append(KapuaListResult jobTargets) final KapuaIdFactory kapuaIdFactory = locator.getFactory(KapuaIdFactory.class); final DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class); final DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class); - final DeviceQuery deviceQuery = deviceFactory.newQuery(kapuaIdFactory.newKapuaId(scopeId)); + final DeviceQuery deviceQuery = new DeviceQuery(kapuaIdFactory.newKapuaId(scopeId)); KapuaId[] targetIds = new KapuaId[jobTargets.getSize()]; int i = 0; diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterServlet.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterServlet.java index 763c0070c58..8fc7e71c082 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterServlet.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/servlet/JobTargetExporterServlet.java @@ -25,11 +25,11 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaIdFactory; import org.eclipse.kapua.model.query.KapuaListResult; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.job.targets.JobTarget; import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +84,7 @@ private void internalDoGet(HttpServletRequest request, HttpServletResponse respo int offset = 0; - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(kapuaIdFactory.newKapuaId(scopeId)); + KapuaQuery jobTargetQuery = new KapuaQuery(kapuaIdFactory.newKapuaId(scopeId)); jobTargetQuery.setPredicate(jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, kapuaIdFactory.newKapuaId(jobId))); // paginate through the matching message jobTargetQuery.setLimit(250); diff --git a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/GwtKapuaJobModelConverter.java b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/GwtKapuaJobModelConverter.java index 70099ff1b88..be23d90ed1d 100644 --- a/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/GwtKapuaJobModelConverter.java +++ b/console/module/job/src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/GwtKapuaJobModelConverter.java @@ -12,8 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.job.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; import org.eclipse.kapua.app.console.module.job.shared.model.GwtJob; @@ -28,12 +31,12 @@ import org.eclipse.kapua.app.console.module.job.shared.model.GwtJobTargetQuery; import org.eclipse.kapua.app.console.module.job.shared.model.scheduler.GwtTriggerProperty; import org.eclipse.kapua.app.console.module.job.shared.model.scheduler.GwtTriggerQuery; -import org.eclipse.kapua.commons.model.query.FieldSortCriteriaImpl; import org.eclipse.kapua.job.engine.JobEngineFactory; import org.eclipse.kapua.job.engine.JobStartOptions; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; @@ -49,22 +52,17 @@ import org.eclipse.kapua.service.job.step.JobStepAttributes; import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepFactory; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerAttributes; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; public class GwtKapuaJobModelConverter { @@ -128,7 +126,7 @@ public static List convertJobStepProperties(List kapuaPropertyNameAttributePredicate = query.attributePredicate(TriggerAttributes.TRIGGER_PROPERTIES_NAME, "jobId"); AttributePredicate kapuaPropertyValueAttributePredicate = query.attributePredicate(TriggerAttributes.TRIGGER_PROPERTIES_VALUE, gwtTriggerQuery.getJobId()); @@ -297,7 +295,7 @@ public static List convertTriggerProperties(List query(PagingLoadConfig loadConfig, final GwtTagQ @Override public UserListResult call() throws Exception { - return userService.query(userFactory.newQuery(null)); + return userService.query(new UserQuery(null)); } }); @@ -186,12 +188,12 @@ public ListLoadResult getTagDescription(String scopeShortId, S final Tag tag = tagService.find(scopeId, tagId); if (tag != null) { -//TODO: #LAYER_VIOLATION - user lookup logic should not be done here (fetching all users is incredibly inefficient anyway) + //TODO: #LAYER_VIOLATION - user lookup logic should not be done here (fetching all users is incredibly inefficient anyway) UserListResult userListResult = KapuaSecurityUtils.doPrivileged(new Callable() { @Override public UserListResult call() throws Exception { - return userService.query(userFactory.newQuery(null)); + return userService.query(new UserQuery(null)); } }); @@ -220,7 +222,7 @@ public UserListResult call() throws Exception { public List findAll(String scopeId) throws GwtKapuaException { List tagList = new ArrayList(); try { - TagQuery query = tagFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(scopeId)); + TagQuery query = new TagQuery(GwtKapuaCommonsModelConverter.convertKapuaId(scopeId)); TagListResult result = tagService.query(query); diff --git a/console/module/tag/src/main/java/org/eclipse/kapua/app/console/module/tag/shared/util/GwtKapuaTagModelConverter.java b/console/module/tag/src/main/java/org/eclipse/kapua/app/console/module/tag/shared/util/GwtKapuaTagModelConverter.java index c59cf43ed15..a0e1455fe8d 100644 --- a/console/module/tag/src/main/java/org/eclipse/kapua/app/console/module/tag/shared/util/GwtKapuaTagModelConverter.java +++ b/console/module/tag/src/main/java/org/eclipse/kapua/app/console/module/tag/shared/util/GwtKapuaTagModelConverter.java @@ -12,21 +12,22 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.tag.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; import org.eclipse.kapua.app.console.module.tag.shared.model.GwtTagQuery; -import org.eclipse.kapua.model.query.FieldSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.FieldSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator; import org.eclipse.kapua.service.tag.TagAttributes; import org.eclipse.kapua.service.tag.TagFactory; import org.eclipse.kapua.service.tag.TagQuery; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; + public class GwtKapuaTagModelConverter { private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); @@ -38,13 +39,15 @@ private GwtKapuaTagModelConverter() { /** * Converts a {@link GwtTagQuery} into a {@link TagQuery} object for backend usage * - * @param loadConfig the load configuration - * @param gwtTagQuery the {@link GwtTagQuery} to convertKapuaId + * @param loadConfig + * the load configuration + * @param gwtTagQuery + * the {@link GwtTagQuery} to convertKapuaId * @return the converted {@link TagQuery} */ public static TagQuery convertTagQuery(PagingLoadConfig loadConfig, GwtTagQuery gwtTagQuery) { - TagQuery query = TAG_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtTagQuery.getScopeId())); + TagQuery query = new TagQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtTagQuery.getScopeId())); // Predicates conversion AndPredicate andPredicate = query.andPredicate(); diff --git a/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/server/GwtUserServiceImpl.java b/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/server/GwtUserServiceImpl.java index 382c328ec8f..c08e4686211 100644 --- a/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/server/GwtUserServiceImpl.java +++ b/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/server/GwtUserServiceImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.user.server; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.ListLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.server.KapuaRemoteServiceServlet; @@ -59,11 +60,11 @@ import org.eclipse.kapua.service.user.UserService; import org.eclipse.kapua.service.user.UserType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; +import com.extjs.gxt.ui.client.data.BaseListLoadResult; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.ListLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; /** * The server side implementation of the RPC service. @@ -210,7 +211,7 @@ public ListLoadResult findAll(String scopeIdString) KapuaId scopeId = KapuaEid.parseCompactId(scopeIdString); List gwtUserList = new ArrayList(); try { - UserQuery query = USER_FACTORY.newQuery(scopeId); + UserQuery query = new UserQuery(scopeId); UserListResult list = USER_SERVICE.query(query); for (User user : list.getItems()) { @@ -244,7 +245,7 @@ public PagingLoadResult query(PagingLoadConfig loadConfig, GwtUserQuery @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -271,7 +272,7 @@ public UserListResult call() throws Exception { @Override public ListLoadResult getUserDescription(boolean isSsoEnabled, String shortScopeId, - String shortUserId) throws GwtKapuaException { + String shortUserId) throws GwtKapuaException { List gwtUserDescription = new ArrayList(); try { final KapuaId scopeId = KapuaEid.parseCompactId(shortScopeId); @@ -286,7 +287,7 @@ public ListLoadResult getUserDescription(boolean isSsoEnabled, @Override public UserListResult call() throws Exception { - return USER_SERVICE.query(USER_FACTORY.newQuery(null)); + return USER_SERVICE.query(new UserQuery(null)); } }); @@ -337,7 +338,7 @@ public UserListResult call() throws Exception { @Override public PagingLoadResult getUsersForRole(PagingLoadConfig pagingLoadConfig, - GwtAccessRoleQuery query) throws GwtKapuaException { + GwtAccessRoleQuery query) throws GwtKapuaException { int totalLength = 0; List list = new ArrayList(); try { @@ -361,7 +362,7 @@ public PagingLoadResult getUsersForRole(PagingLoadConfig pagingLoadConf @Override public PagingLoadResult getUsersForAccount(PagingLoadConfig loadConfig, GwtUserQuery gwtUserQuery, - String accountId) throws GwtKapuaException { + String accountId) throws GwtKapuaException { int totalLength = 0; List gwtUsers = new ArrayList(); @@ -373,7 +374,7 @@ public PagingLoadResult getUsersForAccount(PagingLoadConfig loadConfig, if (!users.isEmpty()) { //TODO: #LAYER_VIOLATION - user lookup should not be done here (horribly inefficient) - final UserQuery allUsersQuery = USER_FACTORY.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(accountId)); + final UserQuery allUsersQuery = new UserQuery(GwtKapuaCommonsModelConverter.convertKapuaId(accountId)); UserListResult allUsers = KapuaSecurityUtils.doPrivileged(new Callable() { @Override @@ -407,7 +408,7 @@ public UserListResult call() throws Exception { private DeviceListResult deviceListQuery(KapuaId scopeId) throws KapuaException { DeviceListResult devicesList = null; if (AUTHORIZATION_SERVICE.isPermitted(PERMISSION_FACTORY.newPermission(Domains.DEVICE, Actions.read, scopeId))) { - DeviceQuery deviceQuery = DEVICE_FACTORY.newQuery(scopeId); + DeviceQuery deviceQuery = new DeviceQuery(scopeId); devicesList = DEVICE_SERVICE.query(deviceQuery); } return devicesList; diff --git a/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/shared/util/GwtKapuaUserModelConverter.java b/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/shared/util/GwtKapuaUserModelConverter.java index bc3f91dd60a..91f9bb4ae67 100644 --- a/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/shared/util/GwtKapuaUserModelConverter.java +++ b/console/module/user/src/main/java/org/eclipse/kapua/app/console/module/user/shared/util/GwtKapuaUserModelConverter.java @@ -12,9 +12,6 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.module.user.shared.util; -import com.extjs.gxt.ui.client.Style.SortDir; -import com.extjs.gxt.ui.client.data.BaseModel; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; import org.eclipse.kapua.app.console.module.user.shared.model.GwtUser.GwtUserStatus; @@ -32,6 +29,10 @@ import org.eclipse.kapua.service.user.UserStatus; import org.eclipse.kapua.service.user.UserType; +import com.extjs.gxt.ui.client.Style.SortDir; +import com.extjs.gxt.ui.client.data.BaseModel; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; + /** * Utility class for convertKapuaId {@link BaseModel}s to {@link KapuaEntity}ies and other Kapua models */ @@ -43,8 +44,10 @@ private GwtKapuaUserModelConverter() { /** * Converts a {@link GwtUserQuery} into a {@link UserQuery} object for backend usage * - * @param loadConfig the load configuration - * @param gwtUserQuery the {@link GwtUserQuery} to convertKapuaId + * @param loadConfig + * the load configuration + * @param gwtUserQuery + * the {@link GwtUserQuery} to convertKapuaId * @return the converted {@link UserQuery} */ public static UserQuery convertUserQuery(PagingLoadConfig loadConfig, GwtUserQuery gwtUserQuery) { @@ -53,7 +56,7 @@ public static UserQuery convertUserQuery(PagingLoadConfig loadConfig, GwtUserQue KapuaLocator locator = KapuaLocator.getInstance(); UserFactory userFactory = locator.getFactory(UserFactory.class); - UserQuery query = userFactory.newQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtUserQuery.getScopeId())); + UserQuery query = new UserQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtUserQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); if (gwtUserQuery.getName() != null && !gwtUserQuery.getName().isEmpty()) { diff --git a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/api/AbstractEntityAttributeMigrator.java b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/api/AbstractEntityAttributeMigrator.java index a59da006688..48266a89e06 100644 --- a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/api/AbstractEntityAttributeMigrator.java +++ b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/api/AbstractEntityAttributeMigrator.java @@ -54,7 +54,7 @@ public void migrate(List entitiesToMigrate) throws KapuaException { @Override public List getChunk(int offset, int limit) throws KapuaException { - KapuaQuery query = newEntityQuery(); + KapuaQuery query = new KapuaQuery(); // This is the most stable sorting even if it is not always indexed query.setSortCriteria(query.fieldSortCriteria(KapuaEntityAttributes.CREATED_ON, SortOrder.ASCENDING)); @@ -67,9 +67,8 @@ public List getChunk(int offset, int limit) throws KapuaException { @Override public long getTotalCount() throws KapuaException { - KapuaQuery query = newEntityQuery(); + KapuaQuery query = new KapuaQuery(); return entityService.count(query); } - protected abstract KapuaQuery newEntityQuery(); } diff --git a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionAttributeMigrator.java b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionAttributeMigrator.java index 1b8ce0616c7..fdb81658f0e 100644 --- a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionAttributeMigrator.java +++ b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionAttributeMigrator.java @@ -16,10 +16,10 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.extras.migrator.encryption.api.AbstractEntityAttributeMigrator; import org.eclipse.kapua.extras.migrator.encryption.api.EntitySecretAttributeMigrator; -import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; public class MfaOptionAttributeMigrator extends AbstractEntityAttributeMigrator implements EntitySecretAttributeMigrator { + public MfaOptionAttributeMigrator(String persistenceUnitName, KapuaJpaTxManagerFactory jpaTxManagerFactory) { super(new MfaOptionMigratorServiceImpl( jpaTxManagerFactory.create(persistenceUnitName), @@ -31,9 +31,4 @@ public MfaOptionAttributeMigrator(String persistenceUnitName, KapuaJpaTxManagerF public String getEntityName() { return MfaOption.TYPE; } - - @Override - protected KapuaQuery newEntityQuery() { - return new MfaOptionMigratorQueryImpl(); - } } diff --git a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionMigratorQueryImpl.java b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionMigratorQueryImpl.java deleted file mode 100644 index 65d19e55d7d..00000000000 --- a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/authentication/MfaOptionMigratorQueryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.extras.migrator.encryption.authentication; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionQuery; - -/** - * {@link MfaOptionQuery} definition. - * - * @since 1.0.0 - */ -public class MfaOptionMigratorQueryImpl extends AbstractKapuaNamedQuery implements MfaOptionQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public MfaOptionMigratorQueryImpl() { - super(); - } -} diff --git a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepAttributeMigrator.java b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepAttributeMigrator.java index 6b84f533c8e..e821bd2d6fe 100644 --- a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepAttributeMigrator.java +++ b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepAttributeMigrator.java @@ -16,7 +16,6 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.extras.migrator.encryption.api.AbstractEntityAttributeMigrator; import org.eclipse.kapua.extras.migrator.encryption.api.EntitySecretAttributeMigrator; -import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.job.step.JobStep; public class JobStepAttributeMigrator extends AbstractEntityAttributeMigrator implements EntitySecretAttributeMigrator { @@ -33,8 +32,4 @@ public String getEntityName() { return JobStep.TYPE; } - @Override - protected KapuaQuery newEntityQuery() { - return new JobStepMigratorQueryImpl(); - } } diff --git a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepMigratorQueryImpl.java b/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepMigratorQueryImpl.java deleted file mode 100644 index e9a1241dc28..00000000000 --- a/extras/encryption-migrator/src/main/java/org/eclipse/kapua/extras/migrator/encryption/job/JobStepMigratorQueryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.extras.migrator.encryption.job; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.service.job.step.JobStepQuery; - -/** - * {@link JobStepQuery} definition. - * - * @since 1.0.0 - */ -public class JobStepMigratorQueryImpl extends AbstractKapuaNamedQuery implements JobStepQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public JobStepMigratorQueryImpl() { - super(); - } -} diff --git a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionFactory.java b/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionFactory.java index 88305e0d0a6..044a5de8692 100644 --- a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionFactory.java +++ b/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionFactory.java @@ -19,6 +19,6 @@ * * @since 1.1.0 */ -public interface QueuedJobExecutionFactory extends KapuaEntityFactory { +public interface QueuedJobExecutionFactory extends KapuaEntityFactory { } diff --git a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionQuery.java b/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionQuery.java deleted file mode 100644 index 2aaef2a32f8..00000000000 --- a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.job.engine.queue; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link QueuedJobExecution} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.1.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = QueuedJobExecutionXmlRegistry.class, factoryMethod = "newQuery") -public interface QueuedJobExecutionQuery extends KapuaQuery { -} diff --git a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionXmlRegistry.java b/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionXmlRegistry.java index e8a33d71999..e53d63fcb29 100644 --- a/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionXmlRegistry.java +++ b/job-engine/api/src/main/java/org/eclipse/kapua/job/engine/queue/QueuedJobExecutionXmlRegistry.java @@ -44,7 +44,4 @@ public QueuedJobExecutionCreator newQueuedJobExecutionCreator() { return queuedJobExecutionFactory.newCreator(null); } - public QueuedJobExecutionQuery newQuery() { - return queuedJobExecutionFactory.newQuery(null); - } } diff --git a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java index fe837571f4f..4d9ace768a2 100644 --- a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java +++ b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java @@ -71,15 +71,12 @@ import org.eclipse.kapua.service.job.execution.JobExecutionXmlRegistry; import org.eclipse.kapua.service.job.step.JobStep; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepXmlRegistry; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; import org.eclipse.kapua.service.job.targets.JobTarget; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.scheduler.trigger.Trigger; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerXmlRegistry; import org.eclipse.persistence.jaxb.JAXBContextFactory; import org.eclipse.persistence.jaxb.MarshallerProperties; @@ -154,7 +151,6 @@ public JAXBContext getJAXBContext() throws KapuaException { JobStep.class, JobStepListResult.class, - JobStepQuery.class, JobStepXmlRegistry.class, JobStepProperty.class, @@ -165,7 +161,6 @@ public JAXBContext getJAXBContext() throws KapuaException { JobTarget.class, JobTargetListResult.class, - JobTargetQuery.class, JobExecutionXmlRegistry.class, JobTargetSublist.class, @@ -182,7 +177,6 @@ public JAXBContext getJAXBContext() throws KapuaException { Trigger.class, TriggerListResult.class, - TriggerQuery.class, TriggerXmlRegistry.class, KuraDeviceConfiguration.class diff --git a/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetReader.java b/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetReader.java index 02d34c4f333..a1c6930ee97 100644 --- a/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetReader.java +++ b/job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetReader.java @@ -40,7 +40,6 @@ import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.slf4j.Logger; @@ -88,7 +87,7 @@ public void open(Serializable arg0) throws Exception { jobLogger.info("Reading target chunk. Step:{} (index:{})...", stepName, stepIndex); // Job Id and JobTarget status filtering - JobTargetQuery query = jobTargetFactory.newQuery(jobContextWrapper.getScopeId()); + KapuaQuery query = new KapuaQuery(jobContextWrapper.getScopeId()); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(JobTargetAttributes.JOB_ID, jobContextWrapper.getJobId()) diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/JobEngineServiceJbatch.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/JobEngineServiceJbatch.java index 80f18a685b9..b7a01c71f70 100644 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/JobEngineServiceJbatch.java +++ b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/JobEngineServiceJbatch.java @@ -12,6 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.job.engine.jbatch; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.KapuaIllegalArgumentException; @@ -33,6 +40,7 @@ import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.job.Job; @@ -41,19 +49,11 @@ import org.eclipse.kapua.service.job.execution.JobExecutionService; import org.eclipse.kapua.service.job.step.JobStepAttributes; import org.eclipse.kapua.service.job.step.JobStepFactory; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - @Singleton public class JobEngineServiceJbatch implements JobEngineService { @@ -96,7 +96,7 @@ public void startJob(KapuaId scopeId, KapuaId jobId, JobStartOptions jobStartOpt throw new KapuaEntityNotFoundException(Job.TYPE, jobId); } // Check job targets - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate(jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, jobId)); if (jobTargetService.count(jobTargetQuery) <= 0) { throw new JobMissingTargetException(scopeId, jobId); @@ -115,7 +115,7 @@ public void startJob(KapuaId scopeId, KapuaId jobId, JobStartOptions jobStartOpt } } // Check job steps - JobStepQuery jobStepQuery = jobStepFactory.newQuery(scopeId); + KapuaQuery jobStepQuery = new KapuaQuery(scopeId); jobStepQuery.setPredicate(jobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobId)); if (jobStepService.count(jobStepQuery) <= 0) { throw new JobMissingStepException(scopeId, jobId); @@ -273,12 +273,17 @@ public void cleanJobData(KapuaId scopeId, KapuaId jobId) throws KapuaException { /** * Using the {@link JbatchDriver} checks whether the {@link Job} is running. * - * @param scopeId The {@link Job#getScopeId()}. - * @param jobId The {@link Job#getId()}. + * @param scopeId + * The {@link Job#getScopeId()}. + * @param jobId + * The {@link Job#getId()}. * @return {@code true} if {@link JbatchDriver} reports that is running, {@code false} otherwise. - * @throws JobCheckRunningException if {@link Job} running status cannot be checked. - * @throws KapuaEntityNotFoundException if {@link Job} does not exists. - * @throws KapuaException if any other error occurs. + * @throws JobCheckRunningException + * if {@link Job} running status cannot be checked. + * @throws KapuaEntityNotFoundException + * if {@link Job} does not exists. + * @throws KapuaException + * if any other error occurs. * @since 1.5.0 */ private boolean internalIsRunning(KapuaId scopeId, KapuaId jobId) throws KapuaException { diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/driver/JbatchDriver.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/driver/JbatchDriver.java index 832e94e5242..19eec12787e 100644 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/driver/JbatchDriver.java +++ b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/driver/JbatchDriver.java @@ -54,13 +54,13 @@ import org.eclipse.kapua.job.engine.jbatch.persistence.JPAPersistenceManagerImpl; import org.eclipse.kapua.job.engine.jbatch.setting.JobEngineSettingKeys; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.job.Job; import org.eclipse.kapua.service.job.execution.JobExecutionService; import org.eclipse.kapua.service.job.step.JobStep; import org.eclipse.kapua.service.job.step.JobStepAttributes; import org.eclipse.kapua.service.job.step.JobStepFactory; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService; @@ -153,7 +153,7 @@ public void startJob(@NotNull KapuaId scopeId, @NotNull KapuaId jobId, @NotNull String jobXmlDefinition; String jobName = JbatchDriver.getJbatchJobName(scopeId, jobId); try { - JobStepQuery query = jobStepFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(JobStepAttributes.JOB_ID, jobId)); JobStepListResult jobSteps = jobStepService.query(query); diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/KapuaJobListener.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/KapuaJobListener.java index 5a347e7630f..697209eef62 100644 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/KapuaJobListener.java +++ b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/KapuaJobListener.java @@ -42,6 +42,7 @@ import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionService; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionStatus; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.job.Job; @@ -56,7 +57,6 @@ import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.slf4j.Logger; @@ -285,7 +285,7 @@ private JobExecution createJobExecution(KapuaId scopeId, KapuaId jobId, JobTarge jobExecutionCreator.setEntityAttributes(jobExecutionProperties); if (jobTargetSublist.isEmpty()) { - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate( jobTargetQuery.andPredicate( @@ -338,7 +338,7 @@ private JobExecution getAnotherJobExecutionRunning(KapuaId scopeId, KapuaId jobI List runningExecutionsIds = BatchRuntime.getJobOperator().getRunningExecutions(jobName); if (runningExecutionsIds.size() > 1) { - JobExecutionQuery jobExecutionQuery = jobExecutionFactory.newQuery(scopeId); + JobExecutionQuery jobExecutionQuery = new JobExecutionQuery(scopeId); jobExecutionQuery.setPredicate( jobExecutionQuery.andPredicate( diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/QueuedJobExecutionCheckTask.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/QueuedJobExecutionCheckTask.java index 9968e4dac2c..13be4ff8532 100644 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/QueuedJobExecutionCheckTask.java +++ b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/QueuedJobExecutionCheckTask.java @@ -12,8 +12,8 @@ *******************************************************************************/ package org.eclipse.kapua.job.engine.jbatch.listener; -import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; +import java.util.TimerTask; + import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.job.engine.JobEngineService; import org.eclipse.kapua.job.engine.jbatch.setting.JobEngineSetting; @@ -22,15 +22,15 @@ import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionAttributes; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionFactory; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionListResult; -import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionQuery; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionService; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionStatus; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.predicate.AndPredicate; +import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.TimerTask; - public class QueuedJobExecutionCheckTask extends TimerTask { private static final Logger LOG = LoggerFactory.getLogger(QueuedJobExecutionCheckTask.class); @@ -64,12 +64,12 @@ public void run() { LOG.info("Checking Job Execution queue for: {}...", jobExecutionId); try { - QueuedJobExecutionQuery query = queuedJobExecutionFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( - new AndPredicateImpl( - new AttributePredicateImpl<>(QueuedJobExecutionAttributes.JOB_ID, jobId), - new AttributePredicateImpl<>(QueuedJobExecutionAttributes.WAIT_FOR_JOB_EXECUTION_ID, jobExecutionId) + new AndPredicate( + new AttributePredicate<>(QueuedJobExecutionAttributes.JOB_ID, jobId), + new AttributePredicate<>(QueuedJobExecutionAttributes.WAIT_FOR_JOB_EXECUTION_ID, jobExecutionId) ) ); diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionFactoryImpl.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionFactoryImpl.java index 6a9029ac52b..86d3c73800a 100644 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionFactoryImpl.java +++ b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.job.engine.queue.QueuedJobExecution; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionCreator; import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionFactory; -import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionQuery; import org.eclipse.kapua.model.id.KapuaId; /** @@ -39,11 +38,6 @@ public QueuedJobExecutionCreator newCreator(KapuaId scopeId) { return new QueuedJobExecutionCreatorImpl(scopeId); } - @Override - public QueuedJobExecutionQuery newQuery(KapuaId scopeId) { - return new QueuedJobExecutionQueryImpl(scopeId); - } - @Override public QueuedJobExecution clone(QueuedJobExecution queuedJobExecution) { try { diff --git a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionQueryImpl.java b/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionQueryImpl.java deleted file mode 100644 index e58f97796e2..00000000000 --- a/job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/queue/jbatch/QueuedJobExecutionQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.job.engine.queue.jbatch; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.job.engine.queue.QueuedJobExecutionQuery; -import org.eclipse.kapua.model.id.KapuaId; - -/** - * {@link QueuedJobExecutionQuery} implementation. - * - * @since 1.1.0 - */ -public class QueuedJobExecutionQueryImpl extends AbstractKapuaQuery implements QueuedJobExecutionQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.1.0 - */ - public QueuedJobExecutionQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/RolePermissionFactoryTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/RolePermissionFactoryTest.java index 6de74c1e466..e30f56787a6 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/RolePermissionFactoryTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/RolePermissionFactoryTest.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.permission.shiro.PermissionImpl; import org.eclipse.kapua.service.authorization.role.RolePermission; import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.shiro.RolePermissionFactoryImpl; import org.junit.Assert; import org.junit.Before; @@ -77,18 +76,6 @@ public void newCreatorNullTest() { Assert.assertNull("Null expected.", rolePermissionFactoryImpl.newCreator(null).getScopeId()); } - @Test - public void newQueryTest() { - Assert.assertTrue("True expected.", rolePermissionFactoryImpl.newQuery(scopeId) instanceof RolePermissionQuery); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, rolePermissionFactoryImpl.newQuery(scopeId).getScopeId()); - } - - @Test - public void newQueryNullTest() { - Assert.assertTrue("True expected.", rolePermissionFactoryImpl.newQuery(null) instanceof RolePermissionQuery); - Assert.assertNull("Null expected.", rolePermissionFactoryImpl.newQuery(null).getScopeId()); - } - @Test public void cloneTest() { RolePermission resultRolePermission = rolePermissionFactoryImpl.clone(rolePermission); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java index e3ea828e27d..7cc550f8a83 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java @@ -12,11 +12,25 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.authorization.access.AccessInfo; @@ -24,23 +38,9 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.user.User; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - /** * {@link AccessInfo} REST API resource. * @@ -57,23 +57,28 @@ public class AccessInfos extends AbstractKapuaResource { /** * Gets the {@link AccessInfo} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param userId The optional {@link User} id to filter results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param userId + * The optional {@link User} id to filter results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link AccessInfoListResult} of all the {@link AccessInfo}s associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessInfoListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("userId") EntityId userId, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - AccessInfoQuery query = accessInfoFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (userId != null) { @@ -88,21 +93,24 @@ public AccessInfoListResult simpleQuery( } /** - * Queries the {@link AccessInfo}s with the given {@link AccessInfoQuery} parameter. + * Queries the {@link AccessInfo}s with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link AccessInfoQuery} to use to filter results. - * @return The {@link AccessInfoListResult} of all the result matching the given {@link AccessInfoQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link AccessInfoListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AccessInfoListResult query( @PathParam("scopeId") ScopeId scopeId, - AccessInfoQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return accessInfoService.query(query); @@ -111,37 +119,42 @@ public AccessInfoListResult query( /** * Counts the {@link AccessInfo}s with the given {@link AccessInfoQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to count results. - * @param query The {@link AccessInfoQuery} to use to filter count results. + * @param scopeId + * The {@link ScopeId} in which to count results. + * @param query + * The {@link AccessInfoQuery} to use to filter count results. * @return The count of all the result matching the given {@link AccessInfoQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, - AccessInfoQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return new CountResult(accessInfoService.count(query)); } /** - * Creates a new {@link AccessInfo} based on the information provided in {@link AccessInfoCreator} - * parameter. + * Creates a new {@link AccessInfo} based on the information provided in {@link AccessInfoCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link AccessInfo}. - * @param accessInfoCreator Provides the information for the new {@link AccessInfo} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link AccessInfo}. + * @param accessInfoCreator + * Provides the information for the new {@link AccessInfo} to be created. * @return The newly created {@link AccessInfo} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, // AccessInfoCreator accessInfoCreator) throws KapuaException { @@ -153,15 +166,18 @@ public Response create( /** * Gets the {@link AccessInfo} specified by the "accessInfoId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link AccessInfo}. - * @param accessInfoId The id of the requested {@link AccessInfo}. + * @param scopeId + * The {@link ScopeId} of the requested {@link AccessInfo}. + * @param accessInfoId + * The id of the requested {@link AccessInfo}. * @return The requested {@link AccessInfo} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{accessInfoId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessInfo find( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId) throws KapuaException { @@ -173,10 +189,13 @@ public AccessInfo find( /** * Deletes the {@link AccessInfo} specified by the "accessInfoId" path parameter. * - * @param scopeId The {@link ScopeId} of the {@link AccessInfo} to be deleted. - * @param accessInfoId The id of the {@link AccessInfo} to be deleted. + * @param scopeId + * The {@link ScopeId} of the {@link AccessInfo} to be deleted. + * @param accessInfoId + * The id of the {@link AccessInfo} to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java index d6953da94f3..ea7109219d2 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java @@ -12,13 +12,26 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaEntityAttributes; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; @@ -28,21 +41,9 @@ import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; /** * {@link AccessPermission} REST API resource. @@ -60,18 +61,25 @@ public class AccessPermissions extends AbstractKapuaResource { /** * Gets the {@link AccessPermission} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param accessInfoId The optional {@link AccessInfo} id to filter results. - * @param offset The result set offset. - * @param limit The result set limit. - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param accessInfoId + * The optional {@link AccessInfo} id to filter results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. * @return The {@link AccessPermissionListResult} of all the {@link AccessPermission}s associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessPermissionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @@ -80,7 +88,7 @@ public AccessPermissionListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - AccessPermissionQuery query = accessPermissionFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId)); if (!Strings.isNullOrEmpty(sortParam)) { @@ -95,23 +103,27 @@ public AccessPermissionListResult simpleQuery( } /** - * Queries the {@link AccessPermission}s with the given {@link AccessPermissionQuery} parameter. + * Queries the {@link AccessPermission}s with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param accessInfoId The {@link AccessInfo} id in which to search results. - * @param query The {@link AccessPermissionQuery} to use to filter results. - * @return The {@link AccessPermissionListResult} of all the result matching the given {@link AccessPermissionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param accessInfoId + * The {@link AccessInfo} id in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link AccessPermissionListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AccessPermissionListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, - AccessPermissionQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); @@ -121,23 +133,27 @@ public AccessPermissionListResult query( } /** - * Counts the {@link AccessPermission}s with the given {@link AccessPermissionQuery} parameter. + * Counts the {@link AccessPermission}s with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to count results. - * @param accessInfoId The {@link AccessInfo} id in which to count results. - * @param query The {@link AccessPermissionQuery} to use to filter count results. - * @return The count of all the result matching the given {@link AccessPermissionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to count results. + * @param accessInfoId + * The {@link AccessInfo} id in which to count results. + * @param query + * The {@link KapuaQuery} to use to filter count results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, - AccessPermissionQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId)); @@ -146,19 +162,22 @@ public CountResult count( } /** - * Creates a new {@link AccessPermission} based on the information provided in {@link AccessPermissionCreator} - * parameter. + * Creates a new {@link AccessPermission} based on the information provided in {@link AccessPermissionCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the AccessPermission. - * @param accessInfoId The {@link AccessInfo} id in which to create the AccessPermission. - * @param accessPermissionCreator Provides the information for the new {@link AccessPermission} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the AccessPermission. + * @param accessInfoId + * The {@link AccessInfo} id in which to create the AccessPermission. + * @param accessPermissionCreator + * Provides the information for the new {@link AccessPermission} to be created. * @return The newly created {@link AccessPermission} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @@ -172,21 +191,25 @@ public Response create( /** * Returns the AccessPermission specified by the "accessPermissionId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link AccessPermission}. - * @param accessInfoId The {@link AccessInfo} id of the requested {@link AccessPermission}. - * @param accessPermissionId The id of the requested AccessPermission. + * @param scopeId + * The {@link ScopeId} of the requested {@link AccessPermission}. + * @param accessInfoId + * The {@link AccessInfo} id of the requested {@link AccessPermission}. + * @param accessPermissionId + * The id of the requested AccessPermission. * @return The requested AccessPermission object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{accessPermissionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessPermission find( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @PathParam("accessPermissionId") EntityId accessPermissionId) throws KapuaException { - AccessPermissionQuery query = accessPermissionFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId), @@ -205,11 +228,15 @@ public AccessPermission find( /** * Deletes the {@link AccessPermission} specified by the "accessPermissionId" path parameter. * - * @param scopeId The {@link ScopeId} of the {@link AccessPermission} to delete. - * @param accessInfoId The {@link AccessInfo} id of the {@link AccessPermission} to delete. - * @param accessPermissionId The id of the AccessPermission to be deleted. + * @param scopeId + * The {@link ScopeId} of the {@link AccessPermission} to delete. + * @param accessInfoId + * The {@link AccessInfo} id of the {@link AccessPermission} to delete. + * @param accessPermissionId + * The id of the AccessPermission to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java index dfcebe6ad41..ea8bb283b27 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java @@ -12,12 +12,26 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaEntityAttributes; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.authorization.access.AccessRole; @@ -25,22 +39,8 @@ import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - @Path("{scopeId}/accessinfos/{accessInfoId}/roles") public class AccessRoles extends AbstractKapuaResource { @@ -52,22 +52,26 @@ public class AccessRoles extends AbstractKapuaResource { /** * Gets the {@link AccessRole} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link AccessRoleListResult} of all the accessRoles associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessRoleListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @QueryParam("askTotalCount") boolean askTotalCount, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - AccessRoleQuery query = accessRoleFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId)); @@ -79,22 +83,25 @@ public AccessRoleListResult simpleQuery( } /** - * Queries the results with the given {@link AccessRoleQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link AccessRoleQuery} to use to filter results. - * @return The {@link AccessRoleListResult} of all the result matching the given {@link AccessRoleQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link AccessRoleListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AccessRoleListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, - AccessRoleQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId)); @@ -103,22 +110,25 @@ public AccessRoleListResult query( } /** - * Counts the results with the given {@link AccessRoleQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link AccessRoleQuery} to use to filter results. - * @return The count of all the result matching the given {@link AccessRoleQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, - AccessRoleQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId)); @@ -127,18 +137,20 @@ public CountResult count( } /** - * Creates a new AccessRole based on the information provided in AccessRoleCreator - * parameter. + * Creates a new AccessRole based on the information provided in AccessRoleCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link AccessRole}. - * @param accessRoleCreator Provides the information for the new AccessRole to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link AccessRole}. + * @param accessRoleCreator + * Provides the information for the new AccessRole to be created. * @return The newly created {@link AccessRole} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @@ -152,20 +164,23 @@ public Response create( /** * Returns the AccessRole specified by the "accessRoleId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link AccessRole}. - * @param accessRoleId The id of the requested {@link AccessRole}. + * @param scopeId + * The {@link ScopeId} of the requested {@link AccessRole}. + * @param accessRoleId + * The id of the requested {@link AccessRole}. * @return The requested {@link AccessRole} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{accessRoleId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AccessRole find( @PathParam("scopeId") ScopeId scopeId, @PathParam("accessInfoId") EntityId accessInfoId, @PathParam("accessRoleId") EntityId accessRoleId) throws KapuaException { - AccessRoleQuery query = accessRoleFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId), @@ -184,9 +199,11 @@ public AccessRole find( /** * Deletes the AccessRole specified by the "accessRoleId" path parameter. * - * @param accessRoleId The id of the AccessRole to be deleted. + * @param accessRoleId + * The id of the AccessRole to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java index 4bfc274aba2..e230fbd3a42 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java @@ -32,6 +32,7 @@ import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaNamedEntityAttributes; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.MatchPredicate; @@ -41,7 +42,6 @@ import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountService; import com.google.common.base.Strings; @@ -93,7 +93,7 @@ public AccountListResult simpleQuery( return accountService.findChildrenRecursively(scopeId); } - AccountQuery query = accountFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setAskTotalCount(askTotalCount); AndPredicate andPredicate = query.andPredicate(); @@ -126,13 +126,13 @@ public String getMatchTerm() { } /** - * Queries the results with the given {@link AccountQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query - * The {@link AccountQuery} to use to filter results. - * @return The {@link AccountListResult} of all the result matching the given {@link AccountQuery} parameter. + * The {@link KapuaQuery} to use to filter results. + * @return The {@link AccountListResult} of all the result matching the given {@link KapuaQuery} parameter. * @throws KapuaException * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 @@ -143,20 +143,20 @@ public String getMatchTerm() { @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public AccountListResult query( @PathParam("scopeId") ScopeId scopeId, // - AccountQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return accountService.query(query); } /** - * Counts the results with the given {@link AccountQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to count results. * @param query - * The {@link AccountQuery} to use to filter results. - * @return The count of all the result matching the given {@link AccountQuery} parameter. + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. * @throws KapuaException * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 @@ -168,7 +168,7 @@ public AccountListResult query( @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, // - AccountQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return new CountResult(accountService.count(query)); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Credentials.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Credentials.java index a40032f1612..cb9b3e50f87 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Credentials.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Credentials.java @@ -26,13 +26,13 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.model.SetResult; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; @@ -41,9 +41,10 @@ import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialService; +import com.google.common.base.Strings; + @Path("{scopeId}/credentials") public class Credentials extends AbstractKapuaResource { @@ -53,19 +54,22 @@ public class Credentials extends AbstractKapuaResource { @Inject public CredentialFactory credentialFactory; - /** * Gets the {@link Credential} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link CredentialListResult} of all the credentials associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public CredentialListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("userId") EntityId userId, @@ -74,7 +78,7 @@ public CredentialListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - CredentialQuery query = credentialFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (userId != null) { @@ -93,60 +97,68 @@ public CredentialListResult simpleQuery( } /** - * Queries the results with the given {@link CredentialQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link CredentialQuery} to use to filter results. - * @return The {@link CredentialListResult} of all the result matching the given {@link CredentialQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link CredentialListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CredentialListResult query( @PathParam("scopeId") ScopeId scopeId, - CredentialQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return credentialService.query(query); } /** - * Counts the results with the given {@link CredentialQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link CredentialQuery} to use to filter results. - * @return The count of all the result matching the given {@link CredentialQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, - CredentialQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return new CountResult(credentialService.count(query)); } /** - * Creates a new Credential based on the information provided in CredentialCreator - * parameter. + * Creates a new Credential based on the information provided in CredentialCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Credential} - * @param credentialCreator Provides the information for the new Credential to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Credential} + * @param credentialCreator + * Provides the information for the new Credential to be created. * @return The newly created Credential object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, CredentialCreator credentialCreator) throws KapuaException { @@ -158,15 +170,18 @@ public Response create( /** * Returns the Credential specified by the "credentialId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Credential}. - * @param credentialId The id of the requested Credential. + * @param scopeId + * The {@link ScopeId} of the requested {@link Credential}. + * @param credentialId + * The id of the requested Credential. * @return The requested Credential object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{credentialId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Credential find( @PathParam("scopeId") ScopeId scopeId, @PathParam("credentialId") EntityId credentialId) throws KapuaException { @@ -178,15 +193,17 @@ public Credential find( /** * Updates the Credential based on the information provided in the Credential parameter. * - * @param credential The modified Credential whose attributed need to be updated. + * @param credential + * The modified Credential whose attributed need to be updated. * @return The updated credential. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{credentialId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Credential update( @PathParam("scopeId") ScopeId scopeId, @PathParam("credentialId") EntityId credentialId, @@ -200,9 +217,11 @@ public Credential update( /** * Deletes the Credential specified by the "credentialId" path parameter. * - * @param credentialId The id of the Credential to be deleted. + * @param credentialId + * The id of the Credential to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE @@ -215,14 +234,16 @@ public Response deleteCredential( return returnNoContent(); } - /** * Unlocks a {@link Credential} that has been locked due to a lockout policy. * - * @param scopeId The {@link ScopeId} of {@link Credential} to unlock. - * @param credentialId The id of the Credential to be unlocked. + * @param scopeId + * The {@link ScopeId} of {@link Credential} to unlock. + * @param credentialId + * The id of the Credential to be unlocked. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 * @deprecated Since 2.0.0. Please make use of {@link #unlock(ScopeId, EntityId)} */ @@ -237,14 +258,16 @@ public Response unlockCredential( return returnNoContent(); } - /** * Unlocks a {@link Credential} that has been locked due to a lockout policy. * - * @param scopeId The {@link ScopeId} of {@link Credential} to unlock. - * @param credentialId The id of the Credential to be unlocked. + * @param scopeId + * The {@link ScopeId} of {@link Credential} to unlock. + * @param credentialId + * The id of the Credential to be unlocked. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 2.0.0 */ @POST @@ -257,10 +280,9 @@ public Response unlock( return returnNoContent(); } - @GET @Path("_availableCredentials") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public SetResult getAvailableAuthAdapter() throws KapuaException { return new SetResult(credentialService.getAvailableCredentialTypes()); } diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceConnections.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceConnections.java index dc4bf788d2d..0235f37fc17 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceConnections.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceConnections.java @@ -12,7 +12,18 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -30,17 +41,7 @@ import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/deviceconnections") public class DeviceConnections extends AbstractKapuaResource { @@ -53,17 +54,23 @@ public class DeviceConnections extends AbstractKapuaResource { /** * Gets the {@link DeviceConnection} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param clientId The id of the {@link Device} in which to search results - * @param status The {@link DeviceConnectionStatus} in which to search results - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param clientId + * The id of the {@link Device} in which to search results + * @param status + * The {@link DeviceConnectionStatus} in which to search results + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link DeviceConnectionListResult} of all the deviceConnections associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceConnectionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("clientId") String clientId, @@ -72,7 +79,7 @@ public DeviceConnectionListResult simpleQuery( @QueryParam("status") DeviceConnectionStatus status, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - DeviceConnectionQuery query = deviceConnectionFactory.newQuery(scopeId); + DeviceConnectionQuery query = new DeviceConnectionQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(clientId)) { @@ -98,16 +105,19 @@ public DeviceConnectionListResult simpleQuery( /** * Queries the results with the given {@link DeviceConnectionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DeviceConnectionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link DeviceConnectionQuery} to use to filter results. * @return The {@link DeviceConnectionListResult} of all the result matching the given {@link DeviceConnectionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DeviceConnectionListResult query( @PathParam("scopeId") ScopeId scopeId, DeviceConnectionQuery query) throws KapuaException { @@ -119,16 +129,19 @@ public DeviceConnectionListResult query( /** * Counts the results with the given {@link DeviceConnectionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DeviceConnectionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link DeviceConnectionQuery} to use to filter results. * @return The count of all the result matching the given {@link DeviceConnectionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, DeviceConnectionQuery query) throws KapuaException { @@ -140,15 +153,18 @@ public CountResult count( /** * Returns the DeviceConnection specified by the "deviceConnectionId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link DeviceConnection}. - * @param deviceConnectionId The id of the requested DeviceConnection. + * @param scopeId + * The {@link ScopeId} of the requested {@link DeviceConnection}. + * @param deviceConnectionId + * The id of the requested DeviceConnection. * @return The requested DeviceConnection object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{deviceConnectionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceConnection find( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceConnectionId") EntityId deviceConnectionId) throws KapuaException { @@ -159,7 +175,7 @@ public DeviceConnection find( @GET @Path("_availableAuth") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public SetResult getAvailableAuthAdapter() { return new SetResult(deviceConnectionService.getAvailableAuthTypes()); } @@ -167,15 +183,18 @@ public SetResult getAvailableAuthAdapter() { /** * Request that the DeviceConnection specified by the "deviceConnectionId" is disconnected from the broker. * - * @param scopeId The {@link ScopeId} of the requested {@link DeviceConnection}. - * @param deviceConnectionId The id of the requested DeviceConnection. + * @param scopeId + * The {@link ScopeId} of the requested {@link DeviceConnection}. + * @param deviceConnectionId + * The id of the requested DeviceConnection. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 2.0.0 */ @POST @Path("{deviceConnectionId}/_disconnect") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response disconnect( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceConnectionId") EntityId deviceConnectionId) throws KapuaException { diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceEvents.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceEvents.java index 082f3f688e4..c9a3ee957f0 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceEvents.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceEvents.java @@ -12,7 +12,19 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; @@ -34,18 +46,7 @@ import org.eclipse.kapua.service.device.registry.event.DeviceEventQuery; import org.eclipse.kapua.service.device.registry.event.DeviceEventService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/devices/{deviceId}/events") public class DeviceEvents extends AbstractKapuaResource { @@ -60,20 +61,29 @@ public class DeviceEvents extends AbstractKapuaResource { /** * Gets the {@link DeviceEvent} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param resource The resource of the {@link DeviceEvent} in which to search results - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param resource + * The resource of the {@link DeviceEvent} in which to search results + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link DeviceEventListResult} of all the deviceEvents associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceEventListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -85,7 +95,7 @@ public DeviceEventListResult simpleQuery( @QueryParam("askTotalCount") boolean askTotalCount, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - DeviceEventQuery query = deviceEventFactory.newQuery(scopeId); + DeviceEventQuery query = new DeviceEventQuery(scopeId); if (deviceRegistryService.find(scopeId, deviceId) == null) { throw new KapuaEntityNotFoundException(Device.TYPE, deviceId); @@ -119,17 +129,21 @@ public DeviceEventListResult simpleQuery( /** * Queries the results with the given {@link DeviceEventQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param query The {@link DeviceEventQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param query + * The {@link DeviceEventQuery} to use to filter results. * @return The {@link DeviceEventListResult} of all the result matching the given {@link DeviceEventQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DeviceEventListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -153,17 +167,21 @@ public DeviceEventListResult query( /** * Counts the results with the given {@link DeviceEventQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param query The {@link DeviceEventQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param query + * The {@link DeviceEventQuery} to use to filter results. * @return The count of all the result matching the given {@link DeviceEventQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -182,16 +200,20 @@ public CountResult count( /** * Returns the DeviceEvent specified by the "deviceEventId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link DeviceEvent}. - * @param deviceId The {@link Device} id of the request {@link DeviceEvent}. - * @param deviceEventId The id of the requested DeviceEvent. + * @param scopeId + * The {@link ScopeId} of the requested {@link DeviceEvent}. + * @param deviceId + * The {@link Device} id of the request {@link DeviceEvent}. + * @param deviceEventId + * The id of the requested DeviceEvent. * @return The requested DeviceEvent object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{deviceEventId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceEvent find( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -201,7 +223,7 @@ public DeviceEvent find( throw new KapuaEntityNotFoundException(Device.TYPE, deviceId); } - DeviceEventQuery query = deviceEventFactory.newQuery(scopeId); + DeviceEventQuery query = new DeviceEventQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(DeviceEventAttributes.DEVICE_ID, deviceId), @@ -220,17 +242,20 @@ public DeviceEvent find( /** * Deletes the DeviceEvent specified by the "deviceEventId" path parameter. * - * @param deviceId The id of the Device in which to delete the event - * @param deviceEventId The id of the DeviceEvent to be deleted. + * @param deviceId + * The id of the Device in which to delete the event + * @param deviceEventId + * The id of the DeviceEvent to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE @Path("{deviceEventId}") public Response deleteDeviceEvent(@PathParam("scopeId") ScopeId scopeId, - @PathParam("deviceId") EntityId deviceId, - @PathParam("deviceEventId") EntityId deviceEventId) throws KapuaException { + @PathParam("deviceId") EntityId deviceId, + @PathParam("deviceEventId") EntityId deviceEventId) throws KapuaException { if (deviceRegistryService.find(scopeId, deviceId) == null) { throw new KapuaEntityNotFoundException(Device.TYPE, deviceId); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperationNotifications.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperationNotifications.java index c41a0ab8933..b980ef13472 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperationNotifications.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperationNotifications.java @@ -25,7 +25,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -43,6 +42,8 @@ import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationService; import org.eclipse.kapua.service.device.registry.Device; +import com.google.common.base.Strings; + @Path("{scopeId}/devices/{deviceId}/operations/{operationId}/notifications") public class DeviceManagementOperationNotifications extends AbstractKapuaResource { @@ -54,17 +55,23 @@ public class DeviceManagementOperationNotifications extends AbstractKapuaResourc /** * Gets the {@link ManagementOperationNotification} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param operationId The id of the {@link Device} in which to search results - * @param resource The resource of the {@link ManagementOperationNotification} in which to search results - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param operationId + * The id of the {@link Device} in which to search results + * @param resource + * The resource of the {@link ManagementOperationNotification} in which to search results + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link ManagementOperationNotificationListResult} of all the ManagementOperationNotifications associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ManagementOperationNotificationListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -75,7 +82,7 @@ public ManagementOperationNotificationListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId); + ManagementOperationNotificationQuery query = new ManagementOperationNotificationQuery(scopeId); AndPredicate andPredicate = query.andPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId)); @@ -99,17 +106,21 @@ public ManagementOperationNotificationListResult simpleQuery( /** * Queries the results with the given {@link ManagementOperationNotificationQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param operationId The id of the {@link Device} in which to search results - * @param query The {@link ManagementOperationNotificationQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param operationId + * The id of the {@link Device} in which to search results + * @param query + * The {@link ManagementOperationNotificationQuery} to use to filter results. * @return The {@link ManagementOperationNotificationListResult} of all the result matching the given {@link ManagementOperationNotificationQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public ManagementOperationNotificationListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -127,17 +138,21 @@ public ManagementOperationNotificationListResult query( /** * Counts the results with the given {@link ManagementOperationNotificationQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param operationId The id of the {@link Device} in which to search results - * @param query The {@link ManagementOperationNotificationQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param operationId + * The id of the {@link Device} in which to search results + * @param query + * The {@link ManagementOperationNotificationQuery} to use to filter results. * @return The count of all the result matching the given {@link ManagementOperationNotificationQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -152,23 +167,27 @@ public CountResult count( /** * Returns the ManagementOperationNotification specified by the "ManagementOperationNotificationId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link ManagementOperationNotification}. - * @param operationId The {@link Device} id of the request {@link ManagementOperationNotification}. - * @param managementOperationNotificationId The id of the requested ManagementOperationNotification. + * @param scopeId + * The {@link ScopeId} of the requested {@link ManagementOperationNotification}. + * @param operationId + * The {@link Device} id of the request {@link ManagementOperationNotification}. + * @param managementOperationNotificationId + * The id of the requested ManagementOperationNotification. * @return The requested ManagementOperationNotification object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{managementOperationNotificationId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ManagementOperationNotification find( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @PathParam("operationId") EntityId operationId, @PathParam("managementOperationNotificationId") EntityId managementOperationNotificationId) throws KapuaException { -//TODO: #LAYER_VIOLATION - findFirst should be resolved in bottom layer - ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId); + //TODO: #LAYER_VIOLATION - findFirst should be resolved in bottom layer + ManagementOperationNotificationQuery query = new ManagementOperationNotificationQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, operationId), @@ -187,10 +206,13 @@ public ManagementOperationNotification find( /** * Deletes the ManagementOperationNotification specified by the "ManagementOperationNotificationId" path parameter. * - * @param operationId The id of the Device in which to delete the ManagementOperation - * @param managementOperationNotificationId The id of the ManagementOperationNotification to be deleted. + * @param operationId + * The id of the Device in which to delete the ManagementOperation + * @param managementOperationNotificationId + * The id of the ManagementOperationNotification to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperations.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperations.java index 85087c62154..791da951ed3 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperations.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DeviceManagementOperations.java @@ -25,7 +25,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -44,6 +43,8 @@ import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationStatus; import org.eclipse.kapua.service.device.registry.Device; +import com.google.common.base.Strings; + @Path("{scopeId}/devices/{deviceId}/operations") public class DeviceManagementOperations extends AbstractKapuaResource { @@ -55,17 +56,23 @@ public class DeviceManagementOperations extends AbstractKapuaResource { /** * Gets the {@link DeviceManagementOperation} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param resource The resource of the {@link DeviceManagementOperation} in which to search results - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param resource + * The resource of the {@link DeviceManagementOperation} in which to search results + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link DeviceManagementOperationListResult} of all the deviceManagementOperations associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceManagementOperationListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -77,7 +84,7 @@ public DeviceManagementOperationListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - DeviceManagementOperationQuery query = deviceManagementOperationFactory.newQuery(scopeId); + DeviceManagementOperationQuery query = new DeviceManagementOperationQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); @@ -110,25 +117,29 @@ public DeviceManagementOperationListResult simpleQuery( /** * Queries the results with the given {@link DeviceManagementOperationQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param query The {@link DeviceManagementOperationQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param query + * The {@link DeviceManagementOperationQuery} to use to filter results. * @return The {@link DeviceManagementOperationListResult} of all the result matching the given {@link DeviceManagementOperationQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DeviceManagementOperationListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, DeviceManagementOperationQuery query) throws KapuaException { if (query.getPredicate() != null) { final AndPredicate andPredicate = query.andPredicate( - query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId), - query.getPredicate() + query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId), + query.getPredicate() ); query.setPredicate(andPredicate); } else { @@ -140,17 +151,21 @@ public DeviceManagementOperationListResult query( /** * Counts the results with the given {@link DeviceManagementOperationQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param deviceId The id of the {@link Device} in which to search results - * @param query The {@link DeviceManagementOperationQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param deviceId + * The id of the {@link Device} in which to search results + * @param query + * The {@link DeviceManagementOperationQuery} to use to filter results. * @return The count of all the result matching the given {@link DeviceManagementOperationQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -164,21 +179,25 @@ public CountResult count( /** * Returns the DeviceManagementOperation specified by the "deviceManagementOperationId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link DeviceManagementOperation}. - * @param deviceId The {@link Device} id of the request {@link DeviceManagementOperation}. - * @param deviceManagementOperationId The id of the requested DeviceManagementOperation. + * @param scopeId + * The {@link ScopeId} of the requested {@link DeviceManagementOperation}. + * @param deviceId + * The {@link Device} id of the request {@link DeviceManagementOperation}. + * @param deviceManagementOperationId + * The id of the requested DeviceManagementOperation. * @return The requested DeviceManagementOperation object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{deviceManagementOperationId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceManagementOperation find( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @PathParam("deviceManagementOperationId") EntityId deviceManagementOperationId) throws KapuaException { - DeviceManagementOperationQuery query = deviceManagementOperationFactory.newQuery(scopeId); + DeviceManagementOperationQuery query = new DeviceManagementOperationQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(DeviceManagementOperationAttributes.DEVICE_ID, deviceId), @@ -197,17 +216,20 @@ public DeviceManagementOperation find( /** * Deletes the DeviceManagementOperation specified by the "deviceManagementOperationId" path parameter. * - * @param deviceId The id of the Device in which to delete the ManagementOperation - * @param deviceManagementOperationId The id of the DeviceManagementOperation to be deleted. + * @param deviceId + * The id of the Device in which to delete the ManagementOperation + * @param deviceManagementOperationId + * The id of the DeviceManagementOperation to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE @Path("{deviceManagementOperationId}") public Response deleteDeviceManagementOperation(@PathParam("scopeId") ScopeId scopeId, - @PathParam("deviceId") EntityId deviceId, - @PathParam("deviceManagementOperationId") EntityId deviceManagementOperationId) throws KapuaException { + @PathParam("deviceId") EntityId deviceId, + @PathParam("deviceManagementOperationId") EntityId deviceManagementOperationId) throws KapuaException { deviceManagementOperationRegistryService.delete(scopeId, deviceManagementOperationId); return returnNoContent(); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Devices.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Devices.java index 8bfea63283d..98f7948d111 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Devices.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Devices.java @@ -12,7 +12,22 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -31,20 +46,7 @@ import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus; import org.eclipse.kapua.service.tag.Tag; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; +import com.google.common.base.Strings; @Path("{scopeId}/devices") public class Devices extends AbstractKapuaResource { @@ -57,23 +59,35 @@ public class Devices extends AbstractKapuaResource { /** * Gets the {@link Device} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param tagId The id of the {@link Tag} in which to search results - * @param clientId The id of the {@link Device} in which to search results - * @param connectionStatus The {@link DeviceConnectionStatus} in which to search results - * @param matchTerm A term to be matched in at least one of the configured fields of this entity - * @param fetchAttributes Additional attributes to be returned. Allowed values: connection, lastEvent - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param tagId + * The id of the {@link Tag} in which to search results + * @param clientId + * The id of the {@link Device} in which to search results + * @param connectionStatus + * The {@link DeviceConnectionStatus} in which to search results + * @param matchTerm + * A term to be matched in at least one of the configured fields of this entity + * @param fetchAttributes + * Additional attributes to be returned. Allowed values: connection, lastEvent + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link DeviceListResult} of all the devices associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DeviceListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("tagId") EntityId tagId, @@ -86,7 +100,7 @@ public DeviceListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - DeviceQuery query = deviceFactory.newQuery(scopeId); + DeviceQuery query = new DeviceQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (tagId != null) { @@ -118,16 +132,19 @@ public DeviceListResult simpleQuery( /** * Queries the results with the given {@link DeviceQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DeviceQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link DeviceQuery} to use to filter results. * @return The {@link DeviceListResult} of all the result matching the given {@link DeviceQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DeviceListResult query( @PathParam("scopeId") ScopeId scopeId, DeviceQuery query) throws KapuaException { @@ -139,16 +156,19 @@ public DeviceListResult query( /** * Counts the results with the given {@link DeviceQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DeviceQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link DeviceQuery} to use to filter results. * @return The count of all the result matching the given {@link DeviceQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, DeviceQuery query) throws KapuaException { @@ -158,18 +178,20 @@ public CountResult count( } /** - * Creates a new Device based on the information provided in DeviceCreator - * parameter. + * Creates a new Device based on the information provided in DeviceCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Device} - * @param deviceCreator Provides the information for the new Device to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Device} + * @param deviceCreator + * Provides the information for the new Device to be created. * @return The newly created Device object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, DeviceCreator deviceCreator) throws KapuaException { @@ -181,15 +203,18 @@ public Response create( /** * Returns the Device specified by the "deviceId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Device}. - * @param deviceId The id of the requested Device. + * @param scopeId + * The {@link ScopeId} of the requested {@link Device}. + * @param deviceId + * The id of the requested Device. * @return The requested Device object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{deviceId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Device find( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId) throws KapuaException { @@ -201,17 +226,21 @@ public Device find( /** * Updates the Device based on the information provided in the Device parameter. * - * @param scopeId The ScopeId of the requested Device. - * @param deviceId The id of the requested {@link Device} - * @param device The modified Device whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested Device. + * @param deviceId + * The id of the requested {@link Device} + * @param device + * The modified Device whose attributed need to be updated. * @return The updated device. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{deviceId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Device update( @PathParam("scopeId") ScopeId scopeId, @PathParam("deviceId") EntityId deviceId, @@ -225,10 +254,13 @@ public Device update( /** * Deletes the Device specified by the "deviceId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Device}. - * @param deviceId The id of the Device to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Device}. + * @param deviceId + * The id of the Device to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Domains.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Domains.java index 9effc5a8d46..39c0ce722a8 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Domains.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Domains.java @@ -12,31 +12,33 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaNamedEntityAttributes; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.eclipse.kapua.service.authorization.domain.DomainRegistryService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; +import com.google.common.base.Strings; @Path("{scopeId}/domains") public class Domains extends AbstractKapuaResource { @@ -49,22 +51,27 @@ public class Domains extends AbstractKapuaResource { /** * Gets the {@link Domain} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link Domain} name in which to search results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link Domain} name in which to search results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link DomainListResult} of all the domains associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DomainListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - DomainQuery query = domainFactory.newQuery(null); + final KapuaQuery query = new KapuaQuery((KapuaId) null); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -79,55 +86,64 @@ public DomainListResult simpleQuery( } /** - * Queries the results with the given {@link DomainQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DomainQuery} to use to filter results. - * @return The {@link DomainListResult} of all the result matching the given {@link DomainQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link DomainListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public DomainListResult query( @PathParam("scopeId") ScopeId scopeId, - DomainQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { return domainRegistryService.query(query); } /** - * Counts the results with the given {@link DomainQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link DomainQuery} to use to filter results. - * @return The count of all the result matching the given {@link DomainQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, - DomainQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { return new CountResult(domainRegistryService.count(query)); } /** * Returns the Domain specified by the "domainId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Domain}. - * @param domainId The id of the requested {@link Domain}. + * @param scopeId + * The {@link ScopeId} of the requested {@link Domain}. + * @param domainId + * The id of the requested {@link Domain}. * @return The requested Domain object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{domainId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Domain find( @PathParam("scopeId") ScopeId scopeId, @PathParam("domainId") EntityId domainId) throws KapuaException { diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java index 5eb39d15aa4..38e1f6f0124 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Groups.java @@ -26,7 +26,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -43,6 +42,8 @@ import org.eclipse.kapua.service.authorization.group.GroupQuery; import org.eclipse.kapua.service.authorization.group.GroupService; +import com.google.common.base.Strings; + @Path("{scopeId}/groups") public class Groups extends AbstractKapuaResource { @@ -54,16 +55,21 @@ public class Groups extends AbstractKapuaResource { /** * Gets the {@link Group} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link Group} name to filter results - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link Group} name to filter results + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link GroupListResult} of all the groups associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public GroupListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @@ -73,7 +79,7 @@ public GroupListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - GroupQuery query = groupFactory.newQuery(scopeId); + final GroupQuery query = new GroupQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -97,16 +103,19 @@ public GroupListResult simpleQuery( /** * Queries the results with the given {@link GroupQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link GroupQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link GroupQuery} to use to filter results. * @return The {@link GroupListResult} of all the result matching the given {@link GroupQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public GroupListResult query( @PathParam("scopeId") ScopeId scopeId, GroupQuery query) throws KapuaException { @@ -118,16 +127,19 @@ public GroupListResult query( /** * Counts the results with the given {@link GroupQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link GroupQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link GroupQuery} to use to filter results. * @return The count of all the result matching the given {@link GroupQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, GroupQuery query) throws KapuaException { @@ -137,16 +149,17 @@ public CountResult count( } /** - * Creates a new Group based on the information provided in GroupCreator - * parameter. + * Creates a new Group based on the information provided in GroupCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Group} - * @param groupCreator Provides the information for the new {@link Group} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Group} + * @param groupCreator + * Provides the information for the new {@link Group} to be created. * @return The newly created {@link Group} object. */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, GroupCreator groupCreator) throws KapuaException { @@ -158,15 +171,18 @@ public Response create( /** * Returns the Group specified by the "groupId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Group}. - * @param groupId The id of the requested Group. + * @param scopeId + * The {@link ScopeId} of the requested {@link Group}. + * @param groupId + * The id of the requested Group. * @return The requested Group object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{groupId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Group find( @PathParam("scopeId") ScopeId scopeId, @PathParam("groupId") EntityId groupId) throws KapuaException { @@ -178,17 +194,21 @@ public Group find( /** * Updates the Group based on the information provided in the Group parameter. * - * @param scopeId The ScopeId of the requested {@link Group}. - * @param groupId The id of the requested {@link Group} - * @param group The modified Group whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested {@link Group}. + * @param groupId + * The id of the requested {@link Group} + * @param group + * The modified Group whose attributed need to be updated. * @return The updated group. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{groupId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Group update( @PathParam("scopeId") ScopeId scopeId, @PathParam("groupId") EntityId groupId, @@ -202,10 +222,13 @@ public Group update( /** * Deletes the Group specified by the "groupId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Group}. - * @param groupId The id of the Group to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Group}. + * @param groupId + * The id of the Group to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java index 4c0b6661783..812304a628d 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java @@ -23,7 +23,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.DateParam; @@ -31,6 +30,7 @@ import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaEntityAttributes; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; @@ -44,9 +44,10 @@ import org.eclipse.kapua.service.job.execution.JobExecutionService; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; +import com.google.common.base.Strings; + @Path("{scopeId}/jobs/{jobId}/executions") public class JobExecutions extends AbstractKapuaResource { @@ -62,19 +63,27 @@ public class JobExecutions extends AbstractKapuaResource { /** * Gets the {@link JobExecution} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param jobId The {@link Job} id to filter results - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param jobId + * The {@link Job} id to filter results + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link JobExecutionListResult} of all the jobs executions associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobExecutionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -85,7 +94,7 @@ public JobExecutionListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobExecutionQuery query = jobExecutionFactory.newQuery(scopeId); + JobExecutionQuery query = new JobExecutionQuery(scopeId); AndPredicate andPredicate = query.andPredicate(query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId)); @@ -112,24 +121,27 @@ public JobExecutionListResult simpleQuery( /** * Queries the results with the given {@link JobExecutionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobExecutionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link JobExecutionQuery} to use to filter results. * @return The {@link JobExecutionListResult} of all the result matching the given {@link JobExecutionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobExecutionListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, JobExecutionQuery query) throws KapuaException { query.setScopeId(scopeId); final AndPredicate andPredicate = query.andPredicate( - query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId), - query.getPredicate() + query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId), + query.getPredicate() ); query.setPredicate(andPredicate); return jobExecutionService.query(query); @@ -138,16 +150,19 @@ public JobExecutionListResult query( /** * Counts the results with the given {@link JobExecutionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobExecutionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link JobExecutionQuery} to use to filter results. * @return The count of all the result matching the given {@link JobExecutionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -161,21 +176,25 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param jobId The id of the requested Job. - * @param executionId The id of the requested JobExecution. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param jobId + * The id of the requested Job. + * @param executionId + * The id of the requested JobExecution. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{executionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobExecution find( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("executionId") EntityId executionId) throws KapuaException { - JobExecutionQuery jobExecutionQuery = jobExecutionFactory.newQuery(scopeId); + JobExecutionQuery jobExecutionQuery = new JobExecutionQuery(scopeId); jobExecutionQuery.setPredicate(jobExecutionQuery.andPredicate( jobExecutionQuery.attributePredicate(JobExecutionAttributes.JOB_ID, jobId), jobExecutionQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, executionId) @@ -189,7 +208,7 @@ public JobExecution find( @GET @Path("{executionId}/targets") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobTargetListResult executionsByTarget( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -197,7 +216,7 @@ public JobTargetListResult executionsByTarget( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { JobExecution jobExecution = jobExecutionService.find(scopeId, executionId); - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate(jobTargetQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, jobExecution.getTargetIds())); jobTargetQuery.setLimit(limit); jobTargetQuery.setOffset(offset); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobStepDefinitions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobStepDefinitions.java index d6109fb64e3..fe5071c9ff1 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobStepDefinitions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobStepDefinitions.java @@ -12,34 +12,35 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.job.Job; import org.eclipse.kapua.service.job.step.JobStep; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionListResult; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; +import com.google.common.base.Strings; @Path("{scopeId}/jobStepDefinitions") public class JobStepDefinitions extends AbstractKapuaResource { @@ -52,17 +53,23 @@ public class JobStepDefinitions extends AbstractKapuaResource { /** * Gets the {@link JobStep} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link JobStepListResult} of all the jobs jobSteps associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobStepDefinitionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("sortParam") String sortParam, @@ -70,7 +77,7 @@ public JobStepDefinitionListResult simpleQuery( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobStepDefinitionQuery query = jobStepDefinitionFactory.newQuery(scopeId); + JobStepDefinitionQuery query = new JobStepDefinitionQuery(scopeId); if (!Strings.isNullOrEmpty(sortParam)) { query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir)); @@ -83,18 +90,21 @@ public JobStepDefinitionListResult simpleQuery( } /** - * Queries the results with the given {@link JobStepQuery} parameter. + * Queries the results with the given {@link JobStepDefinitionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobStepQuery} to use to filter results. - * @return The {@link JobStepListResult} of all the result matching the given {@link JobStepQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link JobStepDefinitionQuery} to use to filter results. + * @return The {@link JobStepListResult} of all the result matching the given {@link JobStepDefinitionQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobStepDefinitionListResult query( @PathParam("scopeId") ScopeId scopeId, JobStepDefinitionQuery query) throws KapuaException { @@ -104,21 +114,24 @@ public JobStepDefinitionListResult query( } /** - * Counts the results with the given {@link JobStepQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobStepQuery} to use to filter results. - * @return The count of all the result matching the given {@link JobStepQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, - JobStepQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); return new CountResult(jobStepDefinitionService.count(query)); @@ -127,15 +140,18 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param stepDefinitionId The id of the requested JobStep. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param stepDefinitionId + * The id of the requested JobStep. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @GET @Path("{stepDefinitionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobStepDefinition find( @PathParam("scopeId") ScopeId scopeId, @PathParam("stepDefinitionId") EntityId stepDefinitionId) throws KapuaException { diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobSteps.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobSteps.java index e545f351bcd..cec577c28e3 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobSteps.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobSteps.java @@ -12,13 +12,27 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaNamedEntityAttributes; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.QueryPredicate; @@ -29,22 +43,9 @@ import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepFactory; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/jobs/{jobId}/steps") public class JobSteps extends AbstractKapuaResource { @@ -57,20 +58,29 @@ public class JobSteps extends AbstractKapuaResource { /** * Gets the {@link JobStep} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param jobId The {@link Job} id to filter results - * @param name The name of the {@link JobStep} to filter result - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param jobId + * The {@link Job} id to filter results + * @param name + * The name of the {@link JobStep} to filter result + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link JobStepListResult} of all the jobs jobSteps associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobStepListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -81,7 +91,7 @@ public JobStepListResult simpleQuery( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobStepQuery query = jobStepFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(query.attributePredicate(JobStepAttributes.JOB_ID, jobId)); @@ -103,22 +113,25 @@ public JobStepListResult simpleQuery( } /** - * Queries the results with the given {@link JobStepQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobStepQuery} to use to filter results. - * @return The {@link JobStepListResult} of all the result matching the given {@link JobStepQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link JobStepListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobStepListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - JobStepQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); QueryPredicate predicate; if (query.getPredicate() != null) { @@ -131,22 +144,25 @@ public JobStepListResult query( } /** - * Counts the results with the given {@link JobStepQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobStepQuery} to use to filter results. - * @return The count of all the result matching the given {@link JobStepQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - JobStepQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(JobStepAttributes.JOB_ID, jobId)); @@ -156,16 +172,20 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param jobId The id of the requested Job. - * @param stepId The id of the requested JobStep. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param jobId + * The id of the requested Job. + * @param stepId + * The id of the requested JobStep. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{stepId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobStep find( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -174,19 +194,22 @@ public JobStep find( } /** - * Creates a new {@link JobStep} based on the information provided in {@link JobStepCreator} - * parameter. + * Creates a new {@link JobStep} based on the information provided in {@link JobStepCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link JobStep} - * @param jobId The ID of the {@link Job} to attach the {@link JobStep} to - * @param jobStepCreator Provides the information for the new {@link JobStep} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link JobStep} + * @param jobId + * The ID of the {@link Job} to attach the {@link JobStep} to + * @param jobStepCreator + * Provides the information for the new {@link JobStep} to be created. * @return The newly created {@link JobStep} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -197,21 +220,25 @@ public Response create( } /** - * Updates a new {@link JobStep} based on the information provided in {@link JobStep} - * parameter. + * Updates a new {@link JobStep} based on the information provided in {@link JobStep} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link JobStep} - * @param jobId The ID of the {@link Job} to attach the {@link JobStep} to - * @param jobStep Provides the information for the new {@link JobStep} to be created. - * @param jobStepId The ID of the {@link JobStep} to be updated + * @param scopeId + * The {@link ScopeId} in which to create the {@link JobStep} + * @param jobId + * The ID of the {@link Job} to attach the {@link JobStep} to + * @param jobStep + * Provides the information for the new {@link JobStep} to be created. + * @param jobStepId + * The ID of the {@link JobStep} to be updated * @return The newly created {@link JobStep} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @PUT @Path("{stepId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobStep update( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -226,10 +253,13 @@ public JobStep update( /** * Deletes the JobStep specified by the "stepId" path parameter. * - * @param scopeId The ScopeId of the requested {@link JobStep}. - * @param stepId The id of the JobStep to be deleted. + * @param scopeId + * The ScopeId of the requested {@link JobStep}. + * @param stepId + * The id of the JobStep to be deleted. * @return HTTP 201 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTargets.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTargets.java index 3e460bad8ee..d05800be133 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTargets.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTargets.java @@ -12,7 +12,19 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -20,6 +32,7 @@ import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; @@ -34,22 +47,10 @@ import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/jobs/{jobId}/targets") public class JobTargets extends AbstractKapuaResource { @@ -66,19 +67,27 @@ public class JobTargets extends AbstractKapuaResource { /** * Gets the {@link JobTarget} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param jobId The {@link Job} id to filter results - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param jobId + * The {@link Job} id to filter results + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link JobTargetListResult} of all the jobs targets associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobTargetListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -88,7 +97,7 @@ public JobTargetListResult simpleQuery( @QueryParam("askTotalCount") boolean askTotalCount, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobTargetQuery query = jobTargetFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId)); @@ -110,44 +119,50 @@ public JobTargetListResult simpleQuery( } /** - * Queries the results with the given {@link JobTargetQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobTargetQuery} to use to filter results. - * @return The {@link JobTargetListResult} of all the result matching the given {@link JobTargetQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link JobTargetListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobTargetListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - JobTargetQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(JobTargetAttributes.JOB_ID, jobId)); return jobTargetService.query(query); } /** - * Counts the results with the given {@link JobTargetQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobTargetQuery} to use to filter results. - * @return The count of all the result matching the given {@link JobTargetQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - JobTargetQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(JobTargetAttributes.JOB_ID, jobId)); @@ -157,21 +172,25 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param jobId The id of the requested Job. - * @param targetId The id of the requested JobTarget. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param jobId + * The id of the requested Job. + * @param targetId + * The id of the requested JobTarget. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{targetId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobTarget find( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("targetId") EntityId targetId) throws KapuaException { - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate(jobTargetQuery.andPredicate( jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, jobId), jobTargetQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, targetId) @@ -185,15 +204,15 @@ public JobTarget find( @GET @Path("{targetId}/executions") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobExecutionListResult executionsByTarget( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("targetId") EntityId targetId, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobExecutionQuery jobExecutionQuery = jobExecutionFactory.newQuery(scopeId); - jobExecutionQuery.setPredicate(jobExecutionQuery.attributePredicate(JobExecutionAttributes.TARGET_IDS, new KapuaId[]{targetId})); + JobExecutionQuery jobExecutionQuery = new JobExecutionQuery(scopeId); + jobExecutionQuery.setPredicate(jobExecutionQuery.attributePredicate(JobExecutionAttributes.TARGET_IDS, new KapuaId[] { targetId })); JobExecutionListResult jobExecutionListResult = jobExecutionService.query(jobExecutionQuery); jobExecutionQuery.setOffset(offset); @@ -203,20 +222,23 @@ public JobExecutionListResult executionsByTarget( } /** - * Creates a new {@link JobTarget} based on the information provided in {@link JobTargetCreator} - * parameter. + * Creates a new {@link JobTarget} based on the information provided in {@link JobTargetCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link JobTarget} - * @param jobId The ID of the {@link Job} to attach the {@link JobTarget} to - * @param jobTargetCreator Provides the information for the new {@link JobTarget} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link JobTarget} + * @param jobId + * The ID of the {@link Job} to attach the {@link JobTarget} to + * @param jobTargetCreator + * Provides the information for the new {@link JobTarget} to be created. * @return The newly created {@link JobTarget} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -230,10 +252,13 @@ public Response create( /** * Deletes the JobTarget specified by the "targetId" path parameter. * - * @param scopeId The ScopeId of the requested {@link JobTarget}. - * @param targetId The id of the JobTarget to be deleted. + * @param scopeId + * The ScopeId of the requested {@link JobTarget}. + * @param targetId + * The id of the JobTarget to be deleted. * @return HTTP 201 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggerDefinitions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggerDefinitions.java index c6c2bb867b2..ac33e964370 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggerDefinitions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggerDefinitions.java @@ -12,7 +12,17 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -27,16 +37,7 @@ import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; +import com.google.common.base.Strings; @Path("{scopeId}/triggerDefinitions") public class JobTriggerDefinitions extends AbstractKapuaResource { @@ -49,17 +50,23 @@ public class JobTriggerDefinitions extends AbstractKapuaResource { /** * Gets the {@link TriggerDefinition} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link TriggerDefinitionListResult} of all the jobs triggers associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TriggerDefinitionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("sortParam") String sortParam, @@ -67,7 +74,7 @@ public TriggerDefinitionListResult simpleQuery( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - TriggerDefinitionQuery query = triggerDefinitionFactory.newQuery(null); + TriggerDefinitionQuery query = new TriggerDefinitionQuery(); if (!Strings.isNullOrEmpty(sortParam)) { query.setSortCriteria(query.fieldSortCriteria(sortParam, sortDir)); @@ -82,16 +89,19 @@ public TriggerDefinitionListResult simpleQuery( /** * Queries the results with the given {@link TriggerDefinitionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TriggerDefinitionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link TriggerDefinitionQuery} to use to filter results. * @return The {@link TriggerDefinitionListResult} of all the result matching the given {@link TriggerDefinitionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public TriggerDefinitionListResult query( @PathParam("scopeId") ScopeId scopeId, TriggerDefinitionQuery query) throws KapuaException { @@ -102,16 +112,19 @@ public TriggerDefinitionListResult query( /** * Counts the results with the given {@link TriggerDefinitionQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TriggerDefinitionQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link TriggerDefinitionQuery} to use to filter results. * @return The count of all the result matching the given {@link TriggerDefinitionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, TriggerDefinitionQuery query) throws KapuaException { @@ -123,15 +136,18 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param triggerDefinitionId The id of the requested Trigger Definition. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param triggerDefinitionId + * The id of the requested Trigger Definition. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @GET @Path("{triggerDefinitionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TriggerDefinition find( @PathParam("scopeId") ScopeId scopeId, @PathParam("triggerDefinitionId") EntityId triggerDefinitionId) throws KapuaException { diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggers.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggers.java index 67a87649e15..56f86874ba6 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggers.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggers.java @@ -12,7 +12,24 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -21,6 +38,7 @@ import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.KapuaNamedEntityAttributes; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; @@ -32,26 +50,10 @@ import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerService; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.google.common.base.Strings; @Path("{scopeId}/jobs/{jobId}/triggers") public class JobTriggers extends AbstractKapuaResource { @@ -64,20 +66,29 @@ public class JobTriggers extends AbstractKapuaResource { /** * Gets the {@link Trigger} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param jobId The {@link Job} id to filter results - * @param name The name of the {@link Trigger} to filter result - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param jobId + * The {@link Job} id to filter results + * @param name + * The name of the {@link Trigger} to filter result + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link TriggerListResult} of all the jobs triggers associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TriggerListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -88,7 +99,7 @@ public TriggerListResult simpleQuery( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - TriggerQuery query = triggerFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(returnJobIdPredicate(jobId, query)); @@ -109,22 +120,25 @@ public TriggerListResult simpleQuery( } /** - * Queries the results with the given {@link TriggerQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TriggerQuery} to use to filter results. - * @return The {@link TriggerListResult} of all the result matching the given {@link TriggerQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link TriggerListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public TriggerListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - TriggerQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); QueryPredicate predicate; if (query.getPredicate() != null) { @@ -137,22 +151,25 @@ public TriggerListResult query( } /** - * Counts the results with the given {@link TriggerQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TriggerQuery} to use to filter results. - * @return The count of all the result matching the given {@link TriggerQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, - TriggerQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(returnJobIdPredicate(jobId, query)); @@ -162,21 +179,25 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param jobId The id of the requested Job. - * @param triggerId The id of the requested Trigger. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param jobId + * The id of the requested Job. + * @param triggerId + * The id of the requested Trigger. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{triggerId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Trigger find( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("triggerId") EntityId triggerId) throws KapuaException { - TriggerQuery triggerQuery = triggerFactory.newQuery(scopeId); + KapuaQuery triggerQuery = new KapuaQuery(scopeId); triggerQuery.setPredicate(triggerQuery.andPredicate( returnJobIdPredicate(jobId, triggerQuery), triggerQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, triggerId) @@ -188,7 +209,7 @@ public Trigger find( return returnNotNullEntity(triggerListResult.getFirstItem(), Trigger.TYPE, triggerId); } - private AndPredicate returnJobIdPredicate(KapuaId jobId, TriggerQuery query) { + private AndPredicate returnJobIdPredicate(KapuaId jobId, KapuaQuery query) { AttributePredicate kapuaPropertyNameAttributePredicate = query.attributePredicate(TriggerAttributes.TRIGGER_PROPERTIES_NAME, "jobId"); AttributePredicate kapuaPropertyValueAttributePredicate = query.attributePredicate(TriggerAttributes.TRIGGER_PROPERTIES_VALUE, jobId.toCompactId()); AttributePredicate kapuaPropertyTypeAttributePredicate = query.attributePredicate(TriggerAttributes.TRIGGER_PROPERTIES_TYPE, KapuaId.class.getName()); @@ -201,20 +222,23 @@ private AndPredicate returnJobIdPredicate(KapuaId jobId, TriggerQuery query) { } /** - * Creates a new {@link Trigger} based on the information provided in {@link TriggerCreator} - * parameter. + * Creates a new {@link Trigger} based on the information provided in {@link TriggerCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Trigger} - * @param triggerCreator Provides the information for the new {@link Trigger} to be created. - * @param jobId The ID of the {@link Job} to attach the {@link Trigger} to + * @param scopeId + * The {@link ScopeId} in which to create the {@link Trigger} + * @param triggerCreator + * Provides the information for the new {@link Trigger} to be created. + * @param jobId + * The ID of the {@link Job} to attach the {@link Trigger} to * @return The newly created {@link Trigger} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -225,29 +249,33 @@ public Response create( triggerProperties = new ArrayList<>(); triggerCreator.setTriggerProperties(triggerProperties); } - triggerProperties.removeIf(triggerProperty -> Arrays.stream(new String[]{"scopeId", "jobId"}).anyMatch(propertyToRemove -> propertyToRemove.equals(triggerProperty.getName()))); + triggerProperties.removeIf(triggerProperty -> Arrays.stream(new String[] { "scopeId", "jobId" }).anyMatch(propertyToRemove -> propertyToRemove.equals(triggerProperty.getName()))); triggerProperties.add(triggerFactory.newTriggerProperty("scopeId", KapuaId.class.getCanonicalName(), scopeId.toCompactId())); triggerProperties.add(triggerFactory.newTriggerProperty("jobId", KapuaId.class.getCanonicalName(), jobId.toCompactId())); return returnCreated(triggerService.create(triggerCreator)); } /** - * Updates a {@link Trigger} based on the information provided in the provided {@link Trigger} - * parameter. + * Updates a {@link Trigger} based on the information provided in the provided {@link Trigger} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Trigger} - * @param triggerId The ID of the {@link Trigger} to update - * @param trigger Provides the information for the new {@link Trigger} to be updated. - * @param jobId The ID of the {@link Job} to attach the {@link Trigger} to + * @param scopeId + * The {@link ScopeId} in which to create the {@link Trigger} + * @param triggerId + * The ID of the {@link Trigger} to update + * @param trigger + * Provides the information for the new {@link Trigger} to be updated. + * @param jobId + * The ID of the {@link Job} to attach the {@link Trigger} to * @return The updated {@link Trigger} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @PUT @Path("{triggerId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Trigger update( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -258,7 +286,7 @@ public Trigger update( triggerProperties = new ArrayList<>(); trigger.setTriggerProperties(triggerProperties); } - triggerProperties.removeIf(triggerProperty -> Arrays.stream(new String[]{"scopeId", "jobId"}).anyMatch(propertyToRemove -> propertyToRemove.equals(triggerProperty.getName()))); + triggerProperties.removeIf(triggerProperty -> Arrays.stream(new String[] { "scopeId", "jobId" }).anyMatch(propertyToRemove -> propertyToRemove.equals(triggerProperty.getName()))); triggerProperties.add(triggerFactory.newTriggerProperty("scopeId", KapuaId.class.getCanonicalName(), scopeId.toCompactId())); triggerProperties.add(triggerFactory.newTriggerProperty("jobId", KapuaId.class.getCanonicalName(), jobId.toCompactId())); trigger.setScopeId(scopeId); @@ -269,10 +297,13 @@ public Trigger update( /** * Deletes the Trigger specified by the "triggerId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Trigger}. - * @param triggerId The id of the Trigger to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Trigger}. + * @param triggerId + * The id of the Trigger to be deleted. * @return HTTP 201 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggersFired.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggersFired.java index 120501db918..45107a0d5c8 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggersFired.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobTriggersFired.java @@ -12,11 +12,23 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; @@ -25,21 +37,9 @@ import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerAttributes; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerFactory; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerService; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerStatus; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - @Path("{scopeId}/jobs/{jobId}/triggers/{triggerId}/fired") public class JobTriggersFired extends AbstractKapuaResource { @@ -51,17 +51,23 @@ public class JobTriggersFired extends AbstractKapuaResource { /** * Gets the {@link Trigger} list for a given {@link Job}. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param jobId The {@link Job} id to filter results. - * @param offset The result set offset. - * @param limit The result set limit. - * @param askTotalCount Whether or not to fetch the total count of elements. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param jobId + * The {@link Job} id to filter results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. + * @param askTotalCount + * Whether or not to fetch the total count of elements. * @return The {@link FiredTriggerListResult} of all the jobs triggers associated to the current selected job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public FiredTriggerListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -71,7 +77,7 @@ public FiredTriggerListResult simpleQuery( @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - FiredTriggerQuery query = firedTriggerFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(FiredTriggerAttributes.TRIGGER_ID, triggerId) @@ -92,23 +98,26 @@ public FiredTriggerListResult simpleQuery( } /** - * Queries the results with the given {@link FiredTriggerQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link FiredTriggerQuery} to use to filter results. - * @return The {@link FiredTriggerListResult} of all the result matching the given {@link FiredTriggerQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link FiredTriggerListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public FiredTriggerListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("triggerId") EntityId triggerId, - FiredTriggerQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); AndPredicate andPredicate = query.andPredicate( @@ -125,23 +134,26 @@ public FiredTriggerListResult query( } /** - * Counts the results with the given {@link FiredTriggerQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link FiredTriggerQuery} to use to filter results. - * @return The count of all the result matching the given {@link FiredTriggerQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @PathParam("triggerId") EntityId triggerId, - FiredTriggerQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); AndPredicate andPredicate = query.andPredicate( diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Jobs.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Jobs.java index 093e92a473e..59d626b7cb1 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Jobs.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Jobs.java @@ -12,7 +12,20 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -29,19 +42,7 @@ import org.eclipse.kapua.service.job.JobQuery; import org.eclipse.kapua.service.job.JobService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/jobs") public class Jobs extends AbstractKapuaResource { @@ -54,19 +55,27 @@ public class Jobs extends AbstractKapuaResource { /** * Gets the {@link Job} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link Job} name to filter results - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link Job} name to filter results + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link JobListResult} of all the jobs associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public JobListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @@ -76,7 +85,7 @@ public JobListResult simpleQuery( @QueryParam("askTotalCount") boolean askTotalCount, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - JobQuery query = jobFactory.newQuery(scopeId); + JobQuery query = new JobQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -101,16 +110,19 @@ public JobListResult simpleQuery( /** * Queries the results with the given {@link JobQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link JobQuery} to use to filter results. * @return The {@link JobListResult} of all the result matching the given {@link JobQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public JobListResult query( @PathParam("scopeId") ScopeId scopeId, JobQuery query) throws KapuaException { @@ -122,16 +134,19 @@ public JobListResult query( /** * Counts the results with the given {@link JobQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link JobQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link JobQuery} to use to filter results. * @return The count of all the result matching the given {@link JobQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, JobQuery query) throws KapuaException { @@ -143,15 +158,18 @@ public CountResult count( /** * Returns the Job specified by the "jobId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Job}. - * @param jobId The id of the requested Job. + * @param scopeId + * The {@link ScopeId} of the requested {@link Job}. + * @param jobId + * The id of the requested Job. * @return The requested Job object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{jobId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Job find( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId) throws KapuaException { @@ -161,18 +179,20 @@ public Job find( } /** - * Creates a new {@link Job} based on the information provided in {@link JobCreator} - * parameter. + * Creates a new {@link Job} based on the information provided in {@link JobCreator} parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Job} - * @param jobCreator Provides the information for the new {@link Job} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Job} + * @param jobCreator + * Provides the information for the new {@link Job} to be created. * @return The newly created {@link Job} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, JobCreator jobCreator) throws KapuaException { @@ -184,17 +204,21 @@ public Response create( /** * Updates the Job based on the information provided in the Job parameter. * - * @param scopeId The ScopeId of the requested {@link Job}. - * @param jobId The id of the requested {@link Job} - * @param job The modified Job whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested {@link Job}. + * @param jobId + * The id of the requested {@link Job} + * @param job + * The modified Job whose attributed need to be updated. * @return The updated job. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @PUT @Path("{jobId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Job update( @PathParam("scopeId") ScopeId scopeId, @PathParam("jobId") EntityId jobId, @@ -208,10 +232,13 @@ public Job update( /** * Deletes the Job specified by the "jobId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Job}. - * @param jobId The id of the Job to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Job}. + * @param jobId + * The id of the Job to be deleted. * @return HTTP 201 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.5.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java index a1e453f87ad..aa5f47a175a 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Roles.java @@ -13,6 +13,7 @@ package org.eclipse.kapua.app.api.resources.v1.resources; import java.util.List; + import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -27,7 +28,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -51,6 +51,8 @@ import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; +import com.google.common.base.Strings; + @Path("{scopeId}/roles") public class Roles extends AbstractKapuaResource { @@ -66,16 +68,21 @@ public class Roles extends AbstractKapuaResource { /** * Gets the {@link Role} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link Role} name in which to search results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link Role} name in which to search results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link RoleListResult} of all the roles associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public RoleListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @@ -85,7 +92,7 @@ public RoleListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - RoleQuery query = roleFactory.newQuery(scopeId); + RoleQuery query = new RoleQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -109,16 +116,19 @@ public RoleListResult simpleQuery( /** * Queries the results with the given {@link RoleQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link RoleQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link RoleQuery} to use to filter results. * @return The {@link RoleListResult} of all the result matching the given {@link RoleQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public RoleListResult query( @PathParam("scopeId") ScopeId scopeId, RoleQuery query) throws KapuaException { @@ -130,16 +140,19 @@ public RoleListResult query( /** * Counts the results with the given {@link RoleQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link RoleQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link RoleQuery} to use to filter results. * @return The count of all the result matching the given {@link RoleQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, RoleQuery query) throws KapuaException { @@ -149,18 +162,20 @@ public CountResult count( } /** - * Creates a new Role based on the information provided in RoleCreator - * parameter. + * Creates a new Role based on the information provided in RoleCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Role} - * @param roleCreator Provides the information for the new {@link Role} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Role} + * @param roleCreator + * Provides the information for the new {@link Role} to be created. * @return The newly created {@link Role} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, RoleCreator roleCreator) throws KapuaException { @@ -172,15 +187,18 @@ public Response create( /** * Returns the Role specified by the "roleId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Role}. - * @param roleId The id of the requested {@link Role}. + * @param scopeId + * The {@link ScopeId} of the requested {@link Role}. + * @param roleId + * The id of the requested {@link Role}. * @return The requested {@link Role} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{roleId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Role find( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId) throws KapuaException { @@ -192,17 +210,21 @@ public Role find( /** * Updates the Role based on the information provided in the Role parameter. * - * @param scopeId The ScopeId of the requested {@link Role}. - * @param roleId The id of the requested {@link Role} - * @param role The modified Role whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested {@link Role}. + * @param roleId + * The id of the requested {@link Role} + * @param role + * The modified Role whose attributed need to be updated. * @return The updated {@link Role}. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{roleId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Role update( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, @@ -216,10 +238,13 @@ public Role update( /** * Deletes the Role specified by the "roleId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Role}. - * @param roleId The id of the Role to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Role}. + * @param roleId + * The id of the Role to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE @@ -235,14 +260,21 @@ public Response deleteRole( /** * Gets all the {@link User}s for a given {@link Role} * - * @param scopeId The ScopeId of the requested {@link Role}. - * @param roleId The id of the Role to be deleted. - * @param offset The result set offset. - * @param limit The result set limit. - * @param sortParam The name of the parameter that will be used as a sorting key for the users - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param scopeId + * The ScopeId of the requested {@link Role}. + * @param roleId + * The id of the Role to be deleted. + * @param offset + * The result set offset. + * @param limit + * The result set limit. + * @param sortParam + * The name of the parameter that will be used as a sorting key for the users + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. * @return An {@link UserListResult} containing the {@link User}s for the given {@link Role} - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.2.0 */ @GET @@ -256,7 +288,7 @@ public UserListResult usersForRole( @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { List usersIds = roleService.userIdsByRoleId(scopeId, roleId); - UserQuery userQuery = userFactory.newQuery(scopeId); + UserQuery userQuery = new UserQuery(scopeId); userQuery.setPredicate(userQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, usersIds)); userQuery.setLimit(limit); userQuery.setOffset(offset); diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/RolesPermissions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/RolesPermissions.java index 04ad770ba77..997a23f4819 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/RolesPermissions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/RolesPermissions.java @@ -12,7 +12,19 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -20,6 +32,7 @@ import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.domain.Actions; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; @@ -29,21 +42,9 @@ import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/roles/{roleId}/permissions") public class RolesPermissions extends AbstractKapuaResource { @@ -56,20 +57,29 @@ public class RolesPermissions extends AbstractKapuaResource { /** * Gets the {@link RolePermission} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param roleId The id of the {@link Role} in which to search results. - * @param domain The domain name to filter results. - * @param action The action to filter results. - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param roleId + * The id of the {@link Role} in which to search results. + * @param domain + * The domain name to filter results. + * @param action + * The action to filter results. + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link RolePermissionListResult} of all the rolePermissions associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public RolePermissionListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, @@ -80,7 +90,7 @@ public RolePermissionListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - RolePermissionQuery query = rolePermissionFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); query.setPredicate(query.attributePredicate(RolePermissionAttributes.ROLE_ID, roleId)); @@ -103,23 +113,27 @@ public RolePermissionListResult simpleQuery( } /** - * Queries the results with the given {@link RolePermissionQuery} parameter. + * Queries the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param roleId The {@link Role} id in which to search results. - * @param query The {@link RolePermissionQuery} to use to filter results. - * @return The {@link RolePermissionListResult} of all the result matching the given {@link RolePermissionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param roleId + * The {@link Role} id in which to search results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The {@link RolePermissionListResult} of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public RolePermissionListResult query( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, - RolePermissionQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); AndPredicate andPredicate = query.andPredicate(); @@ -133,23 +147,27 @@ public RolePermissionListResult query( } /** - * Counts the results with the given {@link RolePermissionQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to count results. - * @param roleId The {@link Role} id in which to count results. - * @param query The {@link RolePermissionQuery} to use to filter results. - * @return The count of all the result matching the given {@link RolePermissionQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to count results. + * @param roleId + * The {@link Role} id in which to count results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, - RolePermissionQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { query.setScopeId(scopeId); query.setPredicate(query.attributePredicate(RolePermissionAttributes.ROLE_ID, roleId)); @@ -157,19 +175,22 @@ public CountResult count( } /** - * Creates a new RolePermission based on the information provided in RolePermissionCreator - * parameter. + * Creates a new RolePermission based on the information provided in RolePermissionCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link RolePermission} - * @param roleId The {@link Role} id in which to create the RolePermission. - * @param rolePermissionCreator Provides the information for the new RolePermission to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link RolePermission} + * @param roleId + * The {@link Role} id in which to create the RolePermission. + * @param rolePermissionCreator + * Provides the information for the new RolePermission to be created. * @return The newly created RolePermission object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, @@ -183,21 +204,25 @@ public Response create( /** * Returns the RolePermission specified by the "rolePermissionId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link RolePermission}. - * @param roleId The {@link Role} id of the requested {@link RolePermission}. - * @param rolePermissionId The id of the requested RolePermission. + * @param scopeId + * The {@link ScopeId} of the requested {@link RolePermission}. + * @param roleId + * The {@link Role} id of the requested {@link RolePermission}. + * @param rolePermissionId + * The id of the requested RolePermission. * @return The requested RolePermission object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{rolePermissionId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public RolePermission find( @PathParam("scopeId") ScopeId scopeId, @PathParam("roleId") EntityId roleId, @PathParam("rolePermissionId") EntityId rolePermissionId) throws KapuaException { - RolePermissionQuery query = rolePermissionFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(RolePermissionAttributes.ROLE_ID, roleId), @@ -216,11 +241,15 @@ public RolePermission find( /** * Deletes the RolePermission specified by the "rolePermissionId" path parameter. * - * @param scopeId The {@link ScopeId} of the {@link RolePermission} to delete. - * @param roleId The {@link Role} id of the {@link RolePermission} to delete. - * @param rolePermissionId The id of the RolePermission to be deleted. + * @param scopeId + * The {@link ScopeId} of the {@link RolePermission} to delete. + * @param roleId + * The {@link Role} id of the {@link RolePermission} to delete. + * @param rolePermissionId + * The id of the RolePermission to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java index c09e9c34a17..2e288e42b01 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Tags.java @@ -26,7 +26,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -43,6 +42,8 @@ import org.eclipse.kapua.service.tag.TagQuery; import org.eclipse.kapua.service.tag.TagService; +import com.google.common.base.Strings; + @Path("{scopeId}/tags") public class Tags extends AbstractKapuaResource { @@ -54,17 +55,22 @@ public class Tags extends AbstractKapuaResource { /** * Gets the {@link Tag} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link Tag} name to filter results - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link Tag} name to filter results + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link TagListResult} of all the tags associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TagListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @@ -74,7 +80,7 @@ public TagListResult simpleQuery( @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - TagQuery query = tagFactory.newQuery(scopeId); + TagQuery query = new TagQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -98,17 +104,20 @@ public TagListResult simpleQuery( /** * Queries the results with the given {@link TagQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TagQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link TagQuery} to use to filter results. * @return The {@link TagListResult} of all the result matching the given {@link TagQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public TagListResult query( @PathParam("scopeId") ScopeId scopeId, TagQuery query) throws KapuaException { @@ -120,17 +129,20 @@ public TagListResult query( /** * Counts the results with the given {@link TagQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link TagQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link TagQuery} to use to filter results. * @return The count of all the result matching the given {@link TagQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, TagQuery query) throws KapuaException { @@ -140,19 +152,21 @@ public CountResult count( } /** - * Creates a new Tag based on the information provided in TagCreator - * parameter. + * Creates a new Tag based on the information provided in TagCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Tag} - * @param tagCreator Provides the information for the new {@link Tag} to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Tag} + * @param tagCreator + * Provides the information for the new {@link Tag} to be created. * @return The newly created {@link Tag} object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, TagCreator tagCreator) throws KapuaException { @@ -164,16 +178,19 @@ public Response create( /** * Returns the Tag specified by the "tagId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link Tag}. - * @param tagId The id of the requested Tag. + * @param scopeId + * The {@link ScopeId} of the requested {@link Tag}. + * @param tagId + * The id of the requested Tag. * @return The requested Tag object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{tagId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Tag find( @PathParam("scopeId") ScopeId scopeId, @PathParam("tagId") EntityId tagId) throws KapuaException { @@ -185,18 +202,22 @@ public Tag find( /** * Updates the Tag based on the information provided in the Tag parameter. * - * @param scopeId The ScopeId of the requested {@link Tag}. - * @param tagId The id of the requested {@link Tag} - * @param tag The modified Tag whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested {@link Tag}. + * @param tagId + * The id of the requested {@link Tag} + * @param tag + * The modified Tag whose attributed need to be updated. * @return The updated tag. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{tagId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Tag update( @PathParam("scopeId") ScopeId scopeId, @PathParam("tagId") EntityId tagId, @@ -210,10 +231,13 @@ public Tag update( /** * Deletes the Tag specified by the "tagId" path parameter. * - * @param scopeId The ScopeId of the requested {@link Tag}. - * @param tagId The id of the Tag to be deleted. + * @param scopeId + * The ScopeId of the requested {@link Tag}. + * @param tagId + * The id of the Tag to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Users.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Users.java index 0da1215e9ce..597b6a0cdcd 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Users.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Users.java @@ -12,7 +12,20 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; -import com.google.common.base.Strings; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; @@ -29,19 +42,7 @@ import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import com.google.common.base.Strings; @Path("{scopeId}/users") public class Users extends AbstractKapuaResource { @@ -54,20 +55,29 @@ public class Users extends AbstractKapuaResource { /** * Gets the {@link User} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param name The {@link User} name in which to search results. - * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. - * @param matchTerm A term to be matched in at least one of the configured fields of this entity - * @param askTotalCount Ask for the total count of the matched entities in the result - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param name + * The {@link User} name in which to search results. + * @param sortParam + * The name of the parameter that will be used as a sorting key + * @param sortDir + * The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. + * @param matchTerm + * A term to be matched in at least one of the configured fields of this entity + * @param askTotalCount + * Ask for the total count of the matched entities in the result + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link UserListResult} of all the users associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public UserListResult simpleQuery( @PathParam("scopeId") ScopeId scopeId, @QueryParam("name") String name, @@ -77,7 +87,7 @@ public UserListResult simpleQuery( @QueryParam("askTotalCount") boolean askTotalCount, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - UserQuery query = userFactory.newQuery(scopeId); + UserQuery query = new UserQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); if (!Strings.isNullOrEmpty(name)) { @@ -102,16 +112,19 @@ public UserListResult simpleQuery( /** * Queries the results with the given {@link UserQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param query The {@link UserQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param query + * The {@link UserQuery} to use to filter results. * @return The {@link UserListResult} of all the result matching the given {@link UserQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_query") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public UserListResult query( @PathParam("scopeId") ScopeId scopeId, UserQuery query) throws KapuaException { @@ -123,16 +136,19 @@ public UserListResult query( /** * Counts the results with the given {@link UserQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to count results. - * @param query The {@link UserQuery} to use to filter results. + * @param scopeId + * The {@link ScopeId} in which to count results. + * @param query + * The {@link UserQuery} to use to filter results. * @return The count of all the result matching the given {@link UserQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, UserQuery query) throws KapuaException { @@ -142,18 +158,20 @@ public CountResult count( } /** - * Creates a new User based on the information provided in UserCreator - * parameter. + * Creates a new User based on the information provided in UserCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link User} - * @param userCreator Provides the information for the new User to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link User} + * @param userCreator + * Provides the information for the new User to be created. * @return The newly created User object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, UserCreator userCreator) throws KapuaException { @@ -165,15 +183,18 @@ public Response create( /** * Returns the User specified by the "userId" path parameter. * - * @param scopeId The {@link ScopeId} of the requested {@link User}. - * @param userId The id of the requested User. + * @param scopeId + * The {@link ScopeId} of the requested {@link User}. + * @param userId + * The id of the requested User. * @return The requested User object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET @Path("{userId}") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public User find( @PathParam("scopeId") ScopeId scopeId, @PathParam("userId") EntityId userId) throws KapuaException { @@ -185,17 +206,21 @@ public User find( /** * Updates the User based on the information provided in the User parameter. * - * @param scopeId The ScopeId of the requested {@link User}. - * @param userId The id of the requested {@link User} - * @param user The modified User whose attributed need to be updated. + * @param scopeId + * The ScopeId of the requested {@link User}. + * @param userId + * The id of the requested {@link User} + * @param user + * The modified User whose attributed need to be updated. * @return The updated user. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @PUT @Path("{userId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public User update( @PathParam("scopeId") ScopeId scopeId, @PathParam("userId") EntityId userId, @@ -209,10 +234,13 @@ public User update( /** * Deletes the User specified by the "userId" path parameter. * - * @param scopeId The ScopeId of the requested {@link User}. - * @param userId The id of the User to be deleted. + * @param scopeId + * The ScopeId of the requested {@link User}. + * @param userId + * The id of the User to be deleted. * @return HTTP 200 if operation has completed successfully. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @DELETE diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/UsersCredentials.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/UsersCredentials.java index 3b3bc9d3597..4537e7df5a9 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/UsersCredentials.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/UsersCredentials.java @@ -12,11 +12,24 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.CountResult; import org.eclipse.kapua.app.api.core.model.EntityId; import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.authentication.credential.Credential; @@ -24,22 +37,9 @@ import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.user.PasswordResetRequest; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - /* @deprecated accidentally exposed under: @@ -59,22 +59,27 @@ public class UsersCredentials extends AbstractKapuaResource { /** * Gets the {@link Credential} list in the scope. * - * @param scopeId The {@link ScopeId} in which to search results. - * @param userId The {@link EntityId} for which search results. - * @param offset The result set offset. - * @param limit The result set limit. + * @param scopeId + * The {@link ScopeId} in which to search results. + * @param userId + * The {@link EntityId} for which search results. + * @param offset + * The result set offset. + * @param limit + * The result set limit. * @return The {@link CredentialListResult} of all the credentials associated to the current selected scope. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public CredentialListResult getAll( @PathParam("scopeId") ScopeId scopeId, @PathParam("userId") EntityId userId, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { - CredentialQuery query = credentialFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(CredentialAttributes.USER_ID, userId)); @@ -86,25 +91,28 @@ public CredentialListResult getAll( return credentialService.query(query); } - /** - * Counts the results with the given {@link CredentialQuery} parameter. + * Counts the results with the given {@link KapuaQuery} parameter. * - * @param scopeId The {@link ScopeId} in which to count results. - * @param userId The {@link EntityId} for which count results. - * @param query The {@link CredentialQuery} to use to filter results. - * @return The count of all the result matching the given {@link CredentialQuery} parameter. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @param scopeId + * The {@link ScopeId} in which to count results. + * @param userId + * The {@link EntityId} for which count results. + * @param query + * The {@link KapuaQuery} to use to filter results. + * @return The count of all the result matching the given {@link KapuaQuery} parameter. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST @Path("_count") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @PathParam("scopeId") ScopeId scopeId, @PathParam("userId") EntityId userId, - CredentialQuery query) throws KapuaException { + KapuaQuery query) throws KapuaException { AndPredicate andPredicate = query.andPredicate(); andPredicate.and(query.attributePredicate(CredentialAttributes.USER_ID, userId)); query.setPredicate(andPredicate); @@ -112,21 +120,23 @@ public CountResult count( return new CountResult(credentialService.count(query)); } - /** - * Creates a new Credential based on the information provided in CredentialCreator - * parameter. + * Creates a new Credential based on the information provided in CredentialCreator parameter. * - * @param scopeId The {@link ScopeId} in which to create the {@link Credential}. - * @param userId The {@link EntityId} for which create the {@link Credential}. - * @param credentialCreator Provides the information for the new Credential to be created. + * @param scopeId + * The {@link ScopeId} in which to create the {@link Credential}. + * @param userId + * The {@link EntityId} for which create the {@link Credential}. + * @param credentialCreator + * Provides the information for the new Credential to be created. * @return The newly created Credential object. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @POST - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response create( @PathParam("scopeId") ScopeId scopeId, @PathParam("userId") EntityId userId, @@ -140,11 +150,15 @@ public Response create( /** * Reset the password for the specific user * - * @param scopeId The {@link ScopeId} of the {@link Credential} to reset. - * @param userId The {@link EntityId} for which to reset the password credential. - * @param passwordResetRequest Request for resetting credential password + * @param scopeId + * The {@link ScopeId} of the {@link Credential} to reset. + * @param userId + * The {@link EntityId} for which to reset the password credential. + * @param passwordResetRequest + * Request for resetting credential password * @return The updated credential. - * @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions. + * @throws KapuaException + * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 2.0.0 * @deprecated since 2.0.0 - use POST POST /{scopeId}/users/{userId}/password/_reset instead (see {@link UsersCredentials}) */ diff --git a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java index 0203a1f1c31..2bb3fa39ee8 100644 --- a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java +++ b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java @@ -81,7 +81,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountListResult; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountUpdateRequest; import org.eclipse.kapua.service.account.CurrentAccountUpdateRequest; import org.eclipse.kapua.service.account.xml.AccountParentPathXmlAdapter; @@ -95,13 +94,11 @@ import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialType; import org.eclipse.kapua.service.authentication.credential.CredentialXmlRegistry; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionCreator; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionListResult; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionQuery; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionXmlRegistry; import org.eclipse.kapua.service.authentication.credential.mfa.ScratchCode; import org.eclipse.kapua.service.authentication.credential.mfa.ScratchCodeListResult; @@ -114,22 +111,17 @@ import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoXmlRegistry; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionXmlRegistry; import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleXmlRegistry; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; -import org.eclipse.kapua.service.authorization.domain.DomainXmlRegistry; import org.eclipse.kapua.service.authorization.group.Group; import org.eclipse.kapua.service.authorization.group.GroupCreator; import org.eclipse.kapua.service.authorization.group.GroupListResult; @@ -142,7 +134,6 @@ import org.eclipse.kapua.service.authorization.role.RolePermission; import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionXmlRegistry; import org.eclipse.kapua.service.authorization.role.RoleQuery; import org.eclipse.kapua.service.authorization.role.RoleXmlRegistry; @@ -285,7 +276,6 @@ import org.eclipse.kapua.service.job.step.JobStep; import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepXmlRegistry; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionListResult; @@ -295,11 +285,9 @@ import org.eclipse.kapua.service.job.targets.JobTarget; import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.scheduler.trigger.Trigger; import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerXmlRegistry; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionListResult; @@ -308,7 +296,6 @@ import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTrigger; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerXmlRegistry; import org.eclipse.kapua.service.storable.model.id.StorableId; import org.eclipse.kapua.service.storable.model.query.SortField; @@ -410,7 +397,6 @@ public JAXBContext getJAXBContext() throws KapuaException { Account.class, AccountCreator.class, AccountListResult.class, - AccountQuery.class, AccountParentPathXmlAdapter.class, AccountXmlRegistry.class, @@ -608,14 +594,12 @@ public JAXBContext getJAXBContext() throws KapuaException { CredentialListResult.class, CredentialCreator.class, CredentialType.class, - CredentialQuery.class, CredentialXmlRegistry.class, // Multi Factor Authentication MfaOption.class, MfaOptionListResult.class, MfaOptionCreator.class, - MfaOptionQuery.class, MfaOptionXmlRegistry.class, ScratchCode.class, ScratchCodeListResult.class, @@ -643,14 +627,11 @@ public JAXBContext getJAXBContext() throws KapuaException { RolePermission.class, RolePermissionListResult.class, RolePermissionCreator.class, - RolePermissionQuery.class, RolePermissionXmlRegistry.class, // Domains Domain.class, DomainListResult.class, - DomainQuery.class, - DomainXmlRegistry.class, // Groups Group.class, @@ -663,21 +644,18 @@ public JAXBContext getJAXBContext() throws KapuaException { AccessInfo.class, AccessInfoListResult.class, AccessInfoCreator.class, - AccessInfoQuery.class, AccessInfoXmlRegistry.class, // Access Permissions AccessPermission.class, AccessPermissionListResult.class, AccessPermissionCreator.class, - AccessPermissionQuery.class, AccessPermissionXmlRegistry.class, // Access Roles AccessRole.class, AccessRoleListResult.class, AccessRoleCreator.class, - AccessRoleQuery.class, AccessRoleXmlRegistry.class, // System Info @@ -734,7 +712,6 @@ public JAXBContext getJAXBContext() throws KapuaException { JobStep.class, JobStepCreator.class, JobStepListResult.class, - JobStepQuery.class, JobStepXmlRegistry.class, JobStepProperty.class, @@ -746,14 +723,12 @@ public JAXBContext getJAXBContext() throws KapuaException { JobTarget.class, JobTargetCreator.class, JobTargetListResult.class, - JobTargetQuery.class, JobExecutionXmlRegistry.class, // Trigger Trigger.class, TriggerCreator.class, TriggerListResult.class, - TriggerQuery.class, TriggerProperty.class, TriggerXmlRegistry.class, @@ -764,7 +739,6 @@ public JAXBContext getJAXBContext() throws KapuaException { FiredTrigger.class, FiredTriggerListResult.class, - FiredTriggerQuery.class, FiredTriggerXmlRegistry.class, JobStepDefinition.class, diff --git a/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountFactory.java b/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountFactory.java index 9e2a0d806ad..5abbe9cee1c 100644 --- a/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountFactory.java +++ b/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountFactory.java @@ -21,7 +21,7 @@ * @see KapuaEntityFactory * @since 1.0.0 */ -public interface AccountFactory extends KapuaEntityFactory { +public interface AccountFactory extends KapuaEntityFactory { /** * Instantiates a new {@link AccountCreator} with the given name. diff --git a/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountQuery.java b/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountQuery.java deleted file mode 100644 index 5e320976b3d..00000000000 --- a/service/account/api/src/main/java/org/eclipse/kapua/service/account/AccountQuery.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.account; - -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.service.account.xml.AccountXmlRegistry; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link Account} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AccountXmlRegistry.class, factoryMethod = "newQuery") -public interface AccountQuery extends KapuaQuery { -} diff --git a/service/account/api/src/main/java/org/eclipse/kapua/service/account/xml/AccountXmlRegistry.java b/service/account/api/src/main/java/org/eclipse/kapua/service/account/xml/AccountXmlRegistry.java index 08ea6672fee..52b5bae1095 100644 --- a/service/account/api/src/main/java/org/eclipse/kapua/service/account/xml/AccountXmlRegistry.java +++ b/service/account/api/src/main/java/org/eclipse/kapua/service/account/xml/AccountXmlRegistry.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountFactory; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.Organization; /** @@ -52,16 +51,6 @@ public AccountCreator newAccountCreator() { return factory.newCreator(null); } - /** - * Instantiates a new {@link AccountQuery}. - * - * @return The newly instantiated {@link AccountQuery}. - * @since 1.0.0 - */ - public AccountQuery newQuery() { - return factory.newQuery(null); - } - /** * Instantiates a new {@link Organization}. * diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountFactoryImpl.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountFactoryImpl.java index 39a2399496f..778a9f02c48 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountFactoryImpl.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountFactory; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.Organization; /** @@ -52,11 +51,6 @@ public Organization newOrganization() { return new OrganizationImpl(); } - @Override - public AccountQuery newQuery(KapuaId scopeId) { - return new AccountQueryImpl(scopeId); - } - @Override public Account clone(Account account) { try { diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountQueryImpl.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountQueryImpl.java deleted file mode 100644 index 1c4531a6d2d..00000000000 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountQueryImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.account.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.account.AccountQuery; - -/** - * {@link AccountQuery} implementation. - * - * @since 1.0.0 - */ -public class AccountQueryImpl extends AbstractKapuaNamedQuery implements AccountQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private AccountQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link AccountQuery#getScopeId()}. - * @since 1.0.0 - */ - public AccountQueryImpl(KapuaId scopeId) { - this(); - - setScopeId(scopeId); - } -} diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java index d187ccab8d8..ce0c2c4bf2e 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java @@ -26,12 +26,12 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.model.KapuaEntityAttributes; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountService; public class AccountRelativeFinderImpl implements AccountRelativeFinder, KapuaService { @@ -47,7 +47,7 @@ public AccountRelativeFinderImpl(AccountFactory accountFactory, AccountService a @Override public AccountListResult findChildren(KapuaId scopeId, Optional excludeTargetScopeId) throws KapuaException { - final AccountQuery childAccountsQuery = accountFactory.newQuery(scopeId); + final KapuaQuery childAccountsQuery = new KapuaQuery(scopeId); // Exclude the scope that is under config update if (excludeTargetScopeId.isPresent()) { childAccountsQuery.setPredicate( @@ -65,7 +65,7 @@ public AccountListResult findChildren(KapuaId scopeId, Optional exclude public List findParentIds(KapuaId accountId) throws KapuaException { Account account = KapuaSecurityUtils.doPrivileged(() -> accountService.find(accountId)); - if(account == null || account.getParentAccountPath() == null) { + if (account == null || account.getParentAccountPath() == null) { return Collections.emptyList(); } @@ -75,10 +75,10 @@ public List findParentIds(KapuaId accountId) throws KapuaException { String accountIdStr = accountId.getId().toString(); // Iterate in reverse order to get parent first, then grandparent, etc - for(int i = splitIds.length - 1; i >= 0; i--) { + for (int i = splitIds.length - 1; i >= 0; i--) { String id = splitIds[i]; - if(id != null && !id.isEmpty() && !id.equals(accountIdStr)) { + if (id != null && !id.isEmpty() && !id.equals(accountIdStr)) { parentAccountIds.add(new KapuaEid(new BigInteger(id))); } } diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountServiceImpl.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountServiceImpl.java index bac7692c02f..9dc097f4d5b 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountServiceImpl.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountServiceImpl.java @@ -412,7 +412,7 @@ private AccountListResult findChildAccountsTrusted(KapuaId accountId) ArgumentValidator.notNull(accountId, KapuaEntityAttributes.ENTITY_ID); ArgumentValidator.notNull(accountId.getId(), "accountId.id"); // Do find - return txManager.execute(tx -> accountRepository.query(tx, new AccountQueryImpl(accountId))); + return txManager.execute(tx -> accountRepository.query(tx, new KapuaQuery(accountId))); } private void checkAccountPermission(KapuaId scopeId, KapuaId accountId, Actions action) throws KapuaException { diff --git a/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java b/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java index 29b66908557..46e2d4293b0 100755 --- a/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java +++ b/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java @@ -47,7 +47,6 @@ import org.eclipse.kapua.service.account.AccountCreator; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; -import org.eclipse.kapua.service.account.AccountQuery; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.account.Organization; import org.junit.Assert; @@ -523,7 +522,7 @@ public void addUnknownIntegerConfigurationValue(String name, int value) throws E @When("I query for all accounts that have the system account as parent") public void queryForNumberOfTopLevelAccounts() throws Exception { - AccountQuery query = accountFactory.newQuery(SYS_SCOPE_ID); + KapuaQuery query = new KapuaQuery(SYS_SCOPE_ID); stepData.remove(INT_VALUE); try { primeException(); @@ -593,7 +592,7 @@ public void checkForAccountModifications(String name) throws KapuaException { @Then("The account with name {string} has {int} subaccount(s)") public void checkNumberOfAccounts(String accountName, int num) throws KapuaException { - KapuaQuery query = accountFactory.newQuery(getCurrentScopeId()); + final KapuaQuery query = new KapuaQuery(getCurrentScopeId()); Account account = accountService.find(getCurrentScopeId()); Assert.assertEquals(accountName, account.getName()); @@ -606,7 +605,7 @@ public void checkNumberOfChildrenForNamedAccount(String name, int num) throws Ex try { primeException(); Account tmpAcc = accountService.findByName(name); - KapuaQuery query = accountFactory.newQuery(tmpAcc.getId()); + final KapuaQuery query = new KapuaQuery(tmpAcc.getId()); long accountCnt = accountService.count(query); Assert.assertEquals(num, accountCnt); @@ -783,7 +782,7 @@ private AccountCreator accountCreatorCreator(String name, BigInteger scopeId, Da @And("I find account with name {string}") public void iFindAccountWithName(String accountName) throws Exception { - AccountQuery accountQuery = accountFactory.newQuery(getCurrentScopeId()); + final KapuaQuery accountQuery = new KapuaQuery(getCurrentScopeId()); accountQuery.setPredicate(accountQuery.attributePredicate(AccountAttributes.NAME, accountName)); AccountListResult accountListResult = accountService.query(accountQuery); Assert.assertTrue(accountListResult.getSize() > 0); @@ -869,7 +868,7 @@ public void iCreateAccountWithNameOrganizationNameAndEmailaddressAndChildAccount @When("I query for all sub-accounts in {string}") public void queryForAllAccountsInCurrentScopeId(String accountName) throws Exception { Account tmpAccount = accountService.findByName(accountName); - AccountQuery query = accountFactory.newQuery(tmpAccount.getId()); + final KapuaQuery query = new KapuaQuery(tmpAccount.getId()); try { primeException(); AccountListResult accList = accountService.query(query); diff --git a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java index 27e46090c29..8abb771e865 100644 --- a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java +++ b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java @@ -29,14 +29,12 @@ import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; import org.eclipse.kapua.commons.model.mappers.KapuaBaseMapperImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.util.xml.XmlUtil; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; import org.eclipse.kapua.service.account.AccountFactory; @@ -99,7 +97,6 @@ protected void configure() { // skip } - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); bind(KapuaJpaRepositoryConfiguration.class).toInstance(new KapuaJpaRepositoryConfiguration()); bind(AuthorizationService.class).toInstance(mockedAuthorization); diff --git a/service/api/src/main/java/org/eclipse/kapua/model/KapuaEntityFactory.java b/service/api/src/main/java/org/eclipse/kapua/model/KapuaEntityFactory.java index 3bbc106a6f6..bcd810e1204 100644 --- a/service/api/src/main/java/org/eclipse/kapua/model/KapuaEntityFactory.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/KapuaEntityFactory.java @@ -14,8 +14,6 @@ import org.eclipse.kapua.KapuaEntityCloneException; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaListResult; -import org.eclipse.kapua.model.query.KapuaQuery; /** * {@link KapuaEntityFactory} definition. @@ -24,13 +22,9 @@ * The {@link KapuaEntity} for which this {@link KapuaEntityFactory} is for. * @param * The {@link KapuaEntityCreator} for which this {@link KapuaEntityFactory} is for. - * @param - * The {@link KapuaQuery} for which this {@link KapuaEntityFactory} is for. - * @param - * The {@link KapuaListResult} for which this {@link KapuaEntityFactory} is for. * @since 1.0.0 */ -public interface KapuaEntityFactory, Q extends KapuaQuery> extends KapuaObjectFactory { +public interface KapuaEntityFactory> extends KapuaObjectFactory { /** * Instantiates a new {@link KapuaEntity}. @@ -52,16 +46,6 @@ public interface KapuaEntityFactory fetchAttributes; + + private Integer offset; + private Integer limit; + private Boolean askTotalCount; + + /** + * Constructor. + * + * @since 1.0.0 + */ + public KapuaQuery() { + } + + /** + * Constructor. + * + * @param scopeId + * The scope {@link KapuaId} of the {@link KapuaQuery} + * @since 1.0.0 + */ + public KapuaQuery(KapuaId scopeId) { + this(); + + setScopeId(scopeId); + } + + /** + * Constructor. + *

+ * It deeply clones the given {@link KapuaQuery} + * + * @param query + * the query to clone. + */ + public KapuaQuery(@NotNull KapuaQuery query) { + setFetchAttributes(query.getFetchAttributes()); + setPredicate(query.getPredicate()); + setLimit(query.getLimit()); + setOffset(query.getOffset()); + setSortCriteria(query.getSortCriteria()); + setAskTotalCount(query.getAskTotalCount()); + } /** * Gets the fetch attribute names list. @@ -40,24 +91,35 @@ public interface KapuaQuery { */ @XmlElementWrapper(name = "fetchAttributeName") @XmlElement(name = "fetchAttributeName") - List getFetchAttributes(); + public List getFetchAttributes() { + if (fetchAttributes == null) { + fetchAttributes = new ArrayList<>(); + } + + return fetchAttributes; + } /** * Adds an attribute to the fetch attribute names list * - * @param fetchAttribute The fetch attribute to add to the list. + * @param fetchAttribute + * The fetch attribute to add to the list. * @since 1.0.0 */ - void addFetchAttributes(@NotNull String fetchAttribute); + public void addFetchAttributes(String fetchAttribute) { + getFetchAttributes().add(fetchAttribute); + } /** - * Sets the fetch attribute names list.
- * This list is a list of optional attributes of a {@link KapuaEntity} that can be fetched when querying. + * Sets the fetch attribute names list.
This list is a list of optional attributes of a {@link KapuaEntity} that can be fetched when querying. * - * @param fetchAttributeNames The fetch attribute names list. + * @param fetchAttributeNames + * The fetch attribute names list. * @since 1.0.0 */ - void setFetchAttributes(@NotNull List fetchAttributeNames); + public void setFetchAttributes(List fetchAttributeNames) { + this.fetchAttributes = fetchAttributeNames; + } /** * Get the scope {@link KapuaId} in which to query. @@ -67,15 +129,20 @@ public interface KapuaQuery { */ @XmlElement(name = "scopeId") @XmlJavaTypeAdapter(KapuaIdAdapter.class) - KapuaId getScopeId(); + public KapuaId getScopeId() { + return scopeId; + } /** * Set the scope {@link KapuaId} in which to query. * - * @param scopeId The scope {@link KapuaId} in which to query. + * @param scopeId + * The scope {@link KapuaId} in which to query. * @since 1.0.0 */ - void setScopeId(KapuaId scopeId); + public void setScopeId(KapuaId scopeId) { + this.scopeId = scopeId; + } /** * Gets the {@link KapuaQuery} {@link QueryPredicate}s. @@ -84,17 +151,20 @@ public interface KapuaQuery { * @since 1.0.0 */ @XmlTransient - QueryPredicate getPredicate(); + public QueryPredicate getPredicate() { + return this.predicate; + } /** - * Sets the {@link KapuaQuery} {@link QueryPredicate}s.
- * The {@link QueryPredicate} can be a simple {@link AttributePredicate} or a combination - * of them by using the {@link AndPredicate} + * Sets the {@link KapuaQuery} {@link QueryPredicate}s.
The {@link QueryPredicate} can be a simple {@link AttributePredicate} or a combination of them by using the {@link AndPredicate} * - * @param queryPredicate The {@link KapuaQuery} {@link QueryPredicate}s. + * @param queryPredicate + * The {@link KapuaQuery} {@link QueryPredicate}s. * @since 1.0.0 */ - void setPredicate(@NotNull QueryPredicate queryPredicate); + public void setPredicate(QueryPredicate queryPredicate) { + this.predicate = queryPredicate; + } /** * Gets the {@link KapuaQuery} {@link KapuaSortCriteria} @@ -103,7 +173,9 @@ public interface KapuaQuery { * @since 1.0.0 */ @XmlTransient - KapuaSortCriteria getSortCriteria(); + public KapuaSortCriteria getSortCriteria() { + return sortCriteria; + } /** * Sets the {@link KapuaQuery} {@link KapuaSortCriteria}. @@ -112,7 +184,9 @@ public interface KapuaQuery { * The {@link KapuaQuery} {@link KapuaSortCriteria}. * @since 1.0.0 */ - void setSortCriteria(@NotNull KapuaSortCriteria sortCriteria); + public void setSortCriteria(KapuaSortCriteria sortCriteria) { + this.sortCriteria = sortCriteria; + } /** * Gets whether to include not scoped {@link KapuaEntity}es in the result set. @@ -122,7 +196,7 @@ public interface KapuaQuery { * @return Whether to include not scoped {@link KapuaEntity}es in the result set. * @since 2.0.0 */ - default boolean getNotScopedEntities() { + public boolean getNotScopedEntities() { return false; } @@ -133,7 +207,9 @@ default boolean getNotScopedEntities() { * @since 1.5.0 */ @XmlTransient - KapuaSortCriteria getDefaultSortCriteria(); + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(KapuaEntityAttributes.ENTITY_ID, SortOrder.ASCENDING); + } /** * Gets the {@link KapuaQuery} offset. @@ -142,20 +218,25 @@ default boolean getNotScopedEntities() { * @since 1.0.0 */ @XmlElement(name = "offset") - Integer getOffset(); + public Integer getOffset() { + return offset; + } /** * Set the {@link KapuaQuery} offset in the result set from which start query. *

- * If set to {@code null} the {@link KapuaQuery} will start from the first result found. - * This also mean that {@link #setOffset(Integer)} with {@code 0} or {@code null} will produce the same result. + * If set to {@code null} the {@link KapuaQuery} will start from the first result found. This also mean that {@link #setOffset(Integer)} with {@code 0} or {@code null} will produce the same + * result. *

* This method and {@link #setLimit(Integer)} are meant to be used to paginate through the result set. * - * @param offset The {@link KapuaQuery} offset. + * @param offset + * The {@link KapuaQuery} offset. * @since 1.0.0 */ - void setOffset(Integer offset); + public void setOffset(Integer offset) { + this.offset = offset; + } /** * Gets the {@link KapuaQuery} limit. @@ -164,7 +245,9 @@ default boolean getNotScopedEntities() { * @since 1.0.0 */ @XmlElement(name = "limit") - Integer getLimit(); + public Integer getLimit() { + return limit; + } /** * Sets max number of result that will be fetched by this {@link KapuaEntity}. @@ -173,20 +256,24 @@ default boolean getNotScopedEntities() { *

* This method and {@link #setOffset(Integer)} are meant to be used to paginate through the result set. * - * @param limit The max number of result that will be fetched by this {@link KapuaEntity}. + * @param limit + * The max number of result that will be fetched by this {@link KapuaEntity}. * @since 1.0.0 */ - void setLimit(Integer limit); + public void setLimit(Integer limit) { + this.limit = limit; + } /** - * Get the {@code askTotalCount} flag. If {@literal true}, the returning {@link KapuaListResult} will also return a value in - * the {@code totalCount} field, indicating how many entries matched the query regardless of {@code limit} and - * {@code offset}. If {@literal false}, {@code totalCount} will be {@literal null}. + * Get the {@code askTotalCount} flag. If {@literal true}, the returning {@link KapuaListResult} will also return a value in the {@code totalCount} field, indicating how many entries matched the + * query regardless of {@code limit} and {@code offset}. If {@literal false}, {@code totalCount} will be {@literal null}. * * @return The value of {@code askTotalCount} * @since 1.2.0 */ - Boolean getAskTotalCount(); + public Boolean getAskTotalCount() { + return askTotalCount; + } /** * Set the {@code askTotalCount} flag. @@ -194,67 +281,94 @@ default boolean getNotScopedEntities() { * @param askTotalCount * @since 1.2.0 */ - void setAskTotalCount(Boolean askTotalCount); + public void setAskTotalCount(Boolean askTotalCount) { + this.askTotalCount = askTotalCount; + } // Predicates factory /** * Creates a new {@link AttributePredicate} * - * @param attributeName The name of the attribute - * @param attributeValue The value of the attribute - * @param The type of {@code attributeValue} + * @param attributeName + * The name of the attribute + * @param attributeValue + * The value of the attribute + * @param + * The type of {@code attributeValue} * @return A new {@link AttributePredicate} for the given parameters */ - AttributePredicate attributePredicate(String attributeName, T attributeValue); + public AttributePredicate attributePredicate(String attributeName, T attributeValue) { + return new AttributePredicate<>(attributeName, attributeValue); + } /** * Creates a new {@link AttributePredicate} * - * @param attributeName The name of the attribute - * @param attributeValue The value of the attribute - * @param operator The operator to apply - * @param The type of {@code attributeValue} + * @param attributeName + * The name of the attribute + * @param attributeValue + * The value of the attribute + * @param operator + * The operator to apply + * @param + * The type of {@code attributeValue} * @return A new {@link AttributePredicate} for the given parameters */ - AttributePredicate attributePredicate(String attributeName, T attributeValue, AttributePredicate.Operator operator); + public AttributePredicate attributePredicate(String attributeName, T attributeValue, AttributePredicate.Operator operator) { + return new AttributePredicate<>(attributeName, attributeValue, operator); + } /** * Creates a new, empty {@link AndPredicate} * * @return A new, empty {@link AndPredicate} */ - AndPredicate andPredicate(); + public AndPredicate andPredicate() { + return new AndPredicate(); + } /** * Creates a new {@link AndPredicate} creating a logical AND with all the provided {@link QueryPredicate} * - * @param queryPredicates A list of {@link QueryPredicate}s to create the {@link AndPredicate} + * @param queryPredicates + * A list of {@link QueryPredicate}s to create the {@link AndPredicate} * @return A new {@link AndPredicate} */ - AndPredicate andPredicate(QueryPredicate... queryPredicates); + public AndPredicate andPredicate(QueryPredicate... queryPredicates) { + return new AndPredicate(queryPredicates); + } /** * Creates a new, empty {@link OrPredicate} * * @return A new, empty {@link OrPredicate} */ - OrPredicate orPredicate(); + public OrPredicate orPredicate() { + return new OrPredicate(); + } /** * Creates a new {@link OrPredicate} creating a logical OR with all the provided {@link QueryPredicate} * - * @param queryPredicates A list of {@link QueryPredicate}s to create the {@link OrPredicate} + * @param queryPredicates + * A list of {@link QueryPredicate}s to create the {@link OrPredicate} * @return A new {@link OrPredicate} */ - OrPredicate orPredicate(QueryPredicate... queryPredicates); + public OrPredicate orPredicate(QueryPredicate... queryPredicates) { + return new OrPredicate(queryPredicates); + } /** * Creates a new {@link FieldSortCriteria} * - * @param attributeName The name of the attribute - * @param sortOrder The {@link SortOrder} + * @param attributeName + * The name of the attribute + * @param sortOrder + * The {@link SortOrder} * @return */ - FieldSortCriteria fieldSortCriteria(String attributeName, SortOrder sortOrder); + public FieldSortCriteria fieldSortCriteria(String attributeName, SortOrder sortOrder) { + return new FieldSortCriteria(attributeName, sortOrder); + } } diff --git a/service/api/src/main/java/org/eclipse/kapua/model/query/QueryFactory.java b/service/api/src/main/java/org/eclipse/kapua/model/query/QueryFactory.java deleted file mode 100644 index adc9c83b1d1..00000000000 --- a/service/api/src/main/java/org/eclipse/kapua/model/query/QueryFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.model.query; - -import org.eclipse.kapua.model.KapuaObjectFactory; - -/** - * {@link KapuaQuery} {@link KapuaObjectFactory} definition. - * - * @since 2.0.0 - */ -public interface QueryFactory extends KapuaObjectFactory { - - /** - * Instantiates a new {@link KapuaQuery}. - * - * @return The newly instantiated {@link KapuaQuery}. - * @since 2.0.0 - */ - KapuaQuery newQuery(); -} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AbstractMatchPredicate.java b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AbstractMatchPredicate.java similarity index 88% rename from commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AbstractMatchPredicate.java rename to service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AbstractMatchPredicate.java index 40f4fe530a4..f5e2e6fd5c2 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/query/predicate/AbstractMatchPredicate.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AbstractMatchPredicate.java @@ -10,12 +10,10 @@ * Contributors: * Eurotech - initial API and implementation *******************************************************************************/ -package org.eclipse.kapua.commons.model.query.predicate; +package org.eclipse.kapua.model.query.predicate; import java.util.List; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; - /** * {@link MatchPredicate} implementation. * diff --git a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AndPredicate.java b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AndPredicate.java index 1104ad0aaf0..81f03b26960 100644 --- a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AndPredicate.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AndPredicate.java @@ -12,8 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.model.query.predicate; -import javax.validation.constraints.NotNull; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; + +import javax.validation.constraints.NotNull; + +import com.google.common.collect.Lists; /** * {@link AndPredicate} definition. @@ -22,17 +27,51 @@ * * @since 1.0.0 */ -public interface AndPredicate extends QueryPredicate { +public class AndPredicate implements QueryPredicate { + + private List predicates; + + /** + * Constructor. + * + * @since 1.0.0 + */ + public AndPredicate() { + setPredicates(new ArrayList<>()); + } + + /** + * Constructor which accepts a not null array of {@link QueryPredicate}s. + * + * @param predicates + * the {@link QueryPredicate}s to add. + * @throws NullPointerException + * if the given parameter is {@code null}. + * @since 1.0.0 + */ + public AndPredicate(@NotNull QueryPredicate... predicates) { + Objects.requireNonNull(predicates); + + setPredicates(Lists.newArrayList(predicates)); + } /** * Adds the given {@link QueryPredicate} to the {@link AndPredicate}. * - * @param predicate The {@link AndPredicate} to concatenate + * @param predicate + * The {@link AndPredicate} to concatenate * @return {@code this} {@link AndPredicate}. - * @throws NullPointerException if the given parameter is {@code null}. + * @throws NullPointerException + * if the given parameter is {@code null}. * @since 1.0.0 */ - AndPredicate and(@NotNull QueryPredicate predicate); + public AndPredicate and(@NotNull QueryPredicate predicate) { + Objects.requireNonNull(predicates); + + getPredicates().add(predicate); + + return this; + } /** * Gets all {@link QueryPredicate} set for this {@link AndPredicate} @@ -40,14 +79,20 @@ public interface AndPredicate extends QueryPredicate { * @return The {@link List} of {@link QueryPredicate}s * @since 1.0.0 */ - List getPredicates(); + public List getPredicates() { + return this.predicates; + } /** * Sets a {@link List} of {@link QueryPredicate}s in AND clause * - * @param predicates The {@link List} of {@link QueryPredicate}s - * @throws NullPointerException if the given parameter is {@code null}. + * @param predicates + * The {@link List} of {@link QueryPredicate}s + * @throws NullPointerException + * if the given parameter is {@code null}. * @since 1.1.0 */ - void setPredicates(@NotNull List predicates); + public void setPredicates(List predicates) { + this.predicates = predicates; + } } diff --git a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AttributePredicate.java b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AttributePredicate.java index 79fde273391..172ac756db2 100644 --- a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AttributePredicate.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/AttributePredicate.java @@ -15,10 +15,11 @@ /** * {@link AttributePredicate} definition. * - * @param Attribute value type. + * @param + * Attribute value type. * @since 1.3.0 */ -public interface AttributePredicate extends QueryPredicate { +public class AttributePredicate implements QueryPredicate { /** * {@link AttributePredicate}s operators @@ -27,7 +28,7 @@ public interface AttributePredicate extends QueryPredicate { * * @since 1.3.0 */ - enum Operator { + public static enum Operator { /** * {@literal #EQUAL} {@link Operator} *

@@ -66,8 +67,7 @@ enum Operator { /** * {@literal #STARTS_WITH} {@link Operator} *

- * Matches results with value that starts with the given value. - * To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. + * Matches results with value that starts with the given value. To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. * * @since 1.3.0 */ @@ -76,8 +76,7 @@ enum Operator { /** * The same of {@link #STARTS_WITH} {@link Operator} but case insensitive *

- * Matches results with value that starts with the given value, case insensitive. - * To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. + * Matches results with value that starts with the given value, case insensitive. To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. * * @since 1.3.0 */ @@ -86,8 +85,7 @@ enum Operator { /** * {@literal #LIKE} {@link Operator} *

- * Matches results with value that are like (in SQL fashion) the given value. - * To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. + * Matches results with value that are like (in SQL fashion) the given value. To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. *

* If you want to match only the beginning of the {@link String} please consider using {@link #STARTS_WITH}. * @@ -98,8 +96,7 @@ enum Operator { /** * {@link #LIKE} {@link Operator} but case insensitive *

- * Matches results with value that are like (in SQL fashion) the given value case insensitive. - * To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. + * Matches results with value that are like (in SQL fashion) the given value case insensitive. To be used with {@link String} {@link org.eclipse.kapua.model.KapuaEntityAttributes}. *

* If you want to match only the beginning of the {@link String} please consider using {@link #STARTS_WITH_IGNORE_CASE}. * @@ -110,8 +107,7 @@ enum Operator { /** * {@literal #GREATER_THAN} {@link Operator} *

- * Matches result with value that is greater but not equal. - * To be used with {@link Comparable} types. + * Matches result with value that is greater but not equal. To be used with {@link Comparable} types. * * @since 1.3.0 */ @@ -120,8 +116,7 @@ enum Operator { /** * {@literal #GREATER_THAN_OR_EQUAL} {@link Operator} *

- * Matches result with value that is greater or equal. - * To be used with {@link Comparable} types. + * Matches result with value that is greater or equal. To be used with {@link Comparable} types. * * @since 1.3.0 */ @@ -130,8 +125,7 @@ enum Operator { /** * {@literal #LESS_THAN} {@link Operator} *

- * Matches result with value that is less but not equal. - * To be used with {@link Comparable} types. + * Matches result with value that is less but not equal. To be used with {@link Comparable} types. * * @since 1.3.0 */ @@ -140,21 +134,58 @@ enum Operator { /** * {@literal #LESS_THAN_OR_EQUAL} {@link Operator} *

- * Matches result with value that is less or equal. - * To be used with {@link Comparable} types. + * Matches result with value that is less or equal. To be used with {@link Comparable} types. * * @since 1.3.0 */ LESS_THAN_OR_EQUAL } + private String attributeName; + private T attributeValue; + private Operator operator; + + /** + * Constructor. + *

+ * Defaults ot {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator#EQUAL} + * + * @param attributeName + * The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. + * @param attributeValue + * The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. + * @since 1.0.0 + */ + public AttributePredicate(String attributeName, T attributeValue) { + this(attributeName, attributeValue, Operator.EQUAL); + } + + /** + * Constructor. + * + * @param attributeName + * The name of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. + * @param attributeValue + * The value of {@link org.eclipse.kapua.model.KapuaEntityAttributes} to set into the {@link AttributePredicate}. + * @param operator + * The {@link org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator} to set into the {@link AttributePredicate}. + * @since 1.0.0 + */ + public AttributePredicate(String attributeName, T attributeValue, Operator operator) { + this.attributeName = attributeName; + this.attributeValue = attributeValue; + this.operator = operator; + } + /** * Gets the name of the {@link org.eclipse.kapua.model.KapuaEntityAttributes} to compare. * * @return The name name of the {@link org.eclipse.kapua.model.KapuaEntityAttributes} to compare. * @since 1.3.0 */ - String getAttributeName(); + public String getAttributeName() { + return attributeName; + } /** * Gets the value to compare the results. @@ -162,7 +193,9 @@ enum Operator { * @return The value to compare the results. * @since 1.3.0 */ - T getAttributeValue(); + public T getAttributeValue() { + return attributeValue; + } /** * Get the {@link Operator} used to compare results. @@ -170,5 +203,7 @@ enum Operator { * @return The {@link Operator} used to compare results. * @since 1.3.0 */ - Operator getOperator(); + public Operator getOperator() { + return operator; + } } diff --git a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/OrPredicate.java b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/OrPredicate.java index 2cc4c8a36dc..58c5bb5640a 100644 --- a/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/OrPredicate.java +++ b/service/api/src/main/java/org/eclipse/kapua/model/query/predicate/OrPredicate.java @@ -12,8 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.model.query.predicate; -import javax.validation.constraints.NotNull; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; + +import javax.validation.constraints.NotNull; + +import com.google.common.collect.Lists; /** * {@link OrPredicate} definition. @@ -22,17 +27,51 @@ * * @since 1.0.0 */ -public interface OrPredicate extends QueryPredicate { +public class OrPredicate implements QueryPredicate { + + private List predicates; + + /** + * Constructor. + * + * @since 1.0.0 + */ + public OrPredicate() { + setPredicates(new ArrayList<>()); + } + + /** + * Constructor which accepts a not {@code null} array of {@link QueryPredicate}s. + * + * @param predicates + * the {@link QueryPredicate}s to add. + * @throws NullPointerException + * if the given parameter is {@code null}. + * @since 1.0.0 + */ + public OrPredicate(@NotNull QueryPredicate... predicates) { + Objects.requireNonNull(predicates); + + setPredicates(Lists.newArrayList(predicates)); + } /** * Adds the given {@link QueryPredicate} to the {@link OrPredicate}. * - * @param predicate The {@link OrPredicate} to concatenate + * @param predicate + * The {@link OrPredicate} to concatenate * @return {@code this} {@link OrPredicate}. - * @throws NullPointerException if the given parameter is {@code null}. + * @throws NullPointerException + * if the given parameter is {@code null}. * @since 1.0.0 */ - OrPredicate or(@NotNull QueryPredicate predicate); + public OrPredicate or(@NotNull QueryPredicate predicate) { + Objects.requireNonNull(predicates); + + getPredicates().add(predicate); + + return this; + } /** * Gets all {@link QueryPredicate} set for this {@link OrPredicate} @@ -40,15 +79,21 @@ public interface OrPredicate extends QueryPredicate { * @return The {@link List} of {@link QueryPredicate}s * @since 1.0.0 */ - List getPredicates(); + public List getPredicates() { + return this.predicates; + } /** * Sets a {@link List} of {@link QueryPredicate}s in OR clause * - * @param predicates The {@link List} of {@link QueryPredicate}s - * @throws NullPointerException if the given parameter is {@code null}. + * @param predicates + * The {@link List} of {@link QueryPredicate}s + * @throws NullPointerException + * if the given parameter is {@code null}. * @since 1.1.0 */ - void setPredicates(@NotNull List predicates); + public void setPredicates(List predicates) { + this.predicates = predicates; + } } diff --git a/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/authentication/AuthenticationLogic.java b/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/authentication/AuthenticationLogic.java index c505cabf576..6733b65d31c 100644 --- a/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/authentication/AuthenticationLogic.java +++ b/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/authentication/AuthenticationLogic.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.authentication; +import java.text.MessageFormat; +import java.util.List; +import java.util.Map; + import org.apache.shiro.ShiroException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.client.security.bean.AclUtils; @@ -22,6 +26,7 @@ import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.registry.ConnectionUserCouplingMode; @@ -32,15 +37,10 @@ import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionAttributes; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionFactory; -import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionQuery; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.MessageFormat; -import java.util.List; -import java.util.Map; - /** * Authentication logic definition * @@ -98,8 +98,8 @@ public abstract List connect(AuthContext authContext) * Execute the disconnection logic * * @param authContext - * @return true send disconnect message (if the disconnection is a clean disconnection) - * false don't send disconnect message (the disconnection is caused by a stealing link or the device is currently connected to another node) + * @return true send disconnect message (if the disconnection is a clean disconnection) false don't send disconnect message (the disconnection is caused by a stealing link or the device is + * currently connected to another node) */ public abstract boolean disconnect(AuthContext authContext); @@ -224,7 +224,7 @@ protected void enforceDeviceUserBound(ConnectionUserCouplingMode connectionUserC */ protected void checkConnectionCountByReservedUserId(KapuaId scopeId, KapuaId userId, long count) throws KapuaException { // check that no devices have this user as strict user - DeviceConnectionOptionQuery query = deviceConnectionOptionFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(DeviceConnectionOptionAttributes.RESERVED_USER_ID, userId)); query.setLimit(1); @@ -286,7 +286,8 @@ protected DeviceConnection createDeviceConnection(AuthContext authContext) throw * Updates a {@link DeviceConnection} using the info provided. * * @param authContext - * @param deviceConnection The {@link DeviceConnection} to update, or null if it needs to be created + * @param deviceConnection + * The {@link DeviceConnection} to update, or null if it needs to be created * @return The updated {@link DeviceConnection} * @throws KapuaException */ diff --git a/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicateImpl.java b/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicate.java similarity index 87% rename from service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicateImpl.java rename to service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicate.java index a4ef55373db..211ce25d05b 100644 --- a/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicateImpl.java +++ b/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/AndPredicate.java @@ -12,20 +12,21 @@ *******************************************************************************/ package org.eclipse.kapua.service.storable.model.query.predicate; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.kapua.service.storable.exception.MappingException; + import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; -import org.eclipse.kapua.service.storable.exception.MappingException; - -import java.util.ArrayList; -import java.util.List; /** * {@link AndPredicate} implementation. * * @since 1.0.0 */ -public class AndPredicateImpl extends StorablePredicateImpl implements AndPredicate { +public class AndPredicate extends StorablePredicateImpl { private List predicates; @@ -34,22 +35,22 @@ public class AndPredicateImpl extends StorablePredicateImpl implements AndPredic * * @since 1.0.0 */ - public AndPredicateImpl() { + public AndPredicate() { } /** * Constructor. * - * @param storablePredicates The {@link StorablePredicate}s to add. + * @param storablePredicates + * The {@link StorablePredicate}s to add. * @since 1.0.0 */ - public AndPredicateImpl(StorablePredicate... storablePredicates) { + public AndPredicate(StorablePredicate... storablePredicates) { this(); setPredicates(Lists.newArrayList(storablePredicates)); } - @Override public List getPredicates() { if (predicates == null) { predicates = new ArrayList<>(); @@ -58,13 +59,11 @@ public List getPredicates() { return this.predicates; } - @Override public AndPredicate addPredicate(StorablePredicate storablePredicate) { getPredicates().add(storablePredicate); return this; } - @Override public void setPredicates(List predicates) { this.predicates = predicates; } diff --git a/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/StorablePredicateFactoryImpl.java b/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/StorablePredicateFactoryImpl.java index 1c53c801060..7e500c3c1bd 100644 --- a/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/StorablePredicateFactoryImpl.java +++ b/service/commons/storable/internal/src/main/java/org/eclipse/kapua/service/storable/model/query/predicate/StorablePredicateFactoryImpl.java @@ -12,16 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.storable.model.query.predicate; -import org.eclipse.kapua.service.storable.model.query.StorableField; - import javax.inject.Singleton; +import org.eclipse.kapua.service.storable.model.query.StorableField; + @Singleton public class StorablePredicateFactoryImpl implements StorablePredicateFactory { @Override public AndPredicate newAndPredicate() { - return new AndPredicateImpl(); + return new AndPredicate(); } @Override diff --git a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationFactory.java b/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationFactory.java index c125842e2ed..a46ec83b6c0 100644 --- a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationFactory.java +++ b/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationFactory.java @@ -19,6 +19,6 @@ * * @since 1.1.0 */ -public interface JobDeviceManagementOperationFactory extends KapuaEntityFactory { +public interface JobDeviceManagementOperationFactory extends KapuaEntityFactory { } diff --git a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationQuery.java b/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationQuery.java deleted file mode 100644 index 35d1f7f4557..00000000000 --- a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.management.job; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link JobDeviceManagementOperation} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.1.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobDeviceManagementOperationXmlRegistry.class, factoryMethod = "newQuery") -public interface JobDeviceManagementOperationQuery extends KapuaQuery { -} diff --git a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationXmlRegistry.java b/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationXmlRegistry.java index f9b2513eb14..eb23385a81b 100644 --- a/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationXmlRegistry.java +++ b/service/device/management/job/api/src/main/java/org/eclipse/kapua/service/device/management/job/JobDeviceManagementOperationXmlRegistry.java @@ -34,7 +34,4 @@ public JobDeviceManagementOperationCreator newJobDeviceManagementOperationCreato return jobDeviceManagementOperationFactory.newCreator(null); } - public JobDeviceManagementOperationQuery newQuery() { - return jobDeviceManagementOperationFactory.newQuery(null); - } } diff --git a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationFactoryImpl.java b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationFactoryImpl.java index 3db27bf80c4..32c2868962a 100644 --- a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationFactoryImpl.java +++ b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperation; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationCreator; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationFactory; -import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationQuery; /** * {@link JobDeviceManagementOperationFactory} implementation. @@ -39,11 +38,6 @@ public JobDeviceManagementOperationCreator newCreator(KapuaId scopeId) { return new JobDeviceManagementOperationCreatorImpl(scopeId); } - @Override - public JobDeviceManagementOperationQuery newQuery(KapuaId scopeId) { - return new JobDeviceManagementOperationQueryImpl(scopeId); - } - @Override public JobDeviceManagementOperation clone(JobDeviceManagementOperation jobDeviceManagementOperation) { try { diff --git a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationQueryImpl.java b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationQueryImpl.java deleted file mode 100644 index 2f0b27f35d8..00000000000 --- a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.management.job.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationQuery; - -/** - * {@link JobDeviceManagementOperationQuery} definition. - * - * @since 1.1.0 - */ -public class JobDeviceManagementOperationQueryImpl extends AbstractKapuaQuery implements JobDeviceManagementOperationQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.1.0 - */ - public JobDeviceManagementOperationQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationServiceImpl.java b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationServiceImpl.java index 9a63d5a979a..36fc997740a 100644 --- a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationServiceImpl.java +++ b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/internal/JobDeviceManagementOperationServiceImpl.java @@ -12,15 +12,23 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.job.internal; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityUniquenessException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl; -import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.predicate.AndPredicate; +import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperation; @@ -28,18 +36,10 @@ import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationCreator; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationFactory; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationListResult; -import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationQuery; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationRepository; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationService; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * {@link JobDeviceManagementOperationService} implementation * @@ -79,11 +79,11 @@ public JobDeviceManagementOperation create(JobDeviceManagementOperationCreator j // Check access authorizationService.checkPermission(permissionFactory.newPermission(Domains.JOB, Actions.write, null)); // Check duplicate - JobDeviceManagementOperationQuery query = new JobDeviceManagementOperationQueryImpl(jobDeviceManagementOperationCreator.getScopeId()); + KapuaQuery query = new KapuaQuery(jobDeviceManagementOperationCreator.getScopeId()); query.setPredicate( - new AndPredicateImpl( - new AttributePredicateImpl<>(JobDeviceManagementOperationAttributes.JOB_ID, jobDeviceManagementOperationCreator.getJobId()), - new AttributePredicateImpl<>(JobDeviceManagementOperationAttributes.DEVICE_MANAGEMENT_OPERATION_ID, jobDeviceManagementOperationCreator.getDeviceManagementOperationId()) + new AndPredicate( + new AttributePredicate<>(JobDeviceManagementOperationAttributes.JOB_ID, jobDeviceManagementOperationCreator.getJobId()), + new AttributePredicate<>(JobDeviceManagementOperationAttributes.DEVICE_MANAGEMENT_OPERATION_ID, jobDeviceManagementOperationCreator.getDeviceManagementOperationId()) ) ); @@ -92,7 +92,8 @@ public JobDeviceManagementOperation create(JobDeviceManagementOperationCreator j List> uniqueAttributes = new ArrayList<>(); uniqueAttributes.add(new AbstractMap.SimpleEntry<>(JobDeviceManagementOperationAttributes.JOB_ID, jobDeviceManagementOperationCreator.getJobId())); - uniqueAttributes.add(new AbstractMap.SimpleEntry<>(JobDeviceManagementOperationAttributes.DEVICE_MANAGEMENT_OPERATION_ID, jobDeviceManagementOperationCreator.getDeviceManagementOperationId())); + uniqueAttributes.add( + new AbstractMap.SimpleEntry<>(JobDeviceManagementOperationAttributes.DEVICE_MANAGEMENT_OPERATION_ID, jobDeviceManagementOperationCreator.getDeviceManagementOperationId())); throw new KapuaEntityUniquenessException(JobDeviceManagementOperation.TYPE, uniqueAttributes); } diff --git a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/manager/internal/JobDeviceManagementOperationManagerServiceImpl.java b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/manager/internal/JobDeviceManagementOperationManagerServiceImpl.java index aad30fefc6c..ea2a01fee65 100644 --- a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/manager/internal/JobDeviceManagementOperationManagerServiceImpl.java +++ b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/manager/internal/JobDeviceManagementOperationManagerServiceImpl.java @@ -12,17 +12,22 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.job.manager.internal; +import java.util.Date; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.job.engine.JobEngineFactory; import org.eclipse.kapua.job.engine.JobEngineService; import org.eclipse.kapua.job.engine.JobStartOptions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperation; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationAttributes; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationFactory; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationListResult; -import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationQuery; import org.eclipse.kapua.service.device.management.job.JobDeviceManagementOperationService; import org.eclipse.kapua.service.device.management.job.manager.JobDeviceManagementOperationManagerService; import org.eclipse.kapua.service.device.management.message.notification.NotifyStatus; @@ -34,16 +39,11 @@ import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.Date; - /** * {@link JobDeviceManagementOperationManagerService} implementation. * @@ -100,7 +100,7 @@ public void processJobTargetOnNotification(KapuaId scopeId, KapuaId operationId, return; } - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate( jobTargetQuery.andPredicate( jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, jobDeviceManagementOperation.getJobId()), @@ -118,20 +118,21 @@ public void processJobTargetOnNotification(KapuaId scopeId, KapuaId operationId, jobTarget = jobTargets.getFirstItem(); if (jobTarget == null) { - LOG.warn("JobTarget with targetId {} for Job {} not found! This is something strange that happened and needs some checking! Reference JobDeviceManagementOperation: {}", deviceManagementOperation.getDeviceId(), jobDeviceManagementOperation.getJobId(), jobDeviceManagementOperation.getId()); + LOG.warn("JobTarget with targetId {} for Job {} not found! This is something strange that happened and needs some checking! Reference JobDeviceManagementOperation: {}", + deviceManagementOperation.getDeviceId(), jobDeviceManagementOperation.getJobId(), jobDeviceManagementOperation.getId()); return; } switch (status) { - case COMPLETED: - jobTarget.setStatus(JobTargetStatus.NOTIFIED_COMPLETION); - break; - case FAILED: - jobTarget.setStatus(JobTargetStatus.PROCESS_FAILED); - break; - case STALE: - default: - break; + case COMPLETED: + jobTarget.setStatus(JobTargetStatus.NOTIFIED_COMPLETION); + break; + case FAILED: + jobTarget.setStatus(JobTargetStatus.PROCESS_FAILED); + break; + case STALE: + default: + break; } jobTargetService.update(jobTarget); @@ -166,14 +167,17 @@ public void processJobTargetOnNotification(KapuaId scopeId, KapuaId operationId, } /** - * This fixes the double {@link NotifyStatus#COMPLETED} {@link ManagementOperationNotification} set from Kura - * when performing a Device package download with the 'install' flag is set to {@code true}. + * This fixes the double {@link NotifyStatus#COMPLETED} {@link ManagementOperationNotification} set from Kura when performing a Device package download with the 'install' flag is set to + * {@code true}. *

* If this is not the last {@link ManagementOperationNotification} the processing must stop. * - * @param deviceManagementOperation The current {@link DeviceManagementOperation} which the {@link ManagementOperationNotification} refers to. - * @param status The {@link ManagementOperationNotification} {@link NotifyStatus}. - * @param resource The {@link ManagementOperationNotification} resource. + * @param deviceManagementOperation + * The current {@link DeviceManagementOperation} which the {@link ManagementOperationNotification} refers to. + * @param status + * The {@link ManagementOperationNotification} {@link NotifyStatus}. + * @param resource + * The {@link ManagementOperationNotification} resource. * @return {@code true} if this is the last {@link ManagementOperationNotification} for the {@link DeviceManagementOperation}, {@code false} otherwise. * @since 1.1.0 */ @@ -199,18 +203,22 @@ private boolean checkLastNotification(DeviceManagementOperation deviceManagement /** * Gets the {@link JobDeviceManagementOperation} associated with the given {@link DeviceManagementOperation#getOperationId()}. * - * @param scopeId The scope {@link KapuaId} of the {@link JobDeviceManagementOperation}. - * @param operationId The {@link DeviceManagementOperation#getOperationId()} to match. + * @param scopeId + * The scope {@link KapuaId} of the {@link JobDeviceManagementOperation}. + * @param operationId + * The {@link DeviceManagementOperation#getOperationId()} to match. * @return The matched {@link JobDeviceManagementOperation} - * @throws KapuaEntityNotFoundException if there is no {@link JobDeviceManagementOperation} with the given {@code operationId}. - * @throws KapuaException If something goes bad. + * @throws KapuaEntityNotFoundException + * if there is no {@link JobDeviceManagementOperation} with the given {@code operationId}. + * @throws KapuaException + * If something goes bad. * @since 1.1.0 */ private JobDeviceManagementOperation getJobDeviceManagementOperation(KapuaId scopeId, KapuaId operationId) throws KapuaException { DeviceManagementOperation deviceManagementOperation = getDeviceManagementOperation(scopeId, operationId); - JobDeviceManagementOperationQuery query = jobDeviceManagementOperationFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(JobDeviceManagementOperationAttributes.DEVICE_MANAGEMENT_OPERATION_ID, deviceManagementOperation.getId())); JobDeviceManagementOperationListResult operations = jobDeviceManagementOperationService.query(query); @@ -223,15 +231,18 @@ private JobDeviceManagementOperation getJobDeviceManagementOperation(KapuaId sco return jobDeviceManagementOperation; } - /** * Gets the {@link DeviceManagementOperation} that matches the given {@code operationId}. * - * @param scopeId The scope {@link KapuaId} of the {@link DeviceManagementOperation}. - * @param operationId The {@link DeviceManagementOperation#getOperationId()} to match. + * @param scopeId + * The scope {@link KapuaId} of the {@link DeviceManagementOperation}. + * @param operationId + * The {@link DeviceManagementOperation#getOperationId()} to match. * @return The matched {@link DeviceManagementOperation}. - * @throws KapuaEntityNotFoundException if there is no {@link DeviceManagementOperation} with the given {@code operationId}. - * @throws KapuaException If something goes bad. + * @throws KapuaEntityNotFoundException + * if there is no {@link DeviceManagementOperation} with the given {@code operationId}. + * @throws KapuaException + * If something goes bad. * @since 1.1.0 */ private DeviceManagementOperation getDeviceManagementOperation(KapuaId scopeId, KapuaId operationId) throws KapuaException { diff --git a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/scheduler/internal/JobDeviceManagementTriggerManagerServiceImpl.java b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/scheduler/internal/JobDeviceManagementTriggerManagerServiceImpl.java index f2b1d51cdec..293205d1bf1 100644 --- a/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/scheduler/internal/JobDeviceManagementTriggerManagerServiceImpl.java +++ b/service/device/management/job/internal/src/main/java/org/eclipse/kapua/service/device/management/job/scheduler/internal/JobDeviceManagementTriggerManagerServiceImpl.java @@ -12,41 +12,40 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.job.scheduler.internal; +import java.util.Date; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.job.engine.JobEngineFactory; import org.eclipse.kapua.job.engine.JobEngineService; import org.eclipse.kapua.job.engine.JobStartOptions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.device.management.job.scheduler.manager.JobDeviceManagementTriggerManagerService; import org.eclipse.kapua.service.device.management.job.scheduler.manager.exception.ProcessOnConnectException; import org.eclipse.kapua.service.job.step.JobStepAttributes; import org.eclipse.kapua.service.job.step.JobStepFactory; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.targets.JobTarget; import org.eclipse.kapua.service.job.targets.JobTargetAttributes; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.eclipse.kapua.service.scheduler.trigger.Trigger; import org.eclipse.kapua.service.scheduler.trigger.TriggerAttributes; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerService; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.Date; - /** * {@link JobDeviceManagementTriggerManagerService} implementation. * @@ -89,14 +88,13 @@ public JobDeviceManagementTriggerManagerServiceImpl( this.triggerFactory = triggerFactory; } - @Override public void processOnConnect(KapuaId scopeId, KapuaId deviceId) throws ProcessOnConnectException { Date now = new Date(); try { - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(scopeId); + KapuaQuery jobTargetQuery = new KapuaQuery(scopeId); jobTargetQuery.setPredicate( jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_TARGET_ID, deviceId) @@ -105,7 +103,7 @@ public void processOnConnect(KapuaId scopeId, KapuaId deviceId) throws ProcessOn JobTargetListResult jobTargetListResult = KapuaSecurityUtils.doPrivileged(() -> jobTargetService.query(jobTargetQuery)); for (JobTarget jt : jobTargetListResult.getItems()) { - JobStepQuery jobStepQuery = jobStepFactory.newQuery(jt.getScopeId()); + KapuaQuery jobStepQuery = new KapuaQuery(jt.getScopeId()); jobStepQuery.setPredicate( jobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jt.getJobId()) @@ -118,7 +116,7 @@ public void processOnConnect(KapuaId scopeId, KapuaId deviceId) throws ProcessOn continue; } - TriggerQuery triggerQuery = triggerFactory.newQuery(scopeId); + KapuaQuery triggerQuery = new KapuaQuery(scopeId); triggerQuery.setPredicate( triggerQuery.andPredicate( diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationFactory.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationFactory.java index bb1a7c27f9f..d42678c6005 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationFactory.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationFactory.java @@ -20,7 +20,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DeviceManagementOperationFactory extends KapuaEntityFactory { +public interface DeviceManagementOperationFactory extends KapuaEntityFactory { /** * Instantiates a new {@link DeviceManagementOperationProperty}. diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationQuery.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationQuery.java index fd82bbd6242..c82becf2fcf 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationQuery.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationQuery.java @@ -12,13 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.registry.operation; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; + /** * {@link DeviceManagementOperation} {@link KapuaQuery} definition. * @@ -27,6 +30,34 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DeviceManagementOperationXmlRegistry.class, factoryMethod = "newQuery") -public interface DeviceManagementOperationQuery extends KapuaQuery { +@XmlType +public class DeviceManagementOperationQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.1.0 + */ + private DeviceManagementOperationQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.1.0 + */ + public DeviceManagementOperationQuery(KapuaId scopeId) { + this(); + + setScopeId(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(DeviceManagementOperationAttributes.STARTED_ON, SortOrder.ASCENDING); + } + } diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationXmlRegistry.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationXmlRegistry.java index 827c836a9ac..dae33e20998 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationXmlRegistry.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/DeviceManagementOperationXmlRegistry.java @@ -35,7 +35,4 @@ DeviceManagementOperationCreator newDeviceManagementOperationCreator() { return factory.newCreator(null); } - DeviceManagementOperationQuery newQuery() { - return factory.newQuery(null); - } } diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationFactory.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationFactory.java index 8e8a3761efb..46e1515076c 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationFactory.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface ManagementOperationNotificationFactory extends KapuaEntityFactory { +public interface ManagementOperationNotificationFactory extends KapuaEntityFactory { } diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationQuery.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationQuery.java index 6c2c03930c4..c3d3520a710 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationQuery.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationQuery.java @@ -12,13 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.registry.operation.notification; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; + /** * {@link ManagementOperationNotification} {@link KapuaQuery} definition. * @@ -27,6 +30,33 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = ManagementOperationNotificationXmlRegistry.class, factoryMethod = "newQuery") -public interface ManagementOperationNotificationQuery extends KapuaQuery { +@XmlType +public class ManagementOperationNotificationQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + private ManagementOperationNotificationQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public ManagementOperationNotificationQuery(KapuaId scopeId) { + this(); + + setScopeId(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(ManagementOperationNotificationAttributes.SENT_ON, SortOrder.ASCENDING); + } } diff --git a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationXmlRegistry.java b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationXmlRegistry.java index f98b3685674..6e4b125a51a 100644 --- a/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationXmlRegistry.java +++ b/service/device/management/registry/api/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/ManagementOperationNotificationXmlRegistry.java @@ -34,7 +34,4 @@ ManagementOperationNotificationCreator newManagementOperationNotificationCreator return managementOperationNotificationFactory.newCreator(null); } - ManagementOperationNotificationQuery newQuery() { - return managementOperationNotificationFactory.newQuery(null); - } } diff --git a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/manager/internal/DeviceManagementRegistryManagerServiceImpl.java b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/manager/internal/DeviceManagementRegistryManagerServiceImpl.java index 4491da0e2fe..d8af6c324ae 100644 --- a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/manager/internal/DeviceManagementRegistryManagerServiceImpl.java +++ b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/manager/internal/DeviceManagementRegistryManagerServiceImpl.java @@ -12,7 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.registry.manager.internal; -import com.google.common.base.Strings; +import java.util.Date; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.model.id.KapuaId; @@ -34,9 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.Date; +import com.google.common.base.Strings; @Singleton public class DeviceManagementRegistryManagerServiceImpl implements DeviceManagementRegistryManagerService { @@ -60,7 +62,8 @@ public DeviceManagementRegistryManagerServiceImpl( } @Override - public void processOperationNotification(KapuaId scopeId, KapuaId operationId, Date updateOn, String resource, NotifyStatus status, Integer progress, String message) throws ManagementOperationNotificationProcessingException { + public void processOperationNotification(KapuaId scopeId, KapuaId operationId, Date updateOn, String resource, NotifyStatus status, Integer progress, String message) + throws ManagementOperationNotificationProcessingException { try { storeManagementNotification(scopeId, operationId, updateOn, status, resource, progress, message); @@ -76,7 +79,6 @@ public void processOperationNotification(KapuaId scopeId, KapuaId operationId, D } } - public void processFailedNotification(KapuaId scopeId, KapuaId operationId, Date updateOn, String resource, String message) throws KapuaException { closeDeviceManagementOperation(scopeId, operationId, updateOn, NotifyStatus.FAILED, message); } @@ -148,7 +150,7 @@ public void closeDeviceManagementOperation(KapuaId scopeId, KapuaId operationId, } while (failed); { - ManagementOperationNotificationQuery query = managementOperationNotificationFactory.newQuery(scopeId); + ManagementOperationNotificationQuery query = new ManagementOperationNotificationQuery(scopeId); query.setPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, deviceManagementOperation.getId())); query.setSortCriteria(query.fieldSortCriteria(ManagementOperationNotificationAttributes.SENT_ON, SortOrder.ASCENDING)); diff --git a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationFactoryImpl.java b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationFactoryImpl.java index d9a977b8528..ecd84b9f59a 100644 --- a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationFactoryImpl.java +++ b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationFactoryImpl.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationCreator; import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationFactory; import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationProperty; -import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery; /** * {@link DeviceManagementOperationFactory} implementation @@ -40,11 +39,6 @@ public DeviceManagementOperationCreator newCreator(KapuaId scopeId) { return new DeviceManagementOperationCreatorImpl(scopeId); } - @Override - public DeviceManagementOperationQuery newQuery(KapuaId scopeId) { - return new DeviceManagementOperationQueryImpl(scopeId); - } - @Override public DeviceManagementOperationProperty newStepProperty(String name, String propertyType, String propertyValue) { return new DeviceManagementOperationPropertyImpl(name, propertyType, propertyValue); diff --git a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationQueryImpl.java b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationQueryImpl.java deleted file mode 100644 index cbc9aa3054d..00000000000 --- a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/internal/DeviceManagementOperationQueryImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.management.registry.operation.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationAttributes; -import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery; - -/** - * {@link DeviceManagementOperationQuery} implementation. - * - * @since 1.1.0 - */ -public class DeviceManagementOperationQueryImpl extends AbstractKapuaQuery implements DeviceManagementOperationQuery { - - /** - * Constructor. - * - * @since 1.1.0 - */ - private DeviceManagementOperationQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.1.0 - */ - public DeviceManagementOperationQueryImpl(KapuaId scopeId) { - this(); - - setScopeId(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(DeviceManagementOperationAttributes.STARTED_ON, SortOrder.ASCENDING); - } -} diff --git a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationFactoryImpl.java b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationFactoryImpl.java index 5140ad1768b..180b8ee32cc 100644 --- a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationFactoryImpl.java +++ b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotification; import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationCreator; import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationFactory; -import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationQuery; /** * {@link ManagementOperationNotificationFactory} implementation. @@ -38,11 +37,6 @@ public ManagementOperationNotificationCreator newCreator(KapuaId scopeId) { return new ManagementOperationNotificationCreatorImpl(scopeId); } - @Override - public ManagementOperationNotificationQuery newQuery(KapuaId scopeId) { - return new ManagementOperationNotificationQueryImpl(scopeId); - } - @Override public ManagementOperationNotification clone(ManagementOperationNotification managementOperationNotification) { return new ManagementOperationNotificationImpl(managementOperationNotification); diff --git a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationQueryImpl.java b/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationQueryImpl.java deleted file mode 100644 index eb34a1c1bfb..00000000000 --- a/service/device/management/registry/internal/src/main/java/org/eclipse/kapua/service/device/management/registry/operation/notification/internal/ManagementOperationNotificationQueryImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.management.registry.operation.notification.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationAttributes; -import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationQuery; - -/** - * {@link ManagementOperationNotificationQuery} implementation. - * - * @since 1.0.0 - */ -public class ManagementOperationNotificationQueryImpl extends AbstractKapuaQuery implements ManagementOperationNotificationQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private ManagementOperationNotificationQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public ManagementOperationNotificationQueryImpl(KapuaId scopeId) { - this(); - - setScopeId(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(ManagementOperationNotificationAttributes.SENT_ON, SortOrder.ASCENDING); - } -} diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceFactory.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceFactory.java index 6960844892b..a26482a45a9 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceFactory.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceFactory.java @@ -21,7 +21,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DeviceFactory extends KapuaEntityFactory { +public interface DeviceFactory extends KapuaEntityFactory { /** * Instantiates a new {@link DeviceCreator} diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceMatchPredicate.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceMatchPredicate.java index 7f2611aed25..33b23c9785d 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceMatchPredicate.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceMatchPredicate.java @@ -12,8 +12,34 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface DeviceMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; +public class DeviceMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 1.3.0 + */ + public DeviceMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + DeviceAttributes.CLIENT_ID, + DeviceAttributes.DISPLAY_NAME, + DeviceAttributes.SERIAL_NUMBER, + DeviceAttributes.MODEL_ID, + DeviceAttributes.MODEL_NAME, + DeviceAttributes.BIOS_VERSION, + DeviceAttributes.FIRMWARE_VERSION, + DeviceAttributes.OS_VERSION, + DeviceAttributes.JVM_VERSION, + DeviceAttributes.OSGI_FRAMEWORK_VERSION, + DeviceAttributes.APPLICATION_FRAMEWORK_VERSION, + DeviceAttributes.CONNECTION_INTERFACE, + DeviceAttributes.CONNECTION_IP + ); + this.matchTerm = matchTerm; + } } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceQuery.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceQuery.java index 69a0ed1f79c..8a7eff8c774 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceQuery.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceQuery.java @@ -12,13 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; + /** * {@link Device} {@link KapuaQuery} definition. * @@ -27,16 +30,47 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DeviceXmlRegistry.class, factoryMethod = "newQuery") -public interface DeviceQuery extends KapuaQuery { +@XmlType +public class DeviceQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + private DeviceQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public DeviceQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(DeviceAttributes.CLIENT_ID, SortOrder.ASCENDING); + } /** * Instantiates a new {@link DeviceMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link DeviceMatchPredicate}. * @since 1.3.0 */ - DeviceMatchPredicate matchPredicate(T matchTerm); + public DeviceMatchPredicate matchPredicate(T matchTerm) { + return new DeviceMatchPredicate<>(matchTerm); + } + } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceXmlRegistry.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceXmlRegistry.java index 36f44928f1d..e5b43d14d30 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceXmlRegistry.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/DeviceXmlRegistry.java @@ -46,10 +46,6 @@ public DeviceCreator newDeviceCreator() { return deviceFactory.newCreator(null, null); } - public DeviceQuery newQuery() { - return deviceFactory.newQuery(null); - } - /** * Instantiates a new {@link DeviceExtendedProperty}. * diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionFactory.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionFactory.java index a19a31be804..260dd0cee25 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionFactory.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DeviceConnectionFactory extends KapuaEntityFactory { +public interface DeviceConnectionFactory extends KapuaEntityFactory { } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionQuery.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionQuery.java index bed3e6c6c51..0f239d2effd 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionQuery.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionQuery.java @@ -12,13 +12,17 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.connection; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; +import org.eclipse.kapua.service.device.registry.DeviceAttributes; + /** * {@link DeviceConnection} {@link KapuaQuery} definition. * @@ -27,6 +31,32 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DeviceConnectionXmlRegistry.class, factoryMethod = "newQuery") -public interface DeviceConnectionQuery extends KapuaQuery { +@XmlType +public class DeviceConnectionQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + private DeviceConnectionQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public DeviceConnectionQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(DeviceAttributes.CLIENT_ID, SortOrder.ASCENDING); + } } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionXmlRegistry.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionXmlRegistry.java index d9b01446c9f..903d35de1b5 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionXmlRegistry.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/DeviceConnectionXmlRegistry.java @@ -35,7 +35,4 @@ public DeviceConnection newDeviceConnection() { return deviceConnectionFactory.newEntity(null); } - public DeviceConnectionQuery newQuery() { - return deviceConnectionFactory.newQuery(null); - } } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionFactory.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionFactory.java index 2c5ee017b0a..1235da32793 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionFactory.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DeviceConnectionOptionFactory extends KapuaEntityFactory { +public interface DeviceConnectionOptionFactory extends KapuaEntityFactory { } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionQuery.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionQuery.java deleted file mode 100644 index bae0cbe9cb8..00000000000 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionQuery.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.connection.option; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link DeviceConnectionOption} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DeviceConnectionOptionXmlRegistry.class, factoryMethod = "newQuery") -public interface DeviceConnectionOptionQuery extends KapuaQuery { - -} diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionXmlRegistry.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionXmlRegistry.java index 39c5b6fbf7d..054217e2de3 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionXmlRegistry.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/DeviceConnectionOptionXmlRegistry.java @@ -34,8 +34,4 @@ public class DeviceConnectionOptionXmlRegistry { public DeviceConnectionOption newDeviceConnectionOption() { return deviceConnectionOptionFactory.newEntity(null); } - - public DeviceConnectionOptionQuery newQuery() { - return deviceConnectionOptionFactory.newQuery(null); - } } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventFactory.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventFactory.java index 8ec7d44c5a8..77e03ff7784 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventFactory.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventFactory.java @@ -23,7 +23,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DeviceEventFactory extends KapuaEntityFactory { +public interface DeviceEventFactory extends KapuaEntityFactory { /** * Instantiates a new {@link DeviceEventCreator} diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventQuery.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventQuery.java index 3882d9c4392..9b0bd746300 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventQuery.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventQuery.java @@ -12,13 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.event; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; + /** * {@link DeviceEvent} {@link KapuaQuery} definition. * @@ -27,6 +30,32 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DeviceEventXmlRegistry.class, factoryMethod = "newQuery") -public interface DeviceEventQuery extends KapuaQuery { +@XmlType +public class DeviceEventQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + private DeviceEventQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public DeviceEventQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.DESCENDING); + } } diff --git a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventXmlRegistry.java b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventXmlRegistry.java index aff51f6f7ef..9e27e692688 100644 --- a/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventXmlRegistry.java +++ b/service/device/registry/api/src/main/java/org/eclipse/kapua/service/device/registry/event/DeviceEventXmlRegistry.java @@ -35,7 +35,4 @@ public DeviceEvent newDeviceEvent() { return deviceEventFactory.newEntity(null); } - public DeviceEventQuery newQuery() { - return deviceEventFactory.newQuery(null); - } } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java index bd018a85761..2dab06adbf7 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java @@ -168,7 +168,6 @@ DeviceValidation deviceValidation(KapuaDeviceRegistrySettings deviceRegistrySett DeviceConnectionService deviceConnectionService, DeviceEventService deviceEventService, DeviceRepository deviceRepository, - DeviceFactory deviceFactory, TagService tagService) { return new DeviceValidationImpl(deviceRegistrySettings.getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_VAR_FIELDS_LENGTH_MAX), deviceRegistrySettings.getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_EXTENDED_PROPERTIES_LENGTH_MAX), @@ -178,7 +177,6 @@ DeviceValidation deviceValidation(KapuaDeviceRegistrySettings deviceRegistrySett deviceConnectionService, deviceEventService, deviceRepository, - deviceFactory, tagService); } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/common/DeviceValidationImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/common/DeviceValidationImpl.java index 0cf7699141c..f836e166894 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/common/DeviceValidationImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/common/DeviceValidationImpl.java @@ -13,7 +13,8 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.common; -import com.google.common.base.Strings; +import java.util.List; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; @@ -31,7 +32,6 @@ import org.eclipse.kapua.service.device.registry.Device; import org.eclipse.kapua.service.device.registry.DeviceCreator; import org.eclipse.kapua.service.device.registry.DeviceExtendedProperty; -import org.eclipse.kapua.service.device.registry.DeviceFactory; import org.eclipse.kapua.service.device.registry.DeviceListResult; import org.eclipse.kapua.service.device.registry.DeviceQuery; import org.eclipse.kapua.service.device.registry.DeviceRegistryService; @@ -43,7 +43,7 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.storage.TxContext; -import java.util.List; +import com.google.common.base.Strings; /** * Logic used to validate preconditions required to execute the {@link DeviceRegistryServiceImpl} operations. @@ -60,7 +60,6 @@ public final class DeviceValidationImpl implements DeviceValidation { private final DeviceConnectionService deviceConnectionService; private final DeviceEventService deviceEventService; private final DeviceRepository deviceRepository; - private final DeviceFactory deviceFactory; private final TagService tagService; public DeviceValidationImpl( @@ -72,7 +71,6 @@ public DeviceValidationImpl( DeviceConnectionService deviceConnectionService, DeviceEventService deviceEventService, DeviceRepository deviceRepository, - DeviceFactory deviceFactory, TagService tagService) { this.birthFieldsClobMaxLength = birthFieldsClobMaxLength; this.birthFieldsExtendedPropertyValueMaxLength = birthFieldsExtendedPropertyValueMaxLength; @@ -82,17 +80,20 @@ public DeviceValidationImpl( this.deviceConnectionService = deviceConnectionService; this.deviceEventService = deviceEventService; this.deviceRepository = deviceRepository; - this.deviceFactory = deviceFactory; this.tagService = tagService; } /** * Validates the {@link DeviceCreator}. * - * @param deviceCreator The {@link DeviceCreator} to validate. - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the {@link DeviceCreator} fields is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param deviceCreator + * The {@link DeviceCreator} to validate. + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the {@link DeviceCreator} fields is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -265,10 +266,14 @@ public void validateCreatePreconditions(DeviceCreator deviceCreator) throws Kapu /** * Validates the {@link Device} for {@link DeviceRegistryService#update(KapuaUpdatableEntity)} operation. * - * @param device The {@link Device} to validate. - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the {@link Device} fields is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param device + * The {@link Device} to validate. + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the {@link Device} fields is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -455,11 +460,16 @@ public void validateUpdatePreconditions(TxContext txContext, Device device) thro /** * Validates the parameters for {@link DeviceRegistryService#find(KapuaId, KapuaId)} operation. * - * @param scopeId The {@link Device#getScopeId()} - * @param deviceId The {@link Device#getId()} - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the parameters is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param scopeId + * The {@link Device#getScopeId()} + * @param deviceId + * The {@link Device#getId()} + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the parameters is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -475,10 +485,14 @@ public void validateFindPreconditions(TxContext txContext, KapuaId scopeId, Kapu /** * Validates the {@link KapuaQuery} for {@link DeviceRegistryService#query(KapuaQuery)} operation. * - * @param query The {@link KapuaQuery} to validate. - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the {@link KapuaQuery} fields is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param query + * The {@link KapuaQuery} to validate. + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the {@link KapuaQuery} fields is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -500,10 +514,14 @@ public void validateQueryPreconditions(KapuaQuery query) throws KapuaException { /** * Validates the {@link KapuaQuery} for {@link DeviceRegistryService#count(KapuaQuery)} operation. * - * @param query The {@link KapuaQuery} to validate. - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the {@link KapuaQuery} fields is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param query + * The {@link KapuaQuery} to validate. + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the {@link KapuaQuery} fields is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -517,11 +535,16 @@ public void validateCountPreconditions(KapuaQuery query) throws KapuaException { /** * Validates the parameters for {@link DeviceRegistryService#delete(KapuaId, KapuaId)} operation. * - * @param scopeId The {@link Device#getScopeId()} - * @param deviceId The {@link Device#getId()} - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the parameters is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param scopeId + * The {@link Device#getScopeId()} + * @param deviceId + * The {@link Device#getId()} + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the parameters is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -537,11 +560,16 @@ public void validateDeletePreconditions(TxContext txContext, KapuaId scopeId, Ka /** * Validates the parameters for {@link DeviceRegistryService#findByClientId(KapuaId, String)} operation. * - * @param scopeId The {@link Device#getScopeId()} - * @param clientId The {@link Device#getClientId()} - * @throws org.eclipse.kapua.KapuaIllegalArgumentException if one of the parameters is invalid. - * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException if current {@link User} does not have sufficient {@link Permission}s - * @throws KapuaException if there are other errors. + * @param scopeId + * The {@link Device#getScopeId()} + * @param clientId + * The {@link Device#getClientId()} + * @throws org.eclipse.kapua.KapuaIllegalArgumentException + * if one of the parameters is invalid. + * @throws org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException + * if current {@link User} does not have sufficient {@link Permission}s + * @throws KapuaException + * if there are other errors. * @since 1.0.0 */ @Override @@ -555,14 +583,17 @@ public void validateFindByClientIdPreconditions(KapuaId scopeId, String clientId /** * Finds the current {@link Group} id assigned to the given {@link Device#getId()}. * - * @param scopeId The {@link Device#getScopeId()} - * @param entityId The {@link Device#getId()} + * @param scopeId + * The {@link Device#getScopeId()} + * @param entityId + * The {@link Device#getId()} * @return The {@link Group} id found. - * @throws KapuaException if any error occurs while looking for the Group. + * @throws KapuaException + * if any error occurs while looking for the Group. * @since 1.0.0 */ private KapuaId findCurrentGroupId(TxContext tx, KapuaId scopeId, KapuaId entityId) throws KapuaException { - DeviceQuery query = deviceFactory.newQuery(scopeId); + DeviceQuery query = new DeviceQuery(scopeId); query.setPredicate(query.attributePredicate(KapuaEntityAttributes.ENTITY_ID, entityId)); DeviceListResult results; diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionFactoryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionFactoryImpl.java index d1c1f083156..734022e1f10 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionFactoryImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.device.registry.connection.DeviceConnection; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionCreator; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionFactory; -import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery; /** * {@link DeviceConnectionFactory} implementation. @@ -34,11 +33,6 @@ public DeviceConnectionCreator newCreator(KapuaId scopeId) { return new DeviceConnectionCreatorImpl(scopeId); } - @Override - public DeviceConnectionQuery newQuery(KapuaId scopeId) { - return new DeviceConnectionQueryImpl(scopeId); - } - @Override public DeviceConnection newEntity(KapuaId scopeId) { return new DeviceConnectionImpl(scopeId); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionImplJpaRepository.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionImplJpaRepository.java index 2dd44dedb61..8af1a2ae703 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionImplJpaRepository.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionImplJpaRepository.java @@ -16,6 +16,7 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration; import org.eclipse.kapua.commons.jpa.KapuaUpdatableEntityJpaRepository; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.device.registry.connection.DeviceConnection; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionAttributes; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult; @@ -33,7 +34,7 @@ public DeviceConnectionImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepo @Override public long countByClientId(TxContext tx, KapuaId scopeId, String clientId) throws KapuaException { - final DeviceConnectionQuery query = new DeviceConnectionQueryImpl(scopeId); + final KapuaQuery query = new DeviceConnectionQuery(scopeId); query.setPredicate(query.attributePredicate(DeviceConnectionAttributes.CLIENT_ID, clientId)); return this.count(tx, query); } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionQueryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionQueryImpl.java deleted file mode 100644 index 2cbbd225ee1..00000000000 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionQueryImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.connection.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.device.registry.DeviceAttributes; -import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery; - -/** - * {@link DeviceConnectionQuery} implementation. - * - * @since 1.0.0 - */ -public class DeviceConnectionQueryImpl extends AbstractKapuaQuery implements DeviceConnectionQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private DeviceConnectionQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public DeviceConnectionQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(DeviceAttributes.CLIENT_ID, SortOrder.ASCENDING); - } -} diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionServiceImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionServiceImpl.java index a1c5744bae6..3b30d5994e1 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionServiceImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/internal/DeviceConnectionServiceImpl.java @@ -12,6 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.connection.internal; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.commons.lang.NotImplementedException; import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaEntityNotFoundException; @@ -43,12 +50,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.Map; -import java.util.Set; - /** * {@link DeviceConnectionService} implementation. * @@ -67,7 +68,8 @@ public class DeviceConnectionServiceImpl extends KapuaConfigurableServiceBase im /** * Constructor. * - * @param serviceConfigurationManager The {@link ServiceConfigurationManager} instance. + * @param serviceConfigurationManager + * The {@link ServiceConfigurationManager} instance. * @since 2.0.0 */ @Inject @@ -172,7 +174,7 @@ public DeviceConnection findByClientId(KapuaId scopeId, String clientId) ArgumentValidator.notEmptyOrNull(clientId, "clientId"); // Build query - DeviceConnectionQueryImpl query = new DeviceConnectionQueryImpl(scopeId); + DeviceConnectionQuery query = new DeviceConnectionQuery(scopeId); query.setPredicate(query.attributePredicate(DeviceConnectionAttributes.CLIENT_ID, clientId)); // Do find @@ -267,7 +269,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { // Private methods private void deleteConnectionByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - DeviceConnectionQuery query = entityFactory.newQuery(accountId); + DeviceConnectionQuery query = new DeviceConnectionQuery(accountId); txManager.execute(tx -> { final DeviceConnectionListResult deviceConnectionsToDelete = repository.query(tx, query); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionFactoryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionFactoryImpl.java index fb9249787ad..fb02d6595dd 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionFactoryImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOption; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionCreator; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionFactory; -import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionQuery; /** * {@link DeviceConnectionOptionFactory} implementation. @@ -34,11 +33,6 @@ public DeviceConnectionOptionCreator newCreator(KapuaId scopeId) { return new DeviceConnectionOptionCreatorImpl(scopeId); } - @Override - public DeviceConnectionOptionQuery newQuery(KapuaId scopeId) { - return new DeviceConnectionOptionQueryImpl(scopeId); - } - @Override public DeviceConnectionOption newEntity(KapuaId scopeId) { return new DeviceConnectionOptionImpl(scopeId); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionQueryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionQueryImpl.java deleted file mode 100644 index fd4ca1102d1..00000000000 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.connection.option.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionQuery; - -/** - * {@link DeviceConnectionOptionQuery} implementation. - * - * @since 1.0.0 - */ -public class DeviceConnectionOptionQueryImpl extends AbstractKapuaQuery implements DeviceConnectionOptionQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private DeviceConnectionOptionQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public DeviceConnectionOptionQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionServiceImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionServiceImpl.java index b3a15a5c37e..0cbaa1e382c 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionServiceImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/connection/option/internal/DeviceConnectionOptionServiceImpl.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.connection.option.internal; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.KapuaIllegalArgumentException; @@ -29,7 +34,6 @@ import org.eclipse.kapua.service.device.authentication.api.DeviceConnectionCredentialAdapter; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionAttributes; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionFactory; -import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery; import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionRepository; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOption; import org.eclipse.kapua.service.device.registry.connection.option.DeviceConnectionOptionCreator; @@ -39,13 +43,8 @@ import org.eclipse.kapua.service.device.registry.connection.option.UserAlreadyReservedException; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.Map; - /** - * DeviceConnectionService exposes APIs to retrieve Device connections under a scope. - * It includes APIs to find, list, and update devices connections associated with a scope. + * DeviceConnectionService exposes APIs to retrieve Device connections under a scope. It includes APIs to find, list, and update devices connections associated with a scope. * * @since 1.0 */ @@ -98,7 +97,7 @@ public DeviceConnectionOption update(DeviceConnectionOption deviceConnectionOpti authorizationService.checkPermission(permissionFactory.newPermission(Domains.DEVICE_CONNECTION, Actions.write, deviceConnectionOptions.getScopeId())); return txManager.execute(tx -> { if (deviceConnectionOptions.getReservedUserId() != null) { - DeviceConnectionQuery query = entityFactory.newQuery(deviceConnectionOptions.getScopeId()); + final KapuaQuery query = new KapuaQuery(deviceConnectionOptions.getScopeId()); AndPredicate deviceAndPredicate = query.andPredicate( query.attributePredicate(DeviceConnectionAttributes.RESERVED_USER_ID, deviceConnectionOptions.getReservedUserId()), diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventFactoryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventFactoryImpl.java index 1011a7d50f4..0d7df1645b7 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventFactoryImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventFactoryImpl.java @@ -21,7 +21,6 @@ import org.eclipse.kapua.service.device.registry.event.DeviceEvent; import org.eclipse.kapua.service.device.registry.event.DeviceEventCreator; import org.eclipse.kapua.service.device.registry.event.DeviceEventFactory; -import org.eclipse.kapua.service.device.registry.event.DeviceEventQuery; /** * {@link DeviceEventFactory} implementation. @@ -43,11 +42,6 @@ public DeviceEventCreator newCreator(KapuaId scopeId, KapuaId deviceId, Date rec return creator; } - @Override - public DeviceEventQuery newQuery(KapuaId scopeId) { - return new DeviceEventQueryImpl(scopeId); - } - @Override public DeviceEvent newEntity(KapuaId scopeId) { return new DeviceEventImpl(scopeId); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventQueryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventQueryImpl.java deleted file mode 100644 index a4b95d55674..00000000000 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/event/internal/DeviceEventQueryImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.event.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.device.registry.event.DeviceEventAttributes; -import org.eclipse.kapua.service.device.registry.event.DeviceEventQuery; - -/** - * {@link DeviceEventQuery} implementation. - * - * @since 1.0.0 - */ -public class DeviceEventQueryImpl extends AbstractKapuaQuery implements DeviceEventQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private DeviceEventQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public DeviceEventQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.DESCENDING); - } -} diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceFactoryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceFactoryImpl.java index b4483e0f333..31eabc7398c 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceFactoryImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceFactoryImpl.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.service.device.registry.DeviceCreator; import org.eclipse.kapua.service.device.registry.DeviceExtendedProperty; import org.eclipse.kapua.service.device.registry.DeviceFactory; -import org.eclipse.kapua.service.device.registry.DeviceQuery; /** * {@link DeviceFactory} implementation. @@ -37,11 +36,6 @@ public DeviceCreator newCreator(KapuaId scopeId, String clientId) { return deviceCreator; } - @Override - public DeviceQuery newQuery(KapuaId scopeId) { - return new DeviceQueryImpl(scopeId); - } - @Override public Device newEntity(KapuaId scopeId) { return new DeviceImpl(scopeId); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceImplJpaRepository.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceImplJpaRepository.java index 503a877deb1..ef67ed8483b 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceImplJpaRepository.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceImplJpaRepository.java @@ -25,6 +25,7 @@ import org.eclipse.kapua.service.device.registry.Device; import org.eclipse.kapua.service.device.registry.DeviceAttributes; import org.eclipse.kapua.service.device.registry.DeviceListResult; +import org.eclipse.kapua.service.device.registry.DeviceQuery; import org.eclipse.kapua.service.device.registry.DeviceRepository; import org.eclipse.kapua.storage.TxContext; @@ -40,7 +41,7 @@ public DeviceImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepoConfig) { @Override public Optional findByClientId(TxContext tx, KapuaId scopeId, String clientId) throws KapuaException { - DeviceQueryImpl query = new DeviceQueryImpl(scopeId); + DeviceQuery query = new DeviceQuery(scopeId); query.setPredicate(query.attributePredicate(DeviceAttributes.CLIENT_ID, clientId)); query.setFetchAttributes(Lists.newArrayList(DeviceAttributes.CONNECTION, DeviceAttributes.LAST_EVENT)); return Optional.ofNullable(this.query(tx, query).getFirstItem()); diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceMatchPredicateImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceMatchPredicateImpl.java deleted file mode 100644 index 6d3d69ee361..00000000000 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceMatchPredicateImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.internal; - -import java.util.Arrays; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.device.registry.DeviceAttributes; -import org.eclipse.kapua.service.device.registry.DeviceMatchPredicate; - -public class DeviceMatchPredicateImpl extends AbstractMatchPredicate implements DeviceMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 1.3.0 - */ - public DeviceMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - DeviceAttributes.CLIENT_ID, - DeviceAttributes.DISPLAY_NAME, - DeviceAttributes.SERIAL_NUMBER, - DeviceAttributes.MODEL_ID, - DeviceAttributes.MODEL_NAME, - DeviceAttributes.BIOS_VERSION, - DeviceAttributes.FIRMWARE_VERSION, - DeviceAttributes.OS_VERSION, - DeviceAttributes.JVM_VERSION, - DeviceAttributes.OSGI_FRAMEWORK_VERSION, - DeviceAttributes.APPLICATION_FRAMEWORK_VERSION, - DeviceAttributes.CONNECTION_INTERFACE, - DeviceAttributes.CONNECTION_IP - ); - this.matchTerm = matchTerm; - } - -} diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceQueryImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceQueryImpl.java deleted file mode 100644 index d1695ccb916..00000000000 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceQueryImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.device.registry.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.device.registry.DeviceAttributes; -import org.eclipse.kapua.service.device.registry.DeviceQuery; - -/** - * {@link DeviceQuery} implementation. - * - * @since 1.0.0 - */ -public class DeviceQueryImpl extends AbstractKapuaQuery implements DeviceQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private DeviceQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public DeviceQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(DeviceAttributes.CLIENT_ID, SortOrder.ASCENDING); - } - - @Override - public DeviceMatchPredicateImpl matchPredicate(T matchTerm) { - return new DeviceMatchPredicateImpl<>(matchTerm); - } - -} diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceRegistryServiceImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceRegistryServiceImpl.java index 1020ecaed77..1c0c5ce75be 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceRegistryServiceImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/internal/DeviceRegistryServiceImpl.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.internal; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.KapuaConfigurableServiceBase; @@ -37,10 +41,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - /** * {@link DeviceRegistryService} implementation. * @@ -85,7 +85,7 @@ public Device create(DeviceCreator deviceCreator) // Check entity limit serviceConfigurationManager.checkAllowedEntities(tx, deviceCreator.getScopeId(), "Devices"); // Check duplicate clientId - DeviceQuery query = entityFactory.newQuery(deviceCreator.getScopeId()); + DeviceQuery query = new DeviceQuery(deviceCreator.getScopeId()); query.setPredicate(query.attributePredicate(DeviceAttributes.CLIENT_ID, deviceCreator.getClientId())); //TODO: check whether this is anywhere efficient if (deviceRepository.count(tx, query) > 0) { @@ -210,7 +210,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { // Private methods private void deleteDeviceByGroupId(KapuaId scopeId, KapuaId groupId) throws KapuaException { - DeviceQuery query = entityFactory.newQuery(scopeId); + DeviceQuery query = new DeviceQuery(scopeId); query.setPredicate(query.attributePredicate(DeviceAttributes.GROUP_ID, groupId)); txManager.execute(tx -> { @@ -225,7 +225,7 @@ private void deleteDeviceByGroupId(KapuaId scopeId, KapuaId groupId) throws Kapu } private void deleteDeviceByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - DeviceQuery query = entityFactory.newQuery(accountId); + DeviceQuery query = new DeviceQuery(accountId); txManager.execute(tx -> { DeviceListResult devicesToDelete = deviceRepository.query(tx, query); diff --git a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/DeviceRegistrySteps.java b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/DeviceRegistrySteps.java index 0f70b334561..ed59d9a3b03 100644 --- a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/DeviceRegistrySteps.java +++ b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/DeviceRegistrySteps.java @@ -467,13 +467,13 @@ public void setDeviceIdToNull() { @Given("A regular query") public void createRegularQuery() { - DeviceQuery query = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery query = new DeviceQuery(getCurrentScopeId()); stepData.put(DEVICE_QUERY, query); } @Given("A query with a null Scope ID") public void createQueryWithNullScopeId() { - DeviceQuery query = deviceFactory.newQuery(null); + DeviceQuery query = new DeviceQuery(null); stepData.put(DEVICE_QUERY, query); } @@ -638,7 +638,7 @@ public void queryForDevices() throws Exception { @When("I query for devices with BIOS version {string}") public void queryForDevicesBasedOnBiosVersion(String version) throws Exception { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); // Search for the known bios version string tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL)); primeException(); @@ -653,7 +653,7 @@ public void queryForDevicesBasedOnBiosVersion(String version) throws Exception { @When("I query for devices with BIOS different from {string}") public void queryForDevicesWithDifferentBiosVersion(String version) throws Exception { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); // Search for the known bios version string tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL)); primeException(); @@ -668,7 +668,7 @@ public void queryForDevicesWithDifferentBiosVersion(String version) throws Excep @When("I query for devices with Client Id {string}") public void queryForDevicesBasedOnClientId(String id) throws Exception { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); // Search for the known bios version string tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, id, AttributePredicate.Operator.EQUAL)); primeException(); @@ -696,12 +696,12 @@ public void countForDevices() throws Exception { @When("I count the devices in scope {int}") public void countDevicesInScope(int scope) throws Exception { - updateCount(() -> (int) deviceRegistryService.count(deviceFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) deviceRegistryService.count(new DeviceQuery(getKapuaId(scope)))); } @When("I count devices with BIOS version {string}") public void countDevicesWithBIOSVersion(String version) throws Exception { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.BIOS_VERSION, version, AttributePredicate.Operator.EQUAL)); updateCount(() -> (int) deviceRegistryService.count(tmpQuery)); } @@ -761,7 +761,7 @@ public void deleteDeviceWithRememberedId() throws Exception { public void deleteDeviceWithClientId(String clientId) throws Exception { try { primeException(); - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, clientId, AttributePredicate.Operator.EQUAL)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); Device device = deviceList.getFirstItem(); @@ -1002,7 +1002,7 @@ public void exerciseAllDeviceFactoryFunctions() { DeviceListResult tmpListRes; tmpDevice = deviceFactory.newEntity(SYS_SCOPE_ID); tmpCreator = deviceFactory.newCreator(SYS_SCOPE_ID); - tmpQuery = deviceFactory.newQuery(SYS_SCOPE_ID); + tmpQuery = new DeviceQuery(SYS_SCOPE_ID); tmpListRes = new DeviceListResult(); Assert.assertNotNull(tmpDevice); Assert.assertNotNull(tmpCreator); @@ -1216,7 +1216,7 @@ public void checkDeviceConnectionStatus(String status) { @Then("I count {int} connections in scope {int}") public void countConnectioncInScope(int target, int scope) throws Exception { - updateCountAndCheck(() -> (int) deviceConnectionService.count(deviceConnectionFactory.newQuery(getKapuaId(scope))), target); + updateCountAndCheck(() -> (int) deviceConnectionService.count(new DeviceConnectionQuery(getKapuaId(scope))), target); } @When("I search for a connection by scope and connection IDs") @@ -1282,7 +1282,7 @@ public void deleteRandomConnection() throws Exception { @When("I query for all connections with the parameter {string} set to {string}") public void queryForConnections(String parameter, String value) throws Exception { - DeviceConnectionQuery query = deviceConnectionFactory.newQuery(getCurrentScopeId()); + DeviceConnectionQuery query = new DeviceConnectionQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(parameter, value, AttributePredicate.Operator.EQUAL)); primeException(); try { @@ -1341,7 +1341,7 @@ public void exerciseAllConnectionFactoryFunctions() { DeviceConnectionCreator tmpCreator = null; DeviceConnectionQuery tmpQuery = null; tmpCreator = deviceConnectionFactory.newCreator(SYS_SCOPE_ID); - tmpQuery = deviceConnectionFactory.newQuery(SYS_SCOPE_ID); + tmpQuery = new DeviceConnectionQuery(SYS_SCOPE_ID); Assert.assertNotNull(tmpCreator); Assert.assertNotNull(tmpQuery); } @@ -1463,12 +1463,12 @@ public void deleteEventWithRandomId() throws Exception { @When("I count events for scope {int}") public void countEventsInScope(int scpId) throws Exception { - updateCount(() -> (int) eventService.count(eventFactory.newQuery(getKapuaId(scpId)))); + updateCount(() -> (int) eventService.count(new DeviceEventQuery(getKapuaId(scpId)))); } @When("I query for {string} events") public void queryForSpecificEvents(String eventType) throws Exception { - DeviceEventQuery tmpQuery = eventFactory.newQuery(getCurrentScopeId()); + DeviceEventQuery tmpQuery = new DeviceEventQuery(getCurrentScopeId()); Assert.assertNotNull(tmpQuery); KapuaMethod tmpMeth = getMethodFromString(eventType); Assert.assertNotNull(tmpMeth); @@ -1510,7 +1510,7 @@ public void searchForEventsGreaterFromDeviceWithClientID(String clientId, String Assert.assertNotNull(account); Device device = deviceRegistryService.findByClientId(account.getId(), clientId); Assert.assertNotNull(device); - DeviceEventQuery eventQuery = eventFactory.newQuery(account.getId()); + DeviceEventQuery eventQuery = new DeviceEventQuery(account.getId()); eventQuery.setPredicate(eventQuery.attributePredicate(DeviceEventAttributes.DEVICE_ID, device.getId(), AttributePredicate.Operator.EQUAL)); eventQuery.setSortCriteria(eventQuery.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.ASCENDING)); DeviceEventListResult deviceEventList = eventService.query(eventQuery); @@ -1550,7 +1550,7 @@ private void searchForEventsFromDeviceWithClientIDInternal(String clientId, Stri private boolean searchForEventsFromDeviceWithClientID(Account account, Device device, int events, boolean timeoutOccurred, boolean greater) throws Exception { DeviceEventListResult deviceEventList = null; try { - DeviceEventQuery eventQuery = eventFactory.newQuery(account.getId()); + DeviceEventQuery eventQuery = new DeviceEventQuery(account.getId()); eventQuery.setPredicate(eventQuery.attributePredicate(DeviceEventAttributes.DEVICE_ID, device.getId(), AttributePredicate.Operator.EQUAL)); eventQuery.setSortCriteria(eventQuery.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.ASCENDING)); deviceEventList = eventService.query(eventQuery); @@ -1636,7 +1636,7 @@ public void exerciseAllEventFactoryFunctions() { DeviceEventListResult tmpList = null; tmpEvent = eventFactory.newEntity(SYS_SCOPE_ID); tmpCreator = eventFactory.newCreator(SYS_SCOPE_ID, getKapuaId(), new Date(), ""); - tmpQuery = eventFactory.newQuery(SYS_SCOPE_ID); + tmpQuery = new DeviceEventQuery(SYS_SCOPE_ID); tmpList = new DeviceEventListResult(); Assert.assertNotNull(tmpEvent); Assert.assertNotNull(tmpCreator); @@ -1704,8 +1704,8 @@ public void iTagDeviceWithTag(String deviceTagName) throws Exception { @When("I search for device with tag {string}") public void iSearchForDeviceWithTag(String deviceTagName) throws Exception { Account lastAcc = (Account) stepData.get(LAST_ACCOUNT); - DeviceQuery deviceQuery = deviceFactory.newQuery(lastAcc.getId()); - TagQuery tagQuery = tagFactory.newQuery(lastAcc.getId()); + DeviceQuery deviceQuery = new DeviceQuery(lastAcc.getId()); + TagQuery tagQuery = new TagQuery(lastAcc.getId()); tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, deviceTagName, AttributePredicate.Operator.EQUAL)); primeException(); try { @@ -2252,7 +2252,7 @@ private KapuaMethod getMethodFromString(String name) { } private Device getDeviceWithClientId(String clientId) throws KapuaException { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, clientId)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); @@ -2562,7 +2562,7 @@ public void iSearchForEventsFromDevicesInAccount(String account, int eventsNum) tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), device.getClientId()); Assert.assertNotNull(tmpDev); Assert.assertNotNull(tmpDev.getId()); - tmpQuery = eventFactory.newQuery(tmpAcc.getId()); + tmpQuery = new DeviceEventQuery(tmpAcc.getId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceEventAttributes.DEVICE_ID, tmpDev.getId(), AttributePredicate.Operator.EQUAL)); tmpQuery.setSortCriteria(tmpQuery.fieldSortCriteria(DeviceEventAttributes.RECEIVED_ON, SortOrder.ASCENDING)); tmpList = eventService.query(tmpQuery); @@ -2594,11 +2594,11 @@ public void iAssignTagToDevice() throws Exception { @And("I assign tag {string} to device {string}") public void iAssignTagNamedToDevice(String tagName, String deviceName) throws Exception { try { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); Device device = deviceList.getFirstItem(); - TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId()); + TagQuery tagQuery = new TagQuery(getCurrentScopeId()); tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult tagList = tagService.query(tagQuery); Tag tag = tagList.getFirstItem(); @@ -2615,10 +2615,10 @@ public void iAssignTagNamedToDevice(String tagName, String deviceName) throws Ex @And("I add device {string} to group {string}") public void iAddDeviceToGroup(String deviceName, String groupName) throws Exception { try { - GroupQuery query = groupFactory.newQuery(getCurrentScopeId()); + GroupQuery query = new GroupQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); Group foundGroup = groupService.query(query).getFirstItem(); - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); Device device = deviceRegistryService.query(tmpQuery).getFirstItem(); KapuaId groupId = foundGroup.getId(); @@ -2645,11 +2645,11 @@ public void iTryToEditDevicesDisplayNameTo(String displayName) throws Exception @Given("Tag {string} is assigned to device {string}") public void tagIsAssignedToDevice(String tagName, String deviceName) throws Throwable { try { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); Device device = deviceList.getFirstItem(); - TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId()); + TagQuery tagQuery = new TagQuery(getCurrentScopeId()); tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult tagList = tagService.query(tagQuery); Tag tag = tagList.getFirstItem(); @@ -2663,7 +2663,7 @@ public void tagIsAssignedToDevice(String tagName, String deviceName) throws Thro @When("I remove device {string} from all groups") public void iChangeDevicesGroupToNoGroup(String deviceName) throws Exception { try { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); Device device = deviceRegistryService.query(tmpQuery).getFirstItem(); device.setGroupId(null); @@ -2706,11 +2706,11 @@ public void iCreateDevicesAndAddThemToGroup(int numberOfDevices, String groupNam @Given("I unassign tag {string} from device {string}") public void iUnassignTagNamedFromDevice(String tagName, String deviceName) throws Exception { try { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); Device device = deviceList.getFirstItem(); - TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId()); + TagQuery tagQuery = new TagQuery(getCurrentScopeId()); tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult tagList = tagService.query(tagQuery); Tag tag = tagList.getFirstItem(); @@ -2727,10 +2727,10 @@ public void iUnassignTagNamedFromDevice(String tagName, String deviceName) throw @Then("Device {string} is in Assigned Devices of group {string}") public void deviceIsInGroupsAssignedDevices(String deviceName, String groupName) throws Exception { try { - GroupQuery query = groupFactory.newQuery(getCurrentScopeId()); + GroupQuery query = new GroupQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); Group foundGroup = groupService.query(query).getFirstItem(); - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); Device device = deviceRegistryService.query(tmpQuery).getFirstItem(); KapuaId expectedGroupId = foundGroup.getId(); @@ -3181,11 +3181,11 @@ public void iChangeDeviceExtendedPropertiesTo(List cu @Given("Tag {string} is not assigned to device {string}") public void tagWithNameIsNotAssignedToDevice(String tagName, String deviceName) throws Throwable { try { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); DeviceListResult deviceList = deviceRegistryService.query(tmpQuery); Device device = deviceList.getFirstItem(); - TagQuery tagQuery = tagFactory.newQuery(getCurrentScopeId()); + TagQuery tagQuery = new TagQuery(getCurrentScopeId()); tagQuery.setPredicate(tagQuery.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult tagList = tagService.query(tagQuery); Tag tag = tagList.getFirstItem(); @@ -3199,10 +3199,10 @@ public void tagWithNameIsNotAssignedToDevice(String tagName, String deviceName) @Then("Device {string} is not in Assigned Devices of group {string}") public void deviceIsNotInGroupsAssignedDevices(String deviceName, String groupName) throws Exception { try { - GroupQuery query = groupFactory.newQuery(getCurrentScopeId()); + GroupQuery query = new GroupQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(GroupAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); Group foundGroup = groupService.query(query).getFirstItem(); - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceName, AttributePredicate.Operator.EQUAL)); Device device = deviceRegistryService.query(tmpQuery).getFirstItem(); KapuaId expectedGroupId = foundGroup.getId(); @@ -3218,91 +3218,91 @@ public void iFilterDevices(List parameters) throws Exception { DeviceListResult devices; stepData.remove("DeviceList"); if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE)); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE)); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE)); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE)); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() == null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() == null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() == null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() == null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.STATUS, deviceParams.getStatus(), AttributePredicate.Operator.LIKE))); devices = deviceRegistryService.query(tmpQuery); stepData.put("DeviceList", devices); } else if (deviceParams.getClientId() != null && deviceParams.getDisplayName() != null && deviceParams.getSerialNumber() != null && deviceParams.getStatus() != null) { - DeviceQuery tmpQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery tmpQuery = new DeviceQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.andPredicate(tmpQuery.attributePredicate(DeviceAttributes.SERIAL_NUMBER, deviceParams.getSerialNumber(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.DISPLAY_NAME, deviceParams.getDisplayName(), AttributePredicate.Operator.LIKE), tmpQuery.attributePredicate(DeviceAttributes.CLIENT_ID, deviceParams.getClientId(), AttributePredicate.Operator.LIKE), @@ -3317,7 +3317,7 @@ public void iSearchForADeviceWithName(String clientID) throws Throwable { try { stepData.remove(DEVICE); primeException(); - DeviceQuery query = deviceFactory.newQuery(SYS_SCOPE_ID); + DeviceQuery query = new DeviceQuery(SYS_SCOPE_ID); query.setPredicate(query.attributePredicate(DeviceAttributes.CLIENT_ID, clientID, AttributePredicate.Operator.EQUAL)); DeviceListResult queryResult = deviceRegistryService.query(query); Device foundDevice = queryResult.getFirstItem(); diff --git a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java index 8064339b11b..f3438a2b069 100644 --- a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java +++ b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java @@ -12,13 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.test; -import com.codahale.metrics.MetricRegistry; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Singleton; -import com.google.inject.name.Names; -import io.cucumber.java.Before; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountRelativeFinder; import org.eclipse.kapua.commons.configuration.RootUserTester; @@ -87,8 +83,14 @@ import org.mockito.Matchers; import org.mockito.Mockito; -import java.util.HashMap; -import java.util.Map; +import com.codahale.metrics.MetricRegistry; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Singleton; +import com.google.inject.name.Names; + +import io.cucumber.java.Before; @Singleton public class DeviceRegistryLocatorConfiguration { @@ -180,7 +182,8 @@ protected void configure() { bind(DeviceEventFactory.class).toInstance(new DeviceEventFactoryImpl()); bind(KapuaMessageFactory.class).toInstance(new KapuaMessageFactoryImpl()); - final DeviceValidation deviceValidation = new DeviceValidationImpl(new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_VAR_FIELDS_LENGTH_MAX), + final DeviceValidation deviceValidation = new DeviceValidationImpl( + new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_VAR_FIELDS_LENGTH_MAX), new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_EXTENDED_PROPERTIES_LENGTH_MAX), mockedAuthorization, permissionFactory, @@ -188,7 +191,6 @@ protected void configure() { deviceConnectionService, deviceEventService, new DeviceImplJpaRepository(jpaRepoConfig), - new DeviceFactoryImpl(), new TagServiceImpl( permissionFactory, mockedAuthorization, diff --git a/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoFactory.java b/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoFactory.java index 73f8dd57b48..60e9b2515f0 100644 --- a/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoFactory.java +++ b/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoFactory.java @@ -13,13 +13,14 @@ package org.eclipse.kapua.service.endpoint; import org.eclipse.kapua.model.KapuaEntityFactory; +import org.eclipse.kapua.model.id.KapuaId; /** * {@link EndpointInfoFactory} definition. * * @since 1.0.0 */ -public interface EndpointInfoFactory extends KapuaEntityFactory { +public interface EndpointInfoFactory extends KapuaEntityFactory { /** * Instantiates a new {@link EndpointUsage}. @@ -30,4 +31,7 @@ public interface EndpointInfoFactory extends KapuaEntityFactory extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; +public class EndpointInfoMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public EndpointInfoMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + EndpointInfoAttributes.SCHEMA, + EndpointInfoAttributes.DNS + ); + this.matchTerm = matchTerm; + } } diff --git a/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoQuery.java b/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoQuery.java index 8e0fcf05e6d..9d4a9503310 100644 --- a/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoQuery.java +++ b/service/endpoint/api/src/main/java/org/eclipse/kapua/service/endpoint/EndpointInfoQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.endpoint; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link EndpointInfo} {@link KapuaQuery} definition. * @@ -28,14 +29,30 @@ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) @XmlType(factoryClass = EndpointInfoXmlRegistry.class, factoryMethod = "newQuery") -public interface EndpointInfoQuery extends KapuaQuery { +public class EndpointInfoQuery extends KapuaQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public EndpointInfoQuery(KapuaId scopeId) { + super(scopeId); + } + /** * Instantiates a new {@link EndpointInfoMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link EndpointInfoMatchPredicate}. * @since 2.1.0 */ - EndpointInfoMatchPredicate matchPredicate(T matchTerm); + public EndpointInfoMatchPredicate matchPredicate(T matchTerm) { + return new EndpointInfoMatchPredicate<>(matchTerm); + } } diff --git a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoFactoryImpl.java b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoFactoryImpl.java index 4b2d655a7b8..619afaa71fe 100644 --- a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoFactoryImpl.java +++ b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoFactoryImpl.java @@ -37,7 +37,7 @@ public EndpointInfo newEntity(KapuaId scopeId) { @Override public EndpointInfoQuery newQuery(KapuaId scopeId) { - return new EndpointInfoQueryImpl(scopeId); + return new EndpointInfoQuery(scopeId); } @Override diff --git a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java deleted file mode 100644 index f239431346f..00000000000 --- a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoMatchPredicateImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.endpoint.internal; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.endpoint.EndpointInfoAttributes; -import org.eclipse.kapua.service.endpoint.EndpointInfoMatchPredicate; - -import java.util.Arrays; - -public class EndpointInfoMatchPredicateImpl extends AbstractMatchPredicate implements EndpointInfoMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 2.1.0 - */ - public EndpointInfoMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - EndpointInfoAttributes.SCHEMA, - EndpointInfoAttributes.DNS - ); - this.matchTerm = matchTerm; - } - -} diff --git a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java deleted file mode 100644 index 7ceed548388..00000000000 --- a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoQueryImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.endpoint.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.endpoint.EndpointInfoMatchPredicate; -import org.eclipse.kapua.service.endpoint.EndpointInfoQuery; - -/** - * {@link EndpointInfoQuery} implementation. - * - * @since 1.0.0 - */ -public class EndpointInfoQueryImpl extends AbstractKapuaQuery implements EndpointInfoQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public EndpointInfoQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public EndpointInfoMatchPredicate matchPredicate(T matchTerm) { - return new EndpointInfoMatchPredicateImpl<>(matchTerm); - } -} diff --git a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoServiceImpl.java b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoServiceImpl.java index 11a4a8bc75a..ab6cd8f5b5c 100644 --- a/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoServiceImpl.java +++ b/service/endpoint/internal/src/main/java/org/eclipse/kapua/service/endpoint/internal/EndpointInfoServiceImpl.java @@ -12,6 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.endpoint.internal; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaEntityUniquenessException; import org.eclipse.kapua.KapuaException; @@ -41,14 +50,6 @@ import org.eclipse.kapua.storage.TxContext; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Predicate; - /** * {@link EndpointInfoService} implementation. * @@ -57,6 +58,7 @@ @Singleton public class EndpointInfoServiceImpl implements EndpointInfoService { + private final AuthorizationService authorizationService; private final PermissionFactory permissionFactory; private final EndpointInfoFactory endpointInfoFactory; @@ -207,7 +209,8 @@ public EndpointInfo find(KapuaId scopeId, KapuaId endpointInfoId) EndpointInfoQuery query = endpointInfoFactory.newQuery(scopeId); EndpointInfoListResult nearestUsableEndpoints = doQuery(tx, query, type); - if (nearestUsableEndpoints.isEmpty() || !nearestUsableEndpoints.getFirstItem().getScopeId().equals(endpointInfoToFind.getScopeId())) { //the second condition is equivalent to verify if the searched endpoint is in this list + if (nearestUsableEndpoints.isEmpty() || !nearestUsableEndpoints.getFirstItem().getScopeId() + .equals(endpointInfoToFind.getScopeId())) { //the second condition is equivalent to verify if the searched endpoint is in this list throw new KapuaEntityNotFoundException(EndpointInfo.TYPE, endpointInfoId); } else { return endpointInfoToFind; @@ -266,7 +269,6 @@ private EndpointInfoListResult doQuery(TxContext tx, KapuaQuery query, String se ); } - // // Private methods and interfaces // @@ -275,19 +277,23 @@ private EndpointInfoListResult doQuery(TxContext tx, KapuaQuery query, String se //to overcome this, I created this interface which is a custom form of a Bifunction throwing the checked KapuaException @FunctionalInterface public interface kapuaBiFunction { + R apply(A input1, B input2) throws KapuaException; } - /** - * Traverse the account hierarchy bottom-up to search for {@link EndpointInfo} respecting the given query, - * performing for each layer the given queryExecutor until the given isEmptyResult dictates to stop OR when endpoints of the same section are found in one layer - * In other terms, this method applies a given function to the "nearest usable endpoints", aka the ones that I see in a given scopeID + * Traverse the account hierarchy bottom-up to search for {@link EndpointInfo} respecting the given query, performing for each layer the given queryExecutor until the given isEmptyResult dictates + * to stop OR when endpoints of the same section are found in one layer In other terms, this method applies a given function to the "nearest usable endpoints", aka the ones that I see in a given + * scopeID * - * @param query The query to filter the {@link EndpointInfo}s. - * @param section section of {@link EndpointInfo} where we want to search the information - * @param queryExecutor function to apply at each layer - * @param isEmptyResult predicate that dictates to stop the traversal when false + * @param query + * The query to filter the {@link EndpointInfo}s. + * @param section + * section of {@link EndpointInfo} where we want to search the information + * @param queryExecutor + * function to apply at each layer + * @param isEmptyResult + * predicate that dictates to stop the traversal when false */ protected R traverse( TxContext tx, @@ -337,18 +343,25 @@ protected R traverse( /** * Checks whether another {@link EndpointInfo} already exists with the given values. * - * @param scopeId The ScopeId of the {@link EndpointInfo} - * @param entityId The entity id, if exists. On update you need to exclude the same entity. - * @param schema The {@link EndpointInfo#getSchema()} value. - * @param dns The {@link EndpointInfo#getDns()} value. - * @param port The {@link EndpointInfo#getPort()} value. - * @param type The {@link EndpointInfo#getEndpointType()} value. - * @throws KapuaException if the values provided matches another {@link EndpointInfo} + * @param scopeId + * The ScopeId of the {@link EndpointInfo} + * @param entityId + * The entity id, if exists. On update you need to exclude the same entity. + * @param schema + * The {@link EndpointInfo#getSchema()} value. + * @param dns + * The {@link EndpointInfo#getDns()} value. + * @param port + * The {@link EndpointInfo#getPort()} value. + * @param type + * The {@link EndpointInfo#getEndpointType()} value. + * @throws KapuaException + * if the values provided matches another {@link EndpointInfo} * @since 1.0.0 */ private void checkDuplicateEndpointInfo(KapuaId scopeId, KapuaId entityId, String schema, String dns, int port, String type) throws KapuaException { - EndpointInfoQuery query = new EndpointInfoQueryImpl(scopeId); + EndpointInfoQuery query = new EndpointInfoQuery(scopeId); AndPredicate andPredicate = query.andPredicate( query.attributePredicate(EndpointInfoAttributes.SCHEMA, schema), diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobFactory.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobFactory.java index 7b985707f04..cf2f8e13a25 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobFactory.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface JobFactory extends KapuaEntityFactory { +public interface JobFactory extends KapuaEntityFactory { } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobMatchPredicate.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobMatchPredicate.java index 36c38f2d7a1..d11329a8c7b 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobMatchPredicate.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobMatchPredicate.java @@ -12,8 +12,24 @@ *******************************************************************************/ package org.eclipse.kapua.service.job; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface JobMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; + +public class JobMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.0.0 + */ + public JobMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + JobAttributes.NAME, + JobAttributes.DESCRIPTION + ); + this.matchTerm = matchTerm; + } } \ No newline at end of file diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobQuery.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobQuery.java index cc8af6b377d..279e7557ab7 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobQuery.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobQuery.java @@ -12,13 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.job; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.AbstractKapuaNamedQuery; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link Job} {@link KapuaQuery} definition. * @@ -27,17 +29,32 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobXmlRegistry.class, factoryMethod = "newQuery") -public interface JobQuery extends KapuaQuery { +@XmlType +public class JobQuery extends AbstractKapuaNamedQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public JobQuery(KapuaId scopeId) { + super(scopeId); + } /** * Instantiates a new {@link JobMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link JobMatchPredicate}. * @since 2.0.0 */ - JobMatchPredicate matchPredicate(T matchTerm); + public JobMatchPredicate matchPredicate(T matchTerm) { + return new JobMatchPredicate<>(matchTerm); + } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobXmlRegistry.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobXmlRegistry.java index 74abe55360f..3b09636e7e0 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobXmlRegistry.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/JobXmlRegistry.java @@ -45,6 +45,6 @@ public JobCreator newJobCreator() { } public JobQuery newQuery() { - return jobFactory.newQuery(null); + return new JobQuery(null); } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionFactory.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionFactory.java index 9a73594b5b1..5b89204448f 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionFactory.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface JobExecutionFactory extends KapuaEntityFactory { +public interface JobExecutionFactory extends KapuaEntityFactory { } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionQuery.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionQuery.java index 74e68ba2e40..69ddb693ac8 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionQuery.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionQuery.java @@ -12,13 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.job.execution; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; +import org.eclipse.kapua.model.query.KapuaSortCriteria; +import org.eclipse.kapua.model.query.SortOrder; + /** * {@link JobExecution} {@link KapuaQuery} definition. * @@ -27,6 +30,22 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobExecutionXmlRegistry.class, factoryMethod = "newQuery") -public interface JobExecutionQuery extends KapuaQuery { +@XmlType +public class JobExecutionQuery extends KapuaQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public JobExecutionQuery(KapuaId scopeId) { + super(scopeId); + } + + @Override + public KapuaSortCriteria getDefaultSortCriteria() { + return fieldSortCriteria(JobExecutionAttributes.STARTED_ON, SortOrder.DESCENDING); + } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionXmlRegistry.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionXmlRegistry.java index 0de567b3408..650dd4c8219 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionXmlRegistry.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/execution/JobExecutionXmlRegistry.java @@ -44,7 +44,4 @@ public JobExecutionCreator newJobExecutionCreator() { return jobExecutionFactory.newCreator(null); } - public JobExecutionQuery newQuery() { - return jobExecutionFactory.newQuery(null); - } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepFactory.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepFactory.java index fa3b3a8bf5c..8f0f680d81b 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepFactory.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepFactory.java @@ -21,7 +21,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface JobStepFactory extends KapuaEntityFactory { +public interface JobStepFactory extends KapuaEntityFactory { /** * Instantiates a new {@link JobStepProperty}. diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepQuery.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepQuery.java deleted file mode 100644 index 464319a1fab..00000000000 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.step; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link JobStep} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobStepXmlRegistry.class, factoryMethod = "newQuery") -public interface JobStepQuery extends KapuaQuery { -} diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepXmlRegistry.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepXmlRegistry.java index 13eaf71fe5c..f1e28f172a2 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepXmlRegistry.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/JobStepXmlRegistry.java @@ -45,10 +45,6 @@ public JobStepCreator newJobStepCreator() { return jobStepFactory.newCreator(null); } - public JobStepQuery newQuery() { - return jobStepFactory.newQuery(null); - } - public JobStepProperty newJobStepProperty() { return jobStepFactory.newStepProperty(null, null, null); } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionFactory.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionFactory.java index bc1c86a7f8b..ff576bdb12d 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionFactory.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionFactory.java @@ -20,7 +20,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface JobStepDefinitionFactory extends KapuaEntityFactory { +public interface JobStepDefinitionFactory extends KapuaEntityFactory { /** * Instantiates a new {@link JobStepProperty}. diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionQuery.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionQuery.java index be9874b0465..9ef0249062b 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionQuery.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionQuery.java @@ -12,13 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.job.step.definition; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.AbstractKapuaNamedQuery; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link JobStepDefinition} {@link KapuaQuery} definition. * @@ -27,6 +29,28 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobStepDefinitionXmlRegistry.class, factoryMethod = "newQuery") -public interface JobStepDefinitionQuery extends KapuaQuery { +@XmlType +public class JobStepDefinitionQuery extends AbstractKapuaNamedQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public JobStepDefinitionQuery(KapuaId scopeId) { + super(scopeId); + } + + /** + * This enables {@link JobStepDefinitionQuery} to retrieve also not scoped {@link JobStepDefinition}s since they are public. + * + * @return {@code true} + * @since 2.0.0 + */ + @Override + public boolean getNotScopedEntities() { + return true; + } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionXmlRegistry.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionXmlRegistry.java index 1ec589e7d1e..ab20432afc9 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionXmlRegistry.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/step/definition/JobStepDefinitionXmlRegistry.java @@ -43,8 +43,4 @@ public JobStepDefinition newJobStepDefinition() { public JobStepDefinitionCreator newJobStepDefinitionCreator() { return jobStepDefinitionFactory.newCreator(null); } - - public JobStepDefinitionQuery newQuery() { - return jobStepDefinitionFactory.newQuery(null); - } } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetFactory.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetFactory.java index 6e6870017c1..953e0690de9 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetFactory.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface JobTargetFactory extends KapuaEntityFactory { +public interface JobTargetFactory extends KapuaEntityFactory { } diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetQuery.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetQuery.java deleted file mode 100644 index 237d12699fa..00000000000 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.targets; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link JobTarget} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = JobTargetXmlRegistry.class, factoryMethod = "newQuery") -public interface JobTargetQuery extends KapuaQuery { -} diff --git a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetXmlRegistry.java b/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetXmlRegistry.java index 8b6b8407ec1..75b92f3f05f 100644 --- a/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetXmlRegistry.java +++ b/service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTargetXmlRegistry.java @@ -44,7 +44,4 @@ public JobTargetCreator newJobTargetCreator() { return jobTargetFactory.newCreator(null); } - public JobTargetQuery newQuery() { - return jobTargetFactory.newQuery(null); - } } diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionFactoryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionFactoryImpl.java index 2cb49565760..1ce1c2e8162 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionFactoryImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.job.execution.JobExecution; import org.eclipse.kapua.service.job.execution.JobExecutionCreator; import org.eclipse.kapua.service.job.execution.JobExecutionFactory; -import org.eclipse.kapua.service.job.execution.JobExecutionQuery; /** * {@link JobExecutionFactory} implementation. @@ -39,11 +38,6 @@ public JobExecutionCreator newCreator(KapuaId scopeId) { return new JobExecutionCreatorImpl(scopeId); } - @Override - public JobExecutionQuery newQuery(KapuaId scopeId) { - return new JobExecutionQueryImpl(scopeId); - } - @Override public JobExecution clone(JobExecution jobExecution) { try { diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionImplJpaRepository.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionImplJpaRepository.java index 848c4e5e520..12fa03d1584 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionImplJpaRepository.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionImplJpaRepository.java @@ -32,7 +32,7 @@ public JobExecutionImplJpaRepository(KapuaJpaRepositoryConfiguration jpaRepoConf @Override public long countByJobId(TxContext tx, KapuaId scopeId, KapuaId jobId) throws KapuaException { - final JobExecutionQuery jobExecutionQuery = new JobExecutionQueryImpl(scopeId); + final JobExecutionQuery jobExecutionQuery = new JobExecutionQuery(scopeId); jobExecutionQuery.setPredicate( jobExecutionQuery.attributePredicate(JobExecutionImpl_.JOB_ID, jobId) ); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionQueryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionQueryImpl.java deleted file mode 100644 index 040361482f9..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/execution/internal/JobExecutionQueryImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.execution.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaSortCriteria; -import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.job.execution.JobExecutionAttributes; -import org.eclipse.kapua.service.job.execution.JobExecutionQuery; - -/** - * {@link JobExecutionQuery} implementation. - * - * @since 1.0.0 - */ -public class JobExecutionQueryImpl extends AbstractKapuaQuery implements JobExecutionQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public JobExecutionQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public KapuaSortCriteria getDefaultSortCriteria() { - return fieldSortCriteria(JobExecutionAttributes.STARTED_ON, SortOrder.DESCENDING); - } -} diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobFactoryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobFactoryImpl.java index 95a580e025c..3f361429a31 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobFactoryImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.job.Job; import org.eclipse.kapua.service.job.JobCreator; import org.eclipse.kapua.service.job.JobFactory; -import org.eclipse.kapua.service.job.JobQuery; /** * {@link JobFactory} implementation. @@ -39,11 +38,6 @@ public JobCreator newCreator(KapuaId scopeId) { return new JobCreatorImpl(scopeId); } - @Override - public JobQuery newQuery(KapuaId scopeId) { - return new JobQueryImpl(scopeId); - } - @Override public Job clone(Job job) { try { diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobMatchPredicateImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobMatchPredicateImpl.java deleted file mode 100644 index 64257773f43..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobMatchPredicateImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.internal; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.job.JobAttributes; -import org.eclipse.kapua.service.job.JobMatchPredicate; - -import java.util.Arrays; - -public class JobMatchPredicateImpl extends AbstractMatchPredicate implements JobMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 2.0.0 - */ - public JobMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - JobAttributes.NAME, - JobAttributes.DESCRIPTION - ); - this.matchTerm = matchTerm; - } - -} \ No newline at end of file diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobQueryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobQueryImpl.java deleted file mode 100644 index 4d9b095a7ca..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobQueryImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.job.JobMatchPredicate; -import org.eclipse.kapua.service.job.JobQuery; - -/** - * {@link JobQuery} implementation. - * - * @since 1.0.0 - */ -public class JobQueryImpl extends AbstractKapuaNamedQuery implements JobQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public JobQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public JobMatchPredicate matchPredicate(T matchTerm) { - return new JobMatchPredicateImpl<>(matchTerm); - } -} diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionAligner.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionAligner.java index 30c7818bc74..6357f515446 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionAligner.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionAligner.java @@ -30,6 +30,7 @@ import org.eclipse.kapua.locator.initializers.KapuaInitializingMethod; import org.eclipse.kapua.model.KapuaNamedEntity; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionRepository; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; @@ -100,7 +101,7 @@ public void populate() { KapuaSecurityUtils.doPrivileged(() -> { txManager.execute(tx -> { // Retrieve all JobStepDefinition from the database - List dbJobStepDefinitions = jobStepDefinitionRepository.query(tx, new JobStepDefinitionQueryImpl(null)).getItems() + List dbJobStepDefinitions = jobStepDefinitionRepository.query(tx, new KapuaQuery((KapuaId) null)).getItems() .stream() .map(dbJobStepDefinition -> (JobStepDefinitionImpl) dbJobStepDefinition) .collect(Collectors.toList()); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionFactoryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionFactoryImpl.java index 120038b64ca..3774d45e89a 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionFactoryImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionCreator; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory; -import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; /** @@ -40,11 +39,6 @@ public JobStepDefinitionCreator newCreator(KapuaId scopeId) { return new JobStepDefinitionCreatorImpl(scopeId); } - @Override - public JobStepDefinitionQuery newQuery(KapuaId scopeId) { - return new JobStepDefinitionQueryImpl(scopeId); - } - @Override public JobStepProperty newStepProperty(String name, String type, String value) { return new JobStepPropertyImpl(name, type, value, null); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionQueryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionQueryImpl.java deleted file mode 100644 index 300924d51e7..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionQueryImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.step.definition.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; -import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; - -/** - * {@link JobStepDefinitionQuery} definition. - * - * @since 1.0.0 - */ -public class JobStepDefinitionQueryImpl extends AbstractKapuaNamedQuery implements JobStepDefinitionQuery { - - /** - * Constructor. - * - * @param scopeId - * The {@link #getScopeId()}. - * @since 1.0.0 - */ - public JobStepDefinitionQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - /** - * This enables {@link JobStepDefinitionQuery} to retrieve also not scoped {@link JobStepDefinition}s since they are public. - * - * @return {@code true} - * @since 2.0.0 - */ - @Override - public boolean getNotScopedEntities() { - return true; - } -} diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionServiceImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionServiceImpl.java index 2458ec68fbf..e61c9d03a2b 100755 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionServiceImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/definition/internal/JobStepDefinitionServiceImpl.java @@ -13,6 +13,7 @@ package org.eclipse.kapua.service.job.step.definition.internal; import java.util.Optional; + import javax.inject.Singleton; import org.eclipse.kapua.KapuaDuplicateNameInAnotherAccountError; @@ -120,7 +121,7 @@ public JobStepDefinition find(KapuaId scopeId, KapuaId stepDefinitionId) throws // Check Access authorizationService.checkPermission(permissionFactory.newPermission(Domains.JOB, Actions.read, scopeId)); - final JobStepDefinitionQuery query = new JobStepDefinitionQueryImpl(scopeId); + final JobStepDefinitionQuery query = new JobStepDefinitionQuery(scopeId); query.setPredicate(query.attributePredicate(JobStepDefinitionAttributes.ENTITY_ID, stepDefinitionId)); // Do find diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepFactoryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepFactoryImpl.java index ad8f9356333..36c9062a8b2 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepFactoryImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepFactory; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; import org.eclipse.kapua.service.job.step.definition.internal.JobStepPropertyImpl; @@ -40,11 +39,6 @@ public JobStepCreator newCreator(KapuaId scopeId) { return new JobStepCreatorImpl(scopeId); } - @Override - public JobStepQuery newQuery(KapuaId scopeId) { - return new JobStepQueryImpl(scopeId); - } - @Override public JobStepProperty newStepProperty(String name, String propertyType, String propertyValue) { return new JobStepPropertyImpl(name, propertyType, propertyValue, null); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepModule.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepModule.java index feef46165be..ae0070d5bbc 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepModule.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepModule.java @@ -17,9 +17,7 @@ import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration; -import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.commons.util.xml.XmlUtil; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.job.execution.JobExecutionFactory; @@ -55,8 +53,6 @@ JobStepService jobStepService(AuthorizationService authorizationService, JobExecutionService jobExecutionService, JobExecutionFactory jobExecutionFactory, JobStepDefinitionRepository jobStepDefinitionRepository, - QueryFactory queryFactory, - KapuaJpaTxManagerFactory jpaTxManagerFactory, XmlUtil xmlUtil) { return new JobStepServiceImpl(authorizationService, permissionFactory, diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepQueryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepQueryImpl.java deleted file mode 100644 index 1f1123f3877..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.step.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.job.step.JobStepQuery; - -/** - * {@link JobStepQuery} definition. - * - * @since 1.0.0 - */ -public class JobStepQueryImpl extends AbstractKapuaNamedQuery implements JobStepQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public JobStepQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java index ead07713317..f811249472f 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/step/internal/JobStepServiceImpl.java @@ -14,10 +14,10 @@ import java.util.List; import java.util.regex.Pattern; + import javax.inject.Singleton; import javax.xml.bind.DatatypeConverter; -import com.google.common.base.Strings; import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; @@ -47,7 +47,6 @@ import org.eclipse.kapua.service.job.step.JobStepFactory; import org.eclipse.kapua.service.job.step.JobStepIndex; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepRepository; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; @@ -57,6 +56,8 @@ import org.eclipse.kapua.storage.TxManager; import org.slf4j.LoggerFactory; +import com.google.common.base.Strings; + /** * {@link JobStepService} implementation. * @@ -143,7 +144,7 @@ public JobStep create(JobStepCreator jobStepCreator) throws KapuaException { throw new CannotModifyJobStepsException(jobStepCreator.getJobId()); } // Populate JobStepCreator.stepIndex if not specified - final JobStepQuery query = new JobStepQueryImpl(jobStepCreator.getScopeId()); + final KapuaQuery query = new KapuaQuery(jobStepCreator.getScopeId()); if (jobStepCreator.getStepIndex() == null) { query.setPredicate(query.attributePredicate(JobStepAttributes.JOB_ID, jobStepCreator.getJobId())); query.setSortCriteria(query.fieldSortCriteria(JobStepAttributes.STEP_INDEX, SortOrder.DESCENDING)); @@ -155,7 +156,7 @@ public JobStep create(JobStepCreator jobStepCreator) throws KapuaException { jobStepCreator.setStepIndex(lastJobStep != null ? lastJobStep.getStepIndex() + 1 : JobStepIndex.FIRST); } // Check if JobStep.stepIndex is duplicate. - JobStepQuery jobStepQuery = new JobStepQueryImpl(jobStepCreator.getScopeId()); + KapuaQuery jobStepQuery = new KapuaQuery(jobStepCreator.getScopeId()); jobStepQuery.setPredicate( jobStepQuery.andPredicate( jobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStepCreator.getJobId()), @@ -168,15 +169,15 @@ public JobStep create(JobStepCreator jobStepCreator) throws KapuaException { if (jobStepAtIndex != null) { // JobStepCreator inserted between existing JobSteps. // Moving existing JobSteps + 1 - JobStepQuery selectorJobStepQuery = new JobStepQueryImpl(jobStepAtIndex.getScopeId()); - selectorJobStepQuery.setPredicate( - selectorJobStepQuery.andPredicate( - selectorJobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStepAtIndex.getJobId()), - selectorJobStepQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStepAtIndex.getStepIndex(), Operator.GREATER_THAN_OR_EQUAL) + KapuaQuery selectorKapuaQuery = new KapuaQuery(jobStepAtIndex.getScopeId()); + selectorKapuaQuery.setPredicate( + selectorKapuaQuery.andPredicate( + selectorKapuaQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStepAtIndex.getJobId()), + selectorKapuaQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStepAtIndex.getStepIndex(), Operator.GREATER_THAN_OR_EQUAL) ) ); - shiftJobStepPosition(tx, selectorJobStepQuery, +1); + shiftJobStepPosition(tx, selectorKapuaQuery, +1); } // Create JobStep JobStep jobStep = jobStepFactory.newEntity(jobStepCreator.getScopeId()); @@ -240,29 +241,29 @@ public JobStep update(JobStep jobStep) throws KapuaException { if (jobStep.getStepIndex() < currentJobStep.getStepIndex()) { // Moved before current position. // Shift JobSteps +1 - JobStepQuery selectorJobStepQuery = new JobStepQueryImpl(jobStep.getScopeId()); - selectorJobStepQuery.setPredicate( - selectorJobStepQuery.andPredicate( - selectorJobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStep.getJobId()), - selectorJobStepQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStep.getStepIndex(), Operator.GREATER_THAN_OR_EQUAL), - selectorJobStepQuery.attributePredicate(JobStepAttributes.STEP_INDEX, currentJobStep.getStepIndex(), Operator.LESS_THAN) + KapuaQuery selectorKapuaQuery = new KapuaQuery(jobStep.getScopeId()); + selectorKapuaQuery.setPredicate( + selectorKapuaQuery.andPredicate( + selectorKapuaQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStep.getJobId()), + selectorKapuaQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStep.getStepIndex(), Operator.GREATER_THAN_OR_EQUAL), + selectorKapuaQuery.attributePredicate(JobStepAttributes.STEP_INDEX, currentJobStep.getStepIndex(), Operator.LESS_THAN) ) ); - shiftJobStepPosition(tx, selectorJobStepQuery, +1); + shiftJobStepPosition(tx, selectorKapuaQuery, +1); } else { // Moved after current position. // Shift JobSteps -1 - JobStepQuery selectorJobStepQuery = new JobStepQueryImpl(jobStep.getScopeId()); - selectorJobStepQuery.setPredicate( - selectorJobStepQuery.andPredicate( - selectorJobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStep.getJobId()), - selectorJobStepQuery.attributePredicate(JobStepAttributes.STEP_INDEX, currentJobStep.getStepIndex(), Operator.GREATER_THAN), - selectorJobStepQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStep.getStepIndex(), Operator.LESS_THAN_OR_EQUAL) + KapuaQuery selectorKapuaQuery = new KapuaQuery(jobStep.getScopeId()); + selectorKapuaQuery.setPredicate( + selectorKapuaQuery.andPredicate( + selectorKapuaQuery.attributePredicate(JobStepAttributes.JOB_ID, jobStep.getJobId()), + selectorKapuaQuery.attributePredicate(JobStepAttributes.STEP_INDEX, currentJobStep.getStepIndex(), Operator.GREATER_THAN), + selectorKapuaQuery.attributePredicate(JobStepAttributes.STEP_INDEX, jobStep.getStepIndex(), Operator.LESS_THAN_OR_EQUAL) ) ); - shiftJobStepPosition(tx, selectorJobStepQuery, -1); + shiftJobStepPosition(tx, selectorKapuaQuery, -1); } } @@ -316,7 +317,7 @@ public void delete(KapuaId scopeId, KapuaId jobStepId) throws KapuaException { final JobStep jobStep = jobStepRepository.find(tx, scopeId, jobStepId) .orElseThrow(() -> new KapuaEntityNotFoundException(JobStep.TYPE, jobStepId)); // Check Job Executions - final JobExecutionQuery jobExecutionQuery = jobExecutionFactory.newQuery(scopeId); + final JobExecutionQuery jobExecutionQuery = new JobExecutionQuery(scopeId); jobExecutionQuery.setPredicate( jobExecutionQuery.attributePredicate(JobExecutionAttributes.JOB_ID, jobStep.getJobId()) ); @@ -330,7 +331,7 @@ public void delete(KapuaId scopeId, KapuaId jobStepId) throws KapuaException { jobStepRepository.delete(tx, scopeId, jobStepId); // Shift following steps of one position in the step index - JobStepQuery query = new JobStepQueryImpl(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate( query.andPredicate( @@ -362,18 +363,18 @@ public int getJobStepPropertyMaxLength() throws KapuaException { // Private methods /** - * Shifts {@link JobStep} matched by the given {@link JobStepQuery} according to the given increment. + * Shifts {@link JobStep} matched by the given {@link KapuaQuery} according to the given increment. * * @param tx * The {@link TxContext} which is owning the transaction. * @param selectorQuery - * The selector {@link JobStepQuery}. + * The selector {@link KapuaQuery}. * @param increment * The increment o apply to the matched {@link JobStep}s * @throws KapuaException * @since 2.0.0 */ - private void shiftJobStepPosition(TxContext tx, JobStepQuery selectorQuery, int increment) throws KapuaException { + private void shiftJobStepPosition(TxContext tx, KapuaQuery selectorQuery, int increment) throws KapuaException { selectorQuery.setSortCriteria(selectorQuery.fieldSortCriteria(JobStepAttributes.STEP_INDEX, SortOrder.ASCENDING)); JobStepListResult followingJobStepListResult = jobStepRepository.query(tx, selectorQuery); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetFactoryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetFactoryImpl.java index cfd25291c12..44b929c4548 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetFactoryImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.job.targets.JobTarget; import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetFactory; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; /** * {@link JobTargetFactory} implementation. @@ -39,11 +38,6 @@ public JobTargetCreator newCreator(KapuaId scopeId) { return new JobTargetCreatorImpl(scopeId); } - @Override - public JobTargetQuery newQuery(KapuaId scopeId) { - return new JobTargetQueryImpl(scopeId); - } - @Override public JobTarget clone(JobTarget jobTarget) { try { diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetQueryImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetQueryImpl.java deleted file mode 100644 index 4c8892c829e..00000000000 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.job.targets.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; - -/** - * {@link JobTargetQuery} implementation. - * - * @since 1.0.0 - */ -public class JobTargetQueryImpl extends AbstractKapuaQuery implements JobTargetQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public JobTargetQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetServiceImpl.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetServiceImpl.java index 001df696bd9..5d53cfdc278 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetServiceImpl.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetServiceImpl.java @@ -12,6 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.service.job.targets.internal; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaEntityUniquenessException; import org.eclipse.kapua.KapuaException; @@ -29,18 +36,11 @@ import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetRepository; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Singleton; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * {@link JobTargetService} implementation. * @@ -84,7 +84,7 @@ public JobTarget create(JobTargetCreator jobTargetCreator) throws KapuaException final Job job = jobRepository.find(tx, jobTargetCreator.getScopeId(), jobTargetCreator.getJobId()) .orElseThrow(() -> new KapuaEntityNotFoundException(Job.TYPE, jobTargetCreator.getJobId())); // Check duplicate - JobTargetQuery jobTargetQuery = new JobTargetQueryImpl(jobTargetCreator.getScopeId()); + KapuaQuery jobTargetQuery = new KapuaQuery(jobTargetCreator.getScopeId()); jobTargetQuery.setPredicate( jobTargetQuery.andPredicate( jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, jobTargetCreator.getJobId()), diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java index 8315e9a5d02..6eba218e487 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java @@ -200,7 +200,7 @@ private void checkJobHasExecution(Job job, int expectedNumberOfExecution) throws @When("I count the execution items for the current job") public void countExecutionsForJob() throws Exception { Job job = (Job) stepData.get("Job"); - JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); + JobExecutionQuery tmpQuery = new JobExecutionQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL)); updateCount(() -> (int) jobExecutionService.count(tmpQuery)); } @@ -208,7 +208,7 @@ public void countExecutionsForJob() throws Exception { @Then("I query for the execution items for the current job") public void queryExecutionsForJobWithPackages() throws Exception { Job job = (Job) stepData.get("Job"); - JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); + JobExecutionQuery tmpQuery = new JobExecutionQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL)); primeException(); try { @@ -235,7 +235,7 @@ public void queryExecutionsForJobWithStartDateInPast() throws Exception { private void queryExecutionsForJobWithStartDate(Date startDate) throws Exception { final Job job = (Job) stepData.get("Job"); - final JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); + final JobExecutionQuery tmpQuery = new JobExecutionQuery(getCurrentScopeId()); final AndPredicate andPredicate = tmpQuery.andPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId())); andPredicate.and(tmpQuery.attributePredicate(JobExecutionAttributes.STARTED_ON, startDate, AttributePredicate.Operator.GREATER_THAN_OR_EQUAL)); tmpQuery.setPredicate(andPredicate); @@ -305,7 +305,7 @@ private void iQueryForTheExecutionItemsForTheCurrentJobAndICountOrMoreInternal(i } private JobExecutionListResult getExecutionsForJob(Job job) throws Exception { - JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); + JobExecutionQuery tmpQuery = new JobExecutionQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL)); return jobExecutionService.query(tmpQuery); } @@ -370,7 +370,7 @@ private void iQueryForTheJobWithTheNameAndJobExecutionCountInternal(String jobNa } private Job getJobAndUpdateStepData(String jobName) throws Exception { - JobQuery tmpQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery tmpQuery = new JobQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobAttributes.NAME, jobName)); stepData.remove("Job"); @@ -450,7 +450,6 @@ public void checkThatNoExecutionWasFound() { public void testTheJobExecutionFactory() { Assert.assertNotNull(jobExecutionFactory.newCreator(SYS_SCOPE_ID)); Assert.assertNotNull(jobExecutionFactory.newEntity(SYS_SCOPE_ID)); - Assert.assertNotNull(jobExecutionFactory.newQuery(SYS_SCOPE_ID)); } // Private methods diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceSteps.java index 71e02233eaa..f650eea81c3 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceSteps.java @@ -263,24 +263,24 @@ public void findJobInDatabase() throws Exception { @When("I count the jobs in the database") public void countJobsInDatabase() throws Exception { - updateCount(() -> (int) jobService.count(jobFactory.newQuery(getCurrentScopeId()))); + updateCount(() -> (int) jobService.count(new JobQuery(getCurrentScopeId()))); } @When("I query for jobs in scope {int}") public void countJobsInScope(int id) throws Exception { - updateCount(() -> jobService.query(jobFactory.newQuery(getKapuaId(id))).getSize()); + updateCount(() -> jobService.query(new JobQuery(getKapuaId(id))).getSize()); } @When("I count the jobs with the name starting with {string}") public void countJobsWithName(String name) throws Exception { - JobQuery tmpQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery tmpQuery = new JobQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobAttributes.NAME, name, Operator.STARTS_WITH)); updateCount(() -> jobService.query(tmpQuery).getSize()); } @When("I query for the job with the name {string}") public void queryForJobWithName(String name) throws Exception { - JobQuery tmpQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery tmpQuery = new JobQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobAttributes.NAME, name)); primeException(); try { @@ -341,7 +341,7 @@ public void testJobFactorySanity() { primeException(); Assert.assertNotNull("The job factory returned a null creator!", jobFactory.newCreator(SYS_SCOPE_ID)); Assert.assertNotNull("The job factory returned a null job object!", jobFactory.newEntity(SYS_SCOPE_ID)); - Assert.assertNotNull("The job factory returned a null job query!", jobFactory.newQuery(SYS_SCOPE_ID)); + Assert.assertNotNull("The job factory returned a null job query!", new JobQuery(SYS_SCOPE_ID)); } @Then("I find a job with name {string}") @@ -378,7 +378,7 @@ public void iTryToEditJobToName(String jobName) throws Throwable { @When("I query for the job with the name {string} and I find it") public void iQueryForTheJobWithTheNameAndIFoundIt(String jobName) throws Exception { - JobQuery tmpQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery tmpQuery = new JobQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobAttributes.NAME, jobName)); primeException(); try { @@ -393,7 +393,7 @@ public void iQueryForTheJobWithTheNameAndIFoundIt(String jobName) throws Excepti @When("I query for the job with term match {string}") public void iQueryForTheJobMatchTerm(String matchTerm) throws Exception { - JobQuery tmpQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery tmpQuery = new JobQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.matchPredicate(matchTerm)); @@ -437,7 +437,7 @@ public void iTryToUpdateJobNameWithInvalidSymbolsInName(String invalidCharacters @Then("I change name of job from {string} to {string}") public void iChangeNameOfJobFromTo(String oldName, String newName) throws Throwable { try { - JobQuery query = jobFactory.newQuery(getCurrentScopeId()); + JobQuery query = new JobQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(JobAttributes.NAME, oldName, Operator.EQUAL)); JobListResult queryResult = jobService.query(query); Job job = queryResult.getFirstItem(); @@ -458,7 +458,7 @@ public void thereIsNoJobWithNameInDatabase(String jobName) { @When("I change the job description from {string} to {string}") public void iChangeTheJobDescriptionFromTo(String oldDescription, String newDescription) throws Throwable { try { - JobQuery query = jobFactory.newQuery(getCurrentScopeId()); + JobQuery query = new JobQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(JobAttributes.DESCRIPTION, oldDescription, Operator.EQUAL)); JobListResult queryResult = jobService.query(query); Job job = queryResult.getFirstItem(); diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceTestBase.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceTestBase.java index c6c75a0cce8..08ee0e540e5 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceTestBase.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobServiceTestBase.java @@ -67,7 +67,7 @@ protected JobServiceTestBase(StepData stepData) { } public Job findJob(String jobName) throws Exception { - JobQuery jobQuery = jobFactory.newQuery(getCurrentScopeId()); + JobQuery jobQuery = new JobQuery(getCurrentScopeId()); jobQuery.setPredicate( jobQuery.attributePredicate(JobAttributes.NAME, jobName) ); diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepDefinitionServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepDefinitionServiceSteps.java index 96a18e4f432..9ce506eb522 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepDefinitionServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepDefinitionServiceSteps.java @@ -25,6 +25,7 @@ import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionCreator; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory; +import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionQuery; import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; import org.eclipse.kapua.service.job.step.definition.JobStepType; @@ -218,12 +219,12 @@ public void searchForStepDefinitionWithTheName(List list) throws Excepti @When("I count the step definition in the database") public void countStepDefinitionInDatabase() throws Exception { - updateCount(() -> (int) jobStepDefinitionService.count(jobStepDefinitionFactory.newQuery(KapuaId.ANY))); + updateCount(() -> (int) jobStepDefinitionService.count(new JobStepDefinitionQuery(KapuaId.ANY))); } @When("I query for step definitions in scope {int}") public void countStepDefinitijonsInScope(Integer id) throws Exception { - updateCount(() -> jobStepDefinitionService.query(jobStepDefinitionFactory.newQuery(KapuaId.ANY)).getSize()); + updateCount(() -> jobStepDefinitionService.query(new JobStepDefinitionQuery(KapuaId.ANY)).getSize()); } @When("I delete the step definition") @@ -327,7 +328,6 @@ public void checkStepDefinitionProcessorName(String name) { public void testTheStepDefinitionFactory() { Assert.assertNotNull(jobStepDefinitionFactory.newCreator(SYS_SCOPE_ID)); Assert.assertNotNull(jobStepDefinitionFactory.newEntity(SYS_SCOPE_ID)); - Assert.assertNotNull(jobStepDefinitionFactory.newQuery(SYS_SCOPE_ID)); Assert.assertNotNull(jobStepDefinitionFactory.newStepProperty("TestName", "TestType", "TestValue", "TestExampleValue")); } diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepServiceSteps.java index 219e528ffef..ea17fc5d7ce 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobStepServiceSteps.java @@ -23,6 +23,7 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.common.StepData; import org.eclipse.kapua.qa.common.cucumber.CucJobStepProperty; @@ -32,7 +33,6 @@ import org.eclipse.kapua.service.job.step.JobStepCreator; import org.eclipse.kapua.service.job.step.JobStepFactory; import org.eclipse.kapua.service.job.step.JobStepListResult; -import org.eclipse.kapua.service.job.step.JobStepQuery; import org.eclipse.kapua.service.job.step.JobStepService; import org.eclipse.kapua.service.job.step.definition.JobStepDefinition; import org.eclipse.kapua.service.job.step.definition.JobStepProperty; @@ -271,7 +271,7 @@ public void iLookForLastJobStep() throws Exception { @When("I look for the JobStep with name {string}") public void iLookForJobStepWithName(String name) throws Exception { - JobStepQuery tmpQuery = jobStepFactory.newQuery(getCurrentScopeId()); + KapuaQuery tmpQuery = new KapuaQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobStepAttributes.NAME, name)); primeException(); @@ -286,7 +286,7 @@ public void iLookForJobStepWithName(String name) throws Exception { @When("I query for a JobStep with the name {string}") public void iQueryForJobStepWithName(String name) throws Exception { - JobStepQuery tmpQuery = jobStepFactory.newQuery(getCurrentScopeId()); + KapuaQuery tmpQuery = new KapuaQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobStepAttributes.NAME, name)); primeException(); @@ -325,7 +325,7 @@ public void iCountJobStepAndCheck(int count, int timeout) throws Exception { } private JobStepListResult getJobStepListResult(KapuaId currentJobId) throws KapuaException { - JobStepQuery jobStepQuery = jobStepFactory.newQuery(getCurrentScopeId()); + KapuaQuery jobStepQuery = new KapuaQuery(getCurrentScopeId()); jobStepQuery.setPredicate(jobStepQuery.attributePredicate(JobStepAttributes.JOB_ID, currentJobId, AttributePredicate.Operator.EQUAL)); return jobStepService.query(jobStepQuery); @@ -333,7 +333,7 @@ private JobStepListResult getJobStepListResult(KapuaId currentJobId) throws Kapu @When("I count the JobSteps in the current scope") public void iCountJobStepInCurrentScope() throws Exception { - updateCount(() -> (int) jobStepService.count(jobStepFactory.newQuery(getCurrentScopeId()))); + updateCount(() -> (int) jobStepService.count(new KapuaQuery(getCurrentScopeId()))); } // Delete @@ -380,7 +380,7 @@ public void checkJobStepNotFound() { public void testTheStepFactory() { Assert.assertNotNull(jobStepFactory.newCreator(SYS_SCOPE_ID)); Assert.assertNotNull(jobStepFactory.newEntity(SYS_SCOPE_ID)); - Assert.assertNotNull(jobStepFactory.newQuery(SYS_SCOPE_ID)); + Assert.assertNotNull(new KapuaQuery(SYS_SCOPE_ID)); Assert.assertNotNull(jobStepFactory.newStepProperty("TestName", "TestType", "TestValue")); } // Private methods diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobTargetServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobTargetServiceSteps.java index 5f3a7f60349..82ed30dd114 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobTargetServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobTargetServiceSteps.java @@ -23,6 +23,7 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaEntity; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.common.StepData; import org.eclipse.kapua.service.device.registry.Device; @@ -37,7 +38,6 @@ import org.eclipse.kapua.service.job.targets.JobTargetCreator; import org.eclipse.kapua.service.job.targets.JobTargetFactory; import org.eclipse.kapua.service.job.targets.JobTargetListResult; -import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; import org.eclipse.kapua.service.job.targets.JobTargetStatus; import org.junit.Assert; @@ -152,7 +152,7 @@ public void iSearchForTheJobTargetsInDatabase() { */ @And("I add device target(s) to job") public void addDeviceTargetsToJob(List clientIds) throws Exception { - DeviceQuery deviceQuery = deviceFactory.newQuery(getCurrentScopeId()); + DeviceQuery deviceQuery = new DeviceQuery(getCurrentScopeId()); deviceQuery.setPredicate( deviceQuery.attributePredicate(DeviceAttributes.CLIENT_ID, clientIds) ); @@ -290,13 +290,13 @@ public void setTargetStepExceptionMessage(String text) throws Exception { @When("I count the targets in the current scope") public void countTargetsForJob() throws Exception { - updateCount(() -> (int) jobTargetService.count(jobTargetFactory.newQuery(getCurrentScopeId()))); + updateCount(() -> (int) jobTargetService.count(new KapuaQuery(getCurrentScopeId()))); } @When("I query the targets for the current job") public void queryTargetsForJob() throws Exception { Job job = (Job) stepData.get("Job"); - JobTargetQuery tmpQuery = jobTargetFactory.newQuery(getCurrentScopeId()); + KapuaQuery tmpQuery = new KapuaQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(JobTargetAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL)); primeException(); try { @@ -334,7 +334,7 @@ public void iConfirmJobTargetHasStatus(int stepIndex, String jobStatus, int time @When("I count the targets in the current scope and I count {int}") public void iCountTheTargetsInTheCurrentScopeAndICount(int targetNum) throws Exception { - updateCountAndCheck(() -> (int) jobTargetService.count(jobTargetFactory.newQuery(getCurrentScopeId())), targetNum); + updateCountAndCheck(() -> (int) jobTargetService.count(new KapuaQuery(getCurrentScopeId())), targetNum); } @Then("The target step index is indeed {int}") @@ -373,7 +373,6 @@ public void checkThatNoTargetWasFound() { public void testTheJobTargetFactory() { Assert.assertNotNull(jobTargetFactory.newCreator(SYS_SCOPE_ID)); Assert.assertNotNull(jobTargetFactory.newEntity(SYS_SCOPE_ID)); - Assert.assertNotNull(jobTargetFactory.newQuery(SYS_SCOPE_ID)); } // Check Job Targets @@ -419,7 +418,7 @@ public void checkJobTargetByNameForJobHas(String clientId, int expectedStepIndex Job job = (Job) stepData.get(JOB); - JobTargetQuery jobTargetQuery = jobTargetFactory.newQuery(job.getScopeId()); + KapuaQuery jobTargetQuery = new KapuaQuery(job.getScopeId()); jobTargetQuery.setPredicate( jobTargetQuery.andPredicate( jobTargetQuery.attributePredicate(JobTargetAttributes.JOB_ID, job.getId()), diff --git a/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java b/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java index f3498d75669..0d785368796 100644 --- a/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java +++ b/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java @@ -24,14 +24,12 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.util.xml.XmlUtil; import org.eclipse.kapua.job.engine.JobEngineService; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; import org.eclipse.kapua.service.account.AccountFactory; @@ -122,7 +120,6 @@ protected void configure() { // Commons bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl()); - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); // Account bind(AccountRelativeFinder.class).toInstance(Mockito.mock(AccountRelativeFinder.class)); diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerFactory.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerFactory.java index 728fa9a8813..f02c3784664 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerFactory.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerFactory.java @@ -21,7 +21,7 @@ * @see KapuaEntityFactory * @since 1.0.0 */ -public interface TriggerFactory extends KapuaEntityFactory { +public interface TriggerFactory extends KapuaEntityFactory { /** * Instantiates a new {@link TriggerProperty} diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerQuery.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerQuery.java deleted file mode 100644 index e07a98ba0be..00000000000 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.scheduler.trigger; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link Trigger} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = TriggerXmlRegistry.class, factoryMethod = "newQuery") -public interface TriggerQuery extends KapuaQuery { -} diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerXmlRegistry.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerXmlRegistry.java index 93f2523a11e..7bd5dadb886 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerXmlRegistry.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/TriggerXmlRegistry.java @@ -35,10 +35,6 @@ public TriggerCreator newCreator() { return triggerFactory.newCreator(null); } - public TriggerQuery newQuery() { - return triggerFactory.newQuery(null); - } - public TriggerProperty newTriggerProperty() { return triggerFactory.newTriggerProperty(null, null, null); } diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionFactory.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionFactory.java index c8f10f4663f..0cb033c3389 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionFactory.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionFactory.java @@ -20,7 +20,7 @@ * @see KapuaEntityFactory * @since 1.1.0 */ -public interface TriggerDefinitionFactory extends KapuaEntityFactory { +public interface TriggerDefinitionFactory extends KapuaEntityFactory { /** * Instantiates a new {@link TriggerProperty}. diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionQuery.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionQuery.java index 1d7b2c6dea7..d6ff5d7e069 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionQuery.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionQuery.java @@ -12,13 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.scheduler.trigger.definition; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.AbstractKapuaNamedQuery; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link TriggerDefinition} {@link KapuaQuery} definition. * @@ -27,6 +29,17 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = TriggerDefinitionXmlRegistry.class, factoryMethod = "newQuery") -public interface TriggerDefinitionQuery extends KapuaQuery { +@XmlType +public class TriggerDefinitionQuery extends AbstractKapuaNamedQuery { + + public TriggerDefinitionQuery() { + } + + public TriggerDefinitionQuery(KapuaId scopeId) { + super(scopeId); + } + + public TriggerDefinitionQuery(KapuaQuery query) { + super(query); + } } diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionXmlRegistry.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionXmlRegistry.java index 24994cfc93b..d231589c09c 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionXmlRegistry.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/TriggerDefinitionXmlRegistry.java @@ -34,7 +34,4 @@ public TriggerDefinitionCreator newCreator() { return triggerDefinitionFactory.newCreator(null); } - public TriggerDefinitionQuery newQuery() { - return triggerDefinitionFactory.newQuery(null); - } } diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerFactory.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerFactory.java index a666528f17e..3bf723e5376 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerFactory.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerFactory.java @@ -20,6 +20,6 @@ * @see KapuaEntityFactory * @since 1.5.0 */ -public interface FiredTriggerFactory extends KapuaEntityFactory { +public interface FiredTriggerFactory extends KapuaEntityFactory { } diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerQuery.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerQuery.java deleted file mode 100644 index 931f70d3a7c..00000000000 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.scheduler.trigger.fired; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link FiredTrigger} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.5.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = FiredTriggerXmlRegistry.class, factoryMethod = "newQuery") -public interface FiredTriggerQuery extends KapuaQuery { -} diff --git a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerXmlRegistry.java b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerXmlRegistry.java index eea6c01f05f..f6ca0a0dc99 100644 --- a/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerXmlRegistry.java +++ b/service/scheduler/api/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/FiredTriggerXmlRegistry.java @@ -34,7 +34,4 @@ public FiredTriggerCreator newCreator() { return firedTriggerFactory.newCreator(null); } - public FiredTriggerQuery newQuery() { - return firedTriggerFactory.newQuery(null); - } } diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionAligner.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionAligner.java index 7493fab39a6..b08c929ffb9 100644 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionAligner.java +++ b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionAligner.java @@ -12,12 +12,25 @@ *******************************************************************************/ package org.eclipse.kapua.service.scheduler.trigger.definition.quartz; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManager; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.JpaAwareTxContext; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.initializers.KapuaInitializingMethod; import org.eclipse.kapua.model.KapuaNamedEntity; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionRepository; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; @@ -26,17 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Named; -import javax.persistence.EntityManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - /** * This aligner aligns the declared {@link TriggerDefinition}s in each module with the database. * @@ -90,7 +92,7 @@ public void populate() { KapuaSecurityUtils.doPrivileged(() -> { txManager.execute(tx -> { // Retrieve all TriggerDefinition from the database - List dbTriggerDefinitions = triggerDefinitionRepository.query(tx, new TriggerDefinitionQueryImpl(null)).getItems() + List dbTriggerDefinitions = triggerDefinitionRepository.query(tx, new KapuaQuery((KapuaId) null)).getItems() .stream() .map(dbTriggrDefinition -> (TriggerDefinitionImpl) dbTriggrDefinition) .collect(Collectors.toList()); @@ -242,8 +244,7 @@ private void alignTriggerDefinitions(TxContext txContext, TriggerDefinitionImpl if (triggerProperty == null) { LOG.info("Database TriggerProperty '{}' is not wired... Removing from database", dbTriggerPropertyEntity.getTriggerProperty().getName()); return true; - } - else { + } else { return false; } }); diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionFactoryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionFactoryImpl.java index 4e85f48cbe6..85a3c027b4d 100644 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionFactoryImpl.java +++ b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionCreator; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; /** @@ -40,11 +39,6 @@ public TriggerDefinitionCreator newCreator(KapuaId scopeId) { return new TriggerDefinitionCreatorImpl(scopeId); } - @Override - public TriggerDefinitionQuery newQuery(KapuaId scopeId) { - return new TriggerDefinitionQueryImpl(scopeId); - } - @Override public TriggerProperty newTriggerProperty(String name, String type, String value) { return new TriggerPropertyImpl(name, type, value); diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionQueryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionQueryImpl.java deleted file mode 100644 index 75167dee26e..00000000000 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/definition/quartz/TriggerDefinitionQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.scheduler.trigger.definition.quartz; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionQuery; - -/** - * {@link TriggerDefinitionQuery} implementation. - * - * @since 1.1.0 - */ -public class TriggerDefinitionQueryImpl extends AbstractKapuaNamedQuery implements TriggerDefinitionQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.1.0 - */ - public TriggerDefinitionQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerFactoryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerFactoryImpl.java index 74812094769..bba556f7007 100644 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerFactoryImpl.java +++ b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTrigger; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerFactory; -import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerQuery; /** * {@link FiredTriggerFactory} implementation. @@ -39,11 +38,6 @@ public FiredTriggerCreator newCreator(KapuaId scopeId) { return new FiredTriggerCreatorImpl(scopeId); } - @Override - public FiredTriggerQuery newQuery(KapuaId scopeId) { - return new FiredTriggerQueryImpl(scopeId); - } - @Override public FiredTrigger clone(FiredTrigger firedTrigger) { try { diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerQueryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerQueryImpl.java deleted file mode 100644 index 001948044d0..00000000000 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/fired/quartz/FiredTriggerQueryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.scheduler.trigger.fired.quartz; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.scheduler.trigger.fired.FiredTriggerQuery; - -/** - * {@link FiredTriggerQuery} implementation. - * - * @since 1.5.0 - */ -public class FiredTriggerQueryImpl extends AbstractKapuaQuery implements FiredTriggerQuery { - - /** - * Constructor. - * - * @param scopeId The scope {@link KapuaId}. - * @since 1.5.0 - */ - public FiredTriggerQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerFactoryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerFactoryImpl.java index 399b2f141f8..83b9bb4f03e 100644 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerFactoryImpl.java +++ b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.scheduler.trigger.Trigger; import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; import org.eclipse.kapua.service.scheduler.trigger.definition.quartz.TriggerPropertyImpl; @@ -41,11 +40,6 @@ public Trigger newEntity(KapuaId scopeId) { return new TriggerImpl(scopeId); } - @Override - public TriggerQuery newQuery(KapuaId scopeId) { - return new TriggerQueryImpl(scopeId); - } - @Override public TriggerProperty newTriggerProperty(String name, String type, String value) { return new TriggerPropertyImpl(name, type, value); diff --git a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerQueryImpl.java b/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerQueryImpl.java deleted file mode 100644 index 0cc4f03f154..00000000000 --- a/service/scheduler/quartz/src/main/java/org/eclipse/kapua/service/scheduler/trigger/quartz/TriggerQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.scheduler.trigger.quartz; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; - -/** - * {@link TriggerQuery} implementation. - * - * @since 1.0.0 - */ -public class TriggerQueryImpl extends AbstractKapuaNamedQuery implements TriggerQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private TriggerQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public TriggerQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/scheduler/test-steps/src/main/java/org/eclipse/kapua/service/scheduler/steps/JobScheduleServiceSteps.java b/service/scheduler/test-steps/src/main/java/org/eclipse/kapua/service/scheduler/steps/JobScheduleServiceSteps.java index 97889210fc3..542d6d7e833 100644 --- a/service/scheduler/test-steps/src/main/java/org/eclipse/kapua/service/scheduler/steps/JobScheduleServiceSteps.java +++ b/service/scheduler/test-steps/src/main/java/org/eclipse/kapua/service/scheduler/steps/JobScheduleServiceSteps.java @@ -12,9 +12,19 @@ *******************************************************************************/ package org.eclipse.kapua.service.scheduler.steps; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.common.StepData; import org.eclipse.kapua.qa.common.TestBase; @@ -24,9 +34,14 @@ import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator; import org.eclipse.kapua.service.scheduler.trigger.TriggerFactory; import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult; -import org.eclipse.kapua.service.scheduler.trigger.TriggerQuery; import org.eclipse.kapua.service.scheduler.trigger.TriggerService; import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinition; +import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionAttributes; +import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory; +import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionQuery; +import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; +import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; +import org.junit.Assert; import com.google.inject.Singleton; @@ -36,21 +51,6 @@ import io.cucumber.java.en.And; import io.cucumber.java.en.Then; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionAttributes; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionQuery; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService; -import org.eclipse.kapua.service.scheduler.trigger.definition.TriggerProperty; -import org.junit.Assert; - -import javax.inject.Inject; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - @Singleton public class JobScheduleServiceSteps extends TestBase { @@ -67,13 +67,13 @@ public class JobScheduleServiceSteps extends TestBase { private static final String TRIGGER_START_DATE = "TriggerStartDate"; private static final String TRIGGER_END_DATE = "TriggerEndDate"; -// **************************************************************************************** -// * Implementation of Gherkin steps used in JobService.feature scenarios. * -// * * -// * MockedLocator is used for Location Service. Mockito is used to mock other * -// * services that the Account services dependent on. Dependent services are: * -// * - Authorization Service * -// **************************************************************************************** + // **************************************************************************************** + // * Implementation of Gherkin steps used in JobService.feature scenarios. * + // * * + // * MockedLocator is used for Location Service. Mockito is used to mock other * + // * services that the Account services dependent on. Dependent services are: * + // * - Authorization Service * + // **************************************************************************************** private static final String KAPUA_ID_CLASS_NAME = "org.eclipse.kapua.model.id.KapuaId"; @@ -83,7 +83,7 @@ public JobScheduleServiceSteps(StepData stepData) { super(stepData); } - @After(value="@setup") + @After(value = "@setup") public void setServices() { KapuaLocator locator = KapuaLocator.getInstance(); triggerFactory = locator.getFactory(TriggerFactory.class); @@ -134,7 +134,7 @@ public void iTryToCreateSchedulerWithName(String schedulerName) throws Exception public void iFindTriggerPropertiesWithName(String triggerDefinitionName) throws Exception { primeException(); try { - TriggerDefinitionQuery triggerDefinitionQuery = triggerDefinitionFactory.newQuery(getCurrentScopeId()); + TriggerDefinitionQuery triggerDefinitionQuery = new TriggerDefinitionQuery(getCurrentScopeId()); triggerDefinitionQuery.setPredicate(triggerDefinitionQuery.attributePredicate(TriggerDefinitionAttributes.NAME, triggerDefinitionName, AttributePredicate.Operator.EQUAL)); TriggerDefinition triggerDefinition = triggerDefinitionService.query(triggerDefinitionQuery).getFirstItem(); stepData.put("TriggerDefinition", triggerDefinition); @@ -412,7 +412,7 @@ public void iDeleteTriggerWithName(String arg0) throws Throwable { @And("I search for the trigger with name {string} in the database") public void iSearchForTheTriggerWithNameInTheDatabase(String triggerName) throws Throwable { - TriggerQuery triggerQuery = triggerFactory.newQuery(getCurrentScopeId()); + KapuaQuery triggerQuery = new KapuaQuery(getCurrentScopeId()); triggerQuery.setPredicate(triggerQuery.attributePredicate(TriggerAttributes.NAME, triggerName, AttributePredicate.Operator.EQUAL)); primeException(); try { @@ -435,7 +435,7 @@ public void iTryToEditSchedulerPropertyTo(String trigerDefinition) throws Except Trigger trigger = (Trigger) stepData.get(TRIGGER); primeException(); try { - TriggerDefinitionQuery triggerDefinitionQuery = triggerDefinitionFactory.newQuery(getCurrentScopeId()); + TriggerDefinitionQuery triggerDefinitionQuery = new TriggerDefinitionQuery(getCurrentScopeId()); triggerDefinitionQuery.setPredicate(triggerDefinitionQuery.attributePredicate(TriggerDefinitionAttributes.NAME, trigerDefinition, AttributePredicate.Operator.EQUAL)); TriggerDefinition triggerDefinition = triggerDefinitionService.query(triggerDefinitionQuery).getFirstItem(); trigger.setTriggerDefinitionId(triggerDefinition.getId()); diff --git a/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java b/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java index 02e6c8c4fb0..16a46e9a568 100644 --- a/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java +++ b/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java @@ -25,7 +25,6 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.util.xml.XmlUtil; @@ -33,7 +32,6 @@ import org.eclipse.kapua.job.engine.client.settings.JobEngineClientSetting; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; import org.eclipse.kapua.service.account.AccountFactory; @@ -158,9 +156,6 @@ protected void configure() { triggerDefinitionRepository, triggerDefinitionFactory)); bind(TriggerDefinitionFactory.class).toInstance(triggerDefinitionFactory); - - // bind Query related services - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); } }; diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialFactory.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialFactory.java index 1e31dab6b5a..f533c052327 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialFactory.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialFactory.java @@ -22,7 +22,7 @@ * * @since 1.0.0 */ -public interface CredentialFactory extends KapuaEntityFactory { +public interface CredentialFactory extends KapuaEntityFactory { /** * Instantiates a new {@link Credential}. diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialQuery.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialQuery.java deleted file mode 100644 index 9e235aba25c..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link Credential} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = CredentialXmlRegistry.class, factoryMethod = "newCredentialQuery") -public interface CredentialQuery extends KapuaQuery { -} diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialXmlRegistry.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialXmlRegistry.java index 6b571b48204..eefb5600103 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialXmlRegistry.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/CredentialXmlRegistry.java @@ -45,14 +45,4 @@ public Credential newCredential() { public CredentialCreator newCredentialCreator() { return credentialFactory.newCreator(null, null, null, null, null, null); } - - /** - * Instantiates a new {@link CredentialQuery}. - * - * @return The newly instantiated {@link CredentialQuery} - * @since 1.0.0 - */ - public CredentialQuery newCredentialQuery() { - return credentialFactory.newQuery(null); - } } diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionFactory.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionFactory.java index c21a9c159d9..db1f4151794 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionFactory.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionFactory.java @@ -22,7 +22,7 @@ * @see KapuaEntityFactory * @since 1.3.0 */ -public interface MfaOptionFactory extends KapuaEntityFactory { +public interface MfaOptionFactory extends KapuaEntityFactory { /** * Instantiates a new {@link MfaOptionCreator}. diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionQuery.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionQuery.java deleted file mode 100644 index 33cc42ad3b7..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential.mfa; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link MfaOption} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.3.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = MfaOptionXmlRegistry.class, factoryMethod = "newQuery") -public interface MfaOptionQuery extends KapuaQuery { -} diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionXmlRegistry.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionXmlRegistry.java index 773adea771e..9ad503a6534 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionXmlRegistry.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/MfaOptionXmlRegistry.java @@ -40,14 +40,4 @@ public MfaOptionCreator newMfaOptionCreator() { public MfaOption newMfaOption() { return mfaOptionFactory.newEntity(null); } - - /** - * Instantiates a new {@link MfaOptionQuery} instance. - * - * @return The newly instantiated {@link MfaOptionQuery} - * @since 1.3.0 - */ - public MfaOptionQuery newQuery() { - return mfaOptionFactory.newQuery(null); - } } diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenFactory.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenFactory.java index 376817c9d1d..cb277276e4b 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenFactory.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenFactory.java @@ -23,7 +23,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface AccessTokenFactory extends KapuaEntityFactory { +public interface AccessTokenFactory extends KapuaEntityFactory { /** * Instantiates a new {@link AccessTokenCreator}. diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenQuery.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenQuery.java deleted file mode 100644 index fb49ebcd280..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/token/AccessTokenQuery.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.token; - -import org.eclipse.kapua.model.query.KapuaQuery; - -/** - * {@link AccessToken} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -public interface AccessTokenQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoFactory.java index 941d00df0bc..784adb9493f 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface AccessInfoFactory extends KapuaEntityFactory { +public interface AccessInfoFactory extends KapuaEntityFactory { } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoQuery.java deleted file mode 100644 index 29f9534835f..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link AccessInfo} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AccessInfoXmlRegistry.class, factoryMethod = "newQuery") -public interface AccessInfoQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoXmlRegistry.java index 78a7a8e4732..f95778c0540 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessInfoXmlRegistry.java @@ -39,7 +39,4 @@ public AccessInfoCreator newAccessInfoCreator() { return accessInfoFactory.newCreator(null); } - public AccessInfoQuery newQuery() { - return accessInfoFactory.newQuery(null); - } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionFactory.java index f8958976955..7841bb0e710 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface AccessPermissionFactory extends KapuaEntityFactory { +public interface AccessPermissionFactory extends KapuaEntityFactory { } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionQuery.java deleted file mode 100644 index 45bf90708e8..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link AccessPermission} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AccessPermissionXmlRegistry.class, factoryMethod = "newQuery") -public interface AccessPermissionQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionXmlRegistry.java index fd14485b1b9..5a9095d179c 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessPermissionXmlRegistry.java @@ -38,8 +38,4 @@ public AccessPermission newAccessPermission() { public AccessPermissionCreator newCreator() { return accessPermissionFactory.newCreator(null); } - - public AccessPermissionQuery newQuery() { - return accessPermissionFactory.newQuery(null); - } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleFactory.java index 5e9ff8007bc..6fe12ad0704 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface AccessRoleFactory extends KapuaEntityFactory { +public interface AccessRoleFactory extends KapuaEntityFactory { } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleQuery.java deleted file mode 100644 index 5f0276e686d..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link AccessRole} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AccessRoleXmlRegistry.class, factoryMethod = "newQuery") -public interface AccessRoleQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleXmlRegistry.java index 1131edbd059..eba9eed0899 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/access/AccessRoleXmlRegistry.java @@ -39,7 +39,4 @@ public AccessRoleCreator newCreator() { return accessRoleFactory.newCreator(null); } - public AccessRoleQuery newQuery() { - return accessRoleFactory.newQuery(null); - } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainFactory.java index a99af9f63b0..4a8154eb2f6 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainFactory.java @@ -20,7 +20,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface DomainFactory extends KapuaEntityFactory { +public interface DomainFactory extends KapuaEntityFactory { /** * Instantiates a new {@link DomainCreator} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainQuery.java deleted file mode 100644 index fd3361f781f..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.domain; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link Domain} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = DomainXmlRegistry.class, factoryMethod = "newQuery") -public interface DomainQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainXmlRegistry.java deleted file mode 100644 index 5a9157c13d2..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/domain/DomainXmlRegistry.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.domain; - -import org.eclipse.kapua.locator.KapuaLocator; - -import javax.xml.bind.annotation.XmlRegistry; - -@XmlRegistry -public class DomainXmlRegistry { - - private final DomainFactory domainFactory = KapuaLocator.getInstance().getFactory(DomainFactory.class); - - public DomainQuery newQuery() { - return domainFactory.newQuery(null); - } -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupFactory.java index 2aa4e192bba..670acfe713b 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupFactory.java @@ -21,7 +21,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface GroupFactory extends KapuaEntityFactory { +public interface GroupFactory extends KapuaEntityFactory { /** * Instantiates a new {@link GroupCreator}. diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupMatchPredicate.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupMatchPredicate.java index 23afb4f1acc..4b9c6f39761 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupMatchPredicate.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupMatchPredicate.java @@ -12,8 +12,24 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.group; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface GroupMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; + +public class GroupMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public GroupMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + GroupAttributes.DESCRIPTION, + GroupAttributes.NAME + ); + this.matchTerm = matchTerm; + } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupQuery.java index 94b9a53d183..2bbda048653 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupQuery.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.group; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link Group} {@link KapuaQuery} definition. * @@ -27,15 +28,31 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = GroupXmlRegistry.class, factoryMethod = "newQuery") -public interface GroupQuery extends KapuaQuery { +@XmlType +public class GroupQuery extends KapuaQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public GroupQuery(KapuaId scopeId) { + super(scopeId); + } + /** * Instantiates a new {@link GroupMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link GroupMatchPredicate}. * @since 2.1.0 */ - GroupMatchPredicate matchPredicate(T matchTerm); + public GroupMatchPredicate matchPredicate(T matchTerm) { + return new GroupMatchPredicate<>(matchTerm); + } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupXmlRegistry.java index 60c3299bd2b..58d75b19f3f 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/group/GroupXmlRegistry.java @@ -40,14 +40,4 @@ public Group newGroup() { public GroupCreator newGroupCreator() { return groupFactory.newCreator(null, null); } - - /** - * Creates a new {@link GroupQuery} instance. - * - * @return The newly created {@link GroupQuery} instance. - * @since 1.0.0 - */ - public GroupQuery newQuery() { - return groupFactory.newQuery(null); - } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleFactory.java index 8fa873eae5c..44b89b7e46e 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleFactory.java @@ -20,7 +20,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface RoleFactory extends KapuaEntityFactory { +public interface RoleFactory extends KapuaEntityFactory { /** * Instantiates a new {@link RolePermission}. diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleMatchPredicate.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleMatchPredicate.java index 5f1e7edbfc6..f7b00050624 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleMatchPredicate.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleMatchPredicate.java @@ -12,8 +12,23 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.role; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface RoleMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; +public class RoleMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public RoleMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + RoleAttributes.DESCRIPTION, + RoleAttributes.NAME + ); + this.matchTerm = matchTerm; + } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionFactory.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionFactory.java index f524ba277f9..3f22b6ff052 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionFactory.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionFactory.java @@ -20,6 +20,6 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface RolePermissionFactory extends KapuaEntityFactory { +public interface RolePermissionFactory extends KapuaEntityFactory { } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionQuery.java deleted file mode 100644 index 5de910b2579..00000000000 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionQuery.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role; - -import org.eclipse.kapua.model.query.KapuaQuery; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link RolePermission} {@link KapuaQuery} definition. - * - * @see KapuaQuery - * @since 1.0.0 - */ -@XmlRootElement(name = "query") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = RolePermissionXmlRegistry.class, factoryMethod = "newQuery") -public interface RolePermissionQuery extends KapuaQuery { -} diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionXmlRegistry.java index 5595b62d70f..e03cd41004a 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RolePermissionXmlRegistry.java @@ -39,7 +39,4 @@ public RolePermissionCreator newCreator() { return rolePermissionFactory.newCreator(null); } - public RolePermissionQuery newQuery() { - return rolePermissionFactory.newQuery(null); - } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleQuery.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleQuery.java index 36d8b3a692b..e3d3c6d93ea 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleQuery.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.role; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link Role} {@link KapuaQuery} definition. * @@ -26,16 +27,42 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = RoleXmlRegistry.class, factoryMethod = "newQuery") -public interface RoleQuery extends KapuaQuery { +@XmlType +public class RoleQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + public RoleQuery() { + super(); + } + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public RoleQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } + /** * Instantiates a new {@link RoleMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link RoleMatchPredicate}. * @since 2.1.0 */ - RoleMatchPredicate matchPredicate(T matchTerm); + public RoleMatchPredicate matchPredicate(T matchTerm) { + return new RoleMatchPredicate<>(matchTerm); + } } diff --git a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleXmlRegistry.java b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleXmlRegistry.java index 003054d4aa2..982975a8dca 100644 --- a/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleXmlRegistry.java +++ b/service/security/authorization/api/src/main/java/org/eclipse/kapua/service/authorization/role/RoleXmlRegistry.java @@ -40,14 +40,4 @@ public Role newRole() { public RoleCreator newRoleCreator() { return roleFactory.newCreator(null); } - - /** - * Creates a new {@link RoleQuery} instance. - * - * @return The newly created {@link RoleQuery} instance. - * @since 1.0.0 - */ - public RoleQuery newQuery() { - return roleFactory.newQuery(null); - } } diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/CertificateFactory.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/CertificateFactory.java index d4864bd3fe2..ad5d0549dc5 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/CertificateFactory.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/CertificateFactory.java @@ -20,7 +20,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface CertificateFactory extends KapuaEntityFactory { +public interface CertificateFactory extends KapuaEntityFactory { /** * Instantiates a new {@link CertificateUsage}. @@ -53,5 +53,4 @@ public interface CertificateFactory extends KapuaEntityFactory { +public interface CertificateInfoFactory extends KapuaEntityFactory { } diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java index 80d1166cb16..92036c50b41 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java @@ -12,8 +12,26 @@ *******************************************************************************/ package org.eclipse.kapua.service.certificate.info; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface CertificateInfoMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; +public class CertificateInfoMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public CertificateInfoMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + CertificateInfoAttributes.NAME, + CertificateInfoAttributes.SERIAL, + CertificateInfoAttributes.SIGNATURE, + CertificateInfoAttributes.ALGORITHM, + CertificateInfoAttributes.SUBJECT + ); + this.matchTerm = matchTerm; + } } \ No newline at end of file diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java index 1bf1f33dee5..531001c5790 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java @@ -12,16 +12,16 @@ *******************************************************************************/ package org.eclipse.kapua.service.certificate.info; -import org.eclipse.kapua.model.query.KapuaForwardableEntityQuery; -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.service.certificate.info.xml.CertificateInfoXmlRegistry; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaForwardableEntityQuery; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link CertificateInfo} {@link KapuaQuery} definition. * @@ -30,8 +30,19 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = CertificateInfoXmlRegistry.class, factoryMethod = "newQuery") -public interface CertificateInfoQuery extends KapuaForwardableEntityQuery { +@XmlType +public class CertificateInfoQuery extends KapuaForwardableEntityQuery { + + public CertificateInfoQuery() { + } + + public CertificateInfoQuery(KapuaId scopeId) { + super(scopeId); + } + + public CertificateInfoQuery(KapuaQuery query) { + super(query); + } @Override /** @@ -41,7 +52,9 @@ public interface CertificateInfoQuery extends KapuaForwardableEntityQuery { * @since 1.1.0 */ @XmlElement(name = "includeInherited") - Boolean getIncludeInherited(); + public Boolean getIncludeInherited() { + return includeInherited; + } @Override /** @@ -50,15 +63,21 @@ public interface CertificateInfoQuery extends KapuaForwardableEntityQuery { * @param includeInherited {@code true} to get inherited {@link CertificateInfo}s, {@code false} otherwise. * @since 1.1.0 */ - void setIncludeInherited(Boolean includeInherited); + public void setIncludeInherited(Boolean includeInherited) { + this.includeInherited = includeInherited; + } /** * Instantiates a new {@link CertificateInfoMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link CertificateInfoMatchPredicate}. * @since 2.1.0 */ - CertificateInfoMatchPredicate matchPredicate(T matchTerm); + public CertificateInfoMatchPredicate matchPredicate(T matchTerm) { + return new CertificateInfoMatchPredicate<>(matchTerm); + } } diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/xml/CertificateInfoXmlRegistry.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/xml/CertificateInfoXmlRegistry.java index 0da71c138a1..cd4d810065c 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/xml/CertificateInfoXmlRegistry.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/xml/CertificateInfoXmlRegistry.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.certificate.info.CertificateInfo; import org.eclipse.kapua.service.certificate.info.CertificateInfoCreator; import org.eclipse.kapua.service.certificate.info.CertificateInfoFactory; -import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; @XmlRegistry public class CertificateInfoXmlRegistry { @@ -33,7 +32,4 @@ public CertificateInfoCreator newCreator() { return certificateInfoFactory.newCreator(null); } - public CertificateInfoQuery newQuery() { - return certificateInfoFactory.newQuery(null); - } } diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/xml/CertificateXmlRegistry.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/xml/CertificateXmlRegistry.java index 52e69f3fb16..7e3ab86d667 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/xml/CertificateXmlRegistry.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/xml/CertificateXmlRegistry.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.certificate.CertificateCreator; import org.eclipse.kapua.service.certificate.CertificateFactory; import org.eclipse.kapua.service.certificate.CertificateGenerator; -import org.eclipse.kapua.service.certificate.CertificateQuery; import org.eclipse.kapua.service.certificate.CertificateUsage; @XmlRegistry @@ -35,10 +34,6 @@ public CertificateCreator newCreator() { return certificateFactory.newCreator(null); } - public CertificateQuery newQuery() { - return certificateFactory.newQuery(null); - } - public CertificateGenerator newCertificateGenerator() { return certificateFactory.newCertificateGenerator(); } diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoFactoryImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoFactoryImpl.java index 8b3184f3c08..e5a2cd7c0e3 100644 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoFactoryImpl.java +++ b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.certificate.info.CertificateInfo; import org.eclipse.kapua.service.certificate.info.CertificateInfoCreator; import org.eclipse.kapua.service.certificate.info.CertificateInfoFactory; -import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; @Singleton public class CertificateInfoFactoryImpl implements CertificateInfoFactory { @@ -34,11 +33,6 @@ public CertificateInfoCreator newCreator(KapuaId scopeId) { throw new UnsupportedOperationException(); } - @Override - public CertificateInfoQuery newQuery(KapuaId scopeId) { - return new CertificateInfoQueryImpl(scopeId); - } - @Override public CertificateInfo clone(CertificateInfo certificateInfo) throws KapuaEntityCloneException { try { diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java deleted file mode 100644 index 4d42434e7a5..00000000000 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.certificate.info.internal; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.certificate.info.CertificateInfoAttributes; -import org.eclipse.kapua.service.certificate.info.CertificateInfoMatchPredicate; - -import java.util.Arrays; - -public class CertificateInfoMatchPredicateImpl extends AbstractMatchPredicate implements CertificateInfoMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 2.1.0 - */ - public CertificateInfoMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - CertificateInfoAttributes.NAME, - CertificateInfoAttributes.SERIAL, - CertificateInfoAttributes.SIGNATURE, - CertificateInfoAttributes.ALGORITHM, - CertificateInfoAttributes.SUBJECT - ); - this.matchTerm = matchTerm; - } - -} diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java deleted file mode 100644 index 3c64874d30f..00000000000 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.certificate.info.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.certificate.info.CertificateInfoMatchPredicate; -import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; - -/** - * {@link CertificateInfoQuery} implementation. - * - * @since 1.0.0 - */ -public class CertificateInfoQueryImpl extends AbstractKapuaNamedQuery implements CertificateInfoQuery { - - private Boolean includeInherited = Boolean.FALSE; - - /** - * Constructor. - * - * @since 1.0.0 - */ - private CertificateInfoQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public CertificateInfoQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public Boolean getIncludeInherited() { - return includeInherited; - } - - @Override - public void setIncludeInherited(Boolean includeInherited) { - this.includeInherited = includeInherited; - } - - @Override - public CertificateInfoMatchPredicate matchPredicate(T matchTerm) { - return new CertificateInfoMatchPredicateImpl<>(matchTerm); - } -} diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoServiceImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoServiceImpl.java index 2fbd815de1a..0d248c93046 100644 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoServiceImpl.java +++ b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoServiceImpl.java @@ -29,7 +29,6 @@ import org.eclipse.kapua.service.certificate.info.CertificateInfoListResult; import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; import org.eclipse.kapua.service.certificate.info.CertificateInfoService; -import org.eclipse.kapua.service.certificate.internal.CertificateQueryImpl; @Singleton public class CertificateInfoServiceImpl implements CertificateInfoService { @@ -55,7 +54,7 @@ public CertificateInfo find(KapuaId scopeId, KapuaId entityId) { public CertificateInfoListResult query(KapuaQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); - CertificateQuery certificateQuery = new CertificateQueryImpl(query); + CertificateQuery certificateQuery = new CertificateQuery(query); CertificateInfoListResult publicCertificates = new CertificateInfoListResult(); publicCertificates.addItem(certificateService.query(certificateQuery).getFirstItem()); @@ -67,7 +66,7 @@ public CertificateInfoListResult query(KapuaQuery query) throws KapuaException { public long count(KapuaQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); - CertificateQuery privateQuery = new CertificateQueryImpl(query); + CertificateQuery privateQuery = new CertificateQuery(query); privateQuery.setIncludeInherited(((CertificateInfoQuery) query).getIncludeInherited()); return certificateService.count(privateQuery); diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateFactoryImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateFactoryImpl.java index 64420883810..5dad8bd6097 100644 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateFactoryImpl.java +++ b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateFactoryImpl.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.service.certificate.CertificateCreator; import org.eclipse.kapua.service.certificate.CertificateFactory; import org.eclipse.kapua.service.certificate.CertificateGenerator; -import org.eclipse.kapua.service.certificate.CertificateQuery; import org.eclipse.kapua.service.certificate.CertificateUsage; import org.eclipse.kapua.service.certificate.KeyUsage; import org.eclipse.kapua.service.certificate.KeyUsageSetting; @@ -43,11 +42,6 @@ public CertificateCreator newCreator(KapuaId scopeId) { throw new UnsupportedOperationException(); } - @Override - public CertificateQuery newQuery(KapuaId scopeId) { - return new CertificateQueryImpl(scopeId); - } - @Override public CertificateUsage newCertificateUsage(String name) { return new CertificateUsageImpl(name); diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateQueryImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateQueryImpl.java deleted file mode 100644 index 5a7fc108e9a..00000000000 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/internal/CertificateQueryImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.certificate.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaForwardableEntityQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.service.certificate.CertificateQuery; - -/** - * {@link CertificateQuery} implementation. - * - * @since 1.0.0 - */ -public class CertificateQueryImpl extends AbstractKapuaForwardableEntityQuery implements CertificateQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private CertificateQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public CertificateQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - /** - * Clone constructor. - * - * @param query The {@link CertificateQuery} to clone. - * @since 1.0.0 - */ - public CertificateQueryImpl(KapuaQuery query) { - super(query); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImpl.java index a6b119cdeb1..1deced40bf4 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionCreator; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionFactory; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionQuery; /** * {@link MfaOptionFactory} implementation. @@ -32,11 +31,6 @@ public MfaOption newEntity(KapuaId scopeId) { return new MfaOptionImpl(scopeId); } - @Override - public MfaOptionQuery newQuery(KapuaId scopeId) { - return new MfaOptionQueryImpl(scopeId); - } - @Override public MfaOptionCreator newCreator(KapuaId scopeId) { return new MfaOptionCreatorImpl(scopeId); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImpl.java deleted file mode 100644 index e1a52d227b0..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential.mfa.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionQuery; - -/** - * {@link MfaOption} query implementation. - * - * @since 1.3.0 - */ -public class MfaOptionQueryImpl extends AbstractKapuaQuery implements MfaOptionQuery { - - /** - * Constructor. - * - * @since 1.3.0 - */ - public MfaOptionQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.3.0 - */ - public MfaOptionQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImpl.java index ea51f3eb37b..1f309b75fc1 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImpl.java @@ -21,7 +21,6 @@ import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; /** @@ -47,11 +46,6 @@ public Credential newCredential(KapuaId scopeId, KapuaId userId, String credenti return new CredentialImpl(scopeId, userId, credentialType, credentialKey, credentialStatus, expirationDate); } - @Override - public CredentialQuery newQuery(KapuaId scopeId) { - return new CredentialQueryImpl(scopeId); - } - @Override public CredentialCreator newCreator(KapuaId scopeId) { return new CredentialCreatorImpl(scopeId); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImpl.java deleted file mode 100644 index 43a4cd87e62..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; - -/** - * {@link CredentialQuery} implementation. - * - * @since 1.0.0 - */ -public class CredentialQueryImpl extends AbstractKapuaQuery implements CredentialQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public CredentialQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public CredentialQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialServiceImpl.java index 3907e7faa3e..ead13e1d321 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialServiceImpl.java @@ -14,7 +14,12 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.stream.Collectors; + import javax.inject.Singleton; import org.eclipse.kapua.KapuaEntityNotFoundException; @@ -33,13 +38,12 @@ import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialAttributes; -import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialRepository; import org.eclipse.kapua.service.authentication.credential.CredentialService; +import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; import org.eclipse.kapua.service.authentication.shiro.CredentialServiceConfigurationManager; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSetting; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSettingKeys; @@ -50,11 +54,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - /** * {@link CredentialService} implementation. * @@ -138,12 +137,12 @@ public Credential create(CredentialCreator credentialCreator) // Convert creator to entity Credential newCredential = new CredentialImpl( - credentialCreator.getScopeId(), - credentialCreator.getUserId(), - credentialCreator.getCredentialType(), - encryptedKey, - credentialCreator.getCredentialStatus(), - credentialCreator.getExpirationDate() + credentialCreator.getScopeId(), + credentialCreator.getUserId(), + credentialCreator.getCredentialType(), + encryptedKey, + credentialCreator.getCredentialStatus(), + credentialCreator.getExpirationDate() ); // Do create @@ -272,13 +271,13 @@ public CredentialListResult findByUserId(KapuaId scopeId, KapuaId userId, String authorizationService.checkPermission(permissionFactory.newPermission(Domains.CREDENTIAL, Actions.read, scopeId)); // Do find - CredentialQuery credentialQuery = new CredentialQueryImpl(scopeId); + KapuaQuery credentialQuery = new KapuaQuery(scopeId); credentialQuery.setPredicate( - credentialQuery.andPredicate( - credentialQuery.attributePredicate(CredentialAttributes.USER_ID, userId), - credentialQuery.attributePredicate(CredentialAttributes.CREDENTIAL_TYPE, credentialType) - ) + credentialQuery.andPredicate( + credentialQuery.attributePredicate(CredentialAttributes.USER_ID, userId), + credentialQuery.attributePredicate(CredentialAttributes.CREDENTIAL_TYPE, credentialType) + ) ); CredentialListResult credentials = txManager.execute(tx -> credentialRepository.query(tx, credentialQuery)); @@ -286,8 +285,6 @@ public CredentialListResult findByUserId(KapuaId scopeId, KapuaId userId, String return credentials; } - - @Override public Credential findByApiKey(String apiKey) throws KapuaException { int preLength = kapuaAuthenticationSetting.getInt(KapuaAuthenticationSettingKeys.AUTHENTICATION_CREDENTIAL_APIKEY_PRE_LENGTH); @@ -301,13 +298,13 @@ public Credential findByApiKey(String apiKey) throws KapuaException { String apiKeyPreValue = apiKey.substring(0, preLength).concat(preSeparator); // Build query - KapuaQuery query = new CredentialQueryImpl(); + KapuaQuery query = new KapuaQuery(); query.setPredicate( - query.andPredicate( - query.attributePredicate(CredentialAttributes.CREDENTIAL_TYPE, "API_KEY"), - query.attributePredicate(CredentialAttributes.CREDENTIAL_KEY, apiKeyPreValue, AttributePredicate.Operator.STARTS_WITH) - ) + query.andPredicate( + query.attributePredicate(CredentialAttributes.CREDENTIAL_TYPE, "API_KEY"), + query.attributePredicate(CredentialAttributes.CREDENTIAL_KEY, apiKeyPreValue, AttributePredicate.Operator.STARTS_WITH) + ) ); // Query @@ -368,7 +365,7 @@ private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws Ka KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); - CredentialQuery query = credentialFactory.newQuery(scopeId); + KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); @@ -382,7 +379,7 @@ private void deleteCredentialByAccountId(KapuaId scopeId, KapuaId accountId) thr KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); - CredentialQuery query = credentialFactory.newQuery(accountId); + final KapuaQuery query = new KapuaQuery(accountId); CredentialListResult credentialsToDelete = query(query); @@ -426,7 +423,6 @@ public Credential adminResetUserPassword(KapuaId scopeId, KapuaId userId, Passwo return txManager.execute(tx -> passwordResetter.resetPassword(tx, scopeId, userId, false, passwordResetRequest)); } - @Override public Set getAvailableCredentialTypes() { return availableCredentialAuthenticationType.keySet(); @@ -434,8 +430,8 @@ public Set getAvailableCredentialTypes() { private boolean tryEditAdminFields(Credential updated, Credential current) { return updated.getLoginFailures() != current.getLoginFailures() || - updated.getFirstLoginFailure() != current.getFirstLoginFailure() || - updated.getLoginFailuresReset() != current.getLoginFailuresReset() || - updated.getLockoutReset() != current.getLockoutReset(); + updated.getFirstLoginFailure() != current.getFirstLoginFailure() || + updated.getLoginFailuresReset() != current.getLoginFailuresReset() || + updated.getLockoutReset() != current.getLockoutReset(); } } diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java index 4d26e755b39..ad8534dd38d 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java @@ -17,10 +17,10 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; + import javax.inject.Inject; import javax.inject.Singleton; -import com.google.common.collect.Sets; import org.apache.shiro.SecurityUtils; import org.apache.shiro.ShiroException; import org.apache.shiro.authc.AuthenticationException; @@ -42,6 +42,8 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.commons.security.KapuaSession; import org.eclipse.kapua.commons.util.KapuaDelayUtil; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.authentication.AuthenticationCredentials; @@ -65,7 +67,6 @@ import org.eclipse.kapua.service.authentication.token.AccessTokenAttributes; import org.eclipse.kapua.service.authentication.token.AccessTokenCreator; import org.eclipse.kapua.service.authentication.token.AccessTokenFactory; -import org.eclipse.kapua.service.authentication.token.AccessTokenQuery; import org.eclipse.kapua.service.authentication.token.AccessTokenService; import org.eclipse.kapua.service.authentication.token.LoginInfo; import org.eclipse.kapua.service.authorization.access.AccessInfo; @@ -73,18 +74,15 @@ import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.role.RolePermissionAttributes; import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionService; import org.eclipse.kapua.service.certificate.Certificate; import org.eclipse.kapua.service.certificate.CertificateAttributes; @@ -109,6 +107,8 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; +import com.google.common.collect.Sets; + /** * {@link AuthenticationService} implementation. * @@ -371,7 +371,7 @@ public AccessToken findAccessToken(String jwt) throws KapuaException { @Override public AccessToken findRefreshableAccessToken(String tokenId) throws KapuaException { - AccessTokenQuery accessTokenQuery = accessTokenFactory.newQuery(null); + KapuaQuery accessTokenQuery = new KapuaQuery((KapuaId) null); AndPredicate andPredicate = accessTokenQuery.andPredicate( accessTokenQuery.attributePredicate(AccessTokenAttributes.REFRESH_EXPIRES_ON, new java.sql.Timestamp(new Date().getTime()), AttributePredicate.Operator.GREATER_THAN_OR_EQUAL), accessTokenQuery.attributePredicate(AccessTokenAttributes.INVALIDATED_ON, null, AttributePredicate.Operator.IS_NULL), @@ -423,18 +423,19 @@ public LoginInfo getLoginInfo() throws KapuaException { AccessInfo accessInfo = KapuaSecurityUtils.doPrivileged(() -> accessInfoService.findByUserId(accessToken.getScopeId(), accessToken.getUserId())); // AccessRole - AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(accessToken.getScopeId()); + final KapuaQuery accessRoleQuery = new KapuaQuery(accessToken.getScopeId()); accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId())); AccessRoleListResult accessRoleListResult = KapuaSecurityUtils.doPrivileged(() -> accessRoleService.query(accessRoleQuery)); // RolePermission - RolePermissionQuery rolePermissionQuery = rolePermissionFactory.newQuery(accessToken.getScopeId()); - rolePermissionQuery.setPredicate(rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, accessRoleListResult.getItems().stream().map(AccessRole::getRoleId).collect(Collectors.toList()))); + final KapuaQuery rolePermissionQuery = new KapuaQuery(accessToken.getScopeId()); + rolePermissionQuery.setPredicate( + rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, accessRoleListResult.getItems().stream().map(AccessRole::getRoleId).collect(Collectors.toList()))); RolePermissionListResult rolePermissions = KapuaSecurityUtils.doPrivileged(() -> rolePermissionService.query(rolePermissionQuery)); loginInfo.setRolePermission(Sets.newHashSet(rolePermissions.getItems())); // AccessPermission - AccessPermissionQuery accessPermissionQuery = accessPermissionFactory.newQuery(accessToken.getScopeId()); + final KapuaQuery accessPermissionQuery = new KapuaQuery(accessToken.getScopeId()); accessPermissionQuery.setPredicate(accessPermissionQuery.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfo.getId())); AccessPermissionListResult accessPermissions = KapuaSecurityUtils.doPrivileged(() -> accessPermissionService.query(accessPermissionQuery)); loginInfo.setAccessPermission(Sets.newHashSet(accessPermissions.getItems())); @@ -459,10 +460,10 @@ public boolean isAuthenticated() // /** - * Checks if the Shiro {@link Subject} is authenticated or not. - * If {@link Subject#isAuthenticated()} {@code equals true}, {@link KapuaAuthenticationException} is raised. + * Checks if the Shiro {@link Subject} is authenticated or not. If {@link Subject#isAuthenticated()} {@code equals true}, {@link KapuaAuthenticationException} is raised. * - * @throws KapuaAuthenticationException If {@link Subject#isAuthenticated()} {@code equals true} + * @throws KapuaAuthenticationException + * If {@link Subject#isAuthenticated()} {@code equals true} * @since 1.0 */ private void checkCurrentSubjectNotAuthenticated() @@ -478,9 +479,11 @@ private void checkCurrentSubjectNotAuthenticated() /** * Converts am instance of {@link AuthenticationCredentials} to the compatible {@link KapuaAuthenticationToken} to be used in Apache Shiro. * - * @param authenticationCredentials The {@link AuthenticationCredentials} to convert + * @param authenticationCredentials + * The {@link AuthenticationCredentials} to convert * @return The converted {@link KapuaAuthenticationToken}. - * @throws KapuaAuthenticationException if the instance of {@link AuthenticationCredentials} cannot be handled or is are invalid. + * @throws KapuaAuthenticationException + * if the instance of {@link AuthenticationCredentials} cannot be handled or is are invalid. * @since 2.0.0 */ private KapuaAuthenticationToken doMapToShiro(AuthenticationCredentials authenticationCredentials) throws KapuaAuthenticationException { @@ -529,7 +532,8 @@ private void handleTokenLoginException(ShiroException se, Subject currentSubject /** * Create and persist a {@link AccessToken} from the data contained in the Shiro {@link Session} * - * @param session The Shiro {@link Session} from which extract data + * @param session + * The Shiro {@link Session} from which extract data * @return The persisted {@link AccessToken} * @throws KapuaException * @since 1.0 @@ -545,8 +549,10 @@ private AccessToken createAccessToken(Session session) throws KapuaException { /** * Create and persist a {@link AccessToken} from a scopeId and a userId * - * @param scopeId The scopeID - * @param userId The userID + * @param scopeId + * The scopeID + * @param userId + * The userID * @return The persisted {@link AccessToken} * @throws KapuaException * @since 1.0.0 @@ -583,8 +589,10 @@ private AccessToken createAccessToken(KapuaEid scopeId, KapuaEid userId) throws /** * Creates a trust key if given {@link AuthenticationToken} is a {@link UsernamePasswordCredentials} and if {@link UsernamePasswordCredentials#getTrustMe()} is {@code true} * - * @param shiroAuthenticationToken The {@link AuthenticationToken} extracted {@link LoginCredentials} - * @param accessToken The {@link AccessToken} of this login. + * @param shiroAuthenticationToken + * The {@link AuthenticationToken} extracted {@link LoginCredentials} + * @param accessToken + * The {@link AccessToken} of this login. * @throws KapuaException * @since 2.0.0 */ @@ -639,7 +647,7 @@ private String generateJwt(KapuaEid scopeId, KapuaEid userId, Date now, long ttl String jwt = null; try { - CertificateQuery certificateQuery = certificateFactory.newQuery(scopeId); + CertificateQuery certificateQuery = new CertificateQuery(scopeId); certificateQuery.setPredicate( certificateQuery.andPredicate( certificateQuery.attributePredicate(CertificateAttributes.USAGE_NAME, "JWT"), @@ -670,8 +678,8 @@ private String generateJwt(KapuaEid scopeId, KapuaEid userId, Date now, long ttl *

* As of 2.1.0, only PASSWORD credentials can be locked. * - * @param authenticationToken The {@link AuthenticationToken} for the login attempt. - * + * @param authenticationToken + * The {@link AuthenticationToken} for the login attempt. * @since 1.1.0 */ private Boolean checkIfCredentialHasJustBeenLocked(AuthenticationToken authenticationToken) throws KapuaException { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java index 4f44e823018..54ad5241ade 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java @@ -110,12 +110,12 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authent } // Set validator final JwtConsumer jwtConsumer = new JwtConsumerBuilder() - .setVerificationKey(CertificateUtils.stringToCertificate(certificateInfo.getCertificate()).getPublicKey()) // Set public key - .setExpectedIssuer(issuer) // Set expected issuer - .setRequireIssuedAt() // Set require reserved claim: iatp - .setRequireExpirationTime() // Set require reserved claim: exp - .setRequireSubject() // // Set require reserved claim: sub - .build(); + .setVerificationKey(CertificateUtils.stringToCertificate(certificateInfo.getCertificate()).getPublicKey()) // Set public key + .setExpectedIssuer(issuer) // Set expected issuer + .setRequireIssuedAt() // Set require reserved claim: iatp + .setRequireExpirationTime() // Set require reserved claim: exp + .setRequireSubject() // // Set require reserved claim: sub + .build(); // This validates JWT final JwtContext jwtContext = jwtConsumer.process(jwt); jwtClaims = jwtContext.getJwtClaims(); @@ -178,7 +178,6 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authent accessToken); } - @Override protected void assertCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) throws AuthenticationException { @@ -199,14 +198,13 @@ public boolean supports(AuthenticationToken authenticationToken) { return authenticationToken instanceof AccessTokenCredentialsImpl; } - private CertificateInfo getNearestCertificate(AuthenticationToken authenticationToken) - throws KapuaException, InvalidJwtException, MalformedClaimException { + throws KapuaException, InvalidJwtException, MalformedClaimException { final JwtConsumer jwtConsumerNoValidation = new JwtConsumerBuilder() - .setSkipAllValidators() - .setDisableRequireSignature() - .setSkipSignatureVerification() - .build(); + .setSkipAllValidators() + .setDisableRequireSignature() + .setSkipSignatureVerification() + .build(); final String principal = (String) authenticationToken.getPrincipal(); final String username = jwtConsumerNoValidation.process(principal).getJwtClaims().getSubject(); final String account = jwtConsumerNoValidation.process(principal).getJwtClaims().getClaimValueAsString("sId"); @@ -214,12 +212,12 @@ private CertificateInfo getNearestCertificate(AuthenticationToken authentication final KapuaId accountId = KapuaEid.parseCompactId(account); final User user = KapuaSecurityUtils.doPrivileged(() -> userService.find(accountId, userId)); - final CertificateInfoQuery certificateInfoQuery = certificateInfoFactory.newQuery(user.getScopeId()); + final CertificateInfoQuery certificateInfoQuery = new CertificateInfoQuery(user.getScopeId()); certificateInfoQuery.setPredicate( - certificateInfoQuery.andPredicate( - certificateInfoQuery.attributePredicate(CertificateAttributes.USAGE_NAME, "JWT"), - certificateInfoQuery.attributePredicate(CertificateAttributes.STATUS, CertificateStatus.VALID) - ) + certificateInfoQuery.andPredicate( + certificateInfoQuery.attributePredicate(CertificateAttributes.USAGE_NAME, "JWT"), + certificateInfoQuery.attributePredicate(CertificateAttributes.STATUS, CertificateStatus.VALID) + ) ); certificateInfoQuery.setIncludeInherited(true); @@ -227,7 +225,6 @@ private CertificateInfo getNearestCertificate(AuthenticationToken authentication return getNearestCertificateFromList(certificateInfoList); } - private CertificateInfo getNearestCertificateFromList(CertificateInfoListResult certificateInfoList) throws KapuaException { CertificateInfo result = certificateInfoList.getFirstItem(); for (CertificateInfo certificateInfo : certificateInfoList.getItems()) { @@ -238,14 +235,12 @@ private CertificateInfo getNearestCertificateFromList(CertificateInfoListResult return result; } - private boolean isNearestThat(CertificateInfo certificateInfo, CertificateInfo result) throws KapuaException { final KapuaId certificateInfoScopeId = certificateInfo.getScopeId(); final KapuaId resultScopeId = result.getScopeId(); return isChildOf(certificateInfoScopeId, resultScopeId); } - private boolean isChildOf(KapuaId certificateInfoScopeId, KapuaId resultScopeId) throws KapuaException { final Account certificateInfoAccount = KapuaSecurityUtils.doPrivileged(() -> accountService.find(certificateInfoScopeId)); final Account resultAccount = KapuaSecurityUtils.doPrivileged(() -> accountService.find(resultScopeId)); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java index 2d182d7d659..6ad2172e746 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java @@ -26,7 +26,6 @@ import org.eclipse.kapua.service.certificate.CertificateAttributes; import org.eclipse.kapua.service.certificate.CertificateStatus; import org.eclipse.kapua.service.certificate.info.CertificateInfo; -import org.eclipse.kapua.service.certificate.info.CertificateInfoFactory; import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; import org.eclipse.kapua.service.certificate.info.CertificateInfoService; import org.eclipse.kapua.service.certificate.util.CertificateUtils; @@ -46,7 +45,6 @@ public class AccessTokenCredentialsMatcher implements CredentialsMatcher { private static final Logger LOG = LoggerFactory.getLogger(AccessTokenCredentialsMatcher.class); private final CertificateInfoService certificateInfoService = KapuaLocator.getInstance().getService(CertificateInfoService.class); - private final CertificateInfoFactory certificateInfoFactory = KapuaLocator.getInstance().getFactory(CertificateInfoFactory.class); private final KapuaAuthenticationSetting kapuaAuthenticationSetting = KapuaLocator.getInstance().getComponent(KapuaAuthenticationSetting.class); @Override @@ -57,7 +55,7 @@ public boolean doCredentialsMatch(AuthenticationToken authenticationToken, Authe try { String issuer = kapuaAuthenticationSetting.getString(KapuaAuthenticationSettingKeys.AUTHENTICATION_SESSION_JWT_ISSUER); - CertificateInfoQuery certificateInfoQuery = certificateInfoFactory.newQuery(null); + CertificateInfoQuery certificateInfoQuery = new CertificateInfoQuery(); certificateInfoQuery.setPredicate( certificateInfoQuery.andPredicate( certificateInfoQuery.attributePredicate(CertificateAttributes.USAGE_NAME, "JWT"), diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImpl.java index 56d100af555..d23c792391f 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImpl.java @@ -21,7 +21,6 @@ import org.eclipse.kapua.service.authentication.token.AccessToken; import org.eclipse.kapua.service.authentication.token.AccessTokenCreator; import org.eclipse.kapua.service.authentication.token.AccessTokenFactory; -import org.eclipse.kapua.service.authentication.token.AccessTokenQuery; import org.eclipse.kapua.service.authentication.token.LoginInfo; /** @@ -56,11 +55,6 @@ public AccessTokenCreator newCreator(KapuaId scopeId) { return new AccessTokenCreatorImpl(scopeId); } - @Override - public AccessTokenQuery newQuery(KapuaId scopeId) { - return new AccessTokenQueryImpl(scopeId); - } - @Override public AccessToken clone(AccessToken accessToken) { try { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImpl.java deleted file mode 100644 index 2b7d7f7c9aa..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.token.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authentication.token.AccessTokenQuery; - -/** - * {@link AccessTokenQuery} implementation. - * - * @since 1.0.0 - */ -public class AccessTokenQueryImpl extends AbstractKapuaQuery implements AccessTokenQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private AccessTokenQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public AccessTokenQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenServiceImpl.java index 1a4c4d1d105..7652107e330 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenServiceImpl.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.token.shiro; +import java.util.Date; +import java.util.Optional; + +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; @@ -26,7 +31,6 @@ import org.eclipse.kapua.service.authentication.token.AccessTokenCreator; import org.eclipse.kapua.service.authentication.token.AccessTokenFactory; import org.eclipse.kapua.service.authentication.token.AccessTokenListResult; -import org.eclipse.kapua.service.authentication.token.AccessTokenQuery; import org.eclipse.kapua.service.authentication.token.AccessTokenRepository; import org.eclipse.kapua.service.authentication.token.AccessTokenService; import org.eclipse.kapua.service.authorization.AuthorizationService; @@ -35,10 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Singleton; -import java.util.Date; -import java.util.Optional; - /** * {@link AccessTokenService} implementation. * @@ -168,7 +168,7 @@ public AccessTokenListResult findByUserId(KapuaId scopeId, KapuaId userId) throw // Check Access authorizationService.checkPermission(permissionFactory.newPermission(Domains.ACCESS_TOKEN, Actions.read, scopeId)); // Build query - AccessTokenQuery query = new AccessTokenQueryImpl(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessTokenAttributes.USER_ID, userId)); // Do query return query(query); @@ -223,7 +223,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { private void deleteAccessTokenByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { - AccessTokenQuery query = new AccessTokenQueryImpl(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessTokenAttributes.USER_ID, userId)); AccessTokenListResult accessTokensToDelete = query(query); @@ -235,7 +235,7 @@ private void deleteAccessTokenByUserId(KapuaId scopeId, KapuaId userId) throws K private void deleteAccessTokenByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - AccessTokenQuery query = new AccessTokenQueryImpl(accountId); + final KapuaQuery query = new KapuaQuery(scopeId); AccessTokenListResult accessTokensToDelete = query(query); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImpl.java index 0985c4cbe21..d14100952d7 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; /** * {@link AccessInfoFactory} implementation. @@ -39,11 +38,6 @@ public AccessInfoCreator newCreator(KapuaId scopeId) { return new AccessInfoCreatorImpl(scopeId); } - @Override - public AccessInfoQuery newQuery(KapuaId scopeId) { - return new AccessInfoQueryImpl(scopeId); - } - @Override public AccessInfo clone(AccessInfo accessInfo) { try { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImpl.java deleted file mode 100644 index 2bf8c254ce0..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; - -/** - * {@link AccessInfoQuery} implementation. - * - * @since 1.0.0 - */ -public class AccessInfoQueryImpl extends AbstractKapuaQuery implements AccessInfoQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AccessInfoQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public AccessInfoQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoServiceImpl.java index cd226537484..02ae11ab102 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoServiceImpl.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.access.shiro; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; @@ -26,7 +28,6 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoRepository; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermission; @@ -46,8 +47,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Singleton; - /** * {@link AccessInfoService} implementation based on JPA. * @@ -70,16 +69,16 @@ public class AccessInfoServiceImpl implements AccessInfoService { private final PermissionValidator permissionValidator; public AccessInfoServiceImpl(AuthorizationService authorizationService, - PermissionFactory permissionFactory, - TxManager txManager, - RoleRepository roleRepository, - AccessRoleFactory accessRoleFactory, - AccessRoleRepository accessRoleRepository, - AccessInfoRepository accessInfoRepository, - AccessInfoFactory accessInfoFactory, - AccessPermissionRepository accessPermissionRepository, - AccessPermissionFactory accessPermissionFactory, - PermissionValidator permissionValidator) { + PermissionFactory permissionFactory, + TxManager txManager, + RoleRepository roleRepository, + AccessRoleFactory accessRoleFactory, + AccessRoleRepository accessRoleRepository, + AccessInfoRepository accessInfoRepository, + AccessInfoFactory accessInfoFactory, + AccessPermissionRepository accessPermissionRepository, + AccessPermissionFactory accessPermissionFactory, + PermissionValidator permissionValidator) { this.authorizationService = authorizationService; this.permissionFactory = permissionFactory; this.txManager = txManager; @@ -223,7 +222,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { } private void deleteAccessInfoByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { - AccessInfoQuery query = accessInfoFactory.newQuery(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessInfoAttributes.USER_ID, userId)); AccessInfoListResult accessInfosToDelete = query(query); @@ -234,7 +233,7 @@ private void deleteAccessInfoByUserId(KapuaId scopeId, KapuaId userId) throws Ka } private void deleteAccessInfoByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - AccessInfoQuery query = accessInfoFactory.newQuery(accountId); + final KapuaQuery query = new KapuaQuery(scopeId); AccessInfoListResult accessInfosToDelete = query(query); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImpl.java index 9b870e015a7..28fe911811f 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; /** * {@link AccessPermissionFactory} implementation. @@ -38,11 +37,6 @@ public AccessPermissionCreator newCreator(KapuaId scopeId) { return new AccessPermissionCreatorImpl(scopeId); } - @Override - public AccessPermissionQuery newQuery(KapuaId scopeId) { - return new AccessPermissionQueryImpl(scopeId); - } - @Override public AccessPermission clone(AccessPermission accessPermission) { return new AccessPermissionImpl(accessPermission); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionImplJpaRepository.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionImplJpaRepository.java index b80c2c6a4db..9d0c9d8f17c 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionImplJpaRepository.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionImplJpaRepository.java @@ -28,10 +28,10 @@ import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionRepository; import org.eclipse.kapua.service.authorization.permission.shiro.PermissionImpl_; import org.eclipse.kapua.storage.TxContext; @@ -46,7 +46,7 @@ public AccessPermissionImplJpaRepository(KapuaJpaRepositoryConfiguration configu @Override public AccessPermissionListResult findByAccessInfoId(TxContext tx, KapuaId scopeId, KapuaId accessInfoId) throws KapuaException { - AccessPermissionQuery query = new AccessPermissionQueryImpl(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId)); return this.query(tx, query); } diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImpl.java deleted file mode 100644 index bd8bfaf7d0e..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; - -/** - * {@link AccessPermissionQuery} implementation. - * - * @since 1.0.0 - */ -public class AccessPermissionQueryImpl extends AbstractKapuaQuery implements AccessPermissionQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AccessPermissionQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public AccessPermissionQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionServiceImpl.java index 95831541558..7b2fe12515b 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionServiceImpl.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.access.shiro; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaEntityUniquenessException; import org.eclipse.kapua.KapuaException; @@ -28,7 +36,6 @@ import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionRepository; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; import org.eclipse.kapua.service.authorization.permission.Permission; @@ -36,13 +43,6 @@ import org.eclipse.kapua.service.authorization.permission.shiro.PermissionValidator; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * {@link AccessPermission} service implementation. * @@ -93,7 +93,7 @@ public AccessPermission create(AccessPermissionCreator accessPermissionCreator) return txManager.execute(tx -> { // Check duplicates - AccessPermissionQuery query = new AccessPermissionQueryImpl(accessPermissionCreator.getScopeId()); + KapuaQuery query = new KapuaQuery(accessPermissionCreator.getScopeId()); query.setPredicate( query.andPredicate( query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, accessPermissionCreator.getScopeId()), diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImpl.java index 0f69305d4ea..d104f53185f 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; /** * {@link AccessRoleFactory} implementation. @@ -39,11 +38,6 @@ public AccessRoleCreator newCreator(KapuaId scopeId) { return new AccessRoleCreatorImpl(scopeId); } - @Override - public AccessRoleQuery newQuery(KapuaId scopeId) { - return new AccessRoleQueryImpl(scopeId); - } - @Override public AccessRole clone(AccessRole accessRole) { try { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImpl.java deleted file mode 100644 index 30d4a79ca4c..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; - -/** - * {@link AccessRoleQuery} implementation. - * - * @since 1.0.0 - */ -public class AccessRoleQueryImpl extends AbstractKapuaQuery implements AccessRoleQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public AccessRoleQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public AccessRoleQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleServiceImpl.java index bd32f1e561e..32e051158b3 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleServiceImpl.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.access.shiro; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; @@ -28,7 +31,6 @@ import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleRepository; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; @@ -37,9 +39,6 @@ import org.eclipse.kapua.service.authorization.role.RoleRepository; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; -import javax.inject.Singleton; - /** * {@link AccessRoleService} implementation. * @@ -90,7 +89,7 @@ public AccessRole create(AccessRoleCreator accessRoleCreator) .orElseThrow(() -> new KapuaEntityNotFoundException(Role.TYPE, accessRoleCreator.getRoleId())); // Check that Role is not already assigned - AccessRoleQuery query = new AccessRoleQueryImpl(accessRoleCreator.getScopeId()); + final KapuaQuery query = new KapuaQuery(accessRoleCreator.getScopeId()); query.setPredicate( query.andPredicate( query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessRoleCreator.getAccessInfoId()), diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/CachingAccessPermissionRepository.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/CachingAccessPermissionRepository.java index 1bd6c57aaf3..c03e7e96c34 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/CachingAccessPermissionRepository.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/access/shiro/CachingAccessPermissionRepository.java @@ -17,16 +17,17 @@ import org.eclipse.kapua.commons.storage.KapuaEntityRepositoryCachingWrapper; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionRepository; import org.eclipse.kapua.storage.TxContext; public class CachingAccessPermissionRepository extends KapuaEntityRepositoryCachingWrapper implements AccessPermissionRepository { + private final AccessPermissionRepository wrapped; public CachingAccessPermissionRepository(AccessPermissionRepository wrapped, EntityCache entityCache) { @@ -56,7 +57,7 @@ public AccessPermissionListResult findByAccessInfoId(TxContext tx, KapuaId scope AccessPermissionListResult listResult = (AccessPermissionListResult) entityCache.getList(scopeId, accessInfoId); if (listResult == null) { // Build query - AccessPermissionQuery query = new AccessPermissionQueryImpl(scopeId); + final KapuaQuery query = new KapuaQuery(scopeId); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId)); listResult = wrapped.findByAccessInfoId(tx, scopeId, accessInfoId); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImpl.java index 2a618267c57..81cdedd3a3b 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainCreator; import org.eclipse.kapua.service.authorization.domain.DomainFactory; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; /** * {@link DomainFactory} implementation. @@ -34,11 +33,6 @@ public DomainCreator newCreator(String name) { return new DomainCreatorImpl(name); } - @Override - public DomainQuery newQuery(KapuaId scopeId) { - return new DomainQueryImpl(scopeId); - } - @Override public Domain newEntity(KapuaId scopeId) { return new DomainImpl(scopeId); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImpl.java deleted file mode 100644 index 4c0b3e8d134..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.domain.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; - -/** - * {@link DomainQuery} implementation. - * - * @since 1.0.0 - */ -public class DomainQueryImpl extends AbstractKapuaNamedQuery implements DomainQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public DomainQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.5.0 - */ - public DomainQueryImpl(KapuaId scopeId) { - super(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainRegistryServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainRegistryServiceImpl.java index cb72c92222f..1ebe8a8be41 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainRegistryServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainRegistryServiceImpl.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.domain.shiro; +import java.util.Optional; + +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; import org.eclipse.kapua.commons.util.ArgumentValidator; @@ -24,7 +28,6 @@ import org.eclipse.kapua.service.authorization.domain.DomainCreator; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.eclipse.kapua.service.authorization.domain.DomainRegistryService; import org.eclipse.kapua.service.authorization.domain.DomainRepository; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; @@ -32,9 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Singleton; -import java.util.Optional; - /** * {@link DomainRegistryService} implementation. * @@ -152,7 +152,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { } private void deleteDomainByAccountId(KapuaId accountId) throws KapuaException { - DomainQuery query = domainFactory.newQuery(accountId); + KapuaQuery query = new KapuaQuery(accountId); DomainListResult domainsToDelete = query(query); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainsAligner.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainsAligner.java index 9b4bf945953..01c20935ee0 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainsAligner.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainsAligner.java @@ -12,11 +12,22 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.domain.shiro; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.inject.Named; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.initializers.KapuaInitializingMethod; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.domain.Domain; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionRepository; import org.eclipse.kapua.service.authorization.domain.DomainRepository; import org.eclipse.kapua.service.authorization.role.RolePermissionRepository; @@ -25,16 +36,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Named; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - public class DomainsAligner { + private final TxManager txManager; private final DomainRepository domainRepository; private final AccessPermissionRepository accessPermissionRepository; @@ -44,10 +47,10 @@ public class DomainsAligner { @Inject public DomainsAligner(@Named("authorizationTxManager") - TxManager txManager, - DomainRepository domainRepository, - AccessPermissionRepository accessPermissionRepository, RolePermissionRepository rolePermissionRepository, - Set knownDomains) { + TxManager txManager, + DomainRepository domainRepository, + AccessPermissionRepository accessPermissionRepository, RolePermissionRepository rolePermissionRepository, + Set knownDomains) { this.txManager = txManager; this.domainRepository = domainRepository; this.accessPermissionRepository = accessPermissionRepository; @@ -65,7 +68,7 @@ public void populate() { try { KapuaSecurityUtils.doPrivileged(() -> { txManager.execute(tx -> { - final List dbDomainEntries = domainRepository.query(tx, new DomainQueryImpl()).getItems(); + final List dbDomainEntries = domainRepository.query(tx, new KapuaQuery()).getItems(); logger.info("Found {} domain declarations in database", dbDomainEntries.size()); for (final org.eclipse.kapua.service.authorization.domain.Domain dbDomainEntry : dbDomainEntries) { @@ -87,7 +90,7 @@ public void populate() { //Align them! alignDomains(tx, dbDomainEntry, wiredDomain); } -// createMissingDomains(tx, declaredDomainsNotInDb, knownDomainsByName); + // createMissingDomains(tx, declaredDomainsNotInDb, knownDomainsByName); logger.info("Domain alignment complete!"); return null; }); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImpl.java index a13a4287fbc..63e7d3ca80b 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.group.Group; import org.eclipse.kapua.service.authorization.group.GroupCreator; import org.eclipse.kapua.service.authorization.group.GroupFactory; -import org.eclipse.kapua.service.authorization.group.GroupQuery; /** * {@link GroupFactory} implementation. @@ -43,11 +42,6 @@ public Group newEntity(KapuaId scopeId) { return new GroupImpl(scopeId); } - @Override - public GroupQuery newQuery(KapuaId scopeId) { - return new GroupQueryImpl(scopeId); - } - @Override public GroupCreator newCreator(KapuaId scopeId) { return new GroupCreatorImpl(scopeId); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupMatchPredicateImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupMatchPredicateImpl.java deleted file mode 100644 index d99618d07a1..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupMatchPredicateImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.group.shiro; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.authorization.group.GroupAttributes; -import org.eclipse.kapua.service.authorization.group.GroupMatchPredicate; - -import java.util.Arrays; - -public class GroupMatchPredicateImpl extends AbstractMatchPredicate implements GroupMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 2.1.0 - */ - public GroupMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - GroupAttributes.DESCRIPTION, - GroupAttributes.NAME - ); - this.matchTerm = matchTerm; - } - -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImpl.java deleted file mode 100644 index 809a08a6564..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.group.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.group.GroupMatchPredicate; -import org.eclipse.kapua.service.authorization.group.GroupQuery; - -/** - * {@link GroupQuery} implementation. - * - * @since 1.0.0 - */ -public class GroupQueryImpl extends AbstractKapuaNamedQuery implements GroupQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public GroupQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public GroupMatchPredicate matchPredicate(T matchTerm) { - return new GroupMatchPredicateImpl<>(matchTerm); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupServiceImpl.java index 4b64a1ae5c6..88538bf8f95 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/group/shiro/GroupServiceImpl.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.group.shiro; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; @@ -35,9 +38,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; - /** * {@link GroupService} implementation. * @@ -55,18 +55,21 @@ public class GroupServiceImpl extends KapuaConfigurableServiceBase implements Gr /** * Injectable constructor * - * @param permissionFactory The {@link PermissionFactory} instance. - * @param authorizationService The {@link AuthorizationService} instance. - * @param serviceConfigurationManager The {@link ServiceConfigurationManager} instance. + * @param permissionFactory + * The {@link PermissionFactory} instance. + * @param authorizationService + * The {@link AuthorizationService} instance. + * @param serviceConfigurationManager + * The {@link ServiceConfigurationManager} instance. * @param txManager * @param groupRepository * @since 2.0.0 */ @Inject public GroupServiceImpl(PermissionFactory permissionFactory, - AuthorizationService authorizationService, - ServiceConfigurationManager serviceConfigurationManager, - TxManager txManager, GroupRepository groupRepository) { + AuthorizationService authorizationService, + ServiceConfigurationManager serviceConfigurationManager, + TxManager txManager, GroupRepository groupRepository) { super(txManager, serviceConfigurationManager, Domains.GROUP, authorizationService, permissionFactory); this.permissionFactory = permissionFactory; this.authorizationService = authorizationService; @@ -176,7 +179,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { } private void deleteGroupByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - GroupQuery query = new GroupQueryImpl(accountId); + GroupQuery query = new GroupQuery(accountId); GroupListResult groupsToDelete = query(query); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/permission/shiro/PermissionValidator.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/permission/shiro/PermissionValidator.java index 8bf3d742c02..1999f264982 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/permission/shiro/PermissionValidator.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/permission/shiro/PermissionValidator.java @@ -12,9 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.permission.shiro; -import com.google.common.collect.Sets; +import java.util.Set; + +import javax.inject.Inject; +import javax.validation.constraints.NotNull; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.KapuaIllegalArgumentException; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; @@ -22,9 +28,7 @@ import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionAttributes; -import javax.inject.Inject; -import javax.validation.constraints.NotNull; -import java.util.Set; +import com.google.common.collect.Sets; public class PermissionValidator { @@ -43,7 +47,7 @@ public void validatePermission(@NotNull Permission permission) throws KapuaExcep public void validatePermissions(@NotNull Set permissions) throws KapuaException { if (!permissions.isEmpty()) { - DomainListResult domains = domainService.query(domainFactory.newQuery(null)); + DomainListResult domains = domainService.query(new KapuaQuery((KapuaId) null)); for (Permission p : permissions) { if (p.getDomain() != null) { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImpl.java index 145649c3377..0b0715573d5 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImpl.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.service.authorization.role.RoleCreator; import org.eclipse.kapua.service.authorization.role.RoleFactory; import org.eclipse.kapua.service.authorization.role.RolePermission; -import org.eclipse.kapua.service.authorization.role.RoleQuery; /** * {@link RoleFactory} implementation. @@ -40,11 +39,6 @@ public RoleCreator newCreator(KapuaId scopeId) { return new RoleCreatorImpl(scopeId); } - @Override - public RoleQuery newQuery(KapuaId scopeId) { - return new RoleQueryImpl(scopeId); - } - @Override public RolePermission newRolePermission() { return new RolePermissionImpl(); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleMatchPredicateImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleMatchPredicateImpl.java deleted file mode 100644 index a9d67a14ce7..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleMatchPredicateImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role.shiro; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.authorization.role.RoleAttributes; -import org.eclipse.kapua.service.authorization.role.RoleMatchPredicate; -import java.util.Arrays; - -public class RoleMatchPredicateImpl extends AbstractMatchPredicate implements RoleMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 2.1.0 - */ - public RoleMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - RoleAttributes.DESCRIPTION, - RoleAttributes.NAME - ); - this.matchTerm = matchTerm; - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionFactoryImpl.java index f2719eb11f0..28c63e38a7c 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionFactoryImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionFactoryImpl.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.authorization.role.RolePermission; import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; /** * {@link RolePermissionFactory} implementation. @@ -38,11 +37,6 @@ public RolePermissionCreator newCreator(KapuaId scopeId) { return new RolePermissionCreatorImpl(scopeId); } - @Override - public RolePermissionQuery newQuery(KapuaId scopeId) { - return new RolePermissionQueryImpl(scopeId); - } - @Override public RolePermission clone(RolePermission rolePermission) { return new RolePermissionImpl(rolePermission); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImpl.java deleted file mode 100644 index babba275acf..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; - -/** - * {@link RolePermissionQuery} implementation. - * - * @since 1.0.0 - */ -public class RolePermissionQueryImpl extends AbstractKapuaQuery implements RolePermissionQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public RolePermissionQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public RolePermissionQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionServiceImpl.java index d1a5e863dcd..b06a0add4ec 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionServiceImpl.java @@ -12,6 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.role.shiro; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaEntityUniquenessException; import org.eclipse.kapua.KapuaErrorCodes; @@ -31,18 +38,11 @@ import org.eclipse.kapua.service.authorization.role.RolePermissionAttributes; import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionRepository; import org.eclipse.kapua.service.authorization.role.RolePermissionService; import org.eclipse.kapua.service.authorization.role.RoleRepository; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Singleton; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * {@link RolePermission} service implementation. * @@ -92,7 +92,7 @@ public RolePermission create(RolePermissionCreator rolePermissionCreator) authorizationService.checkPermission(permission); } // Check duplicates - RolePermissionQuery query = new RolePermissionQueryImpl(rolePermissionCreator.getScopeId()); + KapuaQuery query = new KapuaQuery(rolePermissionCreator.getScopeId()); query.setPredicate( query.andPredicate( query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, rolePermissionCreator.getScopeId()), diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImpl.java deleted file mode 100644 index 45a19a65914..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role.shiro; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.role.RoleMatchPredicate; -import org.eclipse.kapua.service.authorization.role.RoleQuery; - -/** - * {@link RoleQuery} implementation. - * - * @since 1.0.0 - */ -public class RoleQueryImpl extends AbstractKapuaNamedQuery implements RoleQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - public RoleQueryImpl() { - super(); - } - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public RoleQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public RoleMatchPredicate matchPredicate(T matchTerm) { - return new RoleMatchPredicateImpl<>(matchTerm); - } - -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleServiceImpl.java index 3fac5c50337..51b1db3e6fd 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/role/shiro/RoleServiceImpl.java @@ -12,6 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.service.authorization.role.shiro; +import java.util.List; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaDuplicateNameException; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaErrorCodes; @@ -29,13 +35,11 @@ import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; @@ -54,11 +58,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.List; -import java.util.stream.Collectors; - /** * {@link RoleService} implementation. * @@ -80,14 +79,17 @@ public class RoleServiceImpl extends KapuaConfigurableServiceBase implements Rol public AccessInfoService accessInfoService; - /** * Injectable constructor * - * @param permissionFactory The {@link PermissionFactory} instance. - * @param authorizationService The {@link AuthorizationService} instance. - * @param rolePermissionFactory The {@link RolePermissionFactory} instance. - * @param serviceConfigurationManager The {@link ServiceConfigurationManager} instance. + * @param permissionFactory + * The {@link PermissionFactory} instance. + * @param authorizationService + * The {@link AuthorizationService} instance. + * @param rolePermissionFactory + * The {@link RolePermissionFactory} instance. + * @param serviceConfigurationManager + * The {@link ServiceConfigurationManager} instance. * @param txManager * @param roleRepository * @param rolePermissionRepository @@ -259,7 +261,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { private void deleteRoleByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - RoleQuery query = new RoleQueryImpl(accountId); + RoleQuery query = new RoleQuery(accountId); RoleListResult rolesToDelete = query(query); @@ -269,12 +271,13 @@ private void deleteRoleByAccountId(KapuaId scopeId, KapuaId accountId) throws Ka } public List userIdsByRoleId(KapuaId scopeId, KapuaId roleId) throws KapuaException { - AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(scopeId); + KapuaQuery accessRoleQuery = new KapuaQuery(scopeId); accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ROLE_ID, roleId)); AccessRoleListResult accessRoleListResult = accessRoleService.query(accessRoleQuery); - AccessInfoQuery accessInfoQuery = accessInfoFactory.newQuery(scopeId); - accessInfoQuery.setPredicate(accessInfoQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, accessRoleListResult.getItems().stream().map(AccessRole::getAccessInfoId).collect(Collectors.toList()))); + KapuaQuery accessInfoQuery = new KapuaQuery(scopeId); + accessInfoQuery.setPredicate( + accessInfoQuery.attributePredicate(KapuaEntityAttributes.ENTITY_ID, accessRoleListResult.getItems().stream().map(AccessRole::getAccessInfoId).collect(Collectors.toList()))); AccessInfoListResult accessInfoListResult = accessInfoService.query(accessInfoQuery); return accessInfoListResult.getItems().stream().map(AccessInfo::getUserId).collect(Collectors.toList()); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/KapuaAuthorizingRealm.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/KapuaAuthorizingRealm.java index fb0ceb47430..206a3c71e3c 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/KapuaAuthorizingRealm.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/KapuaAuthorizingRealm.java @@ -27,10 +27,10 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaListResult; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoAttributes; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; @@ -97,7 +97,7 @@ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal throw new AuthenticationException(); } // Get user access infos - AccessInfoQuery accessInfoQuery = accessInfoFactory.newQuery(user.getScopeId()); + KapuaQuery accessInfoQuery = new KapuaQuery(user.getScopeId()); accessInfoQuery.setPredicate(accessInfoQuery.attributePredicate(AccessInfoAttributes.USER_ID, user.getId())); final KapuaListResult accessInfos; diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImplTest.java index 7b5119fc23e..87767faaf19 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionFactoryImplTest.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionCreator; -import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -66,14 +65,6 @@ public void newEntityTest() { } } - @Test - public void newQueryTest() { - for (KapuaId scopeId : scopeIds) { - MfaOptionQuery mfaOptionQuery = mfaOptionFactoryImpl.newQuery(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, mfaOptionQuery.getScopeId()); - } - } - @Test public void newCreatorScopeIdParameterTest() { for (KapuaId scopeId : scopeIds) { diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImplTest.java deleted file mode 100644 index 51f23ca3f59..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/mfa/shiro/MfaOptionQueryImplTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential.mfa.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class MfaOptionQueryImplTest { - - @Test - public void mfaOptionQueryImplTest() { - MfaOptionQueryImpl mfaOptionQueryImpl = new MfaOptionQueryImpl(); - Assert.assertNull("Null expected.", mfaOptionQueryImpl.getScopeId()); - Assert.assertNull("mfaOptionQueryImpl.sortCriteria", mfaOptionQueryImpl.getSortCriteria()); - Assert.assertNotNull("mfaOptionQueryImpl.defaultSortCriteria", mfaOptionQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void mfaOptionQueryImplScopeIdParameterTest() { - KapuaId[] scopeIds = {null, KapuaId.ONE}; - - for (KapuaId scopeId : scopeIds) { - MfaOptionQueryImpl mfaOptionQueryImpl = new MfaOptionQueryImpl(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, mfaOptionQueryImpl.getScopeId()); - Assert.assertNull("mfaOptionQueryImpl.sortCriteria", mfaOptionQueryImpl.getSortCriteria()); - Assert.assertNotNull("mfaOptionQueryImpl.defaultSortCriteria", mfaOptionQueryImpl.getDefaultSortCriteria()); - } - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImplTest.java index e123066baee..b34595873e2 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialFactoryImplTest.java @@ -17,10 +17,10 @@ import org.eclipse.kapua.KapuaEntityCloneException; import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; import org.junit.Assert; import org.junit.Before; @@ -113,7 +113,7 @@ public void newMfaOptionTest() { @Test public void newQueryTest() { for (KapuaId scopeId : scopeIds) { - CredentialQuery credentialQuery = credentialFactoryImpl.newQuery(scopeId); + final KapuaQuery credentialQuery = new KapuaQuery(scopeId); Assert.assertEquals("Expected and actual values should be the same.", scopeId, credentialQuery.getScopeId()); } } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImplTest.java deleted file mode 100644 index 7192854baa1..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/credential/shiro/CredentialQueryImplTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.credential.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class CredentialQueryImplTest { - - @Test - public void credentialQueryImplWithoutParameterTest() { - CredentialQueryImpl credentialQueryImpl = new CredentialQueryImpl(); - Assert.assertNull("Null expected.", credentialQueryImpl.getScopeId()); - Assert.assertNull("credentialQueryImpl.sortCriteria", credentialQueryImpl.getSortCriteria()); - Assert.assertNotNull("credentialQueryImpl.defaultSortCriteria", credentialQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void credentialQueryImplScopeIdTest() { - KapuaId[] scopeIds = {null, KapuaId.ONE}; - for (KapuaId scopeId : scopeIds) { - CredentialQueryImpl credentialQueryImpl = new CredentialQueryImpl(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, credentialQueryImpl.getScopeId()); - Assert.assertNull("credentialQueryImpl.sortCriteria", credentialQueryImpl.getSortCriteria()); - Assert.assertNotNull("credentialQueryImpl.defaultSortCriteria", credentialQueryImpl.getDefaultSortCriteria()); - } - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImplTest.java index b3d5eb1b2fc..1c95d23db85 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenFactoryImplTest.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.token.AccessToken; import org.eclipse.kapua.service.authentication.token.AccessTokenCreator; -import org.eclipse.kapua.service.authentication.token.AccessTokenQuery; import org.eclipse.kapua.service.authentication.token.LoginInfo; import org.junit.Assert; import org.junit.Before; @@ -98,14 +97,6 @@ public void newCreatorScopeIdParameterTest() { } } - @Test - public void newQueryTest() { - for (KapuaId scopeId : scopeIds) { - AccessTokenQuery accessTokenQuery = accessTokenFactoryImpl.newQuery(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, accessTokenQuery.getScopeId()); - } - } - @Test public void cloneTest() { Mockito.when(accessToken.getId()).thenReturn(KapuaId.ONE); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImplTest.java deleted file mode 100644 index 1bb5a584d51..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/token/shiro/AccessTokenQueryImplTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.token.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - - -@Category(JUnitTests.class) -public class AccessTokenQueryImplTest { - - @Test - public void accessTokenQueryImplTest() throws Exception { - Constructor accessTokenQueryImpl = AccessTokenQueryImpl.class.getDeclaredConstructor(); - accessTokenQueryImpl.setAccessible(true); - accessTokenQueryImpl.newInstance(); - Assert.assertTrue("True expected.", Modifier.isPrivate(accessTokenQueryImpl.getModifiers())); - } - - @Test - public void accessTokenQueryImplTestScopeIdParameterTest() { - AccessTokenQueryImpl accessTokenQueryImpl = new AccessTokenQueryImpl(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, accessTokenQueryImpl.getScopeId()); - } - - @Test - public void accessTokenQueryImplTestNullScopeIdParameterTest() { - AccessTokenQueryImpl accessTokenQueryImpl = new AccessTokenQueryImpl(null); - Assert.assertNull("Null expected.", accessTokenQueryImpl.getScopeId()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImplTest.java index de5fdf1f83b..6310df8bbba 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoFactoryImplTest.java @@ -16,10 +16,10 @@ import org.eclipse.kapua.KapuaEntityCloneException; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -82,14 +82,14 @@ public void newCreatorNullTest() { @Test public void newQueryTest() { - AccessInfoQuery accessInfoQuery = accessInfoFactoryImpl.newQuery(scopeId); + KapuaQuery accessInfoQuery = new KapuaQuery(scopeId); Assert.assertEquals("Expected and actual values should be the same.", scopeId, accessInfoQuery.getScopeId()); } @Test public void newQueryNullTest() { - AccessInfoQuery accessInfoQuery = accessInfoFactoryImpl.newQuery(null); + KapuaQuery accessInfoQuery = new KapuaQuery((KapuaId) null); Assert.assertNull("Null expected.", accessInfoQuery.getScopeId()); } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImplTest.java deleted file mode 100644 index 30be73ea269..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessInfoQueryImplTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class AccessInfoQueryImplTest { - - @Test - public void accessInfoQueryImplWithoutParameterTest() { - AccessInfoQueryImpl accessInfoQueryImpl = new AccessInfoQueryImpl(); - - Assert.assertNull("Null expected.", accessInfoQueryImpl.getScopeId()); - } - - @Test - public void accessInfoQueryImplScopeIdParameterTest() { - AccessInfoQueryImpl accessInfoQueryImpl = new AccessInfoQueryImpl(KapuaId.ONE); - - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, accessInfoQueryImpl.getScopeId()); - } - - @Test - public void accessInfoQueryImplNullScopeIdParameterTest() { - AccessInfoQueryImpl accessInfoQueryImpl = new AccessInfoQueryImpl(null); - - Assert.assertNull("Null expected.", accessInfoQueryImpl.getScopeId()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImplTest.java index c4ea95a3eb2..cca38d81e72 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionFactoryImplTest.java @@ -16,7 +16,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -49,13 +48,6 @@ public void newCreatorTest() { } } - @Test - public void newQueryTest() { - for (KapuaId scopeId : scopeIds) { - Assert.assertTrue("True expected.", accessPermissionFactoryImpl.newQuery(scopeId) instanceof AccessPermissionQuery); - } - } - @Test public void cloneTest() { AccessPermission accessPermission = Mockito.mock(AccessPermission.class); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImplTest.java deleted file mode 100644 index ee1fb61f155..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessPermissionQueryImplTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class AccessPermissionQueryImplTest { - - @Test - public void accessPermissionQueryImplWithoutParametersTest() { - AccessPermissionQueryImpl accessPermissionQueryImpl = new AccessPermissionQueryImpl(); - Assert.assertNull("Null expected.", accessPermissionQueryImpl.getScopeId()); - Assert.assertNull("accessPermissionQueryImpl.sortCriteria", accessPermissionQueryImpl.getSortCriteria()); - Assert.assertNotNull("accessPermissionQueryImpl.defaultSortCriteria", accessPermissionQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void accessPermissionQueryImplScopeIdParameterTest() { - AccessPermissionQueryImpl accessPermissionQueryImpl = new AccessPermissionQueryImpl(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, accessPermissionQueryImpl.getScopeId()); - Assert.assertNull("accessPermissionQueryImpl.sortCriteria", accessPermissionQueryImpl.getSortCriteria()); - Assert.assertNotNull("accessPermissionQueryImpl.defaultSortCriteria", accessPermissionQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void accessPermissionQueryImplNullScopeIdParameterTest() { - AccessPermissionQueryImpl accessPermissionQueryImpl = new AccessPermissionQueryImpl(null); - Assert.assertNull("Null expected.", accessPermissionQueryImpl.getScopeId()); - Assert.assertNull("accessPermissionQueryImpl.sortCriteria", accessPermissionQueryImpl.getSortCriteria()); - Assert.assertNotNull("accessPermissionQueryImpl.defaultSortCriteria", accessPermissionQueryImpl.getDefaultSortCriteria()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImplTest.java index 187251c0ad8..07aa0e22aef 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleFactoryImplTest.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -71,18 +70,6 @@ public void newCreatorNullTest() { Assert.assertNull("Null expected.", accessRoleCreator.getScopeId()); } - @Test - public void newQueryTest() { - AccessRoleQuery accessRoleQuery = accessRoleFactoryImpl.newQuery(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, accessRoleQuery.getScopeId()); - } - - @Test - public void newQueryNullTest() { - AccessRoleQuery accessRoleQuery = accessRoleFactoryImpl.newQuery(null); - Assert.assertNull("Null expected.", accessRoleQuery.getScopeId()); - } - @Test public void cloneTest() { accessRoleFactoryImpl.clone(accessRole); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImplTest.java deleted file mode 100644 index 4f6601d333e..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/AccessRoleQueryImplTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.access.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class AccessRoleQueryImplTest { - - @Test - public void accessRoleQueryImplWithoutParametersTest() { - AccessRoleQueryImpl accessRoleQueryImpl = new AccessRoleQueryImpl(); - Assert.assertNull("Null expected.", accessRoleQueryImpl.getScopeId()); - Assert.assertNull("accessRoleQueryImpl.sortCriteria", accessRoleQueryImpl.getSortCriteria()); - Assert.assertNotNull("accessRoleQueryImpl.defaultSortCriteria", accessRoleQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void accessRoleQueryImplScopeIdParameterTest() { - AccessRoleQueryImpl accessRoleQueryImpl = new AccessRoleQueryImpl(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, accessRoleQueryImpl.getScopeId()); - Assert.assertNull("accessRoleQueryImpl.sortCriteria", accessRoleQueryImpl.getSortCriteria()); - Assert.assertNotNull("accessRoleQueryImpl.defaultSortCriteria", accessRoleQueryImpl.getDefaultSortCriteria()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImplTest.java index 83d88868642..6dffdc20b93 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainFactoryImplTest.java @@ -22,7 +22,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainCreator; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -58,22 +57,6 @@ public void newCreatorNullNameParameterTest() { Assert.assertNull("Null expected.", domainCreator.getScopeId()); } - @Test - public void newQueryTest() { - DomainQuery domainQuery = domainFactoryImpl.newQuery(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, domainQuery.getScopeId()); - Assert.assertNull("domainQuery.sortCriteria", domainQuery.getSortCriteria()); - Assert.assertNotNull("domainQuery.defaultSortCriteria", domainQuery.getDefaultSortCriteria()); - } - - @Test - public void newQueryNullTest() { - DomainQuery domainQuery = domainFactoryImpl.newQuery(null); - Assert.assertNull("Null expected.", domainQuery.getScopeId()); - Assert.assertNull("domainQuery.sortCriteria", domainQuery.getSortCriteria()); - Assert.assertNotNull("domainQuery.defaultSortCriteria", domainQuery.getDefaultSortCriteria()); - } - @Test public void newEntityTest() { Domain domain = domainFactoryImpl.newEntity(KapuaId.ONE); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImplTest.java deleted file mode 100644 index e3be25cd1e3..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/domain/shiro/DomainQueryImplTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.domain.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class DomainQueryImplTest { - - @Test - public void domainQueryImplWithoutParametersTest() { - DomainQueryImpl domainQueryImpl = new DomainQueryImpl(); - Assert.assertNull("Null expected.", domainQueryImpl.getScopeId()); - } - - @Test - public void domainQueryImplScopeIdParameterTest() { - DomainQueryImpl domainQueryImpl = new DomainQueryImpl(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, domainQueryImpl.getScopeId()); - } - - @Test - public void domainQueryImplNullScopeIdParameterTest() { - DomainQueryImpl domainQueryImpl = new DomainQueryImpl(null); - Assert.assertNull("Null expected.", domainQueryImpl.getScopeId()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImplTest.java index 2615beda67f..1749b5c0181 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupFactoryImplTest.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authorization.group.Group; import org.eclipse.kapua.service.authorization.group.GroupCreator; -import org.eclipse.kapua.service.authorization.group.GroupQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -93,18 +92,6 @@ public void newEntityNullTest() { Assert.assertNull("Null expected.", group.getScopeId()); } - @Test - public void newQueryTest() { - GroupQuery groupQuery = groupFactoryImpl.newQuery(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, groupQuery.getScopeId()); - } - - @Test - public void newQueryNullTest() { - GroupQuery groupQuery = groupFactoryImpl.newQuery(null); - Assert.assertNull("Null expected.", groupQuery.getScopeId()); - } - @Test public void newCreatorTest() { GroupCreator groupCreator = groupFactoryImpl.newCreator(scopeId); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImplTest.java deleted file mode 100644 index 0d60b149cbe..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/group/shiro/GroupQueryImplTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.group.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class GroupQueryImplTest { - - @Test - public void groupQueryImplTest() { - GroupQueryImpl groupQueryImpl = new GroupQueryImpl(KapuaId.ONE); - Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, groupQueryImpl.getScopeId()); - Assert.assertNull("groupQueryImpl.sortCriteria", groupQueryImpl.getSortCriteria()); - Assert.assertNotNull("groupQueryImpl.defaultSortCriteria", groupQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void groupQueryImplNullTest() { - GroupQueryImpl groupQueryImpl = new GroupQueryImpl(null); - Assert.assertNull("Null expected.", groupQueryImpl.getScopeId()); - Assert.assertNull("groupQueryImpl.sortCriteria", groupQueryImpl.getSortCriteria()); - Assert.assertNotNull("groupQueryImpl.defaultSortCriteria", groupQueryImpl.getDefaultSortCriteria()); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImplTest.java index b4fe45669e9..38f079e9a71 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleFactoryImplTest.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.authorization.role.Role; import org.eclipse.kapua.service.authorization.role.RoleCreator; import org.eclipse.kapua.service.authorization.role.RolePermission; -import org.eclipse.kapua.service.authorization.role.RoleQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -77,18 +76,6 @@ public void newCreatorNullTest() { Assert.assertNull("Null expected.", roleFactoryImpl.newCreator(null).getScopeId()); } - @Test - public void newQueryTest() { - Assert.assertTrue("True expected.", roleFactoryImpl.newQuery(scopeId) instanceof RoleQuery); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, roleFactoryImpl.newQuery(scopeId).getScopeId()); - } - - @Test - public void newQueryNullTest() { - Assert.assertTrue("True expected.", roleFactoryImpl.newQuery(null) instanceof RoleQuery); - Assert.assertNull("Null expected.", roleFactoryImpl.newQuery(null).getScopeId()); - } - @Test public void newRolePermissionTest() { Assert.assertTrue("True expected.", roleFactoryImpl.newRolePermission() instanceof RolePermission); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImplTest.java deleted file mode 100644 index 42cd8f69d16..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RolePermissionQueryImplTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class RolePermissionQueryImplTest { - - @Test - public void rolePermissionQueryImplWithoutParametersTest() { - RolePermissionQueryImpl rolePermissionQueryImpl = new RolePermissionQueryImpl(); - Assert.assertNull("Null expected.", rolePermissionQueryImpl.getScopeId()); - Assert.assertNull("rolePermissionQueryImpl.sortCriteria", rolePermissionQueryImpl.getSortCriteria()); - Assert.assertNotNull("rolePermissionQueryImpl.defaultSortCriteria", rolePermissionQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void rolePermissionQueryImpScopeIdTest() { - KapuaId[] scopeIds = {null, KapuaId.ANY}; - - for (KapuaId scopeId : scopeIds) { - RolePermissionQueryImpl rolePermissionQueryImpl = new RolePermissionQueryImpl(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, rolePermissionQueryImpl.getScopeId()); - Assert.assertNull("rolePermissionQueryImpl.sortCriteria", rolePermissionQueryImpl.getSortCriteria()); - Assert.assertNotNull("rolePermissionQueryImpl.defaultSortCriteria", rolePermissionQueryImpl.getDefaultSortCriteria()); - } - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImplTest.java deleted file mode 100644 index 929af6c9a56..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/role/shiro/RoleQueryImplTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authorization.role.shiro; - -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class RoleQueryImplTest { - - @Test - public void rolePermissionQueryImplWithoutParametersTest() { - RoleQueryImpl roleQueryImpl = new RoleQueryImpl(); - Assert.assertNull("Null expected.", roleQueryImpl.getScopeId()); - Assert.assertNull("roleQueryImpl.sortCriteria", roleQueryImpl.getSortCriteria()); - Assert.assertNotNull("roleQueryImpl.defaultSortCriteria", roleQueryImpl.getDefaultSortCriteria()); - } - - @Test - public void rolePermissionQueryImpScopeIdTest() { - KapuaId[] scopeIds = {null, KapuaId.ANY}; - - for (KapuaId scopeId : scopeIds) { - RoleQueryImpl roleQueryImpl = new RoleQueryImpl(scopeId); - Assert.assertEquals("Expected and actual values should be the same.", scopeId, roleQueryImpl.getScopeId()); - Assert.assertNull("roleQueryImpl.sortCriteria", roleQueryImpl.getSortCriteria()); - Assert.assertNotNull("roleQueryImpl.defaultSortCriteria", roleQueryImpl.getDefaultSortCriteria()); - } - } -} \ No newline at end of file diff --git a/service/security/test-steps/src/main/java/org/eclipse/kapua/service/authorization/steps/AuthorizationServiceSteps.java b/service/security/test-steps/src/main/java/org/eclipse/kapua/service/authorization/steps/AuthorizationServiceSteps.java index 9092ef37565..20e4e347ecb 100644 --- a/service/security/test-steps/src/main/java/org/eclipse/kapua/service/authorization/steps/AuthorizationServiceSteps.java +++ b/service/security/test-steps/src/main/java/org/eclipse/kapua/service/authorization/steps/AuthorizationServiceSteps.java @@ -27,6 +27,7 @@ import org.eclipse.kapua.model.KapuaNamedEntityAttributes; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.common.StepData; import org.eclipse.kapua.qa.common.TestBase; @@ -43,7 +44,6 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; -import org.eclipse.kapua.service.authorization.access.AccessInfoQuery; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; @@ -55,19 +55,16 @@ import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; -import org.eclipse.kapua.service.authorization.access.AccessRoleQuery; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.domain.Domain; import org.eclipse.kapua.service.authorization.domain.DomainCreator; import org.eclipse.kapua.service.authorization.domain.DomainFactory; import org.eclipse.kapua.service.authorization.domain.DomainListResult; -import org.eclipse.kapua.service.authorization.domain.DomainQuery; import org.eclipse.kapua.service.authorization.domain.DomainRegistryService; import org.eclipse.kapua.service.authorization.group.Group; import org.eclipse.kapua.service.authorization.group.GroupCreator; import org.eclipse.kapua.service.authorization.group.GroupFactory; import org.eclipse.kapua.service.authorization.group.GroupListResult; -import org.eclipse.kapua.service.authorization.group.GroupQuery; import org.eclipse.kapua.service.authorization.group.GroupService; import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; @@ -80,7 +77,6 @@ import org.eclipse.kapua.service.authorization.role.RolePermissionCreator; import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; -import org.eclipse.kapua.service.authorization.role.RolePermissionQuery; import org.eclipse.kapua.service.authorization.role.RolePermissionService; import org.eclipse.kapua.service.authorization.role.RoleQuery; import org.eclipse.kapua.service.authorization.role.RoleService; @@ -385,18 +381,18 @@ public void deleteLastCreatedRolePermission() throws Exception { @When("I count the roles in scope {int}") public void countRolesInScope(int scope) throws Exception { - updateCount(() -> (int) roleService.count(roleFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) roleService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I count the role permissions in scope {int}") public void countRolePermissionsInScope(Integer scope) throws Exception { - updateCount(() -> (int) rolePermissionService.count(rolePermissionFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) rolePermissionService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I query for the role {string} in scope {int}") public void queryForRoleInScope(String name, Integer scope) throws Exception { KapuaId tmpId = getKapuaId(scope); - RoleQuery tmpQuery = roleFactory.newQuery(tmpId); + KapuaQuery tmpQuery = new KapuaQuery(tmpId); tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL)); stepData.remove(ROLE_LIST); stepData.remove(ROLE_FOUND); @@ -526,7 +522,6 @@ public void checkRoleForUpdates() { public void performRoleFactorySanityChecks() { Assert.assertNotNull(roleFactory.newEntity(SYS_SCOPE_ID)); Assert.assertNotNull(roleFactory.newCreator(SYS_SCOPE_ID)); - Assert.assertNotNull(roleFactory.newQuery(SYS_SCOPE_ID)); Assert.assertNotNull(roleFactory.newRolePermission()); } @@ -534,7 +529,6 @@ public void performRoleFactorySanityChecks() { public void performRolePermissionFactorySanityChecks() { Assert.assertNotNull(rolePermissionFactory.newEntity(SYS_SCOPE_ID)); Assert.assertNotNull(rolePermissionFactory.newCreator(SYS_SCOPE_ID)); - Assert.assertNotNull(rolePermissionFactory.newQuery(SYS_SCOPE_ID)); } @Then("The role comparator does its job") @@ -628,7 +622,7 @@ public void createAListOfDomains(List domains) throws Exception { @Given("I select the domain {string}") public void selectExistingDomain(String name) throws Exception { - DomainQuery query = domainFactory.newQuery(KapuaId.ANY); + final KapuaQuery query = new KapuaQuery(KapuaId.ANY); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL)); try { primeException(); @@ -675,12 +669,12 @@ public void deleteRandomDomainId() throws Exception { @When("I count the domain entries in the database") public void countDomainEntries() throws Exception { - updateCount(() -> (int) domainRegistryService.count(domainFactory.newQuery(null))); + updateCount(() -> (int) domainRegistryService.count(new KapuaQuery((KapuaId) null))); } @When("I query for domains with the name {string}") public void queryForNamedDomain(String name) throws Exception { - DomainQuery query = domainFactory.newQuery(null); + final KapuaQuery query = new KapuaQuery((KapuaId) null); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL)); stepData.remove("DomainList"); try { @@ -822,7 +816,7 @@ public void setGroupConfigurationValue(List cucConfigs) throws Except @When("I count the group entries in the database") public void countGroupEntries() throws Exception { - updateCount(() -> (int) groupService.count(groupFactory.newQuery(SYS_SCOPE_ID))); + updateCount(() -> (int) groupService.count(new KapuaQuery(SYS_SCOPE_ID))); } @Given("I create the group(s)") @@ -878,7 +872,7 @@ public void updateGroupWithFalseId() throws Exception { public void deleteGroupWithName(String groupName) throws Exception { primeException(); try { - GroupQuery tmpQuery = groupFactory.newQuery(getCurrentScopeId()); + final KapuaQuery tmpQuery = new KapuaQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); Group group = groupService.query(tmpQuery).getFirstItem(); groupService.delete(group.getScopeId(), group.getId()); @@ -924,13 +918,13 @@ public void findGroupByRememberedId(String groupName) throws Exception { @When("I count all the groups in scope {int}") public void countGroupsInScope(int scope) throws Exception { - updateCount(() -> (int) groupService.count(groupFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) groupService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I query for the group {string} in scope {int}") public void queryForGroup(String name, int scope) throws Exception { KapuaId tmpId = getKapuaId(scope); - GroupQuery tmpQuery = groupFactory.newQuery(tmpId); + final KapuaQuery tmpQuery = new KapuaQuery(tmpId); tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL)); stepData.remove("GroupList"); stepData.remove(GROUP); @@ -1214,7 +1208,7 @@ public void findLastCreatedAccessRole() throws Exception { @When("I count the access roles in scope {int}") public void countAccesRolesInScope(Integer scope) throws Exception { - updateCount(() -> (int) accessRoleService.count(accessRoleFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) accessRoleService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I delete the last created access role entry") @@ -1243,14 +1237,14 @@ public void deleteLastCreatedAccessInfoEntity() throws Exception { @When("I count the access info entities for scope {int}") public void countAccessInfoEntitiesInScope(Integer scope) throws Exception { - updateCount(() -> (int) accessInfoService.count(accessInfoFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) accessInfoService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I query for the access info entities for the last user") public void queryForLastUserAccessInfoEntities() throws Exception { KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID); User user = (User) stepData.get("User"); - AccessInfoQuery tmpQuery = accessInfoFactory.newQuery(currScope); + final KapuaQuery tmpQuery = new KapuaQuery(currScope); tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessInfoAttributes.USER_ID, user.getId(), AttributePredicate.Operator.EQUAL)); try { primeException(); @@ -1315,7 +1309,7 @@ public void deleteLastCreatedPermission() throws Exception { @When("I count the permissions in scope {int}") public void countPermissionsForScope(Integer scope) throws Exception { - updateCount(() -> (int) accessPermissionService.count(accessPermissionFactory.newQuery(getKapuaId(scope)))); + updateCount(() -> (int) accessPermissionService.count(new KapuaQuery(getKapuaId(scope)))); } @When("I check the sanity of the access info factory") @@ -1324,7 +1318,6 @@ public void accessInfoServiceSanityCheck() throws Exception { primeException(); Assert.assertNotNull(accessInfoFactory.newCreator(getKapuaId())); Assert.assertNotNull(accessInfoFactory.newEntity(null)); - Assert.assertNotNull(accessInfoFactory.newQuery(getKapuaId())); AccessInfoCreator tmpCreator = accessInfoFactory.newCreator(getKapuaId()); Assert.assertNotNull(tmpCreator); AccessInfo tmpAccInfo = accessInfoFactory.newEntity(getKapuaId()); @@ -1341,7 +1334,6 @@ public void accessPermissionFactorySanityCheck() { Assert.assertNotNull(accessPermissionFactory.newCreator(getKapuaId())); Assert.assertNotNull(accessPermissionFactory.newEntity(null)); Assert.assertNotNull(accessPermissionFactory.newEntity(getKapuaId())); - Assert.assertNotNull(accessPermissionFactory.newQuery(getKapuaId())); KapuaId tmpId = getKapuaId(); AccessPermissionCreator tmpCreator = accessPermissionFactory.newCreator(tmpId); Assert.assertNotNull(tmpCreator); @@ -1367,7 +1359,6 @@ public void accessRoleFactorySanityCheck() throws Exception { primeException(); Assert.assertNotNull(accessRoleFactory.newCreator(getKapuaId())); Assert.assertNotNull(accessRoleFactory.newEntity(getKapuaId())); - Assert.assertNotNull(accessRoleFactory.newQuery(getKapuaId())); KapuaId tmpId = getKapuaId(); AccessRoleCreator tmpCreator = accessRoleFactory.newCreator(tmpId); Assert.assertNotNull(tmpCreator); @@ -1617,10 +1608,10 @@ public void checkPermissionComparison() { public void accessRoleWithNameIsFinded(String roleName) throws Exception { try { primeException(); - RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId()); + final KapuaQuery roleQuery = new KapuaQuery(getCurrentScopeId()); roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName)); RoleListResult roleList = roleService.query(roleQuery); - AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId()); + final KapuaQuery accessRoleQuery = new KapuaQuery(getCurrentScopeId()); accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ROLE_ID, roleList.getFirstItem().getId())); AccessRoleListResult searchAccessRole = accessRoleService.query(accessRoleQuery); Assert.assertTrue(searchAccessRole.getSize() > 0); @@ -1721,7 +1712,7 @@ public void iFindLastCreatedGroup(String groupName) throws Exception { public void iFindRoleWithName(String roleName) throws Exception { try { primeException(); - RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId()); + final RoleQuery roleQuery = new RoleQuery(getCurrentScopeId()); roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName, AttributePredicate.Operator.EQUAL)); stepData.remove(ROLE_LIST_RESULT); stepData.remove("Role"); @@ -1784,7 +1775,7 @@ public void iSearchForThePermissionsOfTheRole(String roleName) throws Exception Role role = (Role) stepData.get("Role"); ArrayList rolePermissionList = new ArrayList<>(); Assert.assertEquals(roleName, role.getName()); - RolePermissionQuery rolePermissionQuery = rolePermissionFactory.newQuery(getCurrentScopeId()); + final KapuaQuery rolePermissionQuery = new KapuaQuery(getCurrentScopeId()); rolePermissionQuery.setPredicate(rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, role.getId(), AttributePredicate.Operator.EQUAL)); RolePermissionListResult rolePermissions = rolePermissionService.query(rolePermissionQuery); stepData.remove(ROLE_PERMISSIONS); @@ -1832,7 +1823,7 @@ public void iDeleteTheLastCreatedAdminRolePermissions() throws Exception { public void iCountTheAccessRolesFromUser(String userName) throws Exception { User lastUser = (User) stepData.get("User"); AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO); - AccessRoleQuery tmpQuery = accessRoleFactory.newQuery(getCurrentScopeId()); + final KapuaQuery tmpQuery = new KapuaQuery(getCurrentScopeId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL)); Assert.assertEquals(userName, lastUser.getName()); updateCount(() -> (int) accessRoleService.count(tmpQuery)); @@ -1844,7 +1835,7 @@ public void iSearchGrantedUserToRole() throws Exception { int grantedUsersCount = 0; try { primeException(); - AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId()); + final KapuaQuery accessRoleQuery = new KapuaQuery(getCurrentScopeId()); AccessRoleListResult accessRoleList = accessRoleService.query(accessRoleQuery); for (AccessRole a : accessRoleList.getItems()) { AccessInfo accessInfo = accessInfoService.find(getCurrentScopeId(), a.getAccessInfoId()); @@ -1878,7 +1869,7 @@ public void iFindGrantedUsersWithName(List grantedUsers) throws Excepti public void iFindSpecificRoleInChildAccount(String roleName, String accountName) throws Exception { Account account = (Account) stepData.get(LAST_ACCOUNT); Assert.assertEquals(accountName, account.getName()); - RoleQuery roleQuery = roleFactory.newQuery(account.getId()); + final RoleQuery roleQuery = new RoleQuery(account.getId()); roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName, AttributePredicate.Operator.EQUAL)); RoleListResult childRolesList = roleService.query(roleQuery); stepData.put("ChildRolesList", childRolesList); @@ -1936,7 +1927,7 @@ public void iSearchForThePermissionsOfFoundedRoleInSubaccount(String roleName, S Account account = (Account) stepData.get(LAST_ACCOUNT); Assert.assertEquals(accountName, account.getName()); ArrayList rolePermissionList = new ArrayList<>(); - RolePermissionQuery rolePermissionQuery = rolePermissionFactory.newQuery(account.getId()); + final KapuaQuery rolePermissionQuery = new KapuaQuery(account.getId()); rolePermissionQuery.setPredicate(rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, role.getId(), AttributePredicate.Operator.EQUAL)); RolePermissionListResult rolePermissions = rolePermissionService.query(rolePermissionQuery); stepData.remove(CHILD_ACCOUNT_ROLE_PERMISSION); @@ -2019,7 +2010,7 @@ public void iSearchForAccessRolesFromTheLastUser(String userName) throws Excepti AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO); User user = (User) stepData.get("User"); Assert.assertEquals(userName, user.getName()); - AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId()); + final KapuaQuery accessRoleQuery = new KapuaQuery(getCurrentScopeId()); accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL)); try { primeException(); @@ -2050,7 +2041,7 @@ public void iCountTheAccessRolesFromUserInChildAccount(String accountName) throw Account account = (Account) stepData.get(LAST_ACCOUNT); AccessInfo accessInfo = (AccessInfo) stepData.get(CHILD_ACCOUNT_ACCESS_INFO); Assert.assertEquals(accountName, account.getName()); - AccessRoleQuery tmpQuery = accessRoleFactory.newQuery(account.getId()); + final KapuaQuery tmpQuery = new KapuaQuery(account.getId()); tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL)); updateCount(() -> (int) accessRoleService.count(tmpQuery)); } @@ -2142,7 +2133,7 @@ public void iCreateRoles(int num) throws Exception { @When("I count the roles in the database") public void iCountTheRolesInTheDatabase() throws Exception { - updateCount(() -> (int) (roleService.count(roleFactory.newQuery(getCurrentScopeId())) - 1)); + updateCount(() -> (int) (roleService.count(new RoleQuery(getCurrentScopeId())) - 1)); } @And("I update the role description to {string}") @@ -2177,7 +2168,7 @@ public void iDeleteTheRoleWithNameAndDescription(String roleName, String roleDes public void iFindARoleWithDescription(String roleDesc) throws Throwable { try { primeException(); - RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId()); + RoleQuery roleQuery = new RoleQuery(getCurrentScopeId()); roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.DESCRIPTION, roleDesc, AttributePredicate.Operator.EQUAL)); stepData.remove(ROLE_LIST_RESULT); stepData.remove(ROLE_FOUND); @@ -2246,7 +2237,7 @@ public void iUpdateTheRoleNameWithSpecialCharacters(String invalidSymbols) throw @And("I change the group name from {string} to {string}") public void iChangeTheGroupNameTo(String groupName, String newGroupName) throws Exception { try { - GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID); + final KapuaQuery query = new KapuaQuery(SYS_SCOPE_ID); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); GroupListResult queryResult = groupService.query(query); Group group = queryResult.getFirstItem(); @@ -2261,7 +2252,7 @@ public void iChangeTheGroupNameTo(String groupName, String newGroupName) throws @And("I change the description of group with name {string} to {string}") public void iChangeTheGroupDescriptionTo(String groupName, String groupDescription) throws Exception { try { - GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID); + final KapuaQuery query = new KapuaQuery(SYS_SCOPE_ID); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); GroupListResult queryResult = groupService.query(query); Group group = queryResult.getFirstItem(); @@ -2276,7 +2267,7 @@ public void iChangeTheGroupDescriptionTo(String groupName, String groupDescripti public void iSearchForAGroupNamed(String groupName) throws Exception { try { stepData.remove(GROUP_SECOND); - GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID); + final KapuaQuery query = new KapuaQuery(SYS_SCOPE_ID); query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL)); GroupListResult queryResult = groupService.query(query); Group foundGroup = queryResult.getFirstItem(); diff --git a/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java b/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java index 720f8c78b5e..bea6be1ae5c 100644 --- a/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java +++ b/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java @@ -32,25 +32,23 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.util.xml.XmlUtil; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; -import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialService; +import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.handler.shiro.ApiKeyCredentialTypeHandler; +import org.eclipse.kapua.service.authentication.credential.handler.shiro.JwtCredentialTypeHandler; +import org.eclipse.kapua.service.authentication.credential.handler.shiro.PasswordCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialFactoryImpl; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialImplJpaRepository; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialServiceImpl; -import org.eclipse.kapua.service.authentication.credential.handler.shiro.JwtCredentialTypeHandler; -import org.eclipse.kapua.service.authentication.credential.handler.shiro.PasswordCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordResetterImpl; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordValidator; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordValidatorImpl; @@ -135,7 +133,6 @@ protected void configure() { // skip } - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); bind(KapuaJpaRepositoryConfiguration.class).toInstance(new KapuaJpaRepositoryConfiguration()); bind(AuthorizationService.class).toInstance(mockedAuthorization); @@ -202,16 +199,16 @@ protected void configure() { new PasswordValidatorImpl(credentialServiceConfigurationManager)), new HashSet() {{ add( - new PasswordCredentialTypeHandler( - new KapuaJpaTxManagerFactory(maxInsertAttempts).create("kapua-authorization"), - credentialRepository, - authenticationUtils, - passwordValidator) + new PasswordCredentialTypeHandler( + new KapuaJpaTxManagerFactory(maxInsertAttempts).create("kapua-authorization"), + credentialRepository, + authenticationUtils, + passwordValidator) ); add( - new ApiKeyCredentialTypeHandler( - new KapuaAuthenticationSetting(), - authenticationUtils) + new ApiKeyCredentialTypeHandler( + new KapuaAuthenticationSetting(), + authenticationUtils) ); add(new JwtCredentialTypeHandler(authenticationUtils)); }} diff --git a/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java b/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java index 6d472a6a28c..68dad7fe576 100644 --- a/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java +++ b/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java @@ -12,13 +12,6 @@ *******************************************************************************/ package org.eclipse.kapua.service.systeminfo.test; -import com.codahale.metrics.MetricRegistry; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Singleton; -import com.google.inject.name.Names; -import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.metatype.KapuaMetatypeFactoryImpl; import org.eclipse.kapua.commons.crypto.CryptoUtil; @@ -27,12 +20,10 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; @@ -51,13 +42,20 @@ import org.mockito.Matchers; import org.mockito.Mockito; +import com.codahale.metrics.MetricRegistry; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Singleton; +import com.google.inject.name.Names; + +import io.cucumber.java.Before; + @Singleton public class SystemInfoLocatorConfiguration { /** - * Setup DI with Google Guice DI. - * Create mocked and non mocked service under test and bind them with Guice. - * It is based on custom MockedLocator locator that is meant for service unit tests. + * Setup DI with Google Guice DI. Create mocked and non mocked service under test and bind them with Guice. It is based on custom MockedLocator locator that is meant for service unit tests. */ @Before(value = "@setup", order = 1) public void setupDI() { @@ -87,8 +85,6 @@ protected void configure() { // skip } - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); - bind(AuthorizationService.class).toInstance(mockedAuthorization); // Inject mocked Permission Factory bind(PermissionFactory.class).toInstance(Mockito.mock(PermissionFactory.class)); diff --git a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagFactory.java b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagFactory.java index 9f115487ef9..5e5ef6d9ed5 100644 --- a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagFactory.java +++ b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagFactory.java @@ -21,7 +21,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface TagFactory extends KapuaEntityFactory { +public interface TagFactory extends KapuaEntityFactory { /** * Instantiates a new {@link TagCreator}. diff --git a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagMatchPredicate.java b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagMatchPredicate.java index a1df13b4279..f28794fb894 100644 --- a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagMatchPredicate.java +++ b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagMatchPredicate.java @@ -12,7 +12,24 @@ *******************************************************************************/ package org.eclipse.kapua.service.tag; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; -public interface TagMatchPredicate extends MatchPredicate { +import java.util.Arrays; + +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; + +public class TagMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public TagMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + TagAttributes.DESCRIPTION, + TagAttributes.NAME + ); + this.matchTerm = matchTerm; + } } diff --git a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagQuery.java b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagQuery.java index 0bbfc29faeb..5a77a7a7425 100644 --- a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagQuery.java +++ b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.tag; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link Tag} {@link KapuaQuery} definition. * @@ -27,17 +28,32 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = TagXmlRegistry.class, factoryMethod = "newQuery") -public interface TagQuery extends KapuaQuery { +@XmlType +public class TagQuery extends KapuaQuery { + + /** + * Constructor. + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public TagQuery(KapuaId scopeId) { + super(scopeId); + } /** * Instantiates a new {@link TagMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link TagMatchPredicate}. * @since 2.1.0 */ - TagMatchPredicate matchPredicate(T matchTerm); + public TagMatchPredicate matchPredicate(T matchTerm) { + return new TagMatchPredicate<>(matchTerm); + } } diff --git a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagXmlRegistry.java b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagXmlRegistry.java index c12356b4f6d..3b5f285ab93 100644 --- a/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagXmlRegistry.java +++ b/service/tag/api/src/main/java/org/eclipse/kapua/service/tag/TagXmlRegistry.java @@ -40,6 +40,6 @@ public TagCreator newTagCreator() { } public TagQuery newQuery() { - return tagFactory.newQuery(null); + return new TagQuery(null); } } diff --git a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagFactoryImpl.java b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagFactoryImpl.java index 49778c6df75..bbec50b8bff 100644 --- a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagFactoryImpl.java +++ b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.tag.Tag; import org.eclipse.kapua.service.tag.TagCreator; import org.eclipse.kapua.service.tag.TagFactory; -import org.eclipse.kapua.service.tag.TagQuery; /** * {@link TagFactory} implementation. @@ -43,11 +42,6 @@ public Tag newEntity(KapuaId scopeId) { return new TagImpl(scopeId); } - @Override - public TagQuery newQuery(KapuaId scopeId) { - return new TagQueryImpl(scopeId); - } - @Override public TagCreator newCreator(KapuaId scopeId) { return new TagCreatorImpl(scopeId); diff --git a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagMatchPredicateImpl.java b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagMatchPredicateImpl.java deleted file mode 100644 index e785c278463..00000000000 --- a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagMatchPredicateImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.tag.internal; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.tag.TagAttributes; -import org.eclipse.kapua.service.tag.TagMatchPredicate; -import java.util.Arrays; - -public class TagMatchPredicateImpl extends AbstractMatchPredicate implements TagMatchPredicate { - -/** - * Constructor. - * - * @param matchTerm - * @since 2.1.0 - */ - public TagMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - TagAttributes.DESCRIPTION, - TagAttributes.NAME - ); - this.matchTerm = matchTerm; - } -} diff --git a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagQueryImpl.java b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagQueryImpl.java deleted file mode 100644 index 612e77fe43f..00000000000 --- a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagQueryImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.tag.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.tag.TagMatchPredicate; -import org.eclipse.kapua.service.tag.TagQuery; - -/** - * {@link TagQuery} implementation. - * - * @since 1.0.0 - */ -public class TagQueryImpl extends AbstractKapuaNamedQuery implements TagQuery { - - /** - * Constructor. - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public TagQueryImpl(KapuaId scopeId) { - super(scopeId); - } - - @Override - public TagMatchPredicate matchPredicate(T matchTerm) { - return new TagMatchPredicateImpl<>(matchTerm); - } - -} diff --git a/service/tag/test-steps/src/main/java/org/eclipse/kapua/service/tag/steps/TagServiceSteps.java b/service/tag/test-steps/src/main/java/org/eclipse/kapua/service/tag/steps/TagServiceSteps.java index bb7750467d1..09b73a6a831 100644 --- a/service/tag/test-steps/src/main/java/org/eclipse/kapua/service/tag/steps/TagServiceSteps.java +++ b/service/tag/test-steps/src/main/java/org/eclipse/kapua/service/tag/steps/TagServiceSteps.java @@ -12,14 +12,13 @@ *******************************************************************************/ package org.eclipse.kapua.service.tag.steps; -import com.google.inject.Singleton; -import io.cucumber.java.After; -import io.cucumber.java.Before; -import io.cucumber.java.Scenario; -import io.cucumber.java.en.And; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; @@ -38,11 +37,15 @@ import org.eclipse.kapua.service.tag.TagService; import org.junit.Assert; -import javax.inject.Inject; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import com.google.inject.Singleton; + +import io.cucumber.java.After; +import io.cucumber.java.Before; +import io.cucumber.java.Scenario; +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; /** * Implementation of Gherkin steps used in TagService.feature scenarios. @@ -170,7 +173,7 @@ public void tagWithNameIfSearched(String tagName) throws Throwable { try { stepData.remove("tag"); primeException(); - TagQuery query = tagFactory.newQuery(SYS_SCOPE_ID); + TagQuery query = new TagQuery(SYS_SCOPE_ID); query.setPredicate(query.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); //TODO: #LAYER_VIOLATION - isn't this a find by name? TagListResult queryResult = tagService.query(query); @@ -186,7 +189,7 @@ public void tagWithNameIfSearched(String tagName) throws Throwable { public void deleteTagWithName(String tagName) throws Throwable { try { primeException(); - TagQuery query = tagFactory.newQuery(getCurrentScopeId()); + TagQuery query = new TagQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); //TODO: #LAYER_VIOLATION - isn't this a find by name? TagListResult queryResult = tagService.query(query); @@ -232,7 +235,8 @@ public void tagWithNameIsDeleted(String tagName) throws Throwable { /** * Create TagCreator for creating tag with specified name. * - * @param tagName name of tag + * @param tagName + * name of tag * @return tag creator for tag with specified name */ private TagCreator tagCreatorCreatorWithoutDescription(String tagName) { @@ -266,7 +270,7 @@ public void tagNameIsChangedIntoName(String tagName) throws Exception { public void nameOfTagIsChangedInto(String tagName, String newTagName) throws Exception { try { primeException(); - TagQuery query = tagFactory.newQuery(getCurrentScopeId()); + TagQuery query = new TagQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult queryResult = tagService.query(query); Tag foundTag = queryResult.getFirstItem(); @@ -296,7 +300,7 @@ public void tagDescriptionIsChangedInto(String description) throws Exception { @And("Description of tag {string} is changed into {string}") public void descriptionOfTagIsChangedInto(String tagName, String newDescription) throws Exception { try { - TagQuery query = tagFactory.newQuery(getCurrentScopeId()); + TagQuery query = new TagQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(TagAttributes.NAME, tagName, AttributePredicate.Operator.EQUAL)); TagListResult queryResult = tagService.query(query); Tag foundTag = queryResult.getFirstItem(); diff --git a/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java b/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java index f867da80f3f..0f128e9d65a 100644 --- a/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java +++ b/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java @@ -12,13 +12,8 @@ *******************************************************************************/ package org.eclipse.kapua.service.tag.test; -import com.codahale.metrics.MetricRegistry; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Singleton; -import com.google.inject.name.Names; -import io.cucumber.java.Before; +import java.util.Collections; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountRelativeFinder; import org.eclipse.kapua.commons.configuration.RootUserTester; @@ -34,7 +29,6 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; @@ -42,7 +36,6 @@ import org.eclipse.kapua.message.KapuaMessageFactory; import org.eclipse.kapua.message.internal.KapuaMessageFactoryImpl; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; @@ -87,15 +80,20 @@ import org.mockito.Matchers; import org.mockito.Mockito; -import java.util.Collections; +import com.codahale.metrics.MetricRegistry; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Singleton; +import com.google.inject.name.Names; + +import io.cucumber.java.Before; @Singleton public class TagLocatorConfiguration { /** - * Setup DI with Google Guice DI. - * Create mocked and non mocked service under test and bind them with Guice. - * It is based on custom MockedLocator locator that is meant for service unit tests. + * Setup DI with Google Guice DI. Create mocked and non mocked service under test and bind them with Guice. It is based on custom MockedLocator locator that is meant for service unit tests. */ @Before(value = "@setup", order = 1) public void setupDI() { @@ -131,7 +129,6 @@ protected void configure() { } catch (KapuaException e) { // skip } - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); // Set KapuaMetatypeFactory for Metatype configuration bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl()); @@ -170,7 +167,8 @@ protected void configure() { new DeviceEventImplJpaRepository(jpaRepoConfig) ); - final DeviceValidation deviceValidation = new DeviceValidationImpl(new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_VAR_FIELDS_LENGTH_MAX), + final DeviceValidation deviceValidation = new DeviceValidationImpl( + new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_VAR_FIELDS_LENGTH_MAX), new KapuaDeviceRegistrySettings().getInt(KapuaDeviceRegistrySettingKeys.DEVICE_LIFECYCLE_BIRTH_EXTENDED_PROPERTIES_LENGTH_MAX), mockedAuthorization, permissionFactory, @@ -178,7 +176,6 @@ protected void configure() { deviceConnectionService, deviceEventService, new DeviceImplJpaRepository(jpaRepoConfig), - new DeviceFactoryImpl(), new TagServiceImpl( permissionFactory, mockedAuthorization, diff --git a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserFactory.java b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserFactory.java index ad6f5722827..eb22907b255 100644 --- a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserFactory.java +++ b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserFactory.java @@ -21,7 +21,7 @@ * @see org.eclipse.kapua.model.KapuaEntityFactory * @since 1.0.0 */ -public interface UserFactory extends KapuaEntityFactory { +public interface UserFactory extends KapuaEntityFactory { /** * Instantiates a new {@link UserCreator} diff --git a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserMatchPredicate.java b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserMatchPredicate.java index 22739e77ed8..185bd4afbfb 100644 --- a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserMatchPredicate.java +++ b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserMatchPredicate.java @@ -12,8 +12,28 @@ *******************************************************************************/ package org.eclipse.kapua.service.user; -import org.eclipse.kapua.model.query.predicate.MatchPredicate; +import java.util.Arrays; -public interface UserMatchPredicate extends MatchPredicate { +import org.eclipse.kapua.model.query.predicate.AbstractMatchPredicate; +public class UserMatchPredicate extends AbstractMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 1.3.0 + */ + public UserMatchPredicate(T matchTerm) { + this.attributeNames = Arrays.asList( + UserAttributes.NAME, + UserAttributes.EMAIL, + UserAttributes.PHONE_NUMBER, + UserAttributes.DISPLAY_NAME, + UserAttributes.EXTERNAL_ID, + UserAttributes.DESCRIPTION, + UserAttributes.EXTERNAL_USERNAME + ); + this.matchTerm = matchTerm; + } } diff --git a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserQuery.java b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserQuery.java index aba06704af3..95d24a3246d 100644 --- a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserQuery.java +++ b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserQuery.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.user; -import org.eclipse.kapua.model.query.KapuaQuery; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.KapuaQuery; + /** * {@link User} {@link KapuaQuery} definition. * @@ -27,17 +28,41 @@ */ @XmlRootElement(name = "query") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = UserXmlRegistry.class, factoryMethod = "newQuery") -public interface UserQuery extends KapuaQuery { +@XmlType +public class UserQuery extends KapuaQuery { + + /** + * Constructor. + * + * @since 1.0.0 + */ + private UserQuery() { + super(); + } + + /** + * Constructor + * + * @param scopeId + * The {@link #getScopeId()}. + * @since 1.0.0 + */ + public UserQuery(KapuaId scopeId) { + this(); + setScopeId(scopeId); + } /** * Instantiates a new {@link UserMatchPredicate}. * - * @param matchTerm The term to use to match. - * @param The type of the term + * @param matchTerm + * The term to use to match. + * @param + * The type of the term * @return The newly instantiated {@link UserMatchPredicate}. * @since 1.3.0 */ - UserMatchPredicate matchPredicate(T matchTerm); - + public UserMatchPredicate matchPredicate(T matchTerm) { + return new UserMatchPredicate<>(matchTerm); + } } diff --git a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserXmlRegistry.java b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserXmlRegistry.java index 04d48cb787c..c3ae1a184a6 100644 --- a/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserXmlRegistry.java +++ b/service/user/api/src/main/java/org/eclipse/kapua/service/user/UserXmlRegistry.java @@ -45,6 +45,6 @@ public UserCreator newUserCreator() { } public UserQuery newQuery() { - return userFactory.newQuery(null); + return new UserQuery(null); } } diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserFactoryImpl.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserFactoryImpl.java index 2d04f102a5f..6f4d9d609da 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserFactoryImpl.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserFactoryImpl.java @@ -19,7 +19,6 @@ import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserCreator; import org.eclipse.kapua.service.user.UserFactory; -import org.eclipse.kapua.service.user.UserQuery; /** * {@link UserFactory} implementation. @@ -38,11 +37,6 @@ public UserCreator newCreator(KapuaId scopeId, String name) { return creator; } - @Override - public UserQuery newQuery(KapuaId scopeId) { - return new UserQueryImpl(scopeId); - } - @Override public User newEntity(KapuaId scopeId) { return new UserImpl(scopeId); diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserMatchPredicateImpl.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserMatchPredicateImpl.java deleted file mode 100644 index 4c7d940880a..00000000000 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserMatchPredicateImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.user.internal; - -import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; -import org.eclipse.kapua.service.user.UserAttributes; -import org.eclipse.kapua.service.user.UserMatchPredicate; - -import java.util.Arrays; - -public class UserMatchPredicateImpl extends AbstractMatchPredicate implements UserMatchPredicate { - - /** - * Constructor. - * - * @param matchTerm - * @since 1.3.0 - */ - public UserMatchPredicateImpl(T matchTerm) { - this.attributeNames = Arrays.asList( - UserAttributes.NAME, - UserAttributes.EMAIL, - UserAttributes.PHONE_NUMBER, - UserAttributes.DISPLAY_NAME, - UserAttributes.EXTERNAL_ID, - UserAttributes.DESCRIPTION, - UserAttributes.EXTERNAL_USERNAME - ); - this.matchTerm = matchTerm; - } - -} diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserQueryImpl.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserQueryImpl.java deleted file mode 100644 index b7ad5afa1a6..00000000000 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserQueryImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.user.internal; - -import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; -import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.user.UserQuery; - -/** - * {@link UserQuery} implementation. - * - * @since 1.0.0 - */ -public class UserQueryImpl extends AbstractKapuaNamedQuery implements UserQuery { - - /** - * Constructor. - * - * @since 1.0.0 - */ - private UserQueryImpl() { - super(); - } - - /** - * Constructor - * - * @param scopeId The {@link #getScopeId()}. - * @since 1.0.0 - */ - public UserQueryImpl(KapuaId scopeId) { - this(); - setScopeId(scopeId); - } - - @Override - public UserMatchPredicateImpl matchPredicate(T matchTerm) { - return new UserMatchPredicateImpl<>(matchTerm); - } -} diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java index ffcce384bd4..c35e6d5c0ea 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java @@ -13,6 +13,11 @@ *******************************************************************************/ package org.eclipse.kapua.service.user.internal; +import java.util.Objects; +import java.util.Optional; + +import javax.inject.Singleton; + import org.eclipse.kapua.KapuaDuplicateExternalIdException; import org.eclipse.kapua.KapuaDuplicateExternalUsernameException; import org.eclipse.kapua.KapuaDuplicateNameException; @@ -48,10 +53,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Singleton; -import java.util.Objects; -import java.util.Optional; - /** * {@link UserService} implementation. * @@ -366,7 +367,7 @@ public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { } private void deleteUserByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { - UserQuery query = new UserQueryImpl(accountId); + UserQuery query = new UserQuery(accountId); UserListResult usersToDelete = query(query); for (User u : usersToDelete.getItems()) { diff --git a/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java b/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java index 645205764f2..3745138c31d 100644 --- a/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java +++ b/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java @@ -12,14 +12,21 @@ *******************************************************************************/ package org.eclipse.kapua.service.user.steps; -import com.google.inject.Singleton; -import io.cucumber.java.After; -import io.cucumber.java.Before; -import io.cucumber.java.Scenario; -import io.cucumber.java.en.And; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; +import java.math.BigInteger; +import java.text.MessageFormat; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.commons.security.KapuaSecurityUtils; @@ -46,7 +53,6 @@ import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; -import org.eclipse.kapua.service.authentication.credential.CredentialQuery; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOption; @@ -54,15 +60,12 @@ import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionFactory; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionService; import org.eclipse.kapua.service.authentication.credential.mfa.shiro.MfaOptionFactoryImpl; -import org.eclipse.kapua.service.authentication.credential.shiro.CredentialQueryImpl; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; -import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; -import org.eclipse.kapua.service.authorization.access.shiro.AccessPermissionQueryImpl; import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.user.User; @@ -75,19 +78,15 @@ import org.eclipse.kapua.service.user.UserStatus; import org.junit.Assert; -import javax.inject.Inject; -import java.math.BigInteger; -import java.text.MessageFormat; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import com.google.inject.Singleton; + +import io.cucumber.java.After; +import io.cucumber.java.Before; +import io.cucumber.java.Scenario; +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; /** * Implementation of Gherkin steps used in user test scenarios. @@ -242,7 +241,7 @@ public void searchForUsers() throws Exception { KapuaId scpId = DEFAULT_ID; Set iFoundUsers; stepData.remove(USER_LIST); - KapuaQuery query = userFactory.newQuery(scpId); + KapuaQuery query = new UserQuery(scpId); UserListResult queryResult = userService.query(query); iFoundUsers = new HashSet<>(); List users = queryResult.getItems(); @@ -335,7 +334,7 @@ public void searchUserByName() throws Exception { @When("I query for users in scope with id {int}") public void queryForUsers(int scopeId) throws Exception { stepData.remove(USER_LIST); - UserQuery query = userFactory.newQuery(new KapuaEid(BigInteger.valueOf(scopeId))); + UserQuery query = new UserQuery(new KapuaEid(BigInteger.valueOf(scopeId))); UserListResult queryResult = userService.query(query); Set iFoundUsers = new HashSet<>(); for (User userItem : queryResult.getItems()) { @@ -346,7 +345,7 @@ public void queryForUsers(int scopeId) throws Exception { @When("I count users in scope {int}") public void countUsersInScope(int scopeId) throws Exception { - UserQuery query = userFactory.newQuery(new KapuaEid(BigInteger.valueOf(scopeId))); + UserQuery query = new UserQuery(new KapuaEid(BigInteger.valueOf(scopeId))); stepData.updateCount((int) userService.count(query)); } @@ -464,7 +463,7 @@ public void searchForLastCreatedCredentials() throws Exception { ComparableUser comparableUser = (ComparableUser) stepData.get(LAST_USER); primeException(); try { - CredentialQuery credentialQuery = new CredentialQueryImpl(getCurrentScopeId()); + KapuaQuery credentialQuery = new KapuaQuery(getCurrentScopeId()); credentialQuery.setPredicate(credentialQuery.attributePredicate(CredentialAttributes.USER_ID, comparableUser.getUser().getId())); CredentialListResult credentials = credentialService.query(credentialQuery); stepData.put("CredentialsListFound", credentials); @@ -518,7 +517,7 @@ public void queryForLastAddedPermission() throws Exception { Permission permission = (Permission) stepData.get(LAST_PERMISSION_ADDED_TO_USER); primeException(); try { - AccessPermissionQuery query = new AccessPermissionQueryImpl(getCurrentScopeId()); + KapuaQuery query = new KapuaQuery(getCurrentScopeId()); query.setPredicate(query.attributePredicate(AccessPermissionAttributes.PERMISSION, permission)); AccessPermission accessPermission = accessPermissionService.query(query).getFirstItem(); stepData.put(LAST_FOUND_ACCESS_PERMISSION, accessPermission); @@ -717,12 +716,12 @@ public void logout() throws KapuaException { // ******************* /** - * Extract list of users form step parameter table and create those users in - * kapua. - * Operation is performed in privileged mode, without access and authorization checks. + * Extract list of users form step parameter table and create those users in kapua. Operation is performed in privileged mode, without access and authorization checks. * - * @param userList list of users in step - * @param account account in which users are created + * @param userList + * list of users in step + * @param account + * account in which users are created * @return Set of created users as ComparableUser Set * @throws Exception */ @@ -751,11 +750,12 @@ private HashSet createUsersInList(List userList, Accoun } /** - * Create User object with user data filed with quasi random data for user name, - * email, display name. Scope id and user id is set to test wide id. + * Create User object with user data filed with quasi random data for user name, email, display name. Scope id and user id is set to test wide id. * - * @param userId unique user id - * @param scopeId user scope id + * @param userId + * unique user id + * @param scopeId + * user scope id * @return User instance */ private User createUserInstance(int userId, int scopeId) { @@ -794,10 +794,10 @@ private UserCreator userCreatorCreator(String name, String displayName, String e } /** - * Create credentials for specific user, set users password. - * It finds user by name and sets its password. + * Create credentials for specific user, set users password. It finds user by name and sets its password. * - * @param cucCredentials username and open password + * @param cucCredentials + * username and open password * @return created credential */ private Credential createCredentials(CucCredentials cucCredentials) throws Exception { @@ -819,11 +819,16 @@ private Credential createCredentials(CucCredentials cucCredentials) throws Excep /** * Create credential creator for user with password. * - * @param scopeId scopeId in which user is - * @param userId userId for which credetntials are set - * @param password open password as credetntials - * @param status status of credentials enabled or disabled - * @param expirationDate credential expiration date + * @param scopeId + * scopeId in which user is + * @param userId + * userId for which credetntials are set + * @param password + * open password as credetntials + * @param status + * status of credentials enabled or disabled + * @param expirationDate + * credential expiration date * @return credential creator used for creating credentials */ private CredentialCreator credentialCreatorCreator(KapuaId scopeId, KapuaId userId, String password, CredentialStatus status, Date expirationDate) { @@ -835,10 +840,12 @@ private CredentialCreator credentialCreatorCreator(KapuaId scopeId, KapuaId user /** * Creates permissions for user with specified account. Permissions are created in priveledged mode. * - * @param permissionList list of permissions for user, if targetScopeId is not set user scope that is - * specifed as account - * @param user user for whom permissions are set - * @param account account in which user is defined + * @param permissionList + * list of permissions for user, if targetScopeId is not set user scope that is specifed as account + * @param user + * user for whom permissions are set + * @param account + * account in which user is defined * @throws Exception */ private void createPermissions(List permissionList, ComparableUser user, Account account) throws Exception { @@ -855,12 +862,14 @@ private void createPermissions(List permissionList, ComparableUse } /** - * Create accessInfoCreator instance with data about user permissions. - * If target scope is not defined in permission list use account scope. + * Create accessInfoCreator instance with data about user permissions. If target scope is not defined in permission list use account scope. * - * @param permissionList list of all permissions - * @param user user for which permissions are set - * @param account that user belongs to + * @param permissionList + * list of all permissions + * @param user + * user for which permissions are set + * @param account + * that user belongs to * @return AccessInfoCreator instance for creating user permissions */ private AccessInfoCreator accessInfoCreatorCreator(List permissionList, ComparableUser user, Account account) throws KapuaException { @@ -1037,7 +1046,7 @@ public void iSearchForTheUserWithExpirationDateInThePresent() throws KapuaExcept KapuaId scpId = DEFAULT_ID; Set iFoundUsers; stepData.remove(USER_LIST); - KapuaQuery query = userFactory.newQuery(scpId); + KapuaQuery query = new UserQuery(scpId); UserListResult queryResult = userService.query(query); iFoundUsers = new HashSet<>(); List users = queryResult.getItems(); @@ -1076,7 +1085,7 @@ public void iSearchForTheUserWithExpirationDateInThePast() throws KapuaException KapuaId scpId = DEFAULT_ID; Set iFoundUsers; stepData.remove(USER_LIST); - KapuaQuery query = userFactory.newQuery(scpId); + KapuaQuery query = new UserQuery(scpId); UserListResult queryResult = userService.query(query); iFoundUsers = new HashSet<>(); List users = queryResult.getItems(); @@ -1179,7 +1188,7 @@ public void iFindUsersWithPhoneNumber(List userList) { @And("I search users with phone number {string}") public void iSearchUsersWithPhoneNumber(String phoneNum) throws Throwable { - UserQuery userQuery = userFactory.newQuery(DEFAULT_ID); + UserQuery userQuery = new UserQuery(DEFAULT_ID); userQuery.setPredicate(userQuery.attributePredicate(UserAttributes.PHONE_NUMBER, phoneNum, AttributePredicate.Operator.EQUAL)); UserListResult userListResult = userService.query(userQuery); stepData.put(FOUND_USERS, userListResult); @@ -1187,7 +1196,7 @@ public void iSearchUsersWithPhoneNumber(String phoneNum) throws Throwable { @And("I search users with email {string}") public void iSearchForUsersWithEmail(String email) throws Throwable { - UserQuery userQuery = userFactory.newQuery(DEFAULT_ID); + UserQuery userQuery = new UserQuery(DEFAULT_ID); userQuery.setPredicate(userQuery.attributePredicate(UserAttributes.EMAIL, email, AttributePredicate.Operator.EQUAL)); UserListResult userListResult = userService.query(userQuery); stepData.put(FOUND_USERS, userListResult); diff --git a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java index 39e9e78e324..c16e75879a1 100644 --- a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java +++ b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java @@ -28,14 +28,12 @@ import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.commons.metric.MetricsServiceImpl; -import org.eclipse.kapua.commons.model.query.QueryFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.internal.cache.CacheManagerProvider; import org.eclipse.kapua.commons.setting.system.SystemSetting; import org.eclipse.kapua.commons.util.xml.XmlUtil; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory; -import org.eclipse.kapua.model.query.QueryFactory; import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; import org.eclipse.kapua.service.account.AccountService; @@ -101,8 +99,6 @@ protected void configure() { // skip } - bind(QueryFactory.class).toInstance(new QueryFactoryImpl()); - bind(AuthorizationService.class).toInstance(mockedAuthorization); // Inject mocked Permission Factory PermissionFactory mockPermissionFactory = Mockito.mock(PermissionFactory.class);