Skip to content

Commit

Permalink
Merge pull request #584 from hashmapinc/Tempus-577-Sonar-Cloud-Fix
Browse files Browse the repository at this point in the history
Tempus-577 Fixing sonarcloud bugs and code smells.
  • Loading branch information
VikashSingh94 authored Jul 19, 2018
2 parents 83b5f3b + d0789a4 commit bfeb1ca
Show file tree
Hide file tree
Showing 47 changed files with 300 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<AlarmInfo> getAlarms(
@PathVariable("entityType") String strEntityType,
Expand Down Expand Up @@ -136,7 +136,7 @@ public TimePageData<AlarmInfo> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Asset> getTenantAssets(
@RequestParam int limit,
Expand All @@ -227,7 +227,7 @@ public TextPageData<Asset> 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 {
Expand All @@ -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<Asset> getCustomerAssets(
@PathVariable("customerId") String strCustomerId,
Expand All @@ -268,7 +268,7 @@ public TextPageData<Asset> getCustomerAssets(
}

@PostFilter("hasPermission(filterObject, 'ASSET_READ')")
@RequestMapping(value = "/assets", params = {"assetIds"}, method = RequestMethod.GET)
@GetMapping(value = "/assets", params = {"assetIds"})
@ResponseBody
public List<Asset> getAssetsByIds(
@RequestParam("assetIds") String[] strAssetIds) throws TempusException {
Expand All @@ -294,7 +294,7 @@ public List<Asset> getAssetsByIds(
}

@PostFilter("hasPermission(filterObject, 'ASSET_READ')")
@RequestMapping(value = "/assets", method = RequestMethod.POST)
@PostMapping(value = "/assets")
@ResponseBody
public List<Asset> findByQuery(@RequestBody AssetSearchQuery query) throws TempusException {
checkNotNull(query);
Expand All @@ -318,7 +318,7 @@ public List<Asset> 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<EntitySubtype> getAssetTypes() throws TempusException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuditLog> getAuditLogsByCustomerId(
@PathVariable("customerId") String strCustomerId,
Expand All @@ -53,7 +53,7 @@ public TimePageData<AuditLog> 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<AuditLog> getAuditLogsByUserId(
@PathVariable("userId") String strUserId,
Expand All @@ -73,7 +73,7 @@ public TimePageData<AuditLog> 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<AuditLog> getAuditLogsByEntityId(
@PathVariable("entityType") String strEntityType,
Expand All @@ -95,7 +95,7 @@ public TimePageData<AuditLog> getAuditLogsByEntityId(
}

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs", params = {"limit"}, method = RequestMethod.GET)
@GetMapping(value = "/audit/logs", params = {"limit"})
@ResponseBody
public TimePageData<AuditLog> getAuditLogs(
@RequestParam int limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -103,7 +103,7 @@ public void changePassword (
}


@RequestMapping(value = "/noauth/activate", params = { "activateToken" }, method = RequestMethod.GET)
@GetMapping(value = "/noauth/activate", params = { "activateToken" })
public ResponseEntity<String> checkActivateToken(@RequestParam(value = "activateToken") String activateToken) throws JsonProcessingException, TempusException {
HttpHeaders headers = new HttpHeaders();
HttpStatus responseStatus;
Expand Down Expand Up @@ -134,7 +134,7 @@ public ResponseEntity<String> 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,
Expand All @@ -161,7 +161,7 @@ public void requestResetPasswordByEmail (
}
}

@RequestMapping(value = "/noauth/resetPassword", params = { "resetToken" }, method = RequestMethod.GET)
@GetMapping(value = "/noauth/resetPassword", params = { "resetToken" })
public ResponseEntity<String> checkResetToken(
@RequestParam(value = "resetToken") String resetToken) throws TempusException {
HttpHeaders headers = new HttpHeaders();
Expand All @@ -188,7 +188,7 @@ public ResponseEntity<String> 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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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<ComponentDescriptor> getComponentDescriptorsByType(@PathVariable("componentType") String strComponentType) throws TempusException {
checkParameter("componentType", strComponentType);
Expand All @@ -52,7 +52,7 @@ public List<ComponentDescriptor> 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<ComponentDescriptor> getPluginActionsByPluginClazz(@PathVariable("pluginClazz") String pluginClazz) throws TempusException {
checkParameter("pluginClazz", pluginClazz);
Expand Down
Loading

0 comments on commit bfeb1ca

Please sign in to comment.