Skip to content

Commit

Permalink
Add #364 Data agreement update should not increment version if it is …
Browse files Browse the repository at this point in the history
…draft i.e draft should not have revision
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 25, 2023
1 parent 8c3543a commit 5e4a25a
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions src/v2/handler/dataagreement/config_update_dataagreement.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
common.HandleErrorV2(w, http.StatusInternalServerError, err.Error(), err)
return
}
var currentRevision revision.Revision

// Get revision from db
currentRevision, err := revision.GetLatestByDataAgreementId(dataAgreementId)
currentRevision, err = revision.GetLatestByDataAgreementId(dataAgreementId)
if err != nil {
common.HandleErrorV2(w, http.StatusInternalServerError, err.Error(), err)
return
Expand All @@ -121,24 +123,43 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
// Update life cycle based on active field
lifecycle := setDataAgreementLifecycle(dataAgreementReq.DataAgreement.Active)

// Bump major version for policy
updatedVersion, err := common.BumpMajorVersion(toBeUpdatedDataAgreement.Version)
if err != nil {
m := fmt.Sprintf("Failed to bump major version for data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
toBeUpdatedDataAgreement.Version = updatedVersion
toBeUpdatedDataAgreement.ControllerName = o.Name
toBeUpdatedDataAgreement.ControllerUrl = o.EulaURL
toBeUpdatedDataAgreement.Lifecycle = lifecycle

// Update revision
newRevision, err := revision.UpdateRevisionForDataAgreement(toBeUpdatedDataAgreement, &currentRevision, orgAdminId)
if err != nil {
m := fmt.Sprintf("Failed to update revision for data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
if lifecycle == config.Complete {
// Bump major version for policy
updatedVersion, err := common.BumpMajorVersion(toBeUpdatedDataAgreement.Version)
if err != nil {
m := fmt.Sprintf("Failed to bump major version for data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
toBeUpdatedDataAgreement.Version = updatedVersion

// Update revision
newRevision, err := revision.UpdateRevisionForDataAgreement(toBeUpdatedDataAgreement, &currentRevision, orgAdminId)
if err != nil {
m := fmt.Sprintf("Failed to update revision for data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Save the previous revision to db
updatedRevision, err := revision.Update(currentRevision)
if err != nil {
m := fmt.Sprintf("Failed to update revision: %v", updatedRevision.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Save the revision to db
currentRevision, err = revision.Add(newRevision)
if err != nil {
m := fmt.Sprintf("Failed to create new data agreement: %v", newRevision.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
}

// Save the data agreement to db
Expand All @@ -149,28 +170,12 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) {
return
}

// Save the previous revision to db
updatedRevision, err := revision.Update(currentRevision)
if err != nil {
m := fmt.Sprintf("Failed to update revision: %v", updatedRevision.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Save the revision to db
savedRevision, err := revision.Add(newRevision)
if err != nil {
m := fmt.Sprintf("Failed to create new data agreement: %v", newRevision.Id)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Constructing the response
var resp updateDataAgreementResp
resp.DataAgreement = savedDataAgreement

var revisionForHTTPResponse revision.RevisionForHTTPResponse
revisionForHTTPResponse.Init(savedRevision)
revisionForHTTPResponse.Init(currentRevision)
resp.Revision = revisionForHTTPResponse

response, _ := json.Marshal(resp)
Expand Down

0 comments on commit 5e4a25a

Please sign in to comment.