Skip to content

Commit

Permalink
Removed RDF config variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
robkooper authored and lmarini committed Feb 3, 2020
1 parent 7ea32ff commit 8eb7234
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 266 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.8.1 - 2020-01-29

### Removed
- Removed unused RDF libraries. This was probably used by the rdf/xml functionality that was removed a while back but
the dependencies were never removed.
- Removed Jena validation of JSON-LD metadata. It was creating a blank graph and clients couldn't upload metadata when
Clowder runs in a location that doesn't not have access to https://clowderframework.org/contexts/metadata.jsonld.

### Added
- Scripts to migrate files on disk AWS S3.
[CATS-1034](https://opensource.ncsa.illinois.edu/jira/browse/CATS-1034)
Expand Down
91 changes: 38 additions & 53 deletions app/api/Datasets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -622,66 +622,51 @@ class Datasets @Inject()(
datasets.get(id) match {
case Some(x) => {
val json = request.body
// parse request for JSON-LD model
var model: RDFModel = null
json.validate[RDFModel] match {
case e: JsError => {
Logger.error("Errors: " + JsError.toFlatForm(e))
BadRequest(JsError.toFlatJson(e))
}
case s: JsSuccess[RDFModel] => {
model = s.get

//parse request for agent/creator info
//creator can be UserAgent or ExtractorAgent
var creator: models.Agent = null
json.validate[Agent] match {
case s: JsSuccess[Agent] => {
creator = s.get

// check if the context is a URL to external endpoint
val contextURL: Option[URL] = (json \ "@context").asOpt[String].map(new URL(_))

// check if context is a JSON-LD document
val contextID: Option[UUID] = (json \ "@context").asOpt[JsObject]
.map(contextService.addContext(new JsString("context name"), _))

// when the new metadata is added
val createdAt = new Date()

//parse the rest of the request to create a new models.Metadata object
val attachedTo = ResourceRef(ResourceRef.dataset, id)
val content = (json \ "content")
val version = None
val metadata = models.Metadata(UUID.generate, attachedTo, contextID, contextURL, createdAt, creator,
content, version)

//add metadata to mongo
val metadataId = metadataService.addMetadata(metadata)
val mdMap = metadata.getExtractionSummary

//send RabbitMQ message
current.plugin[RabbitmqPlugin].foreach { p =>
p.metadataAddedToResource(metadataId, metadata.attachedTo, mdMap, Utils.baseUrl(request), request.apiKey, request.user)
}

events.addObjectEvent(request.user, id, x.name,EventType.ADD_METADATA_DATASET.toString)
//parse request for agent/creator info
json.validate[Agent] match {
case s: JsSuccess[Agent] => {
val creator = s.get

// check if the context is a URL to external endpoint
val contextURL: Option[URL] = (json \ "@context").asOpt[String].map(new URL(_))

// check if context is a JSON-LD document
val contextID: Option[UUID] = (json \ "@context").asOpt[JsObject]
.map(contextService.addContext(new JsString("context name"), _))

// when the new metadata is added
val createdAt = new Date()

//parse the rest of the request to create a new models.Metadata object
val attachedTo = ResourceRef(ResourceRef.dataset, id)
val content = (json \ "content")
val version = None
val metadata = models.Metadata(UUID.generate, attachedTo, contextID, contextURL, createdAt, creator,
content, version)

//add metadata to mongo
val metadataId = metadataService.addMetadata(metadata)
val mdMap = metadata.getExtractionSummary

//send RabbitMQ message
current.plugin[RabbitmqPlugin].foreach { p =>
p.metadataAddedToResource(metadataId, metadata.attachedTo, mdMap, Utils.baseUrl(request), request.apiKey, request.user)
}

datasets.index(id)
Ok(toJson("Metadata successfully added to db"))
events.addObjectEvent(request.user, id, x.name, EventType.ADD_METADATA_DATASET.toString)

}
case e: JsError => {
Logger.error("Error getting creator");
BadRequest(toJson(s"Creator data is missing or incorrect."))
}
}
datasets.index(id)
Ok(toJson("Metadata successfully added to db"))
}
case e: JsError => {
Logger.error("Error getting creator");
BadRequest(toJson(s"Creator data is missing or incorrect."))
}
}
}
case None => Logger.error(s"Error getting dataset $id"); NotFound
}
}
}


def getMetadataDefinitions(id: UUID, currentSpace: Option[String]) = PermissionAction(Permission.AddMetadata, Some(ResourceRef(ResourceRef.dataset, id))) { implicit request =>
Expand Down
116 changes: 45 additions & 71 deletions app/api/Files.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,66 +309,53 @@ class Files @Inject()(
files.get(id) match {
case Some(x) => {
val json = request.body
//parse request for agent/creator info
//creator can be UserAgent or ExtractorAgent
var creator: models.Agent = null
json.validate[Agent] match {
case s: JsSuccess[Agent] => {
creator = s.get
//if creator is found, continue processing
val context: JsValue = (json \ "@context")

// check if the context is a URL to external endpoint
val contextURL: Option[URL] = context.asOpt[String].map(new URL(_))

// check if context is a JSON-LD document
val contextID: Option[UUID] =
if (context.isInstanceOf[JsObject]) {
context.asOpt[JsObject].map(contextService.addContext(new JsString("context name"), _))
} else if (context.isInstanceOf[JsArray]) {
context.asOpt[JsArray].map(contextService.addContext(new JsString("context name"), _))
} else None

// when the new metadata is added
val createdAt = Parsers.parseDate((json \ "created_at")).fold(new Date())(_.toDate)

//parse the rest of the request to create a new models.Metadata object
val attachedTo = ResourceRef(ResourceRef.file, id)
val content = (json \ "content")
val version = None
val metadata = models.Metadata(UUID.generate, attachedTo, contextID, contextURL, createdAt, creator,
content, version)

//add metadata to mongo
val metadataId = metadataService.addMetadata(metadata)
val mdMap = metadata.getExtractionSummary

//send RabbitMQ message
current.plugin[RabbitmqPlugin].foreach { p =>
p.metadataAddedToResource(metadataId, metadata.attachedTo, mdMap, Utils.baseUrl(request), request.apiKey, request.user)
}

// parse request for JSON-LD model
var model: RDFModel = null
json.validate[RDFModel] match {
case e: JsError => {
Logger.error("Errors: " + JsError.toFlatForm(e) + "\n\t" + json.toString())
BadRequest(JsError.toFlatJson(e))
}
case s: JsSuccess[RDFModel] => {
model = s.get

//parse request for agent/creator info
//creator can be UserAgent or ExtractorAgent
var creator: models.Agent = null
json.validate[Agent] match {
case s: JsSuccess[Agent] => {
creator = s.get
//if creator is found, continue processing
val context: JsValue = (json \ "@context")

// check if the context is a URL to external endpoint
val contextURL: Option[URL] = context.asOpt[String].map(new URL(_))

// check if context is a JSON-LD document
val contextID: Option[UUID] =
if (context.isInstanceOf[JsObject]) {
context.asOpt[JsObject].map(contextService.addContext(new JsString("context name"), _))
} else if (context.isInstanceOf[JsArray]) {
context.asOpt[JsArray].map(contextService.addContext(new JsString("context name"), _))
} else None

// when the new metadata is added
val createdAt = Parsers.parseDate((json \ "created_at")).fold(new Date())(_.toDate)

//parse the rest of the request to create a new models.Metadata object
val attachedTo = ResourceRef(ResourceRef.file, id)
val content = (json \ "content")
val version = None
val metadata = models.Metadata(UUID.generate, attachedTo, contextID, contextURL, createdAt, creator,
content, version)

//add metadata to mongo
val metadataId = metadataService.addMetadata(metadata)
val mdMap = metadata.getExtractionSummary

//send RabbitMQ message
current.plugin[RabbitmqPlugin].foreach { p =>
p.metadataAddedToResource(metadataId, metadata.attachedTo, mdMap, Utils.baseUrl(request), request.apiKey, request.user)
}

events.addObjectEvent(request.user, id, x.filename, EventType.ADD_METADATA_FILE.toString)
events.addObjectEvent(request.user, id, x.filename, EventType.ADD_METADATA_FILE.toString)

files.index(id)
Ok(toJson("Metadata successfully added to db"))
}
case e: JsError => {
Logger.error("Error getting creator")
BadRequest(toJson(s"Creator data is missing or incorrect."))
}
}
files.index(id)
Ok(toJson("Metadata successfully added to db"))
}
case e: JsError => {
Logger.error("Error getting creator")
BadRequest(toJson(s"Creator data is missing or incorrect."))
}
}
}
Expand All @@ -382,17 +369,6 @@ class Files @Inject()(
try {
val fileList: JsValue = (json \ "files")
val metadata: JsValue = (json \ "metadata")

// parse request for JSON-LD model
var model: RDFModel = null
metadata.validate[RDFModel] match {
case e: JsError => {
Logger.error("Errors: " + JsError.toFlatForm(e) + "\n\t" + metadata.toString())
BadRequest(JsError.toFlatJson(e))
}
case s: JsSuccess[RDFModel] => {
model = s.get

//parse request for agent/creator info
//creator can be UserAgent or ExtractorAgent
var creator: models.Agent = null
Expand Down Expand Up @@ -444,8 +420,6 @@ class Files @Inject()(
Logger.error("Error getting creator")
BadRequest(toJson(s"Creator data is missing or incorrect."))
}
}
}
}
} catch {
case e: ClassCastException => {
Expand Down
Loading

0 comments on commit 8eb7234

Please sign in to comment.