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

Add entityPath property to LegendWriteEntityRequest #261

Merged
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 @@ -17,7 +17,6 @@
package org.finos.legend.engine.ide.lsp.extension.sdlc;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.Sets;
Expand Down Expand Up @@ -147,15 +146,15 @@ public Map<Path, String> convertToOneElementPerFile(Path rootFolder, DocumentSta
}

@Override
public Map.Entry<String, String> contentToPureText(Map<String, ?> content)
public String contentToPureText(Map<String, ?> content)
{
PackageableElement packageableElement = this.objectMapper.convertValue(content, PackageableElement.class);
String pureText = this.pureGrammarComposer.renderPureModelContextData(PureModelContextData.newBuilder().withElement(packageableElement).build());
if (pureText.startsWith("###"))
{
pureText = pureText.substring(pureText.indexOf('\n') + 1);
}
return Pair.of(packageableElement.getPath(), pureText.strip());
return pureText.strip();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ default String description()
*/
Map<Path, String> convertToOneElementPerFile(Path rootFolder, DocumentState documentState);

Map.Entry<String, String> contentToPureText(Map<String, ?> content);
String contentToPureText(Map<String, ?> content);

/**
* Return the mapping of type to classifier path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,8 @@ public CompletableFuture<Void> writeEntity(LegendWriteEntityRequest request)
{
LegendSDLCFeature handler = this.getSDLCHandler();

Map.Entry<String, String> pathToText = handler.contentToPureText(request.getContent());

String path = pathToText.getKey();
String pureText = pathToText.getValue();
String path = request.getEntityPath();
String pureText = handler.contentToPureText(request.getContent());

LegendEntity entity = entities.stream().filter(x -> x.getPath().equals(path)).findAny().orElseThrow(() -> new RuntimeException("Element not found in project: " + path));
TextLocation location = entity.getLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@

public class LegendWriteEntityRequest
{
private String entityPath;
private Map<String, ?> content;

public LegendWriteEntityRequest()
{

}

public LegendWriteEntityRequest(Map<String, ?> content)
public LegendWriteEntityRequest(String entityPath, Map<String, ?> content)
{
this.entityPath = entityPath;
this.content = content;
}

public String getEntityPath()
{
return entityPath;
}

public Map<String, ?> getContent()
{
return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ void writeEntity() throws Exception
" \"package\": \"one\"\n" +
"}";

writeEntity(classEntityToWrite);
writeEntity("one::element", classEntityToWrite);

String mappingToWrite = "{\n" +
" \"_type\": \"mapping\",\n" +
Expand Down Expand Up @@ -566,7 +566,7 @@ void writeEntity() throws Exception
" \"package\": \"vscodelsp::test\"\n" +
"}";

writeEntity(mappingToWrite);
writeEntity("vscodelsp::test::EmployeeMapping", mappingToWrite);

String diagramEntityToWrite = "{\n" +
" \"_type\": \"diagram\",\n" +
Expand All @@ -590,7 +590,7 @@ void writeEntity() throws Exception
" \"propertyViews\": []\n" +
"}";

writeEntity(diagramEntityToWrite);
writeEntity("showcase::northwind::model::NorthwindModelDiagram1", diagramEntityToWrite);

List<ApplyWorkspaceEditParams> workspaceEdits = extension.getClient().workspaceEdits;
Assertions.assertEquals(3, workspaceEdits.size());
Expand Down Expand Up @@ -679,10 +679,10 @@ private static String getJson(List<Either<TextDocumentEdit, ResourceOperation>>
return new GsonBuilder().setPrettyPrinting().create().toJson(mappingElementDocumentChanges.get(0).getLeft());
}

private static void writeEntity(String classEntityToWrite) throws Exception
private static void writeEntity(String entityPath, String classEntityToWrite) throws Exception
{
Map<String, ?> entityContent = new Gson().fromJson(classEntityToWrite, Map.class);
LegendWriteEntityRequest request = new LegendWriteEntityRequest(entityContent);
LegendWriteEntityRequest request = new LegendWriteEntityRequest(entityPath, entityContent);
extension.futureGet(extension.getServer().getLegendLanguageService().writeEntity(request));
}
}
Loading