List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:com.cndatacom.core.orm.PropertyFilter.java
/** * @param filterName ,???. //ww w . j ava 2 s . c om * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { this.filterName = filterName; this.value = value; String matchTypeStr = StringUtils.substringBefore(filterName, "_"); //,EQ String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); //?,S?I String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); //propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR); Assert.isTrue(propertyNames.length > 0, "filter??" + filterName + ",??."); //entity property. if (propertyNameStr.indexOf(LEFT_JION) != -1) { isLeftJion = true; } // Object value_ = null; if (null == value || value.equals("")) { this.propertyValue = null; } else { this.propertyValue = ReflectionUtils.convertStringToObject(value, propertyType); value_ = propertyValue; //?1 if (propertyType.equals(Date.class) && filterName.indexOf("LTD") > -1) { propertyValue = DateUtils.addDays((Date) propertyValue, 1); } } //request? String key = propertyNames[0].replace(".", "_").replace(":", "_"); // if(propertyType!=Date.class) //// Struts2Utils.getRequest().setAttribute(key, propertyValue); //// else{ //// if(Struts2Utils.getRequest().getAttribute(key)!=null){ //// String time_begin=Struts2Utils.getRequest().getAttribute(key)+""; //// Struts2Utils.getRequest().setAttribute(key, time_begin+"="+com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd")); //// }else{ //// Struts2Utils.getRequest().setAttribute(key, com.cndatacom.common.utils.DateUtil.format((Date)value_,"yyyy-MM-dd")); //// } // // } }
From source file:com.cspinformatique.blc.braintree.payment.service.gateway.BraintreePaymentGatewayTransparentRedirectServiceImpl.java
protected PaymentResponseDTO createCommonTRFields(PaymentRequestDTO requestDTO) { Assert.isTrue(requestDTO.getTransactionTotal() != null, "The Transaction Total on the Payment Request DTO must not be null"); Assert.isTrue(requestDTO.getOrderId() != null, "The Order ID on the Payment Request DTO must not be null"); // Put The shipping, billing, and transaction amount fields as hidden // fields on the form // In a real implementation, the gateway will probably provide some API // to tokenize this information // which you can then put on your form as a secure token. For this // sample,// ww w .ja va2s.c om // we will just place them as plain-text hidden fields on the form PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.CREDIT_CARD, BraintreePaymentGatewayType.BRAINTREE_GATEWAY) .responseMap(BraintreePaymentGatewayConstants.ORDER_ID, requestDTO.getOrderId()) .responseMap(BraintreePaymentGatewayConstants.TRANSACTION_AMT, requestDTO.getTransactionTotal()) .responseMap(BraintreePaymentGatewayConstants.TRANSPARENT_REDIRECT_URL, configuration.getTransparentRedirectUrl()); AddressDTO<PaymentRequestDTO> billTo = requestDTO.getBillTo(); if (billTo != null) { responseDTO .responseMap(BraintreePaymentGatewayConstants.BILLING_FIRST_NAME, billTo.getAddressFirstName()) .responseMap(BraintreePaymentGatewayConstants.BILLING_LAST_NAME, billTo.getAddressLastName()) .responseMap(BraintreePaymentGatewayConstants.BILLING_ADDRESS_LINE1, billTo.getAddressLine1()) .responseMap(BraintreePaymentGatewayConstants.BILLING_ADDRESS_LINE2, billTo.getAddressLine2()) .responseMap(BraintreePaymentGatewayConstants.BILLING_CITY, billTo.getAddressCityLocality()) .responseMap(BraintreePaymentGatewayConstants.BILLING_STATE, billTo.getAddressStateRegion()) .responseMap(BraintreePaymentGatewayConstants.BILLING_ZIP, billTo.getAddressPostalCode()) .responseMap(BraintreePaymentGatewayConstants.BILLING_COUNTRY, billTo.getAddressCountryCode()); } AddressDTO<PaymentRequestDTO> shipTo = requestDTO.getShipTo(); if (shipTo != null) { responseDTO .responseMap(BraintreePaymentGatewayConstants.SHIPPING_FIRST_NAME, shipTo.getAddressFirstName()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_LAST_NAME, shipTo.getAddressLastName()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_ADDRESS_LINE1, shipTo.getAddressLine1()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_ADDRESS_LINE2, shipTo.getAddressLine2()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_CITY, shipTo.getAddressCityLocality()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_STATE, shipTo.getAddressStateRegion()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_ZIP, shipTo.getAddressPostalCode()) .responseMap(BraintreePaymentGatewayConstants.SHIPPING_COUNTRY, shipTo.getAddressCountryCode()); } // Calls braintree API to retreive the client token. responseDTO.responseMap(BraintreePaymentGatewayConstants.BRAINTREE_CLIENT_TOKEN, gateway.clientToken().generate()); return responseDTO; }
From source file:org.xinta.eazycode.components.shiro.web.controller.ManageUsersController.java
@RequestMapping("/deleteUser") // @RequiresPermissions("user:delete") public String deleteUser(@RequestParam Long userId) { Assert.isTrue(userId != 1, "Cannot delete admin user"); userService.deleteUser(userId);/*from w w w.j a va 2 s .c o m*/ return "redirect:/manageUsers.do"; }
From source file:org.cleverbus.core.common.dao.ExternalCallDaoJpaImpl.java
@Override @Transactional(propagation = Propagation.MANDATORY) public void lockExternalCall(ExternalCall extCall) throws PersistenceException { Assert.notNull(extCall, "the extCall must not be null"); Assert.isTrue(extCall.getState() != ExternalCallStateEnum.PROCESSING, "the extCall must not be locked in a processing state"); Assert.isTrue(em.contains(extCall), "the extCall must be attached"); // note: https://blogs.oracle.com/carolmcdonald/entry/jpa_2_0_concurrency_and em.lock(extCall, LockModeType.OPTIMISTIC); extCall.setState(ExternalCallStateEnum.PROCESSING); }
From source file:org.opennms.ng.dao.support.DefaultRrdDao.java
/** * <p>getPrintValues</p>/*from w ww . ja va2 s.c o m*/ * * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object. * @param rraConsolidationFunction a {@link String} object. * @param startTimeInMillis a long. * @param endTimeInMillis a long. * @param printFunctions a {@link String} object. * @return an array of double. */ @Override public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) { Assert.notNull(attribute, "attribute argument must not be null"); Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null"); Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument"); Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute"); // if no printFunctions are given just use the rraConsolidationFunction if (printFunctions.length < 1) { printFunctions = new String[] { rraConsolidationFunction }; } RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute; String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction, }; String[] printDefs = new String[printFunctions.length]; for (int i = 0; i < printFunctions.length; i++) { printDefs[i] = "PRINT:ds:" + printFunctions[i] + ":\"%le\""; } String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " "); LOG.debug("commandString: {}", commandString); RrdGraphDetails graphDetails; try { graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure when generating graph to get data with command '" + commandString + "'", e); } String[] printLines; try { printLines = graphDetails.getPrintLines(); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure to get print lines from graph after graphing with command '" + commandString + "'", e); } if (printLines.length != printFunctions.length) { throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString); } double[] values = new double[printLines.length]; for (int i = 0; i < printLines.length; i++) { if (printLines[i].endsWith("nan")) { values[i] = Double.NaN; } else { try { values[i] = Double.parseDouble(printLines[i]); } catch (NumberFormatException e) { throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'"); } } } return values; }
From source file:org.jasig.cas.adaptors.ldap.AbstractLdapUsernamePasswordAuthenticationHandler.java
public final void afterPropertiesSet() throws Exception { Assert.isTrue(this.filter.contains("%u") || this.filter.contains("%U"), "filter must contain %u or %U"); if (this.ldapTemplate == null) { this.ldapTemplate = new LdapTemplate(this.contextSource); }/*from w w w .java2 s . c o m*/ this.ldapTemplate.setIgnorePartialResultException(this.ignorePartialResultException); afterPropertiesSetInternal(); }
From source file:com.crossover.trial.weather.domain.DataPointRepositoryImpl.java
@Override @Transactional(readOnly = true)/*w ww . j a v a 2 s . c o m*/ public Measurement findLatestMeasurementForIata(Airport airport) { Assert.isTrue(airport != null, "airport is required"); return findLatestMeasurementForIata(airport.getIata()); }
From source file:be.vlaanderen.sesam.monitor.internal.util.ThreadPoolTaskScheduler.java
/** * Set the ScheduledExecutorService's pool size. * Default is 1./*from w w w . java 2 s . co m*/ */ public void setPoolSize(int poolSize) { Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher"); this.poolSize = poolSize; }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.config.mapping.CompassMappingXmlSearchableGrailsDomainClassMappingConfigurator.java
/** * Configure the Mapping in the CompassConfiguration for the given domain class * * @param compassConfiguration the CompassConfiguration instance * @param configurationContext a configuration context, for flexible parameter passing * @param searchableGrailsDomainClasses searchable domain classes to map *//* w w w . ja v a 2s. co m*/ public void configureMappings(CompassConfiguration compassConfiguration, Map configurationContext, Collection searchableGrailsDomainClasses) { Assert.notNull(resourceLoader, "resourceLoader cannot be null"); if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) { return; } for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext();) { GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next(); Resource resource = getMappingResource(grailsDomainClass); Assert.isTrue(resource.exists(), "expected mapping resource [" + resource + "] to exist but it does not"); try { compassConfiguration.addURL(resource.getURL()); } catch (IOException ex) { String message = "Failed to configure Compass with mapping resource for class [" + grailsDomainClass.getClazz().getName() + "] and resource [" + getMappingResourceName(grailsDomainClass) + "]"; LOG.error(message, ex); throw new IllegalStateException(message + ": " + ex); } } }