Search in sources :

Example 56 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-business-process by wso2.

the class TaskOperationsImpl method getRenderingTypes.

/**
 * Applies to both tasks and notifications.
 * Returns the rendering  types available for the task or notification.
 *
 * @param taskIdURI : task identifier
 * @return : Array of QNames
 * @throws IllegalArgumentFault
 */
public QName[] getRenderingTypes(URI taskIdURI) throws IllegalArgumentFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {

            public TaskDAO call() throws Exception {
                HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
                HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
                TaskDAO task = daoConn.getTask(taskId);
                validateTaskTenant(task);
                return task;
            }
        });
        HumanTaskBaseConfiguration taskConfiguration = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId()).getTaskConfiguration(QName.valueOf(task.getName()));
        List<QName> renderingTypes = taskConfiguration.getRenderingTypes();
        QName[] types = new QName[renderingTypes.size()];
        types = renderingTypes.toArray(types);
        return types;
    } catch (Exception ex) {
        log.error(ex);
        throw new IllegalArgumentFault(ex);
    }
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) QName(javax.xml.namespace.QName) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 57 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class GraphQLSchemaDefinition method extractGraphQLTypeList.

/**
 * Extract GraphQL Types and Fields from given schema
 *
 * @param schema GraphQL Schema
 * @return list of all types and fields
 */
public List<GraphqlSchemaType> extractGraphQLTypeList(String schema) {
    List<GraphqlSchemaType> typeList = new ArrayList<>();
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeRegistry = schemaParser.parse(schema);
    Map<java.lang.String, TypeDefinition> list = typeRegistry.types();
    for (Map.Entry<String, TypeDefinition> entry : list.entrySet()) {
        if (entry.getValue() instanceof ObjectTypeDefinition) {
            GraphqlSchemaType graphqlSchemaType = new GraphqlSchemaType();
            List<String> fieldList = new ArrayList<>();
            graphqlSchemaType.setType(entry.getValue().getName());
            for (FieldDefinition fieldDef : ((ObjectTypeDefinition) entry.getValue()).getFieldDefinitions()) {
                fieldList.add(fieldDef.getName());
            }
            graphqlSchemaType.setFieldList(fieldList);
            typeList.add(graphqlSchemaType);
        }
    }
    return typeList;
}
Also used : ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) FieldDefinition(graphql.language.FieldDefinition) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaParser(graphql.schema.idl.SchemaParser) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) GraphqlSchemaType(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlSchemaType)

Example 58 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class GraphqlQueryAnalysisMappingUtil method fromDTOtoValidatedGraphqlComplexityInfo.

/**
 * Converts a GraphQLQueryComplexityInfo DTO object into a GraphqlComplexityInfo object. During this process a
 * basic validation is done comparing with the types of the schema
 *
 * @param graphQLQueryComplexityInfoDTO GraphQLQueryComplexityInfoDTO object
 * @param schema                        GraphQL Schema
 * @return a new GraphqlComplexityInfo object corresponding to given GraphQLQueryComplexityInfoDTO object
 */
public static GraphqlComplexityInfo fromDTOtoValidatedGraphqlComplexityInfo(GraphQLQueryComplexityInfoDTO graphQLQueryComplexityInfoDTO, String schema) {
    SchemaParser schemaParser = new SchemaParser();
    Set<String> complexityInfoTypeSet = schemaParser.parse(schema).types().keySet();
    GraphqlComplexityInfo graphqlComplexityInfo = new GraphqlComplexityInfo();
    List<CustomComplexityDetails> customComplexityDetailsList = new ArrayList<CustomComplexityDetails>();
    for (GraphQLCustomComplexityInfoDTO graphQLCustomComplexityInfoDTO : graphQLQueryComplexityInfoDTO.getList()) {
        String complexityType = graphQLCustomComplexityInfoDTO.getType();
        if (complexityInfoTypeSet.contains(complexityType)) {
            CustomComplexityDetails customComplexityDetails = new CustomComplexityDetails();
            customComplexityDetails.setType(complexityType);
            customComplexityDetails.setField(graphQLCustomComplexityInfoDTO.getField());
            customComplexityDetails.setComplexityValue(graphQLCustomComplexityInfoDTO.getComplexityValue());
            customComplexityDetailsList.add(customComplexityDetails);
        } else {
            log.error("Complexity Type : " + complexityType + " is not included in the original schema. Hence " + "skipped.");
        }
    }
    graphqlComplexityInfo.setList(customComplexityDetailsList);
    return graphqlComplexityInfo;
}
Also used : GraphqlComplexityInfo(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo) ArrayList(java.util.ArrayList) GraphQLCustomComplexityInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO) SchemaParser(graphql.schema.idl.SchemaParser) CustomComplexityDetails(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails)

Example 59 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class RegistrationServiceImpl method createOAuthApp.

/**
 * Method to create a OAuth App with client credentials
 *
 * @param appName    application name
 * @param grantTypes grant types
 * @param userName   username of the application
 * @return created Oauth App
 */
private OAuthConsumerAppDTO createOAuthApp(String appName, OAuthApplicationInfo applicationInfo, String grantTypes, String userName) {
    OAuthConsumerAppDTO createdApp = null;
    OAuthAdminService oauthAdminService = new OAuthAdminService();
    OAuthConsumerAppDTO oauthConsumerAppDTO = new OAuthConsumerAppDTO();
    oauthConsumerAppDTO.setApplicationName(appName);
    if (StringUtils.isNotBlank(applicationInfo.getCallBackURL())) {
        oauthConsumerAppDTO.setCallbackUrl(applicationInfo.getCallBackURL());
    }
    oauthConsumerAppDTO.setUsername(userName);
    oauthConsumerAppDTO.setOAuthVersion(OAuthConstants.OAuthVersions.VERSION_2);
    oauthConsumerAppDTO.setGrantTypes(grantTypes.trim());
    try {
        boolean isHashDisabled = OAuth2Util.isHashDisabled();
        if (isHashDisabled) {
            // Creating the Oauth app
            oauthAdminService.registerOAuthApplicationData(oauthConsumerAppDTO);
            // Retrieving the created OAuth application
            createdApp = oauthAdminService.getOAuthApplicationDataByAppName(oauthConsumerAppDTO.getApplicationName());
        } else {
            createdApp = oauthAdminService.registerAndRetrieveOAuthApplicationData(oauthConsumerAppDTO);
        }
    } catch (IdentityOAuthAdminException e) {
        log.error("Error occurred while creating the OAuth app", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Created OAuth App " + appName);
    }
    return createdApp;
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)

Example 60 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project carbon-apimgt by wso2.

the class AlertMgtUtils method toAlertTypeDTO.

/**
 * Convert the alert types to alert type dtos.
 *
 * @param alertTypes: The alert types map.
 * @return A list of AlertTypeDTOs.
 */
public static List<AlertTypeDTO> toAlertTypeDTO(Map<Integer, String> alertTypes) {
    List<AlertTypeDTO> alertTypeDTOList = new ArrayList<>();
    if (alertTypes != null) {
        for (Map.Entry entry : alertTypes.entrySet()) {
            AlertTypeDTO alertTypeDTO = new AlertTypeDTO();
            alertTypeDTO.setId((Integer) entry.getKey());
            alertTypeDTO.setName(entry.getValue().toString());
            alertTypeDTOList.add(alertTypeDTO);
        }
    }
    return alertTypeDTOList;
}
Also used : ArrayList(java.util.ArrayList) AlertTypeDTO(org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3