use of org.joda.time.Duration in project gocd by gocd.
the class LocalizedMessageTest method shouldLocalizeDurations.
@Test
public void shouldLocalizeDurations() throws Exception {
Duration theDuration = new Duration(1000);
String expected = "it took a long time";
when(localizer.localize(theDuration)).thenReturn(expected);
assertThat(LocalizedMessage.localizeDuration(theDuration).localize(localizer), is(expected));
}
use of org.joda.time.Duration in project gocd by gocd.
the class LocalizerTest method shouldLocalizeDurations.
@Test
public void shouldLocalizeDurations() {
CurrentLocale locale = new CurrentLocale();
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("test_message");
MessageSourceAccessor accessor = new MessageSourceAccessor(source);
Localizer localizer = new Localizer(accessor, locale);
assertThat(localizer.localize(new Duration(1000)), is("1 second"));
assertThat(localizer.localize(new Duration(0)), is(""));
locale.setLocaleString(Localizer.LOCALE_KANNADA);
assertThat(localizer.localize(new Duration(1000)), is("1 second"));
}
use of org.joda.time.Duration in project dhis2-core by dhis2.
the class DefaultFileResourceService method ensureStorageStatus.
/**
* TODO Temporary fix. Remove at some point.
*
* Ensures correctness of the storageStatus of this FileResource.
*
* If the status has been 'PENDING' for more than 1 second we check to see if the content may actually have been stored.
* If this is the case the status is corrected to STORED.
*
* This method is a TEMPORARY fix for the for now unsolved issue with a race occurring between the Hibernate object cache
* and the upload callback attempting to modify the FileResource object upon completion.
*
* Resolving that issue (likely by breaking the StorageStatus into a separate table) should make this method redundant.
*/
private FileResource ensureStorageStatus(FileResource fileResource) {
if (fileResource != null && fileResource.getStorageStatus() == FileResourceStorageStatus.PENDING) {
Duration pendingDuration = new Duration(new DateTime(fileResource.getLastUpdated()), DateTime.now());
if (pendingDuration.isLongerThan(Seconds.seconds(1).toStandardDuration())) {
// Upload has been finished for 5+ seconds and is still PENDING.
// Check if content has actually been stored and correct to STORED if this is the case.
boolean contentIsStored = fileResourceContentStore.fileResourceContentExists(fileResource.getStorageKey());
if (contentIsStored) {
// We fix
fileResource.setStorageStatus(FileResourceStorageStatus.STORED);
fileResourceStore.update(fileResource);
log.warn("Corrected issue: FileResource '" + fileResource.getUid() + "' had storageStatus PENDING but content was actually stored.");
}
}
}
return fileResource;
}
use of org.joda.time.Duration in project verify-hub by alphagov.
the class AuthnRequestFromTransactionHandler method handleRequestFromTransaction.
public SessionId handleRequestFromTransaction(SamlResponseWithAuthnRequestInformationDto samlResponse, Optional<String> relayState, String ipAddress, URI assertionConsumerServiceUri, boolean transactionSupportsEidas) {
Duration sessionLength = policyConfiguration.getSessionLength();
DateTime sessionExpiryTimestamp = DateTime.now().plus(sessionLength);
SessionId sessionId = SessionId.createNewSessionId();
SessionStartedState sessionStartedState = new SessionStartedState(samlResponse.getId(), relayState.orNull(), samlResponse.getIssuer(), assertionConsumerServiceUri, samlResponse.getForceAuthentication().orNull(), sessionExpiryTimestamp, sessionId, transactionSupportsEidas);
final List<LevelOfAssurance> transactionLevelsOfAssurance = transactionsConfigProxy.getLevelsOfAssurance(samlResponse.getIssuer());
hubEventLogger.logSessionStartedEvent(samlResponse, ipAddress, sessionExpiryTimestamp, sessionId, transactionLevelsOfAssurance.get(0), transactionLevelsOfAssurance.get(transactionLevelsOfAssurance.size() - 1));
return sessionRepository.createSession(sessionStartedState);
}
use of org.joda.time.Duration in project FlareBot by FlareBot.
the class SeekCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length == 1) {
Long millis = GeneralUtils.parseTime(args[0]);
if (millis == null || millis > Integer.MAX_VALUE) {
MessageUtils.sendErrorMessage("You have entered an invalid duration to skip to!\n" + getExtraInfo(), channel);
return;
}
Track t = FlareBot.instance().getMusicManager().getPlayer(guild.getGuildId()).getPlayingTrack();
if (t == null) {
MessageUtils.sendErrorMessage("There is no song currently playing!", channel);
return;
} else {
if (t.getTrack().getInfo().isStream) {
MessageUtils.sendErrorMessage("Cannot seek on a livestream!", channel);
return;
} else if (!t.getTrack().isSeekable()) {
MessageUtils.sendErrorMessage("Cannot seek on this track!", channel);
return;
} else {
if (millis >= t.getTrack().getDuration()) {
MessageUtils.sendErrorMessage("The duration specified is bigger than the length of the video!", channel);
return;
} else {
t.getTrack().setPosition(millis);
MessageUtils.sendSuccessMessage("The track has been skipped to: " + FormatUtils.formatJodaTime(new Duration(millis).toPeriod()), channel);
return;
}
}
}
}
MessageUtils.sendUsage(this, channel, sender, args);
}
Aggregations