@Override public void updateDownloadLogs(final String id, final UserInfos user, final Handler<JsonObject> handler) { final QueryBuilder query = QueryBuilder.start("_id").is(id); final JsonObject logElem = new JsonObject().putString("userDisplayName", user.getUsername()).putObject("downloadDate", MongoDb.now()); final MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.addToSet("downloadLogs", logElem); mongo.update(ShareBigFiles.SHARE_BIG_FILE_COLLECTION, MongoQueryBuilder.build(query), modifier.build(), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { handler.handle(new JsonObject().putString("status", "ok")); } else { handler.handle(new JsonObject().putString("status", "error") .putString("message", event.body().getString("message"))); } } }); }
@Override public void authorize(final HttpServerRequest request, final Binding binding, final UserInfos user, final Handler<Boolean> handler) { RequestUtils.bodyToJson(request, Server.getPathPrefix(Config.getInstance().getConfig()) + "deletes", new Handler<JsonObject>() { public void handle(JsonObject data) { final List<String> ids = data.getArray("ids").toList(); if (ids != null && !ids.isEmpty()) { List<DBObject> groups = new ArrayList<>(); String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-"); groups.add(QueryBuilder.start("userId").is(user.getUserId()) .put(sharedMethod).is(true).get()); for (String gpId: user.getGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId) .put(sharedMethod).is(true).get()); } QueryBuilder query = QueryBuilder.start("_id").in(new HashSet<String>(ids)).or( QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("shared").elemMatch( new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get() ); MongoAppFilter.executeCountQuery(request, conf.getCollection(), MongoQueryBuilder.build(query), ids.size(), handler); } else { handler.handle(false); } } }); }
protected DBObject transformFieldFilter( final SingleFieldValueFilter<K, T> fieldFilter, final MongoStore<K, T> store) { MongoMapping mapping = store.getMapping(); String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName()); FilterOp filterOp = fieldFilter.getFilterOp(); List<Object> operands = fieldFilter.getOperands(); QueryBuilder builder = QueryBuilder.start(dbFieldName); builder = appendToBuilder(builder, filterOp, operands); if (!fieldFilter.isFilterIfMissing()) { // If false, the find query will pass if the column is not found. DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get(); builder = QueryBuilder.start().or(notExist, builder.get()); } return builder.get(); }
protected DBObject transformMapFilter( final MapFieldValueFilter<K, T> mapFilter, final MongoStore<K, T> store) { MongoMapping mapping = store.getMapping(); String dbFieldName = mapping.getDocumentField(mapFilter.getFieldName()) + "." + store.encodeFieldKey(mapFilter.getMapKey().toString()); FilterOp filterOp = mapFilter.getFilterOp(); List<Object> operands = mapFilter.getOperands(); QueryBuilder builder = QueryBuilder.start(dbFieldName); builder = appendToBuilder(builder, filterOp, operands); if (!mapFilter.isFilterIfMissing()) { // If false, the find query will pass if the column is not found. DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get(); builder = QueryBuilder.start().or(notExist, builder.get()); } return builder.get(); }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getAllByDefinitionId(String pipelineDefinitionId) { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> filteredPipelines = pipelines .stream() .filter(p -> p.getPipelineDefinitionId().equals(pipelineDefinitionId)) .collect(Collectors.toList()); result.setEntity(filteredPipelines); break; case MONGODB: BasicDBObject query = (BasicDBObject) QueryBuilder.start().put("pipelineDefinitionId").is(pipelineDefinitionId).get(); result = this.getPipelineMongoService().QueryExecutor(query); break; } return result; }
@Override public void updateShare(String pageId, String userId, JsonObject value, Handler<Either<String, JsonObject>> handler) { JsonArray shared = new JsonArray(); shared.add(new JsonObject().putString("groupId", value.getString("read")). putBoolean("net-atos-entng-community-controllers-PagesController|get", true)); shared.add(new JsonObject().putString("groupId", value.getString("contrib")). putBoolean("net-atos-entng-community-controllers-PagesController|get", true). putBoolean("net-atos-entng-community-controllers-PagesController|update", true)); shared.add(new JsonObject().putString("groupId", value.getString("manager")). putBoolean("net-atos-entng-community-controllers-PagesController|get", true). putBoolean("net-atos-entng-community-controllers-PagesController|update", true). putBoolean("net-atos-entng-community-controllers-PagesController|delete", true)); MongoUpdateBuilder updateQuery = new MongoUpdateBuilder().set("shared", shared); QueryBuilder query = QueryBuilder.start("_id").is(pageId); mongo.update(conf.getCollection(), MongoQueryBuilder.build(query), updateQuery.build(), MongoDbResult.validActionResultHandler(handler)); }
@Override public void authorize(HttpServerRequest request, Binding binding, UserInfos user, Handler<Boolean> handler) { String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-"); String id = request.params().get(conf.getResourceIdLabel()); if (id != null && !id.trim().isEmpty()) { List<DBObject> groups = new ArrayList<>(); groups.add(QueryBuilder.start("userId").is(user.getUserId()) .put(sharedMethod).is(true).get()); for (String gpId: user.getGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId) .put(sharedMethod).is(true).get()); } QueryBuilder query = QueryBuilder.start("_id").is(id).or( QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(), QueryBuilder.start("shared").elemMatch( new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get() ); MongoAppFilter.executeCountQuery(request, conf.getCollection(), MongoQueryBuilder.build(query), 1, handler); } else { handler.handle(false); } }
public DBObject getQuery(final StatementConstraints contraints) { final QueryBuilder queryBuilder = QueryBuilder.start(); if (contraints.hasSubject()){ queryBuilder.and(new BasicDBObject(SUBJECT, contraints.getSubject().toString())); } if (contraints.hasPredicates()){ final Set<URI> predicates = contraints.getPredicates(); if (predicates.size() > 1){ for (final URI pred : predicates){ final DBObject currentPred = new BasicDBObject(PREDICATE, pred.toString()); queryBuilder.or(currentPred); } } else if (!predicates.isEmpty()){ queryBuilder.and(new BasicDBObject(PREDICATE, predicates.iterator().next().toString())); } } if (contraints.hasContext()){ queryBuilder.and(new BasicDBObject(CONTEXT, contraints.getContext().toString())); } return queryBuilder.get(); }
private DBObject getTemporalObject(final TemporalInstant instant, final TemporalPolicy policy) { final DBObject temporalObj; switch(policy) { case INSTANT_AFTER_INSTANT: temporalObj = QueryBuilder.start(INSTANT) .greaterThan(instant.getAsDateTime().toDate()) .get(); break; case INSTANT_BEFORE_INSTANT: temporalObj = QueryBuilder.start(INSTANT) .lessThan(instant.getAsDateTime().toDate()) .get(); break; case INSTANT_EQUALS_INSTANT: temporalObj = QueryBuilder.start(INSTANT) .is(instant.getAsDateTime().toDate()) .get(); break; default: temporalObj = new BasicDBObject(); } return temporalObj; }
@Test public void testShellDirect() throws Exception { Command cmd = this.utility.parseCommand("SELECT * FROM Customers"); MongoDBConnection connection = Mockito.mock(MongoDBConnection.class); ExecutionContext context = Mockito.mock(ExecutionContext.class); DBCollection dbCollection = Mockito.mock(DBCollection.class); DB db = Mockito.mock(DB.class); Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection); Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true); Mockito.stub(connection.getDatabase()).toReturn(db); Argument arg = new Argument(Direction.IN, null, String.class, null); arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class)); ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection); execution.execute(); Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get()); }
@Override public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception { DBCollection collection = getBlobCollection(); QueryBuilder queryBuilder = new QueryBuilder(); if (chunkIds != null) { queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).in(chunkIds.toArray(new String[0])); if (maxLastModifiedTime > 0) { queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD) .lessThan(maxLastModifiedTime); } } WriteResult result = collection.remove(queryBuilder.get()); if (result.getN() == chunkIds.size()) { return true; } return false; }
@Override public boolean acquireRecoveryLock(int clusterId) { QueryBuilder query = start().and( start(Document.ID).is(Integer.toString(clusterId)).get(), start(ClusterNodeInfo.REV_RECOVERY_LOCK).notEquals(RecoverLockState.ACQUIRED.name()).get() ); DBObject returnFields = new BasicDBObject(); returnFields.put("_id", 1); BasicDBObject setUpdates = new BasicDBObject(); setUpdates.append(ClusterNodeInfo.REV_RECOVERY_LOCK, RecoverLockState.ACQUIRED.name()); BasicDBObject update = new BasicDBObject(); update.append("$set", setUpdates); DBObject oldNode = getClusterNodeCollection().findAndModify(query.get(), returnFields, null /*sort*/, false /*remove*/, update, false /*returnNew*/, false /*upsert*/); return oldNode != null; }
@Nonnull private static QueryBuilder createQueryForUpdate(UpdateOp updateOp, boolean checkConditions) { QueryBuilder query = getByKeyQuery(updateOp.getId()); for (Entry<Key, Operation> entry : updateOp.getChanges().entrySet()) { Key k = entry.getKey(); Operation op = entry.getValue(); switch (op.type) { case CONTAINS_MAP_ENTRY: { if (checkConditions) { query.and(k.toString()).exists(op.value); } break; } } } return query; }
/** * 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(); }
public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) { DBObject lastone = null; try { BasicDBObject searchQuery = new BasicDBObject(); QueryBuilder qb = new QueryBuilder(); qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate); searchQuery.putAll(qb.get()); DBCursor cursor = collection.find(searchQuery); while (cursor.hasNext()) { lastone = cursor.next(); } } catch (MongoException e) { e.printStackTrace(); } return lastone; }
@Override public long countResultsByEventName(String name) { DBObject queryObj = QueryBuilder .start() .and(EventRecord.FIELD_EVENT_NAME).is(name) .get(); long count = collection.count(queryObj); // Done if(logger.isDebugEnabled()) { logger.debug("Counted " + count + " results for event name: " + name); } return count; }
@Override public long countResultsBySuccess() { DBObject queryObj = QueryBuilder .start() .and(EventRecord.FIELD_SUCCESS).is(true) .get(); long count = collection.count(queryObj); // Done if(logger.isDebugEnabled()) { logger.debug("Counted " + count + " results for success: " + true); } return count; }
@Override public long countResultsByFailure() { DBObject queryObj = QueryBuilder .start() .and(EventRecord.FIELD_SUCCESS).is(false) .get(); long count = collection.count(queryObj); // Done if(logger.isDebugEnabled()) { logger.debug("Counted " + count + " results for success: " + false); } return count; }
/** * Refresh the expiry time of a driver * * @param id * the driver id * @param expiryTime * the new expiry time */ public void refreshDriver(String id, long expiryTime) { DBObject queryObj = QueryBuilder .start() .and(FIELD_ID).is(new ObjectId(id)) .get(); DBObject updateObj = BasicDBObjectBuilder .start() .push("$set") .add(FIELD_PING + "." + FIELD_EXPIRES, new Date(expiryTime)) .pop() .get(); testDrivers.findAndModify(queryObj, null, null, false, updateObj, false, false); // Done if (logger.isDebugEnabled()) { logger.debug( "Updated test driver expiry: \n" + " ID: " + id + "\n" + " New: " + expiryTime); } }
/** * Register a driver with a test run * * @param runObjId * the ID of the test run * @param driverId * the ID of the driver to include */ public void addTestRunDriver(ObjectId runObjId, String driverId) { // Find the test run DBObject queryObj = QueryBuilder .start() .and(FIELD_ID).is(runObjId) .get(); DBObject updateObj = BasicDBObjectBuilder.start() .push("$addToSet") .add(FIELD_DRIVERS, driverId) .pop() .get(); DBObject runObj = testRuns.findAndModify(queryObj, null, null, false, updateObj, true, false); // Done if (logger.isDebugEnabled()) { logger.debug( "Added driver ID to run drivers: \n" + " Run ID: " + runObjId + "\n" + " Driver: " + driverId + "\n" + " Drivers: " + runObj.get(FIELD_DRIVERS)); } }
/** * Derigister a driver from a test run * * @param runObjId * the ID of the test run * @param driverId * the ID of the driver to remove */ public void removeTestRunDriver(ObjectId runObjId, String driverId) { // Find the test run DBObject queryObj = QueryBuilder .start() .and(FIELD_ID).is(runObjId) .get(); DBObject updateObj = BasicDBObjectBuilder.start() .push("$pull") .add(FIELD_DRIVERS, driverId) .pop() .get(); DBObject runObj = testRuns.findAndModify(queryObj, null, null, false, updateObj, true, false); // Done if (logger.isDebugEnabled()) { logger.debug( "Removed driver ID from run drivers: \n" + " Run ID: " + runObjId + "\n" + " Driver: " + driverId + "\n" + " Drivers: " + runObj.get(FIELD_DRIVERS)); } }
/** * Fetch masked property names (passwords) by test name. * * @param testName * (String, mandatory) test name * * @return (Set<String>) or exception * * @throws ObjectNotFoundException * @since 2.1.2 */ public Set<String> getMaskedProperyNames(String testName) throws ObjectNotFoundException { ArgumentCheck.checkMandatoryString(testName, "testName"); DBObject queryObj = QueryBuilder .start() .and(FIELD_NAME).is(testName) .get(); BasicDBObjectBuilder fieldsObjBuilder = BasicDBObjectBuilder .start(FIELD_RELEASE, true) .add(FIELD_SCHEMA, true); DBObject testObj = tests.findOne(queryObj, fieldsObjBuilder.get()); ObjectNotFoundException.checkObject(testObj, testName); return getMaskedProperyNames((String) testObj.get(FIELD_RELEASE), (Integer) testObj.get(FIELD_SCHEMA)); }
@Override public List<Blog> findTitleList() { BasicDBObject basicDBObject = new BasicDBObject(); basicDBObject.put("id", 1); basicDBObject.put("title", 1); basicDBObject.put("type", 1); basicDBObject.put("currentDate", 1); QueryBuilder builder = new QueryBuilder(); return mongoTemplate.find(new BasicQuery(builder.get(), basicDBObject), Blog.class); }
@Override public void getQuotaData(final String userId, final Handler<JsonObject> handler) { final QueryBuilder query = QueryBuilder.start("owner.userId").is(userId).put("fileMetadata.size").exists(true); mongo.find(ShareBigFiles.SHARE_BIG_FILE_COLLECTION, MongoQueryBuilder.build(query), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { final JsonArray res = event.body().getArray("results"); final String status = event.body().getString("status"); final JsonObject j = new JsonObject(); if ("ok".equals(status) && res != null) { Long totalUser = 0L; for (Object object : res) { if (!(object instanceof JsonObject)) continue; totalUser += ((JsonObject) object).getObject("fileMetadata").getLong("size"); } final Long residualUser = ShareBigFilesServiceImpl.this.maxQuota - totalUser; final Long residualUserSize = (residualUser < 0) ? 0L : residualUser; handler.handle(j.putNumber("residualQuota", residualUserSize).putString("status", "ok")); } else { handler.handle(j.putString("status", status)); } } }); }
public void retrieves(List<String> ids, final JsonObject projection, UserInfos user, Handler<Either<String, JsonArray>> handler) { QueryBuilder builder = QueryBuilder.start("_id").in(new HashSet<String>(ids)); if (user == null) { builder.put("visibility").is(VisibilityFilter.PUBLIC.name()); } mongo.find(ShareBigFiles.SHARE_BIG_FILE_COLLECTION, MongoQueryBuilder.build(builder), null, projection, validResultsHandler(handler)); }
protected QueryBuilder appendToBuilder(final QueryBuilder builder, final FilterOp filterOp, final List<Object> rawOperands) { List<String> operands = convertOperandsToString(rawOperands); switch (filterOp) { case EQUALS: if (operands.size() == 1) { builder.is(operands.iterator().next()); } else { builder.in(operands); } break; case NOT_EQUALS: if (operands.size() == 1) { builder.notEquals(operands.iterator().next()); } else { builder.notIn(operands); } break; case LESS: builder.lessThan(operands); break; case LESS_OR_EQUAL: builder.lessThanEquals(operands); break; case GREATER: builder.greaterThan(operands); break; case GREATER_OR_EQUAL: builder.greaterThanEquals(operands); break; default: throw new IllegalArgumentException(filterOp + " no MongoDB equivalent yet"); } return builder; }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getAllNonupdatedPipelines() { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines .stream() .filter(p -> !p.areMaterialsUpdated()) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); break; case MONGODB: BasicDBObject query = (BasicDBObject) QueryBuilder.start().put("areMaterialsUpdated").is(false).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); break; } return result; }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getAllUpdatedUnpreparedPipelinesInProgress() { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines .stream() .filter(p -> p.areMaterialsUpdated() && !p.isPrepared() && (p.getStatus() == PipelineStatus.IN_PROGRESS)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); return result; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("areMaterialsUpdated").is(true).get())); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(false).get())); queriesArray.add((new QueryBuilder().start().put("status").is(PipelineStatus.IN_PROGRESS.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start().and( new QueryBuilder().start().and(queriesArray.get(0), queriesArray.get(1)).get(), queriesArray.get(2) ).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); } return result; }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getAllPreparedPipelinesInProgress() { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines .stream() .filter(p -> p.isPrepared() && (p.getStatus() == PipelineStatus.IN_PROGRESS)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); break; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(true).get())); queriesArray.add((new QueryBuilder().start().put("status").is(PipelineStatus.IN_PROGRESS.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start().and(queriesArray.get(0), queriesArray.get(1)).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); break; } return result; }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getAllPreparedAwaitingPipelines() { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAll(); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); List<Pipeline> updatedPipelines = pipelines .stream() .filter(p -> p.isPrepared() && (p.getStatus() == PipelineStatus.AWAITING)) .sorted((p1, p2) -> p1.getStartTime().compareTo(p2.getStartTime())) .collect(Collectors.toList()); result.setEntity(updatedPipelines); break; case MONGODB: List<DBObject> queriesArray = new ArrayList<>(); queriesArray.add((new QueryBuilder().start().put("isPrepared").is(true).get())); queriesArray.add((new QueryBuilder().start().put("status").is(PipelineStatus.AWAITING.toString()).get())); BasicDBObject query = (BasicDBObject) new QueryBuilder().start().and(queriesArray.get(0), queriesArray.get(1)).get(); BasicDBObject sortingFiler = new BasicDBObject("startTime", 1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler); break; } return result; }
@Override @Authorization( scope = PermissionScope.PIPELINE, type = PermissionType.VIEWER ) public ServiceResult getLastRun(String pipelineDefinitionId) { ServiceResult result = null; switch (super.DATABASE_TYPE) { case REDIS: result = this.getAllByDefinitionId(pipelineDefinitionId); List<Pipeline> pipelines = (List<Pipeline>) result.getEntity(); Pipeline lastRun = null; int lastExecutionId = 0; for (Pipeline pipeline : pipelines) { if (pipeline.getExecutionId() > lastExecutionId) { lastRun = pipeline; lastExecutionId = pipeline.getExecutionId(); } } result.setEntity(lastRun); break; case MONGODB: BasicDBObject query = (BasicDBObject) QueryBuilder.start().put("pipelineDefinitionId").is(pipelineDefinitionId).get(); BasicDBObject sortingFiler = new BasicDBObject("executionId", -1); result = this.getPipelineMongoService().QueryExecutor(query, sortingFiler, 0, 1); result.setEntity((Pipeline)((ArrayList) this.getPipelineMongoService().QueryExecutor(query, sortingFiler, 0, 1).getEntity()).get(0)); break; } return result; }
public List<ImMessage> findByTopicNameIn(Collection<String> topics, ObjectId lastMsgId) { DBObject queryCondition = QueryBuilder.start("topicName") .in(topics) .and("_id") .greaterThanEquals(lastMsgId) .get(); Iterator<DBObject> result = messageCollection.find(queryCondition).limit(100).iterator(); return MessageConverter.convert(result); }
@SuppressWarnings("unchecked") @Override public List<String> findOptionTags(Id attributeId) { QueryBuilder query = new QueryBuilder(); query.put(AttributeOption.Col.ATTRIBUTE_ID).is(attributeId); query.put(AttributeOption.Col.TAGS).not().size(0); return (List<String>) distinct(AttributeOption.class, query.get().toMap(), AttributeOption.Col.TAGS); }
@SuppressWarnings("unchecked") @Override public List<RequestContext> forScopes(List<Id> scopeIds) { QueryBuilder query = new QueryBuilder().or(QueryBuilder.start(RequestContext.Col.ID).in(scopeIds).get(), QueryBuilder.start(RequestContext.Col.STORE_ID).in(scopeIds).get(), QueryBuilder.start(RequestContext.Col.MERCHANT_ID).in(scopeIds).get()); return find(RequestContext.class, query.get().toMap()); }
private Document createQuery(QueryFilters[] allQueryFilters) { QueryBuilder retQuery = new QueryBuilder(); for (QueryFilters queryFilters : allQueryFilters) { List<DBObject> dbObjects = new LinkedList<>(); for (QueryFilter queryFilter : queryFilters.getQueryFilters()) { if (queryFilter.getFilter() instanceof String) { Pattern resourcePattern = getPatternForRegex((String) queryFilter.getFilter()); dbObjects.add(new QueryBuilder().put(queryFilter.getField()).regex(resourcePattern).get()); } else { dbObjects.add(new QueryBuilder().put(queryFilter.getField()).is(queryFilter.getFilter()).get()); } } DBObject[] dbObjectArray = dbObjects.toArray(new DBObject[dbObjects.size()]); DBObject filterQuery; if (dbObjectArray.length > 0) { if (queryFilters.getConnectingType() == QueryFilters.ConnectingType.AND) { filterQuery = new QueryBuilder().and(dbObjectArray).get(); } else { filterQuery = new QueryBuilder().or(dbObjectArray).get(); } retQuery.and(filterQuery); } } return new Document(retQuery.get().toMap()); }
@Override public CloseableIteration<Statement, QueryEvaluationException> queryInstantEqualsInstant( final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException { final QueryBuilder qb = QueryBuilder.start(INSTANT) .is(queryInstant.getAsDateTime().toDate()); return withConstraints(constraints, qb.get()); }
@Override public CloseableIteration<Statement, QueryEvaluationException> queryInstantBeforeInstant( final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException { final QueryBuilder qb = QueryBuilder.start(INSTANT) .lessThan(queryInstant.getAsDateTime().toDate()); return withConstraints(constraints, qb.get()); }
@Override public CloseableIteration<Statement, QueryEvaluationException> queryInstantAfterInstant( final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException { final QueryBuilder qb = QueryBuilder.start(INSTANT) .greaterThan(queryInstant.getAsDateTime().toDate()); return withConstraints(constraints, qb.get()); }