class StudentMapper {

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public MappingResult synchronizeStudentMapping(Student student) {
        if (!userMappingDao.existsMappingForSapUserId(student.getId())) {
            // first try to map by personal number
            Identity mappedIdentity = studentMappingByMartikelNumber.tryToMap(student);
            if (mappedIdentity != null) {
                userMappingDao.saveMapping(student, mappedIdentity);
                return MappingResult.NEW_MAPPING_BY_MATRIKEL_NR;
            }
            // second try to map by Email
            mappedIdentity = mappingByEmail.tryToMap(student);
            if (mappedIdentity != null) {
                userMappingDao.saveMapping(student, mappedIdentity);
                return MappingResult.NEW_MAPPING_BY_EMAIL;
            }
            // third try to map by firstName and lastName
            mappedIdentity = mappingByFirstNameAndLastName.tryToMap(student.getFirstName(), student.getLastName());
            if (mappedIdentity != null) {
                // DO NOT SAVE THIS MAPPING, BECAUSE IT HAS TO BE DONE MANUALLY
                return MappingResult.COULD_BE_MAPPED_MANUALLY;
            } else {
                // log.warn("Could not map student:" + student);
                return MappingResult.COULD_NOT_MAP;
            }
        }
        return MappingResult.MAPPING_ALREADY_EXIST;
    }

}