List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:de.itsvs.cwtrpc.security.RpcRedirectStrategy.java
public void setStatusCode(int statusCode) { Assert.isTrue((statusCode > 0), "'statusCode' must not be negative"); this.statusCode = statusCode; }
From source file:com.crossover.trial.weather.domain.AirportRepositoryImpl.java
@Override @Transactional(readOnly = true)//from w w w . j a v a 2 s . c o m public Iterable<Airport> findInRadius(IATA fromIata, double distanceInKm) { Assert.isTrue(fromIata != null, "fromIata is required"); Assert.isTrue(distanceInKm > 0, "distanceInKm must be positive"); Airport fromAirport = airportRepository.findOne(fromIata); if (fromAirport == null) return Collections.emptyList(); return manager.createQuery("select a from Airport a where iata != :fromIata", Airport.class) .setParameter("fromIata", fromIata).getResultList().parallelStream() .filter(toAirport -> fromAirport.calculateDistance(toAirport) <= distanceInKm) .collect(Collectors.toList()); }
From source file:JavaMvc.web.EditUserCommand.java
public void updateUser(User user) { Assert.isTrue(userId.equals(user.getId()), "User ID of command must match the user being updated."); user.setUsername(getUsername());/*from w ww. j a v a 2 s . c om*/ user.setEmail(getEmail()); if (StringUtils.hasText(getPassword())) { user.setPassword(new Sha256Hash(getPassword()).toHex()); } }
From source file:com.jaxio.celerio.configuration.database.ForeignKey.java
public void addImportedKeys(List<ImportedKey> ikeys) { Assert.isTrue(ikeys.size() > 0, "there must be at least one imported key"); for (ImportedKey ikey : ikeys) { addImportedKey(ikey);//from w w w . j a v a2 s . co m } }
From source file:com.oreilly.springdata.jdbc.domain.Product.java
/** * Creates a new {@link Product} from the given name and description. * /*from www.j a va 2 s .c o m*/ * @param name must not be {@literal null} or empty. * @param price must not be {@literal null} or less than or equal to zero. * @param description */ public Product(String name, BigDecimal price, String description) { Assert.hasText(name, "Name must not be null or empty!"); Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!"); this.name = name; this.price = price; this.description = description; }
From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java
public SimpleDBTemplateImpl(String accessKey, String secretKey) { Assert.isTrue(StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey), "Please provide accessKey and secretKey"); sdb = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey, secretKey)); }
From source file:com.cxplonka.feature.service.controller.CustomerController.java
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) public Customer update(@PathVariable long id, @Validated @RequestBody Customer customer) { Assert.notNull(customer, "This field is mandatory."); Assert.isTrue(id > 0, "No valid primary key."); Customer model = repository.findOne(id); if (model != null) { model.setFirstName(customer.getFirstName()); model.setLastName(customer.getLastName()); return repository.saveAndFlush(model); }// w w w. j a va2 s. com return null; }
From source file:org.obiba.onyx.spring.ParticipantRegistryFactoryBean.java
public void validateArgs() throws IllegalArgumentException { Assert.notNull(fixedBean, "fixedBean cannot be null"); Assert.notNull(restfulBean, "restfulBean cannot be null"); Assert.hasText(participantRegistryType, "participantRegistryType must not be null or empty"); Assert.isTrue( participantRegistryType.equalsIgnoreCase(FIXED_TYPE) || participantRegistryType.equalsIgnoreCase(RESTFUL_TYPE), "participantRegistryType must contain the value [" + FIXED_TYPE + "] or [" + RESTFUL_TYPE + "]."); }
From source file:com.athena.chameleon.web.common.controller.FileController.java
@RequestMapping("/download.do") public void download(HttpServletRequest request, HttpServletResponse response, @RequestParam("path") String path) throws Exception { Assert.notNull(path, "name must not be null."); File file = new File(path); Assert.isTrue(file.exists(), path + " does not exist."); String name = path.replaceAll("\\\\", "/"); name = name.substring(name.lastIndexOf("/") + 1, name.length()); long fileSize = file.length(); if (fileSize > 0L) { response.setHeader("Content-Length", Long.toString(fileSize)); }//from w ww .j a va2s . c o m String fileExt = name.substring(name.lastIndexOf(".") + 1); response.reset(); if (fileExt.equals("pdf")) { response.setContentType("application/pdf"); } else if (fileExt.equals("zip")) { response.setContentType("application/zip"); } else if (fileExt.equals("ear")) { response.setContentType("application/zip"); } else if (fileExt.equals("war")) { response.setContentType("application/zip"); } else if (fileExt.equals("jar")) { response.setContentType("application/zip"); } else { response.setContentType("application/octet-stream"); } if (request.getHeader("User-Agent").toLowerCase().contains("firefox") || request.getHeader("User-Agent").toLowerCase().contains("safari")) { response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(name.getBytes("UTF-8"), "ISO-8859-1") + "\""); response.setHeader("Content-Transfer-Encoding", "binary"); } else { response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8")); } try { BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file)); BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream()); int read = 0; while ((read = fin.read()) != -1) { outs.write(read); } IOUtils.closeQuietly(fin); IOUtils.closeQuietly(outs); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java
@Override public AutoSelectSet getAutoSelect() { AutoSelectSet autoSelectSet = new AutoSelectSet(); SQLiteDatabase database = this.database.openDatabase(false); Cursor query = this.database.queryWithLoginSetKey(database, DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME); Assert.isTrue(query.getCount() <= 1, "More than one auto-select entry for " + this.database.getLoginSetKeyForTable() + "."); int indexEnabled = query.getColumnIndex(DatabaseAutoSelectConstants.ENABLED); int indexType = query.getColumnIndex(DatabaseAutoSelectConstants.TYPE); int indexValue = query.getColumnIndex(DatabaseAutoSelectConstants.VALUE); while (query.moveToNext()) { boolean enabled = query.getInt(indexEnabled) > 0; String type = query.getString(indexType); int value = query.getInt(indexValue); autoSelectSet.setEnabled(enabled); autoSelectSet.setAutoSelectType(type); autoSelectSet.setAutoSelectValue(value); }//from ww w .ja va 2 s .c o m query.close(); this.database.closeDatabase(database); return autoSelectSet; }