Defect fix for YANG revision

Change-Id: I6af5e82122629ea69c40b4fc3159bc7712d8293d
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index 2159888..ef302be 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -17,6 +17,7 @@
 package org.onosproject.yangutils.parser.impl.listeners;
 
 import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangRevision;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
@@ -30,6 +31,7 @@
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
 import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA;
@@ -85,6 +87,13 @@
             yangModule.setVersion((byte) 1);
         }
 
+        if (ctx.moduleBody().revisionStatements().revisionStatement().isEmpty()) {
+            String currentDate = setCurrentDateForRevision();
+            YangRevision currentRevision = new YangRevision();
+            currentRevision.setRevDate(currentDate);
+            yangModule.setRevision(currentRevision);
+        }
+
         listener.getParsedDataStack().push(yangModule);
     }
 
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index 4807f8a..eb16253 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
+import org.onosproject.yangutils.datamodel.YangRevision;
 import org.onosproject.yangutils.datamodel.YangSubModule;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -30,6 +31,7 @@
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
 import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA;
@@ -88,6 +90,13 @@
             yangSubModule.setVersion((byte) 1);
         }
 
+        if (ctx.submoduleBody().revisionStatements().revisionStatement().isEmpty()) {
+            String currentDate = setCurrentDateForRevision();
+            YangRevision currentRevision = new YangRevision();
+            currentRevision.setRevDate(currentDate);
+            yangSubModule.setRevision(currentRevision);
+        }
+
         listener.getParsedDataStack().push(yangSubModule);
     }
 
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 07c8105..39a9bae 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -20,6 +20,7 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.regex.Pattern;
 
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -37,6 +38,11 @@
     private static final String TRUE_KEYWORD = "true";
     private static final String FALSE_KEYWORD = "false";
     private static final int IDENTIFIER_LENGTH = 64;
+    private static final String DATE_FORMAT = "yyyy-MM-dd";
+    private static final String EMPTY_STRING = "";
+    private static final String HYPHEN = "-";
+    private static final String SLASH = "/";
+    private static final String SPACE = " ";
 
     /**
      * Creates a new listener util.
@@ -52,7 +58,7 @@
      */
     public static String removeQuotesAndHandleConcat(String yangStringData) {
 
-        yangStringData = yangStringData.replace("\"", "");
+        yangStringData = yangStringData.replace("\"", EMPTY_STRING);
         String[] tmpData = yangStringData.split(Pattern.quote(PLUS));
         StringBuilder builder = new StringBuilder();
         for (String yangString : tmpData) {
@@ -103,7 +109,7 @@
             return false;
         }
 
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
         sdf.setLenient(false);
 
         try {
@@ -184,4 +190,18 @@
             throw parserException;
         }
     }
+
+    /**
+     * Sets current date and makes it in usable format for revision.
+     *
+     * @return usable current date format for revision
+     */
+    public static String setCurrentDateForRevision() {
+
+        Calendar date = Calendar.getInstance();
+        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+        String dateForRevision = ((dateFormat.format(date.getTime())).replaceAll(SLASH, HYPHEN)).replaceAll(SPACE,
+                EMPTY_STRING);
+        return dateForRevision;
+    }
 }
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index 42bf3ab..f5775b3 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -37,8 +37,8 @@
  * Module information extended to support java code generation.
  */
 public class YangJavaModule extends YangModule
-        implements JavaCodeGenerator, HasJavaFileInfo,
-        HasJavaImportData, HasTempJavaCodeFragmentFiles {
+implements JavaCodeGenerator, HasJavaFileInfo,
+HasJavaImportData, HasTempJavaCodeFragmentFiles {
 
     /**
      * Contains the information of the java file being generated.
@@ -76,7 +76,7 @@
     public JavaFileInfo getJavaFileInfo() {
 
         if (javaFileInfo == null) {
-            throw new RuntimeException("Missing java info in java datamodel node");
+            throw new RuntimeException("Missing java info in java datamodel node.");
         }
         return javaFileInfo;
     }
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
index 8226442..2812a36 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
@@ -25,6 +25,7 @@
 import java.io.IOException;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
 import static org.junit.Assert.assertThat;
 
 /**
@@ -64,4 +65,14 @@
 
         YangNode node = manager.getDataModel("src/test/resources/RevisionInValidOrder.yang");
     }
+
+    /**
+     * Checks the revision with current date is created for empty revision statement.
+     */
+    @Test
+    public void processWithoutRevision() throws IOException, ParserException {
+
+        YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang");
+        assertThat(((YangModule) node).getRevision().getRevDate(),   notNullValue());
+    }
 }
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
index c3028de..26d79f4 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
@@ -26,6 +26,7 @@
 import java.io.IOException;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
 import static org.junit.Assert.assertThat;
 
 /**
@@ -107,6 +108,8 @@
         assertThat(yangNode.getBelongsTo().getBelongsToModuleName(), is("ONOS"));
         // Checks for the version value in data model tree.
         assertThat(yangNode.getBelongsTo().getPrefix(), is("On1"));
+        //Checks the revision with current date is created for empty revision statement.
+        assertThat(((YangSubModule) node).getRevision().getRevDate(),   notNullValue());
     }
 
     /**
diff --git a/utils/yangutils/src/test/resources/RevisionAbsence.yang b/utils/yangutils/src/test/resources/RevisionAbsence.yang
new file mode 100644
index 0000000..eb1d1d9
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionAbsence.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+}