use of org.wso2.charon.core.objects.Group in project ballerina by ballerina-lang.
the class TestAnnotationProcessor method process.
@Override
public void process(FunctionNode functionNode, List<AnnotationAttachmentNode> annotations) {
// to avoid processing those, we have to have below check.
if (!suite.getSuiteName().equals(functionNode.getPosition().getSource().getPackageName())) {
return;
}
// traverse through the annotations of this function
for (AnnotationAttachmentNode attachmentNode : annotations) {
String annotationName = attachmentNode.getAnnotationName().getValue();
String functionName = functionNode.getName().getValue();
if (BEFORE_SUITE_ANNOTATION_NAME.equals(annotationName)) {
suite.addBeforeSuiteFunction(functionName);
} else if (AFTER_SUITE_ANNOTATION_NAME.equals(annotationName)) {
suite.addAfterSuiteFunction(functionName);
} else if (BEFORE_EACH_ANNOTATION_NAME.equals(annotationName)) {
suite.addBeforeEachFunction(functionName);
} else if (AFTER_EACH_ANNOTATION_NAME.equals(annotationName)) {
suite.addAfterEachFunction(functionName);
} else if (MOCK_ANNOTATION_NAME.equals(annotationName)) {
String[] vals = new String[2];
// If package property not present the package is .
// TODO: when default values are supported in annotation struct we can remove this
vals[0] = ".";
if (attachmentNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) attachmentNode.getExpression()).getKeyValuePairs();
attributes.forEach(attributeNode -> {
String name = attributeNode.getKey().toString();
String value = attributeNode.getValue().toString();
if (PACKAGE.equals(name)) {
vals[0] = value;
} else if (FUNCTION.equals(name)) {
vals[1] = value;
}
});
suite.addMockFunction(vals[0] + MOCK_ANNOTATION_DELIMITER + vals[1], functionName);
}
} else if (TEST_ANNOTATION_NAME.equals(annotationName)) {
Test test = new Test();
test.setTestName(functionName);
AtomicBoolean shouldSkip = new AtomicBoolean();
AtomicBoolean groupsFound = new AtomicBoolean();
List<String> groups = registry.getGroups();
boolean shouldIncludeGroups = registry.shouldIncludeGroups();
if (attachmentNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) attachmentNode.getExpression()).getKeyValuePairs();
attributes.forEach(attributeNode -> {
String name = attributeNode.getKey().toString();
// Check if enable property is present in the annotation
if (TEST_ENABLE_ANNOTATION_NAME.equals(name) && "false".equals(attributeNode.getValue().toString())) {
// If enable is false, disable the test, no further processing is needed
shouldSkip.set(true);
return;
}
// Check whether user has provided a group list
if (groups != null && !groups.isEmpty()) {
// check if groups attribute is present in the annotation
if (GROUP_ANNOTATION_NAME.equals(name)) {
if (attributeNode.getValue() instanceof BLangArrayLiteral) {
BLangArrayLiteral values = (BLangArrayLiteral) attributeNode.getValue();
boolean isGroupPresent = isGroupAvailable(groups, values.exprs.stream().map(node -> node.toString()).collect(Collectors.toList()));
if (shouldIncludeGroups) {
// include only if the test belong to one of these groups
if (!isGroupPresent) {
// skip the test if this group is not defined in this test
shouldSkip.set(true);
return;
}
} else {
// exclude only if the test belong to one of these groups
if (isGroupPresent) {
// skip if this test belongs to one of the excluded groups
shouldSkip.set(true);
return;
}
}
groupsFound.set(true);
}
}
}
if (VALUE_SET_ANNOTATION_NAME.equals(name)) {
test.setDataProvider(attributeNode.getValue().toString());
}
if (BEFORE_FUNCTION.equals(name)) {
test.setBeforeTestFunction(attributeNode.getValue().toString());
}
if (AFTER_FUNCTION.equals(name)) {
test.setAfterTestFunction(attributeNode.getValue().toString());
}
if (DEPENDS_ON_FUNCTIONS.equals(name)) {
if (attributeNode.getValue() instanceof BLangArrayLiteral) {
BLangArrayLiteral values = (BLangArrayLiteral) attributeNode.getValue();
values.exprs.stream().map(node -> node.toString()).forEach(test::addDependsOnTestFunction);
}
}
});
}
if (groups != null && !groups.isEmpty() && !groupsFound.get() && shouldIncludeGroups) {
// if the user has asked to run only a specific list of groups and this test doesn't have
// that group, we should skip the test
shouldSkip.set(true);
}
if (!shouldSkip.get()) {
suite.addTests(test);
}
} else {
// disregard this annotation
}
}
}
use of org.wso2.charon.core.objects.Group in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
@Override
public void visit(BLangGroupBy groupBy) {
List<? extends ExpressionNode> varList = groupBy.getVariables();
Iterator<? extends ExpressionNode> iterator = varList.iterator();
groupByClause = new StringBuilder("group by ");
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) iterator.next();
addVarRefToClauseBuilder(simpleVarRef, groupByClause);
while (iterator.hasNext()) {
simpleVarRef = (BLangSimpleVarRef) iterator.next();
groupByClause.append(", ");
addVarRefToClauseBuilder(simpleVarRef, groupByClause);
}
}
use of org.wso2.charon.core.objects.Group in project ballerina by ballerina-lang.
the class SqlQueryBuilder method visit.
@Override
public void visit(BLangGroupBy groupBy) {
List<? extends ExpressionNode> varList = groupBy.getVariables();
Iterator<? extends ExpressionNode> iterator = varList.iterator();
groupByClause = new StringBuilder("group by ");
BLangExpression expr = (BLangExpression) iterator.next();
expr.accept(this);
groupByClause.append(exprStack.pop());
while (iterator.hasNext()) {
expr = (BLangExpression) iterator.next();
groupByClause.append(", ");
expr.accept(this);
groupByClause.append(exprStack.pop());
}
}
use of org.wso2.charon.core.objects.Group in project charon by wso2.
the class RoleResourceManager method doPatchRole.
private Role doPatchRole(Role oldRole, SCIMResourceTypeSchema roleSchema, String patchRequest) throws CharonException, BadRequestException, NotImplementedException, InternalErrorException {
// Make a copy of the original group.
Role originalRole = (Role) CopyUtil.deepCopy(oldRole);
Role copyOfOldRole = (Role) CopyUtil.deepCopy(oldRole);
Role patchedRole = null;
List<PatchOperation> opList = getDecoder().decodeRequest(patchRequest);
for (PatchOperation operation : opList) {
switch(operation.getOperation()) {
case SCIMConstants.OperationalConstants.ADD:
if (patchedRole == null) {
patchedRole = (Role) PatchOperationUtil.doPatchAdd(operation, getDecoder(), oldRole, copyOfOldRole, roleSchema);
} else {
patchedRole = (Role) PatchOperationUtil.doPatchAdd(operation, getDecoder(), patchedRole, copyOfOldRole, roleSchema);
}
copyOfOldRole = (Role) CopyUtil.deepCopy(patchedRole);
break;
case SCIMConstants.OperationalConstants.REMOVE:
if (patchedRole == null) {
patchedRole = (Role) PatchOperationUtil.doPatchRemove(operation, oldRole, copyOfOldRole, roleSchema);
} else {
patchedRole = (Role) PatchOperationUtil.doPatchRemove(operation, patchedRole, copyOfOldRole, roleSchema);
}
copyOfOldRole = (Role) CopyUtil.deepCopy(patchedRole);
break;
case SCIMConstants.OperationalConstants.REPLACE:
if (patchedRole == null) {
patchedRole = (Role) PatchOperationUtil.doPatchReplace(operation, getDecoder(), oldRole, copyOfOldRole, roleSchema);
} else {
patchedRole = (Role) PatchOperationUtil.doPatchReplace(operation, getDecoder(), patchedRole, copyOfOldRole, roleSchema);
}
copyOfOldRole = (Role) CopyUtil.deepCopy(patchedRole);
break;
default:
throw new BadRequestException("Unknown operation.", ResponseCodeConstants.INVALID_SYNTAX);
}
}
return (Role) ServerSideValidator.validateUpdatedSCIMObject(originalRole, patchedRole, roleSchema);
}
use of org.wso2.charon.core.objects.Group in project charon by wso2.
the class ResourceTypeResourceManager method buildCombinedResourceType.
/*
* This combines the user and group resource type AbstractSCIMObjects and build a
* one root AbstractSCIMObjects
*
* @param userObject
* @param groupObject
* @return
* @throws CharonException
*/
private AbstractSCIMObject buildCombinedResourceType(AbstractSCIMObject userObject, AbstractSCIMObject groupObject) throws CharonException {
AbstractSCIMObject rootObject = new AbstractSCIMObject();
MultiValuedAttribute multiValuedAttribute = new MultiValuedAttribute(SCIMConstants.ListedResourceSchemaConstants.RESOURCES);
userObject.getSchemaList().clear();
userObject.setSchema(SCIMConstants.RESOURCE_TYPE_SCHEMA_URI);
multiValuedAttribute.setAttributePrimitiveValue(userObject);
groupObject.getSchemaList().clear();
groupObject.setSchema(SCIMConstants.RESOURCE_TYPE_SCHEMA_URI);
multiValuedAttribute.setAttributePrimitiveValue(groupObject);
rootObject.setAttribute(multiValuedAttribute);
rootObject.setSchema(SCIMConstants.LISTED_RESOURCE_CORE_SCHEMA_URI);
// Using a hard coded value of 2 since currently we only support two items in the list.
SimpleAttribute totalResults = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.TOTAL_RESULTS, 2);
rootObject.setAttribute(totalResults);
return rootObject;
}
Aggregations