Search in sources :

Example 1 with LocalDateTime

use of org.joda.time.LocalDateTime in project head by mifos.

the class LoginServiceFacadeWebTier method updatePassword.

@Override
public boolean updatePassword(String username, String oldPassword, String newPassword) {
    MifosUser appUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(appUser);
    PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
    boolean passwordIsAlreadyChanged = user.isPasswordChanged();
    this.personnelService.changePassword(user, newPassword, true);
    Date newExpirationDate = null;
    if (user.getPasswordExpirationDate() != null) {
        newExpirationDate = new LocalDateTime().plusDays(PasswordRules.getPasswordExpirationDatePrelongation()).toDateTime().toDate();
    }
    personnelService.changePasswordExpirationDate(user, newExpirationDate);
    return passwordIsAlreadyChanged;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 2 with LocalDateTime

use of org.joda.time.LocalDateTime in project head by mifos.

the class PersonnelServiceImpl method changePassword.

@Override
public void changePassword(PersonnelBO user, String newPassword, boolean setPasswordChanged) {
    UserContext userContext = new UserContext();
    userContext.setId(user.getPersonnelId());
    userContext.setName(user.getUserName());
    user.updateDetails(userContext);
    validateIfPasswordIsRecentlyUsed(user, newPassword);
    byte[] newEncPass = EncryptionService.getInstance().createEncryptedPassword(newPassword);
    PersonnelUsedPasswordEntity personnelUsedPassword;
    int passwordHistoryCount = PasswordRules.getPasswordHistoryCount();
    if (user.getPersonnelUsedPasswords().size() >= passwordHistoryCount) {
        personnelUsedPassword = new ArrayList<PersonnelUsedPasswordEntity>(user.getPersonnelUsedPasswords()).get(0);
        personnelUsedPassword.setUsedPassword(newEncPass);
        personnelUsedPassword.setDateChanged(new LocalDateTime().toDateTime().toDate());
    } else {
        personnelUsedPassword = new PersonnelUsedPasswordEntity();
        personnelUsedPassword.setPersonnel(user);
        personnelUsedPassword.setUsedPassword(newEncPass);
        personnelUsedPassword.setDateChanged(new LocalDateTime().toDateTime().toDate());
        user.getPersonnelUsedPasswords().add(personnelUsedPassword);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(user);
        user.changePasswordTo(newPassword, user.getPersonnelId(), setPasswordChanged);
        this.personnelDao.save(user);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : PersonnelUsedPasswordEntity(org.mifos.customers.personnel.business.PersonnelUsedPasswordEntity) LocalDateTime(org.joda.time.LocalDateTime) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with LocalDateTime

use of org.joda.time.LocalDateTime in project SeriesGuide by UweTrottmann.

the class TimeTools method parseEpisodeReleaseDate.

/**
     * Calculates the episode release date time as a millisecond instant. Adjusts for time zone
     * effects on release time, e.g. delays between time zones (e.g. in the United States) and DST.
     *
     * @param showTimeZone See {@link #getDateTimeZone(String)}.
     * @param showReleaseTime See {@link #getShowReleaseTime(int)}.
     * @return -1 if no conversion was possible. Otherwise, any other long value (may be negative!).
     */
public static long parseEpisodeReleaseDate(@Nullable Context context, @NonNull DateTimeZone showTimeZone, @Nullable String releaseDate, @NonNull LocalTime showReleaseTime, @Nullable String showCountry, @Nullable String showNetwork, @NonNull String deviceTimeZone) {
    if (releaseDate == null || releaseDate.length() == 0) {
        return Constants.EPISODE_UNKNOWN_RELEASE;
    }
    // get date
    LocalDate localDate;
    try {
        localDate = TVDB_DATE_FORMATTER.parseLocalDate(releaseDate);
    } catch (IllegalArgumentException e) {
        // date string could not be parsed
        if (context != null) {
            Utils.trackCustomEvent(context, AnalyticsTree.CATEGORY_THETVDB_ERROR, "Date parsing failure", releaseDate);
        }
        Timber.e(e, "TheTVDB date could not be parsed: %s", releaseDate);
        return Constants.EPISODE_UNKNOWN_RELEASE;
    }
    // set time
    LocalDateTime localDateTime = localDate.toLocalDateTime(showReleaseTime);
    localDateTime = handleHourPastMidnight(showCountry, showNetwork, localDateTime);
    localDateTime = handleDstGap(showTimeZone, localDateTime);
    // finally get a valid datetime in the show time zone
    DateTime dateTime = localDateTime.toDateTime(showTimeZone);
    // handle time zone effects on release time for US shows (only if device is set to US zone)
    if (deviceTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
        dateTime = applyUnitedStatesCorrections(showCountry, deviceTimeZone, dateTime);
    }
    return dateTime.getMillis();
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 4 with LocalDateTime

use of org.joda.time.LocalDateTime in project qi4j-sdk by Qi4j.

the class AbstractQueryTest method script40_LocalDateTime.

@Test
public void script40_LocalDateTime() {
    QueryBuilder<Person> qb = this.module.newQueryBuilder(Person.class);
    Person person = templateFor(Person.class);
    Query<Person> query = unitOfWork.newQuery(qb.where(eq(person.localDateTimeValue(), new LocalDateTime("2010-03-04T13:23:00", UTC))));
    System.out.println("*** script40_LocalDateTime: " + query);
    verifyUnorderedResults(query, "Jack Doe");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Person(org.qi4j.test.indexing.model.Person) Test(org.junit.Test)

Example 5 with LocalDateTime

use of org.joda.time.LocalDateTime in project qi4j-sdk by Qi4j.

the class AbstractQueryTest method script41_LocalDateTime.

@Test
public void script41_LocalDateTime() {
    QueryBuilder<Person> qb = this.module.newQueryBuilder(Person.class);
    Person person = templateFor(Person.class);
    Query<Person> query = unitOfWork.newQuery(qb.where(ne(person.localDateTimeValue(), new LocalDateTime("2010-03-04T13:23:00", UTC))));
    System.out.println("*** script41_LocalDateTime: " + query);
    verifyUnorderedResults(query, "Joe Doe");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Person(org.qi4j.test.indexing.model.Person) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)204 Test (org.junit.Test)97 LocalDate (org.joda.time.LocalDate)28 DateTime (org.joda.time.DateTime)25 Interval (org.joda.time.Interval)19 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)13 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 ArrayList (java.util.ArrayList)12 SubstitutionScheduleDay (me.vertretungsplan.objects.SubstitutionScheduleDay)12 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)11 LocalTime (org.joda.time.LocalTime)11 Date (java.util.Date)10 SubstitutionSchedule (me.vertretungsplan.objects.SubstitutionSchedule)9 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)8 Substitution (me.vertretungsplan.objects.Substitution)7 HashMap (java.util.HashMap)5 DateTimeZone (org.joda.time.DateTimeZone)5 Test (org.junit.jupiter.api.Test)5 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 Before (org.junit.Before)4