Skip to content

Commit

Permalink
fix owners patch issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mohityadav766 committed Sep 18, 2024
1 parent 55a0272 commit 512911a
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,10 @@ public final PatchResponse<T> patch(UriInfo uriInfo, UUID id, String user, JsonP
updated.setUpdatedAt(System.currentTimeMillis());

prepareInternal(updated, true);
populateOwners(updated.getOwners());
// Validate and populate owners
List<EntityReference> validateOwners = validateAndGetOwners(updated.getOwners());
updated.setOwners(validateOwners);

restorePatchAttributes(original, updated);

// Update the attributes and relationships of an entity
Expand Down Expand Up @@ -966,7 +969,9 @@ public final PatchResponse<T> patch(UriInfo uriInfo, String fqn, String user, Js
updated.setUpdatedAt(System.currentTimeMillis());

prepareInternal(updated, true);
populateOwners(updated.getOwners());
// Validate and populate owners
List<EntityReference> validateOwners = validateAndGetOwners(updated.getOwners());
updated.setOwners(validateOwners);
restorePatchAttributes(original, updated);

// Update the attributes and relationships of an entity
Expand Down Expand Up @@ -1972,21 +1977,17 @@ public final void inheritReviewers(T entity, Fields fields, EntityInterface pare
}
}

protected void populateOwners(List<EntityReference> owners) {
protected List<EntityReference> validateAndGetOwners(List<EntityReference> owners) {
if (nullOrEmpty(owners)) {
return;
return owners;
}
// populate owner entityRefs with all fields
List<EntityReference> refs = validateOwners(owners);
if (nullOrEmpty(refs)) {
return;
return owners;
}
refs.sort(Comparator.comparing(EntityReference::getName));
owners.sort(Comparator.comparing(EntityReference::getName));

for (int i = 0; i < owners.size(); i++) {
EntityUtil.copy(refs.get(i), owners.get(i));
}
return refs;
}

@Transaction
Expand Down

0 comments on commit 512911a

Please sign in to comment.