Skip to content

Commit

Permalink
Issue #IQ-545 fix: added loggers and custom exception
Browse files Browse the repository at this point in the history
  • Loading branch information
krgauraw committed Aug 7, 2023
1 parent c5b9931 commit 7adee09
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.sunbird.job.quml.migrator.exceptions

class QumlMigrationException(message: String) extends java.lang.Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import org.sunbird.job.domain.`object`.ObjectDefinition
import org.sunbird.job.quml.migrator.domain.{ExtDataConfig, ObjectData, ObjectExtData}
import org.sunbird.job.quml.migrator.exceptions.QumlMigrationException
import org.sunbird.job.quml.migrator.task.QumlMigratorConfig
import org.sunbird.job.util._

Expand Down Expand Up @@ -89,15 +90,18 @@ trait QuestionMigrator extends MigrationObjectReader with MigrationObjectUpdater
val migratedExtData = migrateExtData(data.identifier, extMeta)
migratedExtData.remove("primaryCategory")
val migrGrpahData: util.Map[String, AnyRef] = migrateGrpahData(data.identifier, jMap)
if(migrGrpahData.containsKey("bloomsLevel")) migrGrpahData.remove("bloomsLevel")
migrGrpahData.remove("bloomsLevel")
migrGrpahData.remove("version")
val updatedMeta: Map[String, AnyRef] = migrGrpahData.asScala.toMap ++ Map[String, AnyRef]("qumlVersion" -> 1.1.asInstanceOf[AnyRef], "schemaVersion" -> "1.1", "migrationVersion" -> 3.0.asInstanceOf[AnyRef])
logger.info("QuestionMigrator ::: migrateQuestion ::: migrated metadata :::: "+migrGrpahData)
logger.info("QuestionMigrator ::: migrateQuestion ::: migrated ext data :::: "+migratedExtData)
logger.info("QuestionMigrator ::: migrateQuestion ::: Completed Data Transformation For : " + data.identifier)
Some(new ObjectData(data.identifier, updatedMeta, Some(migratedExtData.asScala.toMap), data.hierarchy))
} catch {
case e: Exception => {
case e: java.lang.Exception => {
logger.info("QuestionMigrator ::: migrateQuestion ::: Failed Data Transformation For : " + data.identifier)
logger.info("QuestionMigrator ::: migrateQuestion ::: exception message :: "+ e.getMessage)
logger.info("QuestionMigrator ::: migrateQuestion ::: exception message :: "+ e.getLocalizedMessage)
e.printStackTrace()
val updatedMeta: Map[String, AnyRef] = data.metadata ++ Map[String, AnyRef]("migrationVersion" -> 2.1.asInstanceOf[AnyRef], "migrationError"->e.getMessage)
Some(new ObjectData(data.identifier, updatedMeta, data.extData, data.hierarchy))
Expand All @@ -114,8 +118,9 @@ trait QuestionMigrator extends MigrationObjectReader with MigrationObjectUpdater
} else data
} catch {
case e: Exception => {
logger.info(s"QuestionMigrator ::: migrateGrpahData ::: Error occurred while converting graph data for ${identifier} | Error: " +e.getMessage)
e.printStackTrace()
throw new Exception(s"Error Occurred While Converting Graph Data To Quml 1.1 Format for ${identifier}")
throw new QumlMigrationException(s"Error Occurred While Converting Graph Data To Quml 1.1 Format for ${identifier} | Error: "+e.getMessage)
}
}
}
Expand All @@ -134,9 +139,10 @@ trait QuestionMigrator extends MigrationObjectReader with MigrationObjectUpdater
data
} else data
} catch {
case e: Exception => {
case e: java.lang.Exception => {
e.printStackTrace()
throw new Exception(s"Error Occurred While Converting External Data To Quml 1.1 Format for ${identifier}")
logger.info(s"QuestionMigrator ::: migrateExtData ::: Error occurred while converting external data for ${identifier} | Error: " + e.getMessage )
throw new QumlMigrationException(s"Error Occurred While Converting External Data To Quml 1.1 Format for ${identifier} | Error: "+e.getMessage)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.datastax.driver.core.Row
import com.datastax.driver.core.querybuilder.{Clause, Insert, QueryBuilder}
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import org.sunbird.job.domain.`object`.{ObjectDefinition}
import org.sunbird.job.domain.`object`.ObjectDefinition
import org.sunbird.job.quml.migrator.domain.{ExtDataConfig, ObjectData, ObjectExtData}
import org.sunbird.job.quml.migrator.exceptions.QumlMigrationException
import org.sunbird.job.quml.migrator.task.QumlMigratorConfig
import org.sunbird.job.util.{CassandraUtil, Neo4JUtil, ScalaJsonUtil}

Expand All @@ -18,6 +19,8 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda

private[this] val logger = LoggerFactory.getLogger(classOf[QuestionSetMigrator])

val propsToRemove = List("outcomeDeclaration", "bloomsLevel", "maxScore","version")

def validateQuestionSet(identifier: String, obj: ObjectData)(implicit neo4JUtil: Neo4JUtil): List[String] = {
val messages = ListBuffer[String]()
if (obj.hierarchy.getOrElse(Map()).isEmpty) messages += s"""There is no hierarchy available for : $identifier"""
Expand Down Expand Up @@ -98,19 +101,20 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda
val migrGrpahData: util.Map[String, AnyRef] = migrateGrpahData(data.identifier, metaMap)
val migrExtData: util.Map[String, AnyRef] = migrateExtData(data.identifier, extMeta)
val outcomeDeclaration: util.Map[String, AnyRef] = migrGrpahData.getOrDefault("outcomeDeclaration", Map[String, AnyRef]()).asInstanceOf[util.Map[String, AnyRef]]
migrGrpahData.remove("outcomeDeclaration")
propsToRemove.foreach(prop => migrGrpahData.remove(prop))
migrExtData.put("outcomeDeclaration", outcomeDeclaration)
val migrHierarchy: util.Map[String, AnyRef] = migrateHierarchy(data.identifier, hierarchyData)

logger.info("migrateQuestionSet :: migrated graph data ::: " + migrGrpahData)
logger.info("migrateQuestionSet :: migrated ext data ::: " + migrExtData)
logger.info("migrateQuestionSet :: migrated hierarchy ::: " + migrHierarchy)
val updatedMeta: Map[String, AnyRef] = migrGrpahData.asScala.toMap ++ Map[String, AnyRef]("qumlVersion" -> 1.1.asInstanceOf[AnyRef], "schemaVersion" -> "1.1", "migrationVersion" -> 3.0.asInstanceOf[AnyRef])
logger.info("QuestionSetMigrator ::: migrateQuestionSet ::: Completed Data Transformation For : " + data.identifier)
Some(new ObjectData(data.identifier, updatedMeta, Some(migrExtData.asScala.toMap), Some(migrHierarchy.asScala.toMap)))
} catch {
case e: Exception => {
case e: java.lang.Exception => {
logger.info("QuestionSetMigrator ::: migrateQuestionSet ::: Failed Data Transformation For : " + data.identifier)
logger.info("QuestionSetMigrator ::: migrateQuestionSet ::: exception message :: "+ e.getMessage)
logger.info("QuestionSetMigrator ::: migrateQuestionSet ::: exception message :: "+ e.getLocalizedMessage)
val updatedMeta: Map[String, AnyRef] = data.metadata ++ Map[String, AnyRef]("migrationVersion" -> 2.1.asInstanceOf[AnyRef], "migrationError"->e.getMessage)
Some(new ObjectData(data.identifier, updatedMeta, data.extData, data.hierarchy))
}
Expand All @@ -127,9 +131,10 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda
data
} else data
} catch {
case e: Exception => {
case e: java.lang.Exception => {
e.printStackTrace()
throw new Exception(s"Error Occurred While Converting Graph Data To Quml 1.1 Format for ${identifier}")
logger.info(s"QuestionSetMigrator :: migrateGrpahData ::: Error Occurred While Graph Data Transformation For ${identifier} | Error: "+ e.getMessage)
throw new QumlMigrationException(s"Error Occurred While Converting Graph Data To Quml 1.1 Format for ${identifier} | Error: "+e.getMessage)
}
}
}
Expand All @@ -141,9 +146,10 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda
data
} else data
} catch {
case e: Exception => {
case e: java.lang.Exception => {
e.printStackTrace()
throw new Exception(s"Error Occurred While Converting External Data To Quml 1.1 Format for ${identifier}")
logger.info(s"QuestionSetMigrator :: migrateExtData ::: Error Occurred While External Data Transformation For ${identifier} | Error: "+ e.getMessage)
throw new QumlMigrationException(s"Error Occurred While Converting External Data To Quml 1.1 Format for ${identifier} | Error : "+e.getMessage)
}
}
}
Expand All @@ -168,9 +174,10 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda
data
} else data
} catch {
case e: Exception => {
case e: java.lang.Exception => {
logger.info(s"QuestionSetMigrator :: migrateHierarchy ::: Error Occurred While Hierarchy Data Transformation For ${identifier} | Error: "+ e.getMessage)
e.printStackTrace()
throw new Exception(s"Error Occurred While Converting Hierarchy Data To Quml 1.1 Format for ${identifier}")
throw new QumlMigrationException(s"Error Occurred While Converting Hierarchy Data To Quml 1.1 Format for ${identifier} | Error: "+e.getMessage)
}
}
}
Expand Down Expand Up @@ -198,10 +205,8 @@ trait QuestionSetMigrator extends MigrationObjectReader with MigrationObjectUpda
val chStr = ScalaJsonUtil.serialize(chData)
val chMap: util.Map[String, AnyRef] = mapper.readValue(chStr, classOf[util.Map[String, AnyRef]])
ch.putAll(chMap)
} else throw new Exception(s"Please migrate children having identifier ${childrenId}")
} else throw new QumlMigrationException(s"Please migrate children having identifier ${childrenId}")
}


})
}
}
Expand Down

0 comments on commit 7adee09

Please sign in to comment.