Skip to content

Commit

Permalink
server: remove set unarchived from api
Browse files Browse the repository at this point in the history
Remove set workorders from network api, anything should come through simulation

Also, add allocation warnings to NewJobs
  • Loading branch information
wuzzeb committed Jul 25, 2024
1 parent f0fbe50 commit 768be28
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 147 deletions.
80 changes: 3 additions & 77 deletions client/csharp-api/api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,83 +2211,6 @@ public virtual async System.Threading.Tasks.Task BulkRemoveMaterialFromQueuesAsy
}
}

/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task SetUnarchivedWorkordersAsync(System.Collections.Generic.IEnumerable<Workorder> workorders)
{
return SetUnarchivedWorkordersAsync(workorders, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task SetUnarchivedWorkordersAsync(System.Collections.Generic.IEnumerable<Workorder> workorders, System.Threading.CancellationToken cancellationToken)
{
if (workorders == null)
throw new System.ArgumentNullException("workorders");

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(workorders, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("PUT");

var urlBuilder_ = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
// Operation Path: "api/v1/jobs/workorders"
urlBuilder_.Append("api/v1/jobs/workorders");

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
foreach (var item_ in response_.Headers)
headers_[item_.Key] = item_.Value;
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
return;
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

protected struct ObjectResponseResult<T>
{
public ObjectResponseResult(T responseObject, string responseText)
Expand Down Expand Up @@ -5044,6 +4967,9 @@ public partial class NewJobs
[Newtonsoft.Json.JsonProperty("Programs", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<NewProgramContent> Programs { get; set; }

[Newtonsoft.Json.JsonProperty("AllocationWarning", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<string> AllocationWarning { get; set; }

[Newtonsoft.Json.JsonProperty("DebugMessage", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public byte[] DebugMessage { get; set; }

Expand Down
46 changes: 12 additions & 34 deletions client/insight/src/network/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,40 +967,6 @@ export class JobsClient {
}
return Promise.resolve<JobAndDecrementQuantity[]>(null as any);
}

setUnarchivedWorkorders(workorders: Workorder[]): Promise<void> {
let url_ = this.baseUrl + "/api/v1/jobs/workorders";
url_ = url_.replace(/[?&]$/, "");

const content_ = JSON.stringify(workorders);

let options_: RequestInit = {
body: content_,
method: "PUT",
headers: {
"Content-Type": "application/json",
}
};

return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processSetUnarchivedWorkorders(_response);
});
}

protected processSetUnarchivedWorkorders(response: Response): Promise<void> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
return;
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<void>(null as any);
}
}

export class LogClient {
Expand Down Expand Up @@ -2622,6 +2588,7 @@ export class NewJobs implements INewJobs {
simWorkordersFilled?: WorkorderSimFilled[] | undefined;
currentUnfilledWorkorders?: Workorder[] | undefined;
programs?: NewProgramContent[] | undefined;
allocationWarning?: string[] | undefined;
debugMessage?: string | undefined;

constructor(data?: INewJobs) {
Expand Down Expand Up @@ -2681,6 +2648,11 @@ export class NewJobs implements INewJobs {
for (let item of _data["Programs"])
this.programs!.push(NewProgramContent.fromJS(item));
}
if (Array.isArray(_data["AllocationWarning"])) {
this.allocationWarning = [] as any;
for (let item of _data["AllocationWarning"])
this.allocationWarning!.push(item);
}
this.debugMessage = _data["DebugMessage"];
}
}
Expand Down Expand Up @@ -2737,6 +2709,11 @@ export class NewJobs implements INewJobs {
for (let item of this.programs)
data["Programs"].push(item.toJSON());
}
if (Array.isArray(this.allocationWarning)) {
data["AllocationWarning"] = [];
for (let item of this.allocationWarning)
data["AllocationWarning"].push(item);
}
data["DebugMessage"] = this.debugMessage;
return data;
}
Expand All @@ -2752,6 +2729,7 @@ export interface INewJobs {
simWorkordersFilled?: WorkorderSimFilled[] | undefined;
currentUnfilledWorkorders?: Workorder[] | undefined;
programs?: NewProgramContent[] | undefined;
allocationWarning?: string[] | undefined;
debugMessage?: string | undefined;
}

Expand Down
35 changes: 7 additions & 28 deletions server/fms-insight-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1011,34 +1011,6 @@
}
}
},
"/api/v1/jobs/workorders": {
"put": {
"tags": [
"Jobs"
],
"operationId": "Jobs_SetUnarchivedWorkorders",
"requestBody": {
"x-name": "workorders",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Workorder"
}
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/log/events/all": {
"get": {
"tags": [
Expand Down Expand Up @@ -2500,6 +2472,13 @@
"$ref": "#/components/schemas/NewProgramContent"
}
},
"AllocationWarning": {
"type": "array",
"nullable": true,
"items": {
"type": "string"
}
},
"DebugMessage": {
"type": "string",
"format": "byte",
Expand Down
2 changes: 2 additions & 0 deletions server/lib/BlackMaple.MachineFramework/api/NewJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public record NewJobs

public ImmutableList<NewProgramContent>? Programs { get; init; }

public ImmutableList<string>? AllocationWarning { get; init; }

public byte[]? DebugMessage { get; init; }
}
}
2 changes: 2 additions & 0 deletions server/lib/BlackMaple.MachineFramework/db/JobDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ IEnumerable<WorkorderSimFilled> simFilled
}
}

// This is a last resort, because normally updating workorders should also include a
// new simulation. Otherwise, the simulated start and filled will be incorrect.
public void UpdateCachedWorkorders(IEnumerable<Workorder> workorders)
{
lock (_cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,5 @@ public List<JobAndDecrementQuantity> DecrementQuantities(
"Must specify either loadDecrementsStrictlyAfterDecrementId or loadDecrementsAfterTimeUTC"
);
}

[HttpPut("workorders")]
public void SetUnarchivedWorkorders([FromBody] List<Workorder> workorders)
{
using var db = repo.OpenConnection();
db.UpdateCachedWorkorders(workorders);
jobAndQueue.RecalculateCellState();
}
}
}

0 comments on commit 768be28

Please sign in to comment.