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

com.noenv.wiremongo.mapping.WithDocument Maven / Gradle / Ivy

There is a newer version: 4.5.10
Show newest version
package com.noenv.wiremongo.mapping;

import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.WithDocumentCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import org.bson.types.ObjectId;

import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;

public abstract class WithDocument> extends WithCollection {

  private Matcher document;

  public WithDocument(String method) {
    super(method);
  }

  public WithDocument(JsonObject json) {
    super(json);
    document = Matcher.create(json.getJsonObject("document"));
  }

  public C withDocument(JsonObject document) {
    return withDocument(equalTo(document));
  }

  public C withDocument(Matcher document) {
    this.document = document;
    return self();
  }

  public C returnsObjectId() {
    return returns(ObjectId.get().toHexString());
  }

  @Override
  public boolean matches(Command cmd) {
    if (!super.matches(cmd)) {
      return false;
    }
    if (!(cmd instanceof WithDocumentCommand)) {
      return false;
    }
    WithDocumentCommand c = (WithDocumentCommand) cmd;
    return document == null || document.matches(c.getDocument());
  }

  @Override
  protected String parseResponse(Object jsonValue) {
    return (String) jsonValue;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy