Skip to content

Commit

Permalink
Event Update API changes for update, retire
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-tarento committed Nov 6, 2023
1 parent 0546b1f commit 9c2f752
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,11 @@ class EventActor @Inject()(implicit oec: OntologyEngineContext, ss: StorageServi
}

override def update(request: Request): Future[Response] = {
verifyStandaloneEventAndApply(super.update, request, Some(node => {
if (!"Draft".equalsIgnoreCase(node.getMetadata.getOrDefault("status", "").toString)) {
throw new ClientException(ContentConstants.ERR_CONTENT_NOT_DRAFT, "Update not allowed! Event status isn't draft")
}
}))
verifyStandaloneEventAndApply(super.update, request)
}

def publish(request: Request): Future[Response] = {
verifyStandaloneEventAndApply(super.update, request, Some(node => {
if (!"Draft".equalsIgnoreCase(node.getMetadata.getOrDefault("status", "").toString)) {
throw new ClientException(ContentConstants.ERR_CONTENT_NOT_DRAFT, "Publish not allowed! Event status isn't draft")
}
val versionKey = node.getMetadata.getOrDefault("versionKey", "").toString
if (StringUtils.isNotBlank(versionKey))
request.put("versionKey", versionKey)
}))
verifyStandaloneEventAndApply(super.update, request)
}

override def discard(request: Request): Future[Response] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class EventController @Inject()(@Named(ActorNames.EVENT_ACTOR) eventActor: Actor

def publish(identifier: String): Action[AnyContent] = Action.async { implicit request =>
val headers = commonHeaders()
val content = new java.util.HashMap[String, Object]()
val body = requestBody()
val content = body.getOrDefault(schemaName, new java.util.HashMap()).asInstanceOf[java.util.Map[String, Object]];
content.put("status", "Live")
content.put("identifier", identifier)
content.putAll(headers)
Expand All @@ -67,4 +68,14 @@ class EventController @Inject()(@Named(ActorNames.EVENT_ACTOR) eventActor: Actor
getResult(ApiId.PUBLISH_EVENT, eventActor, contentRequest, version = apiVersion)
}

override def retire(identifier: String) = Action.async { implicit request =>
val headers = commonHeaders()
val body = requestBody()
val content = body.getOrDefault(schemaName, new java.util.HashMap()).asInstanceOf[java.util.Map[String, Object]]
content.put("identifier", identifier)
content.putAll(headers)
val contentRequest = getRequest(content, headers, "retireContent")
setRequestContext(contentRequest, version, objectType, schemaName)
getResult(ApiId.RETIRE_CONTENT, eventActor, contentRequest, version = apiVersion)
}
}

0 comments on commit 9c2f752

Please sign in to comment.