protected List < Team > updateTeamInformation ( FeatureCollector collector ) { long projectDataStart = System . currentTimeMillis ( ) ; List < Team > teams = featureSettings . isJiraBoardAsTeam ( ) ? jiraClient . getBoards ( ) : jiraClient . getTeams ( ) ; //Add or update teams that we got from api teams . forEach ( newTeam -> { String teamId = newTeam . getTeamId ( ) ; newTeam . setCollectorId ( collector . getId ( ) ) ; LOGGER . info ( String . format ( "Adding %s:%s-%s" , collector . getMode ( ) , teamId , newTeam . getName ( ) ) ) ; Team existing = teamRepository . findByTeamId ( teamId ) ; if ( existing == null ) { teamRepository . save ( newTeam ) ; } else { newTeam . setId ( existing . getId ( ) ) ; teamRepository . save ( newTeam ) ; } } ) ; log ( collector . getMode ( ) + " Data Collected. Added " , projectDataStart , teams . size ( ) ) ; projectDataStart = System . currentTimeMillis ( ) ; // Delete the ones that are gone from JIRA List < Team > existingTeams = teamRepository . findByCollectorId ( collector . getId ( ) ) ; Set < String > newTeamIds = teams . stream ( ) . map ( Team :: getTeamId ) . collect ( Collectors . toSet ( ) ) ; Set < Team > toDelete = existingTeams . stream ( ) . filter ( e -> ! newTeamIds . contains ( e . getTeamId ( ) ) ) . collect ( Collectors . toSet ( ) ) ; if ( ! CollectionUtils . isEmpty ( toDelete ) ) { toDelete . forEach ( td -> { LOGGER . info ( String . format ( "Deleting %s:%s-%s" , collector . getMode ( ) , td . getTeamId ( ) , td . getName ( ) ) ) ; } ) ; teamRepository . delete ( toDelete ) ; log ( collector . getMode ( ) + " Data Collected. Deleted " , projectDataStart , toDelete . size ( ) ) ; } return teams ; }
Update team information