You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/11 08:04:29 UTC
[isis] 02/02: ISIS-2726: inlines ClockServiceDefault with
ClockService
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2726
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 42c638cc17ca6d5d08a1bca7a5bb1d4748f67af1
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jun 11 09:04:07 2021 +0100
ISIS-2726: inlines ClockServiceDefault with ClockService
no need for subclassing; is just a wrapper around InteractionLayerTracker service
---
.../org/apache/isis/applib/IsisModuleApplib.java | 2 +
.../isis/applib/services/clock/ClockService.java | 31 +++++++++++--
.../isis/applib/services/clock/package-info.java | 25 ----------
.../iactnlayer/InteractionLayerTracker.java | 3 ++
.../IsisModuleCoreRuntimeServices.java | 2 -
.../runtimeservices/clock/ClockServiceDefault.java | 54 ----------------------
.../CalendarServiceTest_beginningOfMonth.java | 16 +++----
.../CalendarServiceTest_beginningOfQuarter.java | 46 +++++++++---------
8 files changed, 64 insertions(+), 115 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
index 41a2972..a307456 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
@@ -39,6 +39,7 @@ import org.apache.isis.applib.services.appfeatui.ApplicationTypeMember;
import org.apache.isis.applib.services.appfeatui.ApplicationTypeProperty;
import org.apache.isis.applib.services.bookmark.BookmarkHolder_lookup;
import org.apache.isis.applib.services.bookmark.BookmarkHolder_object;
+import org.apache.isis.applib.services.clock.ClockService;
import org.apache.isis.applib.services.commanddto.conmap.ContentMappingServiceForCommandDto;
import org.apache.isis.applib.services.commanddto.conmap.ContentMappingServiceForCommandsDto;
import org.apache.isis.applib.services.commanddto.processor.spi.CommandDtoProcessorServiceIdentity;
@@ -93,6 +94,7 @@ import org.apache.isis.schema.IsisModuleSchema;
UserMemento.class,
// @DomainService(s)
+ ClockService.class,
ConfigurationMenu.class,
LayoutServiceMenu.class,
ImpersonateMenu.class,
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java b/api/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
index a924101..72017f4 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
@@ -18,7 +18,20 @@
*/
package org.apache.isis.applib.services.clock;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Service;
+
+import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.clock.VirtualClock;
+import org.apache.isis.applib.services.iactnlayer.InteractionContext;
+import org.apache.isis.applib.services.iactnlayer.InteractionLayerTracker;
+
+import lombok.RequiredArgsConstructor;
/**
* This service allows an application to be decoupled from the system time.
@@ -28,13 +41,25 @@ import org.apache.isis.applib.clock.VirtualClock;
*
* @since 1.x revised for 2.0 {@index}
*/
-public interface ClockService {
+@Service
+@Named("isis.applib.ClockService")
+@Order(OrderPrecedence.MIDPOINT)
+@Primary
+@Qualifier("Default")
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+public class ClockService {
- VirtualClock getClock();
+ private final InteractionLayerTracker interactionLayerTracker;
+
+ public VirtualClock getClock() {
+ return interactionLayerTracker.currentInteractionContext()
+ .map(InteractionContext::getClock)
+ .orElseGet(VirtualClock::system);
+ }
// -- SHORTCUTS
- default long getEpochMillis() {
+ public long getEpochMillis() {
return getClock().getEpochMillis();
}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/clock/package-info.java b/api/applib/src/main/java/org/apache/isis/applib/services/clock/package-info.java
deleted file mode 100644
index 9f26221..0000000
--- a/api/applib/src/main/java/org/apache/isis/applib/services/clock/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * This domain service provides current time.
- *
- *
- */
-package org.apache.isis.applib.services.clock;
\ No newline at end of file
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionLayerTracker.java b/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionLayerTracker.java
index 3982018..d46145d 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionLayerTracker.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionLayerTracker.java
@@ -28,6 +28,9 @@ import org.apache.isis.commons.internal.exceptions._Exceptions;
* Provides access to the current {@link InteractionLayer}.
*
* @see InteractionService
+ * @see org.apache.isis.applib.services.sudo.SudoService
+ * @see org.apache.isis.applib.services.clock.ClockService
+ *
* @since 2.0 {@index}
*/
public interface InteractionLayerTracker
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
index 600d7b4..b731b99 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/IsisModuleCoreRuntimeServices.java
@@ -29,7 +29,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.apache.isis.core.codegen.bytebuddy.IsisModuleCoreCodegenByteBuddy;
import org.apache.isis.core.runtime.IsisModuleCoreRuntime;
import org.apache.isis.core.runtimeservices.bookmarks.BookmarkServiceDefault;
-import org.apache.isis.core.runtimeservices.clock.ClockServiceDefault;
import org.apache.isis.core.runtimeservices.command.CommandDtoFactoryDefault;
import org.apache.isis.core.runtimeservices.command.CommandExecutorServiceDefault;
import org.apache.isis.core.runtimeservices.email.EmailServiceDefault;
@@ -75,7 +74,6 @@ import org.apache.isis.core.runtimeservices.xmlsnapshot.XmlSnapshotServiceDefaul
BookmarkServiceDefault.class,
EntityChangesPublisherDefault.class,
EntityPropertyChangePublisherDefault.class,
- ClockServiceDefault.class,
CommandDtoFactoryDefault.class,
CommandExecutorServiceDefault.class,
CommandPublisherDefault.class,
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/clock/ClockServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/clock/ClockServiceDefault.java
deleted file mode 100644
index 18729d5..0000000
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/clock/ClockServiceDefault.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.core.runtimeservices.clock;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Primary;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Service;
-
-import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.applib.clock.VirtualClock;
-import org.apache.isis.applib.services.clock.ClockService;
-import org.apache.isis.applib.services.iactnlayer.InteractionContext;
-import org.apache.isis.applib.services.iactnlayer.InteractionLayerTracker;
-
-import lombok.RequiredArgsConstructor;
-
-@Service
-@Named("isis.runtimeservices.ClockServiceDefault")
-@Order(OrderPrecedence.MIDPOINT)
-@Primary
-@Qualifier("Default")
-@RequiredArgsConstructor(onConstructor_ = {@Inject})
-public class ClockServiceDefault implements ClockService {
-
- private final InteractionLayerTracker interactionLayerTracker;
-
- @Override
- public VirtualClock getClock() {
- return interactionLayerTracker.currentInteractionContext()
- .map(InteractionContext::getClock)
- .orElseGet(VirtualClock::system);
- }
-
-}
diff --git a/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfMonth.java b/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfMonth.java
index 2599620..95ed197 100644
--- a/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfMonth.java
+++ b/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfMonth.java
@@ -46,21 +46,21 @@ public class CalendarServiceTest_beginningOfMonth {
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
- new Object[][] {
- { LocalDate.of(2013,4,15), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,4,1), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,4,30), LocalDate.of(2013,4,1)},
+ new Object[][] {
+ { LocalDate.of(2013,4,15), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,4,1), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,4,30), LocalDate.of(2013,4,1)},
});
}
-
+
public CalendarServiceTest_beginningOfMonth(LocalDate date, LocalDate expected) {
this.now = date;
this.expected = expected;
}
-
+
@Before
public void setUp() throws Exception {
- stubClockService = new ClockService() {
+ stubClockService = new ClockService(null) {
@Override
public VirtualClock getClock() {
return VirtualClock.frozenAt(Instant.from(now));
@@ -68,7 +68,7 @@ public class CalendarServiceTest_beginningOfMonth {
};
calendarService = new CalendarService(stubClockService);
}
-
+
@Test
public void test() throws Exception {
assertThat(calendarService.beginningOfMonth(), is(expected));
diff --git a/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfQuarter.java b/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfQuarter.java
index e5d9fee..bba8046 100644
--- a/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfQuarter.java
+++ b/subdomains/base/applib/src/test/java/org/apache/isis/subdomains/base/applib/services/calendar/CalendarServiceTest_beginningOfQuarter.java
@@ -46,36 +46,36 @@ public class CalendarServiceTest_beginningOfQuarter {
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
- new Object[][] {
- { LocalDate.of(2013,1,15), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,1,1), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,1,31), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,2,15), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,2,1), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,2,28), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,3,15), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,3,1), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,3,31), LocalDate.of(2013,1,1)},
- { LocalDate.of(2013,4,15), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,4,1), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,4,30), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,5,15), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,5,1), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,5,31), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,6,15), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,6,1), LocalDate.of(2013,4,1)},
- { LocalDate.of(2013,6,30), LocalDate.of(2013,4,1)},
+ new Object[][] {
+ { LocalDate.of(2013,1,15), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,1,1), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,1,31), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,2,15), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,2,1), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,2,28), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,3,15), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,3,1), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,3,31), LocalDate.of(2013,1,1)},
+ { LocalDate.of(2013,4,15), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,4,1), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,4,30), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,5,15), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,5,1), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,5,31), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,6,15), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,6,1), LocalDate.of(2013,4,1)},
+ { LocalDate.of(2013,6,30), LocalDate.of(2013,4,1)},
});
}
-
+
public CalendarServiceTest_beginningOfQuarter(LocalDate date, LocalDate expected) {
this.now = date;
this.expected = expected;
}
-
+
@Before
public void setUp() throws Exception {
- stubClockService = new ClockService() {
+ stubClockService = new ClockService(null) {
@Override
public VirtualClock getClock() {
return VirtualClock.frozenAt(Instant.from(now));
@@ -83,7 +83,7 @@ public class CalendarServiceTest_beginningOfQuarter {
};
calendarService = new CalendarService(stubClockService);
}
-
+
@Test
public void test() throws Exception {
assertThat(calendarService.beginningOfQuarter(), is(expected));