List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:net.kamhon.ieagle.datagrid.DefaultDatagridModel.java
public void setSorterColumnName(int index, String sortColName) { Assert.isTrue(sorters.size() >= index, "sorters.size() must equals or greater than index"); if (sorters.size() >= index + 1) { Sorter sorter = (Sorter) sorters.get(index); sorter.setColumn(sortColName);//from w w w . j av a2 s .c o m } else if (sorters.size() == index) { Sorter sorter = new DefaultSorter(); sorter.setColumn(sortColName); sorters.add(index, sorter); } }
From source file:com.excilys.ebi.utils.spring.log.slf4j.InjectLoggerAnnotationBeanPostProcessor.java
/** * Processes a bean's fields for injection if it has a {@link InjectLogger} * annotation./*from w w w . j a v a2 s. c om*/ */ protected void processLogger(final Object bean) { final Class<?> clazz = bean.getClass(); ReflectionUtils.doWithFields(clazz, new FieldCallback() { public void doWith(Field field) { Annotation annotation = field.getAnnotation(InjectLogger.class); if (annotation != null) { int modifiers = field.getModifiers(); Assert.isTrue(!Modifier.isStatic(modifiers), "InjectLogger annotation is not supported on static fields"); Assert.isTrue(!Modifier.isFinal(modifiers), "InjectLogger annotation is not supported on final fields"); ReflectionUtils.makeAccessible(field); Logger logger = LoggerFactory.getLogger(clazz); ReflectionUtils.setField(field, bean, logger); } } }); }
From source file:org.broadleafcommerce.payment.service.gateway.AuthorizeNetTransparentRedirectServiceImpl.java
public PaymentResponseDTO common(PaymentRequestDTO requestDTO, Boolean submitForSettlement) { Assert.isTrue(requestDTO.getOrderId() != null, "Must pass an OrderId value on the Payment Request DTO"); Assert.isTrue(requestDTO.getTransactionTotal() != null, "Must pass a Transaction Total value on the Payment Request DTO"); String apiLoginId = configuration.getLoginId(); String transactionKey = configuration.getTransactionKey(); String relayResponseURL = configuration.getResponseUrl(); String merchantTransactionVersion = configuration.getTransactionVersion(); String xTestRequest = configuration.getXTestRequest(); String serverUrl = configuration.getServerUrl(); String custId = requestDTO.getCustomer().getCustomerId(); String orderId = requestDTO.getOrderId(); Fingerprint fingerprint = Fingerprint.createFingerprint(apiLoginId, transactionKey, System.currentTimeMillis(), requestDTO.getTransactionTotal()); PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.CREDIT_CARD, AuthorizeNetGatewayType.AUTHORIZENET) .responseMap(AuthNetField.X_INVOICE_NUM.getFieldName(), System.currentTimeMillis() + "") .responseMap(AuthNetField.X_RELAY_URL.getFieldName(), relayResponseURL) .responseMap(AuthNetField.X_LOGIN.getFieldName(), apiLoginId) .responseMap(AuthNetField.X_FP_SEQUENCE.getFieldName(), fingerprint.getSequence() + "") .responseMap(AuthNetField.X_FP_TIMESTAMP.getFieldName(), fingerprint.getTimeStamp() + "") .responseMap(AuthNetField.X_FP_HASH.getFieldName(), fingerprint.getFingerprintHash()) .responseMap(AuthNetField.X_VERSION_FIELD.getFieldName(), merchantTransactionVersion) .responseMap(AuthNetField.X_METHOD.getFieldName(), "CC") .responseMap(AuthNetField.X_TYPE.getFieldName(), submitForSettlement ? AUTH_CAPTURE : AUTH_ONLY) .responseMap(AuthNetField.X_AMOUNT.getFieldName(), requestDTO.getTransactionTotal()) .responseMap(AuthNetField.X_TEST_REQUEST.getFieldName(), xTestRequest) .responseMap(AuthNetField.X_RELAY_RESPONSE.getFieldName(), "true") .responseMap(AuthNetField.X_CUST_ID.getFieldName(), custId) .responseMap(AuthNetField.X_TRANS_ID.getFieldName(), orderId) .responseMap(MessageConstants.BLC_CID, custId) .responseMap(MessageConstants.BLC_OID, orderId) .responseMap(MessageConstants.AUTHORIZENET_SERVER_URL, serverUrl); if (requestDTO.billToPopulated()) { responseDTO/*from w w w. j a v a 2 s.c om*/ .responseMap(AuthNetField.X_FIRST_NAME.getFieldName(), requestDTO.getBillTo().getAddressFirstName()) .responseMap(AuthNetField.X_LAST_NAME.getFieldName(), requestDTO.getBillTo().getAddressLastName()) .responseMap(AuthNetField.X_ADDRESS.getFieldName(), requestDTO.getBillTo().getAddressLine1()) .responseMap(AuthNetField.X_CITY.getFieldName(), requestDTO.getBillTo().getAddressCityLocality()) .responseMap(AuthNetField.X_STATE.getFieldName(), requestDTO.getBillTo().getAddressStateRegion()) .responseMap(AuthNetField.X_ZIP.getFieldName(), requestDTO.getBillTo().getAddressPostalCode()) .responseMap(AuthNetField.X_COUNTRY.getFieldName(), requestDTO.getBillTo().getAddressCountryCode()) .responseMap(AuthNetField.X_EMAIL.getFieldName(), requestDTO.getBillTo().getAddressEmail() != null ? requestDTO.getBillTo().getAddressEmail() : requestDTO.getCustomer().getEmail()) .responseMap(AuthNetField.X_PHONE.getFieldName(), requestDTO.getBillTo().getAddressPhone()); } for (String fieldKey : requestDTO.getAdditionalFields().keySet()) { responseDTO.responseMap(fieldKey, (String) requestDTO.getAdditionalFields().get(fieldKey)); } try { responseDTO.responseMap(MessageConstants.BLC_TPS, authorizeNetCheckoutService.createTamperProofSeal(custId, orderId)); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return responseDTO; }
From source file:net.projectmonkey.spring.acl.hbase.repository.AccessControlEntryValue.java
public AccessControlEntryValue(final byte[] key, final PermissionFactory permissionFactory) { Assert.notNull(key, "key must not be null"); Assert.notNull(permissionFactory, "permissionFactory must not be null"); String keyString = new String(key); String[] values = keyString.split(SEPARATOR); String authority = values[1]; boolean principal = Boolean.valueOf(values[2]); int permissionMask = Integer.parseInt(values[3]); Assert.isTrue(values.length == 5, "Key must consist of 5 values separated by :"); this.id = UUID.fromString(values[0]); this.sid = SidUtil.createSid(authority, principal); this.permission = permissionFactory.buildFromMask(permissionMask); this.granting = Boolean.valueOf(values[4]); this.authority = authority; this.key = key; }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java
public DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl(final Class<T> domainType) { super(domainType); this.hashAndRangeKeyMethodExtractor = new DynamoDBHashAndRangeKeyMethodExtractorImpl<T>(getJavaType()); ReflectionUtils.doWithMethods(domainType, new MethodCallback() { public void doWith(Method method) { if (method.getAnnotation(DynamoDBHashKey.class) != null) { String setterMethodName = toSetterMethodNameFromAccessorMethod(method); if (setterMethodName != null) { hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName, method.getReturnType()); }//from ww w. ja va 2 s. com } } }); ReflectionUtils.doWithFields(domainType, new FieldCallback() { public void doWith(Field field) { if (field.getAnnotation(DynamoDBHashKey.class) != null) { hashKeyField = ReflectionUtils.findField(domainType, field.getName()); } } }); Assert.isTrue(hashKeySetterMethod != null || hashKeyField != null, "Unable to find hash key field or setter method on " + domainType + "!"); Assert.isTrue(hashKeySetterMethod == null || hashKeyField == null, "Found both hash key field and setter method on " + domainType + "!"); }
From source file:ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.java
@SuppressWarnings("unchecked") public ConstructorAnnotationRowMapper(Class<T> clazz, Collection<ColumnMapperFactory> columnMapperFactories) { int constructorCount = clazz.getConstructors().length; Assert.isTrue(constructorCount == 1, "The class " + clazz.getName() + " must have exactly one public constructor, " + constructorCount + " are present"); con = (Constructor<T>) clazz.getConstructors()[0]; mappedColumn = from(clazz, con.getParameterAnnotations(), con.getParameterTypes(), columnMapperFactories); }
From source file:com.jaxio.celerio.template.pack.LocalResourcePackFile.java
private File convertToFile(String folder) { Assert.notNull(folder, "LocalResourcePackFile pack points to an null folder"); File result = new File(folder); Assert.isTrue(result.exists(), "LocalResourcePackFile pack points to an unknown folder : " + folder); return result; }
From source file:com.fns.grivet.repo.JdbcEntityRepository.java
@Override public void save(Long eid, Attribute attribute, AttributeType attributeType, Object rawValue, LocalDateTime createdTime) { Assert.isTrue(rawValue != null, String .format("Attempt to persist value failed! %s's value must not be null!", attribute.getName())); Object value = ValueHelper.toValue(attributeType, rawValue); String createdBy = getCurrentUsername(); String[] columns = { "eid", "aid", "val", "created_time" }; Map<String, Object> keyValuePairs = ImmutableMap.of("eid", eid, "aid", attribute.getId(), "val", value, "created_time", Timestamp.valueOf(createdTime)); if (createdBy != null) { columns = Arrays.copyOf(columns, columns.length + 1); columns[columns.length - 1] = "created_by"; Map<String, Object> keyValuePairsWithCreatedBy = new HashMap<>(keyValuePairs); keyValuePairsWithCreatedBy.put("created_by", createdBy); keyValuePairs = keyValuePairsWithCreatedBy; }/*from w w w.j a v a 2s . c om*/ new SimpleJdbcInsert(jdbcTemplate).withTableName(String.join("_", "entityav", attributeType.getType())) .usingColumns(columns).execute(keyValuePairs); }
From source file:org.openregistry.core.domain.jpa.JpaActivationKeyImpl.java
public JpaActivationKeyImpl(final Date startDate, final Date endDate) { Assert.isTrue((startDate != null && endDate != null) || (startDate == null && endDate == null), "Both start and end date must be specified, or they must both be null to use the default value."); if (startDate == null && endDate == null) { final Calendar calendar = Calendar.getInstance(); final Date localStartDate = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 10); final Date localEndDate = calendar.getTime(); this.start = localStartDate; this.end = localEndDate; } else {//from w w w . j a v a 2 s .c om Assert.isTrue(endDate.compareTo(startDate) > 0, "The End Date MUST be after the Start Date."); this.start = new Date(startDate.getTime()); this.end = new Date(endDate.getTime()); } this.value = constructNewValue(); }
From source file:com.dosport.hibernate.utils.PropertyFilter.java
/** * @param filterName//from ww w . j ava 2 s . co m * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }