1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| address = AddressExtraction.fromNode(contactNode);
/* ... */
class AddressExtraction {
static String fromNode(JsonNode adresse) {
String candidate = byId(adresse);
if(candidate == null) {
List<Adresse> adresseList = Adresse.search(adresse);
if(adresseList.size() == 1) {
return adresseList.get(0);
} else {
return Adresse.fromJson(adresse);
}
} else {
return candidate;
}
}
private static String byId(JsonNode adresse) {
if (adresse.has("id")) {
return Adresse.find.byId(UUID.fromString(adresse.get("id")
.asText()));
} else {
return null;
}
}
} |