protected Set < Scope > updateProjectInformation ( Collector collector ) { long projectDataStart = System . currentTimeMillis ( ) ; //Add or update teams that we got from api Set < Scope > projects = jiraClient . getProjects ( ) ; projects . forEach ( jiraScope -> { LOGGER . info ( String . format ( "Adding :%s-%s" , jiraScope . getpId ( ) , jiraScope . getName ( ) ) ) ; jiraScope . setCollectorId ( collector . getId ( ) ) ; Scope existing = projectRepository . findByCollectorIdAndPId ( collector . getId ( ) , jiraScope . getpId ( ) ) ; if ( existing == null ) { projectRepository . save ( jiraScope ) ; } else { jiraScope . setId ( existing . getId ( ) ) ; projectRepository . save ( jiraScope ) ; } } ) ; log ( "Project Data Collected" , projectDataStart , projects . size ( ) ) ; // Delete the ones that are gone from JIRA List < Scope > existingProjects = projectRepository . findByCollectorId ( collector . getId ( ) ) ; Set < String > newProjectIds = projects . stream ( ) . map ( Scope :: getpId ) . collect ( Collectors . toSet ( ) ) ; Set < Scope > toDelete = existingProjects . stream ( ) . filter ( e -> ! newProjectIds . contains ( e . getpId ( ) ) ) . collect ( Collectors . toSet ( ) ) ; if ( ! CollectionUtils . isEmpty ( toDelete ) ) { toDelete . forEach ( td -> { LOGGER . info ( String . format ( "Deleting :%s-%s" , td . getpId ( ) , td . getName ( ) ) ) ; } ) ; projectRepository . delete ( toDelete ) ; log ( "Project Data Collected. Deleted " , projectDataStart , toDelete . size ( ) ) ; } return projects ; }
Update project information