-
Notifications
You must be signed in to change notification settings - Fork 27
Feature/maintenance-scheduler #948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MathoMathiasCamara
wants to merge
3
commits into
future
Choose a base branch
from
feature/maintenance-scheduler
base: future
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Moryx.Maintenance.Endpoints/Dtos/GetAllMaintenanceOrderResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using Moryx.Maintenance.Management.Models; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints.Dtos; | ||
| public record GetAllMaintenanceOrderResponse(List<MaintenanceOrderModel> Data); | ||
70 changes: 70 additions & 0 deletions
70
src/Moryx.Maintenance.Endpoints/Dtos/MaintenanceOrderResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using System.ComponentModel; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.Runtime.Serialization; | ||
| using Moryx.ControlSystem.VisualInstructions; | ||
| using Moryx.Maintenance.Attributes; | ||
| using Moryx.Maintenance.IntervalTypes; | ||
| using Moryx.Maintenance.Localizations; | ||
| using Moryx.Serialization; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints.Dtos; | ||
|
|
||
| /// <summary> | ||
| /// UI specific Dto for a maintenance order | ||
| /// </summary> | ||
| [DataContract, EntrySerialize] | ||
| [Display(ResourceType = typeof(Strings), Name = nameof(Strings.MAINTENANCE_FORM))] | ||
| public class MaintenanceOrderResponse | ||
| { | ||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.RESOURCE), | ||
| Description = nameof(Strings.RESOURCE_DESCRIPTION) | ||
| )] | ||
| [MaintainableResources, Required, DataMember] | ||
| public string Resource { get; set; } | ||
|
|
||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.DESCRIPTION) | ||
| )] | ||
| [DataMember] | ||
| public string? Description { get; set; } | ||
|
|
||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.INTERVAL), | ||
| Description = nameof(Strings.INTERVAL_DESCRIPTION) | ||
| )] | ||
| [EntryPrototypes(typeof(IntervalBase)), Required, DataMember] | ||
| public IntervalBase Interval { get; set; } = new Days(); | ||
|
|
||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.INSTRUCTIONS), | ||
| Description = nameof(Strings.INTERVAL_DESCRIPTION) | ||
| )] | ||
| [DataMember] | ||
| public VisualInstruction[] Instructions { get; set; } = []; | ||
|
|
||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.BLOCK), | ||
| Description = nameof(Strings.BLOCK_DESCRIPTION) | ||
| )] | ||
| [EntrySerialize, DataMember] | ||
| public bool Block { get; set; } | ||
|
|
||
| [Display( | ||
| ResourceType = typeof(Strings), | ||
| Name = nameof(Strings.IS_ACTIVE), | ||
| Description = nameof(Strings.IS_ACTIVE_DESCRIPTION) | ||
| )] | ||
| [DefaultValue(true), DataMember] | ||
| public bool IsActive { get; set; } | ||
|
|
||
| [EntrySerialize(EntrySerializeMode.Never), ReadOnly(true), DataMember] | ||
| public DateTime Created { get; set; } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/Moryx.Maintenance.Endpoints/Extensions/MaintenanceOrderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using Moryx.Maintenance.Endpoints.Dtos; | ||
| using Moryx.Maintenance.Management.Models; | ||
| using Moryx.Serialization; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints.Extensions; | ||
|
|
||
| internal static class MaintenanceOrderExtensions | ||
| { | ||
|
|
||
| public static Entry ToEntry(this MaintenanceOrderResponse dto, ICustomSerialization serialization) | ||
| { | ||
| return EntryConvert.EncodeObject(dto, serialization); | ||
| } | ||
|
|
||
| public static MaintenanceOrderResponse ToOrderEntry(this MaintenanceOrderModel dto) | ||
| => new() | ||
| { | ||
| Resource = dto.Resource.Name, | ||
| Description = dto.Description, | ||
| Block = dto.Block, | ||
| IsActive = dto.IsActive, | ||
| Created = dto.Created, | ||
| Instructions = [.. dto.Instructions], | ||
| Interval = dto.Interval.Interval, | ||
| }; | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/Moryx.Maintenance.Endpoints/MaintainableResourcesAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Moryx.AbstractionLayer.Resources; | ||
| using Moryx.Container; | ||
| using Moryx.Serialization; | ||
| using Moryx.Maintenance.Endpoints.Mappers; | ||
| using Moryx.Maintenance.Management.Models; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints; | ||
|
|
||
| internal class MaintainableResourcesAttribute : PossibleValuesAttribute | ||
| { | ||
| public override IEnumerable<string> GetValues(IContainer localContainer, IServiceProvider serviceProvider) | ||
| { | ||
| var values = GetPossibleValues(serviceProvider).Select(x => x.Name); | ||
| return values; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override bool OverridesConversion => true; | ||
|
|
||
| /// <inheritdoc /> | ||
| public override bool UpdateFromPredecessor => true; | ||
|
|
||
| /// <inheritdoc /> | ||
| public override object Parse(IContainer container, IServiceProvider serviceProvider, string value) | ||
| { | ||
| var possibleTypes = GetPossibleValues(serviceProvider); | ||
| return possibleTypes.First(type => type.Name == value).Name; | ||
| } | ||
|
|
||
| private static IEnumerable<ResourceModel> GetPossibleValues(IServiceProvider serviceProvider) | ||
| { | ||
| return serviceProvider? | ||
| .GetService<IResourceManagement>()? | ||
| .GetResources<IMaintainableResource>() | ||
| .Select(x => x.ToDto()) | ||
| ?? []; | ||
| } | ||
| } |
164 changes: 164 additions & 0 deletions
164
src/Moryx.Maintenance.Endpoints/MaintenanceManagementController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Moryx.AbstractionLayer.Resources; | ||
| using Moryx.Maintenance.Endpoints.Dtos; | ||
| using Moryx.Maintenance.Endpoints.Services; | ||
| using Moryx.Maintenance.Exceptions; | ||
| using Moryx.Maintenance.Management.Models; | ||
| using Moryx.Runtime.Modules; | ||
| using Moryx.Serialization; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints; | ||
|
|
||
| /// <summary> | ||
| /// Definition of a REST API on the <see cref="IMaintenanceManagement"/> facade. | ||
| /// </summary> | ||
| [ApiController] | ||
| [Route("api/moryx/maintenances/")] | ||
| [Produces("application/json")] | ||
| public class MaintenanceManagementController( | ||
| IMaintenanceManagement maintenanceManagement, | ||
| IServiceProvider serviceProvider, | ||
| IModuleManager moduleManager, | ||
| IResourceManagement resourceManagement | ||
| ) : ControllerBase | ||
| { | ||
| private readonly MaintenanceService _maintenanceService = new(maintenanceManagement, serviceProvider, moduleManager, resourceManagement); | ||
|
|
||
| [HttpGet] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult<GetAllMaintenanceOrderResponse> GetAll() | ||
| { | ||
| return Response(() => new GetAllMaintenanceOrderResponse([.._maintenanceService.GetAll()])); | ||
| } | ||
|
|
||
| [HttpGet("{id:long}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult<Entry> Get(long id) | ||
| { | ||
| return Response(() => | ||
| { | ||
| return _maintenanceService.Get(id); | ||
| }); | ||
| } | ||
|
|
||
| [HttpGet("prototype")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult<Entry> Prototype() | ||
| { | ||
| return Response(_maintenanceService.Prototype); | ||
| } | ||
|
|
||
| [HttpPost("new")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult Add(Entry entry) | ||
| { | ||
| return Response(() => | ||
| { | ||
| _maintenanceService.Add(entry); | ||
| }); | ||
| } | ||
|
|
||
| [HttpPut("{id:long}")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult Update(long id, Entry entry) | ||
| { | ||
| return Response(() => | ||
| { | ||
| _maintenanceService.Update(id, entry); | ||
| }); | ||
| } | ||
|
|
||
| [HttpPut("{id:long}/acknowledge")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult Acknowledge(long id, Acknowledgement data) | ||
| { | ||
| return Response(() => | ||
| { | ||
| _maintenanceService.Acknowledge(id, data); | ||
| }); | ||
| } | ||
|
|
||
| [HttpPut("{id:long}/start")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult Start(long id) | ||
| { | ||
| return Response(() => | ||
| { | ||
| _maintenanceService.Start(id); | ||
| }); | ||
| } | ||
|
|
||
| [HttpDelete("{id:long}")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public ActionResult Delete(long id) | ||
| { | ||
| return Response(() => | ||
| { | ||
| _maintenanceService.Delete(id); | ||
| }); | ||
| } | ||
|
|
||
| [HttpGet("stream")] | ||
| [ProducesResponseType(typeof(MaintenanceOrderModel), StatusCodes.Status200OK)] | ||
| public async Task Stream(CancellationToken cancelToken) | ||
| { | ||
| await _maintenanceService.Stream(cancelToken, HttpContext); | ||
| } | ||
|
|
||
| private new ActionResult<TResult> Response<TResult>(Func<TResult> func, Func<TResult, ActionResult<TResult>>? onSuccess = null) | ||
| { | ||
| try | ||
| { | ||
| var result = func(); | ||
| return onSuccess != null | ||
| ? onSuccess(result) | ||
| : (ActionResult<TResult>)Ok(result); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return MapToResponse(ex); | ||
| } | ||
| } | ||
|
|
||
| private new ActionResult Response(Action action) | ||
| { | ||
| try | ||
| { | ||
| action(); | ||
| return Ok(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return MapToResponse(ex); | ||
| } | ||
| } | ||
|
|
||
| private ObjectResult MapToResponse(Exception ex) => ex switch | ||
| { | ||
| NotFoundException _ => NotFound(ex.Message), | ||
| ArgumentNullException _ => BadRequest(ex.Message), | ||
| ArgumentException _ => BadRequest(ex.Message), | ||
| KeyNotFoundException _ => StatusCode(500, ex.Message), | ||
| HealthStateException _ => StatusCode(500, ex.Message), | ||
| _ => StatusCode(500, ex.Message), | ||
| }; | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/Moryx.Maintenance.Endpoints/MaintenanceOrderSerialization.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using System.Reflection; | ||
| using Moryx.Configuration; | ||
| using Moryx.Container; | ||
| using Moryx.Serialization; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints; | ||
|
|
||
| internal sealed class MaintenanceOrderSerialization(IContainer container, IServiceProvider serviceProvider) | ||
| : PossibleValuesSerialization(container, serviceProvider, new ValueProviderExecutor(new ValueProviderExecutorSettings())) | ||
| { | ||
| ///// <summary> | ||
| ///// Instance for <see cref="EntrySerializeSerialization"/> we use to filter properties and methods | ||
| ///// </summary> | ||
| private readonly EntrySerializeSerialization _memberFilter = new(); | ||
|
|
||
| /// <summary> | ||
| /// Follow the rules for <see cref="EntrySerializeSerialization"/> | ||
| /// </summary> | ||
| public override IEnumerable<PropertyInfo> GetProperties(Type sourceType) | ||
| { | ||
| return _memberFilter.GetProperties(sourceType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Follow the rules for <see cref="EntrySerializeSerialization"/> | ||
| /// </summary> | ||
| public override IEnumerable<MethodInfo> GetMethods(Type sourceType) | ||
| { | ||
| return _memberFilter.GetMethods(sourceType); | ||
| } | ||
|
|
||
| public override IEnumerable<MappedProperty> WriteFilter(Type sourceType, IEnumerable<Entry> encoded) | ||
| { | ||
| return _memberFilter.WriteFilter(sourceType, encoded); | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) 2025, Phoenix Contact GmbH & Co. KG | ||
| // Licensed under the Apache License, Version 2.0 | ||
| using Moryx.Maintenance.Management.Models; | ||
|
|
||
| namespace Moryx.Maintenance.Endpoints.Mappers; | ||
| internal static class ResourceMapper | ||
| { | ||
| public static ResourceModel ToDto(this IMaintainableResource resource) | ||
| => new ResourceModel(resource.Id, resource.Name); | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/Moryx.Maintenance.Endpoints/Moryx.Maintenance.Endpoints.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
MathoMathiasCamara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| <Description>Moryx.Maintenance.Endpoints</Description> | ||
MathoMathiasCamara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <IsPackable>true</IsPackable> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
MathoMathiasCamara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Moryx.Maintenance.Management\Moryx.Maintenance.Management.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.