This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#69 - uses ticking clock to run commands seemingly at the time that t…
…hey occurred on master. Also... also: - CommandJdos when saved for replay use the timestamp from the DTO, rather than the startedAt. - adds new TickingClockService (similar to SudoService, but for time rather than user) - removes logic to populate userData in CommandJdo#asDto, this is now done in Isis' ContentMappingServiceForCommandDto.
- Loading branch information
1 parent
c8306c4
commit 85826da
Showing
6 changed files
with
94 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...d/replay/src/main/java/org/isisaddons/module/command/replay/impl/TickingClockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.isisaddons.module.command.replay.impl; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.concurrent.Callable; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.isis.applib.ApplicationException; | ||
import org.apache.isis.applib.annotation.DomainService; | ||
import org.apache.isis.applib.annotation.NatureOfService; | ||
import org.apache.isis.applib.annotation.Programmatic; | ||
import org.apache.isis.applib.fixtures.TickingFixtureClock; | ||
import org.apache.isis.core.metamodel.services.configinternal.ConfigurationServiceInternal; | ||
|
||
/** | ||
* If configured as the slave, then sets up to use {@link TickingFixtureClock} | ||
* so that time can be changed dynamically when running. | ||
*/ | ||
@DomainService(nature = NatureOfService.DOMAIN, menuOrder = "1") | ||
public class TickingClockService { | ||
|
||
@PostConstruct | ||
public void init() { | ||
if( notDefined(Constants.MASTER_BASE_URL_ISIS_KEY) || | ||
notDefined(Constants.MASTER_USER_ISIS_KEY) || | ||
notDefined(Constants.MASTER_PASSWORD_ISIS_KEY)) { | ||
return; | ||
} | ||
TickingFixtureClock.replaceExisting(); | ||
} | ||
|
||
private boolean notDefined(final String key) { | ||
return configurationServiceInternal.getProperty(key) == null; | ||
} | ||
|
||
@Programmatic | ||
public void at(Timestamp timestamp, Runnable runnable) { | ||
final TickingFixtureClock instance = (TickingFixtureClock) TickingFixtureClock.getInstance(); | ||
final Timestamp previous = TickingFixtureClock.getTimeAsJavaSqlTimestamp(); | ||
try { | ||
instance.setTime(timestamp); | ||
runnable.run(); | ||
} finally { | ||
instance.setTime(previous); | ||
} | ||
} | ||
|
||
@Programmatic | ||
public <T> T at(Timestamp timestamp, Callable<T> callable) { | ||
final TickingFixtureClock instance = (TickingFixtureClock) TickingFixtureClock.getInstance(); | ||
final Timestamp previous = TickingFixtureClock.getTimeAsJavaSqlTimestamp(); | ||
try { | ||
instance.setTime(timestamp); | ||
return callable.call(); | ||
} catch (Exception e) { | ||
throw new ApplicationException(e); | ||
} finally { | ||
instance.setTime(previous); | ||
} | ||
} | ||
|
||
@Inject | ||
ConfigurationServiceInternal configurationServiceInternal; | ||
} |