use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method unaryFilterTest.
private void unaryFilterTest(String op, Object equalityValue, UnaryFilter.Operator unaryOperator) {
Query q = Query.atPath(ResourcePath.fromString("docs")).filter(filter("prop", op, equalityValue));
Target actual = serializer.encodeTarget(wrapTargetData(q));
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).setWhere(Filter.newBuilder().setUnaryFilter(UnaryFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("prop")).setOp(unaryOperator)));
// Add extra ORDER_BY field for '!=' since it is an inequality.
if (op.equals("!=")) {
structuredQueryBuilder.addOrderBy(Order.newBuilder().setDirection(Direction.ASCENDING).setField(FieldReference.newBuilder().setFieldPath("prop")));
}
structuredQueryBuilder.addOrderBy(defaultKeyOrder());
QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializer method encodeQueryTarget.
public QueryTarget encodeQueryTarget(com.google.firebase.firestore.core.Target target) {
// Dissect the path into parent, collectionId, and optional key filter.
QueryTarget.Builder builder = QueryTarget.newBuilder();
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder();
ResourcePath path = target.getPath();
if (target.getCollectionGroup() != null) {
hardAssert(path.length() % 2 == 0, "Collection Group queries should be within a document path or root.");
builder.setParent(encodeQueryPath(path));
CollectionSelector.Builder from = CollectionSelector.newBuilder();
from.setCollectionId(target.getCollectionGroup());
from.setAllDescendants(true);
structuredQueryBuilder.addFrom(from);
} else {
hardAssert(path.length() % 2 != 0, "Document queries with filters are not supported.");
builder.setParent(encodeQueryPath(path.popLast()));
CollectionSelector.Builder from = CollectionSelector.newBuilder();
from.setCollectionId(path.getLastSegment());
structuredQueryBuilder.addFrom(from);
}
// Encode the filters.
if (target.getFilters().size() > 0) {
structuredQueryBuilder.setWhere(encodeFilters(target.getFilters()));
}
// Encode the orders.
for (OrderBy orderBy : target.getOrderBy()) {
structuredQueryBuilder.addOrderBy(encodeOrderBy(orderBy));
}
// Encode the limit.
if (target.hasLimit()) {
structuredQueryBuilder.setLimit(Int32Value.newBuilder().setValue((int) target.getLimit()));
}
if (target.getStartAt() != null) {
Cursor.Builder cursor = Cursor.newBuilder();
cursor.addAllValues(target.getStartAt().getPosition());
cursor.setBefore(target.getStartAt().isInclusive());
structuredQueryBuilder.setStartAt(cursor);
}
if (target.getEndAt() != null) {
Cursor.Builder cursor = Cursor.newBuilder();
cursor.addAllValues(target.getEndAt().getPosition());
cursor.setBefore(!target.getEndAt().isInclusive());
structuredQueryBuilder.setEndAt(cursor);
}
builder.setStructuredQuery(structuredQueryBuilder);
return builder.build();
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class WatchStream method unwatchTarget.
/**
* Unregisters interest in the results of the query associated with the given target ID.
*/
public void unwatchTarget(int targetId) {
hardAssert(isOpen(), "Unwatching targets requires an open stream");
ListenRequest request = ListenRequest.newBuilder().setDatabase(serializer.databaseName()).setRemoveTarget(targetId).build();
writeRequest(request);
}
use of com.google.firestore.v1.Target in project LinLong-Java by zhenwei1108.
the class X509AttributeCertificateHolderSelector method match.
/**
* Decides if the given attribute certificate should be selected.
*
* @param obj The X509AttributeCertificateHolder which should be checked.
* @return <code>true</code> if the attribute certificate is a match
* <code>false</code> otherwise.
*/
public boolean match(Object obj) {
if (!(obj instanceof X509AttributeCertificateHolder)) {
return false;
}
X509AttributeCertificateHolder attrCert = (X509AttributeCertificateHolder) obj;
if (this.attributeCert != null) {
if (!this.attributeCert.equals(attrCert)) {
return false;
}
}
if (serialNumber != null) {
if (!attrCert.getSerialNumber().equals(serialNumber)) {
return false;
}
}
if (holder != null) {
if (!attrCert.getHolder().equals(holder)) {
return false;
}
}
if (issuer != null) {
if (!attrCert.getIssuer().equals(issuer)) {
return false;
}
}
if (attributeCertificateValid != null) {
if (!attrCert.isValidOn(attributeCertificateValid)) {
return false;
}
}
if (!targetNames.isEmpty() || !targetGroups.isEmpty()) {
Extension targetInfoExt = attrCert.getExtension(Extension.targetInformation);
if (targetInfoExt != null) {
TargetInformation targetinfo;
try {
targetinfo = TargetInformation.getInstance(targetInfoExt.getParsedValue());
} catch (IllegalArgumentException e) {
return false;
}
Targets[] targetss = targetinfo.getTargetsObjects();
if (!targetNames.isEmpty()) {
boolean found = false;
for (int i = 0; i < targetss.length; i++) {
Targets t = targetss[i];
Target[] targets = t.getTargets();
for (int j = 0; j < targets.length; j++) {
if (targetNames.contains(GeneralName.getInstance(targets[j].getTargetName()))) {
found = true;
break;
}
}
}
if (!found) {
return false;
}
}
if (!targetGroups.isEmpty()) {
boolean found = false;
for (int i = 0; i < targetss.length; i++) {
Targets t = targetss[i];
Target[] targets = t.getTargets();
for (int j = 0; j < targets.length; j++) {
if (targetGroups.contains(GeneralName.getInstance(targets[j].getTargetGroup()))) {
found = true;
break;
}
}
}
if (!found) {
return false;
}
}
}
}
return true;
}
use of com.google.firestore.v1.Target in project LinLong-Java by zhenwei1108.
the class X509AttributeCertStoreSelector method match.
/**
* Decides if the given attribute certificate should be selected.
*
* @param obj The attribute certificate which should be checked.
* @return <code>true</code> if the attribute certificate can be selected,
* <code>false</code> otherwise.
*/
public boolean match(Object obj) {
if (!(obj instanceof X509AttributeCertificate)) {
return false;
}
X509AttributeCertificate attrCert = (X509AttributeCertificate) obj;
if (this.attributeCert != null) {
if (!this.attributeCert.equals(attrCert)) {
return false;
}
}
if (serialNumber != null) {
if (!attrCert.getSerialNumber().equals(serialNumber)) {
return false;
}
}
if (holder != null) {
if (!attrCert.getHolder().equals(holder)) {
return false;
}
}
if (issuer != null) {
if (!attrCert.getIssuer().equals(issuer)) {
return false;
}
}
if (attributeCertificateValid != null) {
try {
attrCert.checkValidity(attributeCertificateValid);
} catch (CertificateExpiredException e) {
return false;
} catch (CertificateNotYetValidException e) {
return false;
}
}
if (!targetNames.isEmpty() || !targetGroups.isEmpty()) {
byte[] targetInfoExt = attrCert.getExtensionValue(Extension.targetInformation.getId());
if (targetInfoExt != null) {
TargetInformation targetinfo;
try {
targetinfo = TargetInformation.getInstance(new ASN1InputStream(((DEROctetString) DEROctetString.fromByteArray(targetInfoExt)).getOctets()).readObject());
} catch (IOException e) {
return false;
} catch (IllegalArgumentException e) {
return false;
}
Targets[] targetss = targetinfo.getTargetsObjects();
if (!targetNames.isEmpty()) {
boolean found = false;
for (int i = 0; i < targetss.length; i++) {
Targets t = targetss[i];
Target[] targets = t.getTargets();
for (int j = 0; j < targets.length; j++) {
if (targetNames.contains(GeneralName.getInstance(targets[j].getTargetName()))) {
found = true;
break;
}
}
}
if (!found) {
return false;
}
}
if (!targetGroups.isEmpty()) {
boolean found = false;
for (int i = 0; i < targetss.length; i++) {
Targets t = targetss[i];
Target[] targets = t.getTargets();
for (int j = 0; j < targets.length; j++) {
if (targetGroups.contains(GeneralName.getInstance(targets[j].getTargetGroup()))) {
found = true;
break;
}
}
}
if (!found) {
return false;
}
}
}
}
return true;
}
Aggregations