public int create ( User registrar ) throws IdentityException , InvalidArgumentException { if ( this . deleted ) { throw new IdentityException ( "Identity has been deleted" ) ; } if ( registrar == null ) { throw new InvalidArgumentException ( "Registrar should be a valid member" ) ; } String createURL = "" ; try { createURL = client . getURL ( HFCA_IDENTITY ) ; logger . debug ( format ( "identity url: %s, registrar: %s" , createURL , registrar . getName ( ) ) ) ; String body = client . toJson ( idToJsonObject ( ) ) ; JsonObject result = client . httpPost ( createURL , body , registrar ) ; statusCode = result . getInt ( "statusCode" ) ; if ( statusCode < 400 ) { getHFCAIdentity ( result ) ; logger . debug ( format ( "identity url: %s, registrar: %s done." , createURL , registrar ) ) ; } this . deleted = false ; return statusCode ; } catch ( HTTPException e ) { String msg = format ( "[Code: %d] - Error while creating user '%s' from url '%s': %s" , e . getStatusCode ( ) , getEnrollmentId ( ) , createURL , e . getMessage ( ) ) ; IdentityException identityException = new IdentityException ( msg , e ) ; logger . error ( msg ) ; throw identityException ; } catch ( Exception e ) { String msg = format ( "Error while creating user '%s' from url '%s': %s" , getEnrollmentId ( ) , createURL , e . getMessage ( ) ) ; IdentityException identityException = new IdentityException ( msg , e ) ; logger . error ( msg ) ; throw identityException ; } }
create an identity