Skip to content

Commit

Permalink
Merge pull request #532 from KavinduZoysa/data-mapped-model
Browse files Browse the repository at this point in the history
Implement datamapper
  • Loading branch information
KavinduZoysa authored Jan 9, 2025
2 parents 76cdf8e + ef1d73c commit 9c82ad6
Show file tree
Hide file tree
Showing 125 changed files with 12,191 additions and 16 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@

import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.flowmodelgenerator.core.DataMapManager;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperAddElementRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperModelRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperQueryConvertRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperSourceRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperTypesRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperVisualizeRequest;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperAddElementResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperModelResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperSourceResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperTypesResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperVisualizeResponse;
import io.ballerina.projects.Document;
import io.ballerina.projects.Project;
import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService;
import org.ballerinalang.langserver.commons.workspace.WorkspaceManager;
Expand Down Expand Up @@ -57,16 +68,125 @@ public CompletableFuture<DataMapperTypesResponse> types(DataMapperTypesRequest r
Path filePath = Path.of(request.filePath());
this.workspaceManager.loadProject(filePath);
Optional<SemanticModel> semanticModel = this.workspaceManager.semanticModel(filePath);
if (semanticModel.isEmpty()) {
Optional<Document> document = this.workspaceManager.document(filePath);
if (semanticModel.isEmpty() || document.isEmpty()) {
return response;
}

DataMapManager dataMapManager = new DataMapManager(semanticModel.get());
DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, semanticModel.get(),
document.get());
response.setType(dataMapManager.getTypes(request.flowNode(), request.propertyKey()));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}

@JsonRequest
public CompletableFuture<DataMapperModelResponse> mappings(DataMapperModelRequest request) {
return CompletableFuture.supplyAsync(() -> {
DataMapperModelResponse response = new DataMapperModelResponse();
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()) {
return response;
}

DataMapManager dataMapManager = new DataMapManager(this.workspaceManager, semanticModel.get(),
document.get());
response.setMappingsModel(dataMapManager.getMappings(request.flowNode(), request.position(),
request.propertyKey(), Path.of(request.filePath()), request.targetField(), project));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}

@JsonRequest
public CompletableFuture<DataMapperSourceResponse> getSource(DataMapperSourceRequest request) {
return CompletableFuture.supplyAsync(() -> {
DataMapperSourceResponse response = new DataMapperSourceResponse();
try {
DataMapManager dataMapManager = new DataMapManager(null, null, null);
response.setSource(dataMapManager.getSource(request.mappings(), request.flowNode(),
request.targetField()));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}

@JsonRequest
public CompletableFuture<DataMapperSourceResponse> convertToQuery(DataMapperQueryConvertRequest request) {
return CompletableFuture.supplyAsync(() -> {
DataMapperSourceResponse response = new DataMapperSourceResponse();
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()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(null, null, document.get());
response.setSource(dataMapManager.getQuery(request.flowNode(), request.targetField(),
Path.of(request.filePath()), request.position(), project));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}

@JsonRequest
public CompletableFuture<DataMapperVisualizeResponse> visualizable(DataMapperVisualizeRequest request) {
return CompletableFuture.supplyAsync(() -> {
DataMapperVisualizeResponse response = new DataMapperVisualizeResponse();
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()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(workspaceManager, semanticModel.get(),
document.get());
response.setVisualizableProperties(dataMapManager.getVisualizableProperties(request.flowNode(),
project, filePath, request.position()));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}

@JsonRequest
public CompletableFuture<DataMapperAddElementResponse> addElement(DataMapperAddElementRequest request) {
return CompletableFuture.supplyAsync(() -> {
DataMapperAddElementResponse response = new DataMapperAddElementResponse();
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()) {
return response;
}
DataMapManager dataMapManager = new DataMapManager(workspaceManager, semanticModel.get(),
document.get());
response.setSource(dataMapManager.addElement(request.flowNode(), request.propertyKey(),
Path.of(request.filePath()), request.targetField(), project, request.position()));
} catch (Throwable e) {
response.setError(e);
}
return response;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.request;

import com.google.gson.JsonElement;
import io.ballerina.tools.text.LinePosition;

/**
* Represents a request to get the data mapper model for types.
*
* @param filePath file path of the source file
* @param flowNode flow node of form
* @param position position to add the element
* @param propertyKey The property that needs to consider to get the type
* @param targetField The target field that needs to consider to get the type
* @since 2.0.0
*/
public record DataMapperAddElementRequest(String filePath, JsonElement flowNode, LinePosition position,
String propertyKey, String targetField) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.request;

import com.google.gson.JsonElement;
import io.ballerina.tools.text.LinePosition;

/**
* Represents a request to get the data mapper model for types.
*
* @param filePath file path of the source file
* @param flowNode diagram node
* @param position position of the end of previous statement
* @param propertyKey The property that needs to consider to get the type
* @param targetField The target field that needs to consider to get the type
*
* @since 2.0.0
*/
public record DataMapperModelRequest(String filePath, JsonElement flowNode, LinePosition position, String propertyKey,
String targetField) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.request;

import com.google.gson.JsonElement;
import io.ballerina.tools.text.LinePosition;

/**
* Represents a request to get the data mapper model for types.
*
* @param filePath file path of the source file
* @param flowNode flow node of form
* @param position position of the cursor
* @param propertyKey The property that needs to consider to get the type
* @param targetField The target field that needs to consider to get the type
*
* @since 2.0.0
*/
public record DataMapperQueryConvertRequest(String filePath, JsonElement flowNode, LinePosition position,
String propertyKey, String targetField) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.request;

import com.google.gson.JsonElement;

/**
* Represents a request to get the data mapper model for types.
*
* @param filePath file path of the source file
* @param flowNode flow node of form
* @param mappings data mappings
* @param propertyKey The property that needs to consider to get the type
* @param targetField The target field that needs to consider to get the type
*
* @since 2.0.0
*/
public record DataMapperSourceRequest(String filePath, JsonElement flowNode, JsonElement mappings, String propertyKey,
String targetField) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.request;

import com.google.gson.JsonElement;
import io.ballerina.tools.text.LinePosition;

/**
* Represents a request to get the data mapper model for types.
*
* @param filePath file path of the source file
* @param flowNode flow node of form
* @param position position of the cursor
*
* @since 2.0.0
*/
public record DataMapperVisualizeRequest(String filePath, JsonElement flowNode, LinePosition position) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.response;

/**
* Represents the response containing data mapper model data mapping.
*
* @since 2.0.0
*/
public class DataMapperAddElementResponse extends AbstractFlowModelResponse {

// TODO: Add diagram and mappings
private String source;

public DataMapperAddElementResponse() {

}

public void setSource(String source) {
this.source = source;
}

public String getSource() {
return this.source;
}
}
Loading

0 comments on commit 9c82ad6

Please sign in to comment.