public async Task <HFCAAffiliationResp> UpdateAsync(IUser registrar, bool force, CancellationToken token = default(CancellationToken)) { if (deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } if (string.IsNullOrEmpty(Name)) { throw new ArgumentException("Affiliation name cannot be null or empty"); } string updateURL = ""; try { Dictionary <string, string> queryParm = new Dictionary <string, string>(); queryParm.Add("force", force.ToString()); updateURL = client.GetURL(HFCA_AFFILIATION + "/" + Name, queryParm); logger.Debug($"affiliation url: {updateURL}, registrar: {registrar.Name}"); string body = client.ToJson(AffToJsonObject()); JObject result = await client.HttpPutAsync(updateURL, body, registrar, token).ConfigureAwait(false); GenerateResponse(result); logger.Debug($"identity url: {updateURL}, registrar: {registrar.Name} done."); HFCAAffiliationResp resp = GetResponse(result); childHFCAAffiliations = resp.Children; identities = resp.Identities; return(GetResponse(result)); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while updating affiliation '{Name}' from url '{updateURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while updating affiliation {Name} url: {updateURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }
public async Task <HFCAAffiliationResp> DeleteAsync(IUser registrar, bool force, CancellationToken token = default(CancellationToken)) { if (deleted) { throw new AffiliationException("Affiliation has been deleted"); } if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } string deleteURL = ""; try { Dictionary <string, string> queryParm = new Dictionary <string, string>(); queryParm.Add("force", force.ToString()); deleteURL = client.GetURL(HFCA_AFFILIATION + "/" + Name, queryParm); logger.Debug($"affiliation url: {deleteURL}, registrar: {registrar.Name}"); JObject result = await client.HttpDeleteAsync(deleteURL, registrar, token).ConfigureAwait(false); logger.Debug($"identity url: {deleteURL}, registrar: {registrar.Name} done."); deleted = true; return(GetResponse(result)); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while deleting affiliation '{Name}' from url '{deleteURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while deleting affiliation {Name} url: {deleteURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }
/** * create an affiliation * * @param registrar The identity of the registrar (i.e. who is performing the registration). * @param force Forces the creation of parent affiliations * @return Response of request * @throws AffiliationException if adding an affiliation fails. * @throws InvalidArgumentException */ public async Task <HFCAAffiliationResp> CreateAsync(IUser registrar, bool force, CancellationToken token = default(CancellationToken)) { if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } string createURL = ""; try { logger.Debug($"affiliation url: {createURL}, registrar: {registrar.Name}"); Dictionary <string, string> queryParm = new Dictionary <string, string>(); queryParm.Add("force", force.ToString()); createURL = client.GetURL(HFCA_AFFILIATION, queryParm); //TODO Report bug into the JAVA version, force was never sent. string body = client.ToJson(AffToJsonObject()); JObject result = await client.HttpPostAsync(createURL, body, registrar, token).ConfigureAwait(false); logger.Debug($"identity url: {createURL}, registrar: {registrar.Name} done."); deleted = false; return(GetResponse(result)); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while creating affiliation '{Name}' from url '{createURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while creating affiliation {Name} url: {createURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }
public async Task <int> ReadAsync(IUser registrar, CancellationToken token = default(CancellationToken)) { if (registrar == null) { throw new ArgumentException("Registrar should be a valid member"); } string readAffURL = ""; try { readAffURL = HFCA_AFFILIATION + "/" + Name; logger.Debug($"affiliation url: {readAffURL}, registrar: {registrar.Name}"); JObject result = await client.HttpGetAsync(readAffURL, registrar, token).ConfigureAwait(false); logger.Debug($"affiliation url: {readAffURL}, registrar: {registrar} done."); HFCAAffiliationResp resp = GetResponse(result); childHFCAAffiliations = resp.Children; identities = resp.Identities; deleted = false; return(resp.StatusCode); } catch (HTTPException e) { string msg = $"[Code: {e.StatusCode}] - Error while getting affiliation '{Name}' from url '{readAffURL}': {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } catch (Exception e) { string msg = $"Error while getting affiliation {Name} url: {readAffURL} {e.Message}"; AffiliationException affiliationException = new AffiliationException(msg, e); logger.Error(msg); throw affiliationException; } }