@Override public T getBody() { if (delegate.getBody() == null || targetType.equals(delegate.getBody().getClass())) { return targetType.cast(delegate.getBody()); } Object messageBody = delegate.getBody(); if (ClassUtils.isAssignable(Document.class, messageBody.getClass())) { return converter.read(targetType, (Document) messageBody); } if (converter.getConversionService().canConvert(messageBody.getClass(), targetType)) { return converter.getConversionService().convert(messageBody, targetType); } throw new IllegalArgumentException( String.format("No converter found capable of converting %s to %s", messageBody.getClass(), targetType)); }
private Object doGetConverted(Document fullDocument) { Object result = CONVERTED_UPDATER.get(this); if (result != null) { return result; } if (ClassUtils.isAssignable(Document.class, fullDocument.getClass())) { result = converter.read(targetType, fullDocument); return CONVERTED_UPDATER.compareAndSet(this, null, result) ? result : CONVERTED_UPDATER.get(this); } if (converter.getConversionService().canConvert(fullDocument.getClass(), targetType)) { result = converter.getConversionService().convert(fullDocument, targetType); return CONVERTED_UPDATER.compareAndSet(this, null, result) ? result : CONVERTED_UPDATER.get(this); } throw new IllegalArgumentException(String.format("No converter found capable of converting %s to %s", fullDocument.getClass(), targetType)); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { for (Document dbo : collection.find(dbk)) { String key = (String) dbo.get(ENTITY_FIELD_NAME); if (log.isDebugEnabled()) { log.debug("Processing key: {}", key); } if (!changeSet.getValues().containsKey(key)) { String className = (String) dbo.get(ENTITY_FIELD_CLASS); if (className == null) { throw new DataIntegrityViolationException( "Unble to convert property " + key + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); } Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader()); Object value = mongoTemplate.getConverter().read(clazz, dbo); if (log.isDebugEnabled()) { log.debug("Adding to ChangeSet: {}", key); } changeSet.set(key, value); } } return null; } });
@Override public List<MongoEndpointNotification> findNotificationsByKeyHash(final byte[] keyHash) { LOG.debug("Find unicast notifications by endpoint key hash [{}] ", keyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)).getQueryObject(); DBCursor cursor = mongoTemplate.getDb().getCollection(getCollectionName()).find(dbObject); List<MongoEndpointNotification> endpointNotifications = new ArrayList<>(); while (cursor.hasNext()) { endpointNotifications.add(mongoTemplate.getConverter() .read(MongoEndpointNotification.class, cursor.next())); } return endpointNotifications; }
@Override public MongoEndpointProfile findByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile by endpoint key hash [{}] ", endpointKeyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH) .is(endpointKeyHash)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoTopicListEntry findByHash(byte[] hash) { LOG.debug("Find topic list entry by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointConfiguration findByHash(final byte[] hash) { LOG.debug("Find endpoint configuration by hash [{}] ", hash); DBObject dbObject = query(where(ID).is(hash)).getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Override public MongoEndpointProfile findByAccessToken(String endpointAccessToken) { LOG.debug("Find endpoint profile by access token [{}] ", endpointAccessToken); DBObject dbObject = query(where(EP_ACCESS_TOKEN).is(endpointAccessToken)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
return read(targetType, sourceDocument); } else { if (!ClassUtils.isAssignable(targetType, value.getClass())) {
@Override public T getBody() { if (delegate.getBody() == null || targetType.equals(delegate.getBody().getClass())) { return targetType.cast(delegate.getBody()); } Object messageBody = delegate.getBody(); if (ClassUtils.isAssignable(Document.class, messageBody.getClass())) { return converter.read(targetType, (Document) messageBody); } if (converter.getConversionService().canConvert(messageBody.getClass(), targetType)) { return converter.getConversionService().convert(messageBody, targetType); } throw new IllegalArgumentException( String.format("No converter found capable of converting %s to %s", messageBody.getClass(), targetType)); }
private Object doGetConverted(Document fullDocument) { Object result = CONVERTED_UPDATER.get(this); if (result != null) { return result; } if (ClassUtils.isAssignable(Document.class, fullDocument.getClass())) { result = converter.read(targetType, fullDocument); return CONVERTED_UPDATER.compareAndSet(this, null, result) ? result : CONVERTED_UPDATER.get(this); } if (converter.getConversionService().canConvert(fullDocument.getClass(), targetType)) { result = converter.getConversionService().convert(fullDocument, targetType); return CONVERTED_UPDATER.compareAndSet(this, null, result) ? result : CONVERTED_UPDATER.get(this); } throw new IllegalArgumentException(String.format("No converter found capable of converting %s to %s", fullDocument.getClass(), targetType)); }
return read(targetType, sourceDocument); } else { if (!ClassUtils.isAssignable(targetType, value.getClass())) {
public Object toObject(Class clazz, DBObject dbObject) { if (clazz.equals(ValueWrapper.class)) { return dbObject.get("value"); } return mongoTemplate.getConverter().read(clazz, dbObject); }
private Serializable readObject(DBObject dbObject) throws ClassNotFoundException { TypeInformation<?> information = mapper.getTypeMapper().readType(dbObject); if (information == null) { return null; } return (Serializable) mapper.read(information.getType(), dbObject); }
HistoryRecord<R> history = mappingConverter.read(HistoryRecord.class, histDbObject);
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { for (Document dbo : collection.find(dbk)) { String key = (String) dbo.get(ENTITY_FIELD_NAME); if (log.isDebugEnabled()) { log.debug("Processing key: {}", key); } if (!changeSet.getValues().containsKey(key)) { String className = (String) dbo.get(ENTITY_FIELD_CLASS); if (className == null) { throw new DataIntegrityViolationException( "Unble to convert property " + key + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); } Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader()); Object value = mongoTemplate.getConverter().read(clazz, dbo); if (log.isDebugEnabled()) { log.debug("Adding to ChangeSet: {}", key); } changeSet.set(key, value); } } return null; } });
@Override public FSFile getFile(String fileId) throws ObjectNotFoundException { GridFSDBFile mongoFile = gridFsTemplate.findOne(filenameQuery(fileId)); if (mongoFile==null) { throw new ObjectNotFoundException("File ["+ fileId +"] not found"); } FileMetadata fileMetadata = mongoConverter.read(FileMetadata.class, mongoFile.getMetaData()); return new MongoFSFile(mongoFile, fileMetadata.getFileName()); }