diff --git a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy index 5a5c8eb06..3b062a4bb 100644 --- a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy +++ b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy @@ -276,9 +276,11 @@ class ParatooService { private Map syncParatooProtocols(List 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) { @@ -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 }