Example usage for org.springframework.transaction.interceptor TransactionAspectSupport currentTransactionStatus

List of usage examples for org.springframework.transaction.interceptor TransactionAspectSupport currentTransactionStatus

Introduction

In this page you can find the example usage for org.springframework.transaction.interceptor TransactionAspectSupport currentTransactionStatus.

Prototype

public static TransactionStatus currentTransactionStatus() throws NoTransactionException 

Source Link

Document

Return the transaction status of the current method invocation.

Usage

From source file:com.mobileman.projecth.web.controller.PublicController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/behandlung/signup")
public String signup(HttpServletRequest request, HttpServletResponse response, Model model) {
    ViewState.copyViewState(request, model);
    KeepScroll.save(request, model);//from  w w w .  ja  v a 2s  .  c o  m

    String result = "behandlung/mitmachen";

    boolean error = false;
    boolean passworderror = false;

    String login = request.getParameter("login");
    String password = request.getParameter("password");
    String password2 = request.getParameter("password2");
    String nameOfInstitution = request.getParameter("nameofinstitution");
    String title = request.getParameter("title");
    String namename = request.getParameter("namename");
    String surname = request.getParameter("surname");
    String address = request.getParameter("address");
    String nr = request.getParameter("nr");
    String postcode = request.getParameter("postcode");
    String place = request.getParameter("place");
    String country = request.getParameter("country");
    String telefonCountryCode = request.getParameter("telefoncountrycode");
    String telefon = request.getParameter("telefonnumber");
    String faxCountryCode = request.getParameter("faxcountrycode");
    String fax = request.getParameter("faxnumber");
    String homepage = request.getParameter("homepage");
    String email = request.getParameter("email");
    String accepted = request.getParameter("accepted");
    String type = request.getParameter("usertype");
    String strDisease = request.getParameter("disease");
    Long diseaseId = NumUtils.convert2long(strDisease);

    model.addAttribute("val_nameofinstitution", nameOfInstitution);
    model.addAttribute("val_title", title);
    model.addAttribute("val_namename", namename);
    model.addAttribute("val_surname", surname);
    model.addAttribute("val_address", address);
    model.addAttribute("val_nr", nr);

    model.addAttribute("val_postcode", postcode);
    model.addAttribute("val_place", place);
    model.addAttribute("val_country", country);
    model.addAttribute("val_telefonnumber", telefon);
    model.addAttribute("val_homepage", homepage);
    model.addAttribute("val_disease_id", strDisease);
    model.addAttribute("val_telefoncountrycode", telefonCountryCode);
    model.addAttribute("val_faxcountrycode", faxCountryCode);

    if (StringUtils.isBlank(nameOfInstitution)) {
        nameOfInstitution = null;
    }

    if (StringUtils.isBlank(title)) {
        title = null;
    }
    if (StringUtils.isBlank(namename)) {
        namename = null;
    }
    if (StringUtils.isBlank(surname)) {
        surname = null;
    }
    if (StringUtils.isBlank(address)) {
        address = null;
    }
    if (StringUtils.isBlank(nr)) {
        nr = null;
    }
    if (StringUtils.isBlank(postcode)) {
        postcode = null;
    }
    if (StringUtils.isBlank(place)) {
        place = null;
    }
    if (StringUtils.isBlank(country)) {
        country = null;
    }
    if (StringUtils.isBlank(telefonCountryCode)) {
        telefonCountryCode = null;
    }
    if (StringUtils.isBlank(telefon)) {
        telefon = null;
    }
    if (StringUtils.isBlank(faxCountryCode)) {
        faxCountryCode = null;
    }
    if (StringUtils.isBlank(fax)) {
        fax = null;
    }
    if (StringUtils.isBlank(homepage)) {
        homepage = null;
    }

    if (StringUtils.isBlank(accepted)) {
        model.addAttribute("erroraccepted", true);
        error = true;
    }
    // send activation
    if (StringUtils.isBlank(login)) {
        model.addAttribute("errorlogin", true);
        error = true;
    }
    if (StringUtils.isBlank(password)) {
        model.addAttribute("errorpassword", true);
        error = true;
        passworderror = true;
    }

    if (StringUtils.isBlank(email)) {
        model.addAttribute("erroremail", true);
        error = true;
    }

    if (type.equals("D")) {
        error = checkDoctorMandatoryFileds(request, model);
    }

    if (StringUtils.isBlank(type)) {
        model.addAttribute("errortype", true);
        error = true;
    } else {
        if (type.equals("D")) {
            result = "behandlung/mitmachen_arzt";
        } else {
            result = "behandlung/mitmachen_chronisch_betroffener";
        }
    }

    if (diseaseId == null || diseaseId.equals(0L)) {
        model.addAttribute("errordisease", true);
        error = true;
    }

    if (!CaptchaUtil.verify(request, model)) {
        error = true;
    }

    if (!passworderror) {
        if (!password.equals(password2)) {
            model.addAttribute("errorpasssame", true);
            error = true;
        }
    }

    UserType utype = request.getParameter("usertype").equals("D") ? UserType.D : UserType.P;

    if (!error) {
        do {
            // check login
            try {
                User user = userService.findUserByLogin(login);
                if (user != null) {
                    model.addAttribute("errorloginexists", true);
                    break;
                }
            } catch (Exception ex) {
            }
            // check email

            try {
                User user = userService.findUserByEmail(email);
                if (user != null) {
                    model.addAttribute("erroremailexists", true);
                    break;
                }
            } catch (Exception ex) {
            }

            try {

                diseaseService.findById(diseaseId);
                List<Disease> diseases = Arrays.asList(diseaseService.findById(diseaseId));

                if (utype.equals(UserType.D)) {
                    Doctor doctor = new Doctor();
                    Name name = new Name(namename, surname);
                    doctor.setName(name);
                    MedicalInstitution medicalInstitution = new MedicalInstitution();
                    medicalInstitution.setName(nameOfInstitution);
                    Address add = new Address();
                    add.setAddress(address);
                    add.setNumber(nr);
                    add.setPlace(place);
                    PostalCode postalCode = new PostalCode();
                    postalCode.setCode(postcode);
                    add.setPostalCode(postalCode);
                    medicalInstitution.setAddress(add);

                    Country countr = countryService.findByCode(country);
                    medicalInstitution.setCountry(countr);
                    PhoneNumber phoneNumber = new PhoneNumber();
                    phoneNumber.setCountryCode(telefonCountryCode);
                    phoneNumber.setNumber(telefon);
                    PhoneNumber faxNumber = new PhoneNumber();
                    faxNumber.setCountryCode(faxCountryCode);
                    faxNumber.setNumber(fax);
                    medicalInstitution.setPhoneNumber(phoneNumber);
                    medicalInstitution.setFaxNumber(faxNumber);
                    medicalInstitution.setHomePageUrl(homepage);
                    doctor.setMedicalInstitution(medicalInstitution);
                    doctor.setTitle(title);
                    userService.register(doctor, login, password, email, diseases, request.getServerName());

                } else if (utype.equals(UserType.P)) {
                    Patient patient = new Patient();
                    patient.setName(new Name(login, null));
                    userService.register(patient, login, password, email, diseases, request.getServerName());
                }

                model.addAttribute("info", true);
                result = "behandlung/anmeldung_erfolg";
            } catch (Exception ex) {
                if (LoginException.class.isInstance(ex)) {
                    fillLoginError(model, LoginException.class.cast(ex));
                } else {
                    model.addAttribute("error", "System error");
                }

                ex.printStackTrace();

                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        } while (false);
    }

    prepareSignUpModel(model, utype);
    return result;
}

From source file:org.openregistry.core.service.DefaultPersonService.java

public ServiceExecutionResult<Person> validateAndSavePersonAndRole(
        final ReconciliationCriteria reconciliationCriteria) {
    logger.info(" validateAndSavePersonAndRole start");
    SorPerson sorPerson = reconciliationCriteria.getSorPerson();
    if (sorPerson == null || sorPerson.getRoles() == null)
        throw new IllegalArgumentException("Sor Person not found in provided criteria.");
    SorRole sorRole = reconciliationCriteria.getSorPerson().getRoles().get(0);
    if (sorRole == null)
        throw new IllegalArgumentException("Sor Role not found for provided criteria.");

    setRoleIdAndSource(sorRole, sorPerson.getSourceSor());

    final Set validationErrors = this.validator.validate(sorRole);

    if (!validationErrors.isEmpty()) {
        //since because of existing design we cannot raise exception, we can only rollback the transaction through code
        //OR-384//  w w w  . ja v  a 2s.c  om
        if (TransactionAspectSupport.currentTransactionStatus() != null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

        return new GeneralServiceExecutionResult<Person>(validationErrors);
    }

    Long personId = sorPerson.getPersonId();
    if (personId == null) {
        logger.info("calling saveSorPersonAndConvertToCalculatedPerson");
        // add new Sor Person and roles, create calculated person
        return new GeneralServiceExecutionResult<Person>(
                saveSorPersonAndConvertToCalculatedPerson(reconciliationCriteria));
    } else { // Add new Sor Person and role and link to the existing person
        Person thisPerson = this.personRepository.findByInternalId(personId);
        try {
            logger.info("calling addSorPersonAndLink");
            Person savedPerson = this.addSorPersonAndLink(reconciliationCriteria, thisPerson);
            return new GeneralServiceExecutionResult<Person>(savedPerson);
        } catch (SorPersonAlreadyExistsException sorE) {
            throw new IllegalArgumentException(
                    "If a sor Person of the same source already exists, should call the other method to add the role only");
        }
    }

}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/send_new_message")
public @ResponseBody String sendMessage(HttpServletRequest request, HttpServletResponse response, Model model) {

    DataHolder dataHolder = new DataHolder(request);
    Patient patient = dataHolder.getPatient();

    String result = "";
    String receiver = request.getParameter("receiver");
    String subject = StringEscapeUtils.escapeHtml(request.getParameter("subject"));
    String body = StringEscapeUtils.escapeHtml(request.getParameter("body"));
    boolean copy = Boolean.parseBoolean(request.getParameter("copy"));

    try {//from  w w w. ja va2  s  . co  m
        messageService.sendMessage(patient.getId(), Long.valueOf(receiver), subject, body, copy);
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/reply_to_message")
public @ResponseBody String replyMessage(HttpServletRequest request, HttpServletResponse response,
        Model model) {/*from   www  .ja va 2s. c om*/

    String result = "";
    String messageId = request.getParameter("messageId");
    String body = StringEscapeUtils.escapeHtml(request.getParameter("body"));
    boolean copy = Boolean.parseBoolean(request.getParameter("copy"));

    try {
        messageService.sendReplyToMessage(Long.valueOf(messageId), body, copy);
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:org.openregistry.core.service.DefaultPersonService.java

public ServiceExecutionResult<Person> addPerson(final ReconciliationCriteria reconciliationCriteria)
        throws ReconciliationException, IllegalArgumentException, SorPersonAlreadyExistsException {
    Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null");
    logger.info("addPerson start");
    if (reconciliationCriteria.getSorPerson().getSorId() != null
            && this.findBySorIdentifierAndSource(reconciliationCriteria.getSorPerson().getSourceSor(),
                    reconciliationCriteria.getSorPerson().getSorId()) != null) {
        //throw new IllegalStateException("CANNOT ADD SAME SOR RECORD.");
        throw new SorPersonAlreadyExistsException(
                this.findBySorIdentifierAndSource(reconciliationCriteria.getSorPerson().getSourceSor(),
                        reconciliationCriteria.getSorPerson().getSorId()));
    }//from w ww.  j  a  v a 2 s.  c  o m

    final Set validationErrors = this.validator.validate(reconciliationCriteria);

    if (!validationErrors.isEmpty()) {
        Iterator iter = validationErrors.iterator();
        while (iter.hasNext()) {
            logger.info("validation errors: " + iter.next());
        }
        //since because of existing design we cannot raise exception, we can only rollback the transaction through code
        //OR-384
        if (TransactionAspectSupport.currentTransactionStatus() != null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

        return new GeneralServiceExecutionResult<Person>(validationErrors);
    }

    final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria);

    switch (result.getReconciliationType()) {
    case NONE:
        return new GeneralServiceExecutionResult<Person>(
                saveSorPersonAndConvertToCalculatedPerson(reconciliationCriteria));

    case EXACT:
        return new GeneralServiceExecutionResult<Person>(
                addNewSorPersonAndLinkWithMatchedCalculatedPerson(reconciliationCriteria, result));
    }

    this.criteriaCache.put(reconciliationCriteria, result);
    logger.info("addPerson start");
    throw new ReconciliationException(result);
}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/mark_as_read")
public @ResponseBody String markAsRead(HttpServletRequest request, HttpServletResponse response, Model model) {

    String result = "";
    String messageId = request.getParameter("messageId");

    try {// w  ww  . j  a v  a 2s . c om
        messageService.markAsRead(Long.valueOf(messageId), true);
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/mark_as_unread")
public @ResponseBody String markAsUnread(HttpServletRequest request, HttpServletResponse response,
        Model model) {//from   w  ww  . j a  v a  2s .c  o  m

    String result = "";
    String messageId = request.getParameter("messageId");

    try {
        messageService.markAsRead(Long.valueOf(messageId), false);
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/delete_message")
public @ResponseBody String deleteMessage(HttpServletRequest request, HttpServletResponse response,
        Model model) {//from  w w w.  j  a v a  2 s  .  co  m

    String result = "";
    String messageId = request.getParameter("messageId");

    DataHolder dataHolder = new DataHolder(request);
    Patient patient = dataHolder.getPatient();

    try {
        messageService.deleteMessage(patient.getId(), Long.valueOf(messageId));
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:com.mobileman.projecth.web.controller.patient.PatientController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "/patient/mark_as_spam")
public @ResponseBody String markAsSpamMessage(HttpServletRequest request, HttpServletResponse response,
        Model model) {//from ww w.  jav a2 s .  c  o m

    String result = "";
    String messageId = request.getParameter("messageId");

    DataHolder dataHolder = new DataHolder(request);
    try {
        messageService.markAsSpam(Long.valueOf(messageId), true);
        result = "ok";
    } catch (Exception e) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        result = "error";
    }

    return result;
}

From source file:org.openregistry.core.service.DefaultPersonService.java

public ServiceExecutionResult<ReconciliationResult> reconcile(
        final ReconciliationCriteria reconciliationCriteria) throws IllegalArgumentException {
    Assert.notNull(reconciliationCriteria, "reconciliationCriteria cannot be null");
    logger.info("reconcile start");
    final Set validationErrors = this.validator.validate(reconciliationCriteria);

    if (!validationErrors.isEmpty()) {
        Iterator iter = validationErrors.iterator();
        while (iter.hasNext()) {
            logger.info("validation errors: " + iter.next());
        }// w w w.  jav a 2  s . c om
        logger.info("reconcile start");
        //since because of existing design we cannot raise exception, we can only rollback the transaction through code
        //OR-384
        if (TransactionAspectSupport.currentTransactionStatus() != null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

        return new GeneralServiceExecutionResult<ReconciliationResult>(validationErrors);
    }

    final ReconciliationResult result = this.reconciler.reconcile(reconciliationCriteria);
    //(reconciliationCriteria, result);
    return new GeneralServiceExecutionResult<ReconciliationResult>(result);
}