Skip to content

Commit

Permalink
fix e507b9 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Oct 16, 2022
1 parent b4e120f commit 1f19184
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,112 +1,103 @@
using System.Threading.Tasks;
using Elsa.Events;
using MediatR;
using Passingwind.Abp.ElsaModule.Common;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;

namespace Passingwind.Abp.ElsaModule.Stores
{
public class EntityEventHandler :
ILocalEventHandler<EntityCreatedEventData<WorkflowDefinitionVersion>>,
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinitionVersion>>,
ILocalEventHandler<EntityDeletedEventData<WorkflowDefinitionVersion>>,
//
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinition>>,
//
ILocalEventHandler<EntityDeletedEventData<WorkflowInstance>>,
//
ITransientDependency
{
private readonly IMediator _mediator;
private readonly IStoreMapper _storeMapper;
private readonly IWorkflowDefinitionRepository _workflowDefinitionRepository;
private readonly IWorkflowDefinitionVersionRepository _workflowDefinitionVersionRepository;

public EntityEventHandler(IMediator mediator, IStoreMapper storeMapper, IWorkflowDefinitionRepository workflowDefinitionRepository, IWorkflowDefinitionVersionRepository workflowDefinitionVersionRepository)
{
_mediator = mediator;
_storeMapper = storeMapper;
_workflowDefinitionRepository = workflowDefinitionRepository;
_workflowDefinitionVersionRepository = workflowDefinitionVersionRepository;
}

public async Task HandleEventAsync(EntityCreatedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = await _workflowDefinitionRepository.GetAsync(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(model));

if (model.IsPublished)
await _mediator.Publish(new WorkflowDefinitionPublished(model));
}

public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = await _workflowDefinitionRepository.GetAsync(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(model));

if (model.IsPublished)
await _mediator.Publish(new WorkflowDefinitionPublished(model));
else
await _mediator.Publish(new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition() { DefinitionId = definitionId.ToString(), Id = eventData.Entity.Id.ToString() }));
}

public async Task HandleEventAsync(EntityDeletedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = new WorkflowDefinition(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionDeleted(model));
}

public async Task HandleEventAsync(EntityDeletedEventData<WorkflowInstance> eventData)
{
var model = _storeMapper.MapToModel(eventData.Entity);

await _mediator.Publish(new WorkflowInstanceDeleted(model));
}

public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinition> eventData)
{
var definition = eventData.Entity;
var definitionId = definition.Id;

// published version
if (definition.PublishedVersion.HasValue)
{
var publishVersion = definition.PublishedVersion.Value;
var publishtVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, publishVersion);

var publishModel = _storeMapper.MapToModel(publishtVersionEntity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(publishModel));
await _mediator.Publish(new WorkflowDefinitionPublished(publishModel));
}
else
{
var workflowDefinitionRetracted = new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition { DefinitionId = definitionId.ToString(), Id = definition.Id.ToString() });
await _mediator.Publish(workflowDefinitionRetracted);
}

// latest version
var latestVersion = definition.LatestVersion;
var latestVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, latestVersion);

var latestModel = _storeMapper.MapToModel(latestVersionEntity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(latestModel));
}

}
}
using System.Threading.Tasks;
using Elsa.Events;
using MediatR;
using Passingwind.Abp.ElsaModule.Common;
using Passingwind.Abp.ElsaModule.Stores;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;

namespace Passingwind.Abp.ElsaModule.EventHandlers
{
public class WorkflowDefinitionEventHander :
ILocalEventHandler<EntityCreatedEventData<WorkflowDefinitionVersion>>,
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinitionVersion>>,
ILocalEventHandler<EntityDeletedEventData<WorkflowDefinitionVersion>>,
//
ILocalEventHandler<EntityUpdatedEventData<WorkflowDefinition>>,
//
ITransientDependency
{
private readonly IMediator _mediator;
private readonly IStoreMapper _storeMapper;
private readonly IWorkflowDefinitionRepository _workflowDefinitionRepository;
private readonly IWorkflowDefinitionVersionRepository _workflowDefinitionVersionRepository;

public WorkflowDefinitionEventHander(IMediator mediator, IStoreMapper storeMapper, IWorkflowDefinitionRepository workflowDefinitionRepository, IWorkflowDefinitionVersionRepository workflowDefinitionVersionRepository)
{
_mediator = mediator;
_storeMapper = storeMapper;
_workflowDefinitionRepository = workflowDefinitionRepository;
_workflowDefinitionVersionRepository = workflowDefinitionVersionRepository;
}

public async Task HandleEventAsync(EntityCreatedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = await _workflowDefinitionRepository.GetAsync(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(model));

if (model.IsPublished)
await _mediator.Publish(new WorkflowDefinitionPublished(model));
}

public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = await _workflowDefinitionRepository.GetAsync(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(model));

if (model.IsPublished)
await _mediator.Publish(new WorkflowDefinitionPublished(model));
else
await _mediator.Publish(new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition() { DefinitionId = definitionId.ToString(), Id = eventData.Entity.Id.ToString() }));
}

public async Task HandleEventAsync(EntityDeletedEventData<WorkflowDefinitionVersion> eventData)
{
var definitionId = eventData.Entity.DefinitionId;
var definition = new WorkflowDefinition(definitionId);

var model = _storeMapper.MapToModel(eventData.Entity, definition);

await _mediator.Publish(new WorkflowDefinitionDeleted(model));
}

public async Task HandleEventAsync(EntityUpdatedEventData<WorkflowDefinition> eventData)
{
var definition = eventData.Entity;
var definitionId = definition.Id;

// published version
if (definition.PublishedVersion.HasValue)
{
var publishVersion = definition.PublishedVersion.Value;
var publishtVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, publishVersion);

var publishModel = _storeMapper.MapToModel(publishtVersionEntity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(publishModel));
await _mediator.Publish(new WorkflowDefinitionPublished(publishModel));
}
else
{
var workflowDefinitionRetracted = new WorkflowDefinitionRetracted(new Elsa.Models.WorkflowDefinition { DefinitionId = definitionId.ToString(), Id = definition.Id.ToString() });
await _mediator.Publish(workflowDefinitionRetracted);
}

// latest version
var latestVersion = definition.LatestVersion;
var latestVersionEntity = await _workflowDefinitionVersionRepository.GetByVersionAsync(definitionId, latestVersion);

var latestModel = _storeMapper.MapToModel(latestVersionEntity, definition);

await _mediator.Publish(new WorkflowDefinitionSaved(latestModel));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Elsa.Events;
using MediatR;
using Passingwind.Abp.ElsaModule.Common;
using Passingwind.Abp.ElsaModule.Stores;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;

namespace Passingwind.Abp.ElsaModule.EventHandlers
{
public class WorkflowInstanceEventHander :
ILocalEventHandler<EntityDeletedEventData<WorkflowInstance>>,
//
ITransientDependency
{
private readonly IMediator _mediator;
private readonly IStoreMapper _storeMapper;

public WorkflowInstanceEventHander(IMediator mediator, IStoreMapper storeMapper)
{
_mediator = mediator;
_storeMapper = storeMapper;
}

public async Task HandleEventAsync(EntityDeletedEventData<WorkflowInstance> eventData)
{
var model = _storeMapper.MapToModel(eventData.Entity);

await _mediator.Publish(new WorkflowInstanceDeleted(model));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public virtual WorkflowInstanceModel MapToModel(WorkflowInstance entity)
Metadata = entity.GetMetadata(),
Variables = new Elsa.Models.Variables(entity.GetVariables()),
ActivityData = entity.ActivityData?.ToDictionary(x => x.ActivityId.ToString(), x => (IDictionary<string, object>)x.Data) ?? new Dictionary<string, IDictionary<string, object>>(),
BlockingActivities = entity.BlockingActivities?.Select(x => new BlockingActivity(x.ActivityType, x.ActivityType) { Tag = x.Tag })?.ToHashSet() ?? new HashSet<BlockingActivity>(),
BlockingActivities = entity.BlockingActivities?.Select(x => new BlockingActivity(x.ActivityId.ToString(), x.ActivityType) { Tag = x.Tag })?.ToHashSet() ?? new HashSet<BlockingActivity>(),
ScheduledActivities = new Elsa.Models.SimpleStack<Elsa.Models.ScheduledActivity>(entity.ScheduledActivities?.Select(x => new Elsa.Models.ScheduledActivity(x.ActivityId.ToString(), x.Input)) ?? new List<Elsa.Models.ScheduledActivity>()),
Scopes = new Elsa.Models.SimpleStack<Elsa.Models.ActivityScope>(entity.ActivityScopes?.Select(x => new Elsa.Models.ActivityScope() { ActivityId = x.ActivityId.ToString(), Variables = new Elsa.Models.Variables(x.Variables) })?.ToList() ?? new List<Elsa.Models.ActivityScope>()),

Expand Down

0 comments on commit 1f19184

Please sign in to comment.