Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #KN-000 fix: Term API enhancement to create multiple terms with…
Browse files Browse the repository at this point in the history
… right data
aimansharief committed Jun 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f6fb77d commit e46f039
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -38,23 +38,27 @@ class TermActor @Inject()(implicit oec: OntologyEngineContext) extends BaseActor
@throws[Exception]
private def create(request: Request): Future[Response] = {
val requestList: util.List[util.Map[String, AnyRef]] = getRequestData(request)
request.getRequest.remove("term")
if (TERM_CREATION_LIMIT < requestList.size) throw new ClientException("ERR_INVALID_TERM_REQUEST", "No. of request exceeded max limit of " + TERM_CREATION_LIMIT)
RequestUtil.restrictProperties(request)
val frameworkId = request.getRequest.getOrDefault(Constants.FRAMEWORK, "").asInstanceOf[String]
val CategoryData = validateCategoryInstance(request)
val categoryId = generateIdentifier(frameworkId, request.getRequest.getOrDefault(Constants.CATEGORY, "").asInstanceOf[String])
CategoryData.flatMap(node => {
if (null != node && StringUtils.equalsAnyIgnoreCase(node.getIdentifier, categoryId)) {
val categoryList = new util.ArrayList[Map[String, AnyRef]]
val relationMap = new util.HashMap[String, AnyRef]
relationMap.put("identifier", categoryId)
relationMap.put("index", getIndex(node))
categoryList.add(relationMap)
request.put("categories", categoryList)
val identifier = new util.ArrayList[String]
var codeError = 0
var serverError = 0
val index: Integer = getIndex(node)
var i: Integer = 0
val future = requestList.asScala.map(req => {
val categoryList = new util.ArrayList[util.Map[String, AnyRef]]
val relationMap = new util.HashMap[String, AnyRef]
relationMap.put("identifier", categoryId)
relationMap.put("index", (index + i).asInstanceOf[Integer])
i = (i + 1)
categoryList.add(relationMap)
request.put("categories", categoryList)
request.getRequest.put(Constants.IDENTIFIER, generateIdentifier(categoryId, req.getOrDefault(Constants.CODE, "").asInstanceOf[String]))
request.getRequest.putAll(req)
DataNode.create(request).map(termNode =>
@@ -67,7 +71,7 @@ class TermActor @Inject()(implicit oec: OntologyEngineContext) extends BaseActor
}
})
Future.sequence(future).flatMap { _ =>
createResponse(codeError, serverError, identifier, requestList.size)
createResponse(codeError, serverError, identifier, requestList.size)
}
} else throw new ClientException("ERR_INVALID_CATEGORY_ID", "Please provide valid category")
})

0 comments on commit e46f039

Please sign in to comment.