8d5420e0 by Ean Schuessler

Fix ResourcesRead service by removing invalid artifactHit references

1 parent 6e68f0f3
...@@ -670,81 +670,56 @@ ...@@ -670,81 +670,56 @@
670 throw new Exception("Permission denied for entity: ${entityName}") 670 throw new Exception("Permission denied for entity: ${entityName}")
671 } 671 }
672 672
673 def startTime = System.currentTimeMillis() 673 def startTime = System.currentTimeMillis()
674 try { 674 try {
675 // Get entity definition for field descriptions 675 // Get entity definition for field descriptions
676 def entityInfoList = ec.entity.getAllEntityInfo(0, false) 676 def entityInfoList = ec.entity.getAllEntityInfo(0, false)
677 def entityDef = entityInfoList.find { it.entityName == entityName } 677 def entityDef = entityInfoList.find { it.entityName == entityName }
678 if (!entityDef) { 678 if (!entityDef) {
679 throw new Exception("Entity not found: ${entityName}") 679 throw new Exception("Entity not found: ${entityName}")
680 }
681
682 // Query entity data (limited to prevent large responses)
683 def entityList = ec.entity.find(entityName)
684 .limit(100)
685 .list()
686
687 def executionTime = (System.currentTimeMillis() - startTime) / 1000.0
688
689 // Build field info for LLM
690 def fieldInfo = []
691 entityDef.allFieldInfoList.each { field ->
692 fieldInfo << [
693 name: field.name,
694 type: field.type,
695 description: field.description ?: "",
696 isPk: field.isPk,
697 required: field.notNull
698 ]
699 }
700
701 // Convert to MCP resource content
702 def contents = [
703 [
704 uri: uri,
705 mimeType: "application/json",
706 text: new JsonBuilder([
707 entityName: entityName,
708 description: entityDef.description ?: "",
709 packageName: entityDef.packageName,
710 recordCount: entityList.size(),
711 fields: fieldInfo,
712 data: entityList
713 ]).toString()
714 ]
715 ]
716
717 result = [contents: contents]
718
719 // Update audit record
720 artifactHit.runningTimeMillis = executionTime
721 artifactHit.wasError = "N"
722 artifactHit.outputSize = new JsonBuilder(result).toString().length()
723
724 ec.artifactExecution.disableAuthz()
725 try {
726 artifactHit.update()
727 } finally {
728 ec.artifactExecution.enableAuthz()
729 } 680 }
730
731 } catch (Exception e) {
732 def executionTime = (System.currentTimeMillis() - startTime) / 1000.0
733
734 // Update audit record with error
735 artifactHit.runningTimeMillis = executionTime
736 artifactHit.wasError = "Y"
737 artifactHit.errorMessage = e.message
738 681
739 ec.artifactExecution.disableAuthz() 682 // Query entity data (limited to prevent large responses)
740 try { 683 def entityList = ec.entity.find(entityName)
741 artifactHit.update() 684 .limit(100)
742 } finally { 685 .list()
743 ec.artifactExecution.enableAuthz() 686
687 def executionTime = (System.currentTimeMillis() - startTime) / 1000.0
688
689 // Build field info for LLM
690 def fieldInfo = []
691 entityDef.allFieldInfoList.each { field ->
692 fieldInfo << [
693 name: field.name,
694 type: field.type,
695 description: field.description ?: "",
696 isPk: field.isPk,
697 required: field.notNull
698 ]
744 } 699 }
745 700
701 // Convert to MCP resource content
702 def contents = [
703 [
704 uri: uri,
705 mimeType: "application/json",
706 text: new JsonBuilder([
707 entityName: entityName,
708 description: entityDef.description ?: "",
709 packageName: entityDef.packageName,
710 recordCount: entityList.size(),
711 fields: fieldInfo,
712 data: entityList
713 ]).toString()
714 ]
715 ]
716
717 result = [contents: contents]
718
719 } catch (Exception e) {
720 def executionTime = (System.currentTimeMillis() - startTime) / 1000.0
746 throw new Exception("Error reading resource ${uri}: ${e.message}") 721 throw new Exception("Error reading resource ${uri}: ${e.message}")
747 } 722 }
748 ]]></script> 723 ]]></script>
749 </actions> 724 </actions>
750 </service> 725 </service>
......