Copilot commented on code in PR #6952: URL: https://github.com/apache/texera/pull/6952#discussion_r3678498571
########## sql/updates/29.sql: ########## @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +\c texera_db + +SET search_path TO texera_db; + +BEGIN; + +CREATE TABLE IF NOT EXISTS dataset_contributor +( + cid SERIAL PRIMARY KEY, + did INT NOT NULL, + name VARCHAR(256) NOT NULL, + creator BOOLEAN NOT NULL DEFAULT FALSE, + email VARCHAR(256), + affiliation VARCHAR(256), + comments TEXT, + FOREIGN KEY (did) REFERENCES dataset(did) ON DELETE CASCADE Review Comment: The linked issue (#6926) calls out a distinct contributor **Role** field, but the new schema/API uses a free-text `comments` field instead (no `role` column/field). If the intent is to satisfy the issue’s contract, consider adding a dedicated `role` column (and corresponding API field) or renaming `comments` to `role` and updating any docs/UI plans accordingly. ########## 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: `Contributor` models `affiliation`, `email`, and `comments` as non-optional `String` constructor params without defaults, but the DB schema allows them to be NULL and the tests already pass `null` for `comments`. This makes the JSON contract ambiguous and can force clients to send fields that are meant to be optional. Consider giving these fields default values (or switching to `Option[String]` in a broader refactor) so omitted fields deserialize cleanly and the type better reflects optionality. ########## file-service/src/main/scala/org/apache/texera/service/resource/DatasetResource.scala: ########## @@ -494,6 +564,31 @@ class DatasetResource extends LazyLogging { } } + @POST + @Consumes(Array(MediaType.APPLICATION_JSON)) + @Produces(Array(MediaType.APPLICATION_JSON)) + @RolesAllowed(Array("REGULAR", "ADMIN")) + @Path("/{did}/update/contributors") + def updateDatasetContributors( + @PathParam("did") did: Integer, + modificator: DatasetContributorsModification, + @Auth user: SessionUser + ): Response = { Review Comment: API path/parameter style is inconsistent with existing dataset update endpoints in this resource: `updateDatasetDescription` / `updateDatasetName` use `/update/...` with `did` in the JSON body, while `updateDatasetContributors` uses `/{did}/update/contributors` with `did` as a path param. Consider aligning this endpoint with the established pattern to reduce client-side inconsistency. -- 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]
