Skip to content

Commit

Permalink
Merge pull request #1066 from ShouraySolanki/KN-1071
Browse files Browse the repository at this point in the history
Dialcode_image data publish
  • Loading branch information
pallakartheekreddy authored May 8, 2024
2 parents 4e35580 + 4469b94 commit 1bf360a
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 13 deletions.
3 changes: 1 addition & 2 deletions build/content-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM --platform=linux/x86_64 eclipse-temurin:11.0.20.1_1-jdk-focal
RUN apt-get update \
&& apt-get install unzip \
&& apt-get install curl \
&& apt-get install -y unzip curl \
&& adduser --uid 1001 --home /home/sunbird/ --disabled-login sunbird \
&& mkdir -p /home/sunbird \
&& chown -R sunbird:sunbird /home/sunbird
Expand Down
10 changes: 10 additions & 0 deletions content-api/content-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
<groupId>org.sunbird</groupId>
<artifactId>mimetype-manager</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-classes-epoll</artifactId>
</exclusion>
</exclusions>
<type>jar</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ object DIALManager {

val DIAL_SEARCH_API_URL: String = Platform.config.getString("dial_service.api.base_url") + Platform.config.getString("dial_service.api.search")
val DIALCODE_GENERATE_URI: String = Platform.config.getString("dial_service.api.base_url") + Platform.config.getString("dial_service.api.generate")
val CLOUD_BASE_URL = Platform.getString("cloudstorage.read_base_path", "https://dev.knowlg.sunbird.org")
val DIAL_CONTAINER: String = Platform.getString("cloud_storage_dial_container", "dial")
val DIAL_API_AUTH_KEY: String = ContentConstants.BEARER + Platform.config.getString("dial_service.api.auth_key")
val PASSPORT_KEY: String = Platform.config.getString("graph.passport.key.base")
private val kfClient = new KafkaClient
Expand Down Expand Up @@ -319,7 +321,6 @@ object DIALManager {
val response = ResponseHandler.OK()
val updatedSuccessResponse = getDIALReserveUpdateResponse(response, updateDialCodes.size.asInstanceOf[Integer], contentId, updatedNode)
updatedSuccessResponse.getResult.put(DIALConstants.VERSION_KEY, updatedNode.getMetadata.get(DIALConstants.VERSION_KEY))
println(" publisher ", request.getRequest)
val dialcodes: Map[String, AnyRef] =
updatedSuccessResponse.getResult
.get("reservedDialcodes")
Expand All @@ -340,24 +341,44 @@ object DIALManager {
* prepare qr data
* */


def createRequest(data: Map[String, AnyRef], channel: String, publisher: Option[String], rspObj: Response, request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext) = {

val qrCodeSpecString = request.getRequestString("qrcodespec", "") // Assuming this is a JSON string
val qrCodeSpec = JSON.parseFull(qrCodeSpecString) match {
case Some(map: Map[String, Any]) => map
case _ => Map.empty[String, Any]
}
val mergedConfig: Mmap[String, Any] = defaultConfig.++(qrCodeSpec)

val dialCodesMap = data.map { case (dialcode, index) =>
val fileName = s"$index" + "_" + s"$dialcode"
val dialData = Map(
"data" -> s"https://dev.knowlg.sunbird.org/dial/$dialcode",
"data" -> s"$CLOUD_BASE_URL/$DIAL_CONTAINER/$dialcode",
"text" -> dialcode,
"id" -> fileName
)
val imageData = new util.HashMap[String, AnyRef]()
imageData.put("dialcode", dialcode)
imageData.put("config", mergedConfig.mapValues(_.toString).asJava)
imageData.put("status", Int.box(0))
imageData.put("identifier", fileName)
imageData.put("channel", channel)
imageData.put("publisher", publisher.getOrElse(""))
val imageReq = new Request()
val imageContext = new util.HashMap[String, Object]()
imageContext.putAll(request.getContext)
imageReq.setContext(imageContext)
imageReq.getContext.put("schemaName", "dialcode_image")
imageReq.getContext.put("objectType", "content")
imageReq.putAll(imageData)

oec.dialgraphService.saveExternalProps(imageReq)

dialData
}

val qrCodeSpecString = request.getRequestString("qrcodespec", "") // Assuming this is a JSON string
val qrCodeSpec = JSON.parseFull(qrCodeSpecString) match {
case Some(map: Map[String, Any]) => map
case _ => Map.empty[String, Any]
}
val mergedConfig: Mmap[String, Any] = defaultConfig.++(qrCodeSpec)

val processId = UUID.randomUUID
val dialcodes = dialCodesMap.map(_("text")).toList.asJava
rspObj.getResult.put(DIALConstants.PROCESS_ID, processId)
Expand Down Expand Up @@ -414,6 +435,7 @@ object DIALManager {
val topic: String = DIALTOPIC
val dialEvent = ScalaJsonUtils.serialize(event)
if (StringUtils.isBlank(dialEvent)) throw new ClientException("DIAL_REQUEST_EXCEPTION", "Event is not generated properly.")

kfClient.send(dialEvent, topic)
}

Expand Down Expand Up @@ -555,7 +577,6 @@ object DIALManager {
}})
}})
}}

val headerParam = new util.HashMap[String, String]{put(DIALConstants.X_CHANNEL_ID, channelId); put(DIALConstants.AUTHORIZATION, DIAL_API_AUTH_KEY);}
val generateResponse = oec.httpUtil.post(DIALCODE_GENERATE_URI, requestMap, headerParam)
if (generateResponse.getResponseCode == ResponseCode.OK || generateResponse.getResponseCode == ResponseCode.PARTIAL_SUCCESS) {
Expand Down
6 changes: 4 additions & 2 deletions content-api/content-service/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ content.keyspace = "content_store"
content.metadata.visibility.parent=["textbookunit", "courseunit", "lessonplanunit", "event"]

# Cassandra Configuration
//content.keyspace.name=content_store
//content.keyspace.table=content_data
//content.keyspace.name=dev_content_store
//content.keyspace.table=dev_content_data
#TODO: Add Configuration for assessment. e.g: question_data
orchestrator.keyspace.name=question_store
orchestrator.keyspace.table=question_data
Expand Down Expand Up @@ -495,6 +495,7 @@ dialcode.object_type="DialCode"
#DIAL Code Reserve configuration
kafka.dial.request.topic="sunbirddev.qrimage.request"
dialcode.keyspace=dialcodes
dialcode_image.keyspace=dialcodes

framework.max_term_creation_limit=200

Expand Down Expand Up @@ -762,6 +763,7 @@ cloud_storage_key=""
cloud_storage_secret=""
cloud_storage_container=""
cloud_storage_endpoint=""
cloud_storage_dial_container=""

cloudstorage.metadata.replace_absolute_path=false
cloudstorage.relative_path_prefix= "CONTENT_STORAGE_BASE_PATH"
Expand Down
47 changes: 47 additions & 0 deletions schemas/dialcode_image/1.0/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"objectType": "dialcode_image",
"version": "disable",
"versionCheckMode": "OFF",
"external": {
"tableName": "dialcode_images",
"properties": {
"filename": {
"type": "string"
},
"created_on": {
"type": "string"
},
"dialcode": {
"type": "string"
},
"channel": {
"type": "string"
},
"publisher": {
"type": "string"
},
"config": {
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9_]+$": {
"type": "string"
}
},
"additionalProperties": false
},
"status": {
"type": "integer",
"enum": [
0,
1,
2
]
},
"url": {
"type": "string"
}
},
"primaryKey": ["filename"]
},
"schema_restrict_api": false
}
53 changes: 53 additions & 0 deletions schemas/dialcode_image/1.0/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$id": "dialcode-image-schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Dialcode Image",
"type": "object",
"required": [
"filename",
"dialcode",
"channel",
"publisher",
"config",
"status",
"url"
],
"properties": {
"filename": {
"type": "string"
},
"created_on": {
"type": "string",
"description": "Creation timestamp, likely in ISO 8601 format"
},
"dialcode": {
"type": "string"
},
"channel": {
"type": "string"
},
"publisher": {
"type": "string"
},
"config": {
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9_]+$": {
"type": "string"
}
},
"additionalProperties": false
},
"status": {
"type": "integer",
"enum": [
0,
1,
2
]
},
"url": {
"type": "string"
}
}
}

0 comments on commit 1bf360a

Please sign in to comment.