Skip to content
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

feat: new config to continue batch processing on errors #441

Merged
merged 2 commits into from
Dec 21, 2023
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
10 changes: 10 additions & 0 deletions docs/pages/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ These options are available and explained in detail below:
| `useTableSelector` | Open a Table Selector dialog if multiple tables in view | boolean |
| `spreadsheetRowPropertyName` | If you want to sent the spreadsheet row to the backend | string |
| `componentContainerData` | Open a Table Selector dialog if multiple tables in view | boolean |
| `continueOnError` | If a error occurs in batch processing, continue | boolean |
| `debug` | Option to show more console statements and set Log Level to Debug | boolean |

### `columns`
Expand Down Expand Up @@ -431,6 +432,15 @@ settings="{
}" />
````

### `continueOnError`

**default:** `false`

This option defines whether the batch processing should continue if a error occurs.
If you have for example set `batchSize`to 2 and have 4 rows and a error occurs in the first batch of two rows, the processing will stop. If you set this flag to `true` the processing will continue and the second batch of two rows will be processed.
This may lead to errors in the backend, because the first batch of two rows was not processed correctly.
Use this option with caution.


### `debug`

Expand Down
5 changes: 5 additions & 0 deletions packages/ui5-cc-spreadsheetimporter/src/Component.gen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare module "./Component" {
readAllSheets?: boolean | PropertyBindingInfo | `{${string}}`;
readSheet?: any | PropertyBindingInfo | `{${string}}`;
spreadsheetRowPropertyName?: string | PropertyBindingInfo;
continueOnError?: boolean | PropertyBindingInfo | `{${string}}`;
debug?: boolean | PropertyBindingInfo | `{${string}}`;
componentContainerData?: object | PropertyBindingInfo | `{${string}}`;
checkBeforeRead?: (event: Component$CheckBeforeReadEvent) => void;
Expand Down Expand Up @@ -143,6 +144,10 @@ declare module "./Component" {
getSpreadsheetRowPropertyName(): string;
setSpreadsheetRowPropertyName(spreadsheetRowPropertyName: string): this;

// property: continueOnError
getContinueOnError(): boolean;
setContinueOnError(continueOnError: boolean): this;

// property: debug
getDebug(): boolean;
setDebug(debug: boolean): this;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui5-cc-spreadsheetimporter/src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class Component extends UIComponent {
readAllSheets: { type: "boolean", defaultValue: false },
readSheet: { type: "any", defaultValue: 0 },
spreadsheetRowPropertyName: { type: "string" },
continueOnError: { type: "boolean", defaultValue: false },
debug: { type: "boolean", defaultValue: false },
componentContainerData: { type: "object" }
//Pro Configurations
Expand Down Expand Up @@ -134,6 +135,7 @@ export default class Component extends UIComponent {
this.setUseTableSelector(oCompData?.useTableSelector);
this.setHideSampleData(oCompData?.hideSampleData);
this.setComponentContainerData(oCompData?.componentContainerData);
this.setContinueOnError(oCompData?.continueOnError);
if (oCompData?.availableOptions && oCompData?.availableOptions.length > 0) {
// if availableOptions is set show the Options Menu
this.setShowOptions(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export default class SpreadsheetUpload extends ManagedObject {
if (options.hasOwnProperty("readSheet")) {
this.component.setReadSheet(options.readSheet);
}
if (options.hasOwnProperty("continueOnError")) {
this.component.setContinueOnError(options.continueOnError);
}

// Special case for showOptions
if (options.availableOptions && options.availableOptions.length > 0) {
Expand Down
63 changes: 36 additions & 27 deletions packages/ui5-cc-spreadsheetimporter/src/controller/odata/OData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,45 @@ export default abstract class OData extends ManagedObject {
// Loop over the sliced array
for (const batch of slicedPayloadArray) {
// loop over data from spreadsheet file
for (const payload of batch) {
// Extension method to manipulate payload
try {
await Util.fireEventAsync("changeBeforeCreate", { payload: payload }, component);
} catch (error) {
Log.error("Error while calling the changeBeforeCreate event", error as Error, "SpreadsheetUpload: callOdata");
try {
for (const payload of batch) {
// Extension method to manipulate payload
try {
await Util.fireEventAsync("changeBeforeCreate", { payload: payload }, component);
} catch (error) {
Log.error("Error while calling the changeBeforeCreate event", error as Error, "SpreadsheetUpload: callOdata");
}
this.createAsync(model, binding, payload);
}
// wait for all drafts to be created
await this.submitChanges(model);
let errorsFoundLocal = await this.checkForErrors(model, binding, component.getShowBackendErrorMessages());
if (errorsFoundLocal) {
this.busyDialog.close();
spreadsheetUploadController.errorsFound = true;
break;
} else {
await this.waitForCreation();
}
this.createAsync(model, binding, payload);
}
// wait for all drafts to be created
await this.submitChanges(model);
let errorsFoundLocal = await this.checkForErrors(model, binding, component.getShowBackendErrorMessages());
if (errorsFoundLocal) {
this.busyDialog.close();
spreadsheetUploadController.errorsFound = true;
break;
} else {
await this.waitForCreation();
}

// check for and activate all drafts and wait for all draft to be created
if (component.getActivateDraft() && !errorsFoundLocal) {
await this.waitForDraft();
}
// check for and activate all drafts and wait for all draft to be created
if (component.getActivateDraft() && !errorsFoundLocal) {
await this.waitForDraft();
}

this.resetContexts();
currentProgressPercent = currentProgressPercent + (batch.length / payloadArray.length) * 100;
currentProgressValue = currentProgressValue + batch.length;
(this.busyDialog.getModel("busyModel") as JSONModel).setProperty("/progressPercent", currentProgressPercent);
(this.busyDialog.getModel("busyModel") as JSONModel).setProperty("/progressText", `${currentProgressValue} / ${payloadArray.length}`);
this.resetContexts();
currentProgressPercent = currentProgressPercent + (batch.length / payloadArray.length) * 100;
currentProgressValue = currentProgressValue + batch.length;
(this.busyDialog.getModel("busyModel") as JSONModel).setProperty("/progressPercent", currentProgressPercent);
(this.busyDialog.getModel("busyModel") as JSONModel).setProperty("/progressText", `${currentProgressValue} / ${payloadArray.length}`);
} catch (error) {
if (component.getContinueOnError()) {
Log.error("Error while calling the odata service", error as Error, "SpreadsheetUpload: callOdata");
} else {
// throw error to stop processing
throw error;
}
}
}
spreadsheetUploadController.refreshBinding(context, binding, tableObject.getId());
this.busyDialog.close();
Expand Down
1 change: 1 addition & 0 deletions packages/ui5-cc-spreadsheetimporter/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface ComponentData {
spreadsheetTemplateFile?: string;
useTableSelector?: boolean;
sampleData?: object;
continueOnError?: boolean;
}

// Pro Types
Loading