1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.resources.app.action; |
35 |
|
|
36 |
|
import static info.magnolia.ui.vaadin.overlay.MessageStyleTypeEnum.*; |
37 |
|
|
38 |
|
import info.magnolia.context.Context; |
39 |
|
import info.magnolia.event.EventBus; |
40 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
41 |
|
import info.magnolia.jcr.util.NodeTypes; |
42 |
|
import info.magnolia.jcr.util.NodeUtil; |
43 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
44 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
45 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
46 |
|
import info.magnolia.ui.api.action.ActionExecutionException; |
47 |
|
import info.magnolia.ui.api.app.AppContext; |
48 |
|
import info.magnolia.ui.api.event.AdmincentralEventBus; |
49 |
|
import info.magnolia.ui.api.event.ContentChangedEvent; |
50 |
|
import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector; |
51 |
|
|
52 |
|
import javax.inject.Named; |
53 |
|
import javax.jcr.Node; |
54 |
|
import javax.jcr.RepositoryException; |
55 |
|
import javax.jcr.Session; |
56 |
|
|
57 |
|
import com.vaadin.data.Item; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@deprecated@link |
63 |
|
|
64 |
|
@Deprecated |
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 10 |
Complexity Density: 0.3 |
|
65 |
|
public class RemoveHotfixAction extends AbstractResourceAction<RemoveHotfixActionDefinition> { |
66 |
|
|
67 |
|
private final Item resourceItem; |
68 |
|
private final Context context; |
69 |
|
private final SimpleTranslator i18n; |
70 |
|
private final AppContext appContext; |
71 |
|
private final EventBus eventBus; |
72 |
|
private final ContentConnector contentConnector; |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
74 |
0 |
public RemoveHotfixAction(RemoveHotfixActionDefinition definition, Item resourceItem, Context context, AppContext appContext, SimpleTranslator i18n, @Named(AdmincentralEventBus.NAME) EventBus eventBus, ContentConnector contentConnector, ResourceOrigin origin) {... |
75 |
0 |
super(definition, origin); |
76 |
0 |
this.resourceItem = resourceItem; |
77 |
0 |
this.context = context; |
78 |
0 |
this.i18n = i18n; |
79 |
0 |
this.appContext = appContext; |
80 |
0 |
this.eventBus = eventBus; |
81 |
0 |
this.contentConnector = contentConnector; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.28 |
|
84 |
0 |
@Override... |
85 |
|
public void execute() throws ActionExecutionException { |
86 |
0 |
String resourcePath = (String) resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH).getValue(); |
87 |
0 |
String origin = (String) resourceItem.getItemProperty(ResourcesContainer.ORIGIN_NAME_PROPERTY_ID).getValue(); |
88 |
0 |
boolean isOverriding = (boolean) resourceItem.getItemProperty(ResourcesContainer.OVERRIDING_PROPERTY_ID).getValue(); |
89 |
|
|
90 |
0 |
if (!origin.equals("jcr") || !isOverriding) { |
91 |
0 |
throw new ActionExecutionException(new IllegalStateException("Hotfix is not present")); |
92 |
|
} |
93 |
|
|
94 |
0 |
try { |
95 |
0 |
Session jcrSession = context.getJCRSession(JcrResourceOrigin.RESOURCES_WORKSPACE); |
96 |
0 |
Node node = jcrSession.getNode(resourcePath); |
97 |
0 |
boolean hasSiblings = NodeUtil.getSiblings(node).iterator().hasNext(); |
98 |
|
|
99 |
0 |
if (hasSiblings) { |
100 |
0 |
node.remove(); |
101 |
|
} else { |
102 |
|
|
103 |
0 |
removeNodeAndEmptyAncestorsFromJcr(node); |
104 |
|
} |
105 |
|
|
106 |
0 |
jcrSession.save(); |
107 |
|
|
108 |
0 |
Object newResourcePath = contentConnector.getItemIdByUrlFragment(resourcePath); |
109 |
0 |
reflectChangesForItem(newResourcePath); |
110 |
|
|
111 |
0 |
appContext.openNotification(INFO, true, i18n.translate("resources.actions.removeHotfix.notification.success")); |
112 |
|
} catch (Exception e) { |
113 |
0 |
appContext.openNotification(ERROR, false, i18n.translate("resources.actions.removeHotfix.notification.error")); |
114 |
0 |
throw new ActionExecutionException(e); |
115 |
|
} |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
private void reflectChangesForItem(Object itemId) {... |
119 |
0 |
eventBus.fireEvent(new ContentChangedEvent(itemId)); |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
122 |
0 |
private void removeNodeAndEmptyAncestorsFromJcr(Node node) throws RepositoryException {... |
123 |
0 |
if (node.getDepth() == 0) { |
124 |
0 |
return; |
125 |
|
} |
126 |
0 |
final boolean hasNoMoreResources = !NodeUtil.getNodes(node, NodeTypes.Content.NAME).iterator().hasNext(); |
127 |
0 |
if (hasNoMoreResources) { |
128 |
0 |
Node parent = node.getParent(); |
129 |
0 |
node.remove(); |
130 |
0 |
removeNodeAndEmptyAncestorsFromJcr(parent); |
131 |
|
} |
132 |
|
} |
133 |
|
} |