@Override public void removeByUserIdAndAppTokenAndSchemaVersion(String userId, String appToken, Integer schemaVersion) { remove(query(where(USER_CONF_USER_ID) .is(userId) .and(USER_CONF_APP_TOKEN) .is(appToken) .and(USER_CONF_SCHEMA_VERSION) .is(schemaVersion))); LOG.debug("Removed user specific configuration by user id {}, application token {} " + "and schema version {}", userId, appToken, schemaVersion); } }
@Override public EndpointSpecificConfiguration findByEndpointKeyHashAndConfigurationVersion(byte[] endpointKeyHash, int configurationVersion) { LOG.debug("Try to find endpoint specific configuration by endpointKeyHash {} and configurationVersion {}", endpointKeyHash, configurationVersion); EndpointSpecificConfiguration configuration = findOne(query(where(EP_SPECIFIC_CONFIGURATION_KEY_HASH).is(endpointKeyHash) .and(EP_CONFIGURATION_VERSION).is(configurationVersion))); LOG.trace("Found {} endpoint specific configuration", configuration); return configuration; }
@Override public MongoEndpointUserConfiguration findByUserIdAndAppTokenAndSchemaVersion( String userId, String appToken, Integer schemaVersion ) { LOG.debug("Searching for user specific configuration by user id {}, " + "application token {} and schema version {}", userId, appToken, schemaVersion); MongoEndpointUserConfiguration userConfiguration = findOne(query(where(USER_CONF_USER_ID) .is(userId).and(USER_CONF_APP_TOKEN) .is(appToken) .and(USER_CONF_SCHEMA_VERSION) .is(schemaVersion))); if (LOG.isTraceEnabled()) { LOG.debug("[{},{},{}] Search result: {}.", userId, appToken, schemaVersion, userConfiguration); } else { LOG.debug("[{},{},{}] Search result: {}.", userId, appToken, schemaVersion, userConfiguration != null); } return userConfiguration; }
@Override public Optional<MongoCredentials> find(String applicationId, String credentialsId) { LOG.debug("Searching for credentials by application ID [{}] and credentials ID [{}]", applicationId, credentialsId); Query query = Query.query(Criteria.where(MongoModelConstants.CREDENTIALS_ID) .is(credentialsId) .and(MongoModelConstants.APPLICATION_ID) .is(applicationId)); return Optional.ofNullable(this.findOne(query)); }
@Override public void removeByExternalIdAndTenantId(String externalId, String tenantId) { LOG.debug("Remove user by external uid [{}] and tenant id [{}] ", externalId, tenantId); remove(query(where(EP_USER_EXTERNAL_ID) .is(externalId) .and(EP_USER_TENANT_ID) .is(tenantId))); }
@Override public void remove(String applicationId, String credentialsId) { LOG.debug("Removing credentials [{}] from application [{}]", credentialsId, applicationId); Query query = Query.query(Criteria.where(MongoModelConstants.CREDENTIALS_ID) .is(credentialsId) .and(MongoModelConstants.APPLICATION_ID) .is(applicationId)); this.remove(query); } }
@Override public MongoEndpointUser findByExternalIdAndTenantId(String externalId, String tenantId) { LOG.debug("Find user by external uid [{}] and tenant id [{}] ", externalId, tenantId); return findOne(query(where(EP_USER_EXTERNAL_ID) .is(externalId).and(EP_USER_TENANT_ID) .is(tenantId))); }
@Override public void removeByEndpointKeyHashAndConfigurationVersion(byte[] endpointKeyHash, Integer confSchemaVersion) { LOG.debug("Remove endpoint specific configuration by endpoint key hash [{}] ", endpointKeyHash); mongoTemplate.remove( query(where(EP_SPECIFIC_CONFIGURATION_KEY_HASH).is(endpointKeyHash) .and(EP_CONFIGURATION_VERSION).is(confSchemaVersion)), getCollectionName()); }
@Override public List<MongoNotification> findNotificationsByTopicIdAndVersionAndStartSecNum( String topicId, int seqNumber, int sysNfVersion, int userNfVersion ) { LOG.debug("Find notifications by topic id [{}], sequence number start [{}], " + "system schema version [{}], user schema version [{}]", topicId, seqNumber, sysNfVersion, userNfVersion); return find(query(where(NF_TOPIC_ID) .is(topicId) .and(NF_SEQ_NUM) .gt(seqNumber) .orOperator(where(NF_VERSION) .is(sysNfVersion) .and(NF_TYPE) .is(SYSTEM), where(NF_VERSION) .is(userNfVersion) .and(NF_TYPE) .is(USER)))); }
@Override public Optional<MongoCredentials> updateStatus(String applicationId, String credentialsId, CredentialsStatus status) { LOG.debug("Settings status [{}] for credentials [{}] in application [{}]", status, credentialsId, applicationId); updateFirst( Query.query(Criteria.where(MongoModelConstants.CREDENTIALS_ID) .is(credentialsId) .and(MongoModelConstants.APPLICATION_ID) .is(applicationId)), Update.update(MongoModelConstants.CREDENTIAL_STATUS, status)); return this.find(applicationId, credentialsId); }
@Override protected Criteria and(Part part, Criteria base, Iterator<Object> iterator) { if (base == null) { return create(part, iterator); } PersistentPropertyPath<MongoPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty()); MongoPersistentProperty property = path.getLeafProperty(); return from(part, property, base.and(path.toDotPath()), iterator); }
@Override public Query getQueryForVersion() { MongoPersistentProperty idProperty = entity.getRequiredIdProperty(); MongoPersistentProperty property = entity.getRequiredVersionProperty(); return new Query(Criteria.where(idProperty.getName()).is(getId())// .and(property.getName()).is(getVersion())); }
@Override @ManagedAttribute public int getMessageCountForAllMessageGroups() { Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) .and(MessageDocumentFields.GROUP_ID).exists(true)); long count = this.template.count(query, this.collectionName); Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range"); return (int) count; }
private static Query whereMessageIdIsAndGroupIdIs(UUID id, Object groupId) { return new Query(Criteria.where("headers.id").is(id).and(GROUP_ID_KEY).is(groupId)); }
/** * Replace an existing metadata entry {@code value} with a new one. Otherwise does nothing. * Performs {@code updateFirst} if a document for the provided {@code key} and {@code oldValue} * exists in the {@link #collectionName}. * @param key the metadata entry key * @param oldValue the metadata entry old value to replace * @param newValue the metadata entry new value to put * @return {@code true} if replace was successful, {@code false} otherwise. * @see MongoTemplate#updateFirst(Query, Update, String) */ @Override public boolean replace(String key, String oldValue, String newValue) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(oldValue, "'oldValue' must not be empty."); Assert.hasText(newValue, "'newValue' must not be empty."); Query query = new Query(Criteria.where(ID_FIELD).is(key).and(VALUE).is(oldValue)); return this.template.updateFirst(query, Update.update(VALUE, newValue), this.collectionName) .getModifiedCount() > 0; }
@Override @ManagedAttribute public int getMessageCountForAllMessageGroups() { Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) .and(MessageDocumentFields.GROUP_ID).exists(true)); long count = this.mongoTemplate.count(query, this.collectionName); Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range"); return (int) count; }
@Override protected Criteria and(Part part, Criteria base, Iterator<Object> iterator) { if (base == null) { return create(part, iterator); } PersistentPropertyPath<MongoPersistentProperty> path = context.getPersistentPropertyPath(part.getProperty()); MongoPersistentProperty property = path.getLeafProperty(); return from(part, property, base.and(path.toDotPath()), iterator); }
@Override public long getMessageCount() { Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true) .and(MessageDocumentFields.GROUP_ID).exists(false)); return this.mongoTemplate.getCollection(this.collectionName).countDocuments(query.getQueryObject()); }
@Override public Query getQueryForVersion() { MongoPersistentProperty idProperty = entity.getRequiredIdProperty(); MongoPersistentProperty property = entity.getRequiredVersionProperty(); return new Query(Criteria.where(idProperty.getName()).is(getId())// .and(property.getName()).is(getVersion())); }
@Override public Iterator<RateLimit> findAsyncAfter(long timestamp) { final Query query = Query.query(Criteria.where(FIELD_ASYNC).is(true).and(FIELD_UPDATED_AT).gte(timestamp)); return mongoOperations.find(query, Document.class, RATE_LIMIT_COLLECTION) .stream() .map(this::convert) .iterator(); }