From fd1c94f40c8d41eacb8cdc02fd704743f1a8809c Mon Sep 17 00:00:00 2001
From: bourgesl <bourges.laurent@gmail.com>
Date: Mon, 26 Mar 2018 18:13:31 +0200
Subject: [PATCH] ignore orphan projects in generate Embedded pages

---
 .../fr/osug/doi/GenerateRedirectPipeline.java | 62 ++++++++++---------
 src/main/java/fr/osug/util/FileUtils.java     |  4 +-
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/src/main/java/fr/osug/doi/GenerateRedirectPipeline.java b/src/main/java/fr/osug/doi/GenerateRedirectPipeline.java
index 15b7a1f..62aedb7 100644
--- a/src/main/java/fr/osug/doi/GenerateRedirectPipeline.java
+++ b/src/main/java/fr/osug/doi/GenerateRedirectPipeline.java
@@ -152,38 +152,42 @@ public final class GenerateRedirectPipeline extends AbstractPipeline<PipelineCom
         for (Project p : projects) {
             final String projectName = p.getName();
 
-            final ProjectConfig projectConfig = pipeData.getProjectConfigAll(projectName);
-
-            if (projectConfig.getPropertyBoolean(ProjectConfig.CONF_KEY_GENERATE_EMBEDDED)) {
-                // // [public/staging]/PROJECT/embed/DOI_SUFFIX[.html]
-                sb.append("\n# Project ").append(projectName);
-
-                /*
-                RedirectMatch "^/embed/AMMA-CATCH.CE.RainD_Nc([-]*)(.*)" "/staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc$1$2.html"
-                    /embed/AMMA-CATCH.CE.RainD_Nc           =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc.html
-                    /embed/AMMA-CATCH.CE.RainD_Nc-header    =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc-header.html
-                    /embed/AMMA-CATCH.CE.RainD_Nc-meta      =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc-meta.html
-                 */
-                final List<Doi> dois = dr.findByProject(projectName);
-
-                logger.info("Dois for project[{}]: {}", projectName, dois.size());
-
-                for (Doi doi : dois) {
-                    final String doiSuffix = doi.getIdentifier();
-
-                    // ^/embed/
-                    sb.append("\nRedirectMatch \"^/").append(Paths.DIR_WEB_EMBED).append('/');
-                    sb.append(doiSuffix).append("([-]*)(.*)\" \"");
+            final List<Doi> dois = dr.findByProject(projectName);
 
-                    if (doi.getStatus() == Status.PUBLIC) {
-                        sb.append('/').append(Paths.DIR_WEB_PUBLIC).append('/');
-                    } else {
-                        sb.append('/').append(Paths.DIR_WEB_STAGING).append('/');
+            logger.info("Dois for project[{}]: {}", projectName, dois.size());
+            
+            // skip empty projects (orphans)
+            if (!dois.isEmpty()) {
+                final ProjectConfig projectConfig = pipeData.getProjectConfigAll(projectName);
+
+                if (projectConfig.getPropertyBoolean(ProjectConfig.CONF_KEY_GENERATE_EMBEDDED)) {
+                    // // [public/staging]/PROJECT/embed/DOI_SUFFIX[.html]
+                    sb.append("\n# Project ").append(projectName);
+
+                    /*
+                    RedirectMatch "^/embed/AMMA-CATCH.CE.RainD_Nc([-]*)(.*)" "/staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc$1$2.html"
+                        /embed/AMMA-CATCH.CE.RainD_Nc           =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc.html
+                        /embed/AMMA-CATCH.CE.RainD_Nc-header    =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc-header.html
+                        /embed/AMMA-CATCH.CE.RainD_Nc-meta      =>  /staging/AMMA-CATCH/embed/AMMA-CATCH.CE.RainD_Nc-meta.html
+                     */
+
+                    for (Doi doi : dois) {
+                        final String doiSuffix = doi.getIdentifier();
+
+                        // ^/embed/
+                        sb.append("\nRedirectMatch \"^/").append(Paths.DIR_WEB_EMBED).append('/');
+                        sb.append(doiSuffix).append("([-]*)(.*)\" \"");
+
+                        if (doi.getStatus() == Status.PUBLIC) {
+                            sb.append('/').append(Paths.DIR_WEB_PUBLIC).append('/');
+                        } else {
+                            sb.append('/').append(Paths.DIR_WEB_STAGING).append('/');
+                        }
+                        sb.append(projectName).append('/').append(Paths.DIR_WEB_EMBED).append('/').append(doiSuffix);
+                        sb.append("$1$2").append(GeneratePipeline.HTML_EXT).append('\"');
                     }
-                    sb.append(projectName).append('/').append(Paths.DIR_WEB_EMBED).append('/').append(doiSuffix);
-                    sb.append("$1$2").append(GeneratePipeline.HTML_EXT).append('\"');
+                    sb.append('\n');
                 }
-                sb.append('\n');
             }
         }
         sb.append('\n');
diff --git a/src/main/java/fr/osug/util/FileUtils.java b/src/main/java/fr/osug/util/FileUtils.java
index bf65e22..21ad1ec 100644
--- a/src/main/java/fr/osug/util/FileUtils.java
+++ b/src/main/java/fr/osug/util/FileUtils.java
@@ -180,7 +180,7 @@ public final class FileUtils {
         if (dir != null) {
             return dir;
         }
-        throw new FileNotFoundException("Invalid directory '" + ((dir == null) ? null : dir.getAbsolutePath()) + "' !");
+        throw new FileNotFoundException("Invalid directory '" + ((dir == null) ? path : dir.getAbsolutePath()) + "' !");
     }
 
     /**
@@ -240,7 +240,7 @@ public final class FileUtils {
         if (file != null) {
             return file;
         }
-        throw new FileNotFoundException("Invalid file '" + ((file == null) ? null : file.getAbsolutePath()) + "' !");
+        throw new FileNotFoundException("Invalid file '" + ((file == null) ? path : file.getAbsolutePath()) + "' !");
     }
 
     // writers :  
-- 
GitLab