Package: DefaultIBizImporterPresentationControl
DefaultIBizImporterPresentationControl
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
afterPropertiesSet() |
|
|
|
|
|
||||||||||||||||||||
destroy() |
|
|
|
|
|
||||||||||||||||||||
onConfirm() |
|
|
|
|
|
||||||||||||||||||||
onImportRequest(ImportRequest) |
|
|
|
|
|
||||||||||||||||||||
setBeanFactory(BeanFactory) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueHour: open source accounting
5: * http://tidalwave.it/projects/bluehour
6: *
7: * Copyright (C) 2013 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluehour-src
22: * git clone https://github.com/tidalwave-it/bluehour-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.accounting.ui.importer.ibiz.impl;
27:
28: import javax.annotation.Nonnull;
29: import java.io.IOException;
30: import java.nio.file.Path;
31: import it.tidalwave.accounting.commons.AccountingOpenRequest;
32: import it.tidalwave.accounting.commons.ImportRequest;
33: import it.tidalwave.accounting.importer.ibiz.IBizImporterBuilderFactory;
34: import it.tidalwave.accounting.ui.importer.ibiz.IBizImporterPresentation;
35: import it.tidalwave.accounting.ui.importer.ibiz.IBizImporterPresentationControl;
36: import it.tidalwave.util.annotation.VisibleForTesting;
37: import it.tidalwave.role.ui.BoundProperty;
38: import it.tidalwave.dci.annotation.DciContext;
39: import it.tidalwave.messagebus.MessageBus;
40: import it.tidalwave.messagebus.annotation.ListensTo;
41: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
42: import lombok.RequiredArgsConstructor;
43: import lombok.extern.slf4j.Slf4j;
44: import static it.tidalwave.accounting.role.Saveable._Saveable_;
45: import static it.tidalwave.util.ui.UserNotificationWithFeedback.*;
46:
47: /***************************************************************************************************************************************************************
48: *
49: * @author Fabrizio Giudici
50: *
51: **************************************************************************************************************************************************************/
52: @RequiredArgsConstructor @DciContext @SimpleMessageSubscriber @Slf4j
53: public class DefaultIBizImporterPresentationControl implements IBizImporterPresentationControl
54: {
55: @Nonnull
56: private final MessageBus messageBus;
57:
58: @Nonnull
59: private final IBizImporterBuilderFactory importerBuilderFactory;
60:
61: private final BoundProperty<Path> iBizFolder = new BoundProperty<>();
62:
63: @Nonnull
64: private final IBizImporterPresentation presentation;
65:
66: @VisibleForTesting void onImportRequest (@Nonnull @ListensTo final ImportRequest request)
67: throws IOException
68: {
69: log.info("onImportRequest({})", request);
70: presentation.bind(iBizFolder);
71: iBizFolder.set(Path.of(System.getProperty("user.home") + "/Settings/iBiz"));
72: presentation.chooseFolder(notificationWithFeedback().withFeedback(feedback().withOnConfirm(this::onConfirm)));
73: }
74:
75: private void onConfirm()
76: {
77: // TODO: warn for overwriting data, ask for confirmation
78: // FIXME: this gets executed in JavaFX thread
79: try
80: {
81: presentation.lock();
82: final var accounting = importerBuilderFactory.newBuilder()
83: .withPath(iBizFolder.get())
84: .create();
85: accounting.importAll();
86: accounting.as(_Saveable_).save();
87: messageBus.publish(new AccountingOpenRequest());
88:
89: // TODO: use a progress bar during the import process
90: }
91: catch (Exception e)
92: {
93: log.error("", e);
94: presentation.notifyError();
95: }
96: finally
97: {
98: presentation.unlock();
99: }
100: }
101: }