Search in sources :

Example 91 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class UserSubstitutionService method getSubstitute.

/**
 * Return the substitute info for the given user in path parameter
 * @param user
 * @return SubstituteInfoResponse
 * @throws URISyntaxException
 */
@GET
@Path("/{user}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getSubstitute(@PathParam("user") String user) throws UserStoreException {
    if (!subsFeatureEnabled) {
        return Response.status(405).build();
    }
    user = getTenantAwareUser(user);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (!loggedInUser.equals(user) && !isUserAuthorizedForSubstitute(loggedInUser)) {
        throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
    }
    SubstitutesDataModel model = UserSubstitutionUtils.getSubstituteOfUser(user, tenantId);
    if (model != null) {
        SubstituteInfoResponse response = new SubstituteInfoResponse();
        response.setSubstitute(model.getSubstitute());
        response.setAssignee(model.getUser());
        response.setEnabled(model.isEnabled());
        response.setStartTime(model.getSubstitutionStart());
        response.setEndTime(model.getSubstitutionEnd());
        return Response.ok(response).build();
    } else {
        return Response.status(404).build();
    }
}
Also used : SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) BPMNForbiddenException(org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException)

Example 92 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class UserSubstitutionUtils method getPaginatedModelFromRequest.

/**
 * Prepare the paginated data model for a substitution query
 * @param propertiesMap
 * @param tenantId
 * @return PaginatedSubstitutesDataModel
 */
private static PaginatedSubstitutesDataModel getPaginatedModelFromRequest(Map<String, String> propertiesMap, int tenantId) {
    PaginatedSubstitutesDataModel model = new PaginatedSubstitutesDataModel();
    if (propertiesMap.get(SubstitutionQueryProperties.SUBSTITUTE) != null) {
        model.setSubstitute(propertiesMap.get(SubstitutionQueryProperties.SUBSTITUTE));
    }
    if (propertiesMap.get(SubstitutionQueryProperties.USER) != null) {
        model.setUser(propertiesMap.get(SubstitutionQueryProperties.USER));
    }
    String enabled = propertiesMap.get(SubstitutionQueryProperties.ENABLED);
    if (enabled != null) {
        if (enabled.equalsIgnoreCase("true")) {
            model.setEnabled(true);
        } else if (enabled.equalsIgnoreCase("false")) {
            model.setEnabled(false);
        } else {
            throw new ActivitiIllegalArgumentException("Invalid parameter " + enabled + " for enabled property.");
        }
    }
    model.setTenantId(tenantId);
    int start = Integer.parseInt(propertiesMap.get(SubstitutionQueryProperties.START));
    int size = Integer.parseInt(propertiesMap.get(SubstitutionQueryProperties.SIZE));
    model.setStart(start);
    model.setSize(size);
    model.setOrder(propertiesMap.get(SubstitutionQueryProperties.ORDER));
    model.setSort(propertiesMap.get(SubstitutionQueryProperties.SORT));
    return model;
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel)

Example 93 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class ActivitiDAO method querySubstituteInfoWithoutEnabled.

/**
 * Return the list of substitute info based on query parameters except enabled property.
 * @param model data model with only required query parameter values. Leave others as null.
 * @return List<PaginatedSubstitutesDataModel> Result set of substitute info
 */
public List<SubstitutesDataModel> querySubstituteInfoWithoutEnabled(final PaginatedSubstitutesDataModel model) {
    final RowBounds rw = new RowBounds(model.getStart(), model.getSize());
    CustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>> customSqlExecution = new AbstractCustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>>(SubstitutesMapper.class) {

        public List<SubstitutesDataModel> execute(SubstitutesMapper substitutesMapper) {
            return substitutesMapper.querySubstitutesWithoutEnabled(rw, model);
        }
    };
    return managementService.executeCustomSql(customSqlExecution);
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) AbstractCustomSqlExecution(org.activiti.engine.impl.cmd.AbstractCustomSqlExecution) RowBounds(org.apache.ibatis.session.RowBounds) List(java.util.List) SubstitutesMapper(org.wso2.carbon.bpmn.core.internal.mapper.SubstitutesMapper)

Example 94 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class HumanTaskServer method initTransactionManager.

// initialize the external transaction manager.
private void initTransactionManager() throws HumanTaskServerException {
    String transactionFactoryName = serverConfig.getTransactionFactoryClass();
    if (log.isDebugEnabled()) {
        log.debug("Initializing transaction manager using " + transactionFactoryName);
    }
    try {
        Class txFactoryClass = this.getClass().getClassLoader().loadClass(transactionFactoryName);
        Object txFactory = txFactoryClass.newInstance();
        tnxManager = (TransactionManager) txFactoryClass.getMethod("getTransactionManager", (Class[]) null).invoke(txFactory);
    // Didn't use Debug Transaction manager which used in ODE.
    // TODO: Look for the place we use this axis parameter.
    // axisConfiguration.addParameter("ode.transaction.manager", transactionManager);
    } catch (Exception e) {
        log.fatal("Couldn't initialize a transaction manager with factory: " + transactionFactoryName, e);
        throw new HumanTaskServerException("Couldn't initialize a transaction manager with factory: " + transactionFactoryName, e);
    }
}
Also used : HumanTaskServerException(org.wso2.carbon.humantask.core.engine.HumanTaskServerException) HumanTaskServerException(org.wso2.carbon.humantask.core.engine.HumanTaskServerException)

Example 95 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-apimgt by wso2.

the class GraphQLResponseProcessor method handleResponse.

/**
 * Handle inbound websocket responses of GraphQL subscriptions and perform authentication, authorization
 * and throttling. This identifies operation from the subscription responses using the unique message id parameter.
 *
 * @param msgSize               Message size of graphQL subscription response payload
 * @param msgText               The GraphQL subscription response payload text
 * @param inboundMessageContext InboundMessageContext
 * @return InboundProcessorResponseDTO
 */
@Override
public InboundProcessorResponseDTO handleResponse(int msgSize, String msgText, InboundMessageContext inboundMessageContext) {
    InboundProcessorResponseDTO responseDTO = InboundWebsocketProcessorUtil.authenticateToken(inboundMessageContext);
    JSONObject graphQLMsg = new JSONObject(msgText);
    if (!responseDTO.isError() && checkIfSubscribeMessageResponse(graphQLMsg)) {
        if (graphQLMsg.has(GraphQLConstants.SubscriptionConstants.PAYLOAD_FIELD_NAME_ID) && graphQLMsg.getString(GraphQLConstants.SubscriptionConstants.PAYLOAD_FIELD_NAME_ID) != null) {
            String operationId = graphQLMsg.getString(GraphQLConstants.SubscriptionConstants.PAYLOAD_FIELD_NAME_ID);
            GraphQLOperationDTO graphQLOperationDTO = inboundMessageContext.getVerbInfoForGraphQLMsgId(graphQLMsg.getString(GraphQLConstants.SubscriptionConstants.PAYLOAD_FIELD_NAME_ID));
            // validate scopes based on subscription payload when security is enabled
            String authType = graphQLOperationDTO.getVerbInfoDTO().getAuthType();
            if (!StringUtils.capitalize(APIConstants.AUTH_TYPE_NONE.toLowerCase()).equals(authType)) {
                responseDTO = InboundWebsocketProcessorUtil.validateScopes(inboundMessageContext, graphQLOperationDTO.getOperation(), operationId);
            }
            if (!responseDTO.isError()) {
                // throttle for matching resource
                return InboundWebsocketProcessorUtil.doThrottleForGraphQL(msgSize, graphQLOperationDTO.getVerbInfoDTO(), inboundMessageContext, operationId);
            }
        } else {
            responseDTO = InboundWebsocketProcessorUtil.getBadRequestFrameErrorDTO("Missing mandatory id field in the message");
        }
    }
    return responseDTO;
}
Also used : GraphQLOperationDTO(org.wso2.carbon.apimgt.gateway.dto.GraphQLOperationDTO) JSONObject(org.json.JSONObject) InboundProcessorResponseDTO(org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO)

Aggregations

HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)32 Parameter (org.apache.axis2.description.Parameter)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)13 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 List (java.util.List)10 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8