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;
}
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);
}
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();
}
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"));
}
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"));
}
Aggregations