public function writeToDatabase()
 {
     ignore_user_abort(true);
     $db_name = Request::all()['name'];
     $db_name = str_replace(" ", "_", $db_name);
     $feature_extraction = Request::all()['feature'];
     $neo = new Neo4JConnector('default', 'http', 'localhost', 7474, 'neo4j', 'aiscu');
     $validator = new Neo4JValidator($neo->getConnector());
     while ($av = $validator->isWriteLocked()) {
         if (!$av) {
             sleep(rand(1, 10));
             continue;
         }
     }
     try {
         $isGranted = $neo->grantLock($db_name);
         if ($isGranted) {
             $command = "java -Xmx6G -XX:+CMSClassUnloadingEnabled -jar java/data-importer/target/data-importer-1.0-SNAPSHOT.jar " . $db_name . ' ' . $feature_extraction . ' 2>&1';
             $output = shell_exec($command);
             Log::info($command);
             Log::info($output);
             if (preg_match('/Exception/', $output)) {
                 throw new \Exception("Error occured while writing input data to database. Please check logging file.");
             }
             $neo->execQuery('CREATE (n:Database {name: "' . $db_name . '"})');
         } else {
             throw new \Exception("Locking database is denied.");
         }
     } catch (Exception $e) {
         throw new \Exception($e);
     } finally {
         $isReleased = $neo->releaseLock();
         $filename1 = $db_name . '_cdr';
         $filename2 = $db_name . '_profile';
         unlink(storage_path() . '/tmp_db_store/' . $filename1);
         unlink(storage_path() . '/tmp_db_store/' . $filename2);
         if (!$isReleased) {
             throw new \Exception("Database can't be unlocked. Manually unlocking is needed.");
         }
     }
     return 'success';
 }