use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldRetrieveListDocumentList.
@Test
public void shouldRetrieveListDocumentList() {
DocumentEntity entity = entityManager.insert(createDocumentList());
Document key = entity.find(CouchDBConstant.ID).get();
DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldSaveMap.
@Test
public void shouldSaveMap() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
String id = UUID.randomUUID().toString();
entity.add("properties", Collections.singletonMap("hallo", "Welt"));
entity.add("scope", "xxx");
entity.add("_id", id);
entityManager.insert(entity);
final DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id).and("scope").eq("xxx").build();
final Optional<DocumentEntity> optional = entityManager.select(query).findFirst();
Assertions.assertTrue(optional.isPresent());
DocumentEntity documentEntity = optional.get();
Document properties = documentEntity.find("properties").get();
Assertions.assertNotNull(properties);
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity entity = getEntity();
entity.remove(CouchDBConstant.ID);
entity = entityManager.insert(entity);
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchEntry method toEntity.
DocumentEntity toEntity() {
Document id = Document.of(ID_FIELD, this.id);
List<Document> documents = map.keySet().stream().map(k -> toDocument(k, map)).collect(Collectors.toList());
DocumentEntity entity = DocumentEntity.of(collection, documents);
entity.remove(ID_FIELD);
entity.add(id);
return entity;
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class HttpExecute method toEntity.
private DocumentEntity toEntity(Map<String, Object> jsonEntity) {
DocumentEntity entity = DocumentEntity.of(jsonEntity.get(CouchDBConstant.ENTITY).toString());
entity.addAll(Documents.of(jsonEntity));
entity.remove(CouchDBConstant.ENTITY);
return entity;
}
Aggregations