@@ -168,20 +168,18 @@ static XjcRdeDomain convertDomain(Domain model, RdeMode mode) {
168168 // as the holder of the domain name object.
169169 Optional <VKey <Contact >> registrant = model .getRegistrant ();
170170 if (registrant .isPresent ()) {
171- Contact registrantContact = tm ().transact (() -> tm ().loadByKey (registrant .get ()));
172- checkState (
173- registrantContact != null ,
174- "Registrant contact %s on domain %s does not exist" ,
175- registrant ,
176- domainName );
177- bean .setRegistrant (registrantContact .getContactId ());
171+ Optional <Contact > registrantContact =
172+ tm ().transact (() -> tm ().loadByKeyIfPresent (registrant .get ()));
173+ registrantContact .ifPresent (c -> bean .setRegistrant (c .getContactId ()));
178174 }
179175
180176 // o Zero or more OPTIONAL <contact> elements that contain identifiers
181177 // for the human or organizational social information objects
182178 // associated with the domain name object.
183179 for (DesignatedContact contact : model .getContacts ()) {
184- bean .getContacts ().add (convertDesignatedContact (contact , domainName ));
180+ Optional <XjcDomainContactType > contactType =
181+ convertDesignatedContact (contact , domainName );
182+ contactType .ifPresent (c -> bean .getContacts ().add (c ));
185183 }
186184
187185 // o An OPTIONAL <secDNS> element that contains the public key
@@ -292,23 +290,21 @@ private static XjcSecdnsDsDataType convertDelegationSignerData(DomainDsData mode
292290 }
293291
294292 /** Converts {@link DesignatedContact} to {@link XjcDomainContactType}. */
295- private static XjcDomainContactType convertDesignatedContact (
293+ private static Optional < XjcDomainContactType > convertDesignatedContact (
296294 DesignatedContact model , String domainName ) {
297295 XjcDomainContactType bean = new XjcDomainContactType ();
298296 checkState (
299297 model .getContactKey () != null ,
300298 "Contact key for type %s is null on domain %s" ,
301299 model .getType (),
302300 domainName );
303- Contact contact = tm ().transact (() -> tm ().loadByKey (model .getContactKey ()));
304- checkState (
305- contact != null ,
306- "Contact %s on domain %s does not exist" ,
307- model .getContactKey (),
308- domainName );
301+ Optional <Contact > contact = tm ().transact (() -> tm ().loadByKeyIfPresent (model .getContactKey ()));
302+ if (contact .isEmpty ()) {
303+ return Optional .empty ();
304+ }
309305 bean .setType (XjcDomainContactAttrType .fromValue (Ascii .toLowerCase (model .getType ().toString ())));
310- bean .setValue (contact .getContactId ());
311- return bean ;
306+ bean .setValue (contact .get (). getContactId ());
307+ return Optional . of ( bean ) ;
312308 }
313309
314310 private DomainToXjcConverter () {}
0 commit comments