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();
}
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());
}
}
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);
}
}
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);
}
}
}
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);
}
Aggregations