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

fix search

parent 2f116f7b
Loading
Loading
Loading
Loading
Loading
+29 −4
Original line number 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.slf4j.Logger;
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.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")
  public JsonNode searchOSLProductOfferings( List<String> searchStrings) {
    
    logger.info("searchOSLProductOfferings containing workds: {}", searchStrings);
  @McpTool(description = "Search for OSL product Offerings that are published and available for product ordering in all categories")
  public JsonNode searchOSLProductOfferings( 
      McpSyncRequestContext context,List<String> 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
    try {
+21 −3
Original line number Diff line number Diff line
@@ -193,7 +193,25 @@ public class ServiceCatalogTools {
    context.progress(p -> p.progress(0.5).total(1.0).message("Processing..."));
    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
    context.ping();