Commit aeebf541 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix search

parent 2f116f7b
Loading
Loading
Loading
Loading
Loading
+30 −5
Changes for src/main/java/org/etsi/osl/mcp/server/ProductCatalogTools.java: 30 added lines, 5 removed lines.
Original line number Original line Diff line number Diff line
@@ -26,6 +26,8 @@ import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springaicommunity.mcp.annotation.McpTool;
import org.springaicommunity.mcp.context.McpSyncRequestContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;


@@ -167,12 +169,35 @@ public class ProductCatalogTools {
  }
  }
  
  


  @Tool(description = "Search for OSL product Offerings that are published and available for product ordering in all categories")
  @McpTool(description = "Search for OSL product Offerings that are published and available for product ordering in all categories")
  public JsonNode searchOSLProductOfferings( List<String> searchStrings) {
  public JsonNode searchOSLProductOfferings( 
    
      McpSyncRequestContext context,List<String> searchStrings) {
    logger.info("searchOSLProductOfferings containing workds: {}", searchStrings);
    
    // Send logging notification
    context.info("Processing data: " + searchStrings);
 // Send progress notification (using convenient method)
    context.progress(p -> p.progress(0.5).total(1.0).message("Processing..."));
    logger.info("searchOSLServiceSpecifications containing words: {}", searchStrings);

    // Split strings that contain multiple words separated by comma or space
    List<String> expandedSearchStrings = new java.util.ArrayList<>();
    for (String searchString : searchStrings) {
      if (searchString.contains(",") || searchString.contains(" ")) {
        // Split by comma or space and add each word separately
        String[] words = searchString.split("[,\\s]+");
        for (String word : words) {
          String trimmedWord = word.trim();
          if (!trimmedWord.isEmpty()) {
            expandedSearchStrings.add(trimmedWord);
          }
        }
      } else {
        expandedSearchStrings.add(searchString);
      }
    }
    logger.info("Expanded search strings: {}", expandedSearchStrings);


    List<String> spec =  aCatalogClient.searchProductOfferings( searchStrings );
    List<String> spec =  aCatalogClient.searchProductOfferings( expandedSearchStrings );


    // Filter and get result as JSON string
    // Filter and get result as JSON string
    try {
    try {
+19 −1
Changes for src/main/java/org/etsi/osl/mcp/server/ServiceCatalogTools.java: 19 added lines, 1 removed line.
Original line number Original line Diff line number Diff line
@@ -193,7 +193,25 @@ public class ServiceCatalogTools {
    context.progress(p -> p.progress(0.5).total(1.0).message("Processing..."));
    context.progress(p -> p.progress(0.5).total(1.0).message("Processing..."));
    logger.info("searchOSLServiceSpecifications containing words: {}", searchStrings);
    logger.info("searchOSLServiceSpecifications containing words: {}", searchStrings);


    List<String> spec =  aCatalogClient.searchServiceSpecs( searchStrings );
    // Split strings that contain multiple words separated by comma or space
    List<String> expandedSearchStrings = new java.util.ArrayList<>();
    for (String searchString : searchStrings) {
      if (searchString.contains(",") || searchString.contains(" ")) {
        // Split by comma or space and add each word separately
        String[] words = searchString.split("[,\\s]+");
        for (String word : words) {
          String trimmedWord = word.trim();
          if (!trimmedWord.isEmpty()) {
            expandedSearchStrings.add(trimmedWord);
          }
        }
      } else {
        expandedSearchStrings.add(searchString);
      }
    }
    logger.info("Expanded search strings: {}", expandedSearchStrings);

    List<String> spec =  aCatalogClient.searchServiceSpecs( expandedSearchStrings );


    // Ping the client
    // Ping the client
    context.ping();
    context.ping();