Example usage for org.joda.time.format DateTimeFormatter print

List of usage examples for org.joda.time.format DateTimeFormatter print

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter print.

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:org.apache.falcon.regression.core.util.Util.java

License:Apache License

/**
 * Finds first folder within a date range.
 * @param startTime start date/*  ww  w . ja va 2 s  .com*/
 * @param endTime end date
 * @param folderList list of folders which are under analysis
 * @return first matching folder or null if not present in a list
 */
public static String findFolderBetweenGivenTimeStamps(DateTime startTime, DateTime endTime,
        List<String> folderList) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd/HH/mm");
    for (String folder : folderList) {
        if (folder.compareTo(formatter.print(startTime)) >= 0
                && folder.compareTo(formatter.print(endTime)) <= 0) {
            return folder;
        }
    }
    return null;
}

From source file:org.apache.falcon.state.InstanceID.java

License:Apache License

public InstanceID(EntityType entityType, String entityName, String clusterName, DateTime instanceTime) {
    this.entityType = entityType;
    this.entityName = entityName;
    this.clusterName = clusterName;
    this.instanceTime = new DateTime(instanceTime);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(INSTANCE_FORMAT);
    this.key = this.entityType + KEY_SEPARATOR + this.entityName + KEY_SEPARATOR + this.clusterName
            + KEY_SEPARATOR + fmt.print(instanceTime);
}

From source file:org.apache.fineract.portfolio.calendar.service.CalendarWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult createCalendar(final JsonCommand command) {

    this.fromApiJsonDeserializer.validateForCreate(command.json());
    Long entityId = null;//from   ww  w  . j  ava  2s  . com
    CalendarEntityType entityType = CalendarEntityType.INVALID;
    LocalDate entityActivationDate = null;
    Group centerOrGroup = null;
    if (command.getGroupId() != null) {
        centerOrGroup = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
        entityActivationDate = centerOrGroup.getActivationLocalDate();
        entityType = centerOrGroup.isCenter() ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS;
        entityId = command.getGroupId();
    } else if (command.getLoanId() != null) {
        final Loan loan = this.loanRepository.findOne(command.getLoanId());
        entityActivationDate = (loan.getApprovedOnDate() == null) ? loan.getSubmittedOnDate()
                : loan.getApprovedOnDate();
        entityType = CalendarEntityType.LOANS;
        entityId = command.getLoanId();
    } else if (command.getClientId() != null) {
        final Client client = this.clientRepository.findOneWithNotFoundDetection(command.getClientId());
        entityActivationDate = client.getActivationLocalDate();
        entityType = CalendarEntityType.CLIENTS;
        entityId = command.getClientId();
    }

    final Integer entityTypeId = entityType.getValue();
    final Calendar newCalendar = Calendar.fromJson(command);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("calendar");
    if (entityActivationDate == null || newCalendar.getStartDateLocalDate().isBefore(entityActivationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        String dateAsString = "";
        if (entityActivationDate != null)
            dateAsString = formatter.print(entityActivationDate);

        final String errorMessage = "cannot.be.before." + entityType.name().toLowerCase() + ".activation.date";
        baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue())
                .value(dateAsString).failWithCodeNoParameterAddedToErrorCode(errorMessage);
    }

    if (centerOrGroup != null) {
        Long centerOrGroupId = centerOrGroup.getId();
        Integer centerOrGroupEntityTypeId = entityType.getValue();

        final Group parent = centerOrGroup.getParent();
        if (parent != null) {
            centerOrGroupId = parent.getId();
            centerOrGroupEntityTypeId = CalendarEntityType.CENTERS.getValue();
        }

        final CalendarInstance collectionCalendarInstance = this.calendarInstanceRepository
                .findByEntityIdAndEntityTypeIdAndCalendarTypeId(centerOrGroupId, centerOrGroupEntityTypeId,
                        CalendarType.COLLECTION.getValue());
        if (collectionCalendarInstance != null) {
            final String errorMessage = "multiple.collection.calendar.not.supported";
            baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(errorMessage);
        }
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    this.calendarRepository.save(newCalendar);

    final CalendarInstance newCalendarInstance = CalendarInstance.from(newCalendar, entityId, entityTypeId);
    this.calendarInstanceRepository.save(newCalendarInstance);

    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withEntityId(newCalendar.getId()) //
            .withClientId(command.getClientId()) //
            .withGroupId(command.getGroupId()) //
            .withLoanId(command.getLoanId()) //
            .build();

}

From source file:org.apache.fineract.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> validateAndApprove(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }//from   www .  jav  a 2  s  .c o  m
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.approvalParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    LocalDate approvedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element);
    final LocalDate submittalDate = new LocalDate(account.getSubmittedDate());
    if (approvedDate != null && approvedDate.isBefore(submittalDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);
        baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("approved.date.cannot.be.before.submitted.date");
    }

    Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
    for (ShareAccountTransaction transaction : transactions) {
        if (transaction.isActive() && transaction.isPendingForApprovalTransaction()) {
            validateTotalSubsribedShares(account, transaction, baseDataValidator);
        }
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

    AppUser approvedUser = this.platformSecurityContext.authenticatedUser();
    account.approve(approvedDate.toDate(), approvedUser);
    actualChanges.put(ShareAccountApiConstants.id_paramname, account.getId());
    updateTotalChargeDerived(account);
    return actualChanges;
}

From source file:org.apache.fineract.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> validateAndActivate(JsonCommand jsonCommand, ShareAccount account) {
    Map<String, Object> actualChanges = new HashMap<>();
    if (StringUtils.isBlank(jsonCommand.json())) {
        throw new InvalidJsonException();
    }//from w  w  w  .j  a v a 2  s  .com
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(),
            ShareAccountApiConstants.activateParameters);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("sharesaccount");
    JsonElement element = jsonCommand.parsedJson();
    LocalDate activatedDate = this.fromApiJsonHelper
            .extractLocalDateNamed(ShareAccountApiConstants.activatedate_paramname, element);
    baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname).value(activatedDate)
            .notNull();
    final LocalDate approvedDate = new LocalDate(account.getApprovedDate());
    if (activatedDate != null && activatedDate.isBefore(approvedDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat())
                .withLocale(jsonCommand.extractLocale());
        final String submittalDateAsString = formatter.print(approvedDate);
        baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approved.date");
    }
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
    AppUser approvedUser = this.platformSecurityContext.authenticatedUser();
    account.activate(activatedDate.toDate(), approvedUser);
    handlechargesOnActivation(account);
    actualChanges.put(ShareAccountApiConstants.charges_paramname, activatedDate.toDate());
    return actualChanges;
}

From source file:org.apache.gobblin.source.PartitionedFileSourceBase.java

License:Apache License

@Override
public List<WorkUnit> getWorkunits(SourceState state) {

    lineageInfo = LineageInfo.getLineageInfo(state.getBroker());
    DateTimeFormatter formatter = DateTimeFormat.fullDateTime();

    // Initialize all instance variables for this object
    init(state);//from www  .j  a v  a 2 s.  c  om

    LOG.info("Will pull data from " + formatter.print(this.lowWaterMark) + " until " + this.maxFilesPerJob
            + " files have been processed, or until there is no more data to consume");
    LOG.info("Creating workunits");

    // Weighted MultiWorkUnitWeightedQueue, the job will add new WorkUnits to the queue along with a weight for each
    // WorkUnit. The queue will take care of balancing the WorkUnits amongst a set number of MultiWorkUnits
    MultiWorkUnitWeightedQueue multiWorkUnitWeightedQueue = new MultiWorkUnitWeightedQueue(
            this.maxWorkUnitsPerJob);

    // Add failed work units from the previous execution
    addFailedWorkUnits(getPreviousWorkUnitsForRetry(this.sourceState), multiWorkUnitWeightedQueue);

    // If the file count has not exceeded maxFilesPerJob then start adding new WorkUnits to for this job
    if (this.fileCount >= this.maxFilesPerJob) {
        LOG.info(
                "The number of work units from previous job has already reached the upper limit, no more workunits will be made");
        return multiWorkUnitWeightedQueue.getQueueAsList();
    }

    addNewWorkUnits(multiWorkUnitWeightedQueue);

    List<WorkUnit> workUnits = multiWorkUnitWeightedQueue.getQueueAsList();
    addLineageSourceInfo(workUnits, state);

    return workUnits;
}

From source file:org.apache.isis.core.metamodel.facets.value.datejodalocal.JodaLocalDateUtil.java

License:Apache License

public static String titleString(final DateTimeFormatter formatter, final LocalDate date) {
    return date == null ? "" : formatter.print(date);
}

From source file:org.apache.isis.core.metamodel.facets.value.datetimejodalocal.JodaLocalDateTimeUtil.java

License:Apache License

public static String titleString(final DateTimeFormatter formatter, final LocalDateTime date) {
    return date == null ? "" : formatter.print(date);
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.datepicker.DateTimeConfig.java

License:Apache License

/**
 * The earliest date that may be selected; all earlier dates will be disabled.
 *
 * @param value the earliest start date/*from w  w w  . ja  v a  2  s .  c o m*/
 * @return this instance for chaining
 */
public DateTimeConfig withStartDate(final DateTime value) {
    String format = getFormat();
    String startDate;
    if (Strings.isEmpty(format)) {
        startDate = value.toString();
    } else {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(format);
        startDate = dateTimeFormatter.print(value);
    }
    put(StartDate, startDate);
    return this;
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.datepicker.DateTimeConfig.java

License:Apache License

/**
 * The latest date that may be selected; all later dates will be disabled.
 *
 * @param value the latest end date//w w  w  . j  av a  2 s  . co  m
 * @return this instance for chaining
 */
public DateTimeConfig withEndDate(final DateTime value) {
    Args.notNull(value, "value");
    String format = getFormat();
    String endDate;
    if (Strings.isEmpty(format)) {
        endDate = value.toString();
    } else {
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(format);
        endDate = dateTimeFormatter.print(value);
    }
    put(EndDate, endDate);
    return this;
}