Clover Coverage Report - Google Sitemap Module 2.0.3
Coverage timestamp: Fri Mar 14 2014 11:34:22 CET
../../../../../../../img/srcFileCovDistChart0.png 20% of files have more coverage
50   207   20   5
12   141   0.4   10
10     2  
1    
 
  SiteMapEditorPresenter       Line # 72 50 0% 20 72 0% 0.0
 
No Tests
 
1    /**
2    * This file Copyright (c) 2013 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.app.subapp.sitemapdetail;
35   
36    import info.magnolia.context.MgnlContext;
37    import info.magnolia.event.EventBus;
38    import info.magnolia.jcr.util.PropertyUtil;
39    import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
40    import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.base.SiteMapContentView;
41    import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.base.SiteMapDetailPresenter;
42    import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.event.EntrySelectedEvent;
43    import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
44    import info.magnolia.objectfactory.ComponentProvider;
45    import info.magnolia.ui.actionbar.ActionbarPresenter;
46    import info.magnolia.ui.api.action.ActionDefinition;
47    import info.magnolia.ui.api.action.ActionExecutionException;
48    import info.magnolia.ui.api.app.SubAppContext;
49    import info.magnolia.ui.api.app.SubAppEventBus;
50    import info.magnolia.ui.api.event.AdmincentralEventBus;
51    import info.magnolia.ui.api.event.ContentChangedEvent;
52    import info.magnolia.ui.contentapp.detail.DetailLocation;
53    import info.magnolia.ui.framework.app.SubAppActionExecutor;
54    import info.magnolia.ui.vaadin.actionbar.ActionbarView;
55    import info.magnolia.ui.vaadin.integration.NullItem;
56    import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
57   
58    import javax.inject.Inject;
59    import javax.inject.Named;
60    import javax.jcr.Node;
61    import javax.jcr.RepositoryException;
62    import javax.jcr.Session;
63   
64    import org.apache.commons.lang.StringUtils;
65    import org.slf4j.Logger;
66    import org.slf4j.LoggerFactory;
67   
68    /**
69    * Presenter class, serves as a delegate for {@link SiteMapEditorSubApp}.
70    * Manages {@link SiteMapEditorView}.
71    */
 
72    public class SiteMapEditorPresenter implements EntrySelectedEvent.Handler, ActionbarPresenter.Listener {
73   
74    private Logger log = LoggerFactory.getLogger(getClass());
75   
76    public static final String EDIT_ACTIONS_GROUP = "editActions";
77   
78    private SiteMapEditorView view;
79   
80    private SiteMapDetailPresenter contentPresenter;
81   
82    private ActionbarPresenter actionbarPresenter;
83   
84    private SubAppContext appContext;
85   
86    private EventBus eventBus;
87   
88    private EventBus adminCentralEventBus;
89   
90    private SubAppActionExecutor executor;
91   
92    private JcrNodeAdapter nodeAdapter;
93   
94    private ComponentProvider provider;
95   
96    private String targetWorkspace;
97   
 
98  0 toggle @Inject
99    public SiteMapEditorPresenter(
100    SiteMapEditorView view,
101    ActionbarPresenter actionbarPresenter,
102    SubAppContext appContext,
103    @Named(SubAppEventBus.NAME) EventBus eventBus,
104    @Named(AdmincentralEventBus.NAME) final EventBus adminCentralEventBus,
105    SubAppActionExecutor executor,
106    ComponentProvider provider) {
107  0 this.view = view;
108  0 this.actionbarPresenter = actionbarPresenter;
109  0 this.appContext = appContext;
110  0 this.eventBus = eventBus;
111  0 this.adminCentralEventBus = adminCentralEventBus;
112  0 this.executor = executor;
113  0 this.provider = provider;
114  0 this.eventBus.addHandler(EntrySelectedEvent.class, this);
115  0 this.actionbarPresenter.setListener(this);
116    }
117   
 
118  0 toggle public SiteMapEditorView start() {
119  0 SiteMapEditorSubAppDescriptor descriptor = (SiteMapEditorSubAppDescriptor) appContext.getSubAppDescriptor();
120  0 this.targetWorkspace = descriptor.getTargetWorkspace();
121  0 this.contentPresenter = provider.newInstance(descriptor.getPresenterClass());
122   
123  0 ActionbarView actionbarView = actionbarPresenter.start(descriptor.getActionbar());
124  0 view.setActionbarView(actionbarView);
125   
126  0 SiteMapContentView contentView = contentPresenter.start();
127  0 view.setContentView(contentView);
128   
129  0 if (contentPresenter.getCurrentSelection() == null) {
130  0 actionbarPresenter.disableGroup(EDIT_ACTIONS_GROUP);
131    }
132   
133  0 adminCentralEventBus.addHandler(ContentChangedEvent.class, new ContentChangedEvent.Handler() {
 
134  0 toggle @Override
135    public void onContentChanged(ContentChangedEvent event) {
136  0 if (targetWorkspace.equals(event.getWorkspace())) {
137  0 contentPresenter.edit(nodeAdapter.getJcrItem());
138    }
139    }
140    });
141  0 return view;
142    }
143   
 
144  0 toggle public void setSiteMapNode(JcrNodeAdapter nodeAdapter) {
145  0 this.nodeAdapter = nodeAdapter;
146  0 contentPresenter.edit(nodeAdapter.getJcrItem());
147    }
148   
 
149  0 toggle @Override
150    public void onEntriesSelected(SiteMapEntry entry) {
151  0 if (entry == null) {
152  0 actionbarPresenter.disableGroup(EDIT_ACTIONS_GROUP);
153    } else {
154  0 actionbarPresenter.enableGroup(EDIT_ACTIONS_GROUP);
155    }
156    }
157   
 
158  0 toggle @Override
159    public void onActionbarItemClicked(String itemName) {
160  0 try {
161  0 SiteMapEntry entry = contentPresenter.getCurrentSelection();
162  0 if (entry != null) {
163  0 Node pageNode = MgnlContext.getJCRSession(targetWorkspace).getNode(entry.getPath());
164  0 executor.execute(itemName, new JcrNodeAdapter(pageNode));
165    } else {
166  0 executor.execute(itemName, new NullItem());
167    }
168    } catch (ActionExecutionException e) {
169  0 e.printStackTrace();
170    } catch (RepositoryException e) {
171  0 e.printStackTrace();
172    }
173    }
174   
 
175  0 toggle @Override
176    public String getLabel(String itemName) {
177  0 ActionDefinition actionDefinition = executor.getActionDefinition(itemName);
178  0 return actionDefinition != null ? actionDefinition.getLabel() : null;
179    }
180   
 
181  0 toggle @Override
182    public String getIcon(String itemName) {
183  0 try {
184  0 ActionDefinition actionDefinition = executor.getActionDefinition(itemName);
185  0 return actionDefinition != null ? actionDefinition.getIcon() : null;
186    } catch (Exception e) {
187  0 e.printStackTrace();
188  0 return null;
189    }
190    }
191   
 
192  0 toggle public String getCaptionForLocation(DetailLocation location) {
193  0 return contentPresenter.getLabel() + ": " + getSiteMapName(location);
194    }
195   
 
196  0 toggle private String getSiteMapName(DetailLocation location) {
197  0 String caption = StringUtils.EMPTY;
198  0 try {
199  0 Session session = MgnlContext.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE);
200  0 Node node = session.getNode(location.getNodePath());
201  0 caption = PropertyUtil.getString(node, GoogleSiteMapConfiguration.SITE_MAP_DISPLAY_NAME_PROPERTY_NAME, node.getName());
202    } catch (RepositoryException e) {
203  0 log.warn("Could not set page Tab Title for item : {}", location.getNodePath(), e);
204    }
205  0 return caption;
206    }
207    }