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 info.magnolia.event.EventBus; |
37 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
38 |
|
import info.magnolia.resourceloader.Resource; |
39 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
40 |
|
import info.magnolia.resources.app.ResourcesContentConnector; |
41 |
|
import info.magnolia.ui.api.action.ActionExecutionException; |
42 |
|
import info.magnolia.ui.api.context.UiContext; |
43 |
|
import info.magnolia.ui.api.event.AdmincentralEventBus; |
44 |
|
import info.magnolia.ui.api.event.ContentChangedEvent; |
45 |
|
import info.magnolia.ui.dialog.formdialog.FormDialogPresenter; |
46 |
|
import info.magnolia.ui.dialog.formdialog.FormDialogPresenterFactory; |
47 |
|
import info.magnolia.ui.form.EditorCallback; |
48 |
|
import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector; |
49 |
|
import info.magnolia.ui.vaadin.overlay.MessageStyleTypeEnum; |
50 |
|
|
51 |
|
import javax.inject.Inject; |
52 |
|
import javax.inject.Named; |
53 |
|
|
54 |
|
import org.apache.commons.lang3.StringUtils; |
55 |
|
|
56 |
|
import com.vaadin.data.Item; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@see |
67 |
|
|
|
|
| 72.4% |
Uncovered Elements: 8 (29) |
Complexity: 6 |
Complexity Density: 0.29 |
|
68 |
|
public class UploadResourceAction extends AbstractResourceAction<UploadResourceActionDefinition> { |
69 |
|
|
70 |
|
private final Item resourceItem; |
71 |
|
private final FormDialogPresenterFactory formDialogPresenterFactory; |
72 |
|
private final UiContext uiContext; |
73 |
|
private final SimpleTranslator i18n; |
74 |
|
private final ResourcesContentConnector contentConnector; |
75 |
|
private final EventBus eventBus; |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
77 |
2 |
@Inject... |
78 |
|
public UploadResourceAction(UploadResourceActionDefinition definition, Item resourceItem, ContentConnector contentConnector, FormDialogPresenterFactory formDialogPresenterFactory, UiContext uiContext, SimpleTranslator i18n, @Named(AdmincentralEventBus.NAME) EventBus eventBus, ResourceOrigin origin) { |
79 |
2 |
super(definition, origin); |
80 |
2 |
this.resourceItem = resourceItem; |
81 |
2 |
this.formDialogPresenterFactory = formDialogPresenterFactory; |
82 |
2 |
this.uiContext = uiContext; |
83 |
2 |
this.i18n = i18n; |
84 |
2 |
this.contentConnector = (ResourcesContentConnector) contentConnector; |
85 |
2 |
this.eventBus = eventBus; |
86 |
|
} |
87 |
|
|
|
|
| 53.8% |
Uncovered Elements: 6 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
88 |
2 |
@Override... |
89 |
|
public void execute() throws ActionExecutionException { |
90 |
2 |
String dialogName = getDefinition().getDialogName(); |
91 |
2 |
if (StringUtils.isBlank(dialogName)) { |
92 |
0 |
uiContext.openNotification(MessageStyleTypeEnum.ERROR, false, i18n.translate("ui-framework.actions.no.dialog.definition", getDefinition().getName())); |
93 |
0 |
return; |
94 |
|
} |
95 |
|
|
96 |
2 |
final FormDialogPresenter formDialogPresenter = formDialogPresenterFactory.createFormDialogPresenter(dialogName); |
97 |
|
|
98 |
2 |
if (formDialogPresenter == null) { |
99 |
0 |
uiContext.openNotification(MessageStyleTypeEnum.ERROR, false, i18n.translate("ui-framework.actions.dialog.not.registered", dialogName)); |
100 |
0 |
return; |
101 |
|
} |
102 |
|
|
103 |
2 |
formDialogPresenter.start(resourceItem, getDefinition().getDialogName(), uiContext, new EditorCallback() { |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
105 |
2 |
@Override... |
106 |
|
public void onSuccess(String actionName) { |
107 |
2 |
final Resource parentResource = unwrapResource(resourceItem); |
108 |
2 |
final Resource newResource = contentConnector.createNewResource(parentResource, resourceItem); |
109 |
2 |
eventBus.fireEvent(new ContentChangedEvent(newResource.getPath(), true)); |
110 |
|
|
111 |
2 |
formDialogPresenter.closeDialog(); |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
@Override... |
115 |
|
public void onCancel() { |
116 |
0 |
formDialogPresenter.closeDialog(); |
117 |
|
} |
118 |
|
}); |
119 |
|
} |
120 |
|
} |