All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cosmicpush.common.requests.PushRequestStore Maven / Gradle / Ivy

/*
 * Copyright (c) 2014 Jacob D. Parr
 *
 * This software may not be used without permission.
 */
package com.cosmicpush.common.requests;

import com.cosmicpush.common.clients.Domain;
import com.cosmicpush.common.system.CpCouchServer;
import com.cosmicpush.pub.common.PushType;
import com.couchace.core.api.query.CouchViewQuery;
import org.crazyyak.lib.couchace.DefaultCouchStore;

import java.util.List;

public class PushRequestStore extends DefaultCouchStore {

  public static final String PUSH_REQUEST_DESIGN_NAME = "push-request";

  public PushRequestStore(CpCouchServer couchServer) {
    super(couchServer, PushRequest.class);
  }

  @Override
  public String getDatabaseName() {
    return CpCouchServer.DATABASE_NAME;
  }

  public PushRequest getByPushRequestId(String pushRequestId) {
    return super.getByDocumentId(pushRequestId);
  }

  public QueryResult getByClient(Domain domain, int limit) {

    CouchViewQuery viewQuery = CouchViewQuery.builder(getDesignName(), "byClient")
        .limit(limit)
        .key(domain.getDomainId())
        .build();

    return new QueryResult<>(PushRequest.class, getDatabase(), viewQuery);
  }

  public List getByClientAndType(Domain domain, PushType type) {
    return super.getEntities("byClientAndType", domain.getDomainId(), type.getCode());
  }

  public List getByClientAndSession(Domain domain, String sessionId) {
    return super.getEntities("byClientAndSession", domain.getDomainId(), sessionId);
  }

  public List getByClientAndDevice(Domain domain, String deviceId) {
    return super.getEntities("byClientAndDevice", domain.getDomainId(), deviceId);
  }

  @Override
  public String getDesignName() {
    return PUSH_REQUEST_DESIGN_NAME;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy