Skip to content

Commit

Permalink
💡 enhanced workflow definition batch import & export
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Jul 3, 2023
1 parent 24f8089 commit 6ce035f
Show file tree
Hide file tree
Showing 32 changed files with 2,272 additions and 1,163 deletions.
7 changes: 5 additions & 2 deletions app/src/Passingwind.WorkflowApp.Web/WorkflowAppWebModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Elsa;
using Elsa.Activities.Http.OpenApi;
Expand Down Expand Up @@ -129,18 +130,20 @@ public override void ConfigureServices(ServiceConfigurationContext context)

Configure<JsonOptions>(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Default;
options.JsonSerializerOptions.Converters.Add(new TypeJsonConverter());
options.JsonSerializerOptions.Converters.Add(new JObjectConverter());
options.JsonSerializerOptions.Converters.Add(new JArrayConverter());
});

Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Default;
options.JsonSerializerOptions.Converters.Add(new TypeJsonConverter());
options.JsonSerializerOptions.Converters.Add(new JArrayConverter());
options.JsonSerializerOptions.Converters.Add(new JObjectConverter());
});

// Config default 'JsonSerializerSettings'
JsonConvert.DefaultSettings = () =>
{
Expand Down Expand Up @@ -395,7 +398,7 @@ private void ConfigureSwaggerServices(IServiceCollection services)
return $"{part1}.{part2}";
}
return type.FullName.RemovePostFix("Dto");
return type.FullName.RemovePostFix("Dto").Replace("Dto+", null);
});
options.CustomOperationIds(e =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Content;

namespace Passingwind.Abp.ElsaModule.WorkflowDefinitions;

public interface IWorkflowDefinitionAppService : ICrudAppService<WorkflowDefinitionVersionDto, WorkflowDefinitionDto, Guid, WorkflowDefinitionListRequestDto, WorkflowDefinitionVersionCreateOrUpdateDto, WorkflowDefinitionVersionCreateOrUpdateDto>
public interface IWorkflowDefinitionAppService : ICrudAppService<WorkflowDefinitionVersionDto, WorkflowDefinitionBasicDto, Guid, WorkflowDefinitionListRequestDto, WorkflowDefinitionVersionCreateOrUpdateDto, WorkflowDefinitionVersionCreateOrUpdateDto>
{
Task<PagedResultDto<WorkflowDefinitionVersionListItemDto>> GetVersionsAsync(Guid id, WorkflowDefinitionVersionListRequestDto input);
Task DeleteVersionAsync(Guid id, int version);
Expand All @@ -32,4 +33,8 @@ public interface IWorkflowDefinitionAppService : ICrudAppService<WorkflowDefinit

Task AddOwnerAsync(Guid id, WorkflowDefinitionAddOwnerRequestDto input);
Task DeleteOwnerAsync(Guid id, Guid userId);

Task<IRemoteStreamContent> ExportAsync(WorkflowDefinitionExportRequestDto input);
Task<WorkflowDefinitionImportResultDto> ImportAsync(WorkflowDefinitionImportRequestDto input);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Elsa.Models;
using Volo.Abp.Application.Dtos;

namespace Passingwind.Abp.ElsaModule.WorkflowDefinitions;

public class WorkflowDefinitionBasicDto : AuditedEntityDto<Guid>
{
public string Name { get; set; }

public string DisplayName { get; set; }

public string Description { get; set; }

public int LatestVersion { get; set; }

public int? PublishedVersion { get; set; }

public bool IsSingleton { get; set; }

public bool DeleteCompletedInstances { get; set; }

public string Channel { get; set; }

public string Tag { get; set; }

public WorkflowPersistenceBehavior PersistenceBehavior { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Elsa.Models;
using Volo.Abp.Application.Dtos;
Expand All @@ -11,8 +11,6 @@ public class WorkflowDefinitionDto : AuditedEntityDto<Guid>

public string DisplayName { get; set; }

public Guid? TenantId { get; protected set; }

public string Description { get; set; }

public int LatestVersion { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Passingwind.Abp.ElsaModule.WorkflowDefinitions;

public class WorkflowDefinitionExportRequestDto
{
public Guid[] Ids { get; set; }
//public string Format { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Content;

namespace Passingwind.Abp.ElsaModule.WorkflowDefinitions;

public class WorkflowDefinitionImportRequestDto
{
[Required]
public IRemoteStreamContent File { get; set; }

public bool Overwrite { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace Passingwind.Abp.ElsaModule.WorkflowDefinitions;

public class WorkflowDefinitionImportResultDto
{
public int TotalCount { get; set; }
public int SuccessCount { get; set; }
public int FailedCount { get; set; }

public List<WorkflowImportResult> Results { get; set; }

public class WorkflowImportResult
{
public string FileName { get; set; }
public bool HasError { get; set; }
public string ErrorMessage { get; set; }
public WorkflowDefinitionBasicDto Workflow { get; set; }
}

public WorkflowDefinitionImportResultDto()
{
Results = new List<WorkflowImportResult>();
}

public void Add(string fileName, WorkflowDefinitionBasicDto workflow)
{
Results.Add(new WorkflowImportResult
{
Workflow = workflow,
HasError = false,
FileName = fileName,
});
}

public void Add(string fileName, string errorMessage)
{
Results.Add(new WorkflowImportResult
{
HasError = true,
ErrorMessage = errorMessage,
FileName = fileName,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Passingwind.Abp.ElsaModule.Common;
using Passingwind.Abp.ElsaModule.Localization;
using Passingwind.Abp.ElsaModule.Permissions;
using Volo.Abp.Application.Services;

namespace Passingwind.Abp.ElsaModule;

public abstract class ElsaModuleAppService : ApplicationService
{
protected IWorkflowPermissionService WorkflowPermissionService => LazyServiceProvider.GetRequiredService<IWorkflowPermissionService>();

protected ElsaModuleAppService()
{
LocalizationResource = typeof(ElsaModuleResource);
Expand Down Expand Up @@ -36,4 +42,25 @@ protected virtual async Task CheckWorkflowPermissionAsync(WorkflowDefinition def
{
await AuthorizationService.CheckAsync(definition, name);
}

protected async Task<IEnumerable<Guid>> FilterWorkflowsAsync(IEnumerable<Guid> sources = null)
{
var grantedResult = await WorkflowPermissionService.GetGrantsAsync();

var filterIds = sources?.ToList();

if (!grantedResult.AllGranted)
{
if (sources?.Any() == true)
{
filterIds = grantedResult.WorkflowIds.Intersect(sources).ToList();
}
else
{
filterIds = grantedResult.WorkflowIds.ToList();
}
}

return filterIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,12 @@ public ElsaModuleApplicationAutoMapperProfile()
* Alternatively, you can split your mapping configurations
* into multiple profile classes for a better organization. */

//CreateMap<WorkflowDefinitionCreateOrUpdateDto, WorkflowDefinition>()
// .Ignore(x => x.TenantId)
// .Ignore(x => x.LatestVersion)
// .Ignore(x => x.PublishedVersion)
// .Ignore(x => x.Id)
// .Ignore(x => x.ContextOptions)
// .Ignore(x => x.CustomAttributes)
// .Ignore(x => x.Variables)
// .Ignore(x => x.ConcurrencyStamp)
// .Ignore(x => x.ExtraProperties)
// .IgnoreFullAuditedObjectProperties();

//CreateMap<WorkflowDefinitionVersionCreateOrUpdateDto, WorkflowDefinitionVersion>()
// .Ignore(x => x.TenantId)
// //.Ignore(x => x.Definition)
// .Ignore(x => x.DefinitionId)
// .Ignore(x => x.Id)
// .Ignore(x => x.IsLatest)
// //.Ignore(x => x.IsPublished)
// .Ignore(x => x.Version)
// .IgnoreFullAuditedObjectProperties();

CreateMap<WorkflowDefinitionVersion, WorkflowDefinitionVersionListItemDto>();
CreateMap<WorkflowDefinition, WorkflowDefinitionDto>();
CreateMap<WorkflowDefinition, WorkflowDefinitionBasicDto>();
CreateMap<WorkflowDefinitionVersion, WorkflowDefinitionVersionListItemDto>();
CreateMap<WorkflowDefinitionVersion, WorkflowDefinitionVersionDto>()
.Ignore(x => x.Definition);

//CreateMap<ActivityCreateOrUpdateDto, Activity>()
// .Ignore(x => x.WorkflowDefinitionVersionId)
// .IgnoreAuditedObjectProperties();

//CreateMap<ActivityConnectionDto, ActivityConnection>()
// .Ignore(x => x.WorkflowDefinitionVersionId)
// .IgnoreCreationAuditedObjectProperties();

//CreateMap<ActivityConnectionCreateDto, ActivityConnection>()
// .Ignore(x => x.WorkflowDefinitionVersionId)
// .IgnoreCreationAuditedObjectProperties();

CreateMap<Activity, ActivityDto>();
CreateMap<ActivityConnection, ActivityConnectionDto>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\common.props" />

Expand All @@ -11,7 +11,7 @@
<PackageReference Include="Volo.Abp.AutoMapper" Version="7.0.2" />
<PackageReference Include="Volo.Abp.Ddd.Application" Version="7.0.2" />
<PackageReference Include="Volo.Abp.Caching" Version="7.0.2" />
<PackageReference Include="Volo.Abp.Authorization.Abstractions" Version="7.0.2" />
<PackageReference Include="Volo.Abp.Authorization.Abstractions" Version="7.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 6ce035f

Please sign in to comment.