diff --git a/extensions/last-commit-info/build.gradle.kts b/extensions/last-commit-info/build.gradle.kts index 9a80c0001..9a841be7e 100644 --- a/extensions/last-commit-info/build.gradle.kts +++ b/extensions/last-commit-info/build.gradle.kts @@ -8,6 +8,9 @@ plugins { } dependencies { + annotationProcessor("org.projectlombok:lombok:1.18.26") + compileOnly("org.projectlombok:lombok:1.18.26") + api("${edcGroup}:core-spi:${edcVersion}") api("${edcGroup}:control-plane-spi:${edcVersion}") implementation("${edcGroup}:api-core:${edcVersion}") diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java new file mode 100644 index 000000000..492c18758 --- /dev/null +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfo.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.extension; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class LastCommitInfo { + private String envLastCommitInfo; + private String envLastBuildDate; + private String jarLastCommitInfo; + private String jarLastBuildDate; +} diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java index 1d48f0bce..394031cc3 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoController.java @@ -19,6 +19,7 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; + @Produces({MediaType.APPLICATION_JSON}) @Path("/last-commit-info") public class LastCommitInfoController { @@ -29,7 +30,8 @@ public LastCommitInfoController(LastCommitInfoService lastCommitInfoService) { } @GET - public String getLastCommitInfo() { + @Produces(MediaType.APPLICATION_JSON) + public LastCommitInfo getLastCommitInfo() { return lastCommitInfoService.getLastCommitInfo(); } } diff --git a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java index 461b0a8df..c90ae2ad2 100644 --- a/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java +++ b/extensions/last-commit-info/src/main/java/de/sovity/edc/extension/LastCommitInfoService.java @@ -24,34 +24,40 @@ public class LastCommitInfoService { private final ServiceExtensionContext context; + private String readFileInCurrentClassClasspath(String path) { + var classLoader = LastCommitInfoService.class.getClassLoader(); + var is = classLoader.getResourceAsStream(path); + var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } + public LastCommitInfoService(ServiceExtensionContext context) { this.context = context; } - public String getLastCommitInfo() { - var result = ""; - - if (!getEnvLastCommitInfo().equals("")) { - result += "Env Last Commit Info: \n"; - result += getEnvLastCommitInfo() + "\n"; - } + public String getJarLastCommitInfo() { + return this.readFileInCurrentClassClasspath("jar-last-commit-info.txt"); + } - if (!getEnvLastCommitInfo().equals(getJarLastCommitInfo())) { - result += "Jar Last Commit Info: \n"; - result += getJarLastCommitInfo(); - } + public String getEnvLastCommitInfo() { + return context.getSetting("edc.last.commit.info", ""); + } - return result; + public String getJarLastBuildDate() { + return readFileInCurrentClassClasspath("jar-last-build-date-info.txt"); } - public String getJarLastCommitInfo() { - var classLoader = Thread.currentThread().getContextClassLoader(); - var is = classLoader.getResourceAsStream("jar-last-commit-info.txt"); - var scanner = new Scanner(Objects.requireNonNull(is), StandardCharsets.UTF_8).useDelimiter("\\A"); - return scanner.hasNext() ? scanner.next() : ""; + public String getEnvLastBuildDate() { + return context.getSetting("edc.last.build.date", ""); } - public String getEnvLastCommitInfo() { - return context.getSetting("edc.last.commit.info", ""); + public LastCommitInfo getLastCommitInfo() { + var lastCommitInfo = new LastCommitInfo(); + lastCommitInfo.setEnvLastCommitInfo(getEnvLastCommitInfo()); + lastCommitInfo.setJarLastCommitInfo(getJarLastCommitInfo()); + + lastCommitInfo.setJarLastBuildDate(getJarLastBuildDate()); + lastCommitInfo.setEnvLastBuildDate(getEnvLastBuildDate()); + return lastCommitInfo; } } diff --git a/extensions/last-commit-info/src/main/resources/jar-latest-build-date-info.txt b/extensions/last-commit-info/src/main/resources/jar-latest-build-date-info.txt new file mode 100644 index 000000000..e69de29bb diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java deleted file mode 100644 index c3f59a247..000000000 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoEnvTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.extension.version.controller; - -import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static de.sovity.edc.extension.version.controller.TestUtils.createConfiguration; -import static de.sovity.edc.extension.version.controller.TestUtils.mockRequest; -import static org.hamcrest.Matchers.containsStringIgnoringCase; - -@ApiTest -@ExtendWith(EdcExtension.class) -class LastCommitInfoEnvTest { - - @BeforeEach - void setUp(EdcExtension extension) { - extension.setConfiguration(createConfiguration("env")); - } - - @Test - void testEnvAndJar() { - var request = mockRequest(); - request.assertThat().body(containsStringIgnoringCase("pipeline")); - request.assertThat().body(containsStringIgnoringCase("env")); - } -} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java deleted file mode 100644 index 65f87062e..000000000 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoJarTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 sovity GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * sovity GmbH - initial API and implementation - * - */ - -package de.sovity.edc.extension.version.controller; - -import org.eclipse.edc.junit.annotations.ApiTest; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static de.sovity.edc.extension.version.controller.TestUtils.createConfiguration; -import static de.sovity.edc.extension.version.controller.TestUtils.mockRequest; -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.not; - -@ApiTest -@ExtendWith(EdcExtension.class) -class LastCommitInfoJarTest { - - @BeforeEach - void setUp(EdcExtension extension) { - extension.setConfiguration(createConfiguration("")); - } - - @Test - void testOnlyJar() { - var request = mockRequest(); - request.assertThat().body(containsStringIgnoringCase("pipeline")); - request.assertThat().body(not(containsStringIgnoringCase("env"))); - } -} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java new file mode 100644 index 000000000..36f4a14e9 --- /dev/null +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/LastCommitInfoTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.extension.version.controller; + +import io.restassured.http.ContentType; +import org.eclipse.edc.junit.annotations.ApiTest; +import org.eclipse.edc.junit.extensions.EdcExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort; +import static org.hamcrest.Matchers.equalTo; + +@ApiTest +@ExtendWith(EdcExtension.class) +class LastCommitInfoTest { + + @BeforeEach + void setUp(EdcExtension extension) { + extension.setConfiguration(Map.of( + "web.http.port", String.valueOf(getFreePort()), + "web.http.path", "/api", + "web.http.management.port", String.valueOf(TestUtils.DATA_PORT), + "web.http.management.path", "/api/v1/data", + "edc.api.auth.key", TestUtils.AUTH_KEY, + "edc.last.commit.info", "test env commit message", + "edc.last.build.date", "2023-05-08T15:30:00Z")); + } + + @Test + void testEnvAndJar() { + var request = given() + .baseUri("http://localhost:" + TestUtils.DATA_PORT) + .basePath("/api/v1/data") + .header("x-api-key", TestUtils.AUTH_KEY) + .when() + .contentType(ContentType.JSON) + .get("/last-commit-info") + .then() + .statusCode(200) + .contentType(ContentType.JSON); + + request.assertThat().body("envLastCommitInfo", equalTo("test env commit message")) + .body("envLastBuildDate", equalTo("2023-05-08T15:30:00Z")) + .body("jarLastCommitInfo", equalTo("test jar commit message\n")) + .body("jarLastBuildDate", equalTo("2023-05-09T15:30:00Z\n")); + + } +} diff --git a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java index 8ceecd847..e9f6c6866 100644 --- a/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java +++ b/extensions/last-commit-info/src/test/java/de/sovity/edc/extension/version/controller/TestUtils.java @@ -14,41 +14,12 @@ package de.sovity.edc.extension.version.controller; -import io.restassured.http.ContentType; -import io.restassured.response.ValidatableResponse; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - import static io.restassured.RestAssured.given; import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort; public class TestUtils { - private static final int DATA_PORT = getFreePort(); - private static final String AUTH_KEY = "123456"; - - @NotNull - static Map createConfiguration(String commitInfo) { - return Map.of( - "web.http.port", String.valueOf(getFreePort()), - "web.http.path", "/api", - "web.http.management.port", String.valueOf(DATA_PORT), - "web.http.management.path", "/api/v1/data", - "edc.api.auth.key", AUTH_KEY, - "edc.last.commit.info", commitInfo); - } + public static final int DATA_PORT = getFreePort(); + public static final String AUTH_KEY = "123456"; - static ValidatableResponse mockRequest() { - return given() - .baseUri("http://localhost:" + DATA_PORT) - .basePath("/api/v1/data") - .header("x-api-key", AUTH_KEY) - .when() - .contentType(ContentType.TEXT) - .get(String.format("/last-commit-info")) - .then() - .statusCode(200) - .contentType(ContentType.JSON); - } } diff --git a/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt b/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt new file mode 100644 index 000000000..3f3faacba --- /dev/null +++ b/extensions/last-commit-info/src/test/resources/jar-last-build-date-info.txt @@ -0,0 +1 @@ +2023-05-09T15:30:00Z diff --git a/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt b/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt new file mode 100644 index 000000000..1516a70eb --- /dev/null +++ b/extensions/last-commit-info/src/test/resources/jar-last-commit-info.txt @@ -0,0 +1 @@ +test jar commit message diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java new file mode 100644 index 000000000..b7045a79b --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntry.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.ui.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.OffsetDateTime; + +@Data +@Schema(description = "Transfer History Entry for Transfer History Page") +public class TransferHistoryEntry { + @Schema(description = "Transfer Process ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String transferProcessId; + + + @Schema(description = "Created Date", requiredMode = Schema.RequiredMode.REQUIRED) + private OffsetDateTime createdDate; + + @Schema(description = "Last Change Date", requiredMode = Schema.RequiredMode.REQUIRED) + private OffsetDateTime lastUpdatedDate; + + @Schema(description = "Transfer History State", requiredMode = Schema.RequiredMode.REQUIRED) + private TransferProcessState state; + + @Schema(description = "Contract Agreement ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String contractAgreementId; + + @Schema(description = "Incoming vs Outgoing", requiredMode = Schema.RequiredMode.REQUIRED) + private ContractAgreementDirection direction; + + @Schema(description = "Other Connector's Endpoint", requiredMode = Schema.RequiredMode.REQUIRED) + private String counterPartyAddress; + + + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.REQUIRED) + private String assetName; + + @Schema(description = "Asset ID", requiredMode = Schema.RequiredMode.REQUIRED) + private String assetId; + + @Schema(description = "Error Message") + private String errorMessage; + + +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntryContractAgreementDetails.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntryContractAgreementDetails.java new file mode 100644 index 000000000..89ba560f2 --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryEntryContractAgreementDetails.java @@ -0,0 +1,12 @@ +package de.sovity.edc.ext.wrapper.api.ui.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.OffsetDateTime; + +@Data +public class TransferHistoryEntryContractAgreementDetails { + + +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java new file mode 100644 index 000000000..cfe921976 --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/TransferHistoryPage.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.api.ui.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +@Data +@AllArgsConstructor +public class TransferHistoryPage { + @Schema(description = "Transfer History Page Entries", requiredMode = Schema.RequiredMode.REQUIRED) + private List transferEntries; +}