Package com.casamind.adware.server.billing

Source Code of com.casamind.adware.server.billing.BillingFactory

package com.casamind.adware.server.billing;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import com.casamind.adware.server.domain.Company;
import com.casamind.adware.server.proxy.DatastoreProxy;
import com.casamind.adware.server.proxy.GDataDocumentsProxy;
import com.casamind.adware.shared.GoogleDocumentsTaskTypes;
import com.casamind.adware.shared.model.SlotDTO;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.util.ServiceException;

public class BillingFactory {
  private static final Logger log = Logger.getLogger(BillingFactory.class.getName());
 
  public static String invoice(GDataDocumentsProxy proxy, List<SlotDTO> objects, Date dueDate) {
    String link = "www.casamind.com";
    String entityIds = "";
    try {
      Company company = DatastoreProxy.getCompanyById(objects.get(0).getCompany().getId());
      if (company != null){
        int billNumber = generateBillNumber();
        String title = "FACTURE_" + company.getId().toString() + "_" + Integer.toString(billNumber) + "_" + company.getDisplayName();
        for (SlotDTO dto : objects) {
          entityIds += dto.getId() + ",";
        }
        if (entityIds.endsWith(",")) {
          entityIds = entityIds.substring(0, entityIds.length() - 1);
        }
        log.info("Searching for document entry '" + title + "' in Google Docs account.");
        DocumentListEntry entry = proxy.findDocumentEntry(title);
        if(entry == null){
          log.warning("Did not find document. Will create it.");
          entry = proxy.createDocumentFile("document", title, "billing");
          log.info("Created entry in: " + entry.getDocumentLink().getHref());
        }
        link = proxy.getExportLink(entry, "pdf");
        log.info("Queueing billing resources tasks...");
        QueueFactory.getQueue("gdata").add(TaskOptions.Builder.withUrl("/tasks/gdata/billing")
            .param("task", GoogleDocumentsTaskTypes.CREATE)
            .param("title", title)
            .param("entityIds", entityIds)
            .param("billNumber", Integer.toString(billNumber)));
        log.info("Billing resources task queued successfully!");
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ServiceException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return link;
  }
 
  private static int generateBillNumber() {
    return 0;
  }

}
TOP

Related Classes of com.casamind.adware.server.billing.BillingFactory

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.