Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ public CompletableFuture<ResourceResponse> availableResources(ResourceParam para
return CompletableFuture.supplyAsync(() -> response);
}

@Override
public CompletableFuture<Map<String, ResourceResponse>> getAllResources() {

Map<String, ResourceResponse> allResources = resourceFinder.getAllResources(projectUri);
Comment on lines +340 to +343
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
@Override
public CompletableFuture<Map<String, ResourceResponse>> getAllResources() {
Map<String, ResourceResponse> allResources = resourceFinder.getAllResources(projectUri);
@Override
public CompletableFuture<Map<String, ResourceResponse>> getAllResources() {
log.info("Fetching all available resources for project: {}", projectUri);
Map<String, ResourceResponse> allResources = resourceFinder.getAllResources(projectUri);

return CompletableFuture.supplyAsync(() -> allResources);
}

@Override
public CompletableFuture<Either3<ConnectorResponse, Connector, Boolean>> availableConnectors(ConnectorParam param) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public interface ISynapseLanguageService {
@JsonRequest
CompletableFuture<ResourceResponse> availableResources(ResourceParam param);

@JsonRequest
CompletableFuture<Map<String, ResourceResponse>> getAllResources();

@JsonRequest
CompletableFuture<Either3<ConnectorResponse, Connector, Boolean>> availableConnectors(ConnectorParam param);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ public Map<String, ResourceResponse> getDependentResourcesMap() {
return dependentResourcesMap;
}

public Map<String, ResourceResponse> getAllResources(String projectPath) {

return new HashMap<>();
}
Comment on lines +410 to +413
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
public Map<String, ResourceResponse> getAllResources(String projectPath) {
return new HashMap<>();
}
public Map<String, ResourceResponse> getAllResources(String projectPath) {
log.debug("Getting all resources for project path: {}", projectPath);
return new HashMap<>();
}

Comment on lines +410 to +413
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid an empty default implementation for getAllResources.

Returning an empty map here can silently produce incorrect results when a finder does not override this method. Use findAllResources(projectPath) as the default behavior (or make this method abstract).

Suggested fix
 public Map<String, ResourceResponse> getAllResources(String projectPath) {
-
-        return new HashMap<>();
+        return findAllResources(projectPath);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Map<String, ResourceResponse> getAllResources(String projectPath) {
return new HashMap<>();
}
public Map<String, ResourceResponse> getAllResources(String projectPath) {
return findAllResources(projectPath);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/resourceFinder/AbstractResourceFinder.java`
around lines 410 - 413, The default implementation of
AbstractResourceFinder.getAllResources currently returns an empty map which can
hide bugs; change getAllResources(String projectPath) to delegate to the
existing findAllResources(projectPath) by returning its result (or alternatively
make getAllResources abstract) so subclasses that don't override it inherit
correct behavior; update the method in AbstractResourceFinder to call
findAllResources(projectPath) (or convert getAllResources to abstract) to ensure
consistent resource discovery.


private String getFullyQualifiedName(OverviewPageDetailsResponse pomDetailsResponse, Resource resource) {

// For DataServices and proxy services, the name remains unchanged as by default MI server won't expose versioned services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ private void filterResourcesForUnitTestRegistry(List<Resource> resourcesInRegist
}
}

/**
* Returns all resources in the project, including artifacts, local entries, and registry
* resources from both the main project and resolved dependent projects.
*
* @param projectPath the root directory of the project
* @return a map where the key is the resource type and the value is the corresponding ResourceResponse
*/
@Override
public Map<String, ResourceResponse> getAllResources(String projectPath) {

Map<String, ResourceResponse> allResources = findAllResources(projectPath);
Comment on lines +150 to +153
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
@Override
public Map<String, ResourceResponse> getAllResources(String projectPath) {
Map<String, ResourceResponse> allResources = findAllResources(projectPath);
@Override
public Map<String, ResourceResponse> getAllResources(String projectPath) {
log.info("Getting all resources for project: " + projectPath);
Map<String, ResourceResponse> allResources = findAllResources(projectPath);

Map<String, ResourceResponse> dependentResources = getDependentResourcesMap();
for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) {
Comment on lines +153 to +155
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 5

Suggested change
Map<String, ResourceResponse> allResources = findAllResources(projectPath);
Map<String, ResourceResponse> dependentResources = getDependentResourcesMap();
for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) {
Map<String, ResourceResponse> allResources = findAllResources(projectPath);
Map<String, ResourceResponse> dependentResources = getDependentResourcesMap();
log.debug("Found " + allResources.size() + " main resources and " + dependentResources.size() + " dependent resource types");
for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) {

allResources.computeIfAbsent(entry.getKey(), k -> new ResourceResponse());
mergeResourceResponses(allResources.get(entry.getKey()), entry.getValue());
}
return allResources;
Comment on lines +143 to +159
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

getAllResources currently includes dependent-project resources, which conflicts with the endpoint objective.

This method merges getDependentResourcesMap() into the response, so the returned payload is not project-only. If the endpoint contract is project-owned resources only, return just findAllResources(projectPath).

Suggested fix
 `@Override`
 public Map<String, ResourceResponse> getAllResources(String projectPath) {
-
-        Map<String, ResourceResponse> allResources = findAllResources(projectPath);
-        Map<String, ResourceResponse> dependentResources = getDependentResourcesMap();
-        for (Map.Entry<String, ResourceResponse> entry : dependentResources.entrySet()) {
-            allResources.computeIfAbsent(entry.getKey(), k -> new ResourceResponse());
-            mergeResourceResponses(allResources.get(entry.getKey()), entry.getValue());
-        }
-        return allResources;
+        return findAllResources(projectPath);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/resourceFinder/NewProjectResourceFinder.java`
around lines 143 - 159, getAllResources currently merges dependent-project data
(via getDependentResourcesMap and mergeResourceResponses) into the project
result, violating the project-only contract; change getAllResources to return
only the map produced by findAllResources(projectPath) and remove the code that
obtains getDependentResourcesMap() and merges entries (references:
getAllResources, findAllResources, getDependentResourcesMap,
mergeResourceResponses) so the returned payload contains only project-owned
resources.

}

@Override
protected String getArtifactFolder(String type) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package org.eclipse.lemminx.synapse.resource.finder;

import org.eclipse.lemminx.customservice.synapse.resourceFinder.AbstractResourceFinder;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.NewProjectResourceFinder;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.ResourceFinderFactory;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.ArtifactResource;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.RegistryResource;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.RequestedResource;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.Resource;
import org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo.ResourceResponse;
Expand Down Expand Up @@ -448,6 +451,51 @@ public void testRequestMultipleRegistryResource() {
assertEqualResourceNames(expectedResourceNames, multipleResources.getRegistryResources());
}

@Test
public void testGetAllResources() {

TestNewProjectResourceFinder finder = new TestNewProjectResourceFinder();

// Simulate a dependent project that contributes a sequence artifact and a sequence registry resource
ArtifactResource depSequence = new ArtifactResource();
depSequence.setName("depSequence1");
ResourceResponse depSequenceResponse = new ResourceResponse();
depSequenceResponse.setResources(new ArrayList<>(List.of(depSequence)));

RegistryResource depSequenceRegistry = new RegistryResource();
depSequenceRegistry.setName("depSequenceRegistry1");
depSequenceResponse.setRegistryResources(new ArrayList<>(List.of(depSequenceRegistry)));
finder.addDependentResources("sequence", depSequenceResponse);

// Simulate a dependent project that contributes an api artifact
ArtifactResource depApi = new ArtifactResource();
depApi.setName("depApi1");
ResourceResponse depApiResponse = new ResourceResponse();
depApiResponse.setResources(new ArrayList<>(List.of(depApi)));
finder.addDependentResources("api", depApiResponse);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 6

Suggested change
Map<String, ResourceResponse> allResources = finder.getAllResources(projectPath);
log.info("Retrieved all resources from finder for project path: {}", projectPath);

Map<String, ResourceResponse> allResources = finder.getAllResources(projectPath);

// api: 1 from main project + 1 from dependent project
ResourceResponse apiResources = allResources.get("api");
assertEquals(2, apiResources.getResources().size());
assertEqualResourceNames(new String[]{"testApi", "depApi1"}, apiResources.getResources());

// sequence: 1 artifact from main + 1 from dep; 2 registry from main + 1 from dep
ResourceResponse sequenceResources = allResources.get("sequence");
assertEquals(2, sequenceResources.getResources().size());
assertEquals(3, sequenceResources.getRegistryResources().size());
assertEqualResourceNames(new String[]{"testSequence1", "depSequence1"}, sequenceResources.getResources());
assertEqualResourceNames(new String[]{"testSequence1", "testSequence2", "depSequenceRegistry1"},
sequenceResources.getRegistryResources());

// endpoint: main project resources unaffected by dependent resources
ResourceResponse endpointResources = allResources.get("endpoint");
assertEquals(2, endpointResources.getResources().size());
assertEquals(4, endpointResources.getRegistryResources().size());
assertEqualResourceNames(new String[]{"testEndpoint1", "testEndpoint2"}, endpointResources.getResources());
}

private void assertEqualResourceNames(String[] expectedResourceNames, List<Resource> resources) {

List<String> actualResourceNames =
Expand All @@ -464,4 +512,11 @@ public static boolean areListsEqual(List<String> list1, List<String> list2) {
Collections.sort(list2);
return list1.equals(list2);
}

private static class TestNewProjectResourceFinder extends NewProjectResourceFinder {

void addDependentResources(String type, ResourceResponse response) {
dependentResourcesMap.put(type, response);
}
}
}
Loading