Search in sources :

Example 1 with MifosException

use of org.mifos.core.MifosException in project head by mifos.

the class HomePageController method loadLoanOfficerCustomersHierarchyForSelectedDay.

private void loadLoanOfficerCustomersHierarchyForSelectedDay(Short userId, ModelAndView modelAndView, CustomerSearchFormBean customerSearchFormBean) throws MifosException {
    CustomerHierarchyDto hierarchy;
    List<String> nearestDates = new ArrayList<String>();
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", personnelServiceFacade.getUserPreferredLocale());
    Date selectedDate = new LocalDate().toDateMidnight().toDate();
    DateTime nextDate = new DateTime();
    for (int i = 0; i < 7; i++) {
        nearestDates.add(formatter.format(nextDate.toDate()));
        nextDate = nextDate.plusDays(1);
    }
    if (customerSearchFormBean.getSelectedDateOption() != null) {
        try {
            selectedDate = formatter.parse(customerSearchFormBean.getSelectedDateOption());
        } catch (ParseException e) {
            throw new MifosException(e);
        }
    }
    hierarchy = personnelServiceFacade.getLoanOfficerCustomersHierarchyForDay(userId, new DateTime(selectedDate));
    modelAndView.addObject("nearestDates", nearestDates);
    modelAndView.addObject("hierarchy", hierarchy);
}
Also used : MifosException(org.mifos.core.MifosException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CustomerHierarchyDto(org.mifos.dto.domain.CustomerHierarchyDto) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 2 with MifosException

use of org.mifos.core.MifosException in project head by mifos.

the class StandardTestingService method runIndividualBatchJob.

@Override
public void runIndividualBatchJob(final String requestedJob, final ServletContext ctx) throws MifosException {
    logger.info("running batch job with name: " + requestedJob);
    boolean jobFound = false;
    String jobToRun = null;
    final MifosScheduler mifosScheduler = (MifosScheduler) ctx.getAttribute(MifosScheduler.class.getName());
    try {
        for (String taskName : mifosScheduler.getTaskNames()) {
            if (taskName.equals(requestedJob)) {
                jobFound = true;
                jobToRun = taskName;
                break;
            }
        }
        if (!jobFound) {
            throw new IllegalArgumentException(requestedJob + " is unknown and will not be executed.");
        }
        mifosScheduler.runIndividualTask(jobToRun);
    } catch (TaskSystemException se) {
        throw new MifosException("Scheduler's inner exception while running individual batch job!", se);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) MifosException(org.mifos.core.MifosException) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler)

Example 3 with MifosException

use of org.mifos.core.MifosException in project head by mifos.

the class StandardTestingService method setLocale.

@Override
public void setLocale(String languageCode, String countryCode) throws MifosException {
    try {
        LocaleSetting configLocale = new LocaleSetting();
        configLocale.setLanguageCode(languageCode);
        configLocale.setCountryCode(countryCode);
        Localization localization = Localization.getInstance();
        localization.setConfigLocale(configLocale);
        if (SecurityContextHolder.getContext() != null) {
            if (SecurityContextHolder.getContext().getAuthentication() != null) {
                if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
                    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                    user.setPreferredLocaleId(Localization.getInstance().getLocaleId(Localization.getInstance().getConfiguredLocale()));
                }
            }
        }
        StaticHibernateUtil.startTransaction();
        PersonnelBO p = (PersonnelBO) StaticHibernateUtil.getSessionTL().get(PersonnelBO.class, (short) 1);
        p.setPreferredLocale(Localization.getInstance().getConfiguredLocaleId());
        StaticHibernateUtil.getSessionTL().update(p);
        StaticHibernateUtil.commitTransaction();
        MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
        configMgr.setProperty("Localization.LanguageCode", languageCode);
        configMgr.setProperty("Localization.CountryCode", countryCode);
    } catch (MifosRuntimeException e) {
        throw new MifosException("The locale " + languageCode + "_" + countryCode + " is not supported by Mifos.");
    }
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosException(org.mifos.core.MifosException) LocaleSetting(org.mifos.config.LocaleSetting) MifosUser(org.mifos.security.MifosUser) Localization(org.mifos.config.Localization) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

MifosException (org.mifos.core.MifosException)3 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocaleSetting (org.mifos.config.LocaleSetting)1 Localization (org.mifos.config.Localization)1 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 CustomerHierarchyDto (org.mifos.dto.domain.CustomerHierarchyDto)1 MifosScheduler (org.mifos.framework.components.batchjobs.MifosScheduler)1 TaskSystemException (org.mifos.framework.components.batchjobs.exceptions.TaskSystemException)1 MifosUser (org.mifos.security.MifosUser)1