use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testServiceGetStringPayload.
@Test(description = "Test GetStringPayload function within a service")
public void testServiceGetStringPayload() {
String value = "ballerina";
String path = "/hello/GetStringPayload/" + value;
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), value);
}
use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.
the class TypeChecker method checkFunctionInvocationExpr.
private void checkFunctionInvocationExpr(BLangInvocation iExpr, BStructType structType) {
String funcName = iExpr.name.value;
Name uniqueFuncName = names.fromString(Symbols.getAttachedFuncSymbolName(structType.tsymbol.name.value, funcName));
BPackageSymbol packageSymbol = (BPackageSymbol) structType.tsymbol.owner;
BSymbol funcSymbol = symResolver.lookupMemberSymbol(iExpr.pos, packageSymbol.scope, this.env, uniqueFuncName, SymTag.FUNCTION);
if (funcSymbol == symTable.notFoundSymbol) {
// Check functions defined within the struct.
Name functionName = names.fromString(Symbols.getAttachedFuncSymbolName(iExpr.expr.symbol.type.tsymbol.name.value, iExpr.name.value));
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, functionName, iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol) {
// Check, any function pointer in struct field with given name.
funcSymbol = symResolver.resolveStructField(iExpr.pos, env, names.fromIdNode(iExpr.name), iExpr.expr.symbol.type.tsymbol);
if (funcSymbol == symTable.notFoundSymbol || funcSymbol.type.tag != TypeTags.INVOKABLE) {
dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION_IN_STRUCT, funcName, structType);
resultTypes = getListWithErrorTypes(expTypes.size());
return;
}
if ((funcSymbol.flags & Flags.ATTACHED) != Flags.ATTACHED) {
iExpr.functionPointerInvocation = true;
}
}
} else {
// Attached function found
// Check for the explicit initializer function invocation
BStructSymbol.BAttachedFunction initializerFunc = ((BStructSymbol) structType.tsymbol).initializerFunc;
if (initializerFunc != null && initializerFunc.funcName.value.equals(funcName)) {
dlog.error(iExpr.pos, DiagnosticCode.STRUCT_INITIALIZER_INVOKED, structType.tsymbol.toString());
}
}
iExpr.symbol = funcSymbol;
checkInvocationParamAndReturnType(iExpr);
}
use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.
the class TreeVisitor method isCursorWithinEndpointDef.
/**
* Check whether the cursor is within the endpoint definition node.
* @param nodePosition Diagnostic position of the current node
* @return {@link Boolean} whether the cursor is within the node or not
*/
private boolean isCursorWithinEndpointDef(DiagnosticPos nodePosition) {
int line = documentServiceContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
int column = documentServiceContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
int nodeSLine = nodePosition.sLine;
int nodeELine = nodePosition.eLine;
int nodeSCol = nodePosition.sCol;
int nodeECol = nodePosition.eCol;
return (line > nodeSLine && line < nodeELine) || (line > nodeSLine && line == nodeELine && column < nodeECol) || (line == nodeSLine && column > nodeSCol && line < nodeELine) || (line == nodeSLine && line == nodeELine && column > nodeSCol && column < nodeECol);
}
use of org.wso2.siddhi.query.api.aggregation.Within in project charon by wso2.
the class PatchOperationUtil method doPatchRemoveWithFiltersForLevelTwo.
/*
*
* @param oldResource
* @param attributeParts
* @param expressionNode
* @return
* @throws BadRequestException
* @throws CharonException
*/
private static AbstractSCIMObject doPatchRemoveWithFiltersForLevelTwo(AbstractSCIMObject oldResource, String[] attributeParts, ExpressionNode expressionNode) throws BadRequestException, CharonException {
Attribute attribute = oldResource.getAttribute(attributeParts[0]);
if (attribute != null) {
if (attribute.getMultiValued()) {
List<Attribute> subValues = ((MultiValuedAttribute) attribute).getAttributeValues();
if (subValues != null) {
for (Attribute subValue : subValues) {
Map<String, Attribute> subAttributes = ((ComplexAttribute) subValue).getSubAttributesList();
// this map is to avoid concurrent modification exception.
Map<String, Attribute> tempSubAttributes = (Map<String, Attribute>) CopyUtil.deepCopy(subAttributes);
for (Iterator<Attribute> iterator = tempSubAttributes.values().iterator(); iterator.hasNext(); ) {
Attribute subAttribute = iterator.next();
if (subAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) subAttribute).getValue().equals(expressionNode.getValue())) {
Attribute removingAttribute = subAttributes.get(attributeParts[1]);
if (removingAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
if (removingAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || removingAttribute.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
((ComplexAttribute) subValue).removeSubAttribute(removingAttribute.getName());
}
}
}
}
}
if (subValues.size() == 0) {
// if the attribute has no values, make it unassigned
oldResource.deleteAttribute(attribute.getName());
}
}
} else if (attribute.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
// this is only valid for extension
Attribute subAttribute = attribute.getSubAttribute(attributeParts[1]);
if (subAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
List<Attribute> subValues = ((MultiValuedAttribute) (subAttribute)).getAttributeValues();
if (subValues != null) {
for (Iterator<Attribute> subValueIterator = subValues.iterator(); subValueIterator.hasNext(); ) {
Attribute subValue = subValueIterator.next();
Map<String, Attribute> subValuesSubAttribute = ((ComplexAttribute) subValue).getSubAttributesList();
for (Iterator<Attribute> iterator = subValuesSubAttribute.values().iterator(); iterator.hasNext(); ) {
Attribute subSubAttribute = iterator.next();
if (subSubAttribute.getName().equals(expressionNode.getAttributeValue())) {
if (((SimpleAttribute) (subSubAttribute)).getValue().equals(expressionNode.getValue())) {
if (subValue.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || subValue.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
subValueIterator.remove();
}
}
}
}
}
// if the attribute has no values, make it unassigned
if (((MultiValuedAttribute) (subAttribute)).getAttributeValues().size() == 0) {
((ComplexAttribute) attribute).removeSubAttribute(subAttribute.getName());
}
}
} else {
throw new BadRequestException("Attribute : " + expressionNode.getAttributeValue() + " " + "is not a multivalued attribute.", ResponseCodeConstants.INVALID_PATH);
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[0] + " " + "in the current resource", ResponseCodeConstants.INVALID_PATH);
}
return oldResource;
}
use of org.wso2.siddhi.query.api.aggregation.Within in project charon by wso2.
the class PatchOperationUtil method doPatchRemoveWithFiltersForLevelThree.
/*
*
* @param oldResource
* @param attributeParts
* @param expressionNode
* @return
* @throws BadRequestException
* @throws CharonException
*/
private static AbstractSCIMObject doPatchRemoveWithFiltersForLevelThree(AbstractSCIMObject oldResource, String[] attributeParts, ExpressionNode expressionNode) throws BadRequestException, CharonException {
Attribute attribute = oldResource.getAttribute(attributeParts[0]);
if (attribute != null) {
Attribute subAttribute = attribute.getSubAttribute(attributeParts[1]);
if (subAttribute != null) {
if (subAttribute.getMultiValued()) {
List<Attribute> subValues = ((MultiValuedAttribute) subAttribute).getAttributeValues();
if (subValues != null) {
for (Attribute subValue : subValues) {
Map<String, Attribute> subSubAttributes = ((ComplexAttribute) subValue).getSubAttributesList();
// this map is to avoid concurrent modification exception.
Map<String, Attribute> tempSubSubAttributes = (Map<String, Attribute>) CopyUtil.deepCopy(subSubAttributes);
for (Iterator<Attribute> iterator = tempSubSubAttributes.values().iterator(); iterator.hasNext(); ) {
Attribute subSubAttribute = iterator.next();
if (subSubAttribute.getName().equals(expressionNode.getAttributeValue())) {
Attribute removingAttribute = subSubAttributes.get(attributeParts[2]);
if (removingAttribute == null) {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[2] + " " + "within the attribute " + attributeParts[1], ResponseCodeConstants.INVALID_PATH);
}
if (removingAttribute.getMutability().equals(SCIMDefinitions.Mutability.READ_ONLY) || removingAttribute.getRequired().equals(true)) {
throw new BadRequestException("Can not remove a required attribute or a read-only attribute", ResponseCodeConstants.MUTABILITY);
} else {
((ComplexAttribute) subValue).removeSubAttribute(removingAttribute.getName());
}
}
}
}
if (subValues.size() == 0) {
// if the attribute has no values, make it unassigned
((ComplexAttribute) attribute).removeSubAttribute(subAttribute.getName());
}
}
} else {
throw new BadRequestException("Attribute : " + attributeParts[1] + " " + "is not a multivalued attribute.", ResponseCodeConstants.INVALID_PATH);
}
} else {
throw new BadRequestException("No such sub attribute with the name : " + attributeParts[1] + " " + "within the attribute " + attributeParts[0], ResponseCodeConstants.INVALID_PATH);
}
} else {
throw new BadRequestException("No such attribute with the name : " + attributeParts[0] + " " + "in the current resource", ResponseCodeConstants.INVALID_PATH);
}
return oldResource;
}
Aggregations