class LecturerMapper {

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public MappingResult synchronizeLecturerMapping(Lecturer lecturer) {
        if (!userMappingDao.existsMappingForSapUserId(lecturer.getPersonalNr())) {
            // first try to map by personal number
            Identity mappedIdentity = mappingByPersonalNumber.tryToMap(lecturer.getPersonalNr());
            if (mappedIdentity != null) {
                userMappingDao.saveMapping(lecturer, mappedIdentity);
                return MappingResult.NEW_MAPPING_BY_PERSONAL_NR;
            }
            // second try to map by Email
            mappedIdentity = mappingByEmail.tryToMap(lecturer);
            if (mappedIdentity != null) {
                userMappingDao.saveMapping(lecturer, mappedIdentity);
                return MappingResult.NEW_MAPPING_BY_EMAIL;
            }

            // third try to map by additional personal number
            if (StringUtils.isNotBlank(lecturer.getAdditionalPersonalNrs())) {
                List<String> personalNrs = Arrays.asList(lecturer.getAdditionalPersonalNrs().split("\\s*,\\s*"));
                for (String personalNr : personalNrs) {
                    mappedIdentity = mappingByPersonalNumber.tryToMap(Long.valueOf(personalNr));
                    if (mappedIdentity != null) {
                        userMappingDao.saveMapping(lecturer, mappedIdentity);
                        return MappingResult.NEW_MAPPING_BY_ADDITIONAL_PERSONAL_NR;
                    }
                }
            }

            // forth try to map by firstName and lastName
            mappedIdentity = mappingByFirstNameAndLastName.tryToMap(lecturer.getFirstName(), lecturer.getLastName());
            if (mappedIdentity != null) {
                // DO NOT SAVE THIS MAPPING, BECAUSE IT HAS TO BE DONE MANUALLY
                return MappingResult.COULD_BE_MAPPED_MANUALLY;
            } else {
                // log.info("Could not map lecturer:" + lecturer);
                return MappingResult.COULD_NOT_MAP;
            }
        }
        return MappingResult.MAPPING_ALREADY_EXIST;
    }

}