List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty
public static boolean isEmpty(final Collection<?> coll)
From source file:org.openscore.lang.runtime.bindings.ResultsBinding.java
/** * Resolves the result name of an executable based on the list of all the possible results, the run context * and in the case of a flow, also the already preset result name * * Throws a runtime exception in the following cases: * 1. No possible results were given//from w w w . j a v a2 s.c om * 2. In the case of a flow, the preset result name is not present in the possible results list * 3. One or more of the results contains an illegal expression - not evaluated to true\false value * 4. No result was resolved - none of the results expression returned true * * @param inputs the executable's inputs * @param context the run context * @param possibleResults list of all the possible Result objects of the executable * @param presetResult a given result name. Will be not null only in the case of resolving a result of a flow * @return the resolved result name */ public String resolveResult(Map<String, Serializable> inputs, Map<String, String> context, List<Result> possibleResults, String presetResult) { // We must have possible results if (CollectionUtils.isEmpty(possibleResults)) { throw new RuntimeException("No results were found"); } // In case of calculating the result of a flow, we already have a preset result from the last task of the flow, // we look for it in the possible results of the flow. // If the flow has it as a possible result, we return it as the resolved result. // If not, we throw an exception if (presetResult != null) { for (Result possibleResult : possibleResults) { if (presetResult.equals(possibleResult.getName())) { return presetResult; } } throw new RuntimeException("Result: " + presetResult + " that was calculated in the last task is not a possible result of the flow."); } // In the case of operation, we resolve the result by searching for the first result with a true expression // An empty expression passes as true for (Result result : possibleResults) { String expression = result.getExpression(); // If the answer has no expression, we treat it as a true expression, and choose it if (StringUtils.isEmpty(expression)) { return result.getName(); } //construct script context Map<String, Serializable> scriptContext = new HashMap<>(); //put action outputs scriptContext.putAll(context); //put executable inputs as a map if (MapUtils.isNotEmpty(inputs)) { scriptContext.put(BIND_OUTPUT_FROM_INPUTS_KEY, (Serializable) inputs); } try { Boolean evaluatedResult = (Boolean) scriptEvaluator.evalExpr(expression, scriptContext); if (evaluatedResult == null) { throw new RuntimeException("Expression of the operation result: " + expression + " cannot be evaluated correctly to true or false value"); } if (evaluatedResult) { return result.getName(); } } catch (ClassCastException ex) { throw new RuntimeException("Error resolving the result. The expression " + expression + " does not return boolean value", ex); } } throw new RuntimeException("No possible result was resolved"); }
From source file:org.pentaho.metaverse.api.analyzer.kettle.step.SubtransAnalyzer.java
/** * Checks to see if the sub trans has any RowFromResult steps in it. * If so, it will link the original field node to the fields created in the RowFromResult step in the sub trans * @param originalFieldNode incoming stream field node to the TransExecutorStep * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step * @param subTransNode IMetaverseNode representing the sub-transformation to be executed * @param descriptor Descriptor to use as a basis * @param fieldPredicate predicate to determine if this is the sub field to link with *///from www. j ava2 s . c o m public void linkUsedFieldToSubTrans(IMetaverseNode originalFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor, Predicate<String> fieldPredicate) { List<StepMeta> steps = subTransMeta.getSteps(); if (!CollectionUtils.isEmpty(steps)) { for (StepMeta step : steps) { if (step.getStepMetaInterface() instanceof RowsFromResultMeta) { RowsFromResultMeta rfrm = (RowsFromResultMeta) step.getStepMetaInterface(); // Create a new descriptor for the RowsFromResult step. IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(StepAnalyzer.NONE, DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext()); // Create a new node for the step, to be used as the parent of the the field we want to link to IMetaverseNode subTransStepNode = stepAnalyzer.createNodeFromDescriptor(stepDescriptor); if (linkUsedFieldToStepField(originalFieldNode, subTransMeta, descriptor, fieldPredicate, step, rfrm, subTransStepNode)) { return; } } } } }
From source file:org.pentaho.metaverse.api.analyzer.kettle.step.SubtransAnalyzer.java
/** * Checks to see if the sub trans has the specified step name in it. * If so, it will link the fields it outputs to the fields created by this step and are sent to the * "target step for output rows"./*from www . j a v a 2 s .com*/ * * @param streamFieldNode stream field node sent to the step defined as "target step for output rows" * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step * @param subTransNode IMetaverseNode representing the sub-transformation to be executed * @param descriptor Descriptor to use as a basis for any nodes created * @param resultStepName Name of step whose outputs need to connect to parent trans/step */ public void linkResultFieldToSubTrans(IMetaverseNode streamFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor, String resultStepName) { List<StepMeta> steps = subTransMeta.getSteps(); if (!CollectionUtils.isEmpty(steps)) { for (StepMeta step : steps) { // either look for the step with the specified name, or the name was null and we want the Rows to Result step if (((null != resultStepName) && step.getName().equals(resultStepName)) || (null == resultStepName) && step.getStepMetaInterface() instanceof RowsToResultMeta) { BaseStepMeta baseStepMeta = (BaseStepMeta) step.getStepMetaInterface(); // Create a new descriptor for the RowsToResult step. IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(step.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext()); // Create a new node for the step, to be used as the parent of the the field we want to link to IMetaverseNode subTransStepNode = stepAnalyzer.createNodeFromDescriptor(stepDescriptor); linkResultFieldToStepField(streamFieldNode, subTransMeta, descriptor, resultStepName, step, baseStepMeta, subTransStepNode); } } } }
From source file:org.phenotips.data.internal.controller.AllergiesController.java
@Override public PatientData<String> load(Patient patient) { try {/*from ww w.j av a 2 s. c o m*/ XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(CLASS_REFERENCE); if (data == null) { return null; } @SuppressWarnings("unchecked") List<String> allergies = data.getListValue(DATA_NAME); int nkda = data.getIntValue(NKDA); List<String> result = new ArrayList<>(CollectionUtils.size(allergies) + 1); if (nkda == 1) { result.add(NKDA); } if (!CollectionUtils.isEmpty(allergies)) { result.addAll(allergies); } return new IndexedPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
From source file:org.phenotips.panels.internal.DefaultGenePanelImpl.java
/** * Tries to obtain the preferred gene ID, given {@code geneSymbol}. * * @param geneSymbol the GeneCards gene symbol * @return the preferred gene ID, or geneSymbol if no preferred ID is recorded *//*from w w w .jav a2 s . co m*/ private String getGeneId(@Nonnull final String geneSymbol) { final VocabularyTerm geneTerm = this.hgnc.getTerm(geneSymbol); if (geneTerm != null) { @SuppressWarnings("unchecked") final List<String> geneIdList = (List<String>) geneTerm.get(ENSEMBL_ID_LABEL); return CollectionUtils.isEmpty(geneIdList) ? geneSymbol : geneIdList.get(0); } return geneSymbol; }
From source file:org.phenotips.panels.rest.internal.DefaultGenePanelLoader.java
/** * Generates a new {@link GenePanel} object, given a {@code key} that is a list of HPO term IDs. * * @param key an unmodifiable list of HPO term IDs as strings * @return a {@link GenePanel} object for the provided {@code key} * @throws Exception if {@code key} is empty or {@code null}, or if the generated {@link GenePanel} contains no data */// w w w . jav a 2 s . c om private GenePanel generatePanelsData(@Nonnull final List<String> key) throws Exception { // No need to perform a lookup if the key is not valid. if (CollectionUtils.isEmpty(key)) { throw new Exception(); } // Generate the gene panel data. final GenePanel panel = this.genePanelFactory.build(buildTermsFromIDs(key), Collections.<VocabularyTerm>emptyList()); // Don't want to store any empty values in the loading cache. if (panel.size() == 0) { throw new Exception(); } // Return the stored value. return panel; }
From source file:org.phenotips.panels.rest.internal.DefaultGenePanelsResourceImpl.java
@Override public Response getGeneCountsFromPhenotypes() { Request request = this.container.getRequest(); List<String> presentTerms = new ArrayList<>(); for (Object t : request.getProperties("present-term")) { if (t != null) { presentTerms.add((String) t); }/*from ww w.jav a 2 s . com*/ } presentTerms = Collections.unmodifiableList(presentTerms); List<String> absentTerms = new ArrayList<>(); for (Object t : request.getProperties("absent-term")) { if (t != null) { absentTerms.add((String) t); } } absentTerms = Collections.unmodifiableList(absentTerms); if (CollectionUtils.isEmpty(presentTerms) && CollectionUtils.isEmpty(absentTerms)) { this.logger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int startPage = NumberUtils.toInt((String) request.getProperty(START_PAGE_LABEL), 1); final int numResults = NumberUtils.toInt((String) request.getProperty(RESULTS_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { // Try to generate the JSON for the requested subset of data. final JSONObject panels = getPageData(this.genePanelLoader.get(presentTerms), startPage, numResults); panels.put(REQ_NO, reqNo); return Response.ok(panels, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.logger.error("No content associated with [present-term: {}, absent-term: {}].", presentTerms, absentTerms); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.logger.error("The requested [{}: {}] is out of bounds.", START_PAGE_LABEL, startPage); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.logger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabularyTerm.java
@Override public String getTranslatedName() { Collection<?> translated = getTranslatedValues(NAME_KEY); if (CollectionUtils.isEmpty(translated)) { return null; }//from ww w . ja va 2s . c o m return (String) IterableUtils.get(translated, 0); }
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabularyTerm.java
@Override public String getTranslatedDescription() { Collection<?> translated = getTranslatedValues(DESCRIPTION_KEY); if (CollectionUtils.isEmpty(translated)) { return null; }//from w ww . ja v a2 s .c om return (String) IterableUtils.get(translated, 0); }
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabularyTerm.java
@Override public Collection<?> getTranslatedValues(String property) { Locale currentLocale = getCurrentLocale(); if (StringUtils.isEmpty(currentLocale.getLanguage())) { return getValues(property); }/*ww w . ja v a 2s .co m*/ Collection<Object> result = getValues(property + '_' + currentLocale.toString()); // If the locale has language, country, and variant, try without the variant if (CollectionUtils.isEmpty(result) && StringUtils.isNoneEmpty(currentLocale.getVariant(), currentLocale.getCountry())) { result = getValues(property + '_' + currentLocale.getLanguage() + '_' + currentLocale.getCountry()); } // If the locale has language and country, try without the country if (CollectionUtils.isEmpty(result) && StringUtils.isNoneEmpty(currentLocale.getLanguage(), currentLocale.getCountry())) { result = getValues(property + '_' + currentLocale.getLanguage()); } // If the locale has no country, then the first call included the language only; // at this point, it's certain that no translation is available, return the untranslated default if (CollectionUtils.isEmpty(result)) { result = getValues(property); } return result; }