@@ -757,41 +757,29 @@ public Application(final ServletConfig servletConfig, final MediaTypes mediaType
757757 BuiltinPersonalities .model .add (CSVImport .class , CSVImportImpl .factory );
758758 BuiltinPersonalities .model .add (com .atomgraph .linkeddatahub .model .File .class , FileImpl .factory );
759759
760- // Build ServiceContext map: keyed by service URI, associates each service with its client and proxy config .
761- // Admin services get backendProxyAdmin; end-user services get backendProxyEndUser .
760+ // Build ServiceContext map: keyed by service URI, proxy derived from the app type that references each service .
761+ // Iterating ldt:service statements (app → service) naturally excludes orphan services .
762762 serviceContextMap = new HashMap <>();
763763 org .apache .jena .rdf .model .Model ctxUnion = contextDataset .getUnionModel ();
764- ResIterator serviceIt = ctxUnion .listSubjectsWithProperty (org .apache .jena .vocabulary .RDF .type ,
765- com .atomgraph .core .vocabulary .SD .Service );
764+ org .apache .jena .rdf .model .StmtIterator serviceIt = ctxUnion .listStatements (null , LDT .service , (org .apache .jena .rdf .model .RDFNode ) null );
766765 try
767766 {
768767 while (serviceIt .hasNext ())
769768 {
770- Resource svcResource = serviceIt .next ();
771- com .atomgraph .linkeddatahub .model .Service svc = svcResource .as (com .atomgraph .linkeddatahub .model .Service .class );
772- // Determine which proxy applies: check which type of application references this service
773- org .apache .jena .rdf .model .ResIterator appIt = ctxUnion .listSubjectsWithProperty (
774- LDT .service , svcResource );
775- boolean referencedByAdmin = false ;
776- boolean referencedByEndUser = false ;
777- try
778- {
779- while (appIt .hasNext ())
780- {
781- Resource app = appIt .next ();
782- if (app .hasProperty (org .apache .jena .vocabulary .RDF .type , LAPP .AdminApplication ))
783- referencedByAdmin = true ;
784- if (app .hasProperty (org .apache .jena .vocabulary .RDF .type , LAPP .EndUserApplication ))
785- referencedByEndUser = true ;
786- }
787- }
788- finally
789- {
790- appIt .close ();
791- }
792- URI proxy = referencedByAdmin ? backendProxyAdmin : (referencedByEndUser ? backendProxyEndUser : null );
769+ org .apache .jena .rdf .model .Statement stmt = serviceIt .nextStatement ();
770+ Resource app = stmt .getSubject ();
771+ Resource svcResource = stmt .getResource ();
772+ URI proxy ;
773+
774+ if (app .hasProperty (RDF .type , LAPP .AdminApplication ))
775+ proxy = backendProxyAdmin ;
776+ else if (app .hasProperty (RDF .type , LAPP .EndUserApplication ))
777+ proxy = backendProxyEndUser ;
778+ else
779+ continue ;
780+
793781 serviceContextMap .put (svcResource .getURI (),
794- new com .atomgraph .linkeddatahub .model .ServiceContext (svc , noCertClient , mediaTypes , maxGetRequestSize , proxy ));
782+ new com .atomgraph .linkeddatahub .model .ServiceContext (svcResource . as ( com . atomgraph . linkeddatahub . model . Service . class ) , noCertClient , mediaTypes , maxGetRequestSize , proxy ));
795783 }
796784 }
797785 finally
0 commit comments