Search in sources :

Example 1 with PoliciesDto

use of org.eclipse.che.api.factory.shared.dto.PoliciesDto in project che by eclipse.

the class FactoryBaseValidator method validateCurrentTimeAfterSinceUntil.

/**
     * Validates correct valid since and until times are used (on factory creation)
     *
     * @param factory
     *         factory to validate
     * @throws BadRequestException
     *         if since date greater or equal than until date
     * @throws BadRequestException
     *         if since date less than current date
     * @throws BadRequestException
     *         if until date less than current date
     */
protected void validateCurrentTimeAfterSinceUntil(FactoryDto factory) throws BadRequestException {
    final PoliciesDto policies = factory.getPolicies();
    if (policies == null) {
        return;
    }
    final Long since = policies.getSince() == null ? 0L : policies.getSince();
    final Long until = policies.getUntil() == null ? 0L : policies.getUntil();
    if (since != 0 && until != 0 && since >= until) {
        throw new BadRequestException(FactoryConstants.INVALID_SINCEUNTIL_MESSAGE);
    }
    if (since != 0 && currentTimeMillis() > since) {
        throw new BadRequestException(FactoryConstants.INVALID_SINCE_MESSAGE);
    }
    if (until != 0 && currentTimeMillis() > until) {
        throw new BadRequestException(FactoryConstants.INVALID_UNTIL_MESSAGE);
    }
}
Also used : BadRequestException(org.eclipse.che.api.core.BadRequestException) PoliciesDto(org.eclipse.che.api.factory.shared.dto.PoliciesDto)

Example 2 with PoliciesDto

use of org.eclipse.che.api.factory.shared.dto.PoliciesDto in project che by eclipse.

the class FactoryBaseValidator method validateCurrentTimeBetweenSinceUntil.

/**
     * Validates that factory can be used at present time (used on accept)
     *
     * @param factory
     *         factory to validate
     * @throws BadRequestException
     *         if since date greater than current date<br/>
     * @throws BadRequestException
     *         if until date less than current date<br/>
     */
protected void validateCurrentTimeBetweenSinceUntil(FactoryDto factory) throws BadRequestException {
    final PoliciesDto policies = factory.getPolicies();
    if (policies == null) {
        return;
    }
    final Long since = policies.getSince() == null ? 0L : policies.getSince();
    final Long until = policies.getUntil() == null ? 0L : policies.getUntil();
    if (since != 0 && currentTimeMillis() < since) {
        throw new BadRequestException(FactoryConstants.ILLEGAL_FACTORY_BY_SINCE_MESSAGE);
    }
    if (until != 0 && currentTimeMillis() > until) {
        throw new BadRequestException(FactoryConstants.ILLEGAL_FACTORY_BY_UNTIL_MESSAGE);
    }
}
Also used : BadRequestException(org.eclipse.che.api.core.BadRequestException) PoliciesDto(org.eclipse.che.api.factory.shared.dto.PoliciesDto)

Aggregations

BadRequestException (org.eclipse.che.api.core.BadRequestException)2 PoliciesDto (org.eclipse.che.api.factory.shared.dto.PoliciesDto)2