OPTIONAL MATCH (primaryParticipant:NrParticipant:NrPerformance) WHERE primaryParticipant.id IN $primaryArtistIds WITH collect(primaryParticipant) as primaryParticipants CALL apoc.util.validate(size(primaryParticipants) <> size($primaryArtistIds), 'invalid-primary-participants', []) WITH primaryParticipants OPTIONAL MATCH (featuredParticipant:NrParticipant:NrPerformance) WHERE featuredParticipant.id IN $featuredArtistIds WITH collect(featuredParticipant) as featuredParticipants, primaryParticipants CALL apoc.util.validate(size(featuredParticipants) <> size($featuredArtistIds), 'invalid-featured-participants', []) WITH primaryParticipants, featuredParticipants MERGE (nrsr:NrSoundRecording:NrPerformance { mainArtist: $mainArtist, recordingTitle: $recordingTitle, version: coalesce($version, '') }) ON MATCH SET nrsr:Orchard, nrsr.isrc = $isrc, nrsr.albumName = $albumName, nrsr.catalogNumber = $catalogNumber, nrsr.countryOfLabel = $countryOfLabel, nrsr.countryOfMaster = $countryOfMaster, nrsr.countriesOfRecording = $countriesOfRecording, nrsr.duration = toInteger($duration), nrsr.firstReleaseYear = $firstReleaseYear, nrsr.priority = $priority, nrsr.originalLabel = $originalLabel, nrsr.recordingType = $recordingType, nrsr.recordingYear = $recordingYear, nrsr.totalFeaturedPerformers = $totalFeaturedPerformers, nrsr.lastModifiedAt = datetime(), nrsr.lastModifiedBy = "graphql-neighbouring-rights/createFreshNrSoundRecording/" + $identityId ON CREATE SET nrsr:Orchard, nrsr.isrc = $isrc, nrsr.albumName = $albumName, nrsr.catalogNumber = $catalogNumber, nrsr.countryOfLabel = $countryOfLabel, nrsr.countryOfMaster = $countryOfMaster, nrsr.countriesOfRecording = $countriesOfRecording, nrsr.duration = toInteger($duration), nrsr.firstReleaseYear = $firstReleaseYear, nrsr.id = randomUUID(), nrsr.priority = $priority, nrsr.originalLabel = $originalLabel, nrsr.recordingType = $recordingType, nrsr.recordingYear = $recordingYear, nrsr.totalFeaturedPerformers = $totalFeaturedPerformers, nrsr.createdAt = datetime(), nrsr.createdBy = "graphql-neighbouring-rights/createFreshNrSoundRecording/" + $identityId, nrsr.lastModifiedAt = datetime(), nrsr.lastModifiedBy = "graphql-neighbouring-rights/createFreshNrSoundRecording/" + $identityId WITH nrsr, primaryParticipants, featuredParticipants UNWIND primaryParticipants as primaryParticipant MERGE (nrsr)-[:HAS_PRIMARY_ARTIST]->(primaryParticipant) WITH nrsr, featuredParticipants FOREACH (featuredParticipant IN featuredParticipants | MERGE (nrsr)-[:HAS_FEATURED_ARTIST]->(featuredParticipant) ) RETURN nrsr