private boolean hasAnotherCandidature(PositionEntity positionSelect, CandidateEntity candLog) { List<CandidatureEntity> positionsArray = candidatureDAO.findCandidatureByPosition(positionSelect); List<CandidatureEntity> candidateArray = candidatureDAO.findCandidatureByCandidate(candLog); for (CandidatureEntity p : positionsArray) { for (CandidatureEntity c : candidateArray) { if (p.getId() == c.getId()) { return true; } } break; } return false; }
@Override public CandidatureEntity addCandidature( CandidateEntity candLog, PositionEntity positionSelect, String cvPath, String motivationLetter, Date candidatureDate, Set<Source> sourcesSelect) { if (hasAnotherCandidature(positionSelect, candLog)) { log.error("Already have a candidature for this position"); return null; } else { log.info("Saving candidature in DB"); CandidatureEntity cand = new CandidatureEntity( cvPath, motivationLetter, candidatureDate, CandidatureStatus.SUBMITTED); cand.setPublicSource(sourcesSelect); cand.setCandidate(candLog); cand.setPosition(positionSelect); candidatureDAO.save(cand); return cand; } }
@Override public List<CandidatureEntity> findCandidatureByStatus(CandidatureStatus candidatureStatus) { log.info("Finding candidature by last candidatureStatus: " + candidatureStatus); return candidatureDAO.findCandidatureByStatus(candidatureStatus); }
@Override public List<CandidatureEntity> findCandidatureByDate(Date candidatureDate) { log.info("Finding candidature by last candidatureDate: " + candidatureDate); return candidatureDAO.findCandidatureByDate(candidatureDate); }
@Override public List<CandidatureEntity> findCandidatureBySource(Source publicSource) { log.info("Finding candidature by last publicSource: " + publicSource); return candidatureDAO.findCandidatureBySource(publicSource); }
@Override public List<CandidatureEntity> findCandidatureByPosition(PositionEntity position) { log.info("Finding candidature by last position: " + position); return candidatureDAO.findCandidatureByPosition(position); }
@Override public CandidatureEntity findCandidatureById(Long id) { log.info("Finding candidature by last id: " + id); return candidatureDAO.findCandidatureById(id); }
@Override public List<CandidatureEntity> findAllByOrder() { log.info("Creating query for all candidatures (order by id)"); return candidatureDAO.findAllByOrder(); }