Search code examples
s4sdk

unable to perform Delete operation on Odata services using s4sdk


I followed the blog & I was able to perform create, read & update operations on my custom OData service, but I am unable to find any blog/document for delete operation. Please help.


Solution

  • There is no dedicated blog post for executing delete operations on custom OData Services but we would advise you to follow this pattern:

    public class DeleteAddressCommand extends ErpCommand<Integer> {
        private static final Logger logger = CloudLoggerFactory.getLogger(DeleteAddressCommand.class);
    
        private final BusinessPartnerService service;
        private final String businessPartnerId;
        private final String addressId;
    
        public DeleteAddressCommand(final BusinessPartnerService service,
                                    final String businessPartnerId, final String addressId) {
            super(HystrixUtil.getDefaultErpCommandSetter(
                    DeleteAddressCommand.class,
                    HystrixUtil.getDefaultErpCommandProperties().withExecutionTimeoutInMilliseconds(10000)));
    
            this.service = service;
            this.businessPartnerId = businessPartnerId;
            this.addressId = addressId;
        }
    
        @Override
        protected Integer run() throws Exception {
            final BusinessPartnerAddress addressToDelete = BusinessPartnerAddress.builder()
                    .businessPartner(businessPartnerId)
                    .addressID(addressId)
                    .build();
    
            final ODataDeleteResult oDataDeleteResult = service
                    .deleteBusinessPartnerAddress(addressToDelete)
                    .execute();
    
            return oDataDeleteResult.getHttpStatusCode();
        }
    }
    

    I pasted the code from this official example

    Best wishes Florian