-
Notifications
You must be signed in to change notification settings - Fork 7
Add reference descriptions and make them and names updateable [AS-512] #221
Changes from all commits
220f145
949fa01
fdaf458
62c7e50
2cab3ee
8d5cc0f
84a3b3f
9b48409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import bio.terra.workspace.common.exception.DataReferenceNotFoundException; | ||
| import bio.terra.workspace.common.exception.DuplicateDataReferenceException; | ||
| import bio.terra.workspace.db.exception.InvalidDaoRequestException; | ||
| import bio.terra.workspace.service.datareference.model.CloningInstructions; | ||
| import bio.terra.workspace.service.datareference.model.DataReference; | ||
| import bio.terra.workspace.service.datareference.model.DataReferenceRequest; | ||
|
|
@@ -10,6 +11,7 @@ | |
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.StringJoiner; | ||
| import java.util.UUID; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -43,14 +45,15 @@ public DataReferenceDao(NamedParameterJdbcTemplate jdbcTemplate) { | |
| public String createDataReference(DataReferenceRequest request, UUID referenceId) | ||
| throws DuplicateDataReferenceException { | ||
| String sql = | ||
| "INSERT INTO workspace_data_reference (workspace_id, reference_id, name, cloning_instructions, reference_type, reference) VALUES " | ||
| + "(:workspace_id, :reference_id, :name, :cloning_instructions, :reference_type, cast(:reference AS json))"; | ||
| "INSERT INTO workspace_data_reference (workspace_id, reference_id, name, reference_description, cloning_instructions, reference_type, reference) VALUES " | ||
| + "(:workspace_id, :reference_id, :name, :reference_description, :cloning_instructions, :reference_type, cast(:reference AS json))"; | ||
|
|
||
| MapSqlParameterSource params = | ||
| new MapSqlParameterSource() | ||
| .addValue("workspace_id", request.workspaceId().toString()) | ||
| .addValue("reference_id", referenceId.toString()) | ||
| .addValue("name", request.name()) | ||
| .addValue("reference_description", request.referenceDescription()) | ||
| .addValue("cloning_instructions", request.cloningInstructions().toSql()) | ||
| .addValue("reference_type", request.referenceType().toSql()) | ||
| .addValue("reference", request.referenceObject().toJson()); | ||
|
|
@@ -71,7 +74,7 @@ public String createDataReference(DataReferenceRequest request, UUID referenceId | |
| /** Retrieve a data reference by ID from the DB. */ | ||
| public DataReference getDataReference(UUID workspaceId, UUID referenceId) { | ||
| String sql = | ||
| "SELECT workspace_id, reference_id, name, cloning_instructions, reference_type, reference from workspace_data_reference where workspace_id = :workspace_id AND reference_id = :reference_id"; | ||
| "SELECT workspace_id, reference_id, name, reference_description, cloning_instructions, reference_type, reference from workspace_data_reference where workspace_id = :workspace_id AND reference_id = :reference_id"; | ||
|
|
||
| MapSqlParameterSource params = | ||
| new MapSqlParameterSource() | ||
|
|
@@ -97,7 +100,7 @@ public DataReference getDataReference(UUID workspaceId, UUID referenceId) { | |
| public DataReference getDataReferenceByName( | ||
| UUID workspaceId, DataReferenceType type, String name) { | ||
| String sql = | ||
| "SELECT workspace_id, reference_id, name, cloning_instructions, reference_type, reference from workspace_data_reference where workspace_id = :id AND reference_type = :type AND name = :name"; | ||
| "SELECT workspace_id, reference_id, name, reference_description, cloning_instructions, reference_type, reference from workspace_data_reference where workspace_id = :id AND reference_type = :type AND name = :name"; | ||
|
|
||
| MapSqlParameterSource params = | ||
| new MapSqlParameterSource() | ||
|
|
@@ -135,6 +138,49 @@ public boolean isControlled(UUID workspaceId, UUID referenceId) { | |
| } | ||
| } | ||
|
|
||
| public boolean updateDataReference( | ||
| UUID workspaceId, UUID referenceId, String name, String referenceDescription) { | ||
| if (name == null && referenceDescription == null) { | ||
| throw new InvalidDaoRequestException("Must specify name or referenceDescription to update."); | ||
| } | ||
|
|
||
| MapSqlParameterSource params = | ||
| new MapSqlParameterSource() | ||
| .addValue("id", referenceId.toString()) | ||
| .addValue("workspace_id", workspaceId.toString()) | ||
| .addValue("name", name) | ||
| .addValue("reference_description", referenceDescription); | ||
|
|
||
| StringJoiner updateStatement = | ||
| new StringJoiner( | ||
| ", ", | ||
| "UPDATE workspace_data_reference SET ", | ||
| " WHERE reference_id = :id AND workspace_id = :workspace_id"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (plus, using |
||
|
|
||
| if (name != null) { | ||
| updateStatement.add("name = :name"); | ||
| } | ||
| if (referenceDescription != null) { | ||
| updateStatement.add("reference_description = :reference_description"); | ||
| } | ||
|
ddietterich marked this conversation as resolved.
|
||
|
|
||
| int rowsAffected = jdbcTemplate.update(updateStatement.toString(), params); | ||
| boolean updated = rowsAffected > 0; | ||
|
|
||
| if (updated) | ||
|
ddietterich marked this conversation as resolved.
|
||
| logger.info( | ||
| String.format( | ||
| "Updated record for data reference %s in workspace %s", | ||
| referenceId.toString(), workspaceId.toString())); | ||
| else | ||
| logger.info( | ||
| String.format( | ||
| "Failed to update record for data reference %s in workspace %s", | ||
| referenceId.toString(), workspaceId.toString())); | ||
|
|
||
| return updated; | ||
| } | ||
|
|
||
| public boolean deleteDataReference(UUID workspaceId, UUID referenceId) { | ||
| MapSqlParameterSource params = | ||
| new MapSqlParameterSource() | ||
|
|
@@ -164,7 +210,7 @@ public boolean deleteDataReference(UUID workspaceId, UUID referenceId) { | |
| // should consider joining and listing those entries here. | ||
| public List<DataReference> enumerateDataReferences(UUID workspaceId, int offset, int limit) { | ||
| String sql = | ||
| "SELECT workspace_id, reference_id, name, cloning_instructions, reference_type, reference" | ||
| "SELECT workspace_id, reference_id, name, reference_description, cloning_instructions, reference_type, reference" | ||
| + " FROM workspace_data_reference" | ||
| + " WHERE workspace_id = :id" | ||
| + " ORDER BY reference_id" | ||
|
|
@@ -189,6 +235,7 @@ public List<DataReference> enumerateDataReferences(UUID workspaceId, int offset, | |
| .workspaceId(UUID.fromString(rs.getString("workspace_id"))) | ||
| .referenceId(UUID.fromString(rs.getString("reference_id"))) | ||
| .name(rs.getString("name")) | ||
| .referenceDescription(rs.getString("reference_description")) | ||
| .referenceType(referenceType) | ||
| .cloningInstructions(CloningInstructions.fromSql(rs.getString("cloning_instructions"))) | ||
| .referenceObject(deserializedReferenceObject) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package bio.terra.workspace.db.exception; | ||
|
|
||
| import bio.terra.common.exception.InternalServerErrorException; | ||
|
|
||
| public class InvalidDaoRequestException extends InternalServerErrorException { | ||
|
|
||
| public InvalidDaoRequestException(String message) { | ||
| super(message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,25 @@ paths: | |
| $ref: '#/components/responses/NotFound' | ||
| '500': | ||
| $ref: '#/components/responses/ServerError' | ||
| patch: | ||
| summary: Update name or description of a data reference in a workspace. | ||
| operationId: updateDataReference | ||
| tags: [Workspace] | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/UpdateDataReferenceRequestBody' | ||
| responses: | ||
| '204': | ||
| description: OK | ||
| '403': | ||
| $ref: '#/components/responses/PermissionDenied' | ||
| '404': | ||
| $ref: '#/components/responses/NotFound' | ||
| '500': | ||
| $ref: '#/components/responses/ServerError' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This satisfies the current Jira ticket, but from an API design perspective it's awkward that we can create and get entire data references, but we can only edit the name/description of those references - we can't edit the innards, such as pointing an existing reference at a different snapshot id. I'm not sure the best way to handle this - possibly just explaining it in the API description. |
||
| delete: | ||
| summary: Deletes a data reference from a workspace. | ||
| operationId: deleteDataReference | ||
|
|
@@ -606,6 +625,8 @@ components: | |
| properties: | ||
| name: | ||
| $ref: "#/components/schemas/Name" | ||
| referenceDescription: | ||
| type: string | ||
| resourceId: | ||
| description: The ID of the resource | ||
| type: string | ||
|
|
@@ -617,6 +638,14 @@ components: | |
| cloningInstructions: | ||
| $ref: '#/components/schemas/CloningInstructionsEnum' | ||
|
|
||
| UpdateDataReferenceRequestBody: | ||
| type: object | ||
| properties: | ||
| name: | ||
| $ref: "#/components/schemas/Name" | ||
| referenceDescription: | ||
| type: string | ||
|
|
||
| DataReferenceDescription: | ||
| type: object | ||
| required: [referenceId, name, workspaceId, cloningInstructions] | ||
|
|
@@ -628,6 +657,8 @@ components: | |
| name: | ||
| description: The name of the data reference; used to refer to the reference | ||
| type: string | ||
| referenceDescription: | ||
| type: string | ||
| workspaceId: | ||
| description: The ID of the workspace containing the reference | ||
| type: string | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.