Search in sources :

Example 6 with Record

use of org.wso2.carbon.analytics.datasource.commons.Record in project siddhi by wso2.

the class AbstractQueryableRecordTable method query.

@Override
public StreamEvent query(StateEvent matchingEvent, CompiledCondition compiledCondition, CompiledSelection compiledSelection) throws ConnectionUnavailableException {
    RecordStoreCompiledSelection recordStoreCompiledSelection = ((RecordStoreCompiledSelection) compiledSelection);
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    Map<String, Object> parameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledSelection.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.query(matchingEvent.getTimestamp(), parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    } else {
        records = query(parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.borrowEvent();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Record

use of org.wso2.carbon.analytics.datasource.commons.Record in project carbon-business-process by wso2.

the class UserSubstitutionService method substitute.

/**
 * Add new addSubstituteInfo record.
 * Following request body parameters are required,
 *  assignee : optional, logged in user is used if not provided
 *  substitute : required
 *  startTime : optional, current timestamp if not provided, the timestamp the substitution should start in ISO format
 *  endTime : optional, considered as forever if not provided, the timestamp the substitution should end in ISO format
 * @param request
 * @return 201 created response with the resource location. 405 if substitution disabled
 */
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response substitute(SubstitutionRequest request) {
    try {
        if (!subsFeatureEnabled) {
            return Response.status(405).build();
        }
        String assignee = getRequestedAssignee(request.getAssignee());
        String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
        Date endTime = null;
        Date startTime = new Date();
        DateTime requestStartTime = null;
        if (request.getStartTime() != null) {
            requestStartTime = new DateTime(request.getStartTime());
            startTime = new Date(requestStartTime.getMillis());
        }
        if (request.getEndTime() != null) {
            endTime = validateEndTime(request.getEndTime(), requestStartTime);
        }
        if (!UserSubstitutionUtils.validateTasksList(request.getTaskList(), assignee)) {
            throw new ActivitiIllegalArgumentException("Invalid task list provided, for substitution.");
        }
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        // at this point, substitution is enabled by default
        UserSubstitutionUtils.handleNewSubstituteAddition(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
        return Response.created(new URI("substitutes/" + assignee)).build();
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store", e);
    } catch (URISyntaxException e) {
        throw new ActivitiException("Response location URI creation header", e);
    } catch (ActivitiIllegalArgumentException e) {
        throw new ActivitiIllegalArgumentException(e.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DateTime(org.joda.time.DateTime)

Example 8 with Record

use of org.wso2.carbon.analytics.datasource.commons.Record in project carbon-business-process by wso2.

the class UserSubstitutionUtils method handleChangeSubstitute.

public static void handleChangeSubstitute(String assignee, String substitute, int tenantId) {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    SubstitutesDataModel existingSubInfo = activitiDAO.selectSubstituteInfo(assignee, tenantId);
    if (existingSubInfo != null) {
        activitiDAO.updateSubstitute(assignee, substitute, tenantId, new Date());
        if (existingSubInfo.isEnabled() && isBeforeActivationInterval(existingSubInfo.getSubstitutionStart())) {
            String existingSub = existingSubInfo.getSubstitute();
            existingSubInfo.setSubstitute(substitute);
            boolean transitivityResolved = updateTransitiveSubstitutes(existingSubInfo, tenantId);
            if (!transitivityResolved) {
                // remove added record
                activitiDAO.updateSubstitute(assignee, existingSub, tenantId, existingSubInfo.getUpdated());
                throw new SubstitutionException("Given Substitute is not available. Provide a different user to substitute.");
            }
        }
    } else {
        throw new SubstitutionException("No substitution record found for the user: " + assignee);
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 9 with Record

use of org.wso2.carbon.analytics.datasource.commons.Record in project carbon-business-process by wso2.

the class UserSubstitutionUtils method handleNewSubstituteAddition.

/**
 * Handles addition of new substitute record and it's post conditions.
 * @param assignee
 * @param substitute
 * @param startTime
 * @param endTime
 * @param enabled
 * @param taskList
 * @throws SubstitutionException
 */
public static void handleNewSubstituteAddition(String assignee, String substitute, Date startTime, Date endTime, boolean enabled, List<String> taskList, int tenantId) throws SubstitutionException {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    String taskListStr = getTaskListString(taskList);
    SubstitutesDataModel dataModel = addSubstituteInfo(assignee, substitute, startTime, endTime, taskListStr, tenantId);
    if (dataModel.isEnabled() && isBeforeActivationInterval(dataModel.getSubstitutionStart())) {
        boolean transitivityResolved = updateTransitiveSubstitutes(dataModel, tenantId);
        if (!transitivityResolved) {
            // remove added transitive record
            activitiDAO.removeSubstitute(assignee, tenantId);
            throw new // SubstitutionException
            SubstitutionException("Could not find an available substitute. Use a different user to substitute");
        }
        if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
            // transitive substitute maybe changed, need to retrieve again.
            dataModel = activitiDAO.selectSubstituteInfo(dataModel.getUser(), dataModel.getTenantId());
        }
        if (!SubstitutionDataHolder.getInstance().isTransitivityEnabled() || BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE.equals(dataModel.getTransitiveSub())) {
            bulkReassign(dataModel.getUser(), dataModel.getSubstitute(), taskList);
        } else {
            bulkReassign(dataModel.getUser(), dataModel.getTransitiveSub(), taskList);
        }
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 10 with Record

use of org.wso2.carbon.analytics.datasource.commons.Record in project carbon-business-process by wso2.

the class ActivitiDAO method updateSubstituteInfo.

/**
 * Update the substitute record for given user
 * @param substitutesDataModel
 * @return updated row count. Ideally should return 1.
 */
public int updateSubstituteInfo(final SubstitutesDataModel substitutesDataModel) {
    substitutesDataModel.setUpdated(new Date());
    CustomSqlExecution<SubstitutesMapper, Integer> customSqlExecution = new AbstractCustomSqlExecution<SubstitutesMapper, Integer>(SubstitutesMapper.class) {

        public Integer execute(SubstitutesMapper substitutesMapper) {
            return substitutesMapper.updateSubstitute(substitutesDataModel);
        }
    };
    return managementService.executeCustomSql(customSqlExecution);
}
Also used : AbstractCustomSqlExecution(org.activiti.engine.impl.cmd.AbstractCustomSqlExecution) SubstitutesMapper(org.wso2.carbon.bpmn.core.internal.mapper.SubstitutesMapper) Date(java.util.Date)

Aggregations

HashMap (java.util.HashMap)4 ActivitiDAO (org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)3 PaginatedSubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel)3 SubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)3 Map (java.util.Map)2 Record (org.wso2.carbon.analytics.datasource.commons.Record)2 SensorRecord (org.wso2.iot.sampledevice.api.dto.SensorRecord)2 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)2 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)2 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ParseException (javax.mail.internet.ParseException)1 QName (javax.xml.namespace.QName)1