in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/java/MongoDbScanner.java [359:408]
private void parseMongoDocuments(Path javaFile, List<DataEntity> dataEntities, List<Relationship> relationships) throws IOException {
Optional<CompilationUnit> cuOpt = parseJavaFile(javaFile);
if (cuOpt.isEmpty()) {
return;
}
CompilationUnit cu = cuOpt.get();
cu.findAll(ClassOrInterfaceDeclaration.class).forEach(classDecl -> {
if (!hasAnnotation(classDecl, DOCUMENT_ANNOTATION)) {
return;
}
String className = classDecl.getNameAsString();
String packageName = getPackageName(cu);
String fullyQualifiedName = packageName.isEmpty() ? className : packageName + "." + className;
String collectionName = extractCollectionName(classDecl, className);
String description = DOCUMENT_DESCRIPTION_PREFIX + className;
List<DataEntity.Field> fields = new ArrayList<>();
String primaryKey = null;
for (FieldDeclaration fieldDecl : classDecl.getFields()) {
// Check for @DBRef relationship
if (hasAnnotation(fieldDecl, DBREF_ANNOTATION)) {
extractDbRefRelationship(fieldDecl, fullyQualifiedName, relationships);
} else {
// Regular field or embedded document
DataEntity.Field field = extractField(fieldDecl);
if (field != null) {
fields.add(field);
if (hasAnnotation(fieldDecl, ID_ANNOTATION) && primaryKey == null) {
primaryKey = field.name();
}
}
}
}
DataEntity entity = new DataEntity(
fullyQualifiedName,
collectionName,
DATA_ENTITY_TYPE_COLLECTION,
fields,
primaryKey,
description
);
dataEntities.add(entity);
log.debug("Found MongoDB document: {} -> collection: {}", fullyQualifiedName, collectionName);
});
}