class VulnerabilityConnector {

    public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(
            Vulnerability vulnerability,
            Map<UpdateType, List<Vulnerability>> statusToVulnerabilities){

        Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
        if(dbVulnerability != null){
            if(! isMoreRecent(vulnerability, dbVulnerability)) {
                statusToVulnerabilities.get(UpdateType.OLD).add(dbVulnerability);
                return statusToVulnerabilities;
            } else {
                dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
                RequestStatus requestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
                if (RequestStatus.SUCCESS.equals(requestStatus)){
                    statusToVulnerabilities.get(UpdateType.UPDATED).add(dbVulnerability);
                    return statusToVulnerabilities;
                }
             }
        } else {
            RequestStatus requestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
            if (RequestStatus.SUCCESS.equals(requestStatus)){
                statusToVulnerabilities.get(UpdateType.NEW).add(vulnerability);
                return statusToVulnerabilities;
            }
        }
        statusToVulnerabilities.get(UpdateType.FAILED).add(vulnerability);
        return statusToVulnerabilities;
    }

    public  VulnerabilityConnector();

}