Package com.agendabeleza.controllers

Source Code of com.agendabeleza.controllers.SyncController

package com.agendabeleza.controllers;

import com.agendabeleza.models.CompanyModel;
import com.agendabeleza.utils.Heroku;
import com.agendabeleza.utils.HerokuClient;
import com.agendabeleza.utils.HerokuException;

public class SyncController {

  public boolean existsOnHeroku(CompanyModel pCompanyModel) {

    HerokuClient client = new HerokuClient(Heroku.HOST + Heroku.COMPANY_SERVICES + pCompanyModel.getAzId());
    CompanyModel tCompany;

    try {
      tCompany = (CompanyModel) client.request(CompanyModel.class);
      if (tCompany.getId() == null) {
        return false;
      } else {
        pCompanyModel.setId(tCompany.getId());
        return true;
      }
    } catch (HerokuException e) {
      System.err.println("resposta nula");
      return false;
    }
  }

  public boolean createOnHeroku(CompanyModel pCompanyModel) {

    HerokuClient client = new HerokuClient(Heroku.HOST + Heroku.COMPANY_SERVICES);
    CompanyModel tCompany;

    try {
      client.setMethod(HerokuClient.POST);
      client.setParamsFromObject(pCompanyModel);
      tCompany = (CompanyModel) client.request(CompanyModel.class);

      if (tCompany.getId() == null) {
        return false;
      } else {
        pCompanyModel.setId(tCompany.getId());
        return true;
      }
    } catch (HerokuException e) {
      System.err.println("resposta nula");
      return false;
    }

  }

}
TOP

Related Classes of com.agendabeleza.controllers.SyncController

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.