Search in sources :

Example 6 with Target

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());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query)

Example 7 with Target

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();
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) OrderBy(com.google.firebase.firestore.core.OrderBy) QueryTarget(com.google.firestore.v1.Target.QueryTarget) ResourcePath(com.google.firebase.firestore.model.ResourcePath) CollectionSelector(com.google.firestore.v1.StructuredQuery.CollectionSelector) Cursor(com.google.firestore.v1.Cursor)

Example 8 with Target

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);
}
Also used : ListenRequest(com.google.firestore.v1.ListenRequest)

Example 9 with Target

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;
}
Also used : Extension(com.github.zhenwei.core.asn1.x509.Extension) Target(com.github.zhenwei.core.asn1.x509.Target) TargetInformation(com.github.zhenwei.core.asn1.x509.TargetInformation) X509AttributeCertificateHolder(com.github.zhenwei.pkix.cert.X509AttributeCertificateHolder) Targets(com.github.zhenwei.core.asn1.x509.Targets)

Example 10 with Target

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;
}
Also used : CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) ASN1InputStream(com.github.zhenwei.core.asn1.ASN1InputStream) CertificateExpiredException(java.security.cert.CertificateExpiredException) Targets(com.github.zhenwei.core.asn1.x509.Targets) IOException(java.io.IOException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) Target(com.github.zhenwei.core.asn1.x509.Target) TargetInformation(com.github.zhenwei.core.asn1.x509.TargetInformation)

Aggregations

StructuredQuery (com.google.firestore.v1.StructuredQuery)14 QueryTarget (com.google.firestore.v1.Target.QueryTarget)14 Test (org.junit.Test)14 Query (com.google.firebase.firestore.core.Query)13 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 FieldIndex (com.google.firebase.firestore.model.FieldIndex)4 Value (com.google.firestore.v1.Value)4 TargetData (com.google.firebase.firestore.local.TargetData)3 Nullable (androidx.annotation.Nullable)2 Target (com.github.zhenwei.core.asn1.x509.Target)2 TargetInformation (com.github.zhenwei.core.asn1.x509.TargetInformation)2 Targets (com.github.zhenwei.core.asn1.x509.Targets)2 DocumentKey (com.google.firebase.firestore.model.DocumentKey)2 Status (io.grpc.Status)2 ArrayList (java.util.ArrayList)2 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 Extension (com.github.zhenwei.core.asn1.x509.Extension)1 X509AttributeCertificateHolder (com.github.zhenwei.pkix.cert.X509AttributeCertificateHolder)1