Skip to content

Commit

Permalink
Move participants.json file to resource directory, update CatalogNode…
Browse files Browse the repository at this point in the history
…DirectoryExtension.java
  • Loading branch information
farhin23 committed Dec 17, 2024
1 parent 80a7a39 commit 47632ed
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
7 changes: 3 additions & 4 deletions federated-catalog/fc-03-static-node-directory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ However, this solution is intended for use only within the sample scope; in prod

### Target Node Resolver

#### TargetNodeResolver
The [CatalogNodeResolver](./target-node-resolver/src/main/java/org/eclipse/edc/sample/extension/fc/CatalogNodeDirectory.java)
The [CatalogNodeDirectory](./target-node-resolver/src/main/java/org/eclipse/edc/sample/extension/fc/CatalogNodeDirectory.java)
implements TargetNodeDirectory and overrides its `getAll()` method.
In our implementation, this method maps the array of Json objects from the [`participant.json`](./target-node-resolver/resources/participants.json)
In our implementation, this method maps the file content of [`participant.json`](./target-node-resolver/resources/participants.json)
to a list of TargetNodes.

```java
Expand All @@ -56,7 +55,7 @@ public class CatalogNodeDirectory implements TargetNodeDirectory {
@Override
public List<TargetNode> getAll() {
try {
return objectMapper.readValue(participantListFile, new TypeReference<>() {});
return objectMapper.readValue(participantFileContent, new TypeReference<>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
import org.eclipse.edc.crawler.spi.TargetNode;
import org.eclipse.edc.crawler.spi.TargetNodeDirectory;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class CatalogNodeDirectory implements TargetNodeDirectory {

private final ObjectMapper objectMapper;
private final File participantListFile;
private final String participantFileContent;

public CatalogNodeDirectory(ObjectMapper objectMapper, File participantListFile) {

public CatalogNodeDirectory(ObjectMapper objectMapper, String participantFileContent) {
this.objectMapper = objectMapper;
this.participantListFile = participantListFile;
this.participantFileContent = participantFileContent;
}

@Override
public List<TargetNode> getAll() {
try {
return objectMapper.readValue(participantListFile, new TypeReference<>() {});
return objectMapper.readValue(participantFileContent, new TypeReference<>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

public class CatalogNodeDirectoryExtension implements ServiceExtension {
@Inject
private TypeManager typeManager;

private File participantListFile;
@Provider
public TargetNodeDirectory federatedCacheNodeDirectory() {
String participantsFilePath = "participants.json";

@Override
public void initialize(ServiceExtensionContext context) {
var participantsFilePath = "federated-catalog/fc-03-static-node-directory/target-node-resolver/resources/participants.json";
ClassLoader classLoader = getClass().getClassLoader();
try (InputStream participantFileInputStream = classLoader.getResourceAsStream(participantsFilePath)) {
if (participantFileInputStream == null) {
throw new RuntimeException("Participant list file does not exist: " + participantsFilePath);
}

participantListFile = new File(participantsFilePath).getAbsoluteFile();
if (!participantListFile.exists()) {
throw new RuntimeException("Participant list file does not exist: " + participantsFilePath);
}
}
String participantFileContent = new String(participantFileInputStream.readAllBytes(), StandardCharsets.UTF_8);

@Provider
public TargetNodeDirectory federatedCacheNodeDirectory() {
return new CatalogNodeDirectory(typeManager.getMapper(), participantListFile);
return new CatalogNodeDirectory(typeManager.getMapper(), participantFileContent);
} catch (IOException e) {
throw new RuntimeException("Failed to read and map participant list file: " + participantsFilePath, e);
}
}

}
4 changes: 0 additions & 4 deletions system-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ plugins {
`java-library`
}

tasks.test {
workingDir = rootProject.projectDir
}

dependencies {
testImplementation(libs.edc.junit)
testImplementation(libs.edc.json.ld.lib)
Expand Down

0 comments on commit 47632ed

Please sign in to comment.