javax.validation.constraints.Null Java Examples

The following examples show how to use javax.validation.constraints.Null. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanDefinitionDtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Take a stab at fixing validation problems ?
 * 
 * @param object
 */
private void validate(Object object) {
	Set<ConstraintViolation<Object>> viols = validator.validate(object);
	for (ConstraintViolation<Object> constraintViolation : viols) {
		if (Null.class.isAssignableFrom(constraintViolation.getConstraintDescriptor().getAnnotation().getClass())) {
			Object o = constraintViolation.getLeafBean();
			Iterator<Node> iterator = constraintViolation.getPropertyPath().iterator();
			String propertyName = null;
			while (iterator.hasNext()) {
				propertyName = iterator.next().getName();
			}
			if (propertyName != null) {
				try {
					PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(o.getClass(), propertyName);
					descriptor.getWriteMethod().invoke(o, new Object[] { null });
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example #2
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Determine whether a given field or method is annotated to be not nullable.
 *
 * @param member the field or method to check
 * @return whether member is annotated as nullable or not (returns null if not specified: assumption it is nullable then)
 */
protected Boolean isNullable(MemberScope<?, ?> member) {
    Boolean result;
    if (this.getAnnotationFromFieldOrGetter(member, NotNull.class, NotNull::groups) != null
            || this.getAnnotationFromFieldOrGetter(member, NotBlank.class, NotBlank::groups) != null
            || this.getAnnotationFromFieldOrGetter(member, NotEmpty.class, NotEmpty::groups) != null) {
        // field is specifically NOT nullable
        result = Boolean.FALSE;
    } else if (this.getAnnotationFromFieldOrGetter(member, Null.class, Null::groups) != null) {
        // field is specifically null (and thereby nullable)
        result = Boolean.TRUE;
    } else {
        result = null;
    }
    return result;
}
 
Example #3
Source File: CFMultiDiscoverer.java    From promregator with Apache License 2.0 6 votes vote down vote up
/**
 * performs the discovery based on the configured set of targets in the configuration, (pre-)filtering the returned set applying the filter criteria supplied.
 * The instances discovered are automatically registered at this Discoverer
 * @param applicationIdFilter the (pre-)filter based on ApplicationIds, allowing to early filter the list of instances to discover
 * @param instanceFilter the (pre-)filter based on the Instance instance, allowing to filter the lost if instances to discover
 * @return the list of Instances which were discovered (and registered).
 */
@Null
public List<Instance> discover(@Null Predicate<? super String> applicationIdFilter, @Null Predicate<? super Instance> instanceFilter) {
	log.debug(String.format("We have %d targets configured", this.promregatorConfiguration.getTargets().size()));
	
	List<ResolvedTarget> resolvedTargets = this.targetResolver.resolveTargets(this.promregatorConfiguration.getTargets());
	if (resolvedTargets == null) {
		log.warn("Target resolved was unable to resolve configured targets");
		return Collections.emptyList();
	}
	log.debug(String.format("Raw list contains %d resolved targets", resolvedTargets.size()));
	
	List<Instance> instanceList = this.appInstanceScanner.determineInstancesFromTargets(resolvedTargets, applicationIdFilter, instanceFilter);
	if (instanceList == null) {
		log.warn("Instance Scanner unable to determine instances from provided targets");
		return Collections.emptyList();
	}
	log.debug(String.format("Raw list contains %d instances", instanceList.size()));

	// ensure that the instances are registered / touched properly
	for (Instance instance : instanceList) {
		this.registerInstance(instance);
	}
	
	return instanceList;
}
 
Example #4
Source File: BuildPushResult.java    From pnc with Apache License 2.0 5 votes vote down vote up
@lombok.Builder(builderClassName = "Builder", toBuilder = true)
public BuildPushResult(
        @NotNull(groups = WhenUpdating.class) @Null(groups = WhenCreatingNew.class) String id,
        @NotNull String buildId,
        @NotNull BuildPushStatus status,
        Integer brewBuildId,
        String brewBuildUrl,
        String logContext,
        String message,
        ProductMilestoneCloseResultRef productMilestoneCloseResult) {
    super(id, buildId, status, brewBuildId, brewBuildUrl, logContext, message);
    this.productMilestoneCloseResult = productMilestoneCloseResult;
}
 
Example #5
Source File: NegateExpression.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * @param column   Name of column value to be negated.
 */
public NegateExpression(@Null String column, String alias)
{
  super(column, alias);
  if (this.alias == null) {
    this.alias = "NEGATE(" + column + ")";
  }
}
 
Example #6
Source File: AbstractMetricsEndpoint.java    From promregator with Apache License 2.0 5 votes vote down vote up
public String handleRequest(@Null Predicate<? super String> applicationIdFilter, @Null Predicate<? super Instance> instanceFilter) throws ScrapingException {
	log.debug("Received request to a metrics endpoint");
	Instant start = Instant.now();
	
	this.up.clear();
	
	List<Instance> instanceList = this.cfDiscoverer.discover(applicationIdFilter, instanceFilter);
	
	if (instanceList == null || instanceList.isEmpty()) {
		throw new ScrapingException("Unable to determine any instance to scrape");
	}
	
	List<MetricsFetcher> callablesPrep = this.createMetricsFetchers(instanceList);
	
	List<Future<HashMap<String, MetricFamilySamples>>> futures = this.startMetricsFetchers(callablesPrep);
	log.debug(String.format("Fetching metrics from %d distinct endpoints", futures.size()));
	
	MergableMetricFamilySamples mmfs = waitForMetricsFetchers(futures);
	
	Instant stop = Instant.now();
	Duration duration = Duration.between(start, stop);
	this.handleScrapeDuration(this.requestRegistry, duration);
	
	if (this.isIncludeGlobalMetrics()) {
		// also add our own (global) metrics
		mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry));
	}
	
	// add also our own request-specific metrics
	mmfs.merge(this.gmfspr.determineEnumerationOfMetricFamilySamples(this.requestRegistry));
	
	return mmfs.toType004String();
}
 
Example #7
Source File: NullPostProcessor.java    From RestDoc with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyModel postProcessInternal(PropertyModel propertyModel) {
    Null nullAnno = propertyModel.getPropertyItem().getAnnotation(Null.class);
    if (nullAnno == null)  return propertyModel;

    propertyModel.setRequired(false);

    return propertyModel;
}
 
Example #8
Source File: PromregatorApplicationSimulatorTest.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleInstance() {
	@Null
	List<Instance> actual = this.cfDiscoverer.discover(appId -> appId.equals(CFAccessorSimulator.APP_UUID_PREFIX+"100"), 
			instance -> (CFAccessorSimulator.APP_UUID_PREFIX+"100:1").equals(instance.getInstanceId()));
	assertThat(actual).hasSize(1);
}
 
Example #9
Source File: NoTargetsConfiguredSpringApplication.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Bean
public AppInstanceScanner appInstanceScanner() {
	return new AppInstanceScanner() {

		@Override
		public List<Instance> determineInstancesFromTargets(List<ResolvedTarget> targets, @Null Predicate<? super String> applicationIdFilter, @Null Predicate<? super Instance> instanceFilter) {
			LinkedList<Instance> result = new LinkedList<>();

			return result;
		}

	};
}
 
Example #10
Source File: MessageService.java    From holdmail with Apache License 2.0 5 votes vote down vote up
public MessageList findMessages(@Null @Email String recipientEmail, Pageable pageRequest) {

        List<MessageEntity> entities;

        if (StringUtils.isBlank(recipientEmail)) {
            entities = messageRepository.findAllByOrderByReceivedDateDesc(pageRequest);
        }
        else {
            entities = messageRepository.findAllForRecipientOrderByReceivedDateDesc(recipientEmail, pageRequest);
        }

        return messageListMapper.toMessageList(entities);
    }
 
Example #11
Source File: PromregatorApplicationSimulatorTest.java    From promregator with Apache License 2.0 4 votes vote down vote up
@Test
public void testDiscoveryWorks() {
	@Null
	List<Instance> actual = this.cfDiscoverer.discover(null, null);
	assertThat(200).isEqualTo(actual.size());
}
 
Example #12
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void appendNullValidator(SourceWriter w, JField field) {
	Null nullAnnotation = field.getAnnotation(Null.class);
	if (nullAnnotation != null) {
		w.println(", new NullValidator(\"%s\")", nullAnnotation.message());
	}
}
 
Example #13
Source File: DefaultLoadBalancerCache.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
@Null
protected Object lookup(Object key) {
	return cache.get(key);
}
 
Example #14
Source File: NullPropertyValidator.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Null constraintAnnotation) {
}
 
Example #15
Source File: DefaultModelPlugin.java    From BlogManagePlatform with Apache License 2.0 4 votes vote down vote up
private String resolveNull(Field field) {
	return field.isAnnotationPresent(Null.class) ? "必须为空" : null;
}
 
Example #16
Source File: JavaxValidationModuleTest.java    From jsonschema-generator with Apache License 2.0 4 votes vote down vote up
@Null(groups = Test.class)
public Object getNullGetter() {
    return this.nullGetter;
}
 
Example #17
Source File: RSocketBrokerResponderHandler.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public RSocketBrokerResponderHandler(@NotNull ConnectionSetupPayload setupPayload,
                                     @NotNull RSocketCompositeMetadata compositeMetadata,
                                     @NotNull AppMetadata appMetadata,
                                     @NotNull RSocketAppPrincipal principal,
                                     RSocket peerRsocket,
                                     ServiceRoutingSelector routingSelector,
                                     TopicProcessor<CloudEventImpl> eventProcessor,
                                     RSocketBrokerHandlerRegistry handlerRegistry,
                                     ServiceMeshInspector serviceMeshInspector,
                                     @Null RSocket upstreamRSocket) {
    try {
        this.upstreamRSocket = upstreamRSocket;
        RSocketMimeType dataType = RSocketMimeType.valueOfType(setupPayload.dataMimeType());
        if (dataType != null) {
            this.defaultMessageMimeType = new MessageMimeTypeMetadata(dataType);
            this.defaultEncodingBytebuf = constructDefaultDataEncoding();
        }
        this.appMetadata = appMetadata;
        this.id = appMetadata.getId();
        this.uuid = appMetadata.getUuid();
        //app tags hashcode set
        this.appTagsHashCodeSet.add(("id=" + this.id).hashCode());
        this.appTagsHashCodeSet.add(("uuid=" + this.uuid).hashCode());
        if (appMetadata.getIp() != null && !appMetadata.getIp().isEmpty()) {
            this.appTagsHashCodeSet.add(("ip=" + this.appMetadata.getIp()).hashCode());
        }
        if (appMetadata.getMetadata() != null) {
            for (Map.Entry<String, String> entry : appMetadata.getMetadata().entrySet()) {
                this.appTagsHashCodeSet.add((entry.getKey() + "=" + entry.getValue()).hashCode());
            }
        }
        this.principal = principal;
        this.peerRsocket = peerRsocket;
        this.routingSelector = routingSelector;
        this.eventProcessor = eventProcessor;
        this.handlerRegistry = handlerRegistry;
        this.serviceMeshInspector = serviceMeshInspector;
        //publish services metadata
        if (compositeMetadata.contains(RSocketMimeType.ServiceRegistry)) {
            ServiceRegistryMetadata serviceRegistryMetadata = ServiceRegistryMetadata.from(compositeMetadata.getMetadata(RSocketMimeType.ServiceRegistry));
            if (serviceRegistryMetadata.getPublished() != null && !serviceRegistryMetadata.getPublished().isEmpty()) {
                setPeerServices(serviceRegistryMetadata.getPublished());
                registerPublishedServices();
            }
        }
        //new comboOnClose
        this.comboOnClose = Mono.first(super.onClose(), peerRsocket.onClose());
        this.comboOnClose.doOnTerminate(this::unRegisterPublishedServices).subscribeOn(Schedulers.parallel()).subscribe();
    } catch (Exception e) {
        log.error(RsocketErrorCode.message("RST-500400"), e);
    }
}
 
Example #18
Source File: SysUserDetailsService.java    From DAFramework with MIT License 2 votes vote down vote up
/**
 * 根据用户名获取用户基本信息
 *
 * @param userName
 * @return
 */
@Null
public EUser fetchByName(String userName) {
	return userDao.fetchByName(userName);
}
 
Example #19
Source File: AppInstanceScanner.java    From promregator with Apache License 2.0 2 votes vote down vote up
/**
 * determines a list of instances based on a provided list of targets.
 * Note that there may be more or less instances than targets as input. This may
 * have multiple reasons:
 * - one target resolves to multiple instances (e.g. if an application has multiple
 * instances running due to load balancing or fail-over safety)
 * - one target does not resolve to any instance, if the application has been
 * misconfigured or if the application is currently not running.
 * @param targets the list of targets, for which the properties of instances shall be determined
 * @param applicationIdFilter an optional filter function allowing to prefilter results early, indicating whether an application based on its applicationId is in scope or not
 * @param instanceFilter an optional filter function allowing to prefilter results early, indicating whether an instance is in scope or not
 * @return the list of instances containing the access URL and the instance identifier
 */
@Null
List<Instance> determineInstancesFromTargets(List<ResolvedTarget> targets, @Null Predicate<? super String> applicationIdFilter, @Null Predicate<? super Instance> instanceFilter);
 
Example #20
Source File: CFDiscoverer.java    From promregator with Apache License 2.0 2 votes vote down vote up
/**
 * performs the discovery based on the configured set of targets in the configuration, (pre-)filtering the returned set applying the filter criteria supplied.
 * The instances discovered are automatically registered at this Discoverer
 * @param applicationIdFilter the (pre-)filter based on ApplicationIds, allowing to early filter the list of instances to discover
 * @param instanceFilter the (pre-)filter based on the Instance instance, allowing to filter the lost if instances to discover
 * @return the list of Instances which were discovered (and registered).
 */
List<Instance> discover(@Null Predicate<? super String> applicationIdFilter, @Null Predicate<? super Instance> instanceFilter);
 
Example #21
Source File: DefaultRequiredPlugin.java    From BlogManagePlatform with Apache License 2.0 2 votes vote down vote up
/**
 * 判断是否拥有可以为空的注解
 * @author Frodez
 * @date 2019-06-11
 */
private boolean hasNullableAnnotation(ResolvedMethodParameter methodParameter) {
	return methodParameter.hasParameterAnnotation(Null.class) || methodParameter.hasParameterAnnotation(Nullable.class) || methodParameter
		.hasParameterAnnotation(reactor.util.annotation.Nullable.class);
}