Fix SSH keys migration to MetaData

Issue:
When user's keys are migrated they are always marked as invalid.
There is an error in 'valid' field migration. It relies on getBoolean
implementation that returns 'true' only in case when char value is '1'.
Current table definition specifies 'Y' and 'N' values hence it cannot be
evaluated to 'true'.

Solution:
Introduce mapping function that returns boolean value according to 'Y',
'N' values.

Change-Id: I08310f85f720b3c95ffb4317c6909fbad581d7b6
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
This commit is contained in:
Jacek Centkowski
2016-06-20 18:02:05 +02:00
committed by David Pursehouse
parent 5d7572e268
commit acb6e29f81

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.schema;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;
@@ -84,7 +85,7 @@ public class Schema_124 extends SchemaVersion {
String sshPublicKey = rs.getString(3);
AccountSshKey key = new AccountSshKey(
new AccountSshKey.Id(accountId, seq), sshPublicKey);
boolean valid = rs.getBoolean(4);
boolean valid = toBoolean(rs.getString(4));
if (!valid) {
key.setInvalid();
}
@@ -143,4 +144,8 @@ public class Schema_124 extends SchemaVersion {
}
return fixedKeys;
}
private static boolean toBoolean(String v) {
return !Strings.isNullOrEmpty(v) && v.equalsIgnoreCase("Y");
}
}