xuang7 commented on code in PR #6952:
URL: https://github.com/apache/texera/pull/6952#discussion_r3693804309
##########
file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala:
##########
@@ -175,12 +176,74 @@ object DatasetResource {
normalized
}
+ /**
+ * Helper function to get the contributors using the did
+ */
+ def getContributorsByDid(ctx: DSLContext, did: Integer): List[Contributor] =
{
+ ctx
+ .selectFrom(DATASET_CONTRIBUTOR)
+ .where(DATASET_CONTRIBUTOR.DID.eq(did))
+ .fetch()
+ .asScala
+ .toList
+ .map { record =>
+ Contributor(
+ name = record.getName,
+ creator = record.getCreator,
+ affiliation = record.getAffiliation,
+ email = record.getEmail,
+ comments = record.getComments
+ )
+ }
+ }
+
+ /**
+ * Helper function to insert the contributors of a dataset in one batch
+ */
+ def insertContributors(ctx: DSLContext, did: Integer, contributors:
List[Contributor]): Unit = {
+ if (contributors.isEmpty) {
+ return
+ }
+ val records = contributors.map { contributor =>
+ if (contributor == null || contributor.name == null ||
contributor.name.trim.isEmpty) {
+ throw new BadRequestException("Each contributor must have a name")
+ }
+ if (
+ contributor.name.length > 256 ||
+ Option(contributor.email).exists(_.length > 256) ||
+ Option(contributor.affiliation).exists(_.length > 256)
+ ) {
+ throw new BadRequestException("Contributor fields must not exceed 256
characters")
+ }
+ val record = ctx.newRecord(DATASET_CONTRIBUTOR)
+ record.setDid(did)
+ record.setName(contributor.name)
+ record.setCreator(contributor.creator)
+ record.setAffiliation(contributor.affiliation)
+ record.setEmail(contributor.email)
+ record.setComments(contributor.comments)
+ record
+ }
+ ctx.batchInsert(records.asJava).execute()
+ }
+
+ case class Contributor(
+ name: String,
+ creator: Boolean = false,
+ affiliation: String,
+ email: String,
+ comments: String
+ )
Review Comment:
Updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]