Skip to content

Commit

Permalink
Added check for deleted protocols #823
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Feb 21, 2024
1 parent c33d603 commit 401ac4c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ class ParatooService {
private Map syncParatooProtocols(List<Map> protocols) {

Map result = [errors:[], messages:[]]
List guids = []
protocols.each { Map protocol ->
String id = protocol.id
String guid = protocol.attributes.identifier
guids << guid
String name = protocol.attributes.name
ActivityForm form = ActivityForm.findByExternalId(guid)
if (!form) {
Expand Down Expand Up @@ -318,6 +320,18 @@ class ParatooService {
log.warn "Error saving form with id: "+id+", name: "+name
}
}

List allProtocolForms = ActivityForm.findAll {
externalIds {
idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID
}
status != Status.DELETED
}

List deletions = allProtocolForms.findAll{it.externalIds.find{it.idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID && !(it.externalId in guids)}}
deletions.each { ActivityForm activityForm ->
result.messages << "Form ${activityForm.name} with guid: ${activityForm.externalIds.find{it.idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID}.externalId} has been deleted"
}
result

}
Expand Down

0 comments on commit 401ac4c

Please sign in to comment.