Clover icon

Google Sitemap Module 2.4.3

  1. Project Clover database Thu May 11 2017 16:52:32 CEST
  2. Package info.magnolia.module.googlesitemap.setup.for2_1

File Register21NodeTypeTask.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
28% of files have more coverage

Code metrics

6
28
5
1
119
65
8
0.29
5.6
5
1.6

Classes

Class Line # Actions
Register21NodeTypeTask 60 28 0% 8 4
0.897435989.7%
 

Contributing tests

This file is covered by 12 tests. .

Source view

1    /**
2    * This file Copyright (c) 2013-2017 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.module.googlesitemap.setup.for2_1;
35   
36    import info.magnolia.jcr.util.NodeTypeTemplateUtil;
37    import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
38    import info.magnolia.setup.for5_0.AbstractNodeTypeRegistrationTask;
39   
40    import java.util.ArrayList;
41    import java.util.Arrays;
42    import java.util.LinkedList;
43    import java.util.List;
44   
45    import javax.jcr.PropertyType;
46    import javax.jcr.RepositoryException;
47    import javax.jcr.nodetype.NodeType;
48    import javax.jcr.nodetype.NodeTypeDefinition;
49    import javax.jcr.nodetype.NodeTypeManager;
50    import javax.jcr.nodetype.NodeTypeTemplate;
51    import javax.jcr.version.OnParentVersionAction;
52   
53    import org.slf4j.Logger;
54    import org.slf4j.LoggerFactory;
55   
56    /**
57    * Add GoogleSiteMap mixIn to the mgnl:pages nodeType. <br>
58    * Update the existing SiteMap nodeType definition.
59    */
 
60    public class Register21NodeTypeTask extends AbstractNodeTypeRegistrationTask {
61    private final Logger log = LoggerFactory.getLogger(Register21NodeTypeTask.class);
62    private List<String> nodeTypeToAddMixIn;
63   
 
64  13 toggle public Register21NodeTypeTask(String name, String description, String workspaceName, List<String> nodeTypeToAddMixIn) {
65  13 super(name, description, workspaceName);
66  13 this.nodeTypeToAddMixIn = nodeTypeToAddMixIn != null ? nodeTypeToAddMixIn : new ArrayList<String>();
67    }
68   
 
69  4 toggle @Override
70    public List<NodeTypeDefinition> getNodeTypesToRegister(NodeTypeManager nodeTypeManager) throws RepositoryException {
71  4 LinkedList<NodeTypeDefinition> res = new LinkedList<NodeTypeDefinition>();
72  4 for (String nodeTypeName : nodeTypeToAddMixIn) {
73  4 if (nodeTypeManager.hasNodeType(nodeTypeName)) {
74  4 NodeType nodeType = nodeTypeManager.getNodeType(nodeTypeName);
75  4 res.add(updateExistingNodeType(nodeType, nodeTypeManager));
76    } else {
77  0 log.warn("NodeType {} is not register. {} will not be register as super type to this definition", nodeTypeName, SiteMapNodeTypes.GoogleSiteMap.NAME);
78    }
79    }
80    // Update the siteMap nodeType definition
81  4 if (nodeTypeManager.hasNodeType(SiteMapNodeTypes.SiteMap.NAME)) {
82  4 NodeType nodeType = nodeTypeManager.getNodeType(SiteMapNodeTypes.SiteMap.NAME);
83  4 res.add(updateSiteMapNodeType(nodeType, nodeTypeManager));
84    }
85  4 return res;
86    }
87   
 
88  4 toggle @Override
89    public List<String> getNodeTypesToUnregister(NodeTypeManager nodeTypeManager) throws RepositoryException {
90  4 return null;
91    }
92   
 
93  4 toggle private NodeTypeTemplate updateExistingNodeType(NodeType nodeType, NodeTypeManager nodeTypeManager) throws RepositoryException {
94  4 NodeTypeTemplate nodeTypeTemplate = null;
95    // Add Google SiteMap as superType
96  4 ArrayList<String> superType = new ArrayList<String>(Arrays.asList(nodeType.getDeclaredSupertypeNames()));
97  4 superType.add(SiteMapNodeTypes.GoogleSiteMap.NAME);
98    // Copy all others values
99  4 nodeTypeTemplate = NodeTypeTemplateUtil.createNodeType(nodeTypeManager, nodeType.getName(), superType.toArray(new String[superType.size()]), nodeType.isMixin(), nodeType.hasOrderableChildNodes(), nodeType.getPrimaryItemName(), nodeType.isQueryable());
100  4 nodeTypeTemplate.getNodeDefinitionTemplates().addAll(Arrays.asList(nodeType.getDeclaredChildNodeDefinitions()));
101  4 nodeTypeTemplate.getPropertyDefinitionTemplates().addAll(Arrays.asList(nodeType.getDeclaredPropertyDefinitions()));
102   
103  4 return nodeTypeTemplate;
104    }
105   
 
106  4 toggle private NodeTypeTemplate updateSiteMapNodeType(NodeType nodeType, NodeTypeManager nodeTypeManager) throws RepositoryException {
107  4 NodeTypeTemplate nodeTypeTemplate = null;
108    // Copy basic initial values
109  4 nodeTypeTemplate = NodeTypeTemplateUtil.createNodeType(nodeTypeManager, nodeType.getName(), nodeType.getDeclaredSupertypeNames(), nodeType.isMixin(), nodeType.hasOrderableChildNodes(), nodeType.getPrimaryItemName(), nodeType.isQueryable());
110    // Add the new properties
111  4 nodeTypeTemplate.getPropertyDefinitionTemplates().add(NodeTypeTemplateUtil.createPropertyDefinition(nodeTypeManager, "mgnl:googleSiteMapDisplayName", false, false, false, false, false, true, OnParentVersionAction.COPY, PropertyType.STRING, null, null, null));
112   
113  4 nodeTypeTemplate.getPropertyDefinitionTemplates().add(NodeTypeTemplateUtil.createPropertyDefinition(nodeTypeManager, "mgnl:googleSiteMapType", false, false, false, false, false, true, OnParentVersionAction.COPY, PropertyType.STRING, null, null, null));
114  4 nodeTypeTemplate.getPropertyDefinitionTemplates().add(NodeTypeTemplateUtil.createPropertyDefinition(nodeTypeManager, "mgnl:googleSiteMapURL", false, false, false, false, false, true, OnParentVersionAction.COPY, PropertyType.STRING, null, null, null));
115  4 nodeTypeTemplate.getPropertyDefinitionTemplates().add(NodeTypeTemplateUtil.createPropertyDefinition(nodeTypeManager, "mgnl:googleSiteMapPages", false, false, false, true, false, true, OnParentVersionAction.COPY, PropertyType.STRING, null, null, null));
116  4 nodeTypeTemplate.getPropertyDefinitionTemplates().add(NodeTypeTemplateUtil.createPropertyDefinition(nodeTypeManager, "mgnl:googleSiteMapIncludeVirtualUri", false, false, false, false, false, true, OnParentVersionAction.COPY, PropertyType.BOOLEAN, null, null, null));
117  4 return nodeTypeTemplate;
118    }
119    }