List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.index.DefaultIndexMethod.java
public Object invoke(Object[] args) { Map options = SearchableMethodUtils.getOptionsArgument(args, getDefaultOptions()); final Class clazz = (Class) options.get("class"); final List ids = getIds(args); final List objects = getObjects(args); validateArguments(args, clazz, ids, objects, options); if (isBulkAllowed() && args.length == 0 && clazz == null) { CompassGpsUtils.index(compassGps); return null; }/*from www.j a v a 2 s .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 null; } }); }
From source file:com.athena.chameleon.engine.core.converter.FileEncodingConverter.java
/** * <pre>/*from w ww . j a v a 2s. co m*/ * * </pre> * @param dir */ public void convert(File file, AnalyzeDefinition analyzeDefinition) { Assert.notNull(file, "file must not be null"); Assert.notNull(analyzeDefinition, "analyzeDefinition must not be null"); Assert.isTrue(file.exists(), file + " does not exist."); logger.debug("Convert Target Path or File : [{}]", file.getAbsolutePath()); this.analyzeDefinition = analyzeDefinition; fileSummaryMap = new HashMap<FileType, FileSummary>(); for (FileType fileType : fileTypes) { fileSummary = new FileSummary(); fileSummary.setFileType(fileType); fileSummaryMap.put(fileType, fileSummary); } PDFMetadataDefinition metadataDefinition = (PDFMetadataDefinition) ThreadLocalUtil .get(ChameleonConstants.PDF_METADATA_DEFINITION); analyzeDefinition.setFileName(file.getAbsolutePath()); analyzeDefinition.setFileSummaryMap(fileSummaryMap); warFileList = analyzeDefinition.getWarFileList(); jarFileList = analyzeDefinition.getJarFileList(); convertAll(file); if (policy.getConvertYn()) { executor.getExecutor().shutdown(); try { while (!executor.getExecutor().isTerminated()) { Thread.sleep(100); } } catch (InterruptedException e) { e.printStackTrace(); } } // Runnable Task ? ? Total Count . int totalCount = 0; for (FileType fileType : fileTypes) { if (!fileType.equals(FileType.SUM)) { totalCount += fileSummaryMap.get(fileType).getFileCount(); } } fileSummaryMap.get(FileType.SUM).setFileCount(totalCount); for (FileType fileType : fileTypes) { totalCount += fileSummaryMap.get(fileType).getFileCount(); logger.info("File Type : [{}], \tCount : [{}], \tSource Encoding : [{}], \tTarget Encoding : [{}]", new Object[] { String.format("%12s", fileSummaryMap.get(fileType).getFileType().toString()), String.format("%5s", fileSummaryMap.get(fileType).getFileCount()), String.format("%12s", fileSummaryMap.get(fileType).getSourceEncoding()), String.format("%5s", fileSummaryMap.get(fileType).getTargetEncoding()) }); } // ? ?? ? ? PDFMetadataDefinition? . String extension = file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase(); if (ArchiveType.ZIP.value().equals(extension)) { metadataDefinition.setZipDefinition(analyzeDefinition); } else if (ArchiveType.EAR.value().equals(extension)) { metadataDefinition.setEarDefinition(analyzeDefinition); } else if (ArchiveType.WAR.value().equals(extension)) { metadataDefinition.addWarDefinitionMap(file.getName(), analyzeDefinition); } else if (ArchiveType.JAR.value().equals(extension)) { metadataDefinition.addJarDefinitionMap(file.getName(), analyzeDefinition); } }
From source file:es.osoco.grails.plugins.otp.access.AbstractMultipleVoterFilterInvocationDefinition.java
/** * {@inheritDoc}// w w w . j a v a 2 s . c om * @see org.springframework.security.access.SecurityMetadataSource#getAttributes(java.lang.Object) */ public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { Assert.isTrue(object != null && supports(object.getClass()), "Object must be a FilterInvocation"); FilterInvocation filterInvocation = (FilterInvocation) object; String url = determineUrl(filterInvocation); Collection<ConfigAttribute> configAttributes; try { configAttributes = findConfigAttributes(url); } catch (Exception e) { // TODO fix this throw new RuntimeException(e); } if (configAttributes == null && _rejectIfNoRule) { return DENY; } return configAttributes; }
From source file:com.zhengmo.data.transaction.ChainedTransactionManager.java
/** * Creates a new {@link ChainedTransactionManager} using the given {@link SynchronizationManager} and {@link PlatformTransactionManager}s. * /*from ww w. ja va 2 s .c o m*/ * @param synchronizationManager must not be {@literal null}. * @param transactionManagers must not be {@literal null} or empty. */ ChainedTransactionManager(SynchronizationManager synchronizationManager, PlatformTransactionManager... transactionManagers) { Assert.notNull(synchronizationManager, "SynchronizationManager must not be null!"); Assert.notNull(transactionManagers, "Transaction managers must not be null!"); Assert.isTrue(transactionManagers.length > 0, "At least one PlatformTransactionManager must be given!"); this.synchronizationManager = synchronizationManager; this.transactionManagers = asList(transactionManagers); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.TrustedIdpDAOJPATest.java
@Test public void testAddNewTrustedIdp() { String realm = "urn:org:apache:cxf:fediz:trusted-idp:testadd"; TrustedIdp trustedIdp = createTrustedIdp(realm); trustedIdpDAO.addTrustedIDP(trustedIdp); trustedIdp = trustedIdpDAO.getTrustedIDP(realm); Assert.isTrue("realmb.cert".equals(trustedIdp.getCertificate()), "Certificate name doesn't match"); Assert.isTrue("Realm B description".equals(trustedIdp.getDescription()), "Description name doesn't match"); Assert.isTrue(FederationType.FEDERATE_IDENTITY.equals(trustedIdp.getFederationType()), "FederationType doesn't match"); Assert.isTrue("Realm B".equals(trustedIdp.getName()), "Name doesn't match"); Assert.isTrue("http://docs.oasis-open.org/wsfed/federation/200706".equals(trustedIdp.getProtocol()), "Protocol doesn't match"); Assert.isTrue(realm.equals(trustedIdp.getRealm()), "Realm doesn't match"); Assert.isTrue(TrustType.PEER_TRUST.equals(trustedIdp.getTrustType()), "TrustType doesn't match"); Assert.isTrue("https://localhost:12443/fediz-idp-remote/federation".equals(trustedIdp.getUrl()), "Url doesn't match"); Assert.isTrue(!trustedIdp.isCacheTokens(), "CacheTokens doesn't match"); }
From source file:grails.plugin.searchable.internal.compass.search.SearchableCompassQueryBuilderSortOptionHelper.java
/** * Get the CompassQuery.SortDirection for the given property and optional order/direction Map entry * @param property either CompassQuery.SortImplicitType.SCORE or a class property name (String) * @param options a Map containg// w w w . j a v a 2s. c o m * @return */ public CompassQuery.SortDirection getSortDirection(Object property, Map options) { Assert.notNull(property, "sort property cannot be null"); Assert.notNull(options, "options Map cannot be null"); if (!options.containsKey(ORDER) && !options.containsKey(DIRECTION)) { return CompassQuery.SortDirection.AUTO; } Assert.isTrue( (options.containsKey(ORDER) && !options.containsKey(DIRECTION)) || (!options.containsKey(ORDER) && options.containsKey(DIRECTION)), "Either specify a sort '" + ORDER + "' or '" + DIRECTION + "' or neither but not both"); String value = (String) options.get(DIRECTION); if (value == null) { value = (String) options.get(ORDER); } Assert.isTrue(VALID_SORT_DIRECTION_VALUES.contains(value), "The sort order/direction '" + value + "' is not a valid value"); return property.equals(CompassQuery.SortImplicitType.SCORE) ? value.equals("asc") || value.equals("reverse") ? CompassQuery.SortDirection.REVERSE : CompassQuery.SortDirection.AUTO : value.equals("asc") || value.equals("auto") ? CompassQuery.SortDirection.AUTO : CompassQuery.SortDirection.REVERSE; }
From source file:org.spring.data.gemfire.app.dao.provider.DatabaseGemstoneDao.java
@PostConstruct public void init() { try {//from w ww. ja v a2 s . c o m Context jndiContext = getCache().getJNDIContext(); Object dataSourceObject = jndiContext.lookup(GEMFIREDB_JNDI_LOCATION); Assert.isTrue(dataSourceObject instanceof DataSource, String.format("Expected a javax.sql.DataSource object; but was %1$s%n", ObjectUtils.nullSafeClassName(dataSourceObject))); databaseTemplate = new JdbcTemplate((DataSource) dataSourceObject); System.out.printf("%1$s initialized!%n", getClass().getSimpleName()); } catch (NamingException e) { throw new InitializationException( String.format("Failed to initialize %1$s!", getClass().getSimpleName()), e); } }
From source file:org.jasig.portlet.emailpreview.security.JasyptPBEStringEncryptionServiceImpl.java
/** * {@inheritDoc}/*from ww w .ja v a2 s . c o m*/ */ @PostConstruct public void afterPropertiesSet() throws Exception { final String enc = this.encrypt(this.getClass().getName()); Assert.notNull(enc, "String encryption service is not properly configured."); final String dec = this.decrypt(enc); Assert.notNull(dec, "String decryption service is not properly configured."); Assert.isTrue(dec.equals(this.getClass().getName()), "String decryption failed to decode the encrypted text " + enc); if (usingDefaultEncryptionKey()) { logger.error( "Encryption key at default value. Change it in configuration.properties for improved security!"); } }
From source file:com.googlecode.jdbcproc.daofactory.impl.block.service.OutputParametersGetterBlockServiceImpl.java
private int findEntityParameterIndex(Method daoMethod) { int entityParameterIndex = -1; for (int i = 0; i < daoMethod.getParameterCount(); i++) { if (!BlockFactoryUtils.isSimpleOrListType(daoMethod.getParameterTypes()[i])) { entityParameterIndex = i;/*from w w w . ja v a 2 s. c om*/ break; } } Assert.isTrue(entityParameterIndex >= 0, "Did not find an entity parameter, although this is an entity (probably with lists)"); return entityParameterIndex; }
From source file:edu.byu.softwareDist.manager.impl.LicenseManagerImpl.java
@Override @Transactional(readOnly = false, propagation = REQUIRED) public LicenseSet saveLicenseSet(LicenseSet licenseSet, List<License> licenses) { final Set<License> newLicenses = new HashSet<License>(licenses); LicenseSet saved;//www.j a va 2s.com if (licenseSet.getLicenseSetId() == null) { saved = licenseSetDao.save(licenseSet); for (License license : newLicenses) { license.setLicenseSet(saved); licenseDao.save(license); } } else { //find the old one final LicenseSet old = licenseSetDao.findById(licenseSet.getLicenseSetId()); if (old.getSetType() != licenseSet.getSetType()) { throw new IllegalArgumentException("Cannot change type of a license set"); } saved = licenseSetDao.update(licenseSet); int licenseSetId = saved.getLicenseSetId(); //find all the licenses that are new -- we don't delete licenseSets final List<License> oldLicenses = licenseDao.findAllByLicenseSetId(licenseSetId); Collections.sort(oldLicenses); switch (licenseSet.getSetType()) { case COUNT_NO_KEY: { for (final License license : newLicenses) { license.setLicenseSet(saved); licenseDao.save(license); } break; } case COUNT_KEY: { if (oldLicenses == null || oldLicenses.isEmpty()) {//add the license to the set for (final License nl : newLicenses) { nl.setLicenseSet(saved); licenseDao.save(nl); } } else {//update the existing license //all the keys in this license set are the same, so the first license is as good as any Assert.isTrue(oldLicenses.size() == 1, "There should only be one license key in this type of license set."); final License oldLic = oldLicenses.get(0); final String key = oldLic.getLicenseKey(); Assert.notNull(key); for (final License license : newLicenses) { license.setLicenseSet(saved); if (!key.equals(license.getLicenseKey())) { throw new IllegalStateException( "License key must be the same for all licenses in this licence set"); } if (license.getMaxQty() != null) oldLic.setMaxQty(license.getMaxQty()); if (license.getStatus() != null) oldLic.setStatus(license.getStatus()); licenseDao.update(oldLic); } } break; } case UNIQUE: { //verify that we aren't adding any new keys that already exist in the license set for (License license : newLicenses) { final String key = license.getLicenseKey(); Assert.notNull(key); final UniqueKeyLicense x = new UniqueKeyLicense(key); license.setLicenseSet(old); if (!oldLicenses.contains(x)) { licenseDao.save(license); } } break; } case UNLIMIT_KEY: { /** * It doesn't make sense to add another unlimited with same key license because it will never be used. * It should be added to a new license set */ break; } case UNLIMIT_NO_KEY: { /** * It doesn't make sense to add another unlimited with no key license because it will never be used. * It should be added as a new license set if needed */ break; } default: assert false; } } return saved; }