List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:com.athena.peacock.controller.web.software.SoftwareController.java
/** * <pre>/*from w w w . j av a 2 s . com*/ * ? Agent(machineID)? ? * </pre> * @param jsonRes * @param machineId * @return * @throws Exception */ @RequestMapping("/list") public @ResponseBody GridJsonResponse list(GridJsonResponse jsonRes, MachineDto machine) throws Exception { Assert.isTrue(!StringUtils.isEmpty(machine.getMachineId()), "machineId must not be null."); jsonRes.setTotal(softwareService.getSoftwareInstallListCnt(machine)); jsonRes.setList(softwareService.getSoftwareInstallList(machine)); return jsonRes; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPATest.java
@Test public void testAddNewEntitlement() { Entitlement entitlement5 = new Entitlement(); entitlement5.setName("GUGUS_CREATE"); entitlement5.setDescription("Any entitlement"); entitlementDAO.addEntitlement(entitlement5); List<Entitlement> entitlements = entitlementDAO.getEntitlements(0, 999); Assert.isTrue(31 == entitlements.size(), "Size doesn't match. Entitlement not added"); }
From source file:com.athena.chameleon.engine.core.analyzer.support.EarAnalyzer.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a v a2 s . c o m*/ public String analyze(File file) { Assert.notNull("file", "file must not be null."); Assert.isTrue(file.getName().endsWith(".ear"), "file name must be ends with \".ear\"."); // ? ?? ? ? .(jboss-app.xml, jboss-web.xml ? ? ) ThreadLocalUtil.add(ChameleonConstants.PROJECT_NAME, file.getName().substring(0, file.getName().lastIndexOf("."))); String newFileName = null; try { // ? MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP1); MigrationStatusUtil.setPercentage(this, 20); String tempDir = policy.getUnzipDir() + File.separator + System.currentTimeMillis(); ZipUtil.decompress(file.getAbsolutePath(), tempDir); ThreadLocalUtil.add(ChameleonConstants.EAR_ROOT_DIR, tempDir); // EAR ? ? Web Application(s) ? EJB Application(s) ? ? Exploded // EarAnalyzer ? Application ? ?? ? , ?? ?, ? ?, deployment descriptor XML ? ? ? // ?. ? EarAnalyzer /META-INF/application.xml ?? ? // Web Application(s), EJB Applicaiton(s) ?, FileEncodingConverter ? , analyze() ? ? ? // ? Application ?? . //File appplicationXmlFile = new File(tempDir, "META-INF/application.xml"); File appplicationXmlFile = getAppllicationXml(new File(tempDir)); if (appplicationXmlFile != null && appplicationXmlFile.exists()) { new ApplicationXMLParser().parse(appplicationXmlFile, analyzeDefinition); warFileList = (List<File>) ThreadLocalUtil.get(ChameleonConstants.WAR_FILE_LIST); jarFileList = (List<File>) ThreadLocalUtil.get(ChameleonConstants.JAR_FILE_LIST); } else { warFileList = new ArrayList<File>(); jarFileList = new ArrayList<File>(); } analyzeDefinition.setWarFileList(warFileList); analyzeDefinition.setJarFileList(jarFileList); // ? MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP3); MigrationStatusUtil.setPercentage(this, 40); converter.convert(new File(tempDir), analyzeDefinition); // classes ? ? . if (!StringUtils.isEmpty(getClassesDirPath(new File(tempDir)))) { JarClassLoader jcl = null; List<String> pathList = analyzeDefinition.getLibraryFullPathList(); for (String str : pathList) { try { if (jcl == null) { jcl = new JarClassLoader(new File(str).toURI().toURL()); } else { jcl.addJarURL(new File(str).toURI().toURL().toString()); } } catch (Exception e) { // Ignore. logger.error("[{}] file can't add to Class Loader.", str); } } if (jcl == null) { jcl = new JarClassLoader(this.getClass().getResource("/lib/ejb-api-3.0.jar").toString()); } else { jcl.addJarURL(this.getClass().getResource("/lib/ejb-api-3.0.jar").toString()); } jcl.addJarURL(this.getClass().getResource("/lib/javax.servlet-api-3.0.1.jar").toString()); jcl.addJarURL(this.getClass().getResource("/lib/javaee-api-6.0.jar").toString()); jcl.addJarURL(this.getClass().getResource("/lib/weblogic.jar").toString()); jcl.addJarURL(this.getClass().getResource("/lib/jeus.jar").toString()); analyzeDefinition.setJcl(jcl); ClasspathUtil.addPath(getClassesDirPath(new File(tempDir)), jcl); } // ? ?? ?. MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP3); MigrationStatusUtil.setPercentage(this, 60); analyze(new File(tempDir), tempDir); // war ?? war ?? ?. if (warFileList != null && warFileList.size() > 0) { MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP3_1); MigrationStatusUtil.setPercentage(this, 70); PDFMetadataDefinition metadataDefinition = (PDFMetadataDefinition) ThreadLocalUtil .get(ChameleonConstants.PDF_METADATA_DEFINITION); AnalyzeDefinition warDefinition = null; for (File warFile : warFileList) { warDefinition = new AnalyzeDefinition(); metadataDefinition.addWarDefinitionMap(warFile.getName(), warDefinition); // web xml ? jboss-web.xml ?? ThreadLocalUtil.add(ChameleonConstants.DEPLOY_DIR_IN_EAR, removeTempDir(warFile.getAbsolutePath(), ChameleonConstants.EAR_ROOT_DIR)); new WarAnalyzer(policy, converter, executor, warDefinition, true).analyze(warFile); } } // jar ?? jar ?? ?. if (jarFileList != null && jarFileList.size() > 0) { MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP3_2); MigrationStatusUtil.setPercentage(this, 80); PDFMetadataDefinition metadataDefinition = (PDFMetadataDefinition) ThreadLocalUtil .get(ChameleonConstants.PDF_METADATA_DEFINITION); AnalyzeDefinition jarDefinition = null; for (File jarFile : jarFileList) { jarDefinition = new AnalyzeDefinition(); jarDefinition.setFileName(jarFile.getName()); metadataDefinition.addJarDefinitionMap(jarFile.getName(), jarDefinition); // ejb xml ? jboss.xml ?? ThreadLocalUtil.add(ChameleonConstants.DEPLOY_DIR_IN_EAR, removeTempDir(jarFile.getAbsolutePath(), ChameleonConstants.EAR_ROOT_DIR)); new JarAnalyzer(policy, converter, executor, jarDefinition, true).analyze(jarFile); } } // jboss-classloading.xml ?? ?. makeClassLoading(getMetaInfDirPath(new File(tempDir)), file.getName(), null); // ear ? . MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP4); MigrationStatusUtil.setPercentage(this, 90); newFileName = getResultFile(file); ZipUtil.compress(tempDir, newFileName, ArchiveType.EAR); // . MigrationStatusUtil.setCurrentStatus(MigrationStatusUtil.STEP5); MigrationStatusUtil.setPercentage(this, 100); deleteDirectory(new File(tempDir)); ThreadLocalUtil.add(ChameleonConstants.EAR_ROOT_DIR, null); } catch (Exception e) { logger.error("Unahandled Exception has occurred : ", e); } return newFileName; }
From source file:org.cloudbyexample.dc.web.service.docker.ApplicationController.java
@Override @RequestMapping(value = SAVE_REQUEST, method = RequestMethod.POST) public ApplicationResponse create(@RequestBody Application request) { Assert.isTrue(!isPrimaryKeyValid(request), "Create should not have a valid primary key."); logger.info("Save application. id={}", request.getId()); return service.create(request); }
From source file:grails.plugin.cache.ehcache.GrailsEhcacheCacheManager.java
protected Collection<Cache> loadCaches() { Assert.notNull(cacheManager, "A backing EhCache CacheManager is required"); Status status = cacheManager.getStatus(); Assert.isTrue(Status.STATUS_ALIVE.equals(status), "An 'alive' EhCache CacheManager is required - current cache is " + status); String[] names = cacheManager.getCacheNames(); Collection<Cache> caches = new LinkedHashSet<Cache>(names.length); for (String name : names) { caches.add(new GrailsEhcacheCache(cacheManager.getEhcache(name))); }//from w ww . j ava2s. c o m return caches; }
From source file:com.sshdemo.common.security.manage.service.UserService.java
@Override public String addUser(final String username, final String password, final boolean enabled, final Date accountStart, final Date accountEnd, final UserInfo userInfo) throws UserServiceException { if (accountStart != null && accountEnd != null) { Assert.isTrue(accountEnd.getTime() > accountStart.getTime(), "account date start > end"); }/*from w w w. j ava 2 s . c o m*/ if (hasUsername(username)) { throw new UserServiceException( messages.getMessage("UserService.usernameExist", "username already exist")); } User user = new User(username, enabled, accountStart, accountEnd); UserInfo info = (userInfo != null ? userInfo : new UserInfo()); info.setUsername(username); if (info.getName() == null) { info.setName(username); } user.setUserInfo(info); //?? String newPassword = StringUtils.isBlank(password) ? defaultPassword : password; user.setPassword(newPassword); //UserDetails password? UserDetails userDetails = createUserDetails(user); user.setPassword(passwordEncoder(userDetails, newPassword)); userDao.persist(user); return username; }
From source file:apiserver.core.common.messageHandlers.PreOrPostWireTap.java
/** * Create a new wire tap with the provided {@link MessageSelector}. * * @param preSendChannel the channel to which intercepted messages will be sent * @param postSendChannel the channel to which intercepted messages will be sent * @param selector the selector that must accept a message for it to be * sent to the intercepting channel *///from www .j a va2 s.c o m public PreOrPostWireTap(MessageChannel preSendChannel, MessageChannel postSendChannel, MessageSelector selector) { Assert.isTrue((preSendChannel != null || postSendChannel != null), "at least one channel must be defined"); this.preSendChannel = preSendChannel; this.postSendChannel = postSendChannel; this.selector = selector; }
From source file:org.agatom.springatom.data.vin.model.VinNumber.java
private VinNumber(final String vinNumber) throws VinNumberServiceException { try {/*from w w w . ja v a2 s.c o m*/ Assert.hasText(vinNumber, "VinNumber must not be empty or null"); Assert.isTrue(vinNumber.length() == 17, "VinNumber must have correct length"); } catch (Exception exp) { throw new VinNumberServiceException("VinNumber is either null or has insufficient length 17", exp); } this.vinNumber = vinNumber; this.splitVinNumber(); }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.search.DefaultStringQuerySearchableCompassQueryBuilder.java
public CompassQuery buildQuery(GrailsApplication grailsApplication, CompassSession compassSession, Map options, Object query) {/*from w ww . j a v a 2s. c o m*/ Assert.notNull(query, "query cannot be null"); Assert.isInstanceOf(String.class, query, "query must be a String but is [" + query.getClass().getName() + "]"); String analyzer = (String) getOption(ANALYZER_NAMES, options); String parser = (String) getOption(PARSER_NAMES, options); String defaultSearchProperty = (String) getOption(DEFAULT_PROPERTY_NAMES, options); Collection properties = (Collection) getOption(PROPERTIES_NAMES, options); Boolean useAndDefaultOperator = (Boolean) getOption(USE_AND_DEFAULT_OPERATOR_NAMES, options); Boolean escape = MapUtils.getBoolean(options, "escape", Boolean.FALSE); Assert.isTrue(!(properties != null && defaultSearchProperty != null), "The " + DefaultGroovyMethods.join(DEFAULT_PROPERTY_NAMES, "/") + " and " + DefaultGroovyMethods.join(PROPERTIES_NAMES, "/") + " options cannot be combined"); String queryString = (String) query; if (escape.booleanValue()) { queryString = CompassQueryParser.escape(queryString); } CompassQueryBuilder compassQueryBuilder = compassSession.queryBuilder(); CompassQueryBuilder.ToCompassQuery stringBuilder; if (properties != null && !properties.isEmpty()) { stringBuilder = compassQueryBuilder.multiPropertyQueryString(queryString); for (Iterator iter = properties.iterator(); iter.hasNext();) { ((CompassQueryBuilder.CompassMultiPropertyQueryStringBuilder) stringBuilder) .add((String) iter.next()); } } else { stringBuilder = compassQueryBuilder.queryString(queryString); } if (analyzer != null) { InvokerHelper.invokeMethod(stringBuilder, "setAnalyzer", analyzer); } if (parser != null) { InvokerHelper.invokeMethod(stringBuilder, "setQueryParser", parser); } if (defaultSearchProperty != null) { InvokerHelper.invokeMethod(stringBuilder, "setDefaultSearchProperty", defaultSearchProperty); } if (useAndDefaultOperator != null && useAndDefaultOperator.booleanValue()) { InvokerHelper.invokeMethod(stringBuilder, "useAndDefaultOperator", null); } return stringBuilder.toQuery(); }