Package: ResourcePropertiesPresentable$PropertyPmFinder
ResourcePropertiesPresentable$PropertyPmFinder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ResourcePropertiesPresentable.PropertyPmFinder(ResourceProperties) |
|
|
|
|
|
||||||||||||||||||||
ResourcePropertiesPresentable.PropertyPmFinder(ResourcePropertiesPresentable.PropertyPmFinder, Object) |
|
|
|
|
|
||||||||||||||||||||
computeResults() |
|
|
|
|
|
||||||||||||||||||||
lambda$computeResults$0(Id, ResourceProperties, List, Key) |
|
|
|
|
|
||||||||||||||||||||
lambda$computeResults$1(Id, List, Id) |
|
|
|
|
|
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.ArrayList;
31: import java.util.Collection;
32: import java.util.List;
33: import it.tidalwave.role.Aggregate;
34: import it.tidalwave.util.Id;
35: import it.tidalwave.util.spi.SimpleFinderSupport;
36: import it.tidalwave.role.SimpleComposite;
37: import it.tidalwave.role.ui.Displayable;
38: import it.tidalwave.role.ui.Presentable;
39: import it.tidalwave.role.ui.PresentationModel;
40: import it.tidalwave.dci.annotation.DciRole;
41: import it.tidalwave.northernwind.core.model.ResourceProperties;
42: import lombok.RequiredArgsConstructor;
43: import lombok.extern.slf4j.Slf4j;
44: import static it.tidalwave.northernwind.rca.util.PropertyUtilities.*;
45: import static it.tidalwave.util.Parameters.r;
46:
47: /***********************************************************************************************************************
48: *
49: * A provider of a {@link PresentationModel} for {@link ResourceProperties} suitable for being rendered in a table.
50: * See {@link PropertyPmFinder#computeResults()} for more details.
51: *
52: * @stereotype Role
53: *
54: * @author Fabrizio Giudici
55: *
56: **********************************************************************************************************************/
57: @DciRole(datumType = ResourceProperties.class) @RequiredArgsConstructor @Slf4j
58: public class ResourcePropertiesPresentable implements Presentable
59: {
60: /*******************************************************************************************************************
61: *
62: * A {@link it.tidalwave.util.Finder} of {@link PresentationModel}s for each property inside a given
63: * {@link ResourceProperties}.
64: *
65: ******************************************************************************************************************/
66:• @RequiredArgsConstructor
67: static class PropertyPmFinder extends SimpleFinderSupport<PresentationModel>
68: {
69: private static final long serialVersionUID = 6614643999849054070L;
70:
71: @Nonnull
72: private final ResourceProperties properties;
73:
74: /***************************************************************************************************************
75: *
76: * The usual {@link it.tidalwave.util.Finder} copy constructor.
77: *
78: **************************************************************************************************************/
79: public PropertyPmFinder (@Nonnull final PropertyPmFinder other, @Nonnull final Object override)
80: {
81: super(other, override);
82: final PropertyPmFinder source = getSource(PropertyPmFinder.class, other, override);
83: this.properties = source.properties;
84: }
85:
86: /***************************************************************************************************************
87: *
88: * Each item is a {@link PresentationModel} containing an {@link it.tidalwave.role.Aggregate} suitable
89: * for being rendered in a table with two columns. It's made of two named objects:
90: *
91: * <ul>
92: * <li>{@code Name} contains a {@code PresentationModel} with a {@code Displayable} for the property
93: * name;</li>
94: * <li>{@code Value} contains a {@code PresentationModel} with a {@code Displayable} for the property
95: * value;</li>
96: * </ul>
97: *
98: * @return
99: *
100: **************************************************************************************************************/
101: @Override @Nonnull
102: protected List<? extends PresentationModel> computeResults()
103: {
104: final Id globalGroupId = new Id("");
105: final List<PresentationModel> results = new ArrayList<>();
106: final Collection<Id> groupIds = properties.getGroupIds();
107: groupIds.add(globalGroupId);
108:
109: groupIds.forEach(groupId ->
110: {
111:• final ResourceProperties propertyGroup = groupId.equals(globalGroupId) ? properties : properties.getGroup(groupId);
112:
113: propertyGroup.getKeys().forEach(key ->
114: {
115:• final String prefix = "".equals(groupId.stringValue()) ? "" : groupId.stringValue() + ".";
116: final Aggregate<PresentationModel> aggregate = Aggregate
117: .of("Name", PresentationModel.of(key, Displayable.of(prefix + key.stringValue())))
118: .with( "Value", PresentationModel.of(key, displayableForValue(propertyGroup, key)));
119: results.add(PresentationModel.of(key, r(properties, aggregate)));
120: });
121: });
122:
123: return results;
124: }
125: }
126:
127: @Nonnull
128: private final ResourceProperties ownerProperties;
129:
130: /*******************************************************************************************************************
131: *
132: * Creates a {@link PresentationModel} containing a {@link it.tidalwave.role.Composite} bound to the {@code
133: * PropertyPmFinder}.
134: *
135: * @param localRoles optional additional roles
136: * @return the {@code PresentationModel}
137: *
138: ******************************************************************************************************************/
139: @Override @Nonnull
140: public PresentationModel createPresentationModel (@Nonnull final Collection<Object> localRoles)
141: {
142: return PresentationModel.of(ownerProperties,
143: r(SimpleComposite.of(new PropertyPmFinder(ownerProperties)), localRoles));
144: }
145: }