Clover icon

Magnolia Resources App Module 2.5.3

  1. Project Clover database Thu May 11 2017 16:02:29 CEST
  2. Package info.magnolia.resources.app.detail

File ResourcesDetailPresenter.java

 

Coverage histogram

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

Code metrics

4
12
2
1
97
48
5
0.42
6
2
2.5

Classes

Class Line # Actions
ResourcesDetailPresenter 62 12 0% 5 3
0.833333383.3%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /**
2    * This file Copyright (c) 2016-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.resources.app.detail;
35   
36    import info.magnolia.event.EventBus;
37    import info.magnolia.i18nsystem.I18nizer;
38    import info.magnolia.i18nsystem.SimpleTranslator;
39    import info.magnolia.objectfactory.ComponentProvider;
40    import info.magnolia.ui.api.app.SubAppContext;
41    import info.magnolia.ui.api.availability.AvailabilityChecker;
42    import info.magnolia.ui.api.event.AdmincentralEventBus;
43    import info.magnolia.ui.api.event.ContentChangedEvent;
44    import info.magnolia.ui.contentapp.detail.DetailPresenter;
45    import info.magnolia.ui.contentapp.detail.DetailView;
46    import info.magnolia.ui.form.FormPresenter;
47    import info.magnolia.ui.framework.app.SubAppActionExecutor;
48    import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector;
49    import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
50   
51    import javax.inject.Inject;
52    import javax.inject.Named;
53    import javax.jcr.RepositoryException;
54   
55    import org.apache.commons.lang3.StringUtils;
56    import org.slf4j.Logger;
57    import org.slf4j.LoggerFactory;
58   
59    /**
60    * Implementation of {@link info.magnolia.ui.contentapp.detail.DetailEditorPresenter} that handles success event by using resource path instead of UUID.
61    */
 
62    public class ResourcesDetailPresenter extends DetailPresenter {
63   
64    private static final Logger log = LoggerFactory.getLogger(ResourcesDetailPresenter.class);
65   
66    private final SubAppContext subAppContext;
67   
68    private final EventBus eventBus;
69   
 
70  1 toggle @Inject
71    public ResourcesDetailPresenter(final SubAppContext subAppContext, final @Named(AdmincentralEventBus.NAME) EventBus eventBus, final DetailView view, final ComponentProvider componentProvider, final SubAppActionExecutor executor, final I18nizer i18nizer, final SimpleTranslator i18n, final AvailabilityChecker checker, final ContentConnector contentConnector, final FormPresenter formPresenter) {
72  1 super(subAppContext, eventBus, view, componentProvider, executor, i18nizer, i18n, checker, contentConnector, formPresenter);
73  1 this.subAppContext = subAppContext;
74  1 this.eventBus = eventBus;
75    }
76   
77    /**
78    * Fires {@link ContentChangedEvent} after resource is created/edited. Because resource apps works with paths as item ids,
79    * we're passing path to the event so {@link info.magnolia.ui.contentapp.browser.BrowserPresenter} knows what resource should be selected after creation/edit.
80    */
 
81  1 toggle @Override
82    public void onSuccess(final String actionName) {
83  1 String path = null;
84  1 if (getItem() instanceof JcrNodeAdapter) {
85  1 JcrNodeAdapter adapter = (JcrNodeAdapter) getItem();
86  1 try {
87  1 path = adapter.getJcrItem().getPath();
88    } catch (RepositoryException e) {
89  0 log.warn("Unable to obtain path for item {}", adapter.getItemId());
90    }
91    }
92  1 if (StringUtils.isNotBlank(path)) {
93  1 eventBus.fireEvent(new ContentChangedEvent(path));
94    }
95  1 subAppContext.close();
96    }
97    }