176176import java .io .FileOutputStream ;
177177import java .io .UnsupportedEncodingException ;
178178import java .nio .charset .StandardCharsets ;
179- import java .nio .file .Path ;
180- import java .nio .file .Paths ;
181179import java .security .MessageDigest ;
182180import java .util .Arrays ;
183181import java .util .List ;
@@ -2018,7 +2016,7 @@ public Model getContextModel()
20182016 public Model getDataspaceModel (com .atomgraph .linkeddatahub .apps .model .Application application )
20192017 {
20202018 if (application == null ) throw new IllegalArgumentException ("Application cannot be null" );
2021- return getContextDataset ().getNamedModel (application .getURI ());
2019+ return ModelFactory . createModelForGraph ( new GraphReadOnly ( getContextDataset ().getNamedModel (application .getURI ()). getGraph () ));
20222020 }
20232021
20242022 /**
@@ -2032,7 +2030,7 @@ public Model getDataspaceModel(com.atomgraph.linkeddatahub.apps.model.Applicatio
20322030 * @param newModel the new RDF model to replace the existing named graph
20332031 * @throws IOException if an I/O error occurs
20342032 */
2035- public void updateDataspace (com .atomgraph .linkeddatahub .apps .model .Application application , Model newModel ) throws IOException
2033+ public void updateApp (com .atomgraph .linkeddatahub .apps .model .Application application , Model newModel ) throws IOException
20362034 {
20372035 if (application == null ) throw new IllegalArgumentException ("Application cannot be null" );
20382036 if (newModel == null ) throw new IllegalArgumentException ("Model cannot be null" );
@@ -2041,22 +2039,22 @@ public void updateDataspace(com.atomgraph.linkeddatahub.apps.model.Application a
20412039 {
20422040 String dataspaceURI = application .getURI ();
20432041
2044- // Only support file-based URIs for the default implementation
2045- if (!getContextDatasetURI ().isAbsolute () || !"file" .equals (getContextDatasetURI ().getScheme ()))
2046- {
2047- throw new UnsupportedOperationException ("Only file-based context dataset URIs are supported for updates in default implementation" );
2048- }
2049-
2050- Path configFilePath = Paths .get (getContextDatasetURI ());
2051-
20522042 // Update the named graph in the dataset
20532043 getContextDataset ().removeNamedModel (dataspaceURI ).
20542044 addNamedModel (dataspaceURI , newModel );
20552045
2056- // Write the updated dataset back to file
2057- com .atomgraph .linkeddatahub .server .util .SystemConfigFileManager .writeDataset (getContextDataset (), configFilePath );
2046+ // Write the updated dataset back to file using RDFDataMgr
2047+ // Support both absolute file:// URIs and relative webapp paths (like getDataset does)
2048+ try (java .io .OutputStream out = (getContextDatasetURI ().isAbsolute () ?
2049+ new FileOutputStream (new java .io .File (getContextDatasetURI ())) :
2050+ new FileOutputStream (getServletConfig ().getServletContext ().getRealPath (getContextDatasetURI ().toString ()))))
2051+ {
2052+ Lang lang = RDFDataMgr .determineLang (getContextDatasetURI ().toString (), null , null );
2053+ if (lang == null ) throw new IOException ("Could not determine RDF format from dataset URI: " + getContextDatasetURI ().toString ());
20582054
2059- if (log .isInfoEnabled ()) log .info ("Updated dataspace <{}> in file: {}" , dataspaceURI , configFilePath );
2055+ RDFDataMgr .write (out , getContextDataset (), lang );
2056+ if (log .isInfoEnabled ()) log .info ("Updated dataspace <{}> in context dataset: {}" , dataspaceURI , getContextDatasetURI ());
2057+ }
20602058 }
20612059 }
20622060
0 commit comments