-
Notifications
You must be signed in to change notification settings - Fork 609
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
Allow to select an existing security to replace a newly imported one #3494
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...hen.portfolio.ui/src/name/abuchen/portfolio/ui/wizards/datatransfer/ImportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package name.abuchen.portfolio.ui.wizards.datatransfer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.swt.widgets.Display; | ||
|
||
import name.abuchen.portfolio.datatransfer.Extractor; | ||
import name.abuchen.portfolio.datatransfer.actions.InsertAction; | ||
import name.abuchen.portfolio.model.Client; | ||
import name.abuchen.portfolio.model.Security; | ||
import name.abuchen.portfolio.ui.jobs.ConsistencyChecksJob; | ||
import name.abuchen.portfolio.ui.jobs.UpdateQuotesJob; | ||
import name.abuchen.portfolio.ui.util.swt.ActiveShell; | ||
import name.abuchen.portfolio.ui.wizards.security.FindQuoteProviderDialog; | ||
|
||
public class ImportController | ||
{ | ||
|
||
private final Client client; | ||
|
||
public ImportController(Client client) | ||
{ | ||
this.client = client; | ||
} | ||
|
||
public void perform(List<ReviewExtractedItemsPage> pages) | ||
{ | ||
if (pages.isEmpty()) | ||
return; | ||
|
||
var newSecurities = new ArrayList<Security>(); | ||
|
||
var isDirty = false; | ||
for (ReviewExtractedItemsPage page : pages) | ||
{ | ||
page.afterPage(); | ||
var isPageDirty = importPage(page, newSecurities); | ||
isDirty |= isPageDirty; | ||
} | ||
|
||
if (isDirty) | ||
{ | ||
client.markDirty(); | ||
|
||
// run consistency checks in case bogus transactions have been | ||
// created (say: an outbound delivery of a security where there | ||
// no held shares) | ||
new ConsistencyChecksJob(client, false).schedule(); | ||
} | ||
|
||
if (!newSecurities.isEmpty()) | ||
{ | ||
// updated prices for newly created securities (for example | ||
// crypto currencies already have a working configuration) | ||
|
||
new UpdateQuotesJob(client, newSecurities).schedule(); | ||
|
||
// run async to allow the other dialog to close | ||
|
||
Display.getDefault().asyncExec(() -> { | ||
FindQuoteProviderDialog dialog = new FindQuoteProviderDialog(ActiveShell.get(), client, newSecurities); | ||
dialog.open(); | ||
}); | ||
} | ||
} | ||
|
||
private boolean importPage(ReviewExtractedItemsPage page, ArrayList<Security> newSecurities) | ||
{ | ||
var isDirty = false; | ||
|
||
InsertAction action = new InsertAction(client); | ||
action.setConvertBuySellToDelivery(page.doConvertToDelivery()); | ||
action.setRemoveDividends(page.doRemoveDividends()); | ||
|
||
for (ExtractedEntry entry : page.getEntries()) | ||
{ | ||
if (entry.isImported()) | ||
{ | ||
action.setInvestmentPlanItem(entry.getItem().isInvestmentPlanItem()); | ||
|
||
// apply security override | ||
if (entry.getSecurityOverride() != null) | ||
entry.getItem().setSecurity(entry.getSecurityOverride()); | ||
|
||
entry.getItem().apply(action, page); | ||
isDirty = true; | ||
|
||
if (entry.getItem() instanceof Extractor.SecurityItem) | ||
{ | ||
newSecurities.add(entry.getItem().getSecurity()); | ||
} | ||
} | ||
} | ||
return isDirty; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe that way better for understanding the code?
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.
It was only a formatting change - maybe I should remove even the formatting from the commit.
I am also not sure if the statements are identical due to the missing parenthesis.