Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broader support for online update of securities #1908

Expand Up @@ -51,7 +51,7 @@ else if (p.getPropertyType() == int.class && p.getWriteMethod() != null)
skipped++;
}

assertThat(skipped, equalTo(11));
assertThat(skipped, equalTo(12));

Security target = source.deepCopy();

Expand Down
Expand Up @@ -578,8 +578,8 @@ public class Messages extends NLS
public static String LabelLayoutRelevant;
public static String LabelLevelNameNumber;
public static String LabelLevelNumber;
public static String LabelLinkedToPortfolioReport;
public static String LabelLinkToPortfolioReportNet;
public static String LabelLinkedTo;
public static String LabelLinkTo;
public static String LabelNamePlusCopy;
public static String LabelNet;
public static String LabelNewClassification;
Expand Down
Expand Up @@ -2,19 +2,16 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import com.ibm.icu.text.MessageFormat;

import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.online.SecuritySearchProvider.ResultItem;
import name.abuchen.portfolio.online.impl.PortfolioReportNet;
import name.abuchen.portfolio.online.SecuritySearchProvider;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.PortfolioPlugin;

Expand All @@ -38,26 +35,14 @@ protected IStatus run(IProgressMonitor monitor)

boolean isDirty = false;

PortfolioReportNet portfolioReport = new PortfolioReportNet();

for (Security security : toBeSynced)
{
monitor.worked(1);
SecuritySearchProvider securityUpdater = security.getOnlineProvider();

monitor.worked(1);
try
{
Optional<ResultItem> item = portfolioReport.getUpdatedValues(security.getOnlineId());

if (item.isPresent())
{
boolean hasUpdate = PortfolioReportNet.updateWith(security, item.get());
isDirty = isDirty || hasUpdate;
}
else
{
PortfolioPlugin.info(MessageFormat.format("No data found for ''{0}'' with OnlineId {1}", //$NON-NLS-1$
security.getName(), security.getOnlineId()));
}
isDirty = isDirty || securityUpdater.update(security);
}
catch (IOException e)
{
Expand Down
@@ -1,6 +1,6 @@
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
#Eclipse modern messages class
#Sat Jun 13 22:27:33 CEST 2020
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
#Eclipse modern messages class
#Sat Jun 13 22:27:33 CEST 2020

AboutText = Portfolio Performance\n\nVersion: {0} ({1})\nPlatform: {2}, {3}\nJava: {4}, {5}\n\n(c) Copyright [Andreas Buchen](https://github.com/buchen) 2012 - 2020. All rights reserved.\n\nIn memory of my mother.

Expand Down Expand Up @@ -1196,9 +1196,9 @@ LabelLevelNameNumber = {0} (Level {1})

LabelLevelNumber = Level {0}

LabelLinkToPortfolioReportNet = Link to Portfolio Report
LabelLinkedTo = Linked to <a>{0}</a>

LabelLinkedToPortfolioReport = Linked to <a>Portfolio Report</a>
LabelLinkTo = Link to ...

LabelMaxDrawdown = Maximum Drawdown

Expand Down Expand Up @@ -1922,7 +1922,7 @@ SecurityMenuAddEvent = Event...

SecurityMenuAddNewSecurity = Add new investment instrument

SecurityMenuAddNewSecurityDescription = Search Yahoo Finance by ticker symbol, ISIN, or name\n(using your web browser might find more).
SecurityMenuAddNewSecurityDescription = Search by ticker symbol, ISIN, or name\n(using your web browser might find more).

SecurityMenuAddPrice = Add

Expand Down
Expand Up @@ -1183,9 +1183,9 @@ LabelLevelNameNumber = {0} (Ebene {1})

LabelLevelNumber = Ebene {0}

LabelLinkToPortfolioReportNet = Mit Portfolio Report verkn\u00FCpfen
LabelLinkedTo = Verkn\u00FCpft mit <a>{0}</a>

LabelLinkedToPortfolioReport = Verkn\u00FCpft mit <a>Portfolio Report</a>
LabelLinkTo = Verkn\u00FCpfen mit ...

LabelMaxDrawdown = Maximaler Drawdown

Expand Down Expand Up @@ -1909,7 +1909,7 @@ SecurityMenuAddEvent = Ereignis...

SecurityMenuAddNewSecurity = Wertpapier hinzuf\u00FCgen

SecurityMenuAddNewSecurityDescription = Auf Yahoo Finance anhand Ticker Symbol, ISIN, oder Name nach\nWertpapieren suchen (direkt im Browser findet man evtl. mehr).
SecurityMenuAddNewSecurityDescription = Suche anhand von Ticker Symbol, ISIN, oder Name nach\nWertpapieren (direkt im Browser findet man evtl. mehr).

SecurityMenuAddPrice = Neu

Expand Down
Expand Up @@ -1053,9 +1053,9 @@ LabelLevelNameNumber = {0} (Nivel {1})

LabelLevelNumber = Nivel {0}

LabelLinkToPortfolioReportNet = Enlace con Portfolio Report
LabelLinkTo = Enlace con ...

LabelLinkedToPortfolioReport = Vinculado al <a>Portfolio Report</a>
LabelLinkedTo = Vinculado al <a>{0}</a>

LabelMaxDrawdown = Drawdown m\u00E1ximo

Expand Down Expand Up @@ -1705,7 +1705,7 @@ SecurityListFilterOnlySecurities = Solo valores

SecurityMenuAddNewSecurity = A\u00F1adir un nuevo instrumento de inversi\u00F3n

SecurityMenuAddNewSecurityDescription = Buscar Yahoo Finanzas por s\u00EDmbolo, ISIN, o nombre\n(utilizando el navegador web puede encontrar m\u00E1s).
SecurityMenuAddNewSecurityDescription = Buscar por s\u00EDmbolo, ISIN, o nombre\n(utilizando el navegador web puede encontrar m\u00E1s).

SecurityMenuAddPrice = A\u00F1adir

Expand Down
@@ -1,4 +1,4 @@
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)

AccountFilterRetiredAccounts = Cacher comptes inactifs

Expand Down Expand Up @@ -1156,9 +1156,9 @@ LabelLevelNameNumber = {0} (Niveau {1})

LabelLevelNumber = Niveau {0}

LabelLinkToPortfolioReportNet = Lien vers Portfolio Report
LabelLinkTo = Lien vers ...

LabelLinkedToPortfolioReport = Li\u00E9 \u00E0 <a>Portfolio Report</a>
LabelLinkedTo = Li\u00E9 \u00E0 <a>{0}</a>

LabelMaxDrawdown = Maximum Drawdown

Expand Down Expand Up @@ -1870,7 +1870,7 @@ SecurityListFilterOnlySecurities = Seulement titres

SecurityMenuAddNewSecurity = Ajouter nouvel instrument

SecurityMenuAddNewSecurityDescription = Rechercher Yahoo Finance par symbole, ISIN ou nom\n(l'utilisation du navigateur Web peut en trouver plus).
SecurityMenuAddNewSecurityDescription = Rechercher par symbole, ISIN ou nom\n(l'utilisation du navigateur Web peut en trouver plus).

SecurityMenuAddPrice = Ajouter

Expand Down
Expand Up @@ -1175,9 +1175,9 @@ LabelLevelNameNumber = {0} (Niveau {1})

LabelLevelNumber = Niveau {0}

LabelLinkToPortfolioReportNet = Link met Portfolio Report
LabelLinkTo = Link met ...

LabelLinkedToPortfolioReport = Gekoppeld aan <a>Portfolio Report</a>
LabelLinkedTo = Gekoppeld aan <a>{0}</a>

LabelMaxDrawdown = Maximale daling

Expand Down Expand Up @@ -1891,7 +1891,7 @@ SecurityListFilterOnlySecurities = Alleen effecten

SecurityMenuAddNewSecurity = Nieuw beleggingsinstrument toevoegen

SecurityMenuAddNewSecurityDescription = Zoeken naar Yahoo Finance op tickersymbool, ISIN of naam\n(mogelijk vindt u via uw webbrowser meer).
SecurityMenuAddNewSecurityDescription = Zoeken op tickersymbool, ISIN of naam\n(mogelijk vindt u via uw webbrowser meer).

SecurityMenuAddPrice = Toevoegen

Expand Down
Expand Up @@ -1179,9 +1179,9 @@ LabelLevelNameNumber = {0} (N\u00EDvel {1})

LabelLevelNumber = Level {0}

LabelLinkToPortfolioReportNet = Vincule com o Portfolio Report
LabelLinkTo = Vincule com o ...

LabelLinkedToPortfolioReport = Vinculado ao <a>Portfolio Report</a>
LabelLinkedTo = Vinculado ao <a>{0}</a>

LabelMaxDrawdown = Drawdown m\u00E1ximo

Expand Down Expand Up @@ -1897,7 +1897,7 @@ SecurityListFilterOnlySecurities = Apenas a\u00E7\u00F5es

SecurityMenuAddNewSecurity = Adicionar um novo instrumento de investimento

SecurityMenuAddNewSecurityDescription = Pesquise no Yahoo Finance pelo s\u00EDmbolo, ISIN ou nome\n(usando o seu navegador pode encontrar mais).
SecurityMenuAddNewSecurityDescription = Pesquise pelo s\u00EDmbolo, ISIN ou nome\n(usando o seu navegador pode encontrar mais).

SecurityMenuAddPrice = Adicionar

Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.ToolTip;
Expand Down Expand Up @@ -53,12 +54,16 @@
import name.abuchen.portfolio.money.Values;
import name.abuchen.portfolio.online.Factory;
import name.abuchen.portfolio.online.QuoteFeed;
import name.abuchen.portfolio.online.SecuritySearchProvider;
import name.abuchen.portfolio.online.SecuritySearchProvider.ResultItem;
import name.abuchen.portfolio.online.impl.ETFDataComSearchProvider;
import name.abuchen.portfolio.online.impl.PortfolioReportNet;
import name.abuchen.portfolio.online.impl.PortfolioReportNetSearchProvider;
import name.abuchen.portfolio.snapshot.QuoteQualityMetrics;
import name.abuchen.portfolio.snapshot.ReportingPeriod;
import name.abuchen.portfolio.ui.Images;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.dialogs.ListSelectionDialog;
import name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog;
import name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanDialog;
import name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction;
Expand Down Expand Up @@ -94,22 +99,22 @@
import name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog;
import name.abuchen.portfolio.ui.wizards.splits.StockSplitWizard;
import name.abuchen.portfolio.util.Interval;
import name.abuchen.portfolio.util.Isin;
import name.abuchen.portfolio.util.Pair;

public final class SecuritiesTable implements ModificationListener
{
private class LinkToPortfolioReport extends Action
private class LinkTo extends Action
{
private Security security;

public LinkToPortfolioReport(Security security)
public LinkTo(Security security)
{
super(Messages.LabelLinkToPortfolioReportNet);
super(Messages.LabelLinkTo);
this.security = security;
}

@Override
public void run()
private void linkToPortfolioReport() throws IOException
{
InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), Messages.LabelInfo,
"Portfolio Report URL", "https://www.portfolio-report.net/", //$NON-NLS-1$//$NON-NLS-2$
Expand All @@ -126,24 +131,77 @@ public void run()

String onlineId = matcher.group(1);

Optional<ResultItem> result = new PortfolioReportNet().getUpdatedValues(onlineId);
if (!result.isPresent())
{
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError,
MessageFormat.format(Messages.MsgErrorNoInvestmentVehicleFoundAtURL, url));
}
else
{
security.setOnlineId(onlineId);
PortfolioReportNet.updateWith(security, result.get());
}
}

@Override
public void run()
{

LabelProvider labelProvider = new LabelProvider()
{
@Override
public String getText(Object element)
{
return ((SecuritySearchProvider) element).getName();
}
};
ListSelectionDialog ldlg = new ListSelectionDialog(Display.getCurrent().getActiveShell(), labelProvider);

ldlg.setTitle(Messages.LabelLinkTo);
ldlg.setMessage(String.format("%s %s", Messages.LabelLinkTo, Messages.LabelQuoteFeedProvider)); //$NON-NLS-1$
ldlg.setMultiSelection(false);

ldlg.setElements(Factory.getSearchProvider().stream()
.filter(SecuritySearchProvider::supportsUpdates)
.collect(Collectors.toList())
);

if (ldlg.open() != Window.OK)
return;

try
{
Optional<ResultItem> result = new PortfolioReportNet().getUpdatedValues(onlineId);
if (!result.isPresent())
if (ldlg.getResult()[0].getClass() == PortfolioReportNetSearchProvider.class)
{
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError,
MessageFormat.format(Messages.MsgErrorNoInvestmentVehicleFoundAtURL, url));
linkToPortfolioReport();
}
else

if (ldlg.getResult()[0].getClass() == ETFDataComSearchProvider.class)
{
security.setOnlineId(onlineId);
PortfolioReportNet.updateWith(security, result.get());
linkToETFDataCom();
}
}
catch (IOException e)
{
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, e.getMessage());
}

}

private void linkToETFDataCom() throws IOException, IllegalArgumentException
{
if (!Isin.isValid(security.getIsin()))
{
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError,
MessageFormat.format(Messages.MsgDialogNotAValidISIN, security.getIsin()));
return;
}
ETFDataComSearchProvider searchProvider = new ETFDataComSearchProvider();
String neweOnlineId = String.format("%s:%s", searchProvider.getName(), security.getIsin()); //$NON-NLS-1$
security.setOnlineId(neweOnlineId);

searchProvider.update(security);
}
}

Expand Down Expand Up @@ -922,7 +980,7 @@ private void fillContextMenu(IMenuManager manager)
if (security.getOnlineId() == null)
{
manager.add(new Separator());
manager.add(new LinkToPortfolioReport(security));
manager.add(new LinkTo(security));
}
}

Expand Down
Expand Up @@ -3,6 +3,7 @@
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.graphics.Image;

import name.abuchen.portfolio.model.AttributeType;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.online.SecuritySearchProvider.ResultItem;
Expand Down Expand Up @@ -38,7 +39,12 @@ public Security getSecurity()
if (item == null)
return null;

return item.create();
Security newSecurity = item.create();

for (AttributeType type : newSecurity.getAttributes().getAll().keySet())
this.client.getSettings().addAttributeTypeIfNotExists(type);

return newSecurity;
}

@Override
Expand Down