List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBRepositoryConfigExtension.java
private void postProcess(BeanDefinitionBuilder builder, String amazonDynamoDBRef, String dynamoDBMapperConfigRef, String dynamoDBOperationsRef) { if (StringUtils.hasText(dynamoDBOperationsRef)) { builder.addPropertyReference("dynamoDBOperations", dynamoDBOperationsRef); Assert.isTrue(!StringUtils.hasText(amazonDynamoDBRef), "Cannot specify both amazonDynamoDB bean and dynamoDBOperationsBean in repository configuration"); Assert.isTrue(!StringUtils.hasText(dynamoDBMapperConfigRef), "Cannot specify both dynamoDBMapperConfigBean bean and dynamoDBOperationsBean in repository configuration"); } else {/*from ww w .j a v a2 s . c o m*/ amazonDynamoDBRef = StringUtils.hasText(amazonDynamoDBRef) ? amazonDynamoDBRef : DEFAULT_AMAZON_DYNAMO_DB_BEAN_NAME; builder.addPropertyReference("amazonDynamoDB", amazonDynamoDBRef); if (StringUtils.hasText(dynamoDBMapperConfigRef)) { builder.addPropertyReference("dynamoDBMapperConfig", dynamoDBMapperConfigRef); } } }
From source file:grails.plugin.searchable.internal.compass.index.DefaultIndexMethod.java
public Object invoke(Object[] args) { Map options = SearchableMethodUtils.getOptionsArgument(args, getDefaultOptions()); final Class clazz = (Class) (options.containsKey("match") ? options.remove("match") : options.remove("class")); final List ids = getIds(args); final List objects = getObjects(args); validateArguments(args, clazz, ids, objects, options); if (args.length == 0 || (args.length == 1 && args[0] instanceof Map && clazz != null)) { CompassGpsUtils.index(compassGps, clazz); return null; }/*from ww w.j av a2s .c o m*/ return doInCompass(new CompassCallback() { public Object doInCompass(CompassSession session) throws CompassException { List objectsToSave = objects; if (clazz != null && !ids.isEmpty()) { Assert.isTrue(objects.isEmpty(), "Either provide ids or objects, not both"); objectsToSave = (List) InvokerHelper.invokeStaticMethod(clazz, "getAll", ids); } Assert.notEmpty(objectsToSave); for (Iterator iter = objectsToSave.iterator(); iter.hasNext();) { Object o = iter.next(); if (o != null) { session.save(o); } } return ids.isEmpty() ? (objectsToSave.size() == 1 ? objectsToSave.get(0) : objectsToSave) : (ids.size() == 1 ? objectsToSave.get(0) : objectsToSave); } }); }
From source file:com.github.philippn.springremotingautoconfigure.server.annotation.HttpInvokerServiceExporterRegistrar.java
private void setupExport(Class<?> clazz, String beanName, BeanDefinitionRegistry registry) { Assert.isTrue(clazz.isInterface(), "Annotation @RemoteExport may only be used on interfaces"); BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(HttpInvokerServiceExporter.class).addPropertyReference("service", beanName) .addPropertyValue("serviceInterface", clazz); String mappingPath = getMappingPath(clazz); registry.registerBeanDefinition(mappingPath, builder.getBeanDefinition()); logger.info(/*from w w w. jav a2 s . c om*/ "Mapping HttpInvokerServiceExporter for " + clazz.getSimpleName() + " to [" + mappingPath + "]"); }
From source file:net.projectmonkey.spring.acl.service.SimpleACLService.java
@Override public Map<ObjectIdentity, Acl> readAclsById(final List<ObjectIdentity> identities, final List<Sid> sids) throws NotFoundException { Assert.notNull(identities, "At least one Object Identity required"); Assert.isTrue(identities.size() > 0, "At least one Object Identity required"); Assert.noNullElements(identities.toArray(new ObjectIdentity[0]), "Null object identities are not permitted"); Map<ObjectIdentity, Acl> result = aclRepository.getAclsById(identities, sids); /*/*from ww w .j a v a 2 s . c om*/ * Check we found an ACL for every requested object. Where ACL's do not * exist for some objects throw a suitable exception. */ Set<ObjectIdentity> remainingIdentities = new HashSet<ObjectIdentity>(identities); if (result.size() != remainingIdentities.size()) { remainingIdentities.removeAll(result.keySet()); throw new NotFoundException( "Unable to find ACL information for object identities '" + remainingIdentities + "'"); } return result; }
From source file:grails.plugin.searchable.internal.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 * @param allSearchableGrailsDomainClasses all searchable domain classes, whether configured here or elsewhere *///from www . j a v a2 s .c om public void configureMappings(CompassConfiguration compassConfiguration, Map configurationContext, Collection searchableGrailsDomainClasses, Collection allSearchableGrailsDomainClasses) { 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); } } }
From source file:org.springmodules.validation.bean.conf.loader.annotation.handler.LengthValidationAnnotationHandler.java
protected void validateMin(int min, Class clazz, String propertyName) { Assert.isTrue(min >= 0, "@Length annotation on property '" + clazz.getName() + "." + propertyName + "' is mal-configured - 'min' attribute cannot hold a negative value"); }
From source file:com.abssh.util.PropertyFilter.java
/** * @param filterName/*from w w w . j a v a 2s. co m*/ * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ @SuppressWarnings("unchecked") public PropertyFilter(final String filterName, final Object value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); 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 = propertyNameStr.split(PropertyFilter.OR_SEPARATOR); Assert.isTrue(propertyNames.length > 0, "filter??" + filterName + ",??."); // entity property. if (value != null && (value.getClass().isArray() || Collection.class.isInstance(value) || value.toString().split(",").length > 1)) { // IN ? Object[] vObjects = null; if (value.getClass().isArray()) { vObjects = (Object[]) value; } else if (Collection.class.isInstance(value)) { vObjects = ((Collection) value).toArray(); } else { vObjects = value.toString().split(","); } this.propertyValue = new Object[vObjects.length]; for (int i = 0; i < vObjects.length; i++) { propertyValue[i] = ReflectionUtils.convertValue(vObjects[i], propertyType); } } else { Object tObject = ReflectionUtils.convertValue(value, propertyType); if (tObject != null && matchType == MatchType.LE && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 Date leDate = (Date) tObject; Calendar c = GregorianCalendar.getInstance(); c.setTime(leDate); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LEN && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 // Date leDate = (Date) tObject; // Calendar c = GregorianCalendar.getInstance(); // c.setTime(leDate); // tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LIKE) { tObject = ((String) tObject).replace("%", "\\%").replace("_", "\\_"); } this.propertyValue = new Object[] { tObject }; } }
From source file:com.gzj.tulip.jade.context.spring.JadeFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { Assert.isTrue(objectType.isInterface(), "not a interface class: " + objectType.getName()); Assert.notNull(dataAccessFactory);// w w w .j a va 2 s.c o m Assert.notNull(rowMapperFactory); Assert.notNull(interpreterFactory); // cacheProvider?null??assert.notNull }
From source file:com.crossover.trial.weather.domain.DataPointRepositoryImpl.java
@Override @Transactional//from w ww . j ava2 s. co m public void deleteAllMeasurements(IATA iata) { Assert.isTrue(iata != null, "iata is required"); manager.createQuery("delete from Measurement where id.iata = :iata").setParameter("iata", iata.getCode()) .executeUpdate(); }
From source file:com.azaptree.services.security.domain.impl.SessionImpl.java
public void validate() { Assert.notNull(subjectId, "subjectId is required"); Assert.isTrue(createdOn > 0, "constraint violated: createdOn > 0"); Assert.isTrue(lastAccessedOn >= createdOn, "constraint violated: lastAccessedOn >= createdOn"); Assert.isTrue(timeoutSeconds > 0, "constraint violated: timeoutSeconds > 0"); }