use of org.wso2.carbon.identity.core.model.ExpressionNode in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processRoutesAnnotation.
/**
* Process routes of http annotation to a model.
*
* @param routeArray The list of routes.
* @return A list of istio destination weight models.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<IstioDestinationWeight> processRoutesAnnotation(BLangListConstructorExpr routeArray) throws KubernetesPluginException {
List<IstioDestinationWeight> destinationWeights = new LinkedList<>();
for (ExpressionNode expression : routeArray.getExpressions()) {
BLangRecordLiteral routeFields = (BLangRecordLiteral) expression;
IstioDestinationWeight destinationWeight = new IstioDestinationWeight();
for (BLangRecordLiteral.BLangRecordKeyValueField routeField : convertRecordFields(routeFields.getFields())) {
switch(DestinationWeightConfig.valueOf(routeField.getKey().toString())) {
case destination:
BLangRecordLiteral destinationFields = (BLangRecordLiteral) routeField.getValue();
IstioDestination destination = processDestinationAnnotation(destinationFields);
destinationWeight.setDestination(destination);
break;
case weight:
destinationWeight.setWeight(getIntValue(routeField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + routeField.getKey().toString());
}
}
destinationWeights.add(destinationWeight);
}
return destinationWeights;
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project charon by wso2.
the class PatchOperationUtil method doPatchReplaceOnPathWithFilters.
/*
* This method is to do patch replace for level three attributes with a filter and path value present.
* @param oldResource
* @param copyOfOldResource
* @param schema
* @param decoder
* @param operation
* @param parts
* @throws NotImplementedException
* @throws BadRequestException
* @throws CharonException
* @throws JSONException
* @throws InternalErrorException
*/
private static void doPatchReplaceOnPathWithFilters(AbstractSCIMObject oldResource, SCIMResourceTypeSchema schema, JSONDecoder decoder, PatchOperation operation, String[] parts) throws NotImplementedException, BadRequestException, CharonException, JSONException, InternalErrorException {
if (parts.length != 1) {
// currently we only support simple filters here.
String[] filterParts = parts[1].split(" ");
ExpressionNode expressionNode = new ExpressionNode();
expressionNode.setAttributeValue(filterParts[0]);
expressionNode.setOperation(filterParts[1]);
// According to the specification filter attribute value specified with quotation mark, so we need to
// remove it if exists.
expressionNode.setValue(filterParts[2].replaceAll("^\"|\"$", ""));
if (expressionNode.getOperation().equalsIgnoreCase((SCIMConstants.OperationalConstants.EQ).trim())) {
if (parts.length == 3) {
parts[0] = parts[0] + parts[2];
}
String[] attributeParts = getAttributeParts(parts[0]);
if (attributeParts.length == 1) {
doPatchReplaceWithFiltersForLevelOne(oldResource, attributeParts, expressionNode, operation, schema, decoder);
} else if (attributeParts.length == 2) {
doPatchReplaceWithFiltersForLevelTwo(oldResource, attributeParts, expressionNode, operation, schema, decoder);
} else if (attributeParts.length == 3) {
doPatchReplaceWithFiltersForLevelThree(oldResource, attributeParts, expressionNode, operation, schema, decoder);
}
} else {
throw new NotImplementedException("Only Eq filter is supported");
}
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAOTest method getIdPsSearchWithExpressionNodesExceptionData.
@DataProvider
public Object[][] getIdPsSearchWithExpressionNodesExceptionData() {
ExpressionNode expressionNode1 = new ExpressionNode();
List<ExpressionNode> expressionNodesList1 = new ArrayList<>();
expressionNodesList1.add(expressionNode1);
ExpressionNode expressionNode2 = new ExpressionNode();
List<ExpressionNode> expressionNodesList2 = new ArrayList<>();
expressionNode2.setAttributeValue("InvalidAttribute");
expressionNode2.setOperation("eq");
expressionNode2.setValue("testIdP1");
expressionNodesList2.add(expressionNode2);
ExpressionNode expressionNode3 = new ExpressionNode();
List<ExpressionNode> expressionNodesList3 = new ArrayList<>();
expressionNode3.setAttributeValue("description");
expressionNode3.setOperation("InvalidOperation");
expressionNode3.setValue("2");
expressionNodesList3.add(expressionNode3);
return new Object[][] { { SAMPLE_TENANT_ID, expressionNodesList1, 2, 0, "WrongOrder", "NAME", "ServerException" }, { SAMPLE_TENANT_ID, expressionNodesList1, 2, 0, "DESC", "WrongBy", "ServerException" }, { SAMPLE_TENANT_ID, expressionNodesList2, 1, 0, "ASC", "NAME", "ClientException" }, { SAMPLE_TENANT_ID, expressionNodesList3, 1, 0, "ASC", "NAME", "ClientException" } };
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAOTest method testGetIdPsSearchWithExpressionNodesException.
@Test(dataProvider = "getIdPsSearchWithExpressionNodesExceptionData")
public void testGetIdPsSearchWithExpressionNodesException(int tenantId, List<ExpressionNode> expressionNodes, int limit, int offset, String sortOrder, String sortBy, String exceptionType) throws Exception {
mockStatic(IdentityDatabaseUtil.class);
try (Connection connection = getConnection(DB_NAME)) {
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
addTestIdps();
if (exceptionType.equals("ServerException")) {
assertThrows(IdentityProviderManagementServerException.class, () -> idPManagementDAO.getIdPsSearch(tenantId, expressionNodes, limit, offset, sortOrder, sortBy));
} else if (exceptionType.equals("ClientException")) {
assertThrows(IdentityProviderManagementClientException.class, () -> idPManagementDAO.getIdPsSearch(tenantId, expressionNodes, limit, offset, sortOrder, sortBy));
}
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAOTest method testGetIdPsSearchWithAttributes.
@Test(dataProvider = "getIdPsSearchWithAttributesData")
public void testGetIdPsSearchWithAttributes(int tenantId, List<ExpressionNode> expressionNodes, int limit, int offset, String order, String sortBy, List<String> attributes, int count) throws Exception {
mockStatic(IdentityDatabaseUtil.class);
try (Connection connection = getConnection(DB_NAME)) {
when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
addTestIdps();
List<IdentityProvider> idps = idPManagementDAO.getIdPsSearch(tenantId, expressionNodes, limit, offset, order, sortBy, attributes);
assertEquals(idps.size(), count);
}
}
Aggregations