Package

Source Code of GenerateOrdersReport

/**
* PlayTrade API Java Client
* Copyright 2013 PureBuy Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use the this PlayTrade API Java Client except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Date;

import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.PlayTradeUtils;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.GenerateReportNowCall;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.GetReportStatusCall;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.GetReportStatusCallResult;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.GetReportStatusCallResult.Report;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.PlayTradeApiCallException;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.ReportName;
import uk.co.purebuy.commerce.businessobjects.importexport.playtrade.call.StandardCallResult;

/**
* Requests a report of the last 2 Days of Orders to
* be generated. Then download a list of all the generated
* order reports to see if the generation has been finished yet.
*
* See the {@link ReportName} enumeration for all the different
* reports than can be generated using the same method
* @author Dave/James Allcock
* Copyright 2013 PureBuy Ltd
*/
public class GenerateOrdersReport
{
  /**
   * @param args no arguments
   * @throws PlayTradeApiCallException
   * @throws InterruptedException
   */
  public static void main(String[] args) throws PlayTradeApiCallException, InterruptedException
  {
    final int NUMBER_OF_DAYS = 2//the number of days we want to generate an order report for
   
    //create a request order report call
    GenerateReportNowCall call = new GenerateReportNowCall(
        ReportName.Order,
        NUMBER_OF_DAYS );
   
    //set the authentication
    call.setUsername("user@email.com");
    call.setPassword("password");
       
    //make the call to generate the order report
    StandardCallResult result = call.callGenerateReportNow();
   
    if ( result.getSuccess() != null )
    {
      System.out.println("Sucess :" + result.getSuccess() );
     
      /* wait a while for the report to be generated,
       * reports can take several minutes to be generated
       */
      Thread.sleep( 30000 )
     
      //we requested a report from the previous run, try and get the report ID for it
      GetReportStatusCall getreportstatus = new GetReportStatusCall(ReportName.Order);
      getreportstatus.setNumberOfReports(3);
     
      //set the authentication
      call.setUsername("user@email.com");
      call.setPassword("password");
     
      //make the call
      GetReportStatusCallResult rsresult = getreportstatus.callGetReportStatus();
     
      //have a look at all the reports
      Report[] report = rsresult.getReports();         
      for (int i = 0; i < report.length; i++)
      {
        Date endtime = PlayTradeUtils.parsePlayTradeDateTime( report[i].getReportendtime() );
        Date starttime = PlayTradeUtils.parsePlayTradeDateTime( report[i].getReportstarttime()  );
        System.out.println("Report ID: "+report[i].getReportid() + ", start=" + starttime + ", endtime=" + endtime );       
      }
    }
    else
    {
      throw new Error("Error :" + result.getBusinessLogicError() );
    }
  }

}
TOP

Related Classes of GenerateOrdersReport

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.