@@ -299,94 +299,97 @@ public static void deploy(CkanClient ckanClient, DcatDataset dataset, IRIxResolv
299
299
remoteCkanDataset = ckanClient .updateDataset (remoteCkanDataset );
300
300
}
301
301
302
+
302
303
for (DcatDistribution dcatDistribution : dataset .getDistributions ()) {
303
304
304
305
305
306
CkanResource remoteCkanResource = createOrUpdateResource (ckanClient , remoteCkanDataset , dataset , dcatDistribution );
306
307
307
- // Check if there is a graph in the dataset that matches the distribution
308
- String distributionName = dcatDistribution .getTitle ();
308
+ if (!noFileUpload ) {
309
309
310
- logger .info ("Deploying distribution " + distributionName );
310
+ // Check if there is a graph in the dataset that matches the distribution
311
+ String distributionName = dcatDistribution .getTitle ();
311
312
312
- Set < String > downloadUrls = dcatDistribution . getDownloadURLs ( );
313
+ logger . info ( "Deploying distribution " + distributionName );
313
314
314
- List <String > resolvedUrls = downloadUrls .stream ()
315
- //.filter(Resource::isURIResource)
316
- //.map(Resource::getURI)
317
- .map (iriResolver ::resolve )
318
- .map (IRIx ::str )
319
- .collect (Collectors .toList ());
315
+ Set <String > downloadUrls = dcatDistribution .getDownloadURLs ();
320
316
321
- Set <URI > resolvedValidUrls = resolvedUrls .stream ()
322
- .map (str -> UriUtils .tryNewURI (str ).orElse (null ))
323
- .filter (r -> r != null )
324
- .collect (Collectors .toCollection (LinkedHashSet ::new ));
317
+ List <String > resolvedUrls = downloadUrls .stream ()
318
+ //.filter(Resource::isURIResource)
319
+ //.map(Resource::getURI)
320
+ .map (iriResolver ::resolve )
321
+ .map (IRIx ::str )
322
+ .collect (Collectors .toList ());
325
323
326
- if (resolvedUrls .size () > 1 ) {
327
- logger .warn ("Multiple URLs associated with a distribution; assuming they mirror content and choosing one from " + resolvedUrls );
328
- }
324
+ Set <URI > resolvedValidUrls = resolvedUrls .stream ()
325
+ .map (str -> UriUtils .tryNewURI (str ).orElse (null ))
326
+ .filter (r -> r != null )
327
+ .collect (Collectors .toCollection (LinkedHashSet ::new ));
329
328
330
- Set <URI > urlsToExistingPaths = resolvedValidUrls .stream ()
331
- .filter (uri ->
332
- DcatCkanDeployUtils .pathsGet (uri )
333
- .filter (Files ::exists )
334
- .filter (Files ::isRegularFile )
335
- .isPresent ())
336
- .collect (Collectors .toSet ());
337
-
338
- Set <URI > webUrls = Sets .difference (resolvedValidUrls , urlsToExistingPaths );
339
-
340
- String downloadFilename ;
341
- Optional <Path > pathReference = Optional .empty ();
342
- Path root = null ;
343
- if (urlsToExistingPaths .size () > 0 ) {
344
- URI fileUrl = urlsToExistingPaths .iterator ().next ();
345
- pathReference = DcatCkanDeployUtils .pathsGet (fileUrl );
346
- downloadFilename = pathReference .get ().getFileName ().toString ();
347
- } else {
348
- // TODO This should go through the conjure http cache
349
- root = Files .createTempDirectory ("http-cache-" );
350
- URI webUrl = webUrls .iterator ().next ();
351
- String webUrlPathStr = webUrl .getPath ();
352
- Path tmp = Paths .get (webUrlPathStr );
353
- downloadFilename = tmp .getFileName ().toString ();
354
-
355
- HttpResourceRepositoryFromFileSystemImpl manager = HttpResourceRepositoryFromFileSystemImpl .create (root );
356
-
357
- BasicHttpRequest r = new BasicHttpRequest ("GET" , webUrl .toASCIIString ());
358
- // r.setHeader(HttpHeaders.ACCEPT, WebContent.contentTypeTurtleAlt2);
359
- // r.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,identity;q=0");
360
-
361
- RdfHttpEntityFile httpEntity = manager .get (r , HttpResourceRepositoryFromFileSystemImpl ::resolveRequest );
362
- pathReference = Optional .ofNullable (httpEntity ).map (RdfHttpEntityFile ::getAbsolutePath );
363
- }
329
+ if (resolvedUrls .size () > 1 ) {
330
+ logger .warn ("Multiple URLs associated with a distribution; assuming they mirror content and choosing one from " + resolvedUrls );
331
+ }
332
+
333
+ Set <URI > urlsToExistingPaths = resolvedValidUrls .stream ()
334
+ .filter (uri ->
335
+ DcatCkanDeployUtils .pathsGet (uri )
336
+ .filter (Files ::exists )
337
+ .filter (Files ::isRegularFile )
338
+ .isPresent ())
339
+ .collect (Collectors .toSet ());
340
+
341
+ Set <URI > webUrls = Sets .difference (resolvedValidUrls , urlsToExistingPaths );
342
+
343
+ String downloadFilename ;
344
+ Optional <Path > pathReference = Optional .empty ();
345
+ Path root = null ;
346
+ if (urlsToExistingPaths .size () > 0 ) {
347
+ URI fileUrl = urlsToExistingPaths .iterator ().next ();
348
+ pathReference = DcatCkanDeployUtils .pathsGet (fileUrl );
349
+ downloadFilename = pathReference .get ().getFileName ().toString ();
350
+ } else {
351
+ // TODO This should go through the conjure resource cache
352
+ root = Files .createTempDirectory ("http-cache-" );
353
+ URI webUrl = webUrls .iterator ().next ();
354
+ String webUrlPathStr = webUrl .getPath ();
355
+ Path tmp = Paths .get (webUrlPathStr );
356
+ downloadFilename = tmp .getFileName ().toString ();
364
357
365
- // TODO This breaks if the downloadURLs are web urls.
366
- // We need a flag whether to do a file upload for web urls, or whether to just update metadata
367
-
368
- // Optional<Path> pathReference = resolvedValidUrls.stream()
369
- // .map(DcatCkanDeployUtils::pathsGet)
370
- // .filter(Optional::isPresent)
371
- // .map(Optional::get)
372
- // .filter(Files::exists)
373
- // .findFirst();
374
- //
375
-
376
- if (pathReference .isPresent ()) {
377
- Path path = pathReference .get ();
378
-
379
- //String filename = distributionName + ".nt";
380
- String probedContentType = null ;
381
- try {
382
- probedContentType = Files .probeContentType (path );
383
- } catch (IOException e ) {
384
- logger .warn ("Failed to probe content type of " + path , e );
358
+ HttpResourceRepositoryFromFileSystemImpl manager = HttpResourceRepositoryFromFileSystemImpl .create (root );
359
+
360
+ BasicHttpRequest r = new BasicHttpRequest ("GET" , webUrl .toASCIIString ());
361
+ // r.setHeader(HttpHeaders.ACCEPT, WebContent.contentTypeTurtleAlt2);
362
+ // r.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,identity;q=0");
363
+
364
+ RdfHttpEntityFile httpEntity = manager .get (r , HttpResourceRepositoryFromFileSystemImpl ::resolveRequest );
365
+ pathReference = Optional .ofNullable (httpEntity ).map (RdfHttpEntityFile ::getAbsolutePath );
385
366
}
386
367
387
- String contentType = Optional .ofNullable (probedContentType ).orElse (ContentType .APPLICATION_OCTET_STREAM .toString ());
368
+ // TODO This breaks if the downloadURLs are web urls.
369
+ // We need a flag whether to do a file upload for web urls, or whether to just update metadata
370
+
371
+ // Optional<Path> pathReference = resolvedValidUrls.stream()
372
+ // .map(DcatCkanDeployUtils::pathsGet)
373
+ // .filter(Optional::isPresent)
374
+ // .map(Optional::get)
375
+ // .filter(Files::exists)
376
+ // .findFirst();
377
+ //
378
+
379
+ if (pathReference .isPresent ()) {
380
+ Path path = pathReference .get ();
381
+
382
+ //String filename = distributionName + ".nt";
383
+ String probedContentType = null ;
384
+ try {
385
+ probedContentType = Files .probeContentType (path );
386
+ } catch (IOException e ) {
387
+ logger .warn ("Failed to probe content type of " + path , e );
388
+ }
389
+
390
+ String contentType = Optional .ofNullable (probedContentType ).orElse (ContentType .APPLICATION_OCTET_STREAM .toString ());
388
391
389
- if (!noFileUpload ) {
392
+ // if (!noFileUpload) {
390
393
391
394
logger .info ("Uploading file " + path );
392
395
CkanResource tmp = CkanClientUtils .uploadFile (
@@ -431,18 +434,19 @@ public static void deploy(CkanClient ckanClient, DcatDataset dataset, IRIxResolv
431
434
//remoteCkanResource = ckanClient.updateResource(remoteCkanResource);
432
435
433
436
434
- } else {
435
- logger .info ("File upload disabled. Skipping " + path );
437
+ // } else {
438
+ // logger.info("File upload disabled. Skipping " + path);
439
+ // }
436
440
}
437
- }
438
441
439
- Resource newDownloadUrl = ResourceFactory .createResource (remoteCkanResource .getUrl ());
442
+ Resource newDownloadUrl = ResourceFactory .createResource (remoteCkanResource .getUrl ());
440
443
441
- org .aksw .jena_sparql_api .rdf .collections .ResourceUtils .setProperty (dcatDistribution , DCAT .downloadURL , newDownloadUrl );
444
+ org .aksw .jena_sparql_api .rdf .collections .ResourceUtils .setProperty (dcatDistribution , DCAT .downloadURL , newDownloadUrl );
442
445
443
- if (root != null ) {
444
- logger .info ("Removing directory recursively: " + root );
445
- // MoreFiles.deleteRecursively(root);
446
+ if (root != null ) {
447
+ logger .info ("Removing directory recursively: " + root );
448
+ // MoreFiles.deleteRecursively(root);
449
+ }
446
450
}
447
451
}
448
452
}
0 commit comments