private OrganisationHierarchyCacheItem GetOrganisationTreeItemForOrganisation(Guid organisationId) { _logger.Trace(OperationGetOrgTree, new LogItem(nameof(organisationId), organisationId.ToString())); var queryChildRelationshipsMessage = new Message <object, Relationship> { Method = QueryChildRelationshipsMethodName, Need = new { StartNodeId = organisationId, Active = new RelationshipDateRange(_dateTimeProvider.UtcNow, null), LinkRelationshipTypes = new[] { BusinessToBusinessRelationshipType }, NodeTypes = new[] { AssetTypeOrganisation } } }; var queryChildRelationshipsResponse = _requestStore.PublishAndWaitForResponse(queryChildRelationshipsMessage, ResponseStyle.WholeSolution, SolutionMatchFunctionForAllMetadataNotNull); CheckResponse(queryChildRelationshipsResponse, organisationId); var relationshipsForOrganisation = JsonConvert.DeserializeObject <List <Relationship> >(queryChildRelationshipsResponse.Solution); OrganisationHierarchyCacheItem organisationTreeItem; if (relationshipsForOrganisation.Any()) { organisationTreeItem = ConvertRelationshipsToOrganisationTreeItem(relationshipsForOrganisation, organisationId); } else { //no relationships exist, so get the requested organisation and cast it to an organisation tree item so it can be cached. var getOrganisationMessage = new Message <Guid, OrganisationHierarchyCacheItem> { Method = GetOrganisationMethodName, Need = organisationId }; var getOrganisationResponse = _requestStore.PublishAndWaitForResponse(getOrganisationMessage, ResponseStyle.FirstOrDefault); CheckResponse(getOrganisationResponse, organisationId); organisationTreeItem = JsonConvert.DeserializeObject <OrganisationHierarchyCacheItem>(getOrganisationResponse.Solution); organisationTreeItem.OrganisationId = organisationId; organisationTreeItem.ChildOrganisations = null; } if (organisationTreeItem != null) { //publish result to the backplane to update other caches _backplane.Send(organisationTreeItem); } else { _logger.Warn(OperationGetOrgTree, new LogItem("Event", "Org tree was null, skipping publish")); } return(organisationTreeItem); }
public virtual void Handle(IHttpRequest request, IHttpResponse response) { byte[] buffer = request.Body; object need = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(buffer)); Message <dynamic, object> message = new Message <dynamic, object> { Source = ServiceInfo.Name, Method = Method, Need = need ?? new { } }; requestStore.PublishAndWaitForResponse(message, SuccessStatusCode, response, ResponseStyle, s => true); }