Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Frends.IbmMaximo.Request/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [2.0.0] - 2026-07-23

### Changed
- The task now targets .NET 8.
- Added an **Options** parameter to the main Request task, allowing you to control error handling behaviour: choose whether errors should throw an exception or be returned as a result with `Success = false`, and optionally set a custom error message.

## [1.1.0] - 2024-06-28

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public async Task BasicTest()
Method = HttpMethod.GET
};

var result = await IbmMaximo.Request(input, CancellationToken.None);
var options = new Options { ThrowErrorOnFailure = true };

var result = await IbmMaximo.Request(input, options, CancellationToken.None);
Assert.IsTrue(result.Success);
Assert.IsNotNull(result.Response);
Assert.AreEqual((string)result.Response.hello, "world");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Input
/// <summary>
/// Select request type to show correct editor for input.
/// </summary>
/// <example>CustomRequest</example>
public RequestTypeChoose RequestType { get; set; }

/// <summary>
Expand Down Expand Up @@ -105,72 +106,84 @@ public class Input
/// <summary>
/// Description for the new work order.
/// </summary>
/// <example>Fix HVAC system</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string WorkOrderDescription { get; set; }

/// <summary>
/// Description for the service request.
/// </summary>
/// <example>Request for office equipment</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GenerateServiceRequest, RequestTypeChoose.UpdateServiceRequest)]
public string ServiceRequestDescription { get; set; }

/// <summary>
/// The person who reported the issue.
/// </summary>
/// <example>john.doe</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GenerateServiceRequest, RequestTypeChoose.UpdateServiceRequest)]
public string ReportedBy { get; set; }

/// <summary>
/// Location for new work order.
/// </summary>
/// <example>PLANT1</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string WorkOrderLocation { get; set; }

/// <summary>
/// Identifies the ticket's location.
/// </summary>
/// <example>OFFICE1</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GenerateServiceRequest, RequestTypeChoose.UpdateServiceRequest)]
public string ServiceRequestLocation { get; set; }

/// <summary>
/// Asset number associated with the work order.
/// </summary>
/// <example>ASSET001</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string WorkOrderAssetNum { get; set; }

/// <summary>
/// Asset number associated with the service request.
/// </summary>
/// <example>ASSET002</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GenerateServiceRequest, RequestTypeChoose.UpdateServiceRequest)]
public string ServiceRequestAssetNum { get; set; }

/// <summary>
/// Site associated with the work order.
/// </summary>
/// <example>BEDFORD</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string Site { get; set; }

/// <summary>
/// Scheduled start time for the work order.
/// </summary>
/// <example>2024-01-01T08:00:00Z</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string ScheduledStart { get; set; }

/// <summary>
/// Reported date for the breakdown work order.
/// </summary>
/// <example>2024-01-01T00:00:00Z</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.CreateWorkOrder, RequestTypeChoose.UpdateWorkOrder)]
public string ReportedDate { get; set; }

/// <summary>
/// Reported date for the breakdown work order.
/// </summary>
/// <example>12345</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GetWorkOrder, RequestTypeChoose.UpdateWorkOrder, RequestTypeChoose.DeleteWorkOrder)]
public string WorkOrderId { get; set; }

/// <summary>
/// Reported date for the breakdown work order.
/// </summary>
/// <example>67890</example>
[UIHint(nameof(RequestType), "", RequestTypeChoose.GetServiceRequest, RequestTypeChoose.UpdateServiceRequest, RequestTypeChoose.DeleteServiceRequest)]
public string ServiceRequestId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Frends.IbmMaximo.Request.Definitions;

/// <summary>
/// Options parameters.
/// </summary>
public class Options
{
/// <summary>
/// Whether to throw an exception on failure or return a result with Success = false.
/// </summary>
/// <example>true</example>
[DefaultValue(true)]
public bool ThrowErrorOnFailure { get; set; } = true;

/// <summary>
/// Custom error message to use when an error occurs. If empty, the exception message is used.
/// </summary>
/// <example>IBM Maximo request failed</example>
[DisplayFormat(DataFormatString = "Text")]
[DefaultValue("")]
public string ErrorMessageOnFailure { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<authors>Frends</authors>
<Company>Frends</Company>
<Product>Frends</Product>
<copyright>Frends</copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/FrendsPlatform/Frends.IBMMaximo</PackageProjectUrl>
<PackageProjectUrl>https://frends.com/</PackageProjectUrl>
<IncludeSource>true</IncludeSource>
<PackageTags>Frends</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.1.0</Version>
<Version>2.0.0</Version>
<Description>Task for making an IBM Maximo request.</Description>
</PropertyGroup>

Expand Down
66 changes: 45 additions & 21 deletions Frends.IbmMaximo.Request/Frends.IbmMaximo.Request/IbmMaximo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,58 @@ public static class IbmMaximo
/// [Documentation](https://tasks.frends.com/tasks/frends-tasks/Frends.IbmMaximo.Request)
/// </summary>
/// <param name="input">Input parameters.</param>
/// <param name="options">Options parameters.</param>
/// <param name="cancellationToken">Frends cancellation token.</param>
/// <returns>Object { bool Success, string Error, dynamic Response }</returns>
public static async Task<Result> Request(
[PropertyTab] Input input,
[PropertyTab] Options options,
CancellationToken cancellationToken)
{
switch (input.RequestType)
try
{
case RequestTypeChoose.CustomRequest:
return await CustomRequest(input, cancellationToken);
case RequestTypeChoose.CreateWorkOrder:
return await CreateWorkOrder(input, cancellationToken);
case RequestTypeChoose.GenerateServiceRequest:
return await GenerateServiceRequest(input, cancellationToken);
case RequestTypeChoose.GetWorkOrder:
return await GetWorkOrder(input, cancellationToken);
case RequestTypeChoose.UpdateWorkOrder:
return await UpdateWorkOrder(input, cancellationToken);
case RequestTypeChoose.DeleteWorkOrder:
return await DeleteWorkOrder(input, cancellationToken);
case RequestTypeChoose.GetServiceRequest:
return await GetServiceRequest(input, cancellationToken);
case RequestTypeChoose.UpdateServiceRequest:
return await UpdateServiceRequest(input, cancellationToken);
case RequestTypeChoose.DeleteServiceRequest:
return await DeleteServiceRequest(input, cancellationToken);
default:
return new Result(false, null, $"Unsupported request type: {input.RequestType}");
switch (input.RequestType)
{
case RequestTypeChoose.CustomRequest:
return await CustomRequest(input, cancellationToken);
case RequestTypeChoose.CreateWorkOrder:
return await CreateWorkOrder(input, cancellationToken);
case RequestTypeChoose.GenerateServiceRequest:
return await GenerateServiceRequest(input, cancellationToken);
case RequestTypeChoose.GetWorkOrder:
return await GetWorkOrder(input, cancellationToken);
case RequestTypeChoose.UpdateWorkOrder:
return await UpdateWorkOrder(input, cancellationToken);
case RequestTypeChoose.DeleteWorkOrder:
return await DeleteWorkOrder(input, cancellationToken);
case RequestTypeChoose.GetServiceRequest:
return await GetServiceRequest(input, cancellationToken);
case RequestTypeChoose.UpdateServiceRequest:
return await UpdateServiceRequest(input, cancellationToken);
case RequestTypeChoose.DeleteServiceRequest:
return await DeleteServiceRequest(input, cancellationToken);
default:
return new Result(false, null, $"Unsupported request type: {input.RequestType}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
if (options.ThrowErrorOnFailure)
{
var message = string.IsNullOrEmpty(options.ErrorMessageOnFailure)
? ex.Message
: options.ErrorMessageOnFailure;
throw new Exception(message, ex);
}

var errorMessage = string.IsNullOrEmpty(options.ErrorMessageOnFailure)
? ex.Message
: $"{options.ErrorMessageOnFailure}: {ex.Message}";
return new Result(false, null, errorMessage);
}
}

Expand Down
Loading