Search in sources :

Example 61 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class AuditLogServiceImpl method addAuditLogRegistry.

@Override
public void addAuditLogRegistry(QuestionGroupDetail questionGroupDetail, QuestionGroupDetail oldQuestionGroupDetail, int creatorId, int entityId, String source, String event) {
    PersonnelBusinessService pbs = new PersonnelBusinessService();
    String modifierName;
    if (oldQuestionGroupDetail != null && event.toLowerCase().equals(CREATE)) {
        String questionGroupName;
        String sectionName;
        String fieldName;
        String fieldValue;
        try {
            modifierName = pbs.getPersonnel((short) creatorId).getDisplayName();
        } catch (ServiceException e) {
            modifierName = "";
        }
        questionGroupName = questionGroupDetail.getTitle();
        AuditLog auditLog = new AuditLog(entityId, EntityType.getEntityValue(source.toUpperCase()), modifierName, new DateTimeService().getCurrentJavaSqlDate(), (short) creatorId);
        Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
        for (int sectionPosition = 0; sectionPosition < questionGroupDetail.getSectionDetails().size(); sectionPosition++) {
            SectionDetail sectionDetail = questionGroupDetail.getSectionDetails().get(sectionPosition);
            sectionName = sectionDetail.getName();
            for (int questionPosition = 0; questionPosition < sectionDetail.getQuestions().size(); questionPosition++) {
                SectionQuestionDetail sectionQuestionDetail = sectionDetail.getQuestions().get(questionPosition);
                fieldName = sectionQuestionDetail.getText();
                fieldValue = sectionQuestionDetail.getAnswer();
                String oldFieldValue = null;
                for (SectionDetail oldSectionDetail : oldQuestionGroupDetail.getSectionDetails()) {
                    if (oldSectionDetail.getName().equals(sectionName)) {
                        for (SectionQuestionDetail oldSectionQuestionDetail : oldSectionDetail.getQuestions()) {
                            if (oldSectionQuestionDetail.getText().equals(fieldName)) {
                                oldFieldValue = oldSectionQuestionDetail.getAnswer();
                                break;
                            }
                        }
                        break;
                    }
                }
                if (!fieldValue.equals("")) {
                    if (oldFieldValue != null && !oldFieldValue.equals("")) {
                        if (!oldFieldValue.equals(fieldValue)) {
                            auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), trimField(oldFieldValue, 200), trimField(fieldValue, 200), auditLog));
                        }
                    } else {
                        auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), "-", trimField(fieldValue, 200), auditLog));
                    }
                }
            }
        }
        if (!auditLogRecords.isEmpty()) {
            auditLog.addAuditLogRecords(auditLogRecords);
            legacyAuditDao.save(auditLog);
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) DateTimeService(org.mifos.framework.util.DateTimeService) AuditLog(org.mifos.framework.components.audit.business.AuditLog) HashSet(java.util.HashSet)

Example 62 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class PersonAction method translateFormToCreatePersonnelInformationDto.

@SuppressWarnings("unchecked")
private CreateOrUpdatePersonnelInformation translateFormToCreatePersonnelInformationDto(HttpServletRequest request, PersonActionForm personActionForm) throws PageExpiredException, InvalidDateException {
    UserContext userContext = getUserContext(request);
    PersonnelLevel level = PersonnelLevel.fromInt(getShortValue(personActionForm.getLevel()));
    PersonnelStatus personnelStatus = PersonnelStatus.ACTIVE;
    if (StringUtils.isNotBlank(personActionForm.getStatus())) {
        personnelStatus = PersonnelStatus.getPersonnelStatus(getShortValue(personActionForm.getStatus()));
    }
    OfficeBO office = (OfficeBO) SessionUtils.getAttribute(PersonnelConstants.OFFICE, request);
    if (office == null) {
        Short officeId = getShortValue(personActionForm.getOfficeId());
        office = this.officeDao.findOfficeById(officeId);
    }
    Integer title = getIntegerValue(personActionForm.getTitle());
    Short preferredLocale = Localization.getInstance().getConfiguredLocaleId();
    preferredLocale = getPerefferedLocale(personActionForm, userContext);
    Date dob = null;
    if (personActionForm.getDob() != null && !personActionForm.getDob().equals("")) {
        dob = DateUtils.getDate(personActionForm.getDob());
    }
    Date dateOfJoiningMFI = null;
    if (personActionForm.getDateOfJoiningMFI() != null && !personActionForm.getDateOfJoiningMFI().equals("")) {
        dateOfJoiningMFI = DateUtils.getDateAsSentFromBrowser(personActionForm.getDateOfJoiningMFI());
    }
    Date passwordExpirationDate = null;
    if (personActionForm.getPasswordExpirationDate() != null && !personActionForm.getPasswordExpirationDate().equals("")) {
        passwordExpirationDate = DateUtils.getDate(personActionForm.getPasswordExpirationDate());
    }
    List<RoleBO> roles = new ArrayList<RoleBO>();
    boolean addFlag = false;
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
    if (personActionForm.getPersonnelRoles() != null) {
        for (RoleBO role : masterList) {
            for (String roleId : personActionForm.getPersonnelRoles()) {
                if (roleId != null && role.getId().intValue() == Integer.valueOf(roleId).intValue()) {
                    selectList.add(role);
                    addFlag = true;
                }
            }
        }
    }
    if (addFlag) {
        roles = selectList;
    }
    List<ListElement> roleList = new ArrayList<ListElement>();
    for (RoleBO element : roles) {
        ListElement listElement = new ListElement(new Integer(element.getId()), element.getName());
        roleList.add(listElement);
    }
    Address address = personActionForm.getAddress();
    AddressDto addressDto = new AddressDto(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
    Long id = null;
    if (StringUtils.isNotBlank(personActionForm.getPersonnelId())) {
        id = Long.valueOf(personActionForm.getPersonnelId());
    }
    CreateOrUpdatePersonnelInformation perosonnelInfo = new CreateOrUpdatePersonnelInformation(id, level.getValue(), office.getOfficeId(), title, preferredLocale, personActionForm.getUserPassword(), personActionForm.getLoginName(), personActionForm.getEmailId(), roleList, personActionForm.getCustomFields(), personActionForm.getFirstName(), personActionForm.getMiddleName(), personActionForm.getLastName(), personActionForm.getSecondLastName(), personActionForm.getGovernmentIdNumber(), new DateTime(dob), getIntegerValue(personActionForm.getMaritalStatus()), getIntegerValue(personActionForm.getGender()), new DateTime(dateOfJoiningMFI), new DateTimeService().getCurrentDateTime(), addressDto, personnelStatus.getValue(), new DateTime(passwordExpirationDate));
    return perosonnelInfo;
}
Also used : Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) OfficeBO(org.mifos.customers.office.business.OfficeBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) List(java.util.List) ArrayList(java.util.ArrayList) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) DateTimeService(org.mifos.framework.util.DateTimeService) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 63 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CloseLoanActionStrutsTest method tearDown.

@After
public void tearDown() throws Exception {
    new ConfigurationPersistence().updateConfigurationKeyValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, lsim);
    new DateTimeService().resetToCurrentSystemDateTime();
    loanBO = null;
    group = null;
    center = null;
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) After(org.junit.After)

Example 64 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CloseLoanActionStrutsTest method getLoanAccount.

private LoanBO getLoanAccount() {
    Date startDate = new DateTimeService().getCurrentJavaDateTime();
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    return TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date)

Example 65 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CloseLoanActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    currentDate = new DateTime(2010, 12, 23, 12, 0, 0, 0);
    new DateTimeService().setCurrentDateTime(currentDate);
    ConfigurationPersistence configurationPersistence = new ConfigurationPersistence();
    lsim = configurationPersistence.getConfigurationValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED);
    configurationPersistence.updateConfigurationKeyValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, 1);
    userContext = TestObjectFactory.getContext();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, LoanDisbursementAction.class);
    setRequestPathInfo("/editStatusAction");
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8