Skip to content

Package: DefaultSiteProvider

DefaultSiteProvider

nameinstructionbranchcomplexitylinemethod
DefaultSiteProvider()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
getContextPath()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDocumentPath()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIgnoredFoldersAsString()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLibraryPath()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLocalesAsString()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMediaPath()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNodePath()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSite()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getVersionString()
M: 0 C: 6
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: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
initialize(DefaultSite)
M: 0 C: 43
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
isLogConfigurationEnabled()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isSiteAvailable()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$getSite$0()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$reload$1()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
reload()
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
setDocumentPath(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setIgnoredFoldersAsString(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setLibraryPath(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setLocalesAsString(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setLogConfigurationEnabled(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setMediaPath(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setNodePath(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.core.impl.model;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.PostConstruct;
31: import javax.inject.Inject;
32: import javax.inject.Named;
33: import java.util.ArrayList;
34: import java.util.List;
35: import java.util.Locale;
36: import java.util.Optional;
37: import java.util.concurrent.atomic.AtomicBoolean;
38: import java.util.stream.Stream;
39: import java.io.File;
40: import java.io.IOException;
41: import javax.servlet.ServletContext;
42: import org.springframework.core.task.TaskExecutor;
43: import it.tidalwave.util.BundleUtilities;
44: import it.tidalwave.util.NotFoundException;
45: import it.tidalwave.northernwind.core.model.ModelFactory;
46: import it.tidalwave.northernwind.core.model.Site;
47: import it.tidalwave.northernwind.core.model.SiteProvider;
48: import lombok.Getter;
49: import lombok.Setter;
50: import lombok.ToString;
51: import lombok.extern.slf4j.Slf4j;
52: import static java.util.stream.Collectors.*;
53:
54: /***********************************************************************************************************************
55: *
56: * The default implementation of {@link SiteProvider}.
57: *
58: * @author Fabrizio Giudici
59: *
60: **********************************************************************************************************************/
61: @Slf4j @ToString
62: public class DefaultSiteProvider implements SiteProvider
63: {
64: private static final String ASTERISKS = "****************************************";
65:
66: private static final String DEFAULT_DOCUMENT_PATH = "/content/document";
67:
68: private static final String DEFAULT_MEDIA_PATH = "/content/media";
69:
70: private static final String DEFAULT_LIBRARY_PATH = "/content/library";
71:
72: private static final String DEFAULT_NODE_PATH = "/structure";
73:
74: public static final String DEFAULT_CONTEXT_PATH = "/";
75:
76: @Inject
77: private Optional<ServletContext> servletContext;
78:
79: @Inject
80: private ModelFactory modelFactory;
81:
82: @Inject @Named("taskExecutor")
83: private TaskExecutor executor;
84:
85: @Getter @Setter @Nonnull
86: private String documentPath = DEFAULT_DOCUMENT_PATH;
87:
88: @Getter @Setter @Nonnull
89: private String mediaPath = DEFAULT_MEDIA_PATH;
90:
91: @Getter @Setter @Nonnull
92: private String libraryPath = DEFAULT_LIBRARY_PATH;
93:
94: @Getter @Setter @Nonnull
95: private String nodePath = DEFAULT_NODE_PATH;
96:
97: @Getter @Setter
98: private boolean logConfigurationEnabled;
99:
100: @Getter @Setter @Nonnull
101: private String localesAsString = "";
102:
103: @Getter @Setter @Nonnull
104: private String ignoredFoldersAsString = "";
105:
106: private final List<String> ignoredFolders = new ArrayList<>();
107:
108: private final List<Locale> configuredLocales = new ArrayList<>();
109:
110: private Optional<DefaultSite> site = Optional.empty();
111:
112: private final AtomicBoolean siteAvailable = new AtomicBoolean();
113:
114: /*******************************************************************************************************************
115: *
116: * {@inheritDoc}
117: *
118: ******************************************************************************************************************/
119: @Override @Nonnull
120: public Site getSite()
121: {
122: return site.orElseThrow(() -> new IllegalStateException("Initialization error - @PostConstruct not called?"));
123: }
124:
125: /*******************************************************************************************************************
126: *
127: * {@inheritDoc}
128: *
129: ******************************************************************************************************************/
130: @Override
131: public boolean isSiteAvailable()
132: {
133: return siteAvailable.get();
134: }
135:
136: /*******************************************************************************************************************
137: *
138: * {@inheritDoc}
139: *
140: ******************************************************************************************************************/
141: @Override
142: public void reload()
143: {
144: log.info("reload()");
145: siteAvailable.set(false);
146:
147: site = Optional.of((DefaultSite)modelFactory.createSite().withContextPath(getContextPath())
148: .withDocumentPath(documentPath)
149: .withMediaPath(mediaPath)
150: .withLibraryPath(libraryPath)
151: .withNodePath(nodePath)
152: .withLogConfigurationEnabled(logConfigurationEnabled)
153: .withConfiguredLocales(configuredLocales)
154: .withIgnoredFolders(ignoredFolders)
155: .build());
156: executor.execute(() -> initialize(site.get()));
157: }
158:
159: /*******************************************************************************************************************
160: *
161: * {@inheritDoc}
162: *
163: ******************************************************************************************************************/
164: @Override @Nonnull
165: public String getVersionString()
166: {
167: return BundleUtilities.getMessage(DefaultSiteProvider.class, "NorthernWind.version");
168: }
169:
170: /*******************************************************************************************************************
171: *
172: *
173: *
174: ******************************************************************************************************************/
175: @PostConstruct
176: /* package */ void initialize()
177: {
178: log.info("initialize()");
179: ignoredFolders.addAll(List.of(ignoredFoldersAsString.trim().split(File.pathSeparator)));
180: configuredLocales.addAll(Stream.of(localesAsString.split(","))
181: .map(String::trim)
182: .map(Locale::new)
183: .collect(toList()));
184: reload();
185: }
186:
187: /*******************************************************************************************************************
188: *
189: *
190: *
191: ******************************************************************************************************************/
192: private void initialize (@Nonnull final DefaultSite site)
193: {
194: try
195: {
196: log.info(ASTERISKS);
197: log.info("SITE INITIALIZATION STARTED");
198: log.info(ASTERISKS);
199: final var time = System.currentTimeMillis();
200: site.initialize();
201: siteAvailable.set(true);
202: log.info(ASTERISKS);
203: log.info("SITE INITIALIZATION COMPLETED (in {} msec)", System.currentTimeMillis() - time);
204: log.info(ASTERISKS);
205: }
206: catch (IOException | NotFoundException | RuntimeException e)
207: {
208: log.error(ASTERISKS);
209: log.error("SITE INITIALIZATION FAILED!", e);
210: log.error(ASTERISKS);
211: }
212: }
213:
214: /*******************************************************************************************************************
215: *
216: *
217: *
218: ******************************************************************************************************************/
219: @Nonnull
220: /* package */ String getContextPath()
221: {
222: return servletContext.map(ServletContext::getContextPath).orElse(DEFAULT_CONTEXT_PATH);
223: // log.warn("Running in a non-web environment, set contextPath = {}", DEFAULT_CONTEXT_PATH);
224: }
225: }