protected void atomic(Runnable runnable) { FenixFramework.atomic(runnable); } }
@RequestMapping(value = "/create", method = RequestMethod.POST) public String create(@RequestParam String code, @RequestParam LocalizedString name, @RequestParam(required = false) boolean active, @RequestParam(required = false) boolean visible, @RequestParam( required = false) boolean specialSeasonGranted, @RequestParam(required = false) boolean explicitCreation, @RequestParam(required = false) boolean workingStudentStatute, @RequestParam(required = false) boolean associativeLeaderStatute, @RequestParam(required = false) boolean specialSeasonGrantedByRequest, @RequestParam(required = false) boolean grantOwnerStatute, @RequestParam(required = false) boolean seniorStatute, @RequestParam(required = false) boolean handicappedStatute, Model model) throws Exception { try { StatuteType statuteType = atomic(() -> new StatuteType(code, name, workingStudentStatute, associativeLeaderStatute, specialSeasonGrantedByRequest, grantOwnerStatute, seniorStatute, handicappedStatute, active, explicitCreation, visible, specialSeasonGranted)); return "redirect:/academic/configuration/statutes/" + statuteType.getExternalId(); } catch (DomainException ex) { ControllerHelper.addErrorMessage(ex.getLocalizedMessage(), model); return create(model); } }
private ResponseEntity manageDepartmentGroup(Department department, User user, User loggedUser, Function<User, Group> supplier) { if (isScientificCouncilMember(loggedUser)) { FenixFramework.atomic(() -> { department.setCompetenceCourseMembersGroup(supplier.apply(user)); }); return ResponseEntity.ok(getJsonUser(user).toString()); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); }
public void enforceMinSize(LocalDate start) { int numberOfAvailableCodes = (int) getPaymentCodeStream().filter(paymentCodeIsUsed.negate()).count(); if (numberOfAvailableCodes < getMinSize()) { int numberOfCodesToBeCreated = getMinSize() - numberOfAvailableCodes; int chunks = numberOfCodesToBeCreated / CHUNK_SIZE; int remainder = numberOfCodesToBeCreated % CHUNK_SIZE; IntStream.range(0, chunks).forEach(i -> { FenixFramework.atomic(() -> { IntStream.range(0, CHUNK_SIZE).forEach(j -> { createNewCode(null, start); }); }); }); FenixFramework.atomic(() -> { IntStream.range(0, remainder).forEach(i -> { createNewCode(null, start); }); }); } if (getMinSize() != getPaymentCodeSet().size()) { throw new DomainException("Can't proceed"); } }
public void refreshPaymentCodes(LocalDate start) { final List<EventPaymentCode> paymentCodesToRefresh = getPaymentCodeStream() .filter(paymentCodeHasOpenEvent.or(paymentCodeIsUsed.negate())) .filter(p -> !p.getStartDate().toLocalDate().equals(start)) .collect(Collectors.toList()); Lists.partition(paymentCodesToRefresh, CHUNK_SIZE).forEach(codes -> { FenixFramework.atomic(() -> { codes.forEach(code -> code.edit(start, start.plusMonths(getNumberOfMonths()))); }); }); }
public ActionForward makeDocumentAvailablePage(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final Thesis thesis = getThesis(request); FenixFramework.atomic(() -> thesis.setVisibility(ThesisVisibilityType.INTRANET)); return viewThesis(mapping, actionForm, request, response); }
public ActionForward makeDocumentUnavailable(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final Thesis thesis = getDomainObject(request, "thesisOid"); FenixFramework.atomic(() -> thesis.setVisibility(null)); return showThesisDetails(mapping, request, thesis); }
public ActionForward makeDocumentAvailable(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final Thesis thesis = getDomainObject(request, "thesisOid"); FenixFramework.atomic(() -> thesis.setVisibility(ThesisVisibilityType.INTRANET)); return showThesisDetails(mapping, request, thesis); }
public ActionForward makeDocumentUnavailablePage(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final Thesis thesis = getThesis(request); FenixFramework.atomic(() -> thesis.setVisibility(null)); return viewThesis(mapping, actionForm, request, response); }
public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { final GenericApplication application = getDomainObject(request, "applicationExternalId"); final String confirmationCode = (String) getFromRequest(request, "confirmationCode"); final GenericApplicationFile file = getDomainObject(request, "fileExternalId"); if (application != null && confirmationCode != null && application.getConfirmationCode() != null && application.getConfirmationCode().equals(confirmationCode) && file != null && file.getGenericApplication() == application) { FenixFramework.atomic(() -> file.delete()); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return confirmEmail(mapping, form, request, response); }
@RequestMapping(value = "/{ingressionType}/delete", method = RequestMethod.POST) public String delete(@PathVariable IngressionType ingressionType, Model model, RedirectAttributes redirectAttributes) { try { atomic(() -> ingressionType.delete()); } catch (DomainException e) { ControllerHelper.addErrorMessage(e.getLocalizedMessage(), model); return ControllerHelper.redirect("/academic/configuration/ingression-type", model, redirectAttributes); } ControllerHelper.addInfoMessage(BundleUtil.getString(Bundle.APPLICATION, "label.success.ingressionType.delete"), model); return ControllerHelper.redirect("/academic/configuration/ingression-type", model, redirectAttributes); }
public static InterestRate getOrCreate(LocalDate start, LocalDate end, BigDecimal value) throws FenixActionException { if(isValidRange(start, end)) { if (isValidValue(value)) { return Bennu.getInstance().getInterestRateSet().stream().filter(i -> i.overlap(start, end)).findAny().orElseGet(() -> { try { return FenixFramework.atomic(() -> new InterestRate(start, end, value)); } catch (Exception e) { throw new Error(e); } }); } else { throw new InvalidValueException(value); } } else { throw new InvalidDateRangeException(start, end); } }
public static PartialRegimeEvent create(Person person, Registration registration, StudentCurricularPlan studentCurricularPlan, ExecutionYear executionYear, boolean forAliens) { Set<PostingRule> postingRules = studentCurricularPlan.getDegreeCurricularPlan().getServiceAgreementTemplate() .getPostingRulesBy(EventType.PARTIAL_REGIME_GRATUITY, executionYear.getBeginLocalDate().toDateTimeAtStartOfDay(), executionYear.getEndLocalDate().toDateTimeAtStartOfDay()); if (!postingRules.stream().allMatch(PartialRegimePR.class::isInstance)) { throw cantCreateEvent(); } PartialRegimePR partialRegimePR = postingRules.stream().map(PartialRegimePR.class::cast).filter(p -> p.isForAliens() == forAliens).findAny() .orElseThrow(PartialRegimeEvent::cantCreateEvent); return studentCurricularPlan.getGratuityEvent(executionYear, PartialRegimeEvent.class).findAny().orElseGet(() -> { try { return FenixFramework .atomic(() -> new PartialRegimeEvent(person, registration, studentCurricularPlan, executionYear, partialRegimePR)); } catch (Exception e) { throw cantCreateEvent(e); } }); }
@RequestMapping(value = "/{statuteType}/delete", method = RequestMethod.POST) public String delete(@PathVariable StatuteType statuteType, Model model, RedirectAttributes redirectAttributes) { try { atomic(() -> statuteType.delete()); } catch (DomainException ex) { //Add error messages to the list ControllerHelper.addErrorMessage( BundleUtil.getString(Bundle.APPLICATION, "error.studentStatute.delete") + ex.getMessage(), model); return "/academic/configuration/statutes/"; } ControllerHelper.addInfoMessage(BundleUtil.getString(Bundle.APPLICATION, "success.studentStatute.delete"), model); return ControllerHelper.redirect("/academic/configuration/statutes/", model, redirectAttributes); }
public ActionForward setProcessingDate(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { EctsTableFilter filter = readFilter(request); if (filter.getProcessingDate() != null) { FenixFramework.atomic(() -> { EctsTableIndex ectsTableIndex = EctsTableIndex.readOrCreateByYear(filter.getExecutionInterval()); ectsTableIndex.setProcessingDate(filter.getProcessingDate()); }); } request.setAttribute("filter", filter); return mapping.findForward("index"); }
public static EnrolmentGratuityEvent create(Person person, Enrolment enrolment, EventType eventType, boolean forAliens) { final ExecutionYear executionYear = enrolment.getExecutionYear(); Set<PostingRule> postingRules = enrolment.getStudentCurricularPlan().getDegreeCurricularPlan().getServiceAgreementTemplate() .getPostingRulesBy(eventType, executionYear.getBeginLocalDate().toDateTimeAtStartOfDay(), executionYear.getEndLocalDate().toDateTimeAtStartOfDay()); if (!postingRules.stream().allMatch(EnrolmentGratuityPR.class::isInstance)) { throw cantCreateEvent(enrolment); } EnrolmentGratuityPR enrolmentGratuityPR = postingRules.stream().map(EnrolmentGratuityPR.class::cast).filter(p -> p.isForAliens() == forAliens).findAny() .orElseThrow(() -> cantCreateEvent(enrolment)); return enrolment.getGratuityEvent().orElseGet(() -> { try { return FenixFramework.atomic(() -> new EnrolmentGratuityEvent(person, enrolment, enrolmentGratuityPR)); } catch (Exception e) { throw cantCreateEvent(enrolment); } }); }
public void editIfValid(LocalDate start, LocalDate end, BigDecimal value) throws FenixActionException { if (isValidRange(start, end)) { if (isValidValue(value)) { if (Bennu.getInstance().getInterestRateSet().stream().noneMatch(i -> !i.equals(this) && i.overlap(start, end))) FenixFramework.atomic(() -> { edit(start, end, value); }); } else { throw new InvalidValueException(value); } } else { throw new InvalidDateRangeException(start, end); } }
private void process(final Party party, final DateTime now, final LocalDate afterTomorrow, final LocalDate yesterday) { FenixFramework.atomic(() -> { if (party.isPerson()) { final Person person = (Person) party; final String message = person.getEventsSet().stream() .flatMap(e -> generateNotifications(e, now, afterTomorrow, yesterday)) .reduce("", String::concat); if (!message.isEmpty()) { Message.fromSystem() .to(Group.users(person.getUser())) .template("event.notifications") .parameter("notificationMessage", message) .and() .wrapped() .send(); } } }); }
public static EmptyConversionTable getInstance() { if (Bennu.getInstance().getEmptyConversionTable() == null) { FenixFramework.atomic(() -> { if (Bennu.getInstance().getEmptyConversionTable() == null) { new EmptyConversionTable(); } }); } return Bennu.getInstance().getEmptyConversionTable(); }
public String transferCompetenceCourse() { check(this, RolePredicates.SCIENTIFIC_COUNCIL_PREDICATE); try { if (getCompetenceCourse() == null || readCompetenceCourseGroupUnitToTransferTo() == null || getExecutionSemester() == null) { addErrorMessage(BundleUtil.getString(Bundle.SCIENTIFIC, "error.transferingCompetenceCourse")); return "competenceCoursesManagement"; } FenixFramework.atomic(() -> { getCompetenceCourse().transfer((CompetenceCourseGroupUnit) readCompetenceCourseGroupUnitToTransferTo(), getExecutionSemester(), BundleUtil.getString(Bundle.SCIENTIFIC, "transfer.done.by.scientific.council"), AccessControl.getPerson()); }); } catch (IllegalDataAccessException e) { this.addErrorMessage(BundleUtil.getString(Bundle.SCIENTIFIC, "error.notAuthorized")); } catch (DomainException e) { addErrorMessage(BundleUtil.getString(Bundle.DOMAIN_EXCEPTION, e.getMessage())); } return "competenceCoursesManagement"; }