carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenliang...@apache.org
Subject [7/9] carbondata-site git commit: Integrated auto generate PDF Functionality
Date Wed, 24 May 2017 04:57:03 GMT
Integrated auto generate PDF Functionality


Project: http://git-wip-us.apache.org/repos/asf/carbondata-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata-site/commit/dd843c69
Tree: http://git-wip-us.apache.org/repos/asf/carbondata-site/tree/dd843c69
Diff: http://git-wip-us.apache.org/repos/asf/carbondata-site/diff/dd843c69

Branch: refs/heads/asf-site
Commit: dd843c69f00b05a73fcdb4fbe24bebe4fe26af8e
Parents: 3a8c7ff
Author: PallaviSingh1992 <pallavisingh_1992@yahoo.co.in>
Authored: Wed May 24 00:26:07 2017 +0530
Committer: PallaviSingh1992 <pallavisingh_1992@yahoo.co.in>
Committed: Wed May 24 00:26:07 2017 +0530

----------------------------------------------------------------------
 carbonscript.sh                          |   4 +-
 pom.xml                                  |  73 ++++++++++++++++----------
 src/main/scala/CleanUp.scala             |  26 +++++++++
 src/main/scala/MDFileConverter.scala     |  21 +++++++-
 src/main/scala/WebsiteLauncher.scala     |  23 ++++++--
 src/main/webapp/pdf/maven-pdf-plugin.pdf | Bin 145272 -> 193057 bytes
 src/site/projectLogo/ApacheLogo.png      | Bin 7241 -> 44839 bytes
 src/site/projectLogo/CarbonDataLogo.png  | Bin 10971 -> 6844 bytes
 src/test/scala/MDFileConverterSpec.scala |   2 +-
 9 files changed, 111 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/carbonscript.sh
----------------------------------------------------------------------
diff --git a/carbonscript.sh b/carbonscript.sh
index 538922d..31453e4 100755
--- a/carbonscript.sh
+++ b/carbonscript.sh
@@ -2,6 +2,8 @@ mvn compile
 
 mvn exec:java -Dexec.mainClass=WebsiteLauncher
 
+mvn pdf:pdf
+
 mvn install
 
-mvn pdf:pdf
\ No newline at end of file
+mvn exec:java -Dexec.mainClass=CleanUp
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a863151..3ebdd73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,16 +56,31 @@
               </execution>
           </executions>
       </plugin>
-
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>exec-maven-plugin</artifactId>
-        <version>1.2.1</version>
-        <configuration>
-          <mainClass>WebsiteLauncher</mainClass>
-        </configuration>
-      </plugin>
-
+        <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>exec-maven-plugin</artifactId>
+            <version>1.2.1</version>
+            <executions>
+                <execution>
+                    <id>first-execution</id>
+                    <goals>
+                        <goal>java</goal>
+                    </goals>
+                    <configuration>
+                        <mainClass>WebsiteLauncher</mainClass>
+                    </configuration>
+                </execution>
+                <execution>
+                    <id>second-execution</id>
+                    <goals>
+                        <goal>java</goal>
+                    </goals>
+                    <configuration>
+                        <mainClass>CleanUp</mainClass>
+                    </configuration>
+                </execution>
+            </executions>
+        </plugin>
       <plugin>
         <groupId>org.mortbay.jetty</groupId>
         <artifactId>jetty-maven-plugin</artifactId>
@@ -173,25 +188,6 @@
                     </configuration>
                 </execution>
                 <execution>
-                    <id>publish-pdf</id>
-                    <phase>install</phase>
-                    <goals>
-                        <goal>copy-resources</goal>
-                    </goals>
-                    <configuration>
-                        <outputDirectory>${basedir}/src/pdf</outputDirectory>
-                        <resources>
-                            <resource>
-                                <directory>${basedir}/target/pdf</directory>
-                                <filtering>false</filtering>
-                                <includes>
-                                    <include>**/*.pdf</include>
-                                </includes>
-                            </resource>
-                        </resources>
-                    </configuration>
-                </execution>
-                <execution>
                     <id>copy-pdf</id>
                     <phase>install</phase>
                     <goals>
@@ -210,6 +206,25 @@
                         </resources>
                     </configuration>
                 </execution>
+                <execution>
+                   <id>publish-pdf</id>
+                   <phase>install</phase>
+                   <goals>
+                       <goal>copy-resources</goal>
+                   </goals>
+                   <configuration>
+                       <outputDirectory>${basedir}/src/main/webapp/pdf</outputDirectory>
+                       <resources>
+                           <resource>
+                               <directory>${basedir}/target/pdf</directory>
+                               <filtering>false</filtering>
+                               <includes>
+                                   <include>**/*.pdf</include>
+                               </includes>
+                           </resource>
+                       </resources>
+                   </configuration>
+               </execution>
             </executions>
         </plugin>
     </plugins>

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/main/scala/CleanUp.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/CleanUp.scala b/src/main/scala/CleanUp.scala
new file mode 100644
index 0000000..de6bf0c
--- /dev/null
+++ b/src/main/scala/CleanUp.scala
@@ -0,0 +1,26 @@
+import java.io.File
+
+import org.slf4j.{Logger, LoggerFactory}
+import services.ConfServiceImpl
+
+object CleanUp {
+  def main(args: Array[String]): Unit = {
+
+    val logger: Logger = LoggerFactory.getLogger("CleanUp")
+
+    val conf = new ConfServiceImpl
+
+    logger.info("Starting clean up after PDF Generation")
+    cleanUp(init(conf.readString("mdFileLocation")))
+    logger.info("Successfully completed clean up after PDF Generation")
+  }
+
+  private def init(path: String): File = {
+    new File(path)
+  }
+
+  private def cleanUp(file: File): Boolean = {
+    file.listFiles.map(file => file.delete())
+    file.delete()
+  }
+}

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/main/scala/MDFileConverter.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/MDFileConverter.scala b/src/main/scala/MDFileConverter.scala
index 4fab013..bc5a6f8 100644
--- a/src/main/scala/MDFileConverter.scala
+++ b/src/main/scala/MDFileConverter.scala
@@ -18,7 +18,7 @@ class MDFileConverter @Inject()(fileService: FileService, confService: ConfServi
     *
     * @return status of each file i.e. success or failure
     */
-  def convertToHtml(): String = {
+  def convertToHtml(status: Boolean): String = {
     val listOfFiles: List[String] = confService.readListOfString("fileList")
     val statusList: List[String] = listOfFiles.map { file =>
       val fileURLContent: String = dataService.dataOnGetRequest(url + file + inputFileExtension)
@@ -27,7 +27,7 @@ class MDFileConverter @Inject()(fileService: FileService, confService: ConfServi
         case Some(data: String) => val fileData = fileReadObject.convertMdExtensions(data)
           logger.info(s"Begin writing [ $file outputFileExtension ] at $location")
           val statusHtmlFile = fileService.writeToFile(location + file + outputFileExtension,
headerContent + fileData + footerContent)
-          val statusMdFile = fileService.writeToFile(confService.readString("mdFileLocation")
+ file + inputFileExtension, fileURLContent)
+          saveMdFilesForPDF(status, fileURLContent, file)
           if (statusHtmlFile) {
             logger.info(s"Successfully written [ $file $outputFileExtension ] at $location")
             "Success"
@@ -50,5 +50,22 @@ class MDFileConverter @Inject()(fileService: FileService, confService:
ConfServi
       "[SUCCESS]: All files converted successfully."
     }
   }
+
+  /**
+    * saves the fetched MD Files for generation of PDF
+    * @param status
+    * @param fileURLContent
+    * @param file
+    * @return
+    */
+  private def saveMdFilesForPDF(status: Boolean, fileURLContent: String, file: String): Boolean
= {
+    if (status) {
+      logger.info(s"[SUCCESS] :Saving Markdown : $file for PDF Generation")
+      fileService.writeToFile(confService.readString("mdFileLocation") + file + inputFileExtension,
fileURLContent)
+    } else {
+      logger.error(s"[ERROR] : Failed to save Markdown :$file for PDF Generation")
+      false
+    }
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/main/scala/WebsiteLauncher.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/WebsiteLauncher.scala b/src/main/scala/WebsiteLauncher.scala
index 7919987..f814769 100644
--- a/src/main/scala/WebsiteLauncher.scala
+++ b/src/main/scala/WebsiteLauncher.scala
@@ -1,13 +1,26 @@
+import java.io.File
+
 import org.slf4j.{Logger, LoggerFactory}
-import services.{ConfServiceImpl, FileServiceImpl, DataServiceImpl}
+import services.{ConfServiceImpl, DataServiceImpl, FileServiceImpl}
 
-object WebsiteLauncher  {
-  def main(args: Array[String]):Unit= {
+object WebsiteLauncher {
+  def main(args: Array[String]): Unit = {
     val logger: Logger = LoggerFactory.getLogger("FileOperationMain")
 
-    val fileObject: MDFileConverter = new MDFileConverter(new FileServiceImpl,new ConfServiceImpl,new
DataServiceImpl)
+    val conf = new ConfServiceImpl
+
+    val file = init(conf.readString("mdFileLocation"))
+
+    val dirStatus = file.mkdir()
+
+    val fileObject: MDFileConverter = new MDFileConverter(new FileServiceImpl, new ConfServiceImpl,
new DataServiceImpl)
 
-    val status: String = fileObject.convertToHtml()
+    val status: String = fileObject.convertToHtml(dirStatus)
     logger.info(s"File Conversion to html : $status")
   }
+
+  private def init(path: String): File = {
+    new File(path)
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/main/webapp/pdf/maven-pdf-plugin.pdf
----------------------------------------------------------------------
diff --git a/src/main/webapp/pdf/maven-pdf-plugin.pdf b/src/main/webapp/pdf/maven-pdf-plugin.pdf
index 5f701eb..290e323 100644
Binary files a/src/main/webapp/pdf/maven-pdf-plugin.pdf and b/src/main/webapp/pdf/maven-pdf-plugin.pdf
differ

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/site/projectLogo/ApacheLogo.png
----------------------------------------------------------------------
diff --git a/src/site/projectLogo/ApacheLogo.png b/src/site/projectLogo/ApacheLogo.png
index 9d25899..c25efca 100644
Binary files a/src/site/projectLogo/ApacheLogo.png and b/src/site/projectLogo/ApacheLogo.png
differ

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/site/projectLogo/CarbonDataLogo.png
----------------------------------------------------------------------
diff --git a/src/site/projectLogo/CarbonDataLogo.png b/src/site/projectLogo/CarbonDataLogo.png
index bc09b23..c1e6f20 100644
Binary files a/src/site/projectLogo/CarbonDataLogo.png and b/src/site/projectLogo/CarbonDataLogo.png
differ

http://git-wip-us.apache.org/repos/asf/carbondata-site/blob/dd843c69/src/test/scala/MDFileConverterSpec.scala
----------------------------------------------------------------------
diff --git a/src/test/scala/MDFileConverterSpec.scala b/src/test/scala/MDFileConverterSpec.scala
index 92d11e6..17f63c0 100644
--- a/src/test/scala/MDFileConverterSpec.scala
+++ b/src/test/scala/MDFileConverterSpec.scala
@@ -31,6 +31,6 @@ class MDFileConverterSpec extends FlatSpec with MockitoSugar {
   val fileModification = new MDFileConverter(fileServiceMock, confServiceMock, dataServiceMock)
 
   it should "return successful convert list of files to html files" in {
-    assert(fileModification.convertToHtml() === "[SUCCESS]: All files converted successfully.")
+    assert(fileModification.convertToHtml(true) === "[SUCCESS]: All files converted successfully.")
   }
 }


Mime
View raw message