From d0789a4727c2f27e8a43308c7ac5e74b8987d867 Mon Sep 17 00:00:00 2001 From: Anuj Kumar Date: Thu, 19 Jul 2018 13:33:36 +0530 Subject: [PATCH] Tempus-577 Fixing sonarcloud bugs and code smells. --- .../actors/computation/ComputationActor.java | 9 ++- .../server/controller/AlarmController.java | 14 ++-- .../server/controller/AssetController.java | 24 +++---- .../server/controller/AuditLogController.java | 8 +-- .../server/controller/AuthController.java | 12 ++-- .../ComponentDescriptorController.java | 10 +-- .../controller/ComputationJobController.java | 12 ++-- .../controller/ComputationsController.java | 10 +-- .../controller/ConfigurationController.java | 7 +- .../server/controller/CustomerController.java | 14 ++-- .../controller/DashboardController.java | 38 +++++----- .../controller/DataModelController.java | 12 ++-- .../server/controller/DeviceController.java | 44 ++++++------ .../controller/EntityRelationController.java | 36 +++++----- .../server/controller/EventController.java | 13 ++-- .../server/controller/LoginController.java | 4 +- .../controller/NodeMetricController.java | 7 +- .../server/controller/PluginController.java | 20 +++--- .../server/controller/RuleController.java | 20 +++--- .../server/controller/TenantController.java | 8 +-- .../server/controller/UserController.java | 40 +++++------ .../controller/UserSettingsController.java | 16 ++--- .../controller/WidgetTypeController.java | 10 +-- .../controller/WidgetsBundleController.java | 10 +-- .../service/cluster/rpc/GrpcSession.java | 4 +- .../jwt/extractor/UserInfoTokenConverter.java | 2 +- .../server/common/data/UserPermission.java | 6 +- .../common/data/computation/Computations.java | 10 +-- .../data/datamodel/DataModelObject.java | 8 +-- .../transport/adaptor/JsonConverter.java | 8 +-- .../HostRequestIntervalRegistryTest.java | 2 +- .../dao/audit/CassandraAuditLogDao.java | 8 +-- .../dao/cassandra/CassandraQueryOptions.java | 2 +- .../dao/cassandra/CassandraSocketOptions.java | 2 +- .../AggregatePartitionsFunction.java | 4 +- .../CassandraBaseDepthSeriesDao.java | 69 ++++++++----------- .../dao/model/nosql/ComputationJobEntity.java | 19 +++-- .../dao/model/nosql/ComputationsEntity.java | 16 ++--- .../dao/model/sql/ComputationsEntity.java | 16 ++--- .../server/dao/relation/BaseRelationDao.java | 4 +- .../AggregatePartitionsFunction.java | 4 +- .../CassandraBaseTimeseriesDao.java | 55 ++++++--------- .../dao/service/BaseRelationServiceTest.java | 2 +- .../BaseTagMetaDataServiceTest.java | 4 +- .../handlers/DefaultRestMsgHandler.java | 10 +-- .../handlers/DefaultRuleMsgHandler.java | 8 +-- .../plugin/telemetry/SubscriptionManager.java | 4 +- 47 files changed, 300 insertions(+), 365 deletions(-) diff --git a/application/src/main/java/com/hashmapinc/server/actors/computation/ComputationActor.java b/application/src/main/java/com/hashmapinc/server/actors/computation/ComputationActor.java index 023d080cf..0174cce2b 100644 --- a/application/src/main/java/com/hashmapinc/server/actors/computation/ComputationActor.java +++ b/application/src/main/java/com/hashmapinc/server/actors/computation/ComputationActor.java @@ -22,17 +22,16 @@ import com.hashmapinc.server.actors.ActorSystemContext; import com.hashmapinc.server.actors.service.ContextAwareActor; import com.hashmapinc.server.actors.service.ContextBasedCreator; +import com.hashmapinc.server.actors.service.DefaultActorService; import com.hashmapinc.server.common.data.computation.ComputationJob; import com.hashmapinc.server.common.data.computation.Computations; import com.hashmapinc.server.common.data.id.ComputationId; import com.hashmapinc.server.common.data.id.ComputationJobId; import com.hashmapinc.server.common.data.id.TenantId; +import com.hashmapinc.server.common.data.page.PageDataIterable; import com.hashmapinc.server.common.data.plugin.ComponentLifecycleEvent; import com.hashmapinc.server.common.data.plugin.ComponentLifecycleState; -import com.hashmapinc.server.actors.service.DefaultActorService; -import com.hashmapinc.server.common.data.page.PageDataIterable; import com.hashmapinc.server.common.msg.plugin.ComponentLifecycleMsg; -import com.hashmapinc.server.exception.TempusApplicationException; import java.util.HashMap; import java.util.Map; @@ -53,11 +52,11 @@ public ComputationActor(ActorSystemContext systemContext, TenantId tenantId, Com } @Override - public void preStart() throws TempusApplicationException { + public void preStart(){ start(); } - private void start() throws TempusApplicationException { + private void start(){ logger.info("[{}][{}] Starting computation actor.", computationId, tenantId); computation = systemContext.getComputationsService().findById(computationId); if(computation == null){ diff --git a/application/src/main/java/com/hashmapinc/server/controller/AlarmController.java b/application/src/main/java/com/hashmapinc/server/controller/AlarmController.java index 648c9a733..b4d5371c8 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/AlarmController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/AlarmController.java @@ -36,7 +36,7 @@ public class AlarmController extends BaseController { public static final String ALARM_ID = "alarmId"; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.GET) + @GetMapping(value = "/alarm/{alarmId}") @ResponseBody public Alarm getAlarmById(@PathVariable(ALARM_ID) String strAlarmId) throws TempusException { checkParameter(ALARM_ID, strAlarmId); @@ -50,7 +50,7 @@ public Alarm getAlarmById(@PathVariable(ALARM_ID) String strAlarmId) throws Temp } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/info/{alarmId}", method = RequestMethod.GET) + @GetMapping(value = "/alarm/info/{alarmId}") @ResponseBody public AlarmInfo getAlarmInfoById(@PathVariable(ALARM_ID) String strAlarmId) throws TempusException { checkParameter(ALARM_ID, strAlarmId); @@ -63,7 +63,7 @@ public AlarmInfo getAlarmInfoById(@PathVariable(ALARM_ID) String strAlarmId) thr } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm", method = RequestMethod.POST) + @PostMapping(value = "/alarm") @ResponseBody public Alarm saveAlarm(@RequestBody Alarm alarm) throws TempusException { try { @@ -75,7 +75,7 @@ public Alarm saveAlarm(@RequestBody Alarm alarm) throws TempusException { } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/{alarmId}/ack", method = RequestMethod.POST) + @PostMapping(value = "/alarm/{alarmId}/ack") @ResponseStatus(value = HttpStatus.OK) public void ackAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws TempusException { checkParameter(ALARM_ID, strAlarmId); @@ -89,7 +89,7 @@ public void ackAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws TempusExc } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/{alarmId}/clear", method = RequestMethod.POST) + @PostMapping(value = "/alarm/{alarmId}/clear") @ResponseStatus(value = HttpStatus.OK) public void clearAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws TempusException { checkParameter(ALARM_ID, strAlarmId); @@ -103,7 +103,7 @@ public void clearAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws TempusE } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET) + @GetMapping(value = "/alarm/{entityType}/{entityId}") @ResponseBody public TimePageData getAlarms( @PathVariable("entityType") String strEntityType, @@ -136,7 +136,7 @@ public TimePageData getAlarms( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET) + @GetMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}") @ResponseBody public AlarmSeverity getHighestAlarmSeverity( @PathVariable("entityType") String strEntityType, diff --git a/application/src/main/java/com/hashmapinc/server/controller/AssetController.java b/application/src/main/java/com/hashmapinc/server/controller/AssetController.java index 072a9a9ed..9303ae3d4 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/AssetController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/AssetController.java @@ -50,7 +50,7 @@ public class AssetController extends BaseController { public static final String ASSET_ID = "assetId"; @PostAuthorize("hasPermission(returnObject, 'ASSET_READ')") - @RequestMapping(value = "/asset/{assetId}", method = RequestMethod.GET) + @GetMapping(value = "/asset/{assetId}") @ResponseBody public Asset getAssetById(@PathVariable(ASSET_ID) String strAssetId) throws TempusException { checkParameter(ASSET_ID, strAssetId); @@ -63,7 +63,7 @@ public Asset getAssetById(@PathVariable(ASSET_ID) String strAssetId) throws Temp } @PreAuthorize("hasPermission(#asset, 'ASSET_CREATE') or hasPermission(#asset, 'ASSET_UPDATE')") - @RequestMapping(value = "/asset", method = RequestMethod.POST) + @PostMapping(value = "/asset") @ResponseBody public Asset saveAsset(@RequestBody Asset asset) throws TempusException { try { @@ -92,7 +92,7 @@ public Asset saveAsset(@RequestBody Asset asset) throws TempusException { } @PreAuthorize("hasPermission(#strAssetId, 'ASSET', 'ASSET_DELETE')") - @RequestMapping(value = "/asset/{assetId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/asset/{assetId}") @ResponseStatus(value = HttpStatus.OK) public void deleteAsset(@PathVariable(ASSET_ID) String strAssetId) throws TempusException { checkParameter(ASSET_ID, strAssetId); @@ -115,7 +115,7 @@ public void deleteAsset(@PathVariable(ASSET_ID) String strAssetId) throws Tempus } @PreAuthorize("hasPermission(#strAssetId, 'ASSET', 'ASSET_ASSIGN')") - @RequestMapping(value = "/customer/{customerId}/asset/{assetId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/{customerId}/asset/{assetId}") @ResponseBody public Asset assignAssetToCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(ASSET_ID) String strAssetId) throws TempusException { @@ -146,7 +146,7 @@ public Asset assignAssetToCustomer(@PathVariable("customerId") String strCustome } @PreAuthorize("hasPermission(#strAssetId, 'ASSET', 'ASSET_ASSIGN')") - @RequestMapping(value = "/customer/asset/{assetId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/customer/asset/{assetId}") @ResponseBody public Asset unassignAssetFromCustomer(@PathVariable(ASSET_ID) String strAssetId) throws TempusException { checkParameter(ASSET_ID, strAssetId); @@ -177,7 +177,7 @@ public Asset unassignAssetFromCustomer(@PathVariable(ASSET_ID) String strAssetId } @PreAuthorize("hasPermission(#strAssetId, 'ASSET', 'ASSET_ASSIGN')") - @RequestMapping(value = "/customer/public/asset/{assetId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/public/asset/{assetId}") @ResponseBody public Asset assignAssetToPublicCustomer(@PathVariable(ASSET_ID) String strAssetId) throws TempusException { checkParameter(ASSET_ID, strAssetId); @@ -205,7 +205,7 @@ public Asset assignAssetToPublicCustomer(@PathVariable(ASSET_ID) String strAsset @PreAuthorize("hasAuthority('TENANT_ADMIN')") // TODO return type should be collection of Asset. Create new action ASSET_READ_TENANT // @PostFilter("hasPermission(filterObject, 'ASSET_CREATE')") - @RequestMapping(value = "/tenant/assets", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/tenant/assets", params = {"limit"}) @ResponseBody public TextPageData getTenantAssets( @RequestParam int limit, @@ -227,7 +227,7 @@ public TextPageData getTenantAssets( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/tenant/assets", params = {"assetName"}, method = RequestMethod.GET) + @GetMapping(value = "/tenant/assets", params = {"assetName"}) @ResponseBody public Asset getTenantAsset( @RequestParam String assetName) throws TempusException { @@ -242,7 +242,7 @@ public Asset getTenantAsset( @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") // @PostFilter("hasPermission(filterObject, 'ASSET_READ')") // TODO return type should be collection of Asset. - @RequestMapping(value = "/customer/{customerId}/assets", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}/assets", params = {"limit"}) @ResponseBody public TextPageData getCustomerAssets( @PathVariable("customerId") String strCustomerId, @@ -268,7 +268,7 @@ public TextPageData getCustomerAssets( } @PostFilter("hasPermission(filterObject, 'ASSET_READ')") - @RequestMapping(value = "/assets", params = {"assetIds"}, method = RequestMethod.GET) + @GetMapping(value = "/assets", params = {"assetIds"}) @ResponseBody public List getAssetsByIds( @RequestParam("assetIds") String[] strAssetIds) throws TempusException { @@ -294,7 +294,7 @@ public List getAssetsByIds( } @PostFilter("hasPermission(filterObject, 'ASSET_READ')") - @RequestMapping(value = "/assets", method = RequestMethod.POST) + @PostMapping(value = "/assets") @ResponseBody public List findByQuery(@RequestBody AssetSearchQuery query) throws TempusException { checkNotNull(query); @@ -318,7 +318,7 @@ public List findByQuery(@RequestBody AssetSearchQuery query) throws Tempu } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/asset/types", method = RequestMethod.GET) + @GetMapping(value = "/asset/types") @ResponseBody public List getAssetTypes() throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/controller/AuditLogController.java b/application/src/main/java/com/hashmapinc/server/controller/AuditLogController.java index 505614221..06aba632f 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/AuditLogController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/AuditLogController.java @@ -33,7 +33,7 @@ public class AuditLogController extends BaseController { @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/audit/logs/customer/{customerId}", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/audit/logs/customer/{customerId}", params = {"limit"}) @ResponseBody public TimePageData getAuditLogsByCustomerId( @PathVariable("customerId") String strCustomerId, @@ -53,7 +53,7 @@ public TimePageData getAuditLogsByCustomerId( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/audit/logs/user/{userId}", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/audit/logs/user/{userId}", params = {"limit"}) @ResponseBody public TimePageData getAuditLogsByUserId( @PathVariable("userId") String strUserId, @@ -73,7 +73,7 @@ public TimePageData getAuditLogsByUserId( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/audit/logs/entity/{entityType}/{entityId}", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/audit/logs/entity/{entityType}/{entityId}", params = {"limit"}) @ResponseBody public TimePageData getAuditLogsByEntityId( @PathVariable("entityType") String strEntityType, @@ -95,7 +95,7 @@ public TimePageData getAuditLogsByEntityId( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/audit/logs", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/audit/logs", params = {"limit"}) @ResponseBody public TimePageData getAuditLogs( @RequestParam int limit, diff --git a/application/src/main/java/com/hashmapinc/server/controller/AuthController.java b/application/src/main/java/com/hashmapinc/server/controller/AuthController.java index 79b93cf8c..44f6b7188 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/AuthController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/AuthController.java @@ -83,7 +83,7 @@ public class AuthController extends BaseController { } @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "/auth/changePassword", method = RequestMethod.POST) + @PostMapping(value = "/auth/changePassword") @ResponseStatus(value = HttpStatus.OK) public void changePassword ( @RequestBody JsonNode changePasswordRequest) throws TempusException { @@ -103,7 +103,7 @@ public void changePassword ( } - @RequestMapping(value = "/noauth/activate", params = { "activateToken" }, method = RequestMethod.GET) + @GetMapping(value = "/noauth/activate", params = { "activateToken" }) public ResponseEntity checkActivateToken(@RequestParam(value = "activateToken") String activateToken) throws JsonProcessingException, TempusException { HttpHeaders headers = new HttpHeaders(); HttpStatus responseStatus; @@ -134,7 +134,7 @@ public ResponseEntity checkActivateToken(@RequestParam(value = "activate return new ResponseEntity<>(headers, responseStatus); } - @RequestMapping(value = "/noauth/resetPasswordByEmail", method = RequestMethod.POST) + @PostMapping(value = "/noauth/resetPasswordByEmail") @ResponseStatus(value = HttpStatus.OK) public void requestResetPasswordByEmail ( @RequestBody JsonNode resetPasswordByEmailRequest, @@ -161,7 +161,7 @@ public void requestResetPasswordByEmail ( } } - @RequestMapping(value = "/noauth/resetPassword", params = { "resetToken" }, method = RequestMethod.GET) + @GetMapping(value = "/noauth/resetPassword", params = { "resetToken" }) public ResponseEntity checkResetToken( @RequestParam(value = "resetToken") String resetToken) throws TempusException { HttpHeaders headers = new HttpHeaders(); @@ -188,7 +188,7 @@ public ResponseEntity checkResetToken( return new ResponseEntity<>(headers, responseStatus); } - @RequestMapping(value = "/noauth/activate", method = RequestMethod.POST) + @PostMapping(value = "/noauth/activate") @ResponseStatus(value = HttpStatus.OK) @ResponseBody public JsonNode activateUser( @@ -253,7 +253,7 @@ private OAuth2RestOperations getoAuth2RestOperations(String password, IdentityUs return new OAuth2RestTemplate(userPasswordReq); } - @RequestMapping(value = "/noauth/resetPassword", method = RequestMethod.POST) + @PostMapping(value = "/noauth/resetPassword") @ResponseStatus(value = HttpStatus.OK) @ResponseBody public JsonNode resetPassword( diff --git a/application/src/main/java/com/hashmapinc/server/controller/ComponentDescriptorController.java b/application/src/main/java/com/hashmapinc/server/controller/ComponentDescriptorController.java index 3637a0671..c838d67dd 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/ComponentDescriptorController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/ComponentDescriptorController.java @@ -15,11 +15,11 @@ */ package com.hashmapinc.server.controller; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; import com.hashmapinc.server.common.data.plugin.ComponentDescriptor; import com.hashmapinc.server.common.data.plugin.ComponentType; import com.hashmapinc.server.exception.TempusException; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -28,7 +28,7 @@ public class ComponentDescriptorController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") - @RequestMapping(value = "/component/{componentDescriptorClazz:.+}", method = RequestMethod.GET) + @GetMapping(value = "/component/{componentDescriptorClazz:.+}") @ResponseBody public ComponentDescriptor getComponentDescriptorByClazz(@PathVariable("componentDescriptorClazz") String strComponentDescriptorClazz) throws TempusException { checkParameter("strComponentDescriptorClazz", strComponentDescriptorClazz); @@ -40,7 +40,7 @@ public ComponentDescriptor getComponentDescriptorByClazz(@PathVariable("componen } @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") - @RequestMapping(value = "/components/{componentType}", method = RequestMethod.GET) + @GetMapping(value = "/components/{componentType}") @ResponseBody public List getComponentDescriptorsByType(@PathVariable("componentType") String strComponentType) throws TempusException { checkParameter("componentType", strComponentType); @@ -52,7 +52,7 @@ public List getComponentDescriptorsByType(@PathVariable("co } @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") - @RequestMapping(value = "/components/actions/{pluginClazz:.+}", method = RequestMethod.GET) + @GetMapping(value = "/components/actions/{pluginClazz:.+}") @ResponseBody public List getPluginActionsByPluginClazz(@PathVariable("pluginClazz") String pluginClazz) throws TempusException { checkParameter("pluginClazz", pluginClazz); diff --git a/application/src/main/java/com/hashmapinc/server/controller/ComputationJobController.java b/application/src/main/java/com/hashmapinc/server/controller/ComputationJobController.java index 7499dcc63..0c2370e6f 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/ComputationJobController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/ComputationJobController.java @@ -40,7 +40,7 @@ public class ComputationJobController extends BaseController{ public static final String NOT_FOUND_SUFFIX = " wasn't found! "; @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationid}/jobs", method = RequestMethod.POST) + @PostMapping(value = "/computations/{computationid}/jobs") @ResponseBody public ComputationJob saveComputationJob(@PathVariable("computationid") String strComputationId, @RequestBody ComputationJob source) throws TempusException { @@ -70,7 +70,7 @@ public ComputationJob saveComputationJob(@PathVariable("computationid") String s } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/jobs/{computationJobId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/computations/jobs/{computationJobId}") @ResponseStatus(value = HttpStatus.OK) public void deleteComputationJob(@PathVariable("computationJobId") String strComputationJobId) throws TempusException { checkParameter("computationJobId", strComputationJobId); @@ -91,7 +91,7 @@ public void deleteComputationJob(@PathVariable("computationJobId") String strCom } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}/jobs/{computationJobId}", method = RequestMethod.GET) + @GetMapping(value = "/computations/{computationId}/jobs/{computationJobId}") @ResponseStatus(value = HttpStatus.OK) public ComputationJob getComputationJob(@PathVariable("computationJobId") String strComputationJobId, @PathVariable("computationId") String strComputationId) throws TempusException { @@ -108,7 +108,7 @@ public ComputationJob getComputationJob(@PathVariable("computationJobId") String } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}/jobs/{computationJodId}/activate", method = RequestMethod.POST) + @PostMapping(value = "/computations/{computationId}/jobs/{computationJodId}/activate") @ResponseStatus(value = HttpStatus.OK) public void activateCompuationJobById(@PathVariable("computationJodId") String strComputationJobId, @PathVariable("computationId") String strComputationId) throws TempusException { @@ -137,7 +137,7 @@ public void activateCompuationJobById(@PathVariable("computationJodId") String s } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}/jobs/{computationJodId}/suspend", method = RequestMethod.POST) + @PostMapping(value = "/computations/{computationId}/jobs/{computationJodId}/suspend") @ResponseStatus(value = HttpStatus.OK) public void suspendComputationJobById(@PathVariable("computationJodId") String strComputationJobId, @PathVariable("computationId") String strComputationId) throws TempusException { @@ -166,7 +166,7 @@ public void suspendComputationJobById(@PathVariable("computationJodId") String s } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}/jobs", method = RequestMethod.GET) + @GetMapping(value = "/computations/{computationId}/jobs") @ResponseStatus(value = HttpStatus.OK) public List getComputationJobs(@PathVariable("computationId") String strComputationId) throws TempusException { checkParameter("computationId", strComputationId); diff --git a/application/src/main/java/com/hashmapinc/server/controller/ComputationsController.java b/application/src/main/java/com/hashmapinc/server/controller/ComputationsController.java index ed2b92676..99140a38f 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/ComputationsController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/ComputationsController.java @@ -65,7 +65,7 @@ public class ComputationsController extends BaseController { private ComputationDiscoveryService computationDiscoveryService; @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/computations/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(value = "/computations/upload", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Computations upload(@RequestParam("file") MultipartFile file) throws TempusException { @@ -96,7 +96,7 @@ public Computations upload(@RequestParam("file") MultipartFile file) throws Temp } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/computations/{computationId}") @ResponseBody public void delete(@PathVariable(COMPUTATION_ID) String strComputationId) throws TempusException, IOException { @@ -126,7 +126,7 @@ public void delete(@PathVariable(COMPUTATION_ID) String strComputationId) throws } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/computations", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/computations", params = {"limit"}) @ResponseBody public TextPageData getTenantComputations( @RequestParam int limit, @@ -143,7 +143,7 @@ public TextPageData getTenantComputations( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations", method = RequestMethod.GET) + @GetMapping(value = "/computations") @ResponseBody public List getComputations() throws TempusException { try { @@ -159,7 +159,7 @@ public List getComputations() throws TempusException { } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/computations/{computationId}", method = RequestMethod.GET) + @GetMapping(value = "/computations/{computationId}") @ResponseBody public Computations getComputation(@PathVariable(COMPUTATION_ID) String strComputationId) throws TempusException { diff --git a/application/src/main/java/com/hashmapinc/server/controller/ConfigurationController.java b/application/src/main/java/com/hashmapinc/server/controller/ConfigurationController.java index b03ec9070..cf40bb4e4 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/ConfigurationController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/ConfigurationController.java @@ -20,10 +20,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.hashmapinc.server.exception.TempusException; import java.util.HashMap; @@ -47,7 +44,7 @@ public void setUi(Map ui) { this.ui = ui; } - @RequestMapping(value = "/configurations", method = RequestMethod.GET) + @GetMapping(value = "/configurations") @ResponseBody public Map getUiConfiguration() throws TempusException { if (!ui.isEmpty()) { diff --git a/application/src/main/java/com/hashmapinc/server/controller/CustomerController.java b/application/src/main/java/com/hashmapinc/server/controller/CustomerController.java index 79356e9b6..5bf2af868 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/CustomerController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/CustomerController.java @@ -38,7 +38,7 @@ public class CustomerController extends BaseController { public static final String IS_PUBLIC = "isPublic"; @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}") @ResponseBody public Customer getCustomerById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws TempusException { checkParameter(CUSTOMER_ID, strCustomerId); @@ -51,7 +51,7 @@ public Customer getCustomerById(@PathVariable(CUSTOMER_ID) String strCustomerId) } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}/shortInfo", method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}/shortInfo") @ResponseBody public JsonNode getShortCustomerInfoById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws TempusException { checkParameter(CUSTOMER_ID, strCustomerId); @@ -69,7 +69,7 @@ public JsonNode getShortCustomerInfoById(@PathVariable(CUSTOMER_ID) String strCu } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}/title", method = RequestMethod.GET, produces = "application/text") + @GetMapping(value = "/customer/{customerId}/title", produces = "application/text") @ResponseBody public String getCustomerTitleById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws TempusException { checkParameter(CUSTOMER_ID, strCustomerId); @@ -83,7 +83,7 @@ public String getCustomerTitleById(@PathVariable(CUSTOMER_ID) String strCustomer } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer", method = RequestMethod.POST) + @PostMapping(value = "/customer") @ResponseBody public Customer saveCustomer(@RequestBody Customer customer) throws TempusException { try { @@ -105,7 +105,7 @@ public Customer saveCustomer(@RequestBody Customer customer) throws TempusExcept } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/customer/{customerId}") @ResponseStatus(value = HttpStatus.OK) public void deleteCustomer(@PathVariable(CUSTOMER_ID) String strCustomerId) throws TempusException { checkParameter(CUSTOMER_ID, strCustomerId); @@ -130,7 +130,7 @@ public void deleteCustomer(@PathVariable(CUSTOMER_ID) String strCustomerId) thro } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customers", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/customers", params = {"limit"}) @ResponseBody public TextPageData getCustomers(@RequestParam int limit, @RequestParam(required = false) String textSearch, @@ -146,7 +146,7 @@ public TextPageData getCustomers(@RequestParam int limit, } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/tenant/customers", params = {"customerTitle"}, method = RequestMethod.GET) + @GetMapping(value = "/tenant/customers", params = {"customerTitle"}) @ResponseBody public Customer getTenantCustomer( @RequestParam String customerTitle) throws TempusException { diff --git a/application/src/main/java/com/hashmapinc/server/controller/DashboardController.java b/application/src/main/java/com/hashmapinc/server/controller/DashboardController.java index e42bfee10..839ad6d51 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/DashboardController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/DashboardController.java @@ -17,20 +17,18 @@ import com.hashmapinc.server.common.data.*; import com.hashmapinc.server.common.data.audit.ActionType; +import com.hashmapinc.server.common.data.id.CustomerId; import com.hashmapinc.server.common.data.id.DashboardId; import com.hashmapinc.server.common.data.id.TenantId; import com.hashmapinc.server.common.data.page.TextPageData; import com.hashmapinc.server.common.data.page.TextPageLink; +import com.hashmapinc.server.common.data.page.TimePageData; import com.hashmapinc.server.common.data.page.TimePageLink; -import com.hashmapinc.server.common.data.plugin.ComponentLifecycleEvent; import com.hashmapinc.server.common.data.security.Authority; +import com.hashmapinc.server.exception.TempusException; import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import com.hashmapinc.server.common.data.*; -import com.hashmapinc.server.common.data.id.CustomerId; -import com.hashmapinc.server.common.data.page.TimePageData; -import com.hashmapinc.server.exception.TempusException; import java.util.HashSet; import java.util.Set; @@ -43,14 +41,14 @@ public class DashboardController extends BaseController { public static final String CUSTOMER_ID = "customerId"; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/dashboard/serverTime", method = RequestMethod.GET) + @GetMapping(value = "/dashboard/serverTime") @ResponseBody public long getServerTime() { return System.currentTimeMillis(); } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/dashboard/info/{dashboardId}", method = RequestMethod.GET) + @GetMapping(value = "/dashboard/info/{dashboardId}") @ResponseBody public DashboardInfo getDashboardInfoById(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { checkParameter(DASHBOARD_ID, strDashboardId); @@ -63,7 +61,7 @@ public DashboardInfo getDashboardInfoById(@PathVariable(DASHBOARD_ID) String str } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/dashboard/{dashboardId}", method = RequestMethod.GET) + @GetMapping(value = "/dashboard/{dashboardId}") @ResponseBody public Dashboard getDashboardById(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { checkParameter(DASHBOARD_ID, strDashboardId); @@ -76,7 +74,7 @@ public Dashboard getDashboardById(@PathVariable(DASHBOARD_ID) String strDashboar } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN' , 'CUSTOMER_USER')") - @RequestMapping(value = "/dashboard", method = RequestMethod.POST) + @PostMapping(value = "/dashboard") @ResponseBody public Dashboard saveDashboard(@RequestBody Dashboard dashboard) throws TempusException { try { @@ -110,7 +108,7 @@ private Dashboard autoAssignedUserToDashboard(DashboardId dashboardId,CustomerId @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/dashboard/{dashboardId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/dashboard/{dashboardId}") @ResponseStatus(value = HttpStatus.OK) public void deleteDashboard(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { checkParameter(DASHBOARD_ID, strDashboardId); @@ -135,7 +133,7 @@ public void deleteDashboard(@PathVariable(DASHBOARD_ID) String strDashboardId) t } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/{customerId}/dashboard/{dashboardId}") @ResponseBody public Dashboard assignDashboardToCustomer(@PathVariable(CUSTOMER_ID) String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { @@ -167,7 +165,7 @@ public Dashboard assignDashboardToCustomer(@PathVariable(CUSTOMER_ID) String str } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/customer/{customerId}/dashboard/{dashboardId}") @ResponseBody public Dashboard unassignDashboardFromCustomer(@PathVariable(CUSTOMER_ID) String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { @@ -197,7 +195,7 @@ public Dashboard unassignDashboardFromCustomer(@PathVariable(CUSTOMER_ID) String } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/dashboard/{dashboardId}/customers", method = RequestMethod.POST) + @PostMapping(value = "/dashboard/{dashboardId}/customers") @ResponseBody public Dashboard updateDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId, @RequestBody String[] strCustomerIds) throws TempusException { @@ -278,7 +276,7 @@ private Set getCustomerIds(@RequestBody String[] strCustomerIds) { } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/dashboard/{dashboardId}/customers/add", method = RequestMethod.POST) + @PostMapping(value = "/dashboard/{dashboardId}/customers/add") @ResponseBody public Dashboard addDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId, @RequestBody String[] strCustomerIds) throws TempusException { @@ -321,7 +319,7 @@ public Dashboard addDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDas } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/dashboard/{dashboardId}/customers/remove", method = RequestMethod.POST) + @PostMapping(value = "/dashboard/{dashboardId}/customers/remove") @ResponseBody public Dashboard removeDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId, @RequestBody String[] strCustomerIds) throws TempusException { @@ -365,7 +363,7 @@ public Dashboard removeDashboardCustomers(@PathVariable(DASHBOARD_ID) String str } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/public/dashboard/{dashboardId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/public/dashboard/{dashboardId}") @ResponseBody public Dashboard assignDashboardToPublicCustomer(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { checkParameter(DASHBOARD_ID, strDashboardId); @@ -391,7 +389,7 @@ public Dashboard assignDashboardToPublicCustomer(@PathVariable(DASHBOARD_ID) Str } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/public/dashboard/{dashboardId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/customer/public/dashboard/{dashboardId}") @ResponseBody public Dashboard unassignDashboardFromPublicCustomer(@PathVariable(DASHBOARD_ID) String strDashboardId) throws TempusException { checkParameter(DASHBOARD_ID, strDashboardId); @@ -418,7 +416,7 @@ public Dashboard unassignDashboardFromPublicCustomer(@PathVariable(DASHBOARD_ID) } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/tenant/{tenantId}/dashboards", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/tenant/{tenantId}/dashboards", params = { "limit" }) @ResponseBody public TextPageData getTenantDashboards( @PathVariable("tenantId") String strTenantId, @@ -437,7 +435,7 @@ public TextPageData getTenantDashboards( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/tenant/dashboards", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/tenant/dashboards", params = { "limit" }) @ResponseBody public TextPageData getTenantDashboards( @RequestParam int limit, @@ -454,7 +452,7 @@ public TextPageData getTenantDashboards( } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}/dashboards", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}/dashboards", params = { "limit" }) @ResponseBody public TimePageData getCustomerDashboards( @PathVariable(CUSTOMER_ID) String strCustomerId, diff --git a/application/src/main/java/com/hashmapinc/server/controller/DataModelController.java b/application/src/main/java/com/hashmapinc/server/controller/DataModelController.java index e69d66437..3400ba574 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/DataModelController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/DataModelController.java @@ -38,7 +38,7 @@ public class DataModelController extends BaseController { public static final String DATA_MODEL_ID = "dataModelId"; @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/data-model", method = RequestMethod.POST) + @PostMapping(value = "/data-model") @ResponseBody public DataModel saveDataModel(@RequestBody DataModel dataModel) throws TempusException { dataModel.setTenantId(getCurrentUser().getTenantId()); @@ -57,7 +57,7 @@ public DataModel saveDataModel(@RequestBody DataModel dataModel) throws TempusEx } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "data-model/{dataModelId}", method = RequestMethod.GET) + @GetMapping(value = "data-model/{dataModelId}") @ResponseBody public DataModel fetchDataModelById(@PathVariable(DATA_MODEL_ID) String dataModelId) throws TempusException { try{ @@ -69,7 +69,7 @@ public DataModel fetchDataModelById(@PathVariable(DATA_MODEL_ID) String dataMode } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "data-model", method = RequestMethod.GET) + @GetMapping(value = "data-model") @ResponseBody public List fetchAllDataModelByTenantId() throws TempusException { try{ @@ -80,7 +80,7 @@ public List fetchAllDataModelByTenantId() throws TempusException { } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/data-model/{dataModelId}/objects", method = RequestMethod.POST) + @PostMapping(value = "/data-model/{dataModelId}/objects") @ResponseBody public DataModelObject saveDataModelObject(@RequestBody DataModelObject dataModelObject, @PathVariable String dataModelId) throws TempusException { @@ -102,7 +102,7 @@ public DataModelObject saveDataModelObject(@RequestBody DataModelObject dataMode } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/data-model/{dataModelId}/objects", method = RequestMethod.GET) + @GetMapping(value = "/data-model/{dataModelId}/objects") @ResponseBody public List fetchDataModelObjectsByModel(@PathVariable(DATA_MODEL_ID) String dataModelId) throws TempusException { try { @@ -117,7 +117,7 @@ public List fetchDataModelObjectsByModel(@PathVariable(DATA_MOD } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/data-model/objects/{objectId}", method = RequestMethod.GET) + @GetMapping(value = "/data-model/objects/{objectId}") @ResponseBody public DataModelObject fetchDataModelObjectById(@PathVariable("objectId") String objectId) throws TempusException { diff --git a/application/src/main/java/com/hashmapinc/server/controller/DeviceController.java b/application/src/main/java/com/hashmapinc/server/controller/DeviceController.java index 585c25b81..e23a22a9f 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/DeviceController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/DeviceController.java @@ -18,6 +18,8 @@ import com.google.common.util.concurrent.ListenableFuture; import com.hashmapinc.server.common.data.*; import com.hashmapinc.server.common.data.audit.ActionType; +import com.hashmapinc.server.common.data.device.DeviceSearchQuery; +import com.hashmapinc.server.common.data.id.CustomerId; import com.hashmapinc.server.common.data.id.DeviceId; import com.hashmapinc.server.common.data.id.TenantId; import com.hashmapinc.server.common.data.page.TextPageData; @@ -27,6 +29,10 @@ import com.hashmapinc.server.dao.attributes.AttributesService; import com.hashmapinc.server.dao.depthseries.DepthSeriesService; import com.hashmapinc.server.dao.exception.IncorrectParameterException; +import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.dao.timeseries.TimeseriesService; +import com.hashmapinc.server.exception.TempusErrorCode; +import com.hashmapinc.server.exception.TempusException; import com.hashmapinc.server.service.security.model.SecurityUser; import com.opencsv.CSVWriter; import lombok.extern.slf4j.Slf4j; @@ -34,12 +40,6 @@ import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import com.hashmapinc.server.common.data.device.DeviceSearchQuery; -import com.hashmapinc.server.common.data.id.CustomerId; -import com.hashmapinc.server.dao.model.ModelConstants; -import com.hashmapinc.server.dao.timeseries.TimeseriesService; -import com.hashmapinc.server.exception.TempusErrorCode; -import com.hashmapinc.server.exception.TempusException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -64,7 +64,7 @@ public class DeviceController extends BaseController { protected AttributesService attributesService; @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET) + @GetMapping(value = "/device/{deviceId}") @ResponseBody public Device getDeviceById(@PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { checkParameter(DEVICE_ID, strDeviceId); @@ -77,7 +77,7 @@ public Device getDeviceById(@PathVariable(DEVICE_ID) String strDeviceId) throws } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/device", method = RequestMethod.POST) + @PostMapping(value = "/device") @ResponseBody public Device saveDevice(@RequestBody Device device) throws TempusException { try { @@ -113,7 +113,7 @@ public Device saveDevice(@RequestBody Device device) throws TempusException { } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/device/{deviceId}") @ResponseStatus(value = HttpStatus.OK) public void deleteDevice(@PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { checkParameter(DEVICE_ID, strDeviceId); @@ -136,7 +136,7 @@ public void deleteDevice(@PathVariable(DEVICE_ID) String strDeviceId) throws Tem } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/{customerId}/device/{deviceId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/{customerId}/device/{deviceId}") @ResponseBody public Device assignDeviceToCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { @@ -165,7 +165,7 @@ public Device assignDeviceToCustomer(@PathVariable("customerId") String strCusto } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/device/{deviceId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/customer/device/{deviceId}") @ResponseBody public Device unassignDeviceFromCustomer(@PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { checkParameter(DEVICE_ID, strDeviceId); @@ -193,7 +193,7 @@ public Device unassignDeviceFromCustomer(@PathVariable(DEVICE_ID) String strDevi } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/public/device/{deviceId}", method = RequestMethod.POST) + @PostMapping(value = "/customer/public/device/{deviceId}") @ResponseBody public Device assignDeviceToPublicCustomer(@PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { checkParameter(DEVICE_ID, strDeviceId); @@ -217,7 +217,7 @@ public Device assignDeviceToPublicCustomer(@PathVariable(DEVICE_ID) String strDe } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/device/{deviceId}/credentials", method = RequestMethod.GET) + @GetMapping(value = "/device/{deviceId}/credentials") @ResponseBody public DeviceCredentials getDeviceCredentialsByDeviceId(@PathVariable(DEVICE_ID) String strDeviceId) throws TempusException { checkParameter(DEVICE_ID, strDeviceId); @@ -238,7 +238,7 @@ public DeviceCredentials getDeviceCredentialsByDeviceId(@PathVariable(DEVICE_ID) } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/device/credentials", method = RequestMethod.POST) + @PostMapping(value = "/device/credentials") @ResponseBody public DeviceCredentials saveDeviceCredentials(@RequestBody DeviceCredentials deviceCredentials) throws TempusException { checkNotNull(deviceCredentials); @@ -259,7 +259,7 @@ public DeviceCredentials saveDeviceCredentials(@RequestBody DeviceCredentials de } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/tenant/devices", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/tenant/devices", params = {"limit"}) @ResponseBody public TextPageData getTenantDevices( @RequestParam int limit, @@ -281,7 +281,7 @@ public TextPageData getTenantDevices( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/tenant/devices", params = {"deviceName"}, method = RequestMethod.GET) + @GetMapping(value = "/tenant/devices", params = {"deviceName"}) @ResponseBody public Device getTenantDevice( @RequestParam String deviceName) throws TempusException { @@ -294,7 +294,7 @@ public Device getTenantDevice( } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/customer/{customerId}/devices", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}/devices", params = {"limit"}) @ResponseBody public TextPageData getCustomerDevices( @PathVariable("customerId") String strCustomerId, @@ -320,7 +320,7 @@ public TextPageData getCustomerDevices( } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/devices", params = {"deviceIds"}, method = RequestMethod.GET) + @GetMapping(value = "/devices", params = {"deviceIds"}) @ResponseBody public List getDevicesByIds( @RequestParam("deviceIds") String[] strDeviceIds) throws TempusException { @@ -346,7 +346,7 @@ public List getDevicesByIds( } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/download/deviceAttributesData", method = RequestMethod.GET) + @GetMapping(value = "/download/deviceAttributesData") @ResponseBody public void downloadAttributesDataAsCsv(HttpServletResponse response, @RequestParam("deviceId") String strDeviceId) throws IOException { String csvFileName = "device_attributes_data.csv"; @@ -371,7 +371,7 @@ public void downloadAttributesDataAsCsv(HttpServletResponse response, @RequestPa } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/download/deviceSeriesData", method = RequestMethod.GET) + @GetMapping(value = "/download/deviceSeriesData") @ResponseBody public void downloadTimeSeriesOrDepthSeriesDataAsCSV(HttpServletResponse response, @RequestParam("deviceId") String strDeviceId, @@ -407,7 +407,7 @@ public void downloadTimeSeriesOrDepthSeriesDataAsCSV(HttpServletResponse respons @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/devices", method = RequestMethod.POST) + @PostMapping(value = "/devices") @ResponseBody public List findByQuery(@RequestBody DeviceSearchQuery query) throws TempusException { checkNotNull(query); @@ -431,7 +431,7 @@ public List findByQuery(@RequestBody DeviceSearchQuery query) throws Tem } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/device/types", method = RequestMethod.GET) + @GetMapping(value = "/device/types") @ResponseBody public List getDeviceTypes() throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/controller/EntityRelationController.java b/application/src/main/java/com/hashmapinc/server/controller/EntityRelationController.java index a49963882..297528819 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/EntityRelationController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/EntityRelationController.java @@ -15,18 +15,18 @@ */ package com.hashmapinc.server.controller; -import com.hashmapinc.server.common.data.relation.EntityRelationInfo; -import com.hashmapinc.server.common.data.relation.RelationTypeGroup; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; import com.hashmapinc.server.common.data.id.EntityId; import com.hashmapinc.server.common.data.id.EntityIdFactory; import com.hashmapinc.server.common.data.relation.EntityRelation; +import com.hashmapinc.server.common.data.relation.EntityRelationInfo; import com.hashmapinc.server.common.data.relation.EntityRelationsQuery; +import com.hashmapinc.server.common.data.relation.RelationTypeGroup; import com.hashmapinc.server.exception.TempusErrorCode; import com.hashmapinc.server.exception.TempusException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -42,7 +42,7 @@ public class EntityRelationController extends BaseController { public static final String TO_ID = "toId"; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relation", method = RequestMethod.POST) + @PostMapping(value = "/relation") @ResponseStatus(value = HttpStatus.OK) public void saveRelation(@RequestBody EntityRelation relation) throws TempusException { try { @@ -59,7 +59,7 @@ public void saveRelation(@RequestBody EntityRelation relation) throws TempusExce } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relation", method = RequestMethod.DELETE, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE}) + @DeleteMapping(value = "/relation", params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE}) @ResponseStatus(value = HttpStatus.OK) public void deleteRelation(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @@ -87,7 +87,7 @@ public void deleteRelation(@RequestParam(FROM_ID) String strFromId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = {"id", "type"}) + @DeleteMapping(value = "/relations", params = {"id", "type"}) @ResponseStatus(value = HttpStatus.OK) public void deleteRelations(@RequestParam("entityId") String strId, @RequestParam("entityType") String strType) throws TempusException { @@ -103,7 +103,7 @@ public void deleteRelations(@RequestParam("entityId") String strId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relation", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE}) + @GetMapping(value = "/relation", params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE}) @ResponseBody public EntityRelation getRelation(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @@ -128,7 +128,7 @@ public EntityRelation getRelation(@RequestParam(FROM_ID) String strFromId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE}) + @GetMapping(value = "/relations", params = {FROM_ID, FROM_TYPE}) @ResponseBody public List findByFrom(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @@ -146,7 +146,7 @@ public List findByFrom(@RequestParam(FROM_ID) String strFromId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE}) + @GetMapping(value = "/relations/info", params = {FROM_ID, FROM_TYPE}) @ResponseBody public List findInfoByFrom(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @@ -164,7 +164,7 @@ public List findInfoByFrom(@RequestParam(FROM_ID) String str } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE}) + @GetMapping(value = "/relations", params = {FROM_ID, FROM_TYPE, RELATION_TYPE}) @ResponseBody public List findByFrom(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @@ -184,7 +184,7 @@ public List findByFrom(@RequestParam(FROM_ID) String strFromId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE}) + @GetMapping(value = "/relations", params = {TO_ID, TO_TYPE}) @ResponseBody public List findByTo(@RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType, @@ -202,7 +202,7 @@ public List findByTo(@RequestParam(TO_ID) String strToId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {TO_ID, TO_TYPE}) + @GetMapping(value = "/relations/info", params = {TO_ID, TO_TYPE}) @ResponseBody public List findInfoByTo(@RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType, @@ -220,7 +220,7 @@ public List findInfoByTo(@RequestParam(TO_ID) String strToId } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE, RELATION_TYPE}) + @GetMapping(value = "/relations", params = {TO_ID, TO_TYPE, RELATION_TYPE}) @ResponseBody public List findByTo(@RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType, @@ -240,7 +240,7 @@ public List findByTo(@RequestParam(TO_ID) String strToId, } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations", method = RequestMethod.POST) + @PostMapping(value = "/relations") @ResponseBody public List findByQuery(@RequestBody EntityRelationsQuery query) throws TempusException { checkNotNull(query); @@ -255,7 +255,7 @@ public List findByQuery(@RequestBody EntityRelationsQuery query) } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/relations/info", method = RequestMethod.POST) + @PostMapping(value = "/relations/info") @ResponseBody public List findInfoByQuery(@RequestBody EntityRelationsQuery query) throws TempusException { checkNotNull(query); diff --git a/application/src/main/java/com/hashmapinc/server/controller/EventController.java b/application/src/main/java/com/hashmapinc/server/controller/EventController.java index a21370e58..15857867f 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/EventController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/EventController.java @@ -15,19 +15,18 @@ */ package com.hashmapinc.server.controller; +import com.hashmapinc.server.common.data.Event; import com.hashmapinc.server.common.data.id.EntityIdFactory; import com.hashmapinc.server.common.data.id.TenantId; +import com.hashmapinc.server.common.data.page.TimePageData; import com.hashmapinc.server.common.data.page.TimePageLink; import com.hashmapinc.server.dao.event.EventService; import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.exception.TempusErrorCode; +import com.hashmapinc.server.exception.TempusException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import com.hashmapinc.server.common.data.Event; -import com.hashmapinc.server.common.data.id.*; -import com.hashmapinc.server.common.data.page.TimePageData; -import com.hashmapinc.server.exception.TempusErrorCode; -import com.hashmapinc.server.exception.TempusException; @RestController @RequestMapping("/api") @@ -37,7 +36,7 @@ public class EventController extends BaseController { private EventService eventService; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/events/{entityType}/{entityId}/{eventType}", method = RequestMethod.GET) + @GetMapping(value = "/events/{entityType}/{entityId}/{eventType}") @ResponseBody public TimePageData getEvents( @PathVariable("entityType") String strEntityType, @@ -67,7 +66,7 @@ public TimePageData getEvents( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.GET) + @GetMapping(value = "/events/{entityType}/{entityId}") @ResponseBody public TimePageData getEvents( @PathVariable("entityType") String strEntityType, diff --git a/application/src/main/java/com/hashmapinc/server/controller/LoginController.java b/application/src/main/java/com/hashmapinc/server/controller/LoginController.java index 6db64a363..ce5d892c4 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/LoginController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/LoginController.java @@ -47,7 +47,7 @@ public class LoginController extends BaseController { @Qualifier("clientRestTemplate") OAuth2RestTemplate restTemplate; - @RequestMapping(value = "/auth/login", method = RequestMethod.POST) + @PostMapping(value = "/auth/login") @ResponseBody public LoginResponseToken loginUser(@RequestBody LoginRequest loginRequest) throws TempusException { try { @@ -69,7 +69,7 @@ public LoginResponseToken loginUser(@RequestBody LoginRequest loginRequest) thro } - @RequestMapping(value = "/auth/token", method = RequestMethod.POST) + @PostMapping(value = "/auth/token") @ResponseBody public LoginResponseToken refreshToken(@RequestBody RefreshTokenRequest refreshTokenRequest) throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/controller/NodeMetricController.java b/application/src/main/java/com/hashmapinc/server/controller/NodeMetricController.java index 474651419..cf4596c36 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/NodeMetricController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/NodeMetricController.java @@ -19,10 +19,7 @@ import com.hashmapinc.server.exception.TempusException; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -32,7 +29,7 @@ public class NodeMetricController extends BaseController { @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/nodes", method = RequestMethod.GET) + @GetMapping(value = "/nodes") @ResponseBody public List getNodeMetric() throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/controller/PluginController.java b/application/src/main/java/com/hashmapinc/server/controller/PluginController.java index 7149d2abf..b57a6fd95 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/PluginController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/PluginController.java @@ -39,7 +39,7 @@ public class PluginController extends BaseController { public static final String PLUGIN_ID = "pluginId"; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.GET) + @GetMapping(value = "/plugin/{pluginId}") @ResponseBody public PluginMetaData getPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws TempusException { checkParameter(PLUGIN_ID, strPluginId); @@ -52,7 +52,7 @@ public PluginMetaData getPluginById(@PathVariable(PLUGIN_ID) String strPluginId) } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin/token/{pluginToken}", method = RequestMethod.GET) + @GetMapping(value = "/plugin/token/{pluginToken}") @ResponseBody public PluginMetaData getPluginByToken(@PathVariable("pluginToken") String pluginToken) throws TempusException { checkParameter("pluginToken", pluginToken); @@ -64,7 +64,7 @@ public PluginMetaData getPluginByToken(@PathVariable("pluginToken") String plugi } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin", method = RequestMethod.POST) + @PostMapping(value = "/plugin") @ResponseBody public PluginMetaData savePlugin(@RequestBody PluginMetaData source) throws TempusException { try { @@ -89,7 +89,7 @@ public PluginMetaData savePlugin(@RequestBody PluginMetaData source) throws Temp } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin/{pluginId}/activate", method = RequestMethod.POST) + @PostMapping(value = "/plugin/{pluginId}/activate") @ResponseStatus(value = HttpStatus.OK) public void activatePluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws TempusException { checkParameter(PLUGIN_ID, strPluginId); @@ -115,7 +115,7 @@ public void activatePluginById(@PathVariable(PLUGIN_ID) String strPluginId) thro } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin/{pluginId}/suspend", method = RequestMethod.POST) + @PostMapping(value = "/plugin/{pluginId}/suspend") @ResponseStatus(value = HttpStatus.OK) public void suspendPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws TempusException { checkParameter(PLUGIN_ID, strPluginId); @@ -141,7 +141,7 @@ public void suspendPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throw } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/plugin/system", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/plugin/system", params = {"limit"}) @ResponseBody public TextPageData getSystemPlugins( @RequestParam int limit, @@ -157,7 +157,7 @@ public TextPageData getSystemPlugins( } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/plugin/tenant/{tenantId}", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/plugin/tenant/{tenantId}", params = {"limit"}) @ResponseBody public TextPageData getTenantPlugins( @PathVariable("tenantId") String strTenantId, @@ -176,7 +176,7 @@ public TextPageData getTenantPlugins( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugins", method = RequestMethod.GET) + @GetMapping(value = "/plugins") @ResponseBody public List getPlugins() throws TempusException { try { @@ -196,7 +196,7 @@ public List getPlugins() throws TempusException { } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/plugin", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/plugin", params = {"limit"}) @ResponseBody public TextPageData getTenantPlugins( @RequestParam int limit, @@ -213,7 +213,7 @@ public TextPageData getTenantPlugins( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/plugin/{pluginId}") @ResponseStatus(value = HttpStatus.OK) public void deletePlugin(@PathVariable(PLUGIN_ID) String strPluginId) throws TempusException { checkParameter(PLUGIN_ID, strPluginId); diff --git a/application/src/main/java/com/hashmapinc/server/controller/RuleController.java b/application/src/main/java/com/hashmapinc/server/controller/RuleController.java index 61ee596fb..4fcc7367c 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/RuleController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/RuleController.java @@ -39,7 +39,7 @@ public class RuleController extends BaseController { public static final String RULE_ID = "ruleId"; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule/{ruleId}", method = RequestMethod.GET) + @GetMapping(value = "/rule/{ruleId}") @ResponseBody public RuleMetaData getRuleById(@PathVariable(RULE_ID) String strRuleId) throws TempusException { checkParameter(RULE_ID, strRuleId); @@ -53,7 +53,7 @@ public RuleMetaData getRuleById(@PathVariable(RULE_ID) String strRuleId) throws @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule/token/{pluginToken}", method = RequestMethod.GET) + @GetMapping(value = "/rule/token/{pluginToken}") @ResponseBody public List getRulesByPluginToken(@PathVariable("pluginToken") String pluginToken) throws TempusException { checkParameter("pluginToken", pluginToken); @@ -66,7 +66,7 @@ public List getRulesByPluginToken(@PathVariable("pluginToken") Str } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule", method = RequestMethod.POST) + @PostMapping(value = "/rule") @ResponseBody public RuleMetaData saveRule(@RequestBody RuleMetaData source) throws TempusException { try { @@ -91,7 +91,7 @@ public RuleMetaData saveRule(@RequestBody RuleMetaData source) throws TempusExce } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule/{ruleId}/activate", method = RequestMethod.POST) + @PostMapping(value = "/rule/{ruleId}/activate") @ResponseStatus(value = HttpStatus.OK) public void activateRuleById(@PathVariable(RULE_ID) String strRuleId) throws TempusException { checkParameter(RULE_ID, strRuleId); @@ -117,7 +117,7 @@ public void activateRuleById(@PathVariable(RULE_ID) String strRuleId) throws Tem } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule/{ruleId}/suspend", method = RequestMethod.POST) + @PostMapping(value = "/rule/{ruleId}/suspend") @ResponseStatus(value = HttpStatus.OK) public void suspendRuleById(@PathVariable(RULE_ID) String strRuleId) throws TempusException { checkParameter(RULE_ID, strRuleId); @@ -143,7 +143,7 @@ public void suspendRuleById(@PathVariable(RULE_ID) String strRuleId) throws Temp } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/rule/system", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/rule/system", params = {"limit"}) @ResponseBody public TextPageData getSystemRules( @RequestParam int limit, @@ -159,7 +159,7 @@ public TextPageData getSystemRules( } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/rule/tenant/{tenantId}", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/rule/tenant/{tenantId}", params = {"limit"}) @ResponseBody public TextPageData getTenantRules( @PathVariable("tenantId") String strTenantId, @@ -178,7 +178,7 @@ public TextPageData getTenantRules( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rules", method = RequestMethod.GET) + @GetMapping(value = "/rules") @ResponseBody public List getRules() throws TempusException { try { @@ -194,7 +194,7 @@ public List getRules() throws TempusException { } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/rule", params = {"limit"}, method = RequestMethod.GET) + @GetMapping(value = "/rule", params = {"limit"}) @ResponseBody public TextPageData getTenantRules( @RequestParam int limit, @@ -211,7 +211,7 @@ public TextPageData getTenantRules( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/rule/{ruleId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/rule/{ruleId}") @ResponseStatus(value = HttpStatus.OK) public void deleteRule(@PathVariable(RULE_ID) String strRuleId) throws TempusException { checkParameter(RULE_ID, strRuleId); diff --git a/application/src/main/java/com/hashmapinc/server/controller/TenantController.java b/application/src/main/java/com/hashmapinc/server/controller/TenantController.java index c1f10eb43..796e65a79 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/TenantController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/TenantController.java @@ -34,7 +34,7 @@ public class TenantController extends BaseController { private TenantService tenantService; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/tenant/{tenantId}", method = RequestMethod.GET) + @GetMapping(value = "/tenant/{tenantId}") @ResponseBody public Tenant getTenantById(@PathVariable("tenantId") String strTenantId) throws TempusException { checkParameter("tenantId", strTenantId); @@ -48,7 +48,7 @@ public Tenant getTenantById(@PathVariable("tenantId") String strTenantId) throws } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/tenant", method = RequestMethod.POST) + @PostMapping(value = "/tenant") @ResponseBody public Tenant saveTenant(@RequestBody Tenant tenant) throws TempusException { try { @@ -59,7 +59,7 @@ public Tenant saveTenant(@RequestBody Tenant tenant) throws TempusException { } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/tenant/{tenantId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/tenant/{tenantId}") @ResponseStatus(value = HttpStatus.OK) public void deleteTenant(@PathVariable("tenantId") String strTenantId) throws TempusException { checkParameter("tenantId", strTenantId); @@ -72,7 +72,7 @@ public void deleteTenant(@PathVariable("tenantId") String strTenantId) throws Te } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/tenants", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/tenants", params = { "limit" }) @ResponseBody public TextPageData getTenants(@RequestParam int limit, @RequestParam(required = false) String textSearch, diff --git a/application/src/main/java/com/hashmapinc/server/controller/UserController.java b/application/src/main/java/com/hashmapinc/server/controller/UserController.java index 4cdc10f85..62f594078 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/UserController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/UserController.java @@ -17,19 +17,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.hashmapinc.server.requests.CreateUserRequest; -import com.hashmapinc.server.requests.IdentityUser; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; import com.hashmapinc.server.common.data.EntityType; import com.hashmapinc.server.common.data.User; import com.hashmapinc.server.common.data.audit.ActionType; @@ -42,8 +29,21 @@ import com.hashmapinc.server.common.data.security.UserCredentials; import com.hashmapinc.server.exception.TempusErrorCode; import com.hashmapinc.server.exception.TempusException; +import com.hashmapinc.server.requests.CreateUserRequest; +import com.hashmapinc.server.requests.IdentityUser; import com.hashmapinc.server.service.mail.MailService; import com.hashmapinc.server.service.security.model.SecurityUser; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.servlet.http.HttpServletRequest; @@ -68,7 +68,7 @@ public class UserController extends BaseController { private RestTemplate restTemplate; @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/user/{userId}", method = RequestMethod.GET) + @GetMapping(value = "/user/{userId}") @ResponseBody public User getUserById(@PathVariable(USER_ID) String strUserId) throws TempusException { checkParameter(USER_ID, strUserId); @@ -86,7 +86,7 @@ public User getUserById(@PathVariable(USER_ID) String strUserId) throws TempusEx } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/user", method = RequestMethod.POST) + @PostMapping(value = "/user") @ResponseBody public User saveUser(@RequestBody User user, @RequestParam String activationType, @@ -166,7 +166,7 @@ private User createUser(@RequestBody User user, @RequestParam String activationT } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/user/sendActivationMail", method = RequestMethod.POST) + @PostMapping(value = "/user/sendActivationMail") @ResponseStatus(value = HttpStatus.OK) public void sendActivationEmail( @RequestParam(value = "email") String email, @@ -188,7 +188,7 @@ public void sendActivationEmail( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/user/{userId}/activationLink", method = RequestMethod.GET, produces = "text/plain") + @GetMapping(value = "/user/{userId}/activationLink") @ResponseBody public String getActivationLink( @PathVariable(USER_ID) String strUserId, @@ -225,7 +225,7 @@ public String getActivationLink( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/user/{userId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/user/{userId}") @ResponseStatus(value = HttpStatus.OK) public void deleteUser(@PathVariable(USER_ID) String strUserId) throws TempusException { checkParameter(USER_ID, strUserId); @@ -248,7 +248,7 @@ public void deleteUser(@PathVariable(USER_ID) String strUserId) throws TempusExc } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/tenant/{tenantId}/users", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/tenant/{tenantId}/users", params = { "limit" }) @ResponseBody public TextPageData getTenantAdmins( @PathVariable("tenantId") String strTenantId, @@ -267,7 +267,7 @@ public TextPageData getTenantAdmins( } @PreAuthorize("hasAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/customer/{customerId}/users", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/customer/{customerId}/users", params = { "limit" }) @ResponseBody public TextPageData getCustomerUsers( @PathVariable("customerId") String strCustomerId, diff --git a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java index 56f31a2cf..a78b88270 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/UserSettingsController.java @@ -56,7 +56,7 @@ public class UserSettingsController extends BaseController { @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER', 'SYS_ADMIN')") - @RequestMapping(value = "/settings/{key}", method = RequestMethod.GET) + @GetMapping(value = "/settings/{key}") @ResponseBody public UserSettings getUserSettings(@PathVariable("key") String key) throws TempusException { try { @@ -68,7 +68,7 @@ public UserSettings getUserSettings(@PathVariable("key") String key) throws Temp } @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER', 'SYS_ADMIN')") - @RequestMapping(value = "/settings", method = RequestMethod.POST) + @PostMapping(value = "/settings") @ResponseBody public UserSettings saveUserSettings(@RequestBody UserSettings userSettings) throws TempusException { try { @@ -85,7 +85,7 @@ public UserSettings saveUserSettings(@RequestBody UserSettings userSettings) thr } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/settings/testMail", method = RequestMethod.POST) + @PostMapping(value = "/settings/testMail") public void sendTestMail(@RequestBody UserSettings userSettings) throws TempusException { try { userSettings = checkNotNull(userSettings); @@ -99,7 +99,7 @@ public void sendTestMail(@RequestBody UserSettings userSettings) throws TempusEx } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/settings/themes", method = RequestMethod.GET) + @GetMapping(value = "/settings/themes") public List getThemes() throws TempusException { try { return themeService.findAll(); @@ -110,7 +110,7 @@ public List getThemes() throws TempusException { - @RequestMapping(value = "/theming", method = RequestMethod.GET) + @GetMapping(value = "/theming") @ResponseStatus(value = HttpStatus.OK) public Theme getEnabledTheme() throws TempusException { try { @@ -121,7 +121,7 @@ public Theme getEnabledTheme() throws TempusException { } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/settings/theme", method = RequestMethod.POST) + @PostMapping(value = "/settings/theme") public Theme updateTheme(@RequestBody String value) throws TempusException { try { JsonObject request = new JsonParser().parse(value).getAsJsonObject(); @@ -132,7 +132,7 @@ public Theme updateTheme(@RequestBody String value) throws TempusException { } @PreAuthorize("hasAuthority('SYS_ADMIN')") - @RequestMapping(value = "/settings/uploadLogo", method = RequestMethod.POST) + @PostMapping(value = "/settings/uploadLogo") public Logo uploadLogo(@RequestParam("file") MultipartFile file) throws TempusException { try { @@ -147,7 +147,7 @@ public Logo uploadLogo(@RequestParam("file") MultipartFile file) throws TempusEx } } - @RequestMapping(value = "/logo", method = RequestMethod.GET) + @GetMapping(value = "/logo") @ResponseStatus(value = HttpStatus.OK) public Logo getLogo() throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/controller/WidgetTypeController.java b/application/src/main/java/com/hashmapinc/server/controller/WidgetTypeController.java index c00d0de88..b0b0d502e 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/WidgetTypeController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/WidgetTypeController.java @@ -32,7 +32,7 @@ public class WidgetTypeController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/widgetType/{widgetTypeId}", method = RequestMethod.GET) + @GetMapping(value = "/widgetType/{widgetTypeId}") @ResponseBody public WidgetType getWidgetTypeById(@PathVariable("widgetTypeId") String strWidgetTypeId) throws TempusException { checkParameter("widgetTypeId", strWidgetTypeId); @@ -45,7 +45,7 @@ public WidgetType getWidgetTypeById(@PathVariable("widgetTypeId") String strWidg } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/widgetType", method = RequestMethod.POST) + @PostMapping(value = "/widgetType") @ResponseBody public WidgetType saveWidgetType(@RequestBody WidgetType widgetType) throws TempusException { try { @@ -61,7 +61,7 @@ public WidgetType saveWidgetType(@RequestBody WidgetType widgetType) throws Temp } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/widgetType/{widgetTypeId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/widgetType/{widgetTypeId}") @ResponseStatus(value = HttpStatus.OK) public void deleteWidgetType(@PathVariable("widgetTypeId") String strWidgetTypeId) throws TempusException { checkParameter("widgetTypeId", strWidgetTypeId); @@ -75,7 +75,7 @@ public void deleteWidgetType(@PathVariable("widgetTypeId") String strWidgetTypeI } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/widgetTypes", params = { "isSystem", "bundleAlias"}, method = RequestMethod.GET) + @GetMapping(value = "/widgetTypes", params = { "isSystem", "bundleAlias"}) @ResponseBody public List getBundleWidgetTypes( @RequestParam boolean isSystem, @@ -94,7 +94,7 @@ public List getBundleWidgetTypes( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/widgetType", params = { "isSystem", "bundleAlias", "alias" }, method = RequestMethod.GET) + @GetMapping(value = "/widgetType", params = { "isSystem", "bundleAlias", "alias" }) @ResponseBody public WidgetType getWidgetType( @RequestParam boolean isSystem, diff --git a/application/src/main/java/com/hashmapinc/server/controller/WidgetsBundleController.java b/application/src/main/java/com/hashmapinc/server/controller/WidgetsBundleController.java index 71a9718eb..d20852e36 100644 --- a/application/src/main/java/com/hashmapinc/server/controller/WidgetsBundleController.java +++ b/application/src/main/java/com/hashmapinc/server/controller/WidgetsBundleController.java @@ -34,7 +34,7 @@ public class WidgetsBundleController extends BaseController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/widgetsBundle/{widgetsBundleId}", method = RequestMethod.GET) + @GetMapping(value = "/widgetsBundle/{widgetsBundleId}") @ResponseBody public WidgetsBundle getWidgetsBundleById(@PathVariable("widgetsBundleId") String strWidgetsBundleId) throws TempusException { checkParameter("widgetsBundleId", strWidgetsBundleId); @@ -47,7 +47,7 @@ public WidgetsBundle getWidgetsBundleById(@PathVariable("widgetsBundleId") Strin } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/widgetsBundle", method = RequestMethod.POST) + @PostMapping(value = "/widgetsBundle") @ResponseBody public WidgetsBundle saveWidgetsBundle(@RequestBody WidgetsBundle widgetsBundle) throws TempusException { try { @@ -63,7 +63,7 @@ public WidgetsBundle saveWidgetsBundle(@RequestBody WidgetsBundle widgetsBundle) } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") - @RequestMapping(value = "/widgetsBundle/{widgetsBundleId}", method = RequestMethod.DELETE) + @DeleteMapping(value = "/widgetsBundle/{widgetsBundleId}") @ResponseStatus(value = HttpStatus.OK) public void deleteWidgetsBundle(@PathVariable("widgetsBundleId") String strWidgetsBundleId) throws TempusException { checkParameter("widgetsBundleId", strWidgetsBundleId); @@ -77,7 +77,7 @@ public void deleteWidgetsBundle(@PathVariable("widgetsBundleId") String strWidge } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/widgetsBundles", params = { "limit" }, method = RequestMethod.GET) + @GetMapping(value = "/widgetsBundles", params = { "limit" }) @ResponseBody public TextPageData getWidgetsBundles( @RequestParam int limit, @@ -98,7 +98,7 @@ public TextPageData getWidgetsBundles( } @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") - @RequestMapping(value = "/widgetsBundles", method = RequestMethod.GET) + @GetMapping(value = "/widgetsBundles") @ResponseBody public List getWidgetsBundles() throws TempusException { try { diff --git a/application/src/main/java/com/hashmapinc/server/service/cluster/rpc/GrpcSession.java b/application/src/main/java/com/hashmapinc/server/service/cluster/rpc/GrpcSession.java index f6ac3da39..751795383 100644 --- a/application/src/main/java/com/hashmapinc/server/service/cluster/rpc/GrpcSession.java +++ b/application/src/main/java/com/hashmapinc/server/service/cluster/rpc/GrpcSession.java @@ -15,11 +15,11 @@ */ package com.hashmapinc.server.service.cluster.rpc; +import com.hashmapinc.server.common.msg.cluster.ServerAddress; import com.hashmapinc.server.gen.cluster.ClusterAPIProtos; import io.grpc.stub.StreamObserver; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import com.hashmapinc.server.common.msg.cluster.ServerAddress; import java.io.Closeable; import java.util.UUID; @@ -31,7 +31,7 @@ public final class GrpcSession implements Closeable { private final UUID sessionId; private final boolean client; private final GrpcSessionListener listener; - private StreamObserver inputStream; + private StreamObserver inputStream; // NOSONAR private StreamObserver outputStream; private boolean connected; diff --git a/application/src/main/java/com/hashmapinc/server/service/security/auth/jwt/extractor/UserInfoTokenConverter.java b/application/src/main/java/com/hashmapinc/server/service/security/auth/jwt/extractor/UserInfoTokenConverter.java index 76706783e..a4021f0f7 100644 --- a/application/src/main/java/com/hashmapinc/server/service/security/auth/jwt/extractor/UserInfoTokenConverter.java +++ b/application/src/main/java/com/hashmapinc/server/service/security/auth/jwt/extractor/UserInfoTokenConverter.java @@ -75,7 +75,7 @@ public Authentication extractAuthentication(Map map) { if(!StringUtils.isEmpty(customerId)){ securityUser.setCustomerId(new CustomerId(UUID.fromString((String)customerId))); } - securityUser.setEnabled(enabled != null ? (Boolean)enabled: false); + securityUser.setEnabled(enabled != null && (Boolean)enabled); securityUser.setFirstName(extractNullable("firstName", map)); securityUser.setLastName(extractNullable("lastName", map)); Object authorities = map.get("authorities"); diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/UserPermission.java b/common/data/src/main/java/com/hashmapinc/server/common/data/UserPermission.java index 19d5996ca..970c9f66c 100644 --- a/common/data/src/main/java/com/hashmapinc/server/common/data/UserPermission.java +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/UserPermission.java @@ -29,9 +29,9 @@ public class UserPermission { private String permissionExpr; - private Authority subject; - private Collection resources; - private Collection userActions; + private Authority subject; //NOSONAR + private Collection resources; //NOSONAR + private Collection userActions; //NOSONAR public UserPermission(UserPermission permission){ this(permission.permissionExpr); diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/computation/Computations.java b/common/data/src/main/java/com/hashmapinc/server/common/data/computation/Computations.java index 7145a67c1..48cf0569f 100644 --- a/common/data/src/main/java/com/hashmapinc/server/common/data/computation/Computations.java +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/computation/Computations.java @@ -16,9 +16,9 @@ package com.hashmapinc.server.common.data.computation; import com.fasterxml.jackson.databind.JsonNode; +import com.hashmapinc.server.common.data.HasName; import com.hashmapinc.server.common.data.SearchTextBased; import com.hashmapinc.server.common.data.id.ComputationId; -import com.hashmapinc.server.common.data.HasName; import com.hashmapinc.server.common.data.id.TenantId; public class Computations extends SearchTextBased implements HasName { @@ -53,16 +53,12 @@ public Computations(Computations computations) { } @Override - public boolean equals(Object o) { + public boolean equals(Object o) { // NOSONAR if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - return checkObjEquality((Computations) o); - } - - private boolean checkObjEquality(Computations o) { - Computations that = o; + Computations that = (Computations) o; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (jarPath != null ? !jarPath.equals(that.jarPath) : that.jarPath != null) return false; if (jarName != null ? !jarName.equals(that.jarName) : that.jarName != null) return false; diff --git a/common/data/src/main/java/com/hashmapinc/server/common/data/datamodel/DataModelObject.java b/common/data/src/main/java/com/hashmapinc/server/common/data/datamodel/DataModelObject.java index 01a591ca3..72d754508 100644 --- a/common/data/src/main/java/com/hashmapinc/server/common/data/datamodel/DataModelObject.java +++ b/common/data/src/main/java/com/hashmapinc/server/common/data/datamodel/DataModelObject.java @@ -52,16 +52,12 @@ public DataModelObject(DataModelObject dataModelObject) { } @Override - public boolean equals(Object o) { + public boolean equals(Object o) { //NOSONAR if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - return checkObjEquality((DataModelObject) o); - } - - private boolean checkObjEquality(DataModelObject o) { - DataModelObject that = o; + DataModelObject that = (DataModelObject) o; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (dataModelId != null ? !dataModelId.equals(that.dataModelId) : that.dataModelId != null) return false; diff --git a/common/transport/src/main/java/com/hashmapinc/server/common/transport/adaptor/JsonConverter.java b/common/transport/src/main/java/com/hashmapinc/server/common/transport/adaptor/JsonConverter.java index d638eb1a4..277815117 100644 --- a/common/transport/src/main/java/com/hashmapinc/server/common/transport/adaptor/JsonConverter.java +++ b/common/transport/src/main/java/com/hashmapinc/server/common/transport/adaptor/JsonConverter.java @@ -41,11 +41,11 @@ public class JsonConverter { private JsonConverter() {} - public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject) throws JsonSyntaxException { + public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject) { return convertToTelemetry(jsonObject, BasicRequest.DEFAULT_REQUEST_ID); } - public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, int requestId) throws JsonSyntaxException { + public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, int requestId) { BasicTelemetryUploadRequest request = new BasicTelemetryUploadRequest(requestId); long systemTs = System.currentTimeMillis(); if (jsonObject.isJsonObject()) { @@ -65,7 +65,7 @@ public static TelemetryUploadRequest convertToTelemetry(JsonElement jsonObject, } // test telemetry depth. - public static DepthTelemetryUploadRequest convertToTelemetryDepth(JsonElement jsonObject, int requestId) throws JsonSyntaxException { + public static DepthTelemetryUploadRequest convertToTelemetryDepth(JsonElement jsonObject, int requestId) { BasicDepthTelemetryUploadRequest request = new BasicDepthTelemetryUploadRequest(requestId); if (jsonObject.isJsonObject()) { parseObject(request, jsonObject); @@ -84,7 +84,7 @@ else if (jsonObject.isJsonArray()) { return request; } - public static ToServerRpcRequestMsg convertToServerRpcRequest(JsonElement json, int requestId) throws JsonSyntaxException { + public static ToServerRpcRequestMsg convertToServerRpcRequest(JsonElement json, int requestId) { JsonObject object = json.getAsJsonObject(); return new ToServerRpcRequestMsg(requestId, object.get("method").getAsString(), GSON.toJson(object.get("params"))); } diff --git a/common/transport/src/test/java/com/hashmapinc/server/common/transport/quota/inmemory/HostRequestIntervalRegistryTest.java b/common/transport/src/test/java/com/hashmapinc/server/common/transport/quota/inmemory/HostRequestIntervalRegistryTest.java index e843b6f44..e9ac0b820 100644 --- a/common/transport/src/test/java/com/hashmapinc/server/common/transport/quota/inmemory/HostRequestIntervalRegistryTest.java +++ b/common/transport/src/test/java/com/hashmapinc/server/common/transport/quota/inmemory/HostRequestIntervalRegistryTest.java @@ -45,7 +45,7 @@ public void existingHostUpdated() { @Test public void expiredIntervalsCleaned() throws InterruptedException { registry.tick("aaa"); - Thread.sleep(150L); + Thread.sleep(150L); //NOSONAR registry.tick("bbb"); registry.clean(); assertEquals(1L, registry.tick("aaa")); diff --git a/dao/src/main/java/com/hashmapinc/server/dao/audit/CassandraAuditLogDao.java b/dao/src/main/java/com/hashmapinc/server/dao/audit/CassandraAuditLogDao.java index c56b8c511..dc7492bdd 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/audit/CassandraAuditLogDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/audit/CassandraAuditLogDao.java @@ -126,7 +126,7 @@ public ListenableFuture saveByTenantId(AuditLog auditLog) { long partition = toPartitionTs(LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()); BoundStatement stmt = getSaveByTenantStmt().bind(); - stmt = setSaveStmtVariables(stmt, auditLog, partition); + setSaveStmtVariables(stmt, auditLog, partition); return getFuture(executeAsyncWrite(stmt), rs -> null); } @@ -135,7 +135,7 @@ public ListenableFuture saveByTenantIdAndEntityId(AuditLog auditLog) { log.debug("Save saveByTenantIdAndEntityId [{}] ", auditLog); BoundStatement stmt = getSaveByTenantIdAndEntityIdStmt().bind(); - stmt = setSaveStmtVariables(stmt, auditLog, -1); + setSaveStmtVariables(stmt, auditLog, -1); return getFuture(executeAsyncWrite(stmt), rs -> null); } @@ -144,7 +144,7 @@ public ListenableFuture saveByTenantIdAndCustomerId(AuditLog auditLog) { log.debug("Save saveByTenantIdAndCustomerId [{}] ", auditLog); BoundStatement stmt = getSaveByTenantIdAndCustomerIdStmt().bind(); - stmt = setSaveStmtVariables(stmt, auditLog, -1); + setSaveStmtVariables(stmt, auditLog, -1); return getFuture(executeAsyncWrite(stmt), rs -> null); } @@ -153,7 +153,7 @@ public ListenableFuture saveByTenantIdAndUserId(AuditLog auditLog) { log.debug("Save saveByTenantIdAndUserId [{}] ", auditLog); BoundStatement stmt = getSaveByTenantIdAndUserIdStmt().bind(); - stmt = setSaveStmtVariables(stmt, auditLog, -1); + setSaveStmtVariables(stmt, auditLog, -1); return getFuture(executeAsyncWrite(stmt), rs -> null); } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraQueryOptions.java b/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraQueryOptions.java index e52a218fd..53c562737 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraQueryOptions.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraQueryOptions.java @@ -38,7 +38,7 @@ public class CassandraQueryOptions { @Value("${cassandra.query.write_consistency_level}") private String writeConsistencyLevel; - private QueryOptions opts; + private QueryOptions opts; //NOSONAR private ConsistencyLevel defaultReadConsistencyLevel; private ConsistencyLevel defaultWriteConsistencyLevel; diff --git a/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraSocketOptions.java b/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraSocketOptions.java index 5ffd416d2..494bca8e4 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraSocketOptions.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/cassandra/CassandraSocketOptions.java @@ -47,7 +47,7 @@ public class CassandraSocketOptions { @Value("${cassandra.socket.send_buffer_size}") private Integer sendBufferSize; - private SocketOptions opts; + private SocketOptions opts; //NOSONAR @PostConstruct public void initOpts() { diff --git a/dao/src/main/java/com/hashmapinc/server/dao/depthseries/AggregatePartitionsFunction.java b/dao/src/main/java/com/hashmapinc/server/dao/depthseries/AggregatePartitionsFunction.java index ea699c715..2bc371ef5 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/depthseries/AggregatePartitionsFunction.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/depthseries/AggregatePartitionsFunction.java @@ -138,7 +138,7 @@ private void processMaxAggregation(AggregationResult aggResult, Long curLValue, if (aggResult.sValue == null || curSValue.compareTo(aggResult.sValue) > 0) { aggResult.sValue = curSValue; } - } else if (curJValue != null && (aggResult.jValue == null || curJValue.toString().compareTo(aggResult.jValue.toString()) > 0)) { + } else if (curJValue != null) { aggResult.jValue = curJValue; } } @@ -154,7 +154,7 @@ private void processMinAggregation(AggregationResult aggResult, Long curLValue, if (aggResult.sValue == null || curSValue.compareTo(aggResult.sValue) < 0) { aggResult.sValue = curSValue; } - } else if (curJValue != null && (aggResult.jValue == null || curJValue.toString().compareTo(aggResult.jValue.toString()) < 0)) { + } else if (curJValue != null) { aggResult.jValue = curJValue; } } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/depthseries/CassandraBaseDepthSeriesDao.java b/dao/src/main/java/com/hashmapinc/server/dao/depthseries/CassandraBaseDepthSeriesDao.java index e714b3bf6..940a72f02 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/depthseries/CassandraBaseDepthSeriesDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/depthseries/CassandraBaseDepthSeriesDao.java @@ -30,13 +30,12 @@ import com.hashmapinc.server.common.msg.exception.TempusRuntimeException; import com.hashmapinc.server.dao.model.ModelConstants; import com.hashmapinc.server.dao.nosql.CassandraAbstractAsyncDao; -import com.hashmapinc.server.dao.timeseries.TsPartitionDate; +import com.hashmapinc.server.dao.timeseries.SimpleListenableFuture; import com.hashmapinc.server.dao.util.NoSqlDao; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import com.hashmapinc.server.dao.timeseries.SimpleListenableFuture; import javax.annotation.Nullable; import javax.annotation.PostConstruct; @@ -54,14 +53,13 @@ public class CassandraBaseDepthSeriesDao extends CassandraAbstractAsyncDao imple private static final Double MIN_AGGREGATION_STEP_MS = 0.1; public static final String INSERT_INTO = "INSERT INTO "; public static final String SELECT = "SELECT "; + private static final String EQUAL_PLACEHOLDER = " = ? "; public static final String GENERATED_QUERY_FOR_ENTITY_TYPE_AND_ENTITY_ID = "Generated query [{}] for entityType {} and entityId {}"; @Autowired private Environment environment; - private TsPartitionDate tsFormat; - private PreparedStatement partitionInsertStmt; private PreparedStatement partitionInsertTtlStmt; private PreparedStatement[] latestInsertStmts; @@ -80,7 +78,6 @@ public void init() { super.startExecutor(); if (!isInstall()) { getFetchStmt(DepthAggregation.NONE); - log.debug("HMDC inside init. "); } } @@ -410,34 +407,23 @@ private DsKvEntry convertResultToDsKvEntryForLatest(Row row) { } public static KvEntry toKvEntry(Row row, String key) { - KvEntry kvEntry = null; - String strV = row.get(ModelConstants.STRING_VALUE_COLUMN, String.class); - if (strV != null) { - kvEntry = new StringDataEntry(key, strV); - } else { - Long longV = row.get(ModelConstants.LONG_VALUE_COLUMN, Long.class); - if (longV != null) { - kvEntry = new LongDataEntry(key, longV); - } else { - Double doubleV = row.get(ModelConstants.DOUBLE_VALUE_COLUMN, Double.class); - if (doubleV != null) { - kvEntry = new DoubleDataEntry(key, doubleV); - } else { - Boolean boolV = row.get(ModelConstants.BOOLEAN_VALUE_COLUMN, Boolean.class); - if (boolV != null) { - kvEntry = new BooleanDataEntry(key, boolV); - } else { - JsonNode jsonV = row.get(ModelConstants.JSON_VALUE_COLUMN, JsonNode.class); - if (jsonV != null) { - kvEntry = new JsonDataEntry(key, jsonV); - } else { - log.warn("All values in key-value row are nullable "); - } - } - } - } + if (row.get(ModelConstants.STRING_VALUE_COLUMN, String.class) != null) { + return new StringDataEntry(key, row.get(ModelConstants.STRING_VALUE_COLUMN, String.class)); + } + if (row.get(ModelConstants.LONG_VALUE_COLUMN, Long.class) != null) { + return new LongDataEntry(key, row.get(ModelConstants.LONG_VALUE_COLUMN, Long.class)); + } + if (row.get(ModelConstants.DOUBLE_VALUE_COLUMN, Double.class) != null) { + return new DoubleDataEntry(key, row.get(ModelConstants.DOUBLE_VALUE_COLUMN, Double.class)); + } + if (row.get(ModelConstants.BOOLEAN_VALUE_COLUMN, Boolean.class) != null) { + return new BooleanDataEntry(key, row.get(ModelConstants.BOOLEAN_VALUE_COLUMN, Boolean.class)); + } + if (row.get(ModelConstants.JSON_VALUE_COLUMN, JsonNode.class) != null) { + return new JsonDataEntry(key, row.get(ModelConstants.JSON_VALUE_COLUMN, JsonNode.class)); } - return kvEntry; + log.warn("All values in key-value row are nullable "); + return null; } /** @@ -499,17 +485,16 @@ private PreparedStatement getFetchStmt(DepthAggregation aggType) { } else { fetchStmts[type.ordinal()] = getSession().prepare(SELECT + String.join(", ", ModelConstants.getFetchColumnNames(type)) + " FROM " + ModelConstants.DS_KV_CF - + " WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + " = ? " - + "AND " + ModelConstants.ENTITY_ID_COLUMN + " = ? " - + "AND " + ModelConstants.KEY_COLUMN + " = ? " - + "AND " + ModelConstants.PARTITION_COLUMN + " = ? " + + " WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.ENTITY_ID_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.KEY_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.PARTITION_COLUMN + EQUAL_PLACEHOLDER + "AND " + ModelConstants.DS_COLUMN + " > ? " + "AND " + ModelConstants.DS_COLUMN + " <= ?" + (type == DepthAggregation.NONE ? " ORDER BY " + ModelConstants.DS_COLUMN + " DESC LIMIT ?" : "")); } } } - log.debug("HMDC Out of fetch null "); return fetchStmts[aggType.ordinal()]; } @@ -566,9 +551,9 @@ private PreparedStatement getFindLatestStmt() { ModelConstants.DOUBLE_VALUE_COLUMN + "," + ModelConstants.JSON_VALUE_COLUMN + " " + "FROM " + ModelConstants.DS_KV_LATEST_CF + " " + - "WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + " = ? " + - "AND " + ModelConstants.ENTITY_ID_COLUMN + " = ? " + - "AND " + ModelConstants.KEY_COLUMN + " = ? "); + "WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.ENTITY_ID_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.KEY_COLUMN + EQUAL_PLACEHOLDER); } return findLatestStmt; } @@ -584,8 +569,8 @@ private PreparedStatement getFindAllLatestStmt() { ModelConstants.DOUBLE_VALUE_COLUMN + "," + ModelConstants.JSON_VALUE_COLUMN + " " + "FROM " + ModelConstants.DS_KV_LATEST_CF + " " + - "WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + " = ? " + - "AND " + ModelConstants.ENTITY_ID_COLUMN + " = ? "); + "WHERE " + ModelConstants.ENTITY_TYPE_COLUMN + EQUAL_PLACEHOLDER + + "AND " + ModelConstants.ENTITY_ID_COLUMN + EQUAL_PLACEHOLDER); } return findAllLatestStmt; } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationJobEntity.java b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationJobEntity.java index 55d46bbde..8e898021d 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationJobEntity.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationJobEntity.java @@ -16,7 +16,10 @@ package com.hashmapinc.server.dao.model.nosql; import com.datastax.driver.core.utils.UUIDs; -import com.datastax.driver.mapping.annotations.*; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import com.datastax.driver.mapping.annotations.Transient; import com.fasterxml.jackson.databind.JsonNode; import com.hashmapinc.server.common.data.computation.ComputationJob; import com.hashmapinc.server.common.data.id.ComputationId; @@ -30,7 +33,7 @@ import java.util.UUID; -import static com.hashmapinc.server.dao.model.ModelConstants.*; +import static com.hashmapinc.server.dao.model.ModelConstants.ID_PROPERTY; @Table(name = ModelConstants.COMPUTATION_JOB_COLUMN_FAMILY_NAME) public class ComputationJobEntity implements SearchTextEntity { @Transient @@ -102,24 +105,18 @@ public void setSearchText(String searchText) { } @Override - public boolean equals(Object o) { + public boolean equals(Object o) { // NOSONAR if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - return checkObjEquality((ComputationJobEntity) o); - } - - private boolean checkObjEquality(ComputationJobEntity o) { - ComputationJobEntity that = o; + ComputationJobEntity that = (ComputationJobEntity) o; if (jobName != null ? !jobName.equals(that.jobName) : that.jobName != null) return false; if (searchText != null ? !searchText.equals(that.searchText) : that.searchText != null) return false; if (argParameters != null ? !argParameters.equals(that.argParameters) : that.argParameters != null) return false; if (computationId != null ? !computationId.equals(that.computationId) : that.computationId != null) return false; if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false; - if (jobId != null ? !jobId.equals(that.jobId) : that.jobId != null) return false; - - return true; + return jobId != null ? jobId.equals(that.jobId) : that.jobId == null; } @Override diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationsEntity.java b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationsEntity.java index 81b52197b..17116002e 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationsEntity.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/nosql/ComputationsEntity.java @@ -27,7 +27,7 @@ import java.util.UUID; -import static com.hashmapinc.server.dao.model.ModelConstants.*; +import static com.hashmapinc.server.dao.model.ModelConstants.ID_PROPERTY; @Table(name = ModelConstants.COMPUTATIONS_COLUMN_FAMILY_NAME) public class ComputationsEntity implements SearchTextEntity { @@ -68,7 +68,7 @@ public class ComputationsEntity implements SearchTextEntity { @Override public String getSearchTextSource() { - return name; + return getName(); } public ComputationsEntity() { @@ -189,16 +189,12 @@ public void setArgsType(String argsType) { } @Override - public boolean equals(Object o) { + public boolean equals(Object o) { //NOSONAR if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - return checkObjEquality((ComputationsEntity) o); - } - - private boolean checkObjEquality(ComputationsEntity o) { - ComputationsEntity that = o; + ComputationsEntity that = (ComputationsEntity) o; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (searchText != null ? !searchText.equals(that.searchText) : that.searchText != null) return false; if (jarPath != null ? !jarPath.equals(that.jarPath) : that.jarPath != null) return false; @@ -208,9 +204,7 @@ private boolean checkObjEquality(ComputationsEntity o) { if (jsonDescriptor != null ? !jsonDescriptor.equals(that.jsonDescriptor) : that.jsonDescriptor != null) return false; if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false; if (argsFormat != null ? !argsFormat.equals(that.argsFormat) : that.argsFormat != null) return false; - if (argsType != null ? !argsType.equals(that.argsType) : that.argsType != null) return false; - - return true; + return argsType != null ? argsType.equals(that.argsType) : that.argsType == null; } @Override diff --git a/dao/src/main/java/com/hashmapinc/server/dao/model/sql/ComputationsEntity.java b/dao/src/main/java/com/hashmapinc/server/dao/model/sql/ComputationsEntity.java index e161c50cd..1e81854ec 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/model/sql/ComputationsEntity.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/model/sql/ComputationsEntity.java @@ -21,13 +21,13 @@ import com.hashmapinc.server.common.data.id.ComputationId; import com.hashmapinc.server.common.data.id.TenantId; import com.hashmapinc.server.dao.model.BaseSqlEntity; +import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.dao.model.SearchTextEntity; import com.hashmapinc.server.dao.util.mapping.JsonStringType; import lombok.Data; import lombok.EqualsAndHashCode; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; -import com.hashmapinc.server.dao.model.ModelConstants; -import com.hashmapinc.server.dao.model.SearchTextEntity; import javax.persistence.Column; import javax.persistence.Entity; @@ -119,16 +119,12 @@ public void setSearchText(String searchText) { } @Override - public boolean equals(Object o) { + public boolean equals(Object o) { // NOSONAR if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - return checkObjEquality((ComputationsEntity) o); - } - - private boolean checkObjEquality(ComputationsEntity o) { - ComputationsEntity that = o; + ComputationsEntity that = (ComputationsEntity) o; if (name != null ? !name.equals(that.name) : that.name != null) return false; if (searchText != null ? !searchText.equals(that.searchText) : that.searchText != null) return false; if (jarPath != null ? !jarPath.equals(that.jarPath) : that.jarPath != null) return false; @@ -138,9 +134,7 @@ private boolean checkObjEquality(ComputationsEntity o) { if (jsonDescriptor != null ? !jsonDescriptor.equals(that.jsonDescriptor) : that.jsonDescriptor != null) return false; if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false; if (argsFormat != null ? !argsFormat.equals(that.argsFormat) : that.argsFormat != null) return false; - if (argsType != null ? !argsType.equals(that.argsType) : that.argsType != null) return false; - - return true; + return argsType != null ? argsType.equals(that.argsType) : that.argsType == null; } @Override diff --git a/dao/src/main/java/com/hashmapinc/server/dao/relation/BaseRelationDao.java b/dao/src/main/java/com/hashmapinc/server/dao/relation/BaseRelationDao.java index 0a3d963a2..5cfe3d407 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/relation/BaseRelationDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/relation/BaseRelationDao.java @@ -125,7 +125,7 @@ public ListenableFuture checkRelation(EntityId from, EntityId to, Strin .setString(3, to.getEntityType().name()) .set(4, typeGroup, relationTypeGroupCodec) .setString(5, relationType); - return getFuture(executeAsyncRead(stmt), rs -> rs != null ? rs.one() != null : false); + return getFuture(executeAsyncRead(stmt), rs -> rs != null && rs.one() != null); } @Override @@ -347,7 +347,7 @@ private ListenableFuture> executeAsyncRead(EntityId from, B } private ListenableFuture getBooleanListenableFuture(ResultSetFuture rsFuture) { - return getFuture(rsFuture, rs -> rs != null ? rs.wasApplied() : false); + return getFuture(rsFuture, rs -> rs != null && rs.wasApplied()); } private List getEntityRelations(ResultSet rs) { diff --git a/dao/src/main/java/com/hashmapinc/server/dao/timeseries/AggregatePartitionsFunction.java b/dao/src/main/java/com/hashmapinc/server/dao/timeseries/AggregatePartitionsFunction.java index ae40b9815..90c83fa1f 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/timeseries/AggregatePartitionsFunction.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/timeseries/AggregatePartitionsFunction.java @@ -145,7 +145,7 @@ private void processMinAggregation(AggregationResult aggResult, Long curLValue, aggResult.bValue = aggResult.bValue == null ? curBValue : aggResult.bValue && curBValue; } else if (curSValue != null && (aggResult.sValue == null || curSValue.compareTo(aggResult.sValue) < 0)) { aggResult.sValue = curSValue; - } else if (curJValue != null && (aggResult.jValue == null || curJValue.toString().compareTo(aggResult.jValue.toString()) < 0)) { + } else if (curJValue != null) { aggResult.jValue = curJValue; } } @@ -159,7 +159,7 @@ private void processMaxAggregation(AggregationResult aggResult, Long curLValue, aggResult.bValue = aggResult.bValue == null ? curBValue : aggResult.bValue || curBValue; } else if (curSValue != null && (aggResult.sValue == null || curSValue.compareTo(aggResult.sValue) > 0)) { aggResult.sValue = curSValue; - } else if (curJValue != null && (aggResult.jValue == null || curJValue.toString().compareTo(aggResult.jValue.toString()) > 0)) { + } else if (curJValue != null) { aggResult.jValue = curJValue; } } diff --git a/dao/src/main/java/com/hashmapinc/server/dao/timeseries/CassandraBaseTimeseriesDao.java b/dao/src/main/java/com/hashmapinc/server/dao/timeseries/CassandraBaseTimeseriesDao.java index 5c8a1c3ca..a630b06ff 100644 --- a/dao/src/main/java/com/hashmapinc/server/dao/timeseries/CassandraBaseTimeseriesDao.java +++ b/dao/src/main/java/com/hashmapinc/server/dao/timeseries/CassandraBaseTimeseriesDao.java @@ -25,18 +25,18 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.hashmapinc.server.common.data.DeviceDataSet; +import com.hashmapinc.server.common.data.id.EntityId; import com.hashmapinc.server.common.data.kv.*; import com.hashmapinc.server.common.data.kv.DataType; import com.hashmapinc.server.common.msg.exception.TempusRuntimeException; +import com.hashmapinc.server.dao.model.ModelConstants; +import com.hashmapinc.server.dao.nosql.CassandraAbstractAsyncDao; +import com.hashmapinc.server.dao.util.NoSqlDao; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import com.hashmapinc.server.common.data.id.EntityId; -import com.hashmapinc.server.dao.model.ModelConstants; -import com.hashmapinc.server.dao.nosql.CassandraAbstractAsyncDao; -import com.hashmapinc.server.dao.util.NoSqlDao; import javax.annotation.Nullable; import javax.annotation.PostConstruct; @@ -45,10 +45,6 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; @@ -419,34 +415,23 @@ private TsKvEntry convertResultToTsKvEntryForLatest(Row row) { } public static KvEntry toKvEntry(Row row, String key) { - KvEntry kvEntry = null; - String strV = row.get(STRING_VALUE_COLUMN, String.class); - if (strV != null) { - kvEntry = new StringDataEntry(key, strV); - } else { - Long longV = row.get(LONG_VALUE_COLUMN, Long.class); - if (longV != null) { - kvEntry = new LongDataEntry(key, longV); - } else { - Double doubleV = row.get(DOUBLE_VALUE_COLUMN, Double.class); - if (doubleV != null) { - kvEntry = new DoubleDataEntry(key, doubleV); - } else { - Boolean boolV = row.get(BOOLEAN_VALUE_COLUMN, Boolean.class); - if (boolV != null) { - kvEntry = new BooleanDataEntry(key, boolV); - } else { - JsonNode jsonV = row.get(JSON_VALUE_COLUMN, JsonNode.class); - if (jsonV != null) { - kvEntry = new JsonDataEntry(key, jsonV); - } else { - log.warn("All values in key-value row are nullable "); - } - } - } - } + if (row.get(STRING_VALUE_COLUMN, String.class) != null) { + return new StringDataEntry(key, row.get(STRING_VALUE_COLUMN, String.class)); + } + if (row.get(LONG_VALUE_COLUMN, Long.class) != null) { + return new LongDataEntry(key, row.get(LONG_VALUE_COLUMN, Long.class)); + } + if (row.get(DOUBLE_VALUE_COLUMN, Double.class) != null) { + return new DoubleDataEntry(key, row.get(DOUBLE_VALUE_COLUMN, Double.class)); + } + if (row.get(BOOLEAN_VALUE_COLUMN, Boolean.class) != null) { + return new BooleanDataEntry(key, row.get(BOOLEAN_VALUE_COLUMN, Boolean.class)); + } + if (row.get(JSON_VALUE_COLUMN, JsonNode.class) != null) { + return new JsonDataEntry(key, row.get(JSON_VALUE_COLUMN, JsonNode.class)); } - return kvEntry; + log.warn("All values in key-value row are nullable "); + return null; } /** diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/BaseRelationServiceTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/BaseRelationServiceTest.java index 4079d86a0..11123d51f 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/service/BaseRelationServiceTest.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/BaseRelationServiceTest.java @@ -175,7 +175,7 @@ public void testFindTo() throws ExecutionException, InterruptedException { saveRelation(relationB2); // Data propagation to views is async - Thread.sleep(3000); + Thread.sleep(3000); //NOSONAR List relations = relationService.findByTo(childA, RelationTypeGroup.COMMON); Assert.assertEquals(2, relations.size()); diff --git a/dao/src/test/java/com/hashmapinc/server/dao/service/tagmetadata/BaseTagMetaDataServiceTest.java b/dao/src/test/java/com/hashmapinc/server/dao/service/tagmetadata/BaseTagMetaDataServiceTest.java index 59f1bc396..f001e0fbd 100644 --- a/dao/src/test/java/com/hashmapinc/server/dao/service/tagmetadata/BaseTagMetaDataServiceTest.java +++ b/dao/src/test/java/com/hashmapinc/server/dao/service/tagmetadata/BaseTagMetaDataServiceTest.java @@ -38,7 +38,7 @@ public void createTagMetaDataTest() throws Exception{ String key = "tag"; TagMetaData tagMetaData = createTagMetaData(key); tagMetaDataService.saveTagMetaData(tagMetaData); - Thread.sleep(2000); + Thread.sleep(2000); //NOSONAR TagMetaData result = tagMetaDataService.getTagMetaDataByEntityIdAndKey(deviceId, key).get(); assertNotNull(result); assertEquals(key, result.getKey()); @@ -58,7 +58,7 @@ public void getAllTagMetaDataByEntityIdTest() throws Exception{ tagMetaData = createTagMetaData(key); tagMetaDataService.saveTagMetaData(tagMetaData); - Thread.sleep(4000); + Thread.sleep(4000); //NOSONAR List tagMetaDataList = tagMetaDataService.getAllTagMetaDataByEntityId(deviceId).get(); assertNotNull(tagMetaDataList); diff --git a/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRestMsgHandler.java b/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRestMsgHandler.java index a109dc7dd..2555bc5b2 100644 --- a/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRestMsgHandler.java +++ b/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRestMsgHandler.java @@ -16,11 +16,11 @@ package com.hashmapinc.server.extensions.api.plugins.handlers; import com.fasterxml.jackson.databind.ObjectMapper; +import com.hashmapinc.server.extensions.api.plugins.PluginContext; +import com.hashmapinc.server.extensions.api.plugins.rest.PluginRestMsg; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpMethod; import org.springframework.web.HttpRequestMethodNotSupportedException; -import com.hashmapinc.server.extensions.api.plugins.PluginContext; -import com.hashmapinc.server.extensions.api.plugins.rest.PluginRestMsg; import javax.servlet.ServletException; @@ -55,15 +55,15 @@ public void process(PluginContext ctx, PluginRestMsg msg) { } } - protected void handleHttpGetRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { + protected void handleHttpGetRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { //NOSONAR msg.getResponseHolder().setErrorResult(new HttpRequestMethodNotSupportedException(HttpMethod.GET.name())); } - protected void handleHttpPostRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { + protected void handleHttpPostRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { //NOSONAR msg.getResponseHolder().setErrorResult(new HttpRequestMethodNotSupportedException(HttpMethod.POST.name())); } - protected void handleHttpDeleteRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { + protected void handleHttpDeleteRequest(PluginContext ctx, PluginRestMsg msg) throws ServletException { //NOSONAR msg.getResponseHolder().setErrorResult(new HttpRequestMethodNotSupportedException(HttpMethod.DELETE.name())); } diff --git a/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRuleMsgHandler.java b/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRuleMsgHandler.java index e572dc635..ff08d38ea 100644 --- a/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRuleMsgHandler.java +++ b/extensions-api/src/main/java/com/hashmapinc/server/extensions/api/plugins/handlers/DefaultRuleMsgHandler.java @@ -44,19 +44,19 @@ public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToP //TODO: handle subscriptions to attribute updates. } - protected void handleGetAttributesRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, GetAttributesRequestRuleToPluginMsg msg) { + protected void handleGetAttributesRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, GetAttributesRequestRuleToPluginMsg msg) {//NOSONAR msgTypeNotSupported(msg.getPayload().getMsgType()); } - protected void handleUpdateAttributesRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, UpdateAttributesRequestRuleToPluginMsg msg) { + protected void handleUpdateAttributesRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, UpdateAttributesRequestRuleToPluginMsg msg) {//NOSONAR msgTypeNotSupported(msg.getPayload().getMsgType()); } - protected void handleTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, TelemetryUploadRequestRuleToPluginMsg msg) { + protected void handleTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, TelemetryUploadRequestRuleToPluginMsg msg) {//NOSONAR msgTypeNotSupported(msg.getPayload().getMsgType()); } - protected void handleDepthTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, DepthTelemetryUploadRequestRuleToPluginMsg msg) { + protected void handleDepthTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, DepthTelemetryUploadRequestRuleToPluginMsg msg) {//NOSONAR msgTypeNotSupported(msg.getPayload().getMsgType()); } diff --git a/extensions-core/src/main/java/com/hashmapinc/server/extensions/core/plugin/telemetry/SubscriptionManager.java b/extensions-core/src/main/java/com/hashmapinc/server/extensions/core/plugin/telemetry/SubscriptionManager.java index 774d3f996..2ff5eba96 100644 --- a/extensions-core/src/main/java/com/hashmapinc/server/extensions/core/plugin/telemetry/SubscriptionManager.java +++ b/extensions-core/src/main/java/com/hashmapinc/server/extensions/core/plugin/telemetry/SubscriptionManager.java @@ -69,10 +69,8 @@ public void addLocalWsDepthSubscription(PluginContext ctx, String sessionId, Ent ServerAddress address = server.get(); log.trace("[{}] Forwarding subscription [{}] for device [{}] to [{}]", sessionId, sub.getSubscriptionId(), entityId, address); subscription = new Subscription(sub, true, address); - //rpcHandler.onNewSubscription(ctx, address, sessionId, subscription); } else { log.trace("[{}] Registering local subscription [{}] for device [{}]", sessionId, sub.getSubscriptionId(), entityId); - //subscription = new Subscription(sub, true,(DepthSubscriptionState) sub); subscription = new Subscription(sub, true); } registerSubscription(sessionId, entityId, subscription); @@ -260,7 +258,7 @@ public void onLocalSubscriptionUpdateForDepth(PluginContext ctx, EntityId entity updateDepthSubscriptionState(sessionId, s, update); websocketHandler.sendWsMsg(ctx, sessionId, update); } else { - //rpcHandler.onSubscriptionUpdate(ctx, s.getServer(), sessionId, update); + log.debug("Subscription not local"); } } });