List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty
public static boolean isNotEmpty(final Collection<?> coll)
From source file:com.hp.autonomy.searchcomponents.idol.view.IdolViewServerService.java
private String parseFieldValue(final String referenceField, final List<Hit> documents) { final Hit document = documents.get(0); String referenceFieldValue = null; // Assume the field names are case insensitive final DocContent documentContent = document.getContent(); if (documentContent != null && CollectionUtils.isNotEmpty(documentContent.getContent())) { final NodeList fields = ((Node) documentContent.getContent().get(0)).getChildNodes(); for (int i = 0; i < fields.getLength(); i++) { final Node field = fields.item(i); if (field.getLocalName().equalsIgnoreCase(referenceField)) { referenceFieldValue = field.getFirstChild() == null ? null : field.getFirstChild().getNodeValue(); break; }//from ww w . ja v a2 s .c o m } } return referenceFieldValue; }
From source file:com.mirth.connect.server.api.providers.MirthResourceInvocationHandlerProvider.java
@Override public InvocationHandler create(Invocable method) { return new InvocationHandler() { @Override/*from ww w .j a v a 2 s .co m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String originalThreadName = Thread.currentThread().getName(); try { if (proxy instanceof MirthServlet) { try { MirthServlet mirthServlet = (MirthServlet) proxy; Map<Method, MethodInfo> methodMap = infoMap.get(proxy.getClass()); if (methodMap == null) { methodMap = new ConcurrentHashMap<Method, MethodInfo>(); infoMap.put(mirthServlet.getClass(), methodMap); } MethodInfo methodInfo = methodMap.get(method); if (methodInfo == null) { methodInfo = new MethodInfo(); methodMap.put(method, methodInfo); } Operation operation = methodInfo.getOperation(); if (operation == null) { /* * Get the operation from the MirthOperation annotation present on * the interface method. */ Class<?> clazz = proxy.getClass(); while (clazz != null && operation == null) { for (Class<?> interfaceClass : clazz.getInterfaces()) { if (BaseServletInterface.class.isAssignableFrom(interfaceClass)) { operation = OperationUtil.getOperation(interfaceClass, method); if (operation != null) { methodInfo.setOperation(operation); break; } } } clazz = clazz.getSuperclass(); } } mirthServlet.setOperation(operation); // Set thread name based on the servlet class and operation name Thread.currentThread().setName(mirthServlet.getClass().getSimpleName() + " Thread (" + operation.getDisplayName() + ") < " + originalThreadName); /* * If a DontCheckAuthorized annotation is present on the server * implementation method, then no auditing is done now and the servlet * is expected to call checkUserAuthorized. Two other optional * annotations determine whether the channel/user ID should be used in * the authorization check. */ Boolean checkAuthorized = methodInfo.getCheckAuthorized(); if (checkAuthorized == null) { checkAuthorized = true; Method matchingMethod = mirthServlet.getClass().getMethod(method.getName(), method.getParameterTypes()); if (matchingMethod != null) { checkAuthorized = matchingMethod .getAnnotation(DontCheckAuthorized.class) == null; methodInfo.setCheckAuthorizedChannelId( matchingMethod.getAnnotation(CheckAuthorizedChannelId.class)); methodInfo.setCheckAuthorizedUserId( matchingMethod.getAnnotation(CheckAuthorizedUserId.class)); } methodInfo.setCheckAuthorized(checkAuthorized); } if (checkAuthorized) { /* * We need to know what parameter index the channel/user ID resides * at so we can correctly include it with the authorization request. */ Integer channelIdIndex = methodInfo.getChannelIdIndex(); Integer userIdIndex = methodInfo.getUserIdIndex(); if (args.length > 0) { List<String> paramNames = methodInfo.getParamNames(); if (paramNames == null) { paramNames = new ArrayList<String>(); List<Integer> notFoundIndicies = new ArrayList<Integer>(); /* * The Param annotation lets us know at runtime the name to * use when adding entries into the parameter map, which * will eventually be stored in the event logs. */ int count = 0; for (Annotation[] paramAnnotations : method.getParameterAnnotations()) { boolean found = false; for (Annotation annotation : paramAnnotations) { if (annotation instanceof Param) { Param param = (Param) annotation; // Set the name to null if we're not including it in the parameter map paramNames.add(param.excludeFromAudit() ? null : param.value()); found = true; break; } } if (!found) { notFoundIndicies.add(count); paramNames.add(null); } count++; } // For each parameter name that wasn't found, replace it with a default name to use in the parameter map if (CollectionUtils.isNotEmpty(notFoundIndicies)) { for (Integer index : notFoundIndicies) { paramNames.set(index, getDefaultParamName(paramNames)); } } methodInfo.setParamNames(paramNames); } // Add all arguments to the parameter map, except those that had excludeFromAudit enabled. for (int i = 0; i < args.length; i++) { String paramName = paramNames.get(i); if (paramName != null) { mirthServlet.addToParameterMap(paramNames.get(i), args[i]); } } if (channelIdIndex == null) { channelIdIndex = -1; if (methodInfo.getCheckAuthorizedChannelId() != null) { channelIdIndex = paramNames .indexOf(methodInfo.getCheckAuthorizedChannelId().paramName()); } methodInfo.setChannelIdIndex(channelIdIndex); } if (userIdIndex == null) { userIdIndex = -1; if (methodInfo.getCheckAuthorizedUserId() != null) { userIdIndex = paramNames .indexOf(methodInfo.getCheckAuthorizedUserId().paramName()); } methodInfo.setUserIdIndex(userIdIndex); } } // Authorize the request if (channelIdIndex != null && channelIdIndex >= 0) { mirthServlet.checkUserAuthorized((String) args[channelIdIndex]); } else if (userIdIndex != null && userIdIndex >= 0) { mirthServlet.checkUserAuthorized((Integer) args[userIdIndex], methodInfo.getCheckAuthorizedUserId().auditCurrentUser()); } else { mirthServlet.checkUserAuthorized(); } } } catch (Throwable t) { Throwable converted = convertThrowable(t, new HashSet<Throwable>()); if (converted != null) { t = converted; } if (!(t instanceof WebApplicationException)) { t = new MirthApiException(t); } throw new InvocationTargetException(t); } } try { return method.invoke(proxy, args); } catch (InvocationTargetException e) { Throwable converted = convertThrowable(e, new HashSet<Throwable>()); if (converted != null && converted instanceof InvocationTargetException) { e = (InvocationTargetException) converted; } throw e; } } finally { Thread.currentThread().setName(originalThreadName); } } }; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityJsonParser.java
/** * Gets field raw data value resolved by locator and formats it according locator definition. * * @param locator/*from ww w. j a v a2 s . c o m*/ * activity field locator * @param cData * {@link JsonPath} document context to read * @param formattingNeeded * flag to set if value formatting is not needed * @return value formatted based on locator definition or {@code null} if locator is not defined * * @throws ParseException * if exception occurs while resolving raw data value or applying locator format properties to specified * value * * @see ActivityFieldLocator#formatValue(Object) */ @Override @SuppressWarnings("unchecked") protected Object resolveLocatorValue(ActivityFieldLocator locator, ActivityContext cData, AtomicBoolean formattingNeeded) throws ParseException { Object val = null; String locStr = locator.getLocator(); if (StringUtils.isNotEmpty(locStr)) { if (!locStr.startsWith(JSON_PATH_ROOT)) { locStr = JSON_PATH_ROOT + JSON_PATH_SEPARATOR + locStr; } Object jsonValue = null; try { jsonValue = cData.getData().read(locStr); } catch (JsonPathException exc) { logger().log(!locator.isOptional() ? OpLevel.WARNING : OpLevel.DEBUG, StreamsResources .getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityJsonParser.path.exception"), locStr, exc.getLocalizedMessage()); } if (jsonValue != null) { List<Object> jsonValuesList; if (jsonValue instanceof List) { jsonValuesList = (List<Object>) jsonValue; } else { jsonValuesList = new ArrayList<>(1); jsonValuesList.add(jsonValue); } if (CollectionUtils.isNotEmpty(jsonValuesList)) { List<Object> valuesList = new ArrayList<>(jsonValuesList.size()); for (Object jsonValues : jsonValuesList) { valuesList.add(locator.formatValue(jsonValues)); } val = Utils.simplifyValue(valuesList); formattingNeeded.set(false); } } } return val; }
From source file:com.daimler.spm.storefront.controllers.pages.MyQuotesController.java
protected void sortComments(final AbstractOrderData orderData) { if (orderData != null) { if (CollectionUtils.isNotEmpty(orderData.getComments())) { final List<CommentData> sortedComments = orderData.getComments().stream().sorted( (comment1, comment2) -> comment2.getCreationDate().compareTo(comment1.getCreationDate())) .collect(Collectors.toList()); orderData.setComments(sortedComments); }//from w w w.j a va 2 s . c om if (CollectionUtils.isNotEmpty(orderData.getEntries())) { for (final OrderEntryData orderEntry : orderData.getEntries()) { if (CollectionUtils.isNotEmpty(orderEntry.getComments())) { final List<CommentData> sortedEntryComments = orderEntry.getComments().stream() .sorted((comment1, comment2) -> comment2.getCreationDate() .compareTo(comment1.getCreationDate())) .collect(Collectors.toList()); orderEntry.setComments(sortedEntryComments); } else if (orderEntry.getProduct() != null && orderEntry.getProduct().getMultidimensional() != null && orderEntry.getProduct().getMultidimensional()) { if (CollectionUtils.isNotEmpty(orderEntry.getEntries())) { for (final OrderEntryData multiDOrderEntry : orderEntry.getEntries()) { if (CollectionUtils.isNotEmpty(multiDOrderEntry.getComments())) { final List<CommentData> sortedMultiDOrderEntryComments = multiDOrderEntry .getComments().stream() .sorted((comment1, comment2) -> comment2.getCreationDate() .compareTo(comment1.getCreationDate())) .collect(Collectors.toList()); multiDOrderEntry.setComments(sortedMultiDOrderEntryComments); } } } } } } } }
From source file:com.epam.catgenome.entity.vcf.VcfFilterForm.java
private void addChromosomeFilter(BooleanQuery.Builder builder) { if (CollectionUtils.isNotEmpty(chromosomeIds)) { List<Term> chromosomeTerms = chromosomeIds.stream() .map(id -> new Term(FeatureIndexFields.CHROMOSOME_ID.getFieldName(), id.toString())) .collect(Collectors.toList()); builder.add(new TermsQuery(chromosomeTerms), BooleanClause.Occur.MUST); }/*from w ww . java 2s.c om*/ }
From source file:com.epam.catgenome.dao.DaoHelper.java
@Transactional(propagation = Propagation.MANDATORY) public Long createTempStringList(final Long listId, final Collection<String> list) { Assert.notNull(listId);/*from w w w . j a va 2s.c o m*/ Assert.isTrue(CollectionUtils.isNotEmpty(list)); // creates a new local temporary table if it doesn't exists to handle temporary lists getJdbcTemplate().update(createTemporaryStringListQuery); // fills in a temporary list by given values int i = 0; final Iterator<String> iterator = list.iterator(); final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()]; while (iterator.hasNext()) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(HelperParameters.LIST_ID.name(), listId); params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next()); batchArgs[i] = params; i++; } getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryStringListItemQuery, batchArgs); return listId; }
From source file:com.haulmont.cuba.core.sys.PersistenceSecurityImpl.java
@Override public void checkSecurityToken(Entity entity, View view) { if (BaseEntityInternalAccess.getSecurityToken(entity) == null) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); for (MetaProperty metaProperty : metaClass.getProperties()) { if (metaProperty.getRange().isClass() && metadataTools.isPersistent(metaProperty)) { if (entityStates.isDetached(entity) && !entityStates.isLoaded(entity, metaProperty.getName())) { continue; } else if (view != null && !view.containsProperty(metaProperty.getName())) { continue; }// w w w. j a v a 2s. c o m List<ConstraintData> existingConstraints = getConstraints(metaProperty.getRange().asClass(), constraint -> constraint.getCheckType().memory()); if (CollectionUtils.isNotEmpty(existingConstraints)) { throw new RowLevelSecurityException(format( "Could not read security token from entity %s, " + "even though there are active constraints for the related entities.", entity), entity.getMetaClass().getName()); } } } if (attributeSecuritySupport.isAttributeAccessEnabled(metaClass)) { throw new RowLevelSecurityException( format("Could not read security token from entity %s, " + "even though there are active attribute access for the entity.", entity), entity.getMetaClass().getName()); } } }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaSuggestionField.java
public void removePopupStyleName(String styleName) { if (CollectionUtils.isNotEmpty(getState(false).popupStylename)) { StringTokenizer tokenizer = new StringTokenizer(styleName, " "); while (tokenizer.hasMoreTokens()) { getState().popupStylename.remove(tokenizer.nextToken()); }/*from w w w . j a va 2 s . c o m*/ } }
From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java
/** * Loads a persisted {@code Reference} entity from the database by a specified Biological dataItemID * @param itemID {@code Reference} Biological DataItemID to load * @return loaded {@code Reference} instance *///from w ww . j ava2 s . c o m @Transactional(propagation = Propagation.MANDATORY) public Reference loadReferenceGenomeByBioItemId(final Long itemID) { final List<Reference> list = getNamedParameterJdbcTemplate().query(loadReferenceGenomeByBioIdQuery, new MapSqlParameterSource(GenomeParameters.BIO_DATA_ITEM_ID.name(), itemID), GenomeParameters.getReferenceGenomeMapper()); return CollectionUtils.isNotEmpty(list) ? list.get(0) : null; }
From source file:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java
/** * Fetch all orders grouped by quarter for the last 4 years. For this * iteration the orders are pulled for the last four years (including the * current year), which are 2017,16,15,14 * * @param departmentId/* ww w . ja v a2s. c om*/ * @return a structure of order totals grouped by quarter * * @throws com.oncore.calorders.core.exceptions.DataAccessException */ @GET @Path("fetchOrdersByQuarter/{departmentId}") @Produces({ MediaType.APPLICATION_JSON }) public OrdersByQuarterSeriesData fetchOrdersByQuarter(@PathParam("departmentId") Integer departmentId) throws DataAccessException { List<OrderHistory> orderHistoryList = null; OrdersByQuarterSeriesData ordersByQuarterSeriesData = new OrdersByQuarterSeriesData(); OrdersByQuarterData ordersByQuarterData = null; OrderItemData orderItemData = null; Calendar cal = Calendar.getInstance(); Department department = null; ordersByQuarterData = new OrdersByQuarterData(); ordersByQuarterData.setName("Jan"); ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData); ordersByQuarterData = new OrdersByQuarterData(); ordersByQuarterData.setName("Apr"); ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData); ordersByQuarterData = new OrdersByQuarterData(); ordersByQuarterData.setName("Jul"); ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData); ordersByQuarterData = new OrdersByQuarterData(); ordersByQuarterData.setName("Oct"); ordersByQuarterSeriesData.getOrdersByQuarterDataList().add(ordersByQuarterData); try { Logger.debug(LOG, "Hey testing logging, the fetchOrdersByQuarter is being called!"); department = getEntityManager().createNamedQuery("Department.findByDepUid", Department.class) .setParameter("depUid", departmentId).getSingleResult(); orderHistoryList = getEntityManager().createQuery( "SELECT o FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.createTs > '2014:01:01 15:06:39.673' ORDER BY o.createTs ASC", OrderHistory.class).setParameter("departmentId", department).getResultList(); String month = null; Integer year = null; if (CollectionUtils.isNotEmpty(orderHistoryList)) { for (OrderHistory order : orderHistoryList) { cal.setTime(order.getCreateTs()); month = this.getQuarterMonth(cal.get(Calendar.MONTH)); year = cal.get(Calendar.YEAR); if (year.equals(2015)) { year = 2015; } boolean found = false; for (OrdersByQuarterData quarter : ordersByQuarterSeriesData.getOrdersByQuarterDataList()) { if (month.equalsIgnoreCase(quarter.getName())) { found = false; if (CollectionUtils.isEmpty(quarter.getItems())) { OrderItemData item = new OrderItemData(); item.setYear(year); item.setY(1); item.setLabel(1); quarter.getItems().add(item); } else { for (OrderItemData item : quarter.getItems()) { if (year.equals(item.getYear())) { item.setY(item.getY() + 1); item.setLabel(item.getY()); found = true; break; } } if (!found) { OrderItemData item = new OrderItemData(); item.setYear(year); item.setY(1); item.setLabel(1); quarter.getItems().add(item); break; } } } } } } } catch (Exception ex) { Logger.error(LOG, FormatHelper.getStackTrace(ex)); throw new DataAccessException(ex, ErrorCode.DATAACCESSERROR); } return ordersByQuarterSeriesData; }