use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource in project legend-engine by finos.
the class ExternalSourceSpecificationParseTreeWalker method visitUrlStreamExternalSourceSpecification.
public ExternalSource visitUrlStreamExternalSourceSpecification(ExternalSourceSpecificationSourceCode code, ExternalSourceSpecificationParserGrammar.UrlStreamExternalSourceSpecificationContext ctx) {
UrlStreamExternalSource extSource = new UrlStreamExternalSource();
extSource.sourceInformation = code.getSourceInformation();
ExternalSourceSpecificationParserGrammar.UrlStreamUrlContext urlCtx = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.urlStreamUrl(), "url", code.getSourceInformation());
extSource.url = PureGrammarParserUtility.fromGrammarString(urlCtx.STRING().getText(), true);
return extSource;
}
use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource in project legend-engine by finos.
the class ExternalFormatGrammarComposerExtension method getExtraExternalSourceSpecificationComposers.
@Override
public List<Function2<ExternalSource, PureGrammarComposerContext, String>> getExtraExternalSourceSpecificationComposers() {
return Lists.mutable.with((specification, context) -> {
if (specification instanceof UrlStreamExternalSource) {
UrlStreamExternalSource spec = (UrlStreamExternalSource) specification;
int baseIndentation = 1;
return "UrlStream\n" + context.getIndentationString() + getTabString(1) + "{\n" + context.getIndentationString() + getTabString(2) + "url: " + convertString(spec.url, true) + ";\n" + context.getIndentationString() + getTabString(1) + "}";
}
return null;
});
}
use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource in project legend-engine by finos.
the class ServiceTestGenerationHelper method getNullableTestConnection.
private static Optional<Connection> getNullableTestConnection(Connection connection, Runtime parentRuntime, String mappingPath, Pair<PureModelContextData, PureModel> pureModelPairs, StoreConnections parentStoreConnection, Function<String, String> testDataAccessor, String testData, String idTestDataAccessorResult) {
if (connection instanceof ConnectionPointer) {
String connectionFullPath = ((ConnectionPointer) connection).connection;
PackageableElement found = Iterate.detect(pureModelPairs.getOne().getElements(), e -> connectionFullPath.equals(e.getPath()));
if (!(found instanceof PackageableConnection)) {
throw new RuntimeException("Can't find connection '" + connectionFullPath + "'");
}
connection = ((PackageableConnection) found).connectionValue;
}
if (connection instanceof JsonModelConnection) {
JsonModelConnection conn = (JsonModelConnection) connection;
JsonModelConnection testJsonModelConnection = new JsonModelConnection();
testJsonModelConnection._class = conn._class;
testJsonModelConnection.element = conn.element != null ? conn.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
String executorId = conn.url.split(":")[1];
String connectionTestData = resolveTestData(executorId, idTestDataAccessorResult, testDataAccessor, testData);
if (idTestDataAccessorResult != null) {
((JsonModelConnection) connection).url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
}
testJsonModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(connectionTestData.getBytes(StandardCharsets.UTF_8));
return Optional.of(conn);
}
if (connection instanceof XmlModelConnection) {
XmlModelConnection conn = (XmlModelConnection) connection;
XmlModelConnection testXmlModelConnection = new XmlModelConnection();
testXmlModelConnection._class = conn._class;
testXmlModelConnection.element = conn.element != null ? conn.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
String executorId = conn.url.split(":")[1];
String connectionTestData = resolveTestData(executorId, idTestDataAccessorResult, testDataAccessor, testData);
if (idTestDataAccessorResult != null) {
((XmlModelConnection) connection).url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
}
testXmlModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(connectionTestData.getBytes(StandardCharsets.UTF_8));
return Optional.of(testXmlModelConnection);
}
if (connection instanceof ExternalFormatConnection) {
ExternalFormatConnection conn = (ExternalFormatConnection) connection;
ExternalFormatConnection testConn = new ExternalFormatConnection();
testConn.element = conn.element;
UrlStreamExternalSource source = new UrlStreamExternalSource();
source.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
testConn.externalSource = source;
return Optional.of(testConn);
}
if (connection instanceof ModelChainConnection) {
return Optional.of(connection);
}
if (connection instanceof DatabaseConnection) {
List<String> sql = getSql(parentRuntime, mappingPath, idTestDataAccessorResult, pureModelPairs.getTwo());
return Optional.of(newRelationalConnection(connection, idTestDataAccessorResult, sql));
}
String element = connection.element != null ? connection.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
Connection testConnectionFromFactories = getTestConnectionFromFactories(connection, idTestDataAccessorResult == null ? testData : idTestDataAccessorResult, element);
return testConnectionFromFactories != null ? Optional.of(testConnectionFromFactories) : Optional.empty();
}
Aggregations