Skip to content

Package: DefaultSiteViewController

DefaultSiteViewController

nameinstructionbranchcomplexitylinemethod
DefaultSiteViewController()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
initialize()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$initialize$0(RequestProcessor)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processRequest(Request)
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
resetRequestResettables()
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.ui.spi;
27:
28: import javax.annotation.Nonnull;
29: import javax.annotation.PostConstruct;
30: import javax.inject.Inject;
31: import java.util.List;
32: import org.springframework.context.annotation.Scope;
33: import org.springframework.core.annotation.AnnotationAwareOrderComparator;
34: import it.tidalwave.util.NotFoundException;
35: import it.tidalwave.northernwind.core.model.HttpStatusException;
36: import it.tidalwave.northernwind.core.model.Request;
37: import it.tidalwave.northernwind.core.model.RequestProcessor;
38: import it.tidalwave.northernwind.core.model.spi.RequestHolder;
39: import it.tidalwave.northernwind.core.model.spi.RequestResettable;
40: import it.tidalwave.northernwind.core.model.spi.ResponseHolder;
41: import it.tidalwave.northernwind.frontend.ui.SiteViewController;
42: import lombok.extern.slf4j.Slf4j;
43: import static it.tidalwave.northernwind.core.model.RequestProcessor.Status.*;
44:
45: /***************************************************************************************************************************************************************
46: *
47: * The default implementation of {@link SiteViewController}.
48: *
49: * @author Fabrizio Giudici
50: *
51: **************************************************************************************************************************************************************/
52: @Scope("session") @Slf4j
53: public class DefaultSiteViewController implements SiteViewController
54: {
55: @Inject
56: private List<RequestResettable> requestResettables;
57:
58: @Inject
59: private List<RequestProcessor> requestProcessors;
60:
61: @Inject
62: private RequestHolder requestHolder;
63:
64: @Inject
65: private ResponseHolder<?> responseHolder;
66:
67: /***********************************************************************************************************************************************************
68: * {@inheritDoc}
69: **********************************************************************************************************************************************************/
70: @Override @Nonnull @SuppressWarnings("unchecked")
71: public <RESPONSE_TYPE> RESPONSE_TYPE processRequest (@Nonnull final Request request)
72: {
73: try
74: {
75: log.info("processRequest({})", request);
76: resetRequestResettables();
77: requestHolder.set(request);
78:
79: for (final var requestProcessor : requestProcessors)
80: {
81: log.debug(">>>> trying {} ...", requestProcessor);
82:
83: if (requestProcessor.process(request) == BREAK)
84: {
85: break;
86: }
87: }
88:
89: return (RESPONSE_TYPE)responseHolder.get();
90: }
91: catch (NotFoundException e)
92: {
93: log.warn("processing: {} - {}", request, e.toString());
94: return (RESPONSE_TYPE)responseHolder.response().forException(e).build();
95: }
96: catch (HttpStatusException e)
97: {
98: if (e.isError())
99: {
100: log.warn("processing: " + request, e);
101: }
102:
103: return (RESPONSE_TYPE)responseHolder.response().forException(e).build();
104: }
105: catch (Exception e)
106: {
107: log.error("processing: " + request, e);
108: return (RESPONSE_TYPE)responseHolder.response().forException(e).build();
109: }
110: finally
111: {
112: resetRequestResettables();
113: }
114: }
115:
116: /***********************************************************************************************************************************************************
117: * Resets all {@link Resettable}s.
118: **********************************************************************************************************************************************************/
119: private void resetRequestResettables()
120: {
121:• for (final var requestResettable : requestResettables)
122: {
123: log.debug(">>>> resetting {} ...", requestResettable);
124: requestResettable.requestReset();
125: }
126: }
127:
128: /***********************************************************************************************************************************************************
129: * Logs the {@link RequestProcessor}s.
130: **********************************************************************************************************************************************************/
131: @PostConstruct
132: /* package */ void initialize()
133: {
134: requestProcessors.sort(new AnnotationAwareOrderComparator());
135: log.info(">>>> requestProcessors:");
136: requestProcessors.forEach(p -> log.info(">>>>>>>> {}", p));
137: }
138: }