Search in sources :

Example 51 with ExpressionNode

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;
}
Also used : IstioDestination(org.ballerinax.kubernetes.models.istio.IstioDestination) IstioDestinationWeight(org.ballerinax.kubernetes.models.istio.IstioDestinationWeight) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) LinkedList(java.util.LinkedList)

Example 52 with ExpressionNode

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");
        }
    }
}
Also used : ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException)

Example 53 with ExpressionNode

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" } };
}
Also used : ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) ArrayList(java.util.ArrayList) DataProvider(org.testng.annotations.DataProvider)

Example 54 with ExpressionNode

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));
        }
    }
}
Also used : Connection(java.sql.Connection) IdentityProviderManagementClientException(org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 55 with ExpressionNode

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);
    }
}
Also used : Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)21 ArrayList (java.util.ArrayList)16 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)16 ExpressionNode (org.wso2.carbon.identity.core.model.ExpressionNode)15 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)12 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)8 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)7 Map (java.util.Map)6 IdentityException (org.wso2.carbon.identity.base.IdentityException)6 Attribute (org.wso2.charon3.core.attributes.Attribute)6 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)6 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)6 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)6 Connection (java.sql.Connection)5 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)5 JSONObject (org.json.JSONObject)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 Node (org.wso2.carbon.identity.core.model.Node)5 IdpSearchResult (org.wso2.carbon.idp.mgt.model.IdpSearchResult)5