EventFactory: Use AccountCache#maybeGet instead of AccountCache#get

AccountCache#get returns an empty AccountState to represent a missing
account. The empty AccountState has neither a full name, a preferred
email nor a user name. This means in case of a missing account we
created an empty AccountAttribute. An empty AccountAttribute is no
better than no AccountAttribute. Actually it seems that it was the
intention to return no AccountAttribute in case of a missing account
since null was returned if account state was null. Only account state
was never null since an empty account state was given when the account
was missing.

Change-Id: I558f5fe083e47d2b54a2987fa555b03ad01ce19a
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-01-26 14:56:32 +01:00
parent 8c8d02dd9a
commit 85a8ddf4a0

View File

@@ -246,8 +246,7 @@ public class EventFactory {
la.label = lbl.label;
la.status = lbl.status.name();
if (lbl.appliedBy != null) {
AccountState accountState = accountCache.get(lbl.appliedBy);
la.by = asAccountAttribute(accountState);
la.by = asAccountAttribute(lbl.appliedBy);
}
sa.labels.add(la);
}
@@ -573,7 +572,7 @@ public class EventFactory {
if (id == null) {
return null;
}
return asAccountAttribute(accountCache.get(id));
return accountCache.maybeGet(id).map(a -> asAccountAttribute(a)).orElse(null);
}
/**
@@ -583,10 +582,6 @@ public class EventFactory {
* @return object suitable for serialization to JSON
*/
public AccountAttribute asAccountAttribute(AccountState accountState) {
if (accountState == null) {
return null;
}
AccountAttribute who = new AccountAttribute();
who.name = accountState.getAccount().getFullName();
who.email = accountState.getAccount().getPreferredEmail();