use of org.wso2.ballerinalang.compiler.parser.Parser in project siddhi by wso2.
the class SiddhiCompiler method parseFunctionDefinition.
public static FunctionDefinition parseFunctionDefinition(String source) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.definition_function_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (FunctionDefinition) eval.visit(tree);
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project siddhi by wso2.
the class SiddhiCompiler method parseTimeConstantDefinition.
public static TimeConstant parseTimeConstantDefinition(String source) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.time_value();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (TimeConstant) eval.visit(tree);
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project siddhi by wso2.
the class SiddhiCompiler method parseStoreQuery.
public static StoreQuery parseStoreQuery(String storeQuery) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(storeQuery);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.store_query_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (StoreQuery) eval.visit(tree);
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionThrottlePolicyToDTO.
/**
* Converts a single Subscription Policy model into REST API DTO
*
* @param policy Subscription Policy model object
* @return Converted Subscription policy REST API DTO object
* @throws SubscriptionThrottlePolicyException - If error occurs
*/
public static SubscriptionThrottlePolicyDTO fromSubscriptionThrottlePolicyToDTO(SubscriptionPolicy policy) throws SubscriptionThrottlePolicyException {
try {
SubscriptionThrottlePolicyDTO policyDTO = new SubscriptionThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
SubscriptionPolicy subscriptionPolicy = policy;
policyDTO.setBillingPlan(subscriptionPolicy.getBillingPlan());
policyDTO.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
policyDTO.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
policyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
byte[] customAttributes = subscriptionPolicy.getCustomAttributes();
if (customAttributes != null && customAttributes.length > 0) {
List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
JSONParser parser = new JSONParser();
JSONArray attributeArray = (JSONArray) parser.parse(new String(customAttributes, StandardCharsets.UTF_8));
for (Object attributeObj : attributeArray) {
JSONObject attribute = (JSONObject) attributeObj;
CustomAttributeDTO customAttributeDTO = CommonThrottleMappingUtil.getCustomAttribute(attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_NAME).toString(), attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_VALUE).toString());
customAttributeDTOs.add(customAttributeDTO);
}
policyDTO.setCustomAttributes(customAttributeDTOs);
}
if (policy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
}
return policyDTO;
} catch (ParseException | UnsupportedThrottleLimitTypeException e) {
throw new SubscriptionThrottlePolicyException(e.getMessage(), e);
}
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImpl method getEmailOfUser.
@Override
public String getEmailOfUser(String userId) throws IdentityProviderException {
Response userResponse = scimServiceStub.getUser(userId);
String userEmail;
if (userResponse == null) {
String errorMessage = "Error occurred while retrieving Id of user " + userId + ". Error : Response is null.";
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
if (userResponse.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
String responseBody = userResponse.body().toString();
JsonParser parser = new JsonParser();
JsonObject parsedResponseBody = (JsonObject) parser.parse(responseBody);
userEmail = parsedResponseBody.get("emails").toString().replaceAll("[\\[\\]\"]", "");
log.debug("Email {} of user {} is successfully retrieved from SCIM endpoint.", userEmail, parsedResponseBody.get(USERNAME).getAsString());
} else {
String errorMessage = "Error occurred while retrieving Id of user " + userId + ". Error : " + getErrorMessage(userResponse);
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
return userEmail;
}
Aggregations