Skip to content

Package: ResourcePropertiesSaveable

ResourcePropertiesSaveable

nameinstructionbranchcomplexitylinemethod
ResourcePropertiesSaveable(TimeProvider, ResourceProperties)
M: 23 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
saveExternalProperties(ResourceProperties, WritableFolder)
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
saveIn(ResourceFile)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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 git@bitbucket.org:tidalwave/northernwind-rca-src.git
7: * %%
8: * Copyright (C) 2013 - 2021 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.model.impl.admin.role;
28:
29: import javax.annotation.Nonnull;
30: import java.util.List;
31: import java.io.IOException;
32: import it.tidalwave.util.TimeProvider;
33: import it.tidalwave.util.Key;
34: import it.tidalwave.dci.annotation.DciRole;
35: import it.tidalwave.northernwind.core.model.ResourceFile;
36: import it.tidalwave.northernwind.core.model.ResourceProperties;
37: import it.tidalwave.northernwind.model.admin.role.WritableFolder;
38: import it.tidalwave.northernwind.model.admin.role.Saveable;
39: import lombok.RequiredArgsConstructor;
40: import lombok.extern.slf4j.Slf4j;
41: import static it.tidalwave.role.io.Marshallable.*;
42: import static it.tidalwave.northernwind.model.admin.Properties.*;
43: import static it.tidalwave.northernwind.model.admin.role.WritableFolder.*;
44:
45: /***********************************************************************************************************************
46: *
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: @DciRole(datumType = ResourceProperties.class)
51:•@RequiredArgsConstructor @Slf4j
52: public class ResourcePropertiesSaveable implements Saveable
53: {
54: /** The properties that must be stored in a separate file. */
55: private static final List<Key<?>> EXTERNAL_PROPERTIES = List.of(PROPERTY_FULL_TEXT);
56:
57: @Nonnull
58: private final TimeProvider timeProvider;
59:
60: @Nonnull
61: private final ResourceProperties properties;
62:
63: @Override
64: public void saveIn (@Nonnull final ResourceFile folder)
65: {
66: try
67: {
68: log.debug("saveIn({}, {})", folder, properties);
69: final WritableFolder writableFolder = folder.as(_WritableFolder_);
70: final ResourceProperties p1 = properties.withProperty(PROPERTY_LATEST_MODIFICATION_DATE,
71: timeProvider.currentZonedDateTime());
72: final ResourceProperties p2 = saveExternalProperties(p1, writableFolder);
73: // FIXME: guess the localization (some properties go to Properties, some other to Properties_en.xml etc...
74: writableFolder.write("Properties.xml", p2.as(_Marshallable_));
75: }
76: catch (IOException e)
77: {
78: log.error("property class: " + properties.getClass(), e);
79: }
80: }
81:
82: @Nonnull
83: private ResourceProperties saveExternalProperties (@Nonnull ResourceProperties properties,
84: @Nonnull final WritableFolder writableFolder)
85: throws IOException
86: {
87:• for (final Key<?> property : EXTERNAL_PROPERTIES)
88: {
89: // FIXME: localization
90: // FIXME: conversion to string when different types are used
91: writableFolder.write(property.stringValue() + "_en.xhtml", properties.getProperty(property).get().toString());
92: properties = properties.withoutProperty(property);
93: }
94:
95: return properties;
96: }
97: }