Search in sources :

Example 6 with Converter

use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project ballerina by ballerina-lang.

the class PullCommand method execute.

@Override
public void execute() {
    if (helpFlag) {
        String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(parentCmdParser, "pull");
        outStream.println(commandUsageInfo);
        return;
    }
    if (argList == null || argList.size() == 0) {
        throw new BLangCompilerException("no package given");
    }
    if (argList.size() > 1) {
        throw new BLangCompilerException("too many arguments");
    }
    // Enable remote debugging
    if (null != debugPort) {
        System.setProperty(SYSTEM_PROP_BAL_DEBUG, debugPort);
    }
    String resourceName = argList.get(0);
    String orgName;
    String packageName;
    String version;
    // Get org-name
    int orgNameIndex = resourceName.indexOf("/");
    if (orgNameIndex != -1) {
        orgName = resourceName.substring(0, orgNameIndex);
    } else {
        throw new BLangCompilerException("no package-name provided");
    }
    // Get package name
    int packageNameIndex = resourceName.indexOf(":");
    if (packageNameIndex != -1) {
        // version is provided
        packageName = resourceName.substring(orgNameIndex + 1, packageNameIndex);
        version = resourceName.substring(packageNameIndex + 1, resourceName.length());
    } else {
        packageName = resourceName.substring(orgNameIndex + 1, resourceName.length());
        version = "*";
    }
    URI baseURI = URI.create("https://staging.central.ballerina.io:9090/");
    Repo remoteRepo = new RemoteRepo(baseURI);
    PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
    Patten patten = remoteRepo.calculate(packageID);
    if (patten != Patten.NULL) {
        Converter converter = remoteRepo.getConverterInstance();
        patten.convertToSources(converter, packageID).collect(Collectors.toList());
    } else {
        outStream.println("couldn't find package " + patten);
    }
    Runtime.getRuntime().exit(0);
}
Also used : RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) PackageID(org.ballerinalang.model.elements.PackageID) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URI(java.net.URI) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 7 with Converter

use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project ballerina by ballerina-lang.

the class RepoHierarchy method resolve.

public Resolution resolve(PackageID pkg) {
    log1(pkg);
    for (int i = 0; i < repos.length; i++) {
        Repo repo = repos[i];
        Patten patten = repo.calculate(pkg);
        if (patten != Patten.NULL) {
            Converter converter = repo.getConverterInstance();
            List<PackageSourceEntry> paths = patten.convertToSources(converter, pkg).collect(Collectors.toList());
            log2(repo, patten, paths);
            if (!paths.isEmpty()) {
                return new Resolution(getChildHierarchyForRepo(i), paths);
            }
        } else {
            log3(repo);
        }
    }
    log4();
    return Resolution.NOT_FOUND;
}
Also used : Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) PackageSourceEntry(org.ballerinalang.repository.PackageSourceEntry) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter)

Example 8 with Converter

use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project carbon-business-process by wso2.

the class RestResponseFactory method getVariableValue.

public Object getVariableValue(QueryVariable restVariable) {
    Object value;
    if (restVariable.getType() != null) {
        // Try locating a converter if the type has been specified
        RestVariableConverter converter = null;
        for (RestVariableConverter conv : variableConverters) {
            if (conv.getRestTypeName().equals(restVariable.getType())) {
                converter = conv;
                break;
            }
        }
        if (converter == null) {
            throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
        }
        RestVariable temp = new RestVariable();
        temp.setValue(restVariable.getValue());
        temp.setType(restVariable.getType());
        temp.setName(restVariable.getName());
        value = converter.getVariableValue(temp);
    } else {
        // Revert to type determined by REST-to-Java mapping when no explicit type has been provided
        value = restVariable.getValue();
    }
    return value;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 9 with Converter

use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project siddhi by wso2.

the class EventTestCase method testStreamEventConverter.

@Test
public void testStreamEventConverter() {
    Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
    Attribute volume = new Attribute("volume", Attribute.Type.INT);
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addData(volume);
    metaStreamEvent.initializeAfterWindowData();
    metaStreamEvent.addData(price);
    metaStreamEvent.addOutputData(symbol);
    // complex attribute
    metaStreamEvent.addOutputData(null);
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
    Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200, 50 });
    metaStreamEvent.addInputDefinition(streamDefinition);
    StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
    StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    converter.convertEvent(event, borrowedEvent);
    AssertJUnit.assertTrue(converter instanceof SelectiveStreamEventConverter);
    // volume
    AssertJUnit.assertEquals(1, borrowedEvent.getBeforeWindowData().length);
    // price
    AssertJUnit.assertEquals(1, borrowedEvent.getOnAfterWindowData().length);
    // symbol and avgPrice
    AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
    AssertJUnit.assertEquals(50, borrowedEvent.getBeforeWindowData()[0]);
    AssertJUnit.assertEquals(200, borrowedEvent.getOnAfterWindowData()[0]);
    AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SelectiveStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) StreamEventConverter(org.wso2.siddhi.core.event.stream.converter.StreamEventConverter) SimpleStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.SimpleStreamEventConverter) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Event(org.wso2.siddhi.core.event.Event) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) SelectiveStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Example 10 with Converter

use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project siddhi by wso2.

the class EventTestCase method testPassThroughStreamEventConverter.

@Test
public void testPassThroughStreamEventConverter() {
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
    Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
    Attribute volume = new Attribute("volume", Attribute.Type.INT);
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
    metaStreamEvent.addOutputDataAllowingDuplicate(price);
    metaStreamEvent.addOutputDataAllowingDuplicate(volume);
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
    Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200.0, 50 });
    metaStreamEvent.addInputDefinition(streamDefinition);
    StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
    StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    converter.convertEvent(event, borrowedEvent);
    AssertJUnit.assertTrue(converter instanceof ZeroStreamEventConverter);
    AssertJUnit.assertEquals(3, borrowedEvent.getOutputData().length);
    AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
    AssertJUnit.assertEquals(200.0, borrowedEvent.getOutputData()[1]);
    AssertJUnit.assertEquals(50, borrowedEvent.getOutputData()[2]);
}
Also used : ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SelectiveStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) StreamEventConverter(org.wso2.siddhi.core.event.stream.converter.StreamEventConverter) SimpleStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.SimpleStreamEventConverter) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Event(org.wso2.siddhi.core.event.Event) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)9 Patten (org.wso2.ballerinalang.compiler.packaging.Patten)8 RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)3 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)3 Event (org.wso2.siddhi.core.event.Event)3 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)3 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)3 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)3 SelectiveStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)3 ZeroStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter)3 Attribute (org.wso2.siddhi.query.api.definition.Attribute)3 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)3 URI (java.net.URI)2 Path (java.nio.file.Path)2 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)2 PackageSourceEntry (org.ballerinalang.repository.PackageSourceEntry)2 Converter (org.wso2.ballerinalang.compiler.packaging.converters.Converter)2