2121import com .atomgraph .linkeddatahub .apps .model .EndUserApplication ;
2222import com .atomgraph .linkeddatahub .client .GraphStoreClient ;
2323import com .atomgraph .linkeddatahub .resource .admin .ClearOntology ;
24- import com .atomgraph .linkeddatahub .server .filter .response .CacheInvalidationFilter ;
2524import com .atomgraph .linkeddatahub .server .security .AgentContext ;
26- import com .atomgraph .linkeddatahub .server .util .UriPath ;
2725import com .atomgraph .linkeddatahub .server .util .XSLTMasterUpdater ;
2826import static com .atomgraph .server .status .UnprocessableEntityStatus .UNPROCESSABLE_ENTITY ;
2927import jakarta .inject .Inject ;
4543import org .apache .jena .update .UpdateFactory ;
4644import org .apache .jena .update .UpdateRequest ;
4745import org .apache .jena .util .FileManager ;
48- import org .glassfish .jersey .uri .UriComponent ;
4946import org .slf4j .Logger ;
5047import org .slf4j .LoggerFactory ;
5148import java .io .IOException ;
@@ -78,8 +75,6 @@ public class UninstallPackage
7875{
7976 private static final Logger log = LoggerFactory .getLogger (UninstallPackage .class );
8077
81- public final String MASTER_STYLESHEET_URL = "/static/xsl/layout.xsl" ;
82-
8378 private final com .atomgraph .linkeddatahub .apps .model .Application application ;
8479 private final com .atomgraph .linkeddatahub .Application system ;
8580 private final DataManager dataManager ;
@@ -111,7 +106,7 @@ public UninstallPackage(com.atomgraph.linkeddatahub.apps.model.Application appli
111106 /**
112107 * Uninstalls a package from the current dataspace.
113108 *
114- * @param packageURI the package URI (e.g., https://packages.linkeddatahub.com/skos/#this)
109+ * @param packageURI the package URI (e.g., <samp> https://packages.linkeddatahub.com/skos/#this</samp> )
115110 * @param referer the referring URL
116111 * @return JAX-RS response
117112 */
@@ -147,14 +142,14 @@ public Response post(@FormParam("package-uri") String packageURI, @HeaderParam("
147142 if (log .isErrorEnabled ()) log .error ("Package ontology and stylesheet are both unspecified for package: {}" , packageURI );
148143 throw new WebApplicationException ("Package ontology and stylesheet are both unspecified" , UNPROCESSABLE_ENTITY .getStatusCode ()); // 422 Unprocessable Entity
149144 }
150-
145+
151146 if (ontology != null ) uninstallOntology (endUserApp , ontology .getURI ());
152147
153148 if (stylesheet != null )
154149 {
155- String packagePath = UriPath . convert ( packageURI );
150+ String packagePath = pkg . getStylesheetPath ( );
156151 uninstallStylesheet (Paths .get (getServletContext ().getRealPath ("/static" )), packagePath , endUserApp );
157- regenerateMasterStylesheet (endUserApp , packagePath );
152+ regenerateMasterStylesheet (endUserApp , pkg );
158153 }
159154
160155 //removeImportFromApplication(endUserApp, packageURI);
@@ -264,7 +259,7 @@ private void uninstallStylesheet(Path staticDir, String packagePath, EndUserAppl
264259 if (endUserApp .getFrontendProxy () != null )
265260 {
266261 if (log .isDebugEnabled ()) log .debug ("Purging stylesheet from frontend proxy cache: {}" , stylesheetURL );
267- ban (endUserApp .getFrontendProxy (), stylesheetURL , false );
262+ getSystem (). ban (endUserApp .getFrontendProxy (), stylesheetURL , false );
268263 }
269264
270265 // Delete directory if empty
@@ -277,29 +272,36 @@ private void uninstallStylesheet(Path staticDir, String packagePath, EndUserAppl
277272
278273 /**
279274 * Regenerates master stylesheet for the application without the uninstalled package.
275+ *
276+ * @param app the application
277+ * @param removedPackage the package being uninstalled
278+ * @throws IOException if regeneration fails
280279 */
281- private void regenerateMasterStylesheet (EndUserApplication app , String removedPackagePath ) throws IOException
280+ private void regenerateMasterStylesheet (EndUserApplication app , com . atomgraph . linkeddatahub . apps . model . Package removedPackage ) throws IOException
282281 {
283- // Get all currently installed packages
284- Set <Resource > packages = app .getImportedPackages ();
282+ // Get all currently installed packages and convert to stylesheet paths
283+ Set <Resource > packageResources = app .getImportedPackages ();
285284 List <String > packagePaths = new ArrayList <>();
286285
287- for (Resource pkg : packages )
286+ String removedPath = removedPackage .getStylesheetPath ();
287+ for (Resource pkgRes : packageResources )
288288 {
289- String pkgPath = UriPath .convert (pkg .getURI ());
289+ com .atomgraph .linkeddatahub .apps .model .Package pkg = pkgRes .as (com .atomgraph .linkeddatahub .apps .model .Package .class );
290+ String pkgPath = pkg .getStylesheetPath ();
290291 // Exclude the package being removed
291- if (!pkgPath .equals (removedPackagePath )) packagePaths .add (pkgPath );
292+ if (!pkgPath .equals (removedPath ))
293+ packagePaths .add (pkgPath );
292294 }
293295
294- // Regenerate master stylesheet
296+ // Regenerate master stylesheet (XSLTMasterUpdater works with paths)
295297 XSLTMasterUpdater updater = new XSLTMasterUpdater (getServletContext ());
296298 updater .regenerateMasterStylesheet (packagePaths );
297299
298300 // Purge master stylesheet from cache
299301 if (app .getFrontendProxy () != null )
300302 {
301- if (log .isDebugEnabled ()) log .debug ("Purging master stylesheet from frontend proxy cache: {}" , MASTER_STYLESHEET_URL );
302- ban (app .getFrontendProxy (), MASTER_STYLESHEET_URL , false );
303+ if (log .isDebugEnabled ()) log .debug ("Purging master stylesheet from frontend proxy cache: {}" , com . atomgraph . linkeddatahub . Application . MASTER_STYLESHEET_PATH );
304+ getSystem (). ban (app .getFrontendProxy (), com . atomgraph . linkeddatahub . Application . MASTER_STYLESHEET_PATH , false );
303305 }
304306 }
305307
@@ -374,38 +376,6 @@ private com.atomgraph.linkeddatahub.apps.model.Package getPackage(String package
374376 }
375377 }
376378
377- protected void ban (Resource proxy , String url )
378- {
379- ban (proxy , url , true );
380- }
381-
382- /**
383- * Bans URL from the backend proxy cache.
384- *
385- * @param proxy proxy server URL
386- * @param url banned URL
387- * @param urlEncode if true, the banned URL value will be URL-encoded
388- */
389- protected void ban (Resource proxy , String url , boolean urlEncode )
390- {
391- if (url == null ) throw new IllegalArgumentException ("Resource cannot be null" );
392-
393- // Extract path from URL - Varnish req.url only contains the path, not the full URL
394- URI uri = URI .create (url );
395- String path = uri .getPath ();
396- if (uri .getQuery () != null ) path += "?" + uri .getQuery ();
397-
398- final String urlValue = urlEncode ? UriComponent .encode (path , UriComponent .Type .UNRESERVED ) : path ;
399-
400- try (Response cr = getSystem ().getClient ().target (proxy .getURI ()).
401- request ().
402- header (CacheInvalidationFilter .HEADER_NAME , urlValue ).
403- method ("BAN" , Response .class ))
404- {
405- // Response automatically closed by try-with-resources
406- }
407- }
408-
409379 /**
410380 * Returns the system application.
411381 *
0 commit comments