Skip to content

Package: DefaultIBizImporterPresentationControl

DefaultIBizImporterPresentationControl

nameinstructionbranchcomplexitylinemethod
afterPropertiesSet()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
destroy()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
onConfirm()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
onImportRequest(ImportRequest)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setBeanFactory(BeanFactory)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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 org.springframework.stereotype.Component;
32: import it.tidalwave.accounting.commons.AccountingOpenRequest;
33: import it.tidalwave.accounting.commons.ImportRequest;
34: import it.tidalwave.accounting.importer.ibiz.IBizImporterBuilderFactory;
35: import it.tidalwave.accounting.ui.importer.ibiz.IBizImporterPresentation;
36: import it.tidalwave.accounting.ui.importer.ibiz.IBizImporterPresentationControl;
37: import it.tidalwave.util.annotation.VisibleForTesting;
38: import it.tidalwave.role.ui.BoundProperty;
39: import it.tidalwave.dci.annotation.DciContext;
40: import it.tidalwave.messagebus.MessageBus;
41: import it.tidalwave.messagebus.annotation.ListensTo;
42: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
43: import lombok.RequiredArgsConstructor;
44: import lombok.extern.slf4j.Slf4j;
45: import static it.tidalwave.accounting.role.Saveable._Saveable_;
46: import static it.tidalwave.util.ui.UserNotificationWithFeedback.*;
47:
48: /***************************************************************************************************************************************************************
49: *
50: * @author Fabrizio Giudici
51: *
52: **************************************************************************************************************************************************************/
53: @Component @RequiredArgsConstructor @DciContext @SimpleMessageSubscriber @Slf4j
54: public class DefaultIBizImporterPresentationControl implements IBizImporterPresentationControl
55: {
56: @Nonnull
57: private final MessageBus messageBus;
58:
59: @Nonnull
60: private final IBizImporterBuilderFactory importerBuilderFactory;
61:
62: private final BoundProperty<Path> iBizFolder = new BoundProperty<>();
63:
64: @Nonnull
65: private final IBizImporterPresentation presentation;
66:
67: @VisibleForTesting void onImportRequest (@Nonnull @ListensTo final ImportRequest request)
68: throws IOException
69: {
70: log.info("onImportRequest({})", request);
71: presentation.bind(iBizFolder);
72: iBizFolder.set(Path.of(System.getProperty("user.home") + "/Settings/iBiz"));
73: presentation.chooseFolder(notificationWithFeedback().withFeedback(feedback().withOnConfirm(this::onConfirm)));
74: }
75:
76: private void onConfirm()
77: {
78: // TODO: warn for overwriting data, ask for confirmation
79: // FIXME: this gets executed in JavaFX thread
80: try
81: {
82: presentation.lock();
83: final var accounting = importerBuilderFactory.newBuilder()
84: .withPath(iBizFolder.get())
85: .create();
86: accounting.importAll();
87: accounting.as(_Saveable_).save();
88: messageBus.publish(new AccountingOpenRequest());
89:
90: // TODO: use a progress bar during the import process
91: }
92: catch (Exception e)
93: {
94: log.error("", e);
95: presentation.notifyError();
96: }
97: finally
98: {
99: presentation.unlock();
100: }
101: }
102: }