List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:com.ewcms.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, final Integer organId) throws UserServiceException { Organ organ = null;//w w w.ja v a 2s . c o m if (organId != null) { organ = siteFac.getOrgan(organId); } if (accountStart != null && accountEnd != null) { Assert.isTrue(accountEnd.getTime() > accountStart.getTime(), "account date start > end"); } 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); user.setOrgan(organ); //?? 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:org.obiba.onyx.core.identifier.impl.randomincrement.RandomIncrementIdentifierSequence.java
private IdentifierSequenceState loadSequenceState() { List<IdentifierSequenceState> result = persistenceManager.list(IdentifierSequenceState.class); Assert.notEmpty(result, "IdentifierSequenceState does not exist (was the startSequence method called?)"); Assert.isTrue(result.size() == 1, "Unexpected number of IdentifierSequenceState entities: " + result.size() + " (expected 1)"); return result.get(0); }
From source file:org.apache.shiro.samples.sprhib.web.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 ww . j av a2s . c o m*/ return "redirect:/s/manageUsers"; }
From source file:org.cloudbyexample.dc.web.service.docker.ProvisionController.java
@Override @RequestMapping(value = UPDATE_REQUEST, method = RequestMethod.PUT) public ProvisionResponse update(@RequestBody Provision request) { Assert.isTrue(isPrimaryKeyValid(request), "Update should have a valid primary key."); logger.info("Update provision. id={}", request.getId()); return service.update(request); }
From source file:com.athena.chameleon.common.utils.ZipUtil.java
/** * <pre>//from ww w. j a va 2 s. co m * ? ?? ? ? . * </pre> * @param sourceFile * @param destDir * @return * @throws IOException */ public static boolean decompress(String sourceFile, String destDir) throws IOException { Assert.notNull(sourceFile, "sourceFile cannot be null."); File src = new File(sourceFile); File dest = null; Assert.isTrue(src.exists(), src + " does not exist."); Assert.isTrue(src.isFile(), sourceFile + " is not a file."); if (StringUtils.isEmpty(destDir)) { dest = new File(src.getParent(), src.getName().substring(0, src.getName().lastIndexOf("."))); } else { dest = new File(destDir); } Unzip unzip = new Unzip(); unzip.setSrc(src); unzip.setDest(dest); unzip.execute(); return true; }
From source file:JavaMvc.Controllers.ManageUsersController.java
@RequestMapping("/deleteUser") @RequiresPermissions("user:delete") public String deleteUser(@RequestParam Long userId) { Assert.isTrue(userId != 1, "Cannot delete admin user"); userService.deleteUser(userId);//ww w .j a v a2 s . com return "redirect:/manageUsers"; }
From source file:org.agatom.springatom.data.model.vin.VinNumber.java
private VinNumber(final String number) throws VinNumberServiceException { this();//www .j a v a2 s . c o m try { Assert.hasText(number, "VinNumber must not be empty or null"); Assert.isTrue(number.length() == 17, "VinNumber must have correct length"); } catch (Exception exp) { throw new VinNumberServiceException("VinNumber is either null or has insufficient length 17", exp); } this.setNumber(number); }
From source file:com.miko.demo.birt.core.BirtEngineFactory.java
private void validateLogDirectory(File f) { Assert.notNull(f, " the directory must not be null"); Assert.isTrue(f.isDirectory(), " the path given must be a directory"); Assert.isTrue(f.exists(), "the path specified must exist!"); }
From source file:grails.plugin.springsecurity.web.access.intercept.AbstractFilterInvocationDefinition.java
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { Assert.notNull(object, "Object must be a FilterInvocation"); Assert.isTrue(supports(object.getClass()), "Object must be a FilterInvocation"); FilterInvocation filterInvocation = (FilterInvocation) object; String url = determineUrl(filterInvocation); Collection<ConfigAttribute> configAttributes; try {//from www . j av a 2 s.co m configAttributes = findConfigAttributes(url, filterInvocation.getRequest().getMethod()); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } if ((configAttributes == null || configAttributes.isEmpty()) && rejectIfNoRule) { // return something that cannot be valid; this will cause the voters to abstain or deny return DENY; } return configAttributes; }
From source file:org.kuali.maven.plugins.graph.sanitize.RelatedArtifactSanitizer.java
protected void sanitize(MavenContext context) { DependencyNode dn = context.getDependencyNode(); // The validation logic assures that artifact and related are not null for conflicts and duplicates Artifact artifact = dn.getArtifact(); Artifact related = dn.getRelatedArtifact(); State state = State.getState(dn.getState()); // Test them to see if they are exactly the same or just similar boolean equal = helper.equals(artifact, related); boolean similar = helper.similar(artifact, related); // The validation logic assures that at least one is true, but no harm in double checking Assert.isTrue(equal || similar, "Invalid state."); if (equal) {//from w w w . jav a 2 s . com // The main artifact and related artifact are exactly the same if (state == CONFLICT) { // Maven told us this was a CONFLICT, yet the artifacts are exactly the same. // WTF is up with that? The only thing it is possible to do at this point is // switch this artifact out WITH THE EXACT SAME ARTIFACT!!! How is that a conflict? logger.info(CONFLICT + "->" + DUPLICATE + " " + artifact); } // Set state to duplicate and make sure replacement is nulled out context.setState(DUPLICATE); context.setReplacement(null); } else if (similar) { // The main artifact and related artifact are NOT exactly the same, but they differ only by version if (state == DUPLICATE) { // Maven told us this was a DUPLICATE, yet the related artifact is a different version // We are going to assume the duplicate flag is a mistake and re-flag this as a conflict logger.info(DUPLICATE + "->" + CONFLICT + " " + artifact); } // Set state to conflict, and store the artifact Maven replaced it with context.setState(CONFLICT); context.setReplacement(related); } else { // Something has gone horribly wrong Assert.isTrue(false, "Invalid state"); } }