List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.opennms.ng.services.eventconfig.EventExpander.java
/** * <p>afterPropertiesSet</p> */// w w w . j ava 2s .c o m @Override public void afterPropertiesSet() { Assert.state(m_eventConfDao != null, "property eventConfDao must be set"); }
From source file:org.biopax.validator.ws.ValidatorController.java
/** * JSP pages and RESTful web services controller, the main one that checks BioPAX data. * All parameter names are important, i.e., these are part of public API (for clients) * //from w w w . j a v a2s . c o m * Framework's built-in parameters: * @param request the web request object (may contain multi-part data, i.e., multiple files uploaded) * @param response * @param mvcModel Spring MVC Model * @param writer HTTP response writer * * BioPAX Validator/Normalizer query parameters: * @param url * @param retDesired * @param autofix * @param filter * @param maxErrors * @param profile * @param normalizer binds to three boolean options: normalizer.fixDisplayName, normalizer.inferPropertyOrganism, normalizer.inferPropertyDataSource * @return * @throws IOException */ @RequestMapping(value = "/check", method = RequestMethod.POST) public String check(HttpServletRequest request, HttpServletResponse response, Model mvcModel, Writer writer, @RequestParam(required = false) String url, @RequestParam(required = false) String retDesired, @RequestParam(required = false) Boolean autofix, @RequestParam(required = false) Behavior filter, @RequestParam(required = false) Integer maxErrors, @RequestParam(required = false) String profile, //normalizer!=null when called from the JSP; //but it's usually null when from the validator-client or a web script @ModelAttribute("normalizer") Normalizer normalizer) throws IOException { Resource resource = null; // a resource to validate // create the response container ValidatorResponse validatorResponse = new ValidatorResponse(); if (url != null && url.length() > 0) { if (url != null) log.info("url : " + url); try { resource = new UrlResource(url); } catch (MalformedURLException e) { mvcModel.addAttribute("error", e.toString()); return "check"; } try { Validation v = execute(resource, resource.getDescription(), maxErrors, autofix, filter, profile, normalizer); validatorResponse.addValidationResult(v); } catch (Exception e) { return errorResponse(mvcModel, "check", "Exception: " + e); } } else if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; Map files = multiRequest.getFileMap(); Assert.state(!files.isEmpty(), "No files to validate"); for (Object o : files.values()) { MultipartFile file = (MultipartFile) o; String filename = file.getOriginalFilename(); // a workaround (for some reason there is always a no-name-file; // this might be a javascript isue) if (file.getBytes().length == 0 || filename == null || "".equals(filename)) continue; log.info("check : " + filename); resource = new ByteArrayResource(file.getBytes()); try { Validation v = execute(resource, filename, maxErrors, autofix, filter, profile, normalizer); validatorResponse.addValidationResult(v); } catch (Exception e) { return errorResponse(mvcModel, "check", "Exception: " + e); } } } else { return errorResponse(mvcModel, "check", "No BioPAX input source provided!"); } if ("xml".equalsIgnoreCase(retDesired)) { response.setContentType("application/xml"); ValidatorUtils.write(validatorResponse, writer, null); } else if ("html".equalsIgnoreCase(retDesired)) { /* could also use ValidatorUtils.write with a xml-to-html xslt source but using JSP here makes it easier to keep the same style, header, footer*/ mvcModel.addAttribute("response", validatorResponse); return "groupByCodeResponse"; } else { // owl only response.setContentType("text/plain"); // write all the OWL results one after another TODO any better solution? for (Validation result : validatorResponse.getValidationResult()) { if (result.getModelData() != null) writer.write(result.getModelData() + NEWLINE); else // empty result writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<rdf:RDF></rdf:RDF>" + NEWLINE); } } return null; // (Writer is used instead) }
From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java
private String getServiceId(final Map<String, Object> attributes) { String name = (String) attributes.get("name"); if (!StringUtils.hasText(name)) { name = (String) attributes.get("value"); }/*w ww. ja va 2s . c om*/ if (!StringUtils.hasText(name)) { return ""; } String host = null; try { host = new URI("http://" + name).getHost(); } catch (URISyntaxException e) { } Assert.state(host != null, "Service id not legal hostname (" + name + ")"); return name; }
From source file:org.cfr.capsicum.datasource.TransactionAwareDataSourceProxy.java
/** * Delegates to DataSourceUtils for automatically participating in Spring-managed * transactions. Throws the original SQLException, if any. * <p>The returned Connection handle implements the ConnectionProxy interface, * allowing to retrieve the underlying target Connection. * @return a transactional Connection if any, a new one else * @see DataSourceUtils#doGetConnection//from w w w .ja v a 2 s . c o m * @see ConnectionProxy#getTargetConnection */ @Override public Connection getConnection() throws SQLException { DataSource ds = getTargetDataSource(); Assert.state(ds != null, "'targetDataSource' is required"); return getTransactionAwareConnectionProxy(ds); }
From source file:cn.clickvalue.cv2.model.rowmapper.BeanPropertyRowMapper.java
/** * Extract the values for all columns in the current row. * <p>Utilizes public setters and result set metadata. * @see java.sql.ResultSetMetaData/*w w w . j a v a 2 s . c o m*/ */ public Object mapRow(ResultSet rs, int rowNumber) throws SQLException { Assert.state(this.mappedClass != null, "Mapped class was not specified"); Object mappedObject = BeanUtils.instantiateClass(this.mappedClass); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject); initBeanWrapper(bw); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); for (int index = 1; index <= columnCount; index++) { String column = lookupColumnName(rsmd, index).toLowerCase(); PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column); if (pd != null) { try { Object value = getColumnValue(rs, index, pd); if (logger.isDebugEnabled() && rowNumber == 0) { logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type " + pd.getPropertyType()); } bw.setPropertyValue(pd.getName(), value); } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( "Unable to map column " + column + " to property " + pd.getName(), ex); } } } return mappedObject; }
From source file:your.microservice.core.util.YourServletUriComponentsBuilder.java
/** * Obtain the request through {@link RequestContextHolder}. * @return the active servlet request//from w w w .j a v a 2 s .c o m */ protected static HttpServletRequest getCurrentRequest() { RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder"); Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes); HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); Assert.state(servletRequest != null, "Could not find current HttpServletRequest"); return servletRequest; }
From source file:net.sf.gazpachoquest.services.core.impl.QuestionServiceImpl.java
@Override @Transactional(readOnly = false)/*from ww w. j a v a 2s. c o m*/ public Question save(final Question question) { Assert.state(!question.isNew(), "Question must be already persisted. Try by adding to Section or as added as subquestion first."); Question existing = repository.save(question); for (Question subquestion : question.getSubquestions()) { if (!subquestion.isNew()) { // Skip created subquestions continue; } existing.addSubquestion(subquestion); } for (QuestionOption questionOption : question.getQuestionOptions()) { if (!questionOption.isNew()) { // Skip created questionOptions continue; } existing.addQuestionOption(questionOption); } return existing; }
From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsMethodInvokingJobDetailFactoryBean.java
@Override public Class<?> getTargetClass() { Class<?> targetClass = super.getTargetClass(); if (targetClass == null && targetBeanName != null) { Assert.state(beanFactory != null, "BeanFactory must be set when using 'targetBeanName'"); targetClass = beanFactory.getType(targetBeanName); }//from w w w . j ava 2 s. c om return targetClass; }
From source file:org.opennms.ng.dao.support.DefaultRrdDao.java
/** * <p>afterPropertiesSet</p> * * @throws Exception if any./*from ww w. j ava 2 s . c o m*/ */ @Override public void afterPropertiesSet() throws Exception { Assert.state(m_rrdStrategy != null, "property rrdStrategy must be set and be non-null"); Assert.state(m_rrdBaseDirectory != null, "property rrdBaseDirectory must be set and be non-null"); Assert.state(m_rrdBinaryPath != null, "property rrdBinaryPath must be set and be non-null"); }