Search in sources :

Example 11 with Converter

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

the class RestResponseFactory method createRestVariable.

/*public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope,
                                           String id, int variableType, boolean includeBinaryValue, String baseUri){

        return createRestVariable(name, value, scope, id, variableType, includeBinaryValue, baseUri);
    }*/
public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope, String id, int variableType, boolean includeBinaryValue, String baseUri) {
    RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
    RestVariableConverter converter = null;
    RestVariable restVar = new RestVariable();
    restVar.setVariableScope(scope);
    restVar.setName(name);
    if (value != null) {
        // Try converting the value
        for (RestVariableConverter c : variableConverters) {
            if (c.getVariableType().isAssignableFrom(value.getClass())) {
                converter = c;
                break;
            }
        }
        if (converter != null) {
            converter.convertVariableValue(value, restVar);
            restVar.setType(converter.getRestTypeName());
        } else {
            // Revert to default conversion, which is the serializable/byte-array form
            if (value instanceof Byte[] || value instanceof byte[]) {
                restVar.setType(BYTE_ARRAY_VARIABLE_TYPE);
            } else {
                restVar.setType(SERIALIZABLE_VARIABLE_TYPE);
            }
            if (includeBinaryValue) {
                restVar.setValue(value);
            }
            if (variableType == VARIABLE_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_EXECUTION) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_TASK) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_PROCESS) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
            } else if (variableType == VARIABLE_HISTORY_VARINSTANCE) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_VARIABLE_INSTANCE_DATA, id));
            } else if (variableType == VARIABLE_HISTORY_DETAIL) {
                restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_DETAIL_VARIABLE_DATA, id));
            }
        }
    }
    return restVar;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)

Example 12 with Converter

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

the class PackageLoader method genRepoHierarchy.

private RepoHierarchy genRepoHierarchy(Path sourceRoot) {
    Path balHomeDir = HomeRepoUtils.createAndGetHomeReposPath();
    Path projectHiddenDir = sourceRoot.resolve(".ballerina");
    RepoHierarchyBuilder.RepoNode[] systemArr = loadSystemRepos();
    Converter<Path> converter = sourceDirectory.getConverter();
    Repo remote = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
    Repo homeCacheRepo = new CacheRepo(balHomeDir);
    Repo homeRepo = new ZipRepo(balHomeDir);
    Repo projectCacheRepo = new CacheRepo(projectHiddenDir);
    Repo projectRepo = new ZipRepo(projectHiddenDir);
    RepoHierarchyBuilder.RepoNode homeCacheNode;
    if (offline) {
        homeCacheNode = node(homeCacheRepo, systemArr);
    } else {
        homeCacheNode = node(homeCacheRepo, node(remote, systemArr));
    }
    RepoHierarchyBuilder.RepoNode nonLocalRepos = node(projectRepo, node(projectCacheRepo, homeCacheNode), node(homeRepo, homeCacheNode));
    RepoHierarchyBuilder.RepoNode fullRepoGraph;
    if (converter != null) {
        Repo programingSource = new ProgramingSourceRepo(converter);
        Repo projectSource = new ProjectSourceRepo(converter);
        fullRepoGraph = node(programingSource, node(projectSource, nonLocalRepos));
    } else {
        fullRepoGraph = nonLocalRepos;
    }
    return RepoHierarchyBuilder.build(fullRepoGraph);
}
Also used : Path(java.nio.file.Path) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)

Example 13 with Converter

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

the class PushUtils method resolvePkgPathInRemoteRepo.

/**
 * Get URI of the package from the remote repo.
 *
 * @param packageID packageID object
 * @return full URI path of the package relative to the remote repo
 */
private static String resolvePkgPathInRemoteRepo(PackageID packageID) {
    Repo<URI> remoteRepo = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
    Patten patten = remoteRepo.calculate(packageID);
    if (patten == Patten.NULL) {
        throw new BLangCompilerException("Couldn't find package " + packageID.toString());
    }
    Converter<URI> converter = remoteRepo.getConverterInstance();
    List<URI> uris = patten.convert(converter).collect(Collectors.toList());
    if (uris.isEmpty()) {
        throw new BLangCompilerException("Couldn't find package " + packageID.toString());
    }
    return uris.get(0).toString();
}
Also used : BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URI(java.net.URI)

Example 14 with Converter

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

the class PattenTest method testReduction.

@Test
public void testReduction() {
    Converter<String> mock = mockResolver("root-dir", (a, b) -> a + " > " + b, null, null);
    Patten subject = new Patten(path("hello", "world"));
    List<String> strings = subject.convert(mock).collect(Collectors.toList());
    Assert.assertEquals(strings, Collections.singletonList("root-dir > hello > world"));
}
Also used : Patten(org.wso2.ballerinalang.compiler.packaging.Patten) Test(org.testng.annotations.Test)

Example 15 with Converter

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

the class PattenTest method testBalExpansion.

@Test
public void testBalExpansion() {
    Converter<String> mock = mockResolver("project-dir", null, null, s -> Stream.of(s + " > dir1 > x.bal", s + " > y.bal", s + " > dir2 > dir3 > f.bal"));
    Patten subject = new Patten(Patten.WILDCARD_SOURCE);
    List<String> strings = subject.convert(mock).collect(Collectors.toList());
    Assert.assertEquals(strings, Arrays.asList("project-dir > dir1 > x.bal", "project-dir > y.bal", "project-dir > dir2 > dir3 > f.bal"));
}
Also used : Patten(org.wso2.ballerinalang.compiler.packaging.Patten) 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