private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) { Assert.isNull( stepExecution.getId(), "to-be-saved (not updated) StepExecution can't already have an id assigned"); Assert.isNull( stepExecution.getVersion(), "to-be-saved (not updated) StepExecution can't already have a version assigned"); validateStepExecution(stepExecution); stepExecution.setId(stepExecutionIncrementer.nextLongValue()); stepExecution.incrementVersion(); // Should be 0 List<Object[]> parameters = new ArrayList<Object[]>(); String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription()); Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(), stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() }; Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP }; parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length)); parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length)); return parameters; }
/** * Configure a base URL to prepend URI templates with. The base URL must have a scheme and host * but may optionally contain a port and a path. The base URL must be fully expanded and encoded * which can be done via {@link UriComponentsBuilder}. * * @param baseUrl the base URL. */ public void setBaseUrl(String baseUrl) { if (baseUrl != null) { UriComponents uriComponents = UriComponentsBuilder.fromUriString(baseUrl).build(); Assert.hasText(uriComponents.getScheme(), "'baseUrl' must have a scheme"); Assert.hasText(uriComponents.getHost(), "'baseUrl' must have a host"); Assert.isNull(uriComponents.getQuery(), "'baseUrl' cannot have a query"); Assert.isNull(uriComponents.getFragment(), "'baseUrl' cannot have a fragment"); } this.baseUrl = baseUrl; }
public void create(Project project) { Assert.isNull( projectService.findProject(project.getName()), "project [" + project.getName() + "] has exist"); MongoTemplate template = project.fetchMongoTemplate(); Assert.notNull(template, "mongo uri is not access"); Assert.notNull(template.getDb(), "mongo uri is not access"); Assert.isTrue( project.fetchMongoTemplate().collectionExists(project.getLogCollection()), " [" + project.getLogCollection() + "] 日志表不存在"); try { List<Task> taskList = Lists.newArrayList(); logger.debug("init task count:{}", project.getTasks().size()); for (Task _task : project.getTasks()) { Task task = getTemplateTask(_task); Task tempTask = renderTemplateTask(task, project); if (tempTask != null) taskList.add(tempTask); } project.setTasks(taskList); } catch (Exception e) { logger.error("", e); throw new IllegalArgumentException("自动添加监控脚本错误:" + e.getMessage()); } projectService.saveProject(project); }
/** * Bind the given resource for the given key to the current thread. * * @param key the key to bind the value to (usually the resource factory) * @param value the value to bind (usually the active resource object) * @throws IllegalStateException if there is already a value bound to the thread */ public static void bind(Object key, Object value) { Assert.notNull(value, "Value must not be null"); Map<Object, Object> map = resources.get(); // set ThreadLocal Map if none found if (map == null) { map = new HashMap<Object, Object>(); resources.set(map); } Object oldValue = map.put(key, value); Assert.isNull( oldValue, "Already value [" + oldValue + "] for key [" + key + "] bound to thread [" + Thread.currentThread().getName() + "]"); if (logger.isTraceEnabled()) { logger.trace( "Bound value [" + value + "] for key [" + key + "] to thread [" + Thread.currentThread().getName() + "]"); } }
public FileWritingMessageHandlerSpec fileNameExpression(String fileNameExpression) { Assert.isNull( this.fileNameGenerator, "'fileNameGenerator' and 'fileNameGeneratorExpression' are mutually exclusive."); this.defaultFileNameGenerator = new DefaultFileNameGenerator(); this.defaultFileNameGenerator.setExpression(fileNameExpression); return fileNameGenerator(this.defaultFileNameGenerator); }
@Transactional @Rollback(true) @Test public void testDeleteEventHandler() { EventHandler eventHandlerTest = eventService.getEventHandlerById(NUMBER_ONE); Assert.isTrue(eventHandlerTest.getEventHandlerName().equals("Users data import")); eventService.deleteEventHandlerById(NUMBER_ONE); EventHandler eventHandlerTestNew = eventService.getEventHandlerById(NUMBER_ONE); Assert.isNull(eventHandlerTestNew); }
@Test @Transactional public void testHydratedCanvasForNonExistenceCanvas() throws Exception { Canvas canvas = null; try { canvas = this.uIService.getHydratedCanvas(30000L); } catch (Exception e) { Assert.isNull(canvas, "Canvas Shouldn't Exist for CanvasId 30000"); } }
@Transactional @Rollback(true) @Test public void testDeleteEvent() { Event eventTest = eventService.getEventById(NUMBER_ONE); Assert.isTrue( eventTest.getEventDescription().equals("Import user details to the lucas system")); eventService.deleteEventById(eventTest.getEventId()); Event eventTestNew = eventService.getEventById(NUMBER_ONE); Assert.isNull(eventTestNew); }
@Test @Transactional public void testOpenCanvasesForNonExistenceUser() throws Exception { List<OpenUserCanvas> openUserCanvases = null; try { openUserCanvases = this.uIService.getAllOpenCanvasForUser(99999L); } catch (Exception e) { Assert.isNull( openUserCanvases, "User have OpenCanvas , Open Canvas is not Null for User Annonimus "); } }
// ref: 18.3 public void assignToClerkManual(Clerk clerk, Order order) { Assert.notNull(clerk); Assert.isTrue(clerk.getId() != 0); Assert.notNull(order); Assert.isTrue(order.getId() != 0); Assert.isNull(order.getClerk()); order.setClerk(clerk); this.save(order); }
@Transactional(propagation = Propagation.REQUIRED) public Ficha cancelarDeposito(final String fichaId) { Ficha bean = (Ficha) getHibernateTemplate().get(Ficha.class, fichaId); Assert.isNull( bean.getCorte(), "La ficha ya ha sido contabilizada en un ingreso al sistema de bancos"); if (bean.getPartidas().size() == 0) return bean; bean.getPartidas().clear(); bean.setComentario("CANCELADO"); bean.setCancelada(new Date()); bean.getImporte(); return save(bean); }
// req: 16.1 public void cancelOrder(Order order) { Assert.notNull(order); Assert.isTrue(order.getId() != 0); Assert.isTrue( order.getConsumer().equals(consumerService.findByPrincipal()), "Only the owner can cancel the order"); Assert.isTrue(order.getCancelMoment() == null, "order.cancel.error.isCancelled"); Clerk clerk; clerk = clerkService.findByOrder(order); Assert.isNull(clerk, "Can't remove a order when a clerk has assigned"); order.setCancelMoment(new Date()); this.save(order); }
/** * Handle document type definition with validation of publicId and systemId. * * @param received * @param source * @param validationContext * @param namespaceContext */ private void doDocumentTypeDefinition( Node received, Node source, XmlMessageValidationContext validationContext, NamespaceContext namespaceContext, TestContext context) { Assert.isTrue( source instanceof DocumentType, "Missing document type definition in expected xml fragment"); DocumentType receivedDTD = (DocumentType) received; DocumentType sourceDTD = (DocumentType) source; if (log.isDebugEnabled()) { log.debug( "Validating document type definition: " + receivedDTD.getPublicId() + " (" + receivedDTD.getSystemId() + ")"); } if (!StringUtils.hasText(sourceDTD.getPublicId())) { Assert.isNull( receivedDTD.getPublicId(), ValidationUtils.buildValueMismatchErrorMessage( "Document type public id not equal", sourceDTD.getPublicId(), receivedDTD.getPublicId())); } else if (sourceDTD.getPublicId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) { if (log.isDebugEnabled()) { log.debug( "Document type public id: '" + receivedDTD.getPublicId() + "' is ignored by placeholder '" + CitrusConstants.IGNORE_PLACEHOLDER + "'"); } } else { Assert.isTrue( StringUtils.hasText(receivedDTD.getPublicId()) && receivedDTD.getPublicId().equals(sourceDTD.getPublicId()), ValidationUtils.buildValueMismatchErrorMessage( "Document type public id not equal", sourceDTD.getPublicId(), receivedDTD.getPublicId())); } if (!StringUtils.hasText(sourceDTD.getSystemId())) { Assert.isNull( receivedDTD.getSystemId(), ValidationUtils.buildValueMismatchErrorMessage( "Document type system id not equal", sourceDTD.getSystemId(), receivedDTD.getSystemId())); } else if (sourceDTD.getSystemId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) { if (log.isDebugEnabled()) { log.debug( "Document type system id: '" + receivedDTD.getSystemId() + "' is ignored by placeholder '" + CitrusConstants.IGNORE_PLACEHOLDER + "'"); } } else { Assert.isTrue( StringUtils.hasText(receivedDTD.getSystemId()) && receivedDTD.getSystemId().equals(sourceDTD.getSystemId()), ValidationUtils.buildValueMismatchErrorMessage( "Document type system id not equal", sourceDTD.getSystemId(), receivedDTD.getSystemId())); } validateXmlTree( received.getNextSibling(), source.getNextSibling(), validationContext, namespaceContext, context); }
private Map<String, Map<Class<?>, HandlerMethod>> findHandlerMethodsForTarget( final Object targetObject, final Class<? extends Annotation> annotationType, final String methodName, final boolean requiresReply) { Map<String, Map<Class<?>, HandlerMethod>> handlerMethods = new HashMap<String, Map<Class<?>, HandlerMethod>>(); final Map<Class<?>, HandlerMethod> candidateMethods = new HashMap<Class<?>, HandlerMethod>(); final Map<Class<?>, HandlerMethod> candidateMessageMethods = new HashMap<Class<?>, HandlerMethod>(); final Map<Class<?>, HandlerMethod> fallbackMethods = new HashMap<Class<?>, HandlerMethod>(); final Map<Class<?>, HandlerMethod> fallbackMessageMethods = new HashMap<Class<?>, HandlerMethod>(); final AtomicReference<Class<?>> ambiguousFallbackType = new AtomicReference<Class<?>>(); final AtomicReference<Class<?>> ambiguousFallbackMessageGenericType = new AtomicReference<Class<?>>(); final Class<?> targetClass = this.getTargetClass(targetObject); MethodFilter methodFilter = new UniqueMethodFilter(targetClass); ReflectionUtils.doWithMethods( targetClass, new MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { boolean matchesAnnotation = false; if (method.isBridge()) { return; } if (isMethodDefinedOnObjectClass(method)) { return; } if (method.getDeclaringClass().equals(Proxy.class)) { return; } if (!Modifier.isPublic(method.getModifiers())) { return; } if (requiresReply && void.class.equals(method.getReturnType())) { return; } if (methodName != null && !methodName.equals(method.getName())) { return; } if (annotationType != null && AnnotationUtils.findAnnotation(method, annotationType) != null) { matchesAnnotation = true; } HandlerMethod handlerMethod = null; try { handlerMethod = new HandlerMethod(method, canProcessMessageList); } catch (IneligibleMethodException e) { if (logger.isDebugEnabled()) { logger.debug( "Method [" + method + "] is not eligible for Message handling " + e.getMessage() + "."); } return; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Method [" + method + "] is not eligible for Message handling.", e); } return; } Class<?> targetParameterType = handlerMethod.getTargetParameterType(); if (matchesAnnotation || annotationType == null) { if (handlerMethod.isMessageMethod()) { if (candidateMessageMethods.containsKey(targetParameterType)) { throw new IllegalArgumentException( "Found more than one method match for type " + "[Message<" + targetParameterType + ">]"); } candidateMessageMethods.put(targetParameterType, handlerMethod); } else { if (candidateMethods.containsKey(targetParameterType)) { String exceptionMessage = "Found more than one method match for "; if (Void.class.equals(targetParameterType)) { exceptionMessage += "empty parameter for 'payload'"; } else { exceptionMessage += "type [" + targetParameterType + "]"; } throw new IllegalArgumentException(exceptionMessage); } candidateMethods.put(targetParameterType, handlerMethod); } } else { if (handlerMethod.isMessageMethod()) { if (fallbackMessageMethods.containsKey(targetParameterType)) { // we need to check for duplicate type matches, // but only if we end up falling back // and we'll only keep track of the first one ambiguousFallbackMessageGenericType.compareAndSet(null, targetParameterType); } fallbackMessageMethods.put(targetParameterType, handlerMethod); } else { if (fallbackMethods.containsKey(targetParameterType)) { // we need to check for duplicate type matches, // but only if we end up falling back // and we'll only keep track of the first one ambiguousFallbackType.compareAndSet(null, targetParameterType); } fallbackMethods.put(targetParameterType, handlerMethod); } } } }, methodFilter); if (!candidateMethods.isEmpty() || !candidateMessageMethods.isEmpty()) { handlerMethods.put(CANDIDATE_METHODS, candidateMethods); handlerMethods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); return handlerMethods; } if ((ambiguousFallbackType.get() != null || ambiguousFallbackMessageGenericType.get() != null) && ServiceActivator.class.equals(annotationType)) { /* * When there are ambiguous fallback methods, * a Service Activator can finally fallback to RequestReplyExchanger.exchange(m). * Ambiguous means > 1 method that takes the same payload type, or > 1 method * that takes a Message with the same generic type. */ List<Method> frameworkMethods = new ArrayList<Method>(); Class<?>[] allInterfaces = org.springframework.util.ClassUtils.getAllInterfacesForClass(targetClass); for (Class<?> iface : allInterfaces) { try { if ("org.springframework.integration.gateway.RequestReplyExchanger" .equals(iface.getName())) { frameworkMethods.add(targetClass.getMethod("exchange", Message.class)); if (logger.isDebugEnabled()) { logger.debug( targetObject.getClass() + ": Ambiguous fallback methods; using RequestReplyExchanger.exchange()"); } } } catch (Exception e) { // should never happen (but would fall through to errors below) } } if (frameworkMethods.size() == 1) { HandlerMethod handlerMethod = new HandlerMethod(frameworkMethods.get(0), canProcessMessageList); handlerMethods.put( CANDIDATE_METHODS, Collections.<Class<?>, HandlerMethod>singletonMap(Object.class, handlerMethod)); handlerMethods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); return handlerMethods; } } try { Assert.state( !fallbackMethods.isEmpty() || !fallbackMessageMethods.isEmpty(), "Target object of type [" + this.targetObject.getClass() + "] has no eligible methods for handling Messages."); } catch (Exception e) { // TODO backward compatibility throw new IllegalArgumentException(e.getMessage()); } Assert.isNull( ambiguousFallbackType.get(), "Found ambiguous parameter type [" + ambiguousFallbackType + "] for method match: " + fallbackMethods.values()); Assert.isNull( ambiguousFallbackMessageGenericType.get(), "Found ambiguous parameter type [" + ambiguousFallbackMessageGenericType + "] for method match: " + fallbackMethods.values()); handlerMethods.put(CANDIDATE_METHODS, fallbackMethods); handlerMethods.put(CANDIDATE_MESSAGE_METHODS, fallbackMessageMethods); return handlerMethods; }
@Override public Integer addApplication(Application application) { LOGGER.info("SERVICE: addApplication"); Assert.isNull(application.getApplicationId(), "Id should be null!"); return applicationDao.addApplication(application); }
private void assertFormRemoveSuccess() { DynaProcessForm fromExpected = DynaProcessForm.queryActiveDynaProcessFormByProcessId(PROCESS_ID); Assert.isNull(fromExpected); }
/** * Registers a TcpSender; for server sockets, used to provide connection information so a sender * can be used to reply to incoming messages. * * @param sender The sender */ public void registerSender(TcpSender sender) { Assert.isNull( this.sender, this.getClass().getName() + " may only be used by one outbound adapter"); this.sender = sender; }
/** * Registers a TcpListener to receive messages after the payload has been converted from the input * data. * * @param listener the TcpListener. */ public void registerListener(TcpListener listener) { Assert.isNull( this.listener, this.getClass().getName() + " may only be used by one inbound adapter"); this.listener = listener; }