Java Code Examples for com.mongodb.QueryBuilder#get()

The following examples show how to use com.mongodb.QueryBuilder#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoReader.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
/**
 * Create query partition.
 *
 * @param partition the partition
 * @return the dB object
 */
private DBObject createQueryPartition(MongoPartition partition) {

    QueryBuilder queryBuilderMin = QueryBuilder.start(partition.getKey());
    DBObject bsonObjectMin = queryBuilderMin.greaterThanEquals(partition.splitWrapper().getStartToken()).get();

    QueryBuilder queryBuilderMax = QueryBuilder.start(partition.getKey());
    DBObject bsonObjectMax = queryBuilderMax.lessThan(partition.splitWrapper().getEndToken()).get();

    QueryBuilder queryBuilder = QueryBuilder.start();
    if (partition.splitWrapper().getStartToken() != null) {
        queryBuilder.and(bsonObjectMin);
    }

    if (partition.splitWrapper().getEndToken() != null) {
        queryBuilder.and(bsonObjectMax);
    }

    LOG.debug("mongodb query "+queryBuilder.get());

    return queryBuilder.get();
}
 
Example 2
Source File: AbstractHistoricalMetricProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public List<Pongo> getHistoricalMeasurements(MetricProviderContext context, Project project, Date start, Date end) {
	
	DB db = context.getProjectDB(project);
	DBCollection collection = db.getCollection(this.getCollectionName());
	
	QueryBuilder builder = QueryBuilder.start();
	if (start != null) {
		builder.and("__datetime").greaterThanEquals(start.toJavaDate());
	}
	if (end != null) {
		builder.and("__datetime").lessThanEquals(end.toJavaDate());
	}
	 
	BasicDBObject query = (BasicDBObject) builder.get(); 

	Iterator<DBObject> it = collection.find(query).iterator();
	
	List<Pongo> pongoList = new ArrayList<Pongo>();
	
	while (it.hasNext()) {
		DBObject dbObject = it.next();
		pongoList.add(PongoFactory.getInstance().createPongo(dbObject));
	}
	
	return pongoList;
	
}
 
Example 3
Source File: RawMetricResource.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public Representation doRepresent() {
	
	/**
	 * Fetch data metrics for both HistoricalMetricProvider & TransientMetricProvider
	 */
	String projectId = (String) getRequest().getAttributes().get("projectid");
	String metricId = (String) getRequest().getAttributes().get("metricid");
	
	String start = getQueryValue("startDate");
	String end = getQueryValue("endDate");
	
	QueryBuilder builder = QueryBuilder.start();
	try {
		if (start != null && start != "") {
			builder.and("__datetime").greaterThanEquals(new Date(start).toJavaDate());
		}
		if (end != null && end != "") {
			builder.and("__datetime").lessThanEquals(new Date(end).toJavaDate());
		}
	} catch (ParseException e) {
		e.getStackTrace();
	}
	
	BasicDBObject query = (BasicDBObject) builder.get(); 
	
	ArrayNode results = mapper.createArrayNode();
			
	if (projectId != null && metricId != null) {
		this.db = mongo.getDB(ANALYSIS_SCHEDULING_DATABASE);
		ProjectAnalysisResportory repository = new ProjectAnalysisResportory(this.db);
		Iterable<MetricExecution> listMetricExecutions = repository.getMetricExecutions().findByProjectId(projectId);
		
		List<String> metricExecutions = new ArrayList<>();
		for (MetricExecution metricExecution : listMetricExecutions) {
			metricExecutions.add(metricExecution.getMetricProviderId());
		}

		if (metricExecutions.contains(metricId)) {
			List<IMetricProvider> platformProvider = this.platform.getMetricProviderManager().getMetricProviders();
			for (IMetricProvider iMetricProvider : platformProvider) {
				if (iMetricProvider.getIdentifier().equals(metricId)) {
					Project project = platform.getProjectRepositoryManager().getProjectRepository().getProjects().findOneByShortName(projectId);
					if(iMetricProvider instanceof IHistoricalMetricProvider) {
						results.addAll(getHistoricDocuments(platform.getMetricsRepository(project).getDb().getCollection(((IHistoricalMetricProvider) iMetricProvider).getCollectionName()), query));
					} else if (iMetricProvider instanceof ITransientMetricProvider) {
						results.addAll(getTransientDocuments(((ITransientMetricProvider) iMetricProvider).adapt(platform.getMetricsRepository(project).getDb()).getPongoCollections()));
					}
					break;
				}
			}

		}
	
	}
	
	return Util.createJsonRepresentation(results);
}
 
Example 4
Source File: MetricVisualisationResource.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public Representation doRepresent() {
		String projectName = (String) getRequest().getAttributes().get("projectid");
		String metricId = (String) getRequest().getAttributes().get("metricid");
		
		String agg = getQueryValue("agg");
		String start = getQueryValue("startDate");
		String end = getQueryValue("endDate");
		
		QueryBuilder builder = QueryBuilder.start();
		if (agg != null && agg != "") {
//			builder.... // TODO
		}
		try {
			if (start != null && start != "") {
				builder.and("__datetime").greaterThanEquals(new Date(start).toJavaDate());
			}
			if (end != null && end != "") {
				builder.and("__datetime").lessThanEquals(new Date(end).toJavaDate());
			}
		} catch (ParseException e) {
			return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "Invalid date. Format must be YYYYMMDD.");
		}
		
		BasicDBObject query = (BasicDBObject) builder.get(); 
		
		ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository();
		
		Project project = projectRepo.getProjects().findOneByShortName(projectName);
		if (project == null) {
			getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
			return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "No project was found with the requested name.");
		}
		
		MetricVisualisationExtensionPointManager manager = MetricVisualisationExtensionPointManager.getInstance();
		manager.getRegisteredVisualisations();

		MetricVisualisation vis = manager.findVisualisationById(metricId);
		
		if (vis == null) {
			return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "No visualiser found with specified ID.");
		}
		
		DB db = platform.getMetricsRepository(project).getDb();
		JsonNode visualisation = vis.visualise(db, query);
		
		StringRepresentation resp = new StringRepresentation(visualisation.toString());
		resp.setMediaType(MediaType.APPLICATION_JSON);
		return resp;
	}
 
Example 5
Source File: MongoReader.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
/**
 * Generate filter query.
 *
 * @param partition the partition
 * @return the dB object
 */
private DBObject generateFilterQuery(MongoPartition partition) {

    if (mongoDeepJobConfig.getQuery() != null) {
        QueryBuilder queryBuilder = QueryBuilder.start();

        queryBuilder.and(createQueryPartition(partition), mongoDeepJobConfig.getQuery());

        LOG.debug("mongodb query "+queryBuilder.get());

        return queryBuilder.get();
    }

    return createQueryPartition(partition);

}
 
Example 6
Source File: MongoDeepJobConfig.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public MongoDeepJobConfig<T> filterQuery(QueryBuilder query) {
    this.query = query.get();
    return this;
}