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