Remove unnecessary API module dependencies (#2842)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-12-02 13:53:36 +02:00
committed by GitHub
parent 6988f5eafb
commit 29da04f6da
29 changed files with 103 additions and 185 deletions

View File

@@ -0,0 +1,34 @@
<!--
Copyright (c) 2015 Bosch Software Innovations GmbH and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hawkbit-rest-api</artifactId>
<name>hawkBit :: REST :: API</name>
<dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2023 Bosch.IO GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.rest;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import io.swagger.v3.oas.models.tags.Tag;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public class OpenApi {
public static final String HAWKBIT_SERVER_OPENAPI_ENABLED = "hawkbit.server.openapi.enabled";
public static final String X_HAWKBIT = "x-hawkbit";
public static final String ORDER = "order";
public static List<Tag> sort(final List<Tag> tags) {
tags.sort(TAG_COMPARATOR);
return tags;
}
private static final Comparator<Tag> TAG_COMPARATOR = new Comparator<>() {
@Override
public int compare(final Tag o1, final Tag o2) {
final int o1Order = order(o1);
final int o2Order = order(o2);
if (o1Order == o2Order) {
return o1.getName().compareTo(o2.getName());
} else {
return Integer.compare(o1Order, o2Order);
}
}
private static int order(final Tag tag) {
return Optional.ofNullable(tag.getExtensions())
.map(extensions -> extensions.get(X_HAWKBIT))
.filter(extension -> Map.class.isAssignableFrom(extension.getClass()))
.map(Map.class::cast)
.map(propertiesMap -> propertiesMap.get(ORDER))
.map(String.class::cast)
.map(Integer::parseInt)
.orElse(0);
}
};
}

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.rest.json.model;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;
/**
* An exception model rest representation with JSON annotations for response bodies in case of RESTful exception occurrence.
*/
@Data
@JsonInclude(Include.NON_EMPTY)
public class ExceptionInfo {
private String exceptionClass;
private String errorCode;
private String message;
private Map<String, Object> info;
}

View File

@@ -0,0 +1,166 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.rest.json.model;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.springframework.hateoas.RepresentationModel;
/**
* List that extends RepresentationModel to ensure that links in content are in HAL format.
*
* @param <T> of the response content
*/
public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implements List<T> {
private final List<T> content;
/**
* @param content to delegate
*/
public ResponseList(final List<T> content) {
this.content = content;
}
@Override
public int size() {
return content.size();
}
@Override
public boolean isEmpty() {
return content.isEmpty();
}
@Override
public boolean contains(final Object o) {
return content.contains(o);
}
@Override
public Iterator<T> iterator() {
return content.iterator();
}
@Override
public Object[] toArray() {
return content.toArray();
}
@Override
public <C> C[] toArray(final C[] a) {
return content.toArray(a);
}
@Override
public boolean add(final T e) {
return content.add(e);
}
@Override
public boolean remove(final Object o) {
return content.remove(o);
}
@Override
public boolean containsAll(final Collection<?> c) {
return new HashSet<>(content).containsAll(c);
}
@Override
public boolean addAll(final Collection<? extends T> c) {
return content.addAll(c);
}
@Override
public boolean addAll(final int index, final Collection<? extends T> c) {
return content.addAll(index, c);
}
@Override
public boolean removeAll(final Collection<?> c) {
return content.removeAll(c);
}
@Override
public boolean retainAll(final Collection<?> c) {
return content.retainAll(c);
}
@Override
public void clear() {
content.clear();
}
@Override
public T get(final int index) {
return content.get(index);
}
@Override
public T set(final int index, final T element) {
return content.set(index, element);
}
@Override
public void add(final int index, final T element) {
content.add(index, element);
}
@Override
public T remove(final int index) {
return content.remove(index);
}
@Override
public int indexOf(final Object o) {
return content.indexOf(o);
}
@Override
public int lastIndexOf(final Object o) {
return content.lastIndexOf(o);
}
@Override
public ListIterator<T> listIterator() {
return content.listIterator();
}
@Override
public ListIterator<T> listIterator(final int index) {
return content.listIterator(index);
}
@Override
public List<T> subList(final int fromIndex, final int toIndex) {
return content.subList(fromIndex, toIndex);
}
@Override
public String toString() {
return "ResponseList [content=" + content + "]";
}
@Override
public boolean equals(final Object o) {
return content.equals(o);
}
@Override
public int hashCode() {
return content.hashCode();
}
}

View File

@@ -0,0 +1,53 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.rest.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
/**
* Feature: Unit Tests - Management API<br/>
* Story: Error Handling
*/
class ExceptionInfoTest {
/**
* Ensures that setters and getters match on teh payload.
*/
@Test
void setterAndGetterOnExceptionInfo() {
final String knownExceptionClass = "hawkbit.test.exception.Class";
final String knownErrorCode = "hawkbit.error.code.Known";
final String knownMessage = "a known message";
final Map<String, Object> knownInfo = new HashMap<>();
knownInfo.put("param1", "1");
knownInfo.put("param2", 2);
final ExceptionInfo underTest = new ExceptionInfo();
underTest.setErrorCode(knownErrorCode);
underTest.setExceptionClass(knownExceptionClass);
underTest.setMessage(knownMessage);
underTest.setInfo(knownInfo);
assertThat(underTest.getErrorCode()).as("The error code should match with the known error code in the test")
.isEqualTo(knownErrorCode);
assertThat(underTest.getExceptionClass())
.as("The exception class should match with the known error code in the test")
.isEqualTo(knownExceptionClass);
assertThat(underTest.getMessage()).as("The message should match with the known error code in the test")
.isEqualTo(knownMessage);
assertThat(underTest.getInfo()).as("The parameters should match with the known error code in the test")
.isEqualTo(knownInfo);
}
}