cap-js / change-tracking

CDS plugin providing out-of-the box support for automatic capturing, storing, and viewing of the change records of modeled entities.
https://cap.cloud.sap/docs
Apache License 2.0
20 stars 8 forks source link

Questions about Object ID definition #69

Open 032660 opened 7 months ago

032660 commented 7 months ago

Hi colleagues, There was a discussion whether direct DB operations (not via services) should be also considered in the change tracking. Finally a decision was made that a service was necessary. We created such dummy-services like for example

service PaymentWrapperService @(requires: 'system-user') { entity Payments as projection on db.payments.Payments; entity Payables as projection on db.payables.Payables; entity PaymentOrders as projection on db.paymentOrders.PaymentOrders; entity Receivables as projection on db.receivables.Receivables; entity BusinessTransactions as projection on db.businessTransactions.BusinessTransactions; }

And all INSERT/UPDATE operations are now fulfilled via this service like:

INSERT([paymentToInsert]).into(PaymentWrapperService.Entity.Payments)

This works. Moreover, entity BusinessTransactions is a view defined as union of 3 other entities: Payments, Payables and Receivables. But on the UI based on BusinessTransactions the change history of Payment or other entities is shown – this is if course very good. However some things do not work as expected. All three entities Payments, Payables and Receivables in the view BusinessTransactions have a field displayId. For Payables and Receivables it was possible to define Changelog as @changelog: [displayId]

However for Payments it is not possible (then npm run build would bring an error saying that dependencies exist). It is only possible to define it as @changelog.ObjectID: [displayId]

But then EntityID on the Changes DB table remains empty and “Payment” is shown as Object ID . I tried @changelog.entityID: [displayId]

But it does not make any difference. Even in the DB table SAP_CHANGELOG_CHANGES Entity ID is empty.

I suppose that this is happening because the entity Payments has associations to other entities (Payments and PaymentOrders) having changelogs with the same entityID “displayId”: Type : Association to one codelists.PaymentTypeCodes; Direction : Association to one PaymentDirectionCodes; displayId : String; //readable ID Company : Association to one Companies; BusinessPartner : Association to one BusinessPartners; PaymentOrder : Association to one PaymentOrders; Wallet : Association to one wallets.Wallets; Transaction : Association to one wallets.Transactions; cryptoAmount : Decimal; CryptoAmountCurrency : Association to one Cryptocurrencies;

@changelog
fiatAmount               : Decimal; //Call reuse service to round due to allowed number of digits wherever necessary
FiatAmountCurrency       : Association to one FiatCurrencies;

@changelog
paymentExecutionDateTime : DateTime; //TimeStamp is not used here because we do not need 0,1 microsecond precision (sec precision is enough)

@title    : '{i18n>Status}'
@changelog: [LifecycleStatus.code]
LifecycleStatus          : Association to one codelists.PaymentLifecycleStatusCodes;

Fee                      : Association to one Payments;

Am I right? Does not it work when one entity is associated with another one with the same changelog Entity ID? How should we define ObjectID in this case?

One more question: if we are showing an amount in the change log, how can we add currency to it? Is it possible? I mean not just showing “5.5” but “5.5 USD”.

I am attaching an example from UI.

ChangeLog

Thank you and kind regards, Elena Gurevitch

JocelynGu135 commented 7 months ago

HI @032660 ,

Could you provide the git repo and the detail steps how to reproduce this issue? Thanks a lot.

Best Regards Jocelyn

JocelynGu135 commented 7 months ago

Hi @032660 ,

From your description I found now using @changelog.ObjectID to specify objectID, and using changelog.entityID to specify entityID. It is only possible to define it as @changelog.ObjectID: [displayId]

But then EntityID on the Changes DB table remains empty and “Payment” is shown as Object ID . I tried @changelog.entityID: [displayId]

But this is not the correct way to use it. You can find how to define the Object ID in the following link. And the entity ID cannot be specified.

Best Regards Jocelyn

032660 commented 7 months ago

Hi Jocelyn,

I know that correct would be @changelog: [displayId].

But if I do so and try to build I am getting an error: Error: HDI deployment failed with exit code 1 at HdiDeployUtil.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\lib\deploy\to-hana\hdiDeployUtil.js:46:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async HanaDeployer.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\lib\deploy\to-hana\hana.js:103:9)
at async Object.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\bin\deploy\index.js:129:5) at async Object.exec (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\bin\cds.js:54:16)

And the only specisl thing for this entity Payments that it has an association to the same entity Payments - that is why I thought it could be the reason.

Kind regards, Elena

JocelynGu135 commented 7 months ago

Hi @032660 ,

Because there is no reproducible environment from your side, so I can only try to reproduce it locally in my project. Payment.cds

image

Payable.cds

image

BusinessTransactions.cds

image

then execute "npm run build", but no error message in terminal.

Are there any missing steps to reproduce this issue?

Best Regards Jocelyn

032660 commented 7 months ago

Hi Jocelyn,

Thank you! Special in the entity Payments is that it has association to the same entity:

Fee : Association to one Payments;

And it has associations to other entities declared to use the changelog: Payment Orders and Business Partners.


entity Payments : cuid, managed { Type : Association to one codelists.PaymentTypeCodes; Direction : Association to one PaymentDirectionCodes; displayId : String; //readable ID Company : Association to one Companies; BusinessPartner : Association to one BusinessPartners; PaymentOrder : Association to one PaymentOrders; Wallet : Association to one wallets.Wallets; Transaction : Association to one wallets.Transactions;

@title    : '{i18n>CryptoAmountChangelog}'
@changelog
cryptoAmount             : Decimal;

CryptoAmountCurrency     : Association to one Cryptocurrencies;

@title    : '{i18n>FiatAmountChangelog}'
@changelog
fiatAmount               : Decimal; //Call reuse service to round due to allowed number of digits wherever necessary

FiatAmountCurrency       : Association to one FiatCurrencies;

@title    : '{i18n>PaymentExecutionDateTime}'
@changelog
paymentExecutionDateTime : DateTime; //TimeStamp is not used here because we do not need 0,1 microsecond precision (sec precision is enough)

@title    : '{i18n>Status}'
@changelog: [LifecycleStatus.name]
LifecycleStatus          : Association to one codelists.PaymentLifecycleStatusCodes;

**Fee                      : Association to one Payments;**

@title    : '{i18n>NetworkFee}'
@changelog
feeDisplayId             : String;

Network                  : Association to one Networks;
Account                  : Association to one Accounts;
ExchangeRate             : Association to one ExchangeRates;
PaymentAgreementOutgoing : Association to one PaymentAgreementsOutgoing;
PaymentAgreementIncoming : Association to one PaymentAgreementsIncoming;

};


Kind regards, Elena

JocelynGu135 commented 7 months ago

Hi @032660 ,

According your comment, I add two new attribute "BusinessPartner" & "PaymentOrder", "Fee" is already in Payments entity. And both "BusinessPartners" and "PaymentOrders" other are declared to use the changelog, then object ID are defined as displayId.

image

But still no error when execute "npm run build".

Here is the git repo which I want to reproduce this issue: https://github.tools.sap/ROCKETS/simple-bookshop/tree/fix/issue%2369.

Best Regards Jocelyn

032660 commented 7 months ago

Hi Jocelyn,

I am sorry not to have explained what we are executing.

It is not "npm run build" but "npm run cds2types && npm run deploy && npm run testdata:deploy-main" and I am not sure you can execute this in your branch. When I am executing the script (which has name "npm run build:dev" - that is why I provided wrong information) then I must log on with the SAP user.

And I am getting the error on

Error: HDI deployment failed with exit code 1 at HdiDeployUtil.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\lib\deploy\to-hana\hdiDeployUtil.js:46:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async HanaDeployer.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\lib\deploy\to-hana\hana.js:103:9) at async Object.deploy (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\bin\deploy\index.js:129:5) at async Object.exec (C:\Users\D032660\github\C4B\crypto-for-business\node_modules\@sap\cds-dk\bin\cds.js:54:16)

Command failed: npx cds deploy --to hana:D032660 --store-credentials --auto-undeploy

So npx cds deploy seems to be an issue.

Kind regards, Elena

032660 commented 7 months ago

P.S. I created a branch where it can be tested: https://github.tools.sap/erp4sme/crypto-for-business/tree/paymentChangelog.

And on https://github.tools.sap/erp4sme/crypto-for-business/tree/main it is described what is necessary to work on our project.

But you can see: you must then request some access rights and so on. I wouldn't like to make you doing all that efforts.

May be you should just try "deploy" in your branch?

Kind regards, Elena

JocelynGu135 commented 7 months ago

Hi @032660 ,

I try to run the project in my local, when execute npm run build:dev, also met the error message like follow.

image

Is this error the same as what you encountered? In these error messages, I did not see anything related to change tracking or payment entity.

In addition, when I switch to main branch and execute npm run build:dev, also get the similar error message. Whether in main branch also contains the same change tracking feature as paymentChangelog branch?

Best Regards Jocelyn

032660 commented 7 months ago

Hi Jocelyn,

I am getting only the error below on your screenshot and only if I define changelog for Payments as @changelog: [displayId] in db\payment\payments\Payments.cds.

If I use @changelog.ObjectID: [displayId] (which however does not have any affect) then there is no any error during npm run build:dev.

Concerning the error you are getting: you can just remove all the entries from the table "...ACCOUNTS_ACCOUNTS" for your local HDI container. This should help.

Kind regards, Elena