@@ -354,6 +354,71 @@ append_quads()
354354 fi
355355}
356356
357+ gsp_append_quads ()
358+ {
359+ local graph_store_url=" $1 "
360+ local auth_user=" $2 "
361+ local auth_pwd=" $3 "
362+ local filename=" $4 "
363+
364+ # Create temporary SPARQL query to extract distinct graph URIs
365+ local query_file
366+ query_file=$( mktemp)
367+ cat > " $query_file " << 'EOF '
368+ SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o }}
369+ EOF
370+
371+ # Execute SPARQL query to get graph URIs safely
372+ local graph_uris
373+ graph_uris=$( sparql --data=" $filename " --query=" $query_file " --results=CSV | tail -n +2 | cut -d, -f1)
374+
375+ # Clean up query file
376+ rm -f " $query_file "
377+
378+ # Iterate through each graph URI
379+ while IFS= read -r graph_uri; do
380+ if [ -n " $graph_uri " ]; then
381+ # Remove any trailing newlines/whitespace
382+ graph_uri=$( echo " $graph_uri " | tr -d ' \n\r' )
383+ # Create temporary file for this graph's content
384+ local temp_file
385+ temp_file=$( mktemp)
386+
387+ # Create SPARQL query to extract triples for specific graph
388+ local extract_query
389+ extract_query=$( mktemp)
390+ cat > " $extract_query " << EOF
391+ CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <$graph_uri > { ?s ?p ?o } }
392+ EOF
393+
394+ # Extract triples for this specific graph as N-Triples
395+ sparql --data=" $filename " --query=" $extract_query " --results=NT > " $temp_file "
396+
397+ # Send the graph's triples to the graph store using standard GSP
398+ if [ -n " $auth_user " ] && [ -n " $auth_pwd " ]; then
399+ curl \
400+ -f \
401+ --basic \
402+ --user " $auth_user " :" $auth_pwd " \
403+ --url-query " graph=$graph_uri " \
404+ " $graph_store_url " \
405+ -H " Content-Type: application/n-triples" \
406+ --data-binary @" $temp_file "
407+ else
408+ curl \
409+ -f \
410+ --url-query " graph=$graph_uri " \
411+ " $graph_store_url " \
412+ -H " Content-Type: application/n-triples" \
413+ --data-binary @" $temp_file "
414+ fi
415+
416+ # Clean up temporary files
417+ rm -f " $temp_file " " $extract_query "
418+ fi
419+ done <<< " $graph_uris"
420+ }
421+
357422generate_cert ()
358423{
359424 local alias=" $1 "
@@ -580,6 +645,8 @@ readarray apps < <(xmlstarlet sel -B \
580645 -o " \" \" " \
581646 -v " srx:binding[@name = 'quadStore']" \
582647 -o " \" \" " \
648+ -v " srx:binding[@name = 'graphStore']" \
649+ -o " \" \" " \
583650 -v " srx:binding[@name = 'endpoint']" \
584651 -o " \" \" " \
585652 -v " srx:binding[@name = 'authUser']" \
@@ -597,19 +664,20 @@ for app in "${apps[@]}"; do
597664 app_type=" ${app_array[1]// \" / } "
598665 app_origin=" ${app_array[2]// \" / } "
599666 app_quad_store_url=" ${app_array[3]// \" / } "
600- app_endpoint_url=" ${app_array[4]// \" / } "
601- app_service_auth_user=" ${app_array[5]// \" / } "
602- app_service_auth_pwd=" ${app_array[6]// \" / } "
603- app_owner=" ${app_array[7]// \" / } "
667+ app_graph_store_url=" ${app_array[4]// \" / } "
668+ app_endpoint_url=" ${app_array[5]// \" / } "
669+ app_service_auth_user=" ${app_array[6]// \" / } "
670+ app_service_auth_pwd=" ${app_array[7]// \" / } "
671+ app_owner=" ${app_array[8]// \" / } "
604672
605673 printf " \n### Processing app: %s (type: %s, origin: %s)\n" " $app_uri " " $app_type " " $app_origin "
606674
607675 if [ -z " $app_uri " ]; then
608676 printf " \nApp URI could not be extracted from %s. Exiting...\n" " $CONTEXT_DATASET "
609677 exit 1
610678 fi
611- if [ -z " $app_quad_store_url " ]; then
612- printf " \nQuad store URL could not be extracted for the <%s> app. Exiting...\n" " $app_uri "
679+ if [ -z " $app_quad_store_url " ] && [ -z " $app_graph_store_url " ] ; then
680+ printf " \nNeither quad store nor graph store URL could be extracted for the <%s> app. Exiting...\n" " $app_uri "
613681 exit 1
614682 fi
615683 if [ -z " $app_origin " ]; then
@@ -639,7 +707,22 @@ for app in "${apps[@]}"; do
639707 echo " <${app_uri} > <http://xmlns.com/foaf/0.1/maker> <${OWNER_URI} > <${app_uri} > ." >> " $based_context_dataset "
640708 fi
641709
642- printf " \n### Quad store URL: %s\n" " $app_quad_store_url "
710+ if [ -n " $app_quad_store_url " ]; then
711+ printf " \n### Quad store URL: %s\n" " $app_quad_store_url "
712+ else
713+ printf " \n### Graph store URL (GSP fallback): %s\n" " $app_graph_store_url "
714+ fi
715+
716+ # resolve the effective store URL and upload function for this app
717+ if [ -n " $app_quad_store_url " ]; then
718+ app_store_url=" $app_quad_store_url "
719+ app_store_content_type=" application/n-quads"
720+ app_store_fn=" append_quads"
721+ else
722+ app_store_url=" $app_graph_store_url "
723+ app_store_content_type=" application/n-triples"
724+ app_store_fn=" gsp_append_quads"
725+ fi
643726
644727 # Create app-specific subfolder based on origin
645728 app_folder=$( echo " $app_origin " | sed ' s|https://||' | sed ' s|http://||' | sed ' s|[:/]|-|g' )
@@ -676,11 +759,11 @@ for app in "${apps[@]}"; do
676759
677760 trig --base=" ${app_origin} /" " $END_USER_DATASET " > " /var/linkeddatahub/based-datasets/${app_folder} /end-user.nq"
678761
679- printf " \n### Waiting for %s...\n" " $app_quad_store_url "
680- wait_for_url " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " $TIMEOUT " " application/n-quads "
762+ printf " \n### Waiting for %s...\n" " $app_store_url "
763+ wait_for_url " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " $TIMEOUT " " $app_store_content_type "
681764
682765 printf " \n### Loading end-user dataset into the triplestore...\n"
683- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /end-user.nq" " application/n-quads "
766+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /end-user.nq" " $app_store_content_type "
684767
685768 elif [ " $app_type " = " https://w3id.org/atomgraph/linkeddatahub/apps#AdminApplication" ]; then
686769
@@ -699,11 +782,11 @@ for app in "${apps[@]}"; do
699782
700783 trig --base=" ${app_origin} /" " $ADMIN_DATASET " > " /var/linkeddatahub/based-datasets/${app_folder} /admin.nq"
701784
702- printf " \n### Waiting for %s...\n" " $app_quad_store_url "
703- wait_for_url " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " $TIMEOUT " " application/n-quads "
785+ printf " \n### Waiting for %s...\n" " $app_store_url "
786+ wait_for_url " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " $TIMEOUT " " $app_store_content_type "
704787
705788 printf " \n### Loading admin dataset into the triplestore...\n"
706- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /admin.nq" " application/n-quads "
789+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /admin.nq" " $app_store_content_type "
707790
708791 # derive the corresponding end-user origin by stripping the leading 'admin.' from the hostname
709792 end_user_origin=$( echo " $app_origin " | sed ' s|://admin\.|://|' )
@@ -716,15 +799,15 @@ for app in "${apps[@]}"; do
716799 trig --base=" ${app_origin} /" --output=nq " $namespace_ontology_dataset_path " > " /var/linkeddatahub/based-datasets/${app_folder} /namespace-ontology.nq"
717800
718801 printf " \n### Loading namespace ontology into the admin triplestore...\n"
719- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /namespace-ontology.nq" " application/n-quads "
802+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /namespace-ontology.nq" " $app_store_content_type "
720803
721804 # Load full owner/secretary metadata (agent + key) only for root admin app
722805 if [ " $app_origin " = " $ADMIN_ORIGIN " ]; then
723806 printf " \n### Uploading the metadata of the owner agent...\n\n"
724- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " /var/linkeddatahub/based-datasets/root-owner.nq " application/n-quads "
807+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " /var/linkeddatahub/based-datasets/root-owner.nq " $app_store_content_type "
725808
726809 printf " \n### Uploading the metadata of the secretary agent...\n\n"
727- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " /var/linkeddatahub/based-datasets/root-secretary.nq " application/n-quads "
810+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " /var/linkeddatahub/based-datasets/root-secretary.nq " $app_store_content_type "
728811 fi
729812
730813 # Load owner/secretary authorizations for this app (with app-specific UUIDs)
@@ -742,7 +825,7 @@ for app in "${apps[@]}"; do
742825 trig --base=" ${app_origin} /" --output=nq " $owner_auth_dataset_path " > " /var/linkeddatahub/based-datasets/${app_folder} /owner-authorization.nq"
743826
744827 printf " \n### Uploading owner authorizations for this app...\n\n"
745- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /owner-authorization.nq" " application/n-quads "
828+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /owner-authorization.nq" " $app_store_content_type "
746829
747830 secretary_auth_dataset_path=" /var/linkeddatahub/datasets/${app_folder} /secretary-authorization.trig"
748831 mkdir -p " $( dirname " $secretary_auth_dataset_path " ) "
@@ -757,7 +840,7 @@ for app in "${apps[@]}"; do
757840 trig --base=" ${app_origin} /" --output=nq " $secretary_auth_dataset_path " > " /var/linkeddatahub/based-datasets/${app_folder} /secretary-authorization.nq"
758841
759842 printf " \n### Uploading secretary authorizations for this app...\n\n"
760- append_quads " $app_quad_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /secretary-authorization.nq" " application/n-quads "
843+ " $app_store_fn " " $app_store_url " " $app_service_auth_user " " $app_service_auth_pwd " " /var/linkeddatahub/based-datasets/${app_folder} /secretary-authorization.nq" " $app_store_content_type "
761844
762845 fi
763846 fi
0 commit comments