Skip to content

Commit

Permalink
Explicit index updating with onStatusChange interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangf1122 committed Jan 15, 2024
1 parent 8a49652 commit 71368be
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected String createDraft(ServiceContext context, String templateId, String g

List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatus);
sa.onStatusChange(listOfStatusChange);
sa.onStatusChange(listOfStatusChange, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onEdit(int id, boolean minorEdit) throws Exception {
* @return
* @throws Exception
*/
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOfStatus) throws Exception {
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOfStatus, boolean updateIndex) throws Exception {

if (listOfStatus.stream().map(MetadataStatus::getMetadataId).distinct().count() != listOfStatus.size()) {
throw new IllegalArgumentException("Multiple status update received on the same metadata");
Expand Down Expand Up @@ -179,7 +179,7 @@ public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOf
context.debug("Change status of metadata with id " + status.getMetadataId() + " from " + currentStatusId + " to " + statusId);

// we know we are allowed to do the change, apply any side effects
boolean deleted = applyStatusChange(status.getMetadataId(), status, statusId);
boolean deleted = applyStatusChange(status.getMetadataId(), status, statusId, updateIndex);

// inform content reviewers if the status is submitted
try {
Expand Down Expand Up @@ -218,10 +218,10 @@ public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> listOf
* eg. if APPROVED, publish a record,
* if RETIRED, unpublish or delete the record.
*/
private boolean applyStatusChange(int metadataId, MetadataStatus status, String toStatusId) throws Exception {
private boolean applyStatusChange(int metadataId, MetadataStatus status, String toStatusId, boolean updateIndex) throws Exception {
boolean deleted = false;
if (!deleted) {
metadataStatusManager.setStatusExt(status, false);
if (!deleted && updateIndex) {
metadataStatusManager.setStatusExt(status, true);
}
return deleted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public interface StatusActions {

public void onEdit(int id, boolean minorEdit) throws Exception;

public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> status) throws Exception;
public Map<Integer, StatusChangeType> onStatusChange(List<MetadataStatus> status, boolean updateIndex) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public Map<Integer, StatusChangeType> setStatus(@Parameter(description = API_PAR

List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatusValue);
Map<Integer, StatusChangeType> statusUpdate = sa.onStatusChange(listOfStatusChange);
Map<Integer, StatusChangeType> statusUpdate = sa.onStatusChange(listOfStatusChange, false);

int metadataIdApproved = metadata.getId();

Expand Down Expand Up @@ -1308,6 +1308,6 @@ private void changeMetadataStatus(ServiceContext context, AbstractMetadata metad
metadataStatusValue.setPreviousState(previousStatus);
List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatusValue);
sa.onStatusChange(listOfStatusChange);
sa.onStatusChange(listOfStatusChange, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void saveEdits(

List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatus);
sa.onStatusChange(listOfStatusChange);
sa.onStatusChange(listOfStatusChange, true);
} else {
throw new SecurityException(String.format("Only users with editor profile can submit."));
}
Expand All @@ -442,7 +442,7 @@ public void saveEdits(

List<MetadataStatus> listOfStatusChange = new ArrayList<>(1);
listOfStatusChange.add(metadataStatus);
sa.onStatusChange(listOfStatusChange);
sa.onStatusChange(listOfStatusChange, true);
} else {
throw new SecurityException(String.format("Only users with review profile can approve."));
}
Expand Down

0 comments on commit 71368be

Please sign in to comment.