Fix sonar findings on 21 style (#3020)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2026-04-15 16:57:10 +03:00
committed by GitHub
parent 643e96b7b1
commit 82ee1cc4e6
12 changed files with 284 additions and 273 deletions

View File

@@ -39,7 +39,7 @@ public class AmqpDeadletterProperties {
* @return map which holds the properties * @return map which holds the properties
*/ */
public Map<String, Object> getDeadLetterExchangeArgs(final String exchange) { public Map<String, Object> getDeadLetterExchangeArgs(final String exchange) {
final Map<String, Object> args = new HashMap<>(1); final Map<String, Object> args = HashMap.newHashMap(1);
args.put("x-dead-letter-exchange", exchange); args.put("x-dead-letter-exchange", exchange);
return args; return args;
} }
@@ -55,7 +55,7 @@ public class AmqpDeadletterProperties {
} }
private Map<String, Object> getTTLArgs() { private Map<String, Object> getTTLArgs() {
final Map<String, Object> args = new HashMap<>(1); final Map<String, Object> args = HashMap.newHashMap(1);
args.put("x-message-ttl", getTtl()); args.put("x-message-ttl", getTtl());
return args; return args;
} }

View File

@@ -142,7 +142,7 @@ public class DmfAmqpDeclarationConfiguration {
} }
private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() { private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {
final Map<String, Object> args = new HashMap<>(2); final Map<String, Object> args = HashMap.newHashMap(2);
args.put("x-message-ttl", Duration.ofSeconds(30).toMillis()); args.put("x-message-ttl", Duration.ofSeconds(30).toMillis());
args.put("x-max-length", 1_000); args.put("x-max-length", 1_000);
return args; return args;

View File

@@ -9,6 +9,9 @@
*/ */
package org.eclipse.hawkbit.mcp.server.tools; package org.eclipse.hawkbit.mcp.server.tools;
import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.mcp.server.config.HawkbitMcpProperties; import org.eclipse.hawkbit.mcp.server.config.HawkbitMcpProperties;
@@ -24,10 +27,18 @@ import org.eclipse.hawkbit.mcp.server.dto.TargetRequest;
import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction; import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSetRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSetRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody; import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
@@ -39,9 +50,6 @@ import org.eclipse.hawkbit.sdk.Tenant;
import org.springaicommunity.mcp.annotation.McpTool; import org.springaicommunity.mcp.annotation.McpTool;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import java.util.Collections;
import java.util.List;
/** /**
* MCP tools for hawkBit using the SDK. * MCP tools for hawkBit using the SDK.
* <p> * <p>
@@ -213,31 +221,31 @@ public class HawkbitMcpToolProvider {
final MgmtTargetRestApi api = hawkbitClient.mgmtService(MgmtTargetRestApi.class, dummyTenant); final MgmtTargetRestApi api = hawkbitClient.mgmtService(MgmtTargetRestApi.class, dummyTenant);
if (request instanceof TargetRequest.Create r) { if (request instanceof TargetRequest.Create(MgmtTargetRequestBody body)) {
validateOperation(OP_CREATE, TARGETS); validateOperation(OP_CREATE, TARGETS);
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_CREATE, "Request body is required for CREATE operation"); return OperationResponse.failure(OP_CREATE, "Request body is required for CREATE operation");
} }
final ResponseEntity<List<MgmtTarget>> response = api.createTargets(List.of(r.body())); final ResponseEntity<List<MgmtTarget>> response = api.createTargets(List.of(body));
final List<MgmtTarget> created = response.getBody(); final List<MgmtTarget> created = response.getBody();
return OperationResponse.success(OP_CREATE, "Target created successfully", return OperationResponse.success(OP_CREATE, "Target created successfully",
created != null && !created.isEmpty() ? created.get(0) : null); created != null && !created.isEmpty() ? created.get(0) : null);
} else if (request instanceof TargetRequest.Update r) { } else if (request instanceof TargetRequest.Update(String controllerId, MgmtTargetRequestBody body)) {
validateOperation(OP_UPDATE, TARGETS); validateOperation(OP_UPDATE, TARGETS);
if (r.controllerId() == null || r.controllerId().isBlank()) { if (controllerId == null || controllerId.isBlank()) {
return OperationResponse.failure(OP_UPDATE, "controllerId is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "controllerId is required for UPDATE operation");
} }
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_UPDATE, "Request body is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "Request body is required for UPDATE operation");
} }
final ResponseEntity<MgmtTarget> response = api.updateTarget(r.controllerId(), r.body()); final ResponseEntity<MgmtTarget> response = api.updateTarget(controllerId, body);
return OperationResponse.success(OP_UPDATE, "Target updated successfully", response.getBody()); return OperationResponse.success(OP_UPDATE, "Target updated successfully", response.getBody());
} else if (request instanceof TargetRequest.Delete r) { } else if (request instanceof TargetRequest.Delete(String controllerId)) {
validateOperation(OP_DELETE, TARGETS); validateOperation(OP_DELETE, TARGETS);
if (r.controllerId() == null || r.controllerId().isBlank()) { if (controllerId == null || controllerId.isBlank()) {
return OperationResponse.failure(OP_DELETE, "controllerId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "controllerId is required for DELETE operation");
} }
api.deleteTarget(r.controllerId()); api.deleteTarget(controllerId);
return OperationResponse.success(OP_DELETE, "Target deleted successfully"); return OperationResponse.success(OP_DELETE, "Target deleted successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
@@ -258,85 +266,85 @@ public class HawkbitMcpToolProvider {
final MgmtRolloutRestApi api = hawkbitClient.mgmtService(MgmtRolloutRestApi.class, dummyTenant); final MgmtRolloutRestApi api = hawkbitClient.mgmtService(MgmtRolloutRestApi.class, dummyTenant);
if (request instanceof RolloutRequest.Create r) { if (request instanceof RolloutRequest.Create(MgmtRolloutRestRequestBodyPost body)) {
validateRolloutOperation(OP_CREATE); validateRolloutOperation(OP_CREATE);
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION); return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION);
} }
final ResponseEntity<MgmtRolloutResponseBody> response = api.create(r.body()); final ResponseEntity<MgmtRolloutResponseBody> response = api.create(body);
return OperationResponse.success(OP_CREATE, "Rollout created successfully", response.getBody()); return OperationResponse.success(OP_CREATE, "Rollout created successfully", response.getBody());
} else if (request instanceof RolloutRequest.Update r) { } else if (request instanceof RolloutRequest.Update(Long rolloutId, MgmtRolloutRestRequestBodyPut body)) {
validateRolloutOperation("update"); validateRolloutOperation("update");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_UPDATE, "rolloutId is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "rolloutId is required for UPDATE operation");
} }
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION); return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION);
} }
final ResponseEntity<MgmtRolloutResponseBody> response = api.update(r.rolloutId(), r.body()); final ResponseEntity<MgmtRolloutResponseBody> response = api.update(rolloutId, body);
return OperationResponse.success(OP_UPDATE, "Rollout updated successfully", response.getBody()); return OperationResponse.success(OP_UPDATE, "Rollout updated successfully", response.getBody());
} else if (request instanceof RolloutRequest.Delete r) { } else if (request instanceof RolloutRequest.Delete(Long rolloutId)) {
validateRolloutOperation(OP_DELETE); validateRolloutOperation(OP_DELETE);
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_DELETE, "rolloutId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "rolloutId is required for DELETE operation");
} }
api.delete(r.rolloutId()); api.delete(rolloutId);
return OperationResponse.success(OP_DELETE, "Rollout deleted successfully"); return OperationResponse.success(OP_DELETE, "Rollout deleted successfully");
} else if (request instanceof RolloutRequest.Start r) { } else if (request instanceof RolloutRequest.Start(Long rolloutId)) {
validateRolloutOperation("start"); validateRolloutOperation("start");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_START, "rolloutId is required for START operation"); return OperationResponse.failure(OP_START, "rolloutId is required for START operation");
} }
api.start(r.rolloutId()); api.start(rolloutId);
return OperationResponse.success(OP_START, "Rollout started successfully"); return OperationResponse.success(OP_START, "Rollout started successfully");
} else if (request instanceof RolloutRequest.Pause r) { } else if (request instanceof RolloutRequest.Pause(Long rolloutId)) {
validateRolloutOperation("pause"); validateRolloutOperation("pause");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_PAUSE, "rolloutId is required for PAUSE operation"); return OperationResponse.failure(OP_PAUSE, "rolloutId is required for PAUSE operation");
} }
api.pause(r.rolloutId()); api.pause(rolloutId);
return OperationResponse.success(OP_PAUSE, "Rollout paused successfully"); return OperationResponse.success(OP_PAUSE, "Rollout paused successfully");
} else if (request instanceof RolloutRequest.Stop r) { } else if (request instanceof RolloutRequest.Stop(Long rolloutId)) {
validateRolloutOperation("stop"); validateRolloutOperation("stop");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_STOP, "rolloutId is required for STOP operation"); return OperationResponse.failure(OP_STOP, "rolloutId is required for STOP operation");
} }
api.stop(r.rolloutId()); api.stop(rolloutId);
return OperationResponse.success(OP_STOP, "Rollout stopped successfully"); return OperationResponse.success(OP_STOP, "Rollout stopped successfully");
} else if (request instanceof RolloutRequest.Resume r) { } else if (request instanceof RolloutRequest.Resume(Long rolloutId)) {
validateRolloutOperation("resume"); validateRolloutOperation("resume");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_RESUME, "rolloutId is required for RESUME operation"); return OperationResponse.failure(OP_RESUME, "rolloutId is required for RESUME operation");
} }
api.resume(r.rolloutId()); api.resume(rolloutId);
return OperationResponse.success(OP_RESUME, "Rollout resumed successfully"); return OperationResponse.success(OP_RESUME, "Rollout resumed successfully");
} else if (request instanceof RolloutRequest.Approve r) { } else if (request instanceof RolloutRequest.Approve(Long rolloutId, String remark)) {
validateRolloutOperation("approve"); validateRolloutOperation("approve");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_APPROVE, "rolloutId is required for APPROVE operation"); return OperationResponse.failure(OP_APPROVE, "rolloutId is required for APPROVE operation");
} }
api.approve(r.rolloutId(), r.remark()); api.approve(rolloutId, remark);
return OperationResponse.success(OP_APPROVE, "Rollout approved successfully"); return OperationResponse.success(OP_APPROVE, "Rollout approved successfully");
} else if (request instanceof RolloutRequest.Deny r) { } else if (request instanceof RolloutRequest.Deny(Long rolloutId, String remark)) {
validateRolloutOperation("deny"); validateRolloutOperation("deny");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_DENY, "rolloutId is required for DENY operation"); return OperationResponse.failure(OP_DENY, "rolloutId is required for DENY operation");
} }
api.deny(r.rolloutId(), r.remark()); api.deny(rolloutId, remark);
return OperationResponse.success(OP_DENY, "Rollout denied successfully"); return OperationResponse.success(OP_DENY, "Rollout denied successfully");
} else if (request instanceof RolloutRequest.Retry r) { } else if (request instanceof RolloutRequest.Retry(Long rolloutId)) {
validateRolloutOperation("retry"); validateRolloutOperation("retry");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_RETRY, "rolloutId is required for RETRY operation"); return OperationResponse.failure(OP_RETRY, "rolloutId is required for RETRY operation");
} }
final ResponseEntity<MgmtRolloutResponseBody> response = api.retryRollout(r.rolloutId()); final ResponseEntity<MgmtRolloutResponseBody> response = api.retryRollout(rolloutId);
return OperationResponse.success(OP_RETRY, "Rollout retry created successfully", response.getBody()); return OperationResponse.success(OP_RETRY, "Rollout retry created successfully", response.getBody());
} else if (request instanceof RolloutRequest.TriggerNextGroup r) { } else if (request instanceof RolloutRequest.TriggerNextGroup(Long rolloutId)) {
validateRolloutOperation("trigger-next-group"); validateRolloutOperation("trigger-next-group");
if (r.rolloutId() == null) { if (rolloutId == null) {
return OperationResponse.failure(OP_TRIGGER_NEXT_GROUP, "rolloutId is required for TRIGGER_NEXT_GROUP operation"); return OperationResponse.failure(OP_TRIGGER_NEXT_GROUP, "rolloutId is required for TRIGGER_NEXT_GROUP operation");
} }
api.triggerNextGroup(r.rolloutId()); api.triggerNextGroup(rolloutId);
return OperationResponse.success(OP_TRIGGER_NEXT_GROUP, "Next rollout group triggered successfully"); return OperationResponse.success(OP_TRIGGER_NEXT_GROUP, "Next rollout group triggered successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
@@ -353,31 +361,31 @@ public class HawkbitMcpToolProvider {
final MgmtDistributionSetRestApi api = hawkbitClient.mgmtService(MgmtDistributionSetRestApi.class, dummyTenant); final MgmtDistributionSetRestApi api = hawkbitClient.mgmtService(MgmtDistributionSetRestApi.class, dummyTenant);
if (request instanceof DistributionSetRequest.Create r) { if (request instanceof DistributionSetRequest.Create(MgmtDistributionSetRequestBodyPost body)) {
validateOperation(OP_CREATE, DISTRIBUTION_SETS); validateOperation(OP_CREATE, DISTRIBUTION_SETS);
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION); return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION);
} }
final ResponseEntity<List<MgmtDistributionSet>> response = api.createDistributionSets(List.of(r.body())); final ResponseEntity<List<MgmtDistributionSet>> response = api.createDistributionSets(List.of(body));
final List<MgmtDistributionSet> created = response.getBody(); final List<MgmtDistributionSet> created = response.getBody();
return OperationResponse.success(OP_CREATE, "Distribution set created successfully", return OperationResponse.success(OP_CREATE, "Distribution set created successfully",
created != null && !created.isEmpty() ? created.get(0) : null); created != null && !created.isEmpty() ? created.get(0) : null);
} else if (request instanceof DistributionSetRequest.Update r) { } else if (request instanceof DistributionSetRequest.Update(Long distributionSetId, MgmtDistributionSetRequestBodyPut body)) {
validateOperation(OP_UPDATE, DISTRIBUTION_SETS); validateOperation(OP_UPDATE, DISTRIBUTION_SETS);
if (r.distributionSetId() == null) { if (distributionSetId == null) {
return OperationResponse.failure(OP_UPDATE, "distributionSetId is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "distributionSetId is required for UPDATE operation");
} }
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION); return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION);
} }
final ResponseEntity<MgmtDistributionSet> response = api.updateDistributionSet(r.distributionSetId(), r.body()); final ResponseEntity<MgmtDistributionSet> response = api.updateDistributionSet(distributionSetId, body);
return OperationResponse.success(OP_UPDATE, "Distribution set updated successfully", response.getBody()); return OperationResponse.success(OP_UPDATE, "Distribution set updated successfully", response.getBody());
} else if (request instanceof DistributionSetRequest.Delete r) { } else if (request instanceof DistributionSetRequest.Delete(Long distributionSetId)) {
validateOperation(OP_DELETE, DISTRIBUTION_SETS); validateOperation(OP_DELETE, DISTRIBUTION_SETS);
if (r.distributionSetId() == null) { if (distributionSetId == null) {
return OperationResponse.failure(OP_DELETE, "distributionSetId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "distributionSetId is required for DELETE operation");
} }
api.deleteDistributionSet(r.distributionSetId()); api.deleteDistributionSet(distributionSetId);
return OperationResponse.success(OP_DELETE, "Distribution set deleted successfully"); return OperationResponse.success(OP_DELETE, "Distribution set deleted successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
@@ -393,20 +401,20 @@ public class HawkbitMcpToolProvider {
final MgmtActionRestApi api = hawkbitClient.mgmtService(MgmtActionRestApi.class, dummyTenant); final MgmtActionRestApi api = hawkbitClient.mgmtService(MgmtActionRestApi.class, dummyTenant);
if (request instanceof ActionRequest.Delete r) { if (request instanceof ActionRequest.Delete(Long actionId)) {
validateActionOperation(OP_DELETE); validateActionOperation(OP_DELETE);
if (r.actionId() == null) { if (actionId == null) {
return OperationResponse.failure(OP_DELETE, "actionId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "actionId is required for DELETE operation");
} }
api.deleteAction(r.actionId()); api.deleteAction(actionId);
return OperationResponse.success(OP_DELETE, "Action deleted successfully"); return OperationResponse.success(OP_DELETE, "Action deleted successfully");
} else if (request instanceof ActionRequest.DeleteBatch r) { } else if (request instanceof ActionRequest.DeleteBatch(List<Long> actionIds, String rsql)) {
validateActionOperation("delete-batch"); validateActionOperation("delete-batch");
if ((r.actionIds() == null || r.actionIds().isEmpty()) && if ((actionIds == null || actionIds.isEmpty()) &&
(r.rsql() == null || r.rsql().isBlank())) { (rsql == null || rsql.isBlank())) {
return OperationResponse.failure(OP_DELETE_BATCH, "Either actionIds or rsql is required for DELETE_BATCH operation"); return OperationResponse.failure(OP_DELETE_BATCH, "Either actionIds or rsql is required for DELETE_BATCH operation");
} }
api.deleteActions(r.rsql(), r.actionIds()); api.deleteActions(rsql, actionIds);
return OperationResponse.success(OP_DELETE_BATCH, "Actions deleted successfully"); return OperationResponse.success(OP_DELETE_BATCH, "Actions deleted successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
@@ -423,31 +431,31 @@ public class HawkbitMcpToolProvider {
final MgmtSoftwareModuleRestApi api = hawkbitClient.mgmtService(MgmtSoftwareModuleRestApi.class, dummyTenant); final MgmtSoftwareModuleRestApi api = hawkbitClient.mgmtService(MgmtSoftwareModuleRestApi.class, dummyTenant);
if (request instanceof SoftwareModuleRequest.Create r) { if (request instanceof SoftwareModuleRequest.Create(MgmtSoftwareModuleRequestBodyPost body)) {
validateOperation(OP_CREATE, SOFTWARE_MODULES); validateOperation(OP_CREATE, SOFTWARE_MODULES);
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION); return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION);
} }
final ResponseEntity<List<MgmtSoftwareModule>> response = api.createSoftwareModules(List.of(r.body())); final ResponseEntity<List<MgmtSoftwareModule>> response = api.createSoftwareModules(List.of(body));
final List<MgmtSoftwareModule> created = response.getBody(); final List<MgmtSoftwareModule> created = response.getBody();
return OperationResponse.success(OP_CREATE, "Software module created successfully", return OperationResponse.success(OP_CREATE, "Software module created successfully",
created != null && !created.isEmpty() ? created.get(0) : null); created != null && !created.isEmpty() ? created.get(0) : null);
} else if (request instanceof SoftwareModuleRequest.Update r) { } else if (request instanceof SoftwareModuleRequest.Update(Long softwareModuleId, MgmtSoftwareModuleRequestBodyPut body)) {
validateOperation(OP_UPDATE, SOFTWARE_MODULES); validateOperation(OP_UPDATE, SOFTWARE_MODULES);
if (r.softwareModuleId() == null) { if (softwareModuleId == null) {
return OperationResponse.failure(OP_UPDATE, "softwareModuleId is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "softwareModuleId is required for UPDATE operation");
} }
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION); return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION);
} }
final ResponseEntity<MgmtSoftwareModule> response = api.updateSoftwareModule(r.softwareModuleId(), r.body()); final ResponseEntity<MgmtSoftwareModule> response = api.updateSoftwareModule(softwareModuleId, body);
return OperationResponse.success(OP_UPDATE, "Software module updated successfully", response.getBody()); return OperationResponse.success(OP_UPDATE, "Software module updated successfully", response.getBody());
} else if (request instanceof SoftwareModuleRequest.Delete r) { } else if (request instanceof SoftwareModuleRequest.Delete(Long softwareModuleId)) {
validateOperation(OP_DELETE, SOFTWARE_MODULES); validateOperation(OP_DELETE, SOFTWARE_MODULES);
if (r.softwareModuleId() == null) { if (softwareModuleId == null) {
return OperationResponse.failure(OP_DELETE, "softwareModuleId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "softwareModuleId is required for DELETE operation");
} }
api.deleteSoftwareModule(r.softwareModuleId()); api.deleteSoftwareModule(softwareModuleId);
return OperationResponse.success(OP_DELETE, "Software module deleted successfully"); return OperationResponse.success(OP_DELETE, "Software module deleted successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
@@ -464,35 +472,34 @@ public class HawkbitMcpToolProvider {
final MgmtTargetFilterQueryRestApi api = hawkbitClient.mgmtService(MgmtTargetFilterQueryRestApi.class, dummyTenant); final MgmtTargetFilterQueryRestApi api = hawkbitClient.mgmtService(MgmtTargetFilterQueryRestApi.class, dummyTenant);
if (request instanceof TargetFilterRequest.Create r) { if (request instanceof TargetFilterRequest.Create(MgmtTargetFilterQueryRequestBody body)) {
validateOperation(OP_CREATE, TARGET_FILTERS); validateOperation(OP_CREATE, TARGET_FILTERS);
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION); return OperationResponse.failure(OP_CREATE, BODY_IS_REQUIRED_FOR_CREATE_OPERATION);
} }
final ResponseEntity<MgmtTargetFilterQuery> response = api.createFilter(r.body()); final ResponseEntity<MgmtTargetFilterQuery> response = api.createFilter(body);
return OperationResponse.success(OP_CREATE, "Target filter created successfully", response.getBody()); return OperationResponse.success(OP_CREATE, "Target filter created successfully", response.getBody());
} else if (request instanceof TargetFilterRequest.Update r) { } else if (request instanceof TargetFilterRequest.Update(Long filterId, MgmtTargetFilterQueryRequestBody body)) {
validateOperation(OP_UPDATE, TARGET_FILTERS); validateOperation(OP_UPDATE, TARGET_FILTERS);
if (r.filterId() == null) { if (filterId == null) {
return OperationResponse.failure(OP_UPDATE, "filterId is required for UPDATE operation"); return OperationResponse.failure(OP_UPDATE, "filterId is required for UPDATE operation");
} }
if (r.body() == null) { if (body == null) {
return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION); return OperationResponse.failure(OP_UPDATE, BODY_IS_REQUIRED_FOR_UPDATE_OPERATION);
} }
final ResponseEntity<MgmtTargetFilterQuery> response = api.updateFilter(r.filterId(), r.body()); final ResponseEntity<MgmtTargetFilterQuery> response = api.updateFilter(filterId, body);
return OperationResponse.success(OP_UPDATE, "Target filter updated successfully", response.getBody()); return OperationResponse.success(OP_UPDATE, "Target filter updated successfully", response.getBody());
} else if (request instanceof TargetFilterRequest.Delete r) { } else if (request instanceof TargetFilterRequest.Delete(Long filterId)) {
validateOperation(OP_DELETE, TARGET_FILTERS); validateOperation(OP_DELETE, TARGET_FILTERS);
if (r.filterId() == null) { if (filterId == null) {
return OperationResponse.failure(OP_DELETE, "filterId is required for DELETE operation"); return OperationResponse.failure(OP_DELETE, "filterId is required for DELETE operation");
} }
api.deleteFilter(r.filterId()); api.deleteFilter(filterId);
return OperationResponse.success(OP_DELETE, "Target filter deleted successfully"); return OperationResponse.success(OP_DELETE, "Target filter deleted successfully");
} }
throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName()); throw new IllegalArgumentException("Unknown request type: " + request.getClass().getSimpleName());
} }
private void validateOperation(final String operation, final String entity) { private void validateOperation(final String operation, final String entity) {
if (!isOperationEnabled(operation, entity)) { if (!isOperationEnabled(operation, entity)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@@ -60,7 +60,8 @@ public class EntityMatcher {
@SuppressWarnings({ "java:S3776", "java:S3358", "java:S1125", "java:S6541" }) // better readable this way @SuppressWarnings({ "java:S3776", "java:S3358", "java:S1125", "java:S6541" }) // better readable this way
private <T> boolean match(final T t, final Node node) { private <T> boolean match(final T t, final Node node) {
if (node instanceof Node.Comparison comparison) { switch (node) {
case Node.Comparison comparison -> {
final String[] split = comparison.getKey().split("\\.", 2); final String[] split = comparison.getKey().split("\\.", 2);
try { try {
final Getter fieldGetter = getGetter(t.getClass(), split[0]); final Getter fieldGetter = getGetter(t.getClass(), split[0]);
@@ -132,13 +133,14 @@ public class EntityMatcher {
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
} else if (node instanceof Node.Logical logical) { }
case Node.Logical logical -> {
return switch (logical.getOp()) { return switch (logical.getOp()) {
case AND -> logical.getChildren().stream().allMatch(child -> match(t, child)); case AND -> logical.getChildren().stream().allMatch(child -> match(t, child));
case OR -> logical.getChildren().stream().anyMatch(child -> match(t, child)); case OR -> logical.getChildren().stream().anyMatch(child -> match(t, child));
}; };
} else { }
throw new IllegalArgumentException("Unsupported node type: " + node.getClass()); default -> throw new IllegalArgumentException("Unsupported node type: " + node.getClass());
} }
} }
@@ -151,13 +153,11 @@ public class EntityMatcher {
return o; return o;
} }
// if here - ignoreCase in true and we have non-null value // if here - ignoreCase in true and we have non-null value
if (o instanceof String str) { return switch (o) {
return str.toLowerCase(); case String str -> str.toLowerCase();
} else if (o instanceof Collection<?> collection) { case Collection<?> collection -> collection.stream().map(this::ignoreCase).toList();
return collection.stream().map(this::ignoreCase).toList(); default -> o;
} else { };
return o;
}
} }
// java:S3011 uses reflection to private members anyway // java:S3011 uses reflection to private members anyway

View File

@@ -105,16 +105,20 @@ public class SpecificationBuilder<T> {
} }
public Predicate build(final Node node) { public Predicate build(final Node node) {
if (node instanceof Comparison comparison) { switch (node) {
case Comparison comparison -> {
return predicate(comparison); return predicate(comparison);
} else if (node instanceof Logical logical) { }
case Logical logical -> {
final Logical.Operator op = Objects.requireNonNull(logical.getOp()); final Logical.Operator op = Objects.requireNonNull(logical.getOp());
if (op == Logical.Operator.AND) { switch (op) {
case Logical.Operator.AND -> {
return cb.and(logical.getChildren().stream() return cb.and(logical.getChildren().stream()
.map(this::build) .map(this::build)
.toList() .toList()
.toArray(PREDICATES_ARRAY_0)); .toArray(PREDICATES_ARRAY_0));
} else if (op == Logical.Operator.OR) { }
case Logical.Operator.OR -> {
final Map<String, Integer> state = pathResolver.getState(); final Map<String, Integer> state = pathResolver.getState();
return cb.or(logical.getChildren().stream() return cb.or(logical.getChildren().stream()
.map(child -> { .map(child -> {
@@ -123,11 +127,11 @@ public class SpecificationBuilder<T> {
}) })
.toList() .toList()
.toArray(PREDICATES_ARRAY_0)); .toArray(PREDICATES_ARRAY_0));
} else {
throw new IllegalArgumentException("Unsupported logical operator: " + op);
} }
} else { default -> throw new IllegalArgumentException("Unsupported logical operator: " + op);
throw new IllegalArgumentException("Unsupported node type: " + node.getClass()); }
}
default -> throw new IllegalArgumentException("Unsupported node type: " + node.getClass());
} }
} }

View File

@@ -36,7 +36,7 @@ import org.springframework.transaction.TransactionSystemException;
@Slf4j @Slf4j
public class ExceptionMapper { public class ExceptionMapper {
private static final Map<String, String> EXCEPTION_MAPPING = new HashMap<>(4); private static final Map<String, String> EXCEPTION_MAPPING = HashMap.newHashMap(4);
// this is required to enable a certain order of exception and to select the most specific mappable exception according to the type // this is required to enable a certain order of exception and to select the most specific mappable exception according to the type
// hierarchy of the exception // hierarchy of the exception

View File

@@ -81,7 +81,7 @@ public class JpaConfiguration extends JpaBaseConfiguration {
@Override @Override
protected Map<String, Object> getVendorProperties(final DataSource dataSource) { protected Map<String, Object> getVendorProperties(final DataSource dataSource) {
final Map<String, Object> properties = new HashMap<>(7); final Map<String, Object> properties = HashMap.newHashMap(7);
// Turn off dynamic weaving to disable LTW lookup in static weaving mode // Turn off dynamic weaving to disable LTW lookup in static weaving mode
properties.put(PersistenceUnitProperties.WEAVING, "false"); properties.put(PersistenceUnitProperties.WEAVING, "false");
// needed for reports // needed for reports

View File

@@ -34,6 +34,7 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy; import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
/** /**
@@ -154,13 +155,13 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
return false; return false;
} }
final BaseEntity other = (BaseEntity) obj; final BaseEntity other = (BaseEntity) obj;
final Long id = getId(); final Long thisId = getId();
final Long otherId = other.getId(); final Long otherId = other.getId();
if (id == null) { if (thisId == null) {
if (otherId != null) { if (otherId != null) {
return false; return false;
} }
} else if (!id.equals(otherId)) { } else if (!thisId.equals(otherId)) {
return false; return false;
} }
return getOptLockRevision() == other.getOptLockRevision(); return getOptLockRevision() == other.getOptLockRevision();
@@ -198,9 +199,9 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
} }
protected boolean isController() { protected boolean isController() {
return SecurityContextHolder.getContext().getAuthentication() != null && final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().getAuthentication().getDetails() return authentication != null
instanceof TenantAwareAuthenticationDetails tenantAwareDetails && && authentication.getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails
tenantAwareDetails.controller(); && tenantAwareDetails.controller();
} }
} }

View File

@@ -678,7 +678,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
log.debug("{} events in flushUpdateQueue.", size); log.debug("{} events in flushUpdateQueue.", size);
final Set<TargetPoll> events = new HashSet<>(queue.size()); final Set<TargetPoll> events = HashSet.newHashSet(queue.size());
final int drained = queue.drainTo(events); final int drained = queue.drainTo(events);
if (drained <= 0) { if (drained <= 0) {

View File

@@ -68,13 +68,13 @@ public class StatisticsUtils {
final Meter.Id id = m.getId(); final Meter.Id id = m.getId();
if (id.getName().startsWith(Statistics.METER_PREFIX)) { if (id.getName().startsWith(Statistics.METER_PREFIX)) {
final double value; final double value;
if (m instanceof Counter counter) { switch (m) {
value = counter.count(); case Counter counter -> value = counter.count();
} else if (m instanceof FunctionCounter functionCounter) { case FunctionCounter functionCounter -> value = functionCounter.count();
value = functionCounter.count(); default -> {
} else {
return; return;
} }
}
final StringBuilder key = new StringBuilder(id.getName()); final StringBuilder key = new StringBuilder(id.getName());
final List<Tag> tags = id.getTags(); final List<Tag> tags = id.getTags();

View File

@@ -255,9 +255,8 @@ public final class TargetView extends TableView<TargetView.TargetWithDs, String>
} }
private static List<MgmtTargetFilterQuery> listFilters(HawkbitMgmtClient hawkbitClient) { private static List<MgmtTargetFilterQuery> listFilters(HawkbitMgmtClient hawkbitClient) {
return Optional.ofNullable(hawkbitClient.getTargetFilterQueryRestApi() return Optional.ofNullable(hawkbitClient.getTargetFilterQueryRestApi().getFilters(null, 0, 30, null, null).getBody())
.getFilters(null, 0, 30, null, null).getBody()) .map(PagedList::getContent)
.map(PagedList<MgmtTargetFilterQuery>::getContent)
.orElseGet(List::of); .orElseGet(List::of);
} }

View File

@@ -149,20 +149,20 @@ public final class Filter extends Div {
return null; return null;
} }
if (value instanceof Collection<?> coll) { switch (value) {
case Collection<?> coll -> {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
coll.stream().forEach(next -> sb.append(key).append("==").append(next).append(',')); coll.stream().forEach(next -> sb.append(key).append("==").append(next).append(','));
return sb.substring(0, sb.length() - 1); return sb.substring(0, sb.length() - 1);
} else if (value instanceof Optional<?> opt) {
if (opt.isEmpty()) {
return null;
} else {
return key + "==" + opt.get();
} }
} else { case Optional<?> opt -> {
return opt.map(o -> key + "==" + o).orElse(null);
}
default -> {
return key + "==" + value; return key + "==" + value;
} }
} }
}
private static void clear(final Stream<Component> components) { private static void clear(final Stream<Component> components) {
if (components == null) { if (components == null) {