Skip to content

Commit

Permalink
Fail import only with securities that actually have a duplicate ident…
Browse files Browse the repository at this point in the history
…ifier

Issue: #477
  • Loading branch information
buchen committed Apr 23, 2016
1 parent 870d7a6 commit f1d768b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public class SecurityCache
{
private static final Security DUPLICATE_SECURITY_MARKER = new Security();

private final Client client;

private final Map<String, Security> isin2security;
Expand All @@ -29,39 +31,37 @@ public SecurityCache(Client client)
this.client = client;

this.isin2security = client.getSecurities().stream().filter(s -> s.getIsin() != null && !s.getIsin().isEmpty())
.collect(Collectors.toMap(Security::getIsin, s -> s,
(l, r) -> failWith(Messages.MsgErrorDuplicateISIN, l.getIsin())));
.collect(Collectors.toMap(Security::getIsin, s -> s, (l, r) -> DUPLICATE_SECURITY_MARKER));

this.wkn2security = client.getSecurities().stream().filter(s -> s.getWkn() != null && !s.getWkn().isEmpty())
.collect(Collectors.toMap(Security::getWkn, s -> s,
(l, r) -> failWith(Messages.MsgErrorDuplicateWKN, l.getWkn())));
.collect(Collectors.toMap(Security::getWkn, s -> s, (l, r) -> DUPLICATE_SECURITY_MARKER));

this.ticker2security = client.getSecurities().stream()
.filter(s -> s.getTickerSymbol() != null && !s.getTickerSymbol().isEmpty())
.collect(Collectors.toMap(Security::getTickerSymbol, s -> s,
(l, r) -> failWith(Messages.MsgErrorDuplicateTicker, l.getTickerSymbol())));
}

private Security failWith(String message, String parameter)
{
throw new IllegalArgumentException(MessageFormat.format(message, parameter));
.filter(s -> s.getTickerSymbol() != null && !s.getTickerSymbol().isEmpty()).collect(Collectors
.toMap(Security::getTickerSymbol, s -> s, (l, r) -> DUPLICATE_SECURITY_MARKER));
}

public Security lookup(String isin, String tickerSymbol, String wkn, Supplier<Security> creationFunction)
{
Security security = null;
if (isin != null)
security = isin2security.get(isin);
if (security == DUPLICATE_SECURITY_MARKER)
throw new IllegalArgumentException(MessageFormat.format(Messages.MsgErrorDuplicateISIN, isin));
if (security != null)
return security;

if (wkn != null)
security = wkn2security.get(wkn);
if (security == DUPLICATE_SECURITY_MARKER)
throw new IllegalArgumentException(MessageFormat.format(Messages.MsgErrorDuplicateWKN, isin));
if (security != null)
return security;

if (tickerSymbol != null)
security = ticker2security.get(tickerSymbol);
if (security == DUPLICATE_SECURITY_MARKER)
throw new IllegalArgumentException(MessageFormat.format(Messages.MsgErrorDuplicateTicker, isin));
if (security != null)
return security;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<Item> extract(int skipLines, List<String[]> rawValues, Map<String, C
{
extract(results, strings, field2column);
}
catch (ParseException | UnsupportedOperationException e)
catch (ParseException | UnsupportedOperationException | IllegalArgumentException e)
{
errors.add(new IOException(MessageFormat.format(Messages.CSVLineXwithMsgY, lineNo, e.getMessage()), e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public abstract class CSVExtractor implements Extractor
public abstract List<Item> extract(int skipLines, List<String[]> rawValues, Map<String, Column> field2column,
List<Exception> errors);

@Override
public String getFilterExtension()
{
return "*.csv"; //$NON-NLS-1$
}

@Override
public List<Item> extract(List<File> files, List<Exception> errors)
{
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -86,7 +88,7 @@ protected final Long getShares(String name, String[] rawValues, Map<String, Colu
return null;

Number num = (Number) field2column.get(name).getFormat().getFormat().parseObject(value);
return (long) Math.round(num.doubleValue() * Values.Share.factor());
return Math.round(num.doubleValue() * Values.Share.factor());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,8 @@ public String getFilterExtension()
@Override
public List<Item> extract(List<File> files, List<Exception> errors)
{
try
{
// careful: security cache makes extractor stateful
securityCache = new SecurityCache(client);
}
catch (IllegalArgumentException e)
{
errors.add(e);
return Collections.emptyList();
}
// careful: security cache makes extractor stateful
securityCache = new SecurityCache(client);

List<Item> results = new ArrayList<>();
for (File f : files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ MsgDeltaWithoutAssets = Warning: delta without assets: {0} on {1}

MsgErrorDecrypting = Error while decrypting output: {0}

MsgErrorDuplicateISIN = ISIN {0} exists multiple times in the list of securities. The import feature does not support multiple identical ISINs (at the moment).
MsgErrorDuplicateISIN = ISIN {0} exists multiple times in the list of securities.

MsgErrorDuplicateTicker = Ticker {0} exists multiple times in the list of securities. The import feature does not support multiple identical ticker (at the moment).
MsgErrorDuplicateTicker = Ticker {0} exists multiple times in the list of securities.

MsgErrorDuplicateWKN = WKN {0} exists multiple times in the list of securities. The import feature does not support multiple identical WKNs (at the moment).
MsgErrorDuplicateWKN = WKN {0} exists multiple times in the list of securities.

MsgErrorEncrypting = Error while encrypting output: {0}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ MsgDeltaWithoutAssets = Warnung: Ver\u00E4nderung ohne Kapital: {0} am {1}

MsgErrorDecrypting = Fehler w\u00E4hrend der Entschl\u00FCsselung: {0}

MsgErrorDuplicateISIN = ISIN {0} existiert mehrfach in der Wertpapierliste. Der Import unterst\u00FCtzt mehrere identische ISINs (momentan) nicht.
MsgErrorDuplicateISIN = ISIN {0} existiert mehrfach in der Wertpapierliste.

MsgErrorDuplicateTicker = Ticker Symbol {0} existiert mehrfach in der Wertpapierliste. Der Import unterst\u00FCtzt mehrere identische Ticker (momentan) nicht.
MsgErrorDuplicateTicker = Ticker Symbol {0} existiert mehrfach in der Wertpapierliste.

MsgErrorDuplicateWKN = WKN {0} existiert mehrfach in der Wertpapierliste. Der Import unterst\u00FCtzt mehrere identische WKNs (momentan) nicht.
MsgErrorDuplicateWKN = WKN {0} existiert mehrfach in der Wertpapierliste.

MsgErrorEncrypting = Fehler w\u00E4hrend der Verschl\u00FCsselung: {0}

Expand Down

0 comments on commit f1d768b

Please sign in to comment.