question

ondrej avatar image
ondrej asked mmercurio commented

Is tender creation asynchronous ?

Hi,

if in an AsyncTask I execute:

protected List<Tender> doInBackground(....{
    tenderConnector.checkAndCreateTender("MyTender",getPackageName(), true, false);
    tenders = tenderConnector.getTenders();
}

Then the tenders list does not contain the just created "MyTender". However the custom tender is present when the I do get tenders from the web API. The getTenders call returns the new tender if it is executed about 2 seconds later. Is it normal situation? I did not encountered (also I did not searched for) such a problem with the OrderConnector for example.

Please correct me if my assumptions are wrong. I thought that checkAndCreateTender is a blocking call.

Note: This is currently on an emulator, I did not test it on the Devkit yet.

Thank you, Ondrej

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

jim-patel avatar image
jim-patel answered mmercurio commented

Yes, it is asynchronous. An example of using the TenderConnector.TenderCallback to handle this can be found in the examples on github here. The relevant function:

  private void createTender() {
final String tenderName = "Clover Example Tender";
final String packageName = getPackageName();

tenderConnector.checkAndCreateTender(tenderName, packageName, true, false, new TenderConnector.TenderCallback<Tender>() {
  @Override
  public void onServiceSuccess(Tender result, ResultStatus status) {
    super.onServiceSuccess(result, status);
    String text = "Custom Tender:\n";
    text += "  " + result.getId() + " , " + result.getLabel() + " , " + result.getLabelKey() + " , " + result.getEnabled() + " , " + result.getOpensCashDrawer() + "\n";
    resultText.setText(text);
  }

  @Override
  public void onServiceFailure(ResultStatus status) {
    super.onServiceFailure(status);
    resultText.setText(status.getStatusMessage());
  }

  @Override
  public void onServiceConnectionFailure() {
    super.onServiceConnectionFailure();
    resultText.setText("Service Connection Failure");
  }
});

}

3 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ondrej avatar image ondrej commented ·

Thank you for the example,

I have tried it, but anyways:

  1. creating a tender using a callback listener
  2. getting the tenders using a callback listener from the onServiceSuccess method from the point 1. does not resolve the problem of 'new tender not YET present in the list'.

I still have to use a workaround using an AsyncTask and waiting in a loop until the tender appears.

Regads, Ondrej

0 Likes 0 ·
Mike M avatar image Mike M commented ·

Why not just use the Tender result object from the method callback: onServiceSuccess(Tender result, ResultStatus status)?

The tender is likely still being written to the device's sql database, so calling getTenders will need to happen after that has succeeded, which explains the couple seconds delay you mentioned. So that being said, please use the result object mentioned above.

Also, many thanks @Jim Patel for the thorough answer!

0 Likes 0 ·
mmercurio avatar image mmercurio commented ·

Hi @mike, can the checkAndCreateTender method be used to first check to see if a custom tender with the same label and labelKey already exists?

What I'm looking for is a way to first check to see if the custom tender exists and if not, create it. More specifically, what does checkAndCreateTender do if there is already a custom tender created for my app with the same label and labelKey? Thanks!

0 Likes 0 ·

Welcome to the
Clover Developer Community