Package: DefaultContentChildCreator
DefaultContentChildCreator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultContentChildCreator(MessageBus, ModelFactory, Content) |
|
|
|
|
|
||||||||||||||||||||
createContent(String, TypeSafeMap) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
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.rca.ui.contentmanager.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.io.IOException;
31: import it.tidalwave.dci.annotation.DciRole;
32: import it.tidalwave.messagebus.MessageBus;
33: import it.tidalwave.northernwind.core.model.Content;
34: import it.tidalwave.northernwind.core.model.ModelFactory;
35: import it.tidalwave.northernwind.core.model.ResourceFile;
36: import it.tidalwave.northernwind.core.model.ResourceProperties;
37: import it.tidalwave.northernwind.rca.ui.event.ContentCreatedEvent;
38: import it.tidalwave.util.TypeSafeMap;
39: import lombok.RequiredArgsConstructor;
40: import lombok.extern.slf4j.Slf4j;
41: import static it.tidalwave.northernwind.model.admin.role.Saveable.*;
42:
43: /***********************************************************************************************************************
44: *
45: * A default implementation of {@link ContentCreator}.
46: *
47: * @stereotype role
48: *
49: * @author Fabrizio Giudici
50: *
51: **********************************************************************************************************************/
52:•@DciRole(datumType = Content.class) @RequiredArgsConstructor @Slf4j
53: public class DefaultContentChildCreator implements ContentChildCreator
54: {
55: @Nonnull
56: private final MessageBus messageBus;
57:
58: @Nonnull
59: private final ModelFactory modelFactory; // TODO: get from content - depends on NW-197
60:
61: @Nonnull
62: private final Content parentContent;
63:
64: @Override @Nonnull
65: public Content createContent (@Nonnull final String folderName, @Nonnull final TypeSafeMap propertyValues)
66: throws IOException
67: {
68: log.info("createContent({}, {}) - {}", folderName, propertyValues, parentContent);
69: final ResourceFile newFolder = parentContent.getFile().createFolder(folderName);
70: final Content content = modelFactory.createContent().withFolder(newFolder).build();
71: final ResourceProperties properties = modelFactory.createProperties().withSafeValues(propertyValues).build();
72: // content.getProperties().merged(properties).as(_Saveable_).saveIn(content.getFile());
73: properties.as(_Saveable_).saveIn(content.getFile());
74:
75: messageBus.publish(ContentCreatedEvent.of(parentContent, content));
76:
77: return content;
78: }
79: }