@Override protected Aggregator doCreateInternal( ValuesSource valuesSource, AggregationContext context, Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { if (valuesSource instanceof ValuesSource.Numeric) { return new DiversifiedNumericSamplerAggregator( name, shardSize, factories, context, parent, pipelineAggregators, metaData, (Numeric) valuesSource, maxDocsPerValue); } if (valuesSource instanceof ValuesSource.Bytes) { ExecutionMode execution = null; if (executionHint != null) { execution = ExecutionMode.fromString(executionHint, context.searchContext().parseFieldMatcher()); } // In some cases using ordinals is just not supported: override // it if (execution == null) { execution = ExecutionMode.GLOBAL_ORDINALS; } if ((execution.needsGlobalOrdinals()) && (!(valuesSource instanceof ValuesSource.Bytes.WithOrdinals))) { execution = ExecutionMode.MAP; } return execution.create( name, factories, shardSize, maxDocsPerValue, valuesSource, context, parent, pipelineAggregators, metaData); } throw new AggregationExecutionException( "Sampler aggregation cannot be applied to field [" + config.fieldContext().field() + "]. It can only be applied to numeric or string fields."); }
/* * (non-Javadoc) * @see eu.stratosphere.core.io.IOReadableWritable#read(java.io.DataInput) */ @Override public void read(final DataInput in) throws IOException { this.mode = ExecutionMode.values()[in.readInt()]; final ArrayList<String> requiredPackages = new ArrayList<String>(); for (int count = in.readInt(); count > 0; count--) requiredPackages.add(in.readUTF()); this.query = null; final byte[] planBuffer = new byte[in.readInt()]; in.readFully(planBuffer); final JobID dummId = new JobID(); try { LibraryCacheManager.register( dummId, requiredPackages.toArray(new String[requiredPackages.size()])); SopremoEnvironment.getInstance().setClassLoader(LibraryCacheManager.getClassLoader(dummId)); this.query = SopremoUtil.deserialize(planBuffer, SopremoPlan.class); } catch (final IOException e) { e.printStackTrace(); } finally { try { LibraryCacheManager.unregister(dummId); } catch (final IOException e) { } } }
@Override protected Aggregator doCreateInternal( ValuesSource valuesSource, AggregationContext aggregationContext, Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { if (collectsFromSingleBucket == false) { return asMultiBucketAggregator(this, aggregationContext, parent); } numberOfAggregatorsCreated++; if (valuesSource instanceof ValuesSource.Bytes) { ExecutionMode execution = null; if (executionHint != null) { execution = ExecutionMode.fromString( executionHint, aggregationContext.searchContext().parseFieldMatcher()); } if (!(valuesSource instanceof ValuesSource.Bytes.WithOrdinals)) { execution = ExecutionMode.MAP; } if (execution == null) { if (Aggregator.descendsFromBucketAggregator(parent)) { execution = ExecutionMode.GLOBAL_ORDINALS_HASH; } else { execution = ExecutionMode.GLOBAL_ORDINALS; } } assert execution != null; return execution.create( name, factories, valuesSource, bucketCountThresholds, includeExclude, aggregationContext, parent, this, pipelineAggregators, metaData); } if ((includeExclude != null) && (includeExclude.isRegexBased())) { throw new AggregationExecutionException( "Aggregation [" + name + "] cannot support regular expression style include/exclude " + "settings as they can only be applied to string fields. Use an array of numeric values for include/exclude clauses used to filter numeric fields"); } if (valuesSource instanceof ValuesSource.Numeric) { if (((ValuesSource.Numeric) valuesSource).isFloatingPoint()) { throw new UnsupportedOperationException("No support for examining floating point numerics"); } IncludeExclude.LongFilter longFilter = null; if (includeExclude != null) { longFilter = includeExclude.convertToLongFilter(); } return new SignificantLongTermsAggregator( name, factories, (ValuesSource.Numeric) valuesSource, config.format(), bucketCountThresholds, aggregationContext, parent, this, longFilter, pipelineAggregators, metaData); } throw new AggregationExecutionException( "sigfnificant_terms aggregation cannot be applied to field [" + config.fieldContext().field() + "]. It can only be applied to numeric or string fields."); }
public MessageContainer runRules( List<RuleSetBean> ruleSets, ExecutionMode executionMode, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub, Phase phase) { if (variableAndValue == null || variableAndValue.isEmpty()) { logger.warn("You must be executing Rules in Batch"); variableAndValue = new HashMap<String, String>(); } MessageContainer messageContainer = new MessageContainer(); HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>(); for (RuleSetBean ruleSet : ruleSets) { String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue()); List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null; if (toBeExecuted.containsKey(key)) { allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key); } else { toBeExecuted.put(key, new ArrayList<RuleActionContainer>()); allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key); } ItemDataBean itemData = null; for (ExpressionBean expressionBean : ruleSet.getExpressions()) { ruleSet.setTarget(expressionBean); for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) { String result = null; RuleBean rule = ruleSetRule.getRuleBean(); ExpressionObjectWrapper eow = new ExpressionObjectWrapper( ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue, ecb); try { OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow); result = oep.parseAndEvaluateExpression(rule.getExpression().getValue()); itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue()); // Actions List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, phase); if (itemData != null) { Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator(); while (itr.hasNext()) { RuleActionBean ruleActionBean = itr.next(); RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean( ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid()); if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) { itr.remove(); } } } for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) { RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet); allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer); } logger.info( "RuleSet with target : {} , Ran Rule : {} The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() }); } catch (OpenClinicaSystemException osa) { // TODO: report something useful } } } } for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) { // Sort the list of actions Collections.sort(entry.getValue(), new RuleActionContainerComparator()); for (RuleActionContainer ruleActionContainer : entry.getValue()) { logger.info( "START Expression is : {} , RuleAction : {} , ExecutionMode : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString(), executionMode }); ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean()); ruleActionContainer .getRuleAction() .setCuratedMessage( curateMessage( ruleActionContainer.getRuleAction(), (ruleActionContainer.getRuleAction().getRuleSetRule()))); ActionProcessor ap = ActionProcessorFacade.getActionProcessor( ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule()); RuleActionBean rab = ap.execute( RuleRunnerMode.DATA_ENTRY, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents( ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction())); if (rab != null) { messageContainer.add( getExpressionService() .getGroupOrdninalConcatWithItemOid( ruleActionContainer.getRuleSetBean().getTarget().getValue()), ruleActionContainer.getRuleAction()); } logger.info( "END Expression is : {} , RuleAction : {} , ExecutionMode : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString(), executionMode }); } } return messageContainer; }
public static void executeExternalProcess( @Nullable final Project myProject, @NotNull final ProcessHandler processHandler, @NotNull final ExecutionMode mode, @NotNull final String presentableCmdline) { final String title = mode.getTitle() != null ? mode.getTitle() : "Please wait..."; assert title != null; final Runnable process; if (mode.cancelable()) { process = createCancelableExecutionProcess(processHandler, mode.shouldCancelFun()); } else { if (mode.getTimeout() <= 0) { process = new Runnable() { public void run() { processHandler.waitFor(); } }; } else { process = createTimelimitedExecutionProcess( processHandler, mode.getTimeout(), presentableCmdline); } } if (mode.withModalProgress()) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( process, title, mode.cancelable(), myProject, mode.getProgressParentComponent()); } else if (mode.inBackGround()) { final Task task = new Task.Backgroundable(myProject, title, mode.cancelable()) { public void run(@NotNull final ProgressIndicator indicator) { process.run(); } }; ProgressManager.getInstance().run(task); } else { final String title2 = mode.getTitle2(); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null && title2 != null) { indicator.setText2(title2); } process.run(); } }