Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get semantic model when it is used #563

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,16 @@
public class DataMapManager {

private final WorkspaceManager workspaceManager;
private final SemanticModel semanticModel;
private final Document document;
private final Gson gson;

public DataMapManager(WorkspaceManager workspaceManager, SemanticModel semanticModel, Document document) {
public DataMapManager(WorkspaceManager workspaceManager, Document document) {
this.workspaceManager = workspaceManager;
this.semanticModel = semanticModel;
this.document = document;
this.gson = new Gson();
}

public JsonElement getTypes(JsonElement node, String propertyKey) {
public JsonElement getTypes(JsonElement node, String propertyKey, SemanticModel semanticModel) {
FlowNode flowNode = gson.fromJson(node, FlowNode.class);
Codedata codedata = flowNode.codedata();
NodeKind nodeKind = codedata.node();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public CompletableFuture<DataMapperTypesResponse> types(DataMapperTypesRequest r
return response;
}

DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, semanticModel.get(),
document.get());
response.setType(dataMapManager.getTypes(request.flowNode(), request.propertyKey()));
DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, document.get());
response.setType(dataMapManager.getTypes(request.flowNode(), request.propertyKey(),
semanticModel.get()));
} catch (Throwable e) {
response.setError(e);
}
Expand All @@ -90,14 +90,12 @@ public CompletableFuture<DataMapperModelResponse> mappings(DataMapperModelReques
try {
Path filePath = Path.of(request.filePath());
Project project = this.workspaceManager.loadProject(filePath);
Optional<SemanticModel> semanticModel = this.workspaceManager.semanticModel(filePath);
Optional<Document> document = this.workspaceManager.document(filePath);
if (semanticModel.isEmpty() || document.isEmpty()) {
if (document.isEmpty()) {
return response;
}

DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, semanticModel.get(),
document.get());
DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, document.get());
response.setMappingsModel(dataMapManager.getMappings(request.flowNode(), request.position(),
request.propertyKey(), Path.of(request.filePath()), request.targetField(), project));
} catch (Throwable e) {
Expand All @@ -112,7 +110,7 @@ public CompletableFuture<DataMapperSourceResponse> getSource(DataMapperSourceReq
return CompletableFuture.supplyAsync(() -> {
DataMapperSourceResponse response = new DataMapperSourceResponse();
try {
DataMapManager dataMapManager = new DataMapManager(null, null, null);
DataMapManager dataMapManager = new DataMapManager(null, null);
response.setSource(dataMapManager.getSource(request.mappings(), request.flowNode(),
request.targetField()));
} catch (Throwable e) {
Expand All @@ -134,7 +132,7 @@ public CompletableFuture<DataMapperSourceResponse> convertToQuery(DataMapperQuer
if (semanticModel.isEmpty() || document.isEmpty()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(null, null, document.get());
DataMapManager dataMapManager = new DataMapManager(null, document.get());
response.setSource(dataMapManager.getQuery(request.flowNode(), request.targetField(),
Path.of(request.filePath()), request.position(), project));
} catch (Throwable e) {
Expand All @@ -151,13 +149,11 @@ public CompletableFuture<DataMapperVisualizeResponse> visualizable(DataMapperVis
try {
Path filePath = Path.of(request.filePath());
Project project = this.workspaceManager.loadProject(filePath);
Optional<SemanticModel> semanticModel = this.workspaceManager.semanticModel(filePath);
Optional<Document> document = this.workspaceManager.document(filePath);
if (semanticModel.isEmpty() || document.isEmpty()) {
if (document.isEmpty()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(workspaceManager, semanticModel.get(),
document.get());
DataMapManager dataMapManager = new DataMapManager(workspaceManager, document.get());
response.setVisualizableProperties(dataMapManager.getVisualizableProperties(request.flowNode(),
project, filePath, request.position()));
} catch (Throwable e) {
Expand All @@ -179,8 +175,7 @@ public CompletableFuture<DataMapperAddElementResponse> addElement(DataMapperAddE
if (semanticModel.isEmpty() || document.isEmpty()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(workspaceManager, semanticModel.get(),
document.get());
DataMapManager dataMapManager = new DataMapManager(workspaceManager, document.get());
response.setSource(dataMapManager.addElement(request.flowNode(), request.propertyKey(),
Path.of(request.filePath()), request.targetField(), project, request.position()));
} catch (Throwable e) {
Expand Down
Loading