diff --git a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java index f649447..81f04f6 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -50,6 +50,7 @@ import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.backend.BackendQuery; import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest; import ch.psi.daq.domain.query.channels.ChannelsRequest; +import ch.psi.daq.domain.query.channels.LongHash; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.AggregationType; import ch.psi.daq.domain.query.operation.Compression; @@ -123,6 +124,14 @@ public class QueryRestController implements ApplicationContextAware { } } + @RequestMapping( + value = DomainConfig.PATH_CHANNELS_HASH, + method = {RequestMethod.GET}, + produces = {MediaType.APPLICATION_JSON_VALUE}) + public LongHash getChannelsHash() throws Throwable { + return queryManager.getChannelsHash(); + } + @RequestMapping( value = DomainConfig.PATH_CHANNELS, method = {RequestMethod.GET, RequestMethod.POST}, @@ -148,6 +157,14 @@ public class QueryRestController implements ApplicationContextAware { getChannels(new ChannelsRequest(channelName), res); } + @RequestMapping( + value = DomainConfig.PATH_CHANNELS_CONFIG_HASH, + method = {RequestMethod.GET}, + produces = {MediaType.APPLICATION_JSON_VALUE}) + public LongHash getChannelConfigurationsHash() throws Throwable { + return queryManager.getChannelConfigurationsHash(); + } + @RequestMapping( value = DomainConfig.PATH_CHANNELS_CONFIG, method = {RequestMethod.GET, RequestMethod.POST}, diff --git a/src/main/java/ch/psi/daq/queryrest/query/QueryManager.java b/src/main/java/ch/psi/daq/queryrest/query/QueryManager.java index 8b2327f..642c7e0 100644 --- a/src/main/java/ch/psi/daq/queryrest/query/QueryManager.java +++ b/src/main/java/ch/psi/daq/queryrest/query/QueryManager.java @@ -17,17 +17,24 @@ import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest; import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse; import ch.psi.daq.domain.query.channels.ChannelsRequest; import ch.psi.daq.domain.query.channels.ChannelsResponse; +import ch.psi.daq.domain.query.channels.LongHash; public interface QueryManager { - + + LongHash getChannelsHash(); + Stream getChannels(final ChannelsRequest request) throws Exception; - - Stream getChannelConfigurations(final ChannelConfigurationsRequest request) throws Exception; - + + LongHash getChannelConfigurationsHash(); + + Stream getChannelConfigurations(final ChannelConfigurationsRequest request) + throws Exception; + ChannelConfiguration getChannelConfiguration(final ChannelName channel) throws Exception; - - Entry>> queryConfigs(final DAQConfigQuery query) throws Exception; - + + Entry>> queryConfigs(final DAQConfigQuery query) + throws Exception; + List>>> queryEvents(final DAQQueries queries) throws Exception; -} +} diff --git a/src/main/java/ch/psi/daq/queryrest/query/QueryManagerImpl.java b/src/main/java/ch/psi/daq/queryrest/query/QueryManagerImpl.java index 1b8f0af..7283c21 100644 --- a/src/main/java/ch/psi/daq/queryrest/query/QueryManagerImpl.java +++ b/src/main/java/ch/psi/daq/queryrest/query/QueryManagerImpl.java @@ -33,6 +33,7 @@ import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest; import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse; import ch.psi.daq.domain.query.channels.ChannelsRequest; import ch.psi.daq.domain.query.channels.ChannelsResponse; +import ch.psi.daq.domain.query.channels.LongHash; import ch.psi.daq.domain.query.processor.QueryProcessor; import ch.psi.daq.query.config.QueryConfig; import ch.psi.daq.queryrest.config.QueryRestConfig; @@ -47,13 +48,19 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware { final Backend backend = context.getBean(DomainConfig.BEAN_NAME_BACKEND_DEFAULT, Backend.class); context = backend.getApplicationContext(); - channelsCache = context.getBean(QueryConfig.BEAN_NAME_HISTORIC_CHANNELS_CACHE, BackendsChannelConfigurationCache.class); + channelsCache = + context.getBean(QueryConfig.BEAN_NAME_HISTORIC_CHANNELS_CACHE, BackendsChannelConfigurationCache.class); queryAnalizerFactory = context.getBean(QueryRestConfig.BEAN_NAME_QUERY_ANALIZER_FACTORY, Function.class); } @PreDestroy public void destroy() {} + @Override + public LongHash getChannelsHash() { + return channelsCache.getChannelsHash(); + } + @Override public Stream getChannels(ChannelsRequest request) { // in case not specified use defaults (e.g. GET) @@ -64,6 +71,11 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware { return channelsCache.getChannels(request); } + @Override + public LongHash getChannelConfigurationsHash() { + return channelsCache.getChannelConfigurationsHash(); + } + @Override public Stream getChannelConfigurations(ChannelConfigurationsRequest request) { // in case not specified use defaults (e.g. GET) @@ -100,7 +112,7 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware { return channelToConfig.entrySet().stream() .map(entry -> { return Triple.of( - query, + query, new ChannelName(entry.getKey(), query.getBackend()), entry.getValue()); }); diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTest.java index 64ec4c5..3b4b07a 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTest.java @@ -19,6 +19,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; @@ -32,6 +33,7 @@ import ch.psi.daq.domain.query.DAQQueries; import ch.psi.daq.domain.query.DAQQuery; import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.channels.ChannelsRequest; +import ch.psi.daq.domain.query.channels.LongHash; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.AggregationDescriptor; import ch.psi.daq.domain.query.operation.AggregationType; @@ -72,6 +74,8 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements private Backend backend; private Backend backend2; private Backend backend3; + + private ObjectMapper objectMapper = new ObjectMapper(); @Override public void setApplicationContext(ApplicationContext context) throws BeansException { @@ -122,6 +126,41 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements .andExpect(MockMvcResultMatchers.jsonPath("$[2].channels[1]").value("BoolWaveform")); } + + @Test + public void testChannelsHash() throws Exception { + MvcResult result = this.mockMvc + .perform( + MockMvcRequestBuilders + .get(DomainConfig.PATH_CHANNELS_HASH) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + String response = result.getResponse().getContentAsString(); + System.out.println("Response: " + response); + + LongHash hash1 = + objectMapper.readValue(response, LongHash.class); + + result = this.mockMvc + .perform( + MockMvcRequestBuilders + .get(DomainConfig.PATH_CHANNELS_HASH) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + response = result.getResponse().getContentAsString(); + System.out.println("Response: " + response); + + LongHash hash2 = + objectMapper.readValue(response, LongHash.class); + + assertEquals(hash1.getHash(), hash2.getHash()); + } @Test public void testSpecificChannelSearch() throws Exception { diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerChannelConfigurationTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerChannelConfigurationTest.java index 2bc4a90..e68db92 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerChannelConfigurationTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerChannelConfigurationTest.java @@ -33,6 +33,7 @@ import ch.psi.daq.domain.json.ChannelConfigurationsList; import ch.psi.daq.domain.query.DAQConfigQuery; import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest; import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse; +import ch.psi.daq.domain.query.channels.LongHash; import ch.psi.daq.domain.request.range.RequestRangePulseId; import ch.psi.daq.test.queryrest.AbstractDaqRestTest; @@ -49,6 +50,41 @@ public class QueryRestControllerChannelConfigurationTest extends AbstractDaqRest @After public void tearDown() throws Exception {} + @Test + public void testChannelConfigurationsHash() throws Exception { + MvcResult result = this.mockMvc + .perform( + MockMvcRequestBuilders + .get(DomainConfig.PATH_CHANNELS_CONFIG_HASH) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + String response = result.getResponse().getContentAsString(); + System.out.println("Response: " + response); + + LongHash hash1 = + objectMapper.readValue(response, LongHash.class); + + result = this.mockMvc + .perform( + MockMvcRequestBuilders + .get(DomainConfig.PATH_CHANNELS_CONFIG_HASH) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn(); + + response = result.getResponse().getContentAsString(); + System.out.println("Response: " + response); + + LongHash hash2 = + objectMapper.readValue(response, LongHash.class); + + assertEquals(hash1.getHash(), hash2.getHash()); + } + @Test public void testChannelConfigurationQuery_01() throws Exception { DAQConfigQuery query = new DAQConfigQuery(