@Override
  protected void configure() {
    final ObjectifyFactory of = new ObjectifyFactory();
    of.register(Device.class);
    of.register(Event.class);
    bind(ObjectifyFactory.class).toInstance(of);

    bind(DeviceService.class).in(Singleton.class);
    bind(PushService.class).in(Singleton.class);
  }
 @Override
 public PaymentGateway getPaymentGateway(Long gateway_id) {
   Objectify ofy = objectifyFactory.begin();
   if (log.isDebugEnabled()) {
     log.debug("getCreditCard");
   }
   PaymentGateway fetched = ofy.query(PaymentGateway.class).filter("gateway_id", gateway_id).get();
   return fetched;
 }
  @Cacheable("users")
  public GaeUser findUser(String userId) {
    logger.debug("Attempting to find user with ID {}", userId);

    Objectify objectify = objectifyFactory.begin();
    GaeUser user = objectify.find(GaeUser.class, userId);

    if (user != null) {
      logger.debug("Found user with name {}", user.getNickname());
      logger.debug("User has authorities {}", user.getAuthorities());
    } else {
      logger.debug("No user found");
    }

    return user;
  }
  public void registerUser(GaeUser newUser) {
    logger.debug("Registering user with ID {}", newUser.getUserId());
    logger.debug("Giving user the following authorities: {}", newUser.getAuthorities());

    Objectify objectify = objectifyFactory.begin();
    objectify.put(newUser);

    if (newUser.getAuthorities().contains(AppRole.DOCTOR)) {
      Doctor doc = new Doctor(newUser);
      objectify.put(doc);
      cacheManager.getCache("doctors").put(doc.getUserId(), doc);
    }

    if (newUser.getAuthorities().contains(AppRole.PATIENT)) {
      Patient pat = new Patient(newUser);
      objectify.put(pat);
      cacheManager.getCache("patients").put(pat.getUserId(), pat);
    }

    cacheManager.getCache("users").put(newUser.getUserId(), newUser);
  }
  @Override
  public boolean update(PaymentGateway item) throws Exception {
    log.info("update()");

    if (item == null) return false;

    Objectify ofy = objectifyFactory.begin();

    log.info(
        "verify if this PaymentGateway already exist " + "in the datastore: " + item.toString());
    boolean thisAddressAlreadyExist =
        ofy.query(PaymentGateway.class).ancestor(item.getGateway_id()).get() != null;

    if (thisAddressAlreadyExist) {
      log.info("Confirmed: this PaymentGateway already exist.");
      ofy.put(item);
      return true;
    } else {
      log.info(
          "This PaymentGateway doesn't exist at the datastore or "
              + "something whas wrong (might be the ancestor reference");
      return false;
    }
  }
 @Override
 public boolean remove(PaymentGateway item) throws Exception {
   Objectify ofy = objectifyFactory.begin();
   ofy.delete(item);
   return true;
 }
 @Override
 public Key<PaymentGateway> create(PaymentGateway item) throws Exception {
   Objectify ofy = objectifyFactory.begin();
   Key<PaymentGateway> paymentGatewayKey = ofy.put(item);
   return paymentGatewayKey;
 }
 public PaymentGatewayDAOImpl() {
   if (objectifyFactory != null)
     log.info(
         "objectifyFactory was injected succesfully to this dao: " + objectifyFactory.toString());
 }
 public void removeUser(String userId) {
   Objectify objectify = objectifyFactory.begin();
   objectify.delete(new Key<GaeUser>(GaeUser.class, userId));
 }