microsoft / Partner-Center-Java

Partner Center SDK for Java
https://docs.microsoft.com/java/partnercenter/
31 stars 12 forks source link

Fetching AuditLog by CompanyID #106

Closed vikasbo closed 4 years ago

vikasbo commented 4 years ago

Try fetching AuditLogs for customer, results in a runtime exception:

Steps to reproduce

Use the code to the affect

SimpleFieldFilter filter = new SimpleFieldFilter(AuditRecordSearchField.CUSTOMER_ID.toString(),
FieldFilterOperation.EQUALS, customer.getId());
try {
DateTime startDate = new DateTime(new Date()).withDayOfMonth(1);
DateTime endDate = new DateTime(new Date()).plusDays(1);
System.out.println(String.format("Fetching audit logs for dates = %s and %s", startDate, endDate));
SeekBasedResourceCollection<AuditRecord> auditRecordsPage = partnerOperations.getAuditRecords().query(startDate,
endDate, QueryFactory.getInstance().buildSimpleQuery(filter));

Expected behavior

Expected to initialize and then iterate via the code below: for (AuditRecord auditRecord : auditRecordsPage.getItems()) {

But fails to initialize lazy collection SeekBasedResourceCollection<AuditRecord> auditRecordsPage.

Share the expected output

Actual behavior

What is the behavior observed?

Apparently, using the Java API, the API expects DateTime but throws exception asking date to be entered in YYYY-MM-DD.

This is the reason error is not clear. DateTime stores dates internally, and the API does not accept string, so how do we send the Date in YYYY-MM-DD format.

Diagnostic logs

See below:

Error/Stacktrace below.

| Server running. Browse to http://localhost:8080/webdata customer.getCompanyProfile().getCompanyName() = ABC Associates Fetching audit logs for dates = 2020-02-01T00:00:00.000+05:30 and 2020-02-04T00:00:00.000+05:30 Default logger ERROR: Partner service failed response:{ "message": "The given date '2020-02-01T00:00:00.000 05:30' was not recognized as a valid DateTime. Please enter in 'YYYY-MM-DD' format." } | Error PartnerException: ErrorCategory: BAD_INPUT, ServiceErrorPayload: Error code: null Error message: null com.microsoft.store.partnercenter.models.ApiFault@599b0148 , Context: Request Id: 9f0ebc85-a415-4073-b801-0ab9c0888886, Correlation Id: en-US, Locale: {2}00000000-0000-0000-0000-000000000000, Base Description: com.microsoft.store.partnercenter.exception.PartnerException | Error at com.microsoft.store.partnercenter.errorhandling.DefaultPartnerServiceErrorHandler.handleFailedResponse(DefaultPartnerServiceErrorHandler.java:96) | Error at com.microsoft.store.partnercenter.network.PartnerServiceClient.handleResponse(PartnerServiceClient.java:599) | Error at com.microsoft.store.partnercenter.network.PartnerServiceClient.get(PartnerServiceClient.java:225) | Error at com.microsoft.store.partnercenter.network.PartnerServiceClient.get(PartnerServiceClient.java:271) | Error at com.microsoft.store.partnercenter.auditrecords.AuditRecordsCollection.query(AuditRecordsCollection.java:125) | Error at in.webdataconsulting.jbilling.server.integration.partnercenter.MicrosoftPartnerCenterIntegrationTask.doExecute(MicrosoftPartnerCenterIntegrationTask.java:122) | Error at com.sapienter.jbilling.server.process.task.ScheduledTask.execute(ScheduledTask.java:151) | Error at org.quartz.core.JobRunShell.run(JobRunShell.java:202) | Error at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) order.getId() = 28a3d2b0-e07f-4738-8bda-ff94e51c92d4

Please share test platform diagnostics logs.
The logs may contain test assembly paths, kindly review and mask those before sharing.

Environment

Please share additional details about your environment. Version

ghost commented 4 years ago

@vikasbo thank you for reporting this issue, and I am pleased to share that it will be resolved with the next official release. To ensure that this issue does not happen again a date formatter was added to the code to ensure the date is in YYYY-MM-DD format

vikasbo commented 4 years ago

@isaiahwilliams Thank you for the response. Could you share the timeline for the next release? Thanks.

vikasbo commented 4 years ago

Please also let me know if there is a work around?

ghost commented 4 years ago

@vikasbo version 1.15.3 has just been released. Included in that release is a fix for this particular issue. Please let us know if you encounter any other issues.