private Set < Artifact > saveArtifacts ( Collection < Artifact > artifacts , Map < String , TargetRepository > repositoriesCache , Map < Artifact . IdentifierSha256 , Artifact > artifactCache ) { logger . debug ( "Saving {} artifacts." , artifacts . size ( ) ) ; Set < Artifact > savedArtifacts = new HashSet <> ( ) ; Set < Artifact . IdentifierSha256 > artifactConstraints = new HashSet <> ( ) ; for ( Artifact artifact : artifacts ) { artifactConstraints . add ( new Artifact . IdentifierSha256 ( artifact . getIdentifier ( ) , artifact . getSha256 ( ) ) ) ; } Set < Artifact > artifactsInDb = null ; if ( artifactConstraints . size ( ) > 0 ) { artifactsInDb = artifactRepository . withIdentifierAndSha256s ( artifactConstraints ) ; } if ( artifactsInDb != null ) { for ( Artifact artifact : artifactsInDb ) { logger . trace ( "Found in DB, adding to cache. Artifact {}" , artifact ) ; artifactCache . put ( artifact . getIdentifierSha256 ( ) , artifact ) ; } } for ( Artifact artifact : artifacts ) { TargetRepository targetRepository = artifact . getTargetRepository ( ) ; linkTargetRepository ( repositoriesCache , artifact , targetRepository ) ; Artifact artifactFromDb ; if ( RepositoryType . GENERIC_PROXY . equals ( targetRepository . getRepositoryType ( ) ) ) { artifactFromDb = saveHttpArtifact ( artifact ) ; } else { artifactFromDb = getOrSaveRepositoryArtifact ( artifact , artifactCache ) ; } savedArtifacts . add ( artifactFromDb ) ; } logger . debug ( "Artifacts saved: {}." , artifacts ) ; return savedArtifacts ; }
Checks the given list against the existing database and creates a new list containing artifacts which have been saved to or loaded from the database .