-
-
Notifications
You must be signed in to change notification settings - Fork 0
Refact 13.12 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: refact-2025
Are you sure you want to change the base?
Refact 13.12 #21
Changes from all commits
31faa5a
4b8ea48
4f1e88c
d616f6f
bd23332
25a6e6d
362b5b4
dbd77db
dc84f5a
f4bd179
c406ab5
3816488
2c6725f
ff50342
03c86f0
a7ee6ed
14dddde
c1bf874
d96f9c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package pl.koder95.eme.dfs; | ||
|
|
||
| public enum BookType { | ||
| LIBER_BAPTISMORUM, | ||
| LIBER_CONFIRMATORUM, | ||
| LIBER_MATRIMONIORUM, | ||
| LIBER_DEFUNCTORUM | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package pl.koder95.eme.dfs; | ||
|
|
||
| import java.util.Map; | ||
| import org.w3c.dom.Node; | ||
|
|
||
| public interface IndexNodeInterpreter { | ||
| Map<String, String> interpret(Node node); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package pl.koder95.eme.dfs.impl; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.w3c.dom.NamedNodeMap; | ||
| import org.w3c.dom.Node; | ||
| import pl.koder95.eme.dfs.IndexNodeInterpreter; | ||
|
|
||
| public class IndexNodeInterpreterImpl implements IndexNodeInterpreter { | ||
| @Override | ||
| public Map<String, String> interpret(Node node) { | ||
| if (node == null || node.getNodeName().equalsIgnoreCase("index")) { | ||
| throw new IllegalArgumentException("Node is null or node is not an index"); | ||
| } | ||
| Map<String, String> data = new HashMap<>(); | ||
| NamedNodeMap attrs = node.getAttributes(); // pobiera listę atrybutów | ||
| while (attrs.getLength() > 0) { | ||
| Node attr = attrs.item(0); // pobiera pierwszy atrybut | ||
| String key = attr.getNodeName(); // - nazwa atrybutu | ||
| String value = attr.getTextContent(); // - wartość atrybutu | ||
| data.put(key, value); // dodanie nazwy i wartości atrybutu do danych | ||
| attrs.removeNamedItem(key); // usuwa odczytany atrybut | ||
| } | ||
| return data; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package pl.koder95.eme.factory; | ||
|
|
||
| import pl.koder95.eme.dfs.BookType; | ||
| import pl.koder95.eme.dfs.Index; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public interface IndexFactory { | ||
|
|
||
| Index create(Map<String, String> data); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package pl.koder95.eme.factory.impl; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
|
|
||
| import pl.koder95.eme.dfs.Book; | ||
| import pl.koder95.eme.dfs.BookType; | ||
| import pl.koder95.eme.dfs.Index; | ||
| import pl.koder95.eme.dfs.IndexNodeInterpreter; | ||
| import pl.koder95.eme.factory.IndexFactory; | ||
|
|
||
| public class BasicIndexFactory implements IndexFactory { | ||
|
|
||
| private final Function<Set<String>, BookType> bookTypeMatcher; | ||
| private final Map<BookType, Book> bookMap; | ||
|
|
||
| public BasicIndexFactory(Function<Set<String>, BookType> bookTypeMatcher, Map<BookType, Book> bookMap) { | ||
| this.bookTypeMatcher = bookTypeMatcher; | ||
| this.bookMap = bookMap; | ||
| } | ||
|
|
||
| @Override | ||
| public Index create(Map<String, String> data) { | ||
| if (data == null) return null; | ||
| BookType bookType = bookTypeMatcher.apply(data.keySet()); | ||
| if (bookType == null) return null; | ||
| return Index.create(bookMap.get(bookType), data); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package pl.koder95.eme.factory.impl; | ||
|
|
||
| import pl.koder95.eme.dfs.Book; | ||
| import pl.koder95.eme.dfs.BookType; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.BiPredicate; | ||
|
|
||
| public class StandardIndexFactory extends BasicIndexFactory { | ||
|
|
||
| public StandardIndexFactory(BiPredicate<Set<String>, BookType> bookTypePattern) { | ||
| super(strings -> Arrays.stream(BookType.values()) | ||
| .filter(bookType -> bookTypePattern.test(strings, bookType)) | ||
| .findFirst().orElseThrow(), | ||
| Map.of( | ||
| BookType.LIBER_BAPTISMORUM, new Book("Księga ochrzczonych"), | ||
| BookType.LIBER_CONFIRMATORUM, new Book("Księga bierzmowanych"), | ||
| BookType.LIBER_MATRIMONIORUM, new Book("Księga zaślubionych"), | ||
| BookType.LIBER_DEFUNCTORUM, new Book("Księga zmarłych") | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| public StandardIndexFactory() { | ||
| this((strings, bookType) -> switch (bookType) { | ||
| case null -> false; | ||
| case LIBER_CONFIRMATORUM -> strings.contains("confirmation-name"); | ||
| case LIBER_DEFUNCTORUM -> strings.contains("death-date-time"); | ||
| case LIBER_MATRIMONIORUM -> strings.contains("husband-surname"); | ||
| default -> strings.contains("surname"); | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package pl.koder95.eme.fx; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.Parent; | ||
| import javafx.scene.control.Dialog; | ||
| import javafx.scene.control.DialogPane; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.ProgressIndicator; | ||
| import javafx.scene.layout.VBox; | ||
| import javafx.scene.text.Font; | ||
| import javafx.scene.text.FontWeight; | ||
| import pl.koder95.eme.dfs.IndexList; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| public class ProgressDialog extends Dialog<Boolean> { | ||
| private static final AtomicLong PROGRESS_DIALOG_THREAD_SEQ = new AtomicLong(); | ||
|
|
||
| private ProgressDialog() { | ||
| this.setDialogPane(createDialogPane()); | ||
| setOnShown(event -> Platform.runLater(createProgressThread()::start)); | ||
| } | ||
|
|
||
| private Thread createProgressThread() { | ||
| return new Thread(() -> { | ||
| reloadAllIndexLists(); | ||
| Platform.runLater(() -> { | ||
| setResult(true); | ||
| close(); | ||
| }); | ||
| }, "Progress Dialog Thread #" + PROGRESS_DIALOG_THREAD_SEQ.incrementAndGet()); | ||
| } | ||
|
|
||
| private DialogPane createDialogPane() { | ||
| ProgressIndicator indicator = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); | ||
| Label label = new Label("Czekaj..."); | ||
| label.setFont(Font.font(label.getFont().getFamily(), FontWeight.BOLD, 24)); | ||
| DialogPane pane = new DialogPane(); | ||
| pane.setContent(createMainPane(indicator, label)); | ||
| return pane; | ||
| } | ||
|
|
||
| private Parent createMainPane(ProgressIndicator indicator, Label label) { | ||
| VBox main = new VBox(indicator, label); | ||
| main.setMaxWidth(Double.MAX_VALUE); | ||
| main.setSpacing(10); | ||
| main.setFillWidth(true); | ||
| main.setAlignment(Pos.CENTER); | ||
| return main; | ||
| } | ||
|
|
||
| private static void reloadAllIndexLists() { | ||
| for (IndexList value : IndexList.values()) { | ||
| reload(value); | ||
| } | ||
| } | ||
|
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new reload path clears each Useful? React with 👍 / 👎. |
||
|
|
||
| private static void reload(IndexList value) { | ||
| value.clear(); | ||
| value.load(); | ||
| } | ||
|
|
||
| public static void start() { | ||
| Platform.runLater(() -> new ProgressDialog().showAndWait()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package pl.koder95.eme.model; | ||
|
|
||
| import pl.koder95.eme.core.spi.PersonalDataModel; | ||
|
|
||
| public record PersonalData(String surname, String name, | ||
| String ban, String can, String man, String dan) | ||
| implements PersonalDataModel { | ||
| private static final String NOMEN = "N."; | ||
| private static final String EAN = "–"; | ||
|
|
||
| @Override | ||
| public String getSurname() { | ||
| return surname == null || surname.isBlank() ? NOMEN : surname; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return name == null || name.isBlank() ? NOMEN : name; | ||
| } | ||
|
|
||
| @Override | ||
| public String getBaptismAN() { | ||
| return ban == null || ban.isBlank() ? EAN : ban; | ||
| } | ||
|
|
||
| @Override | ||
| public String getConfirmationAN() { | ||
| return can == null || can.isBlank() ? EAN : can; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMarriageAN() { | ||
| return man == null || man.isBlank() ? EAN : man; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDeceaseAN() { | ||
| return dan == null || dan.isBlank() ? EAN : dan; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package pl.koder95.eme.service; | ||
|
|
||
| import pl.koder95.eme.core.spi.PersonalDataModel; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.function.Predicate; | ||
|
|
||
| public interface DataService { | ||
| void load(); | ||
| void save(); | ||
| Collection<PersonalDataModel> findPeople(Predicate<PersonalDataModel> predicate); | ||
| Collection<PersonalDataModel> findPeople(String userText, boolean cancelled); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
Book.load()passes a real<index ...>node throughIndex.create(), the node-name check succeeds and this interpreter is called, but this condition throws exactly for nodes namedindex. Any existingindices.xmlcontaining at least one valid index now aborts startup/loading instead of importing acts.Useful? React with 👍 / 👎.