下面列出了怎么用org.hibernate.validator.constraints.NotBlank的API类实例代码及写法,或者点击链接到github查看源代码。
@RequestMapping(value="/groupsum", method={RequestMethod.POST, RequestMethod.GET})
public @ResponseBody Map<Integer, BigDecimal> groupsum(@NotBlank @RequestParam String indName,
@RequestParam(required=false) String filterDims,
@RequestParam String groupbyDim,
@NotBlank @RequestParam String... timeSeries) throws Throwable {
LOGGER.info("Try to sum {} on {} with filter {}.", indName, ObjectUtils.getDisplayString(timeSeries), filterDims);
long timing = System.currentTimeMillis();
Map<String, List<Integer>> filter = (filterDims == null || "".equals(filterDims)) ? null
: objectMapper.readValue(filterDims, new TypeReference<Map<String, List<Integer>>>() {});
Map<Integer, BigDecimal> sum = manager.aggs(timeSeries).sum(indName, groupbyDim, filter);
LOGGER.info("Sucess to sum {} on {} result size is {} using {}ms.", indName, timeSeries, sum.size(), System.currentTimeMillis() - timing);
LOGGER.debug("Sucess to sum {} on {} result is {}.", indName, timeSeries, sum);
return sum;
}
@RequestMapping(value="/groupcount", method={RequestMethod.POST, RequestMethod.GET})
public @ResponseBody Map<Integer, Long> groupcount(@NotBlank @RequestParam String indName,
@RequestParam(required=false) String filterDims,
@RequestParam String groupbyDim,
@NotBlank @RequestParam String... timeSeries) throws Throwable {
LOGGER.info("Try to count {} on {} with filter {}.", indName, ObjectUtils.getDisplayString(timeSeries), filterDims);
long timing = System.currentTimeMillis();
Map<String, List<Integer>> filter = (filterDims == null || "".equals(filterDims)) ? null
: objectMapper.readValue(filterDims, new TypeReference<Map<String, List<Integer>>>() {});
Map<Integer, Long> count = manager.aggs(timeSeries).count(indName, groupbyDim, filter);
LOGGER.info("Sucess to count {} on {} result size is {} using {}ms.", indName, timeSeries, count.size(), System.currentTimeMillis() - timing);
LOGGER.debug("Sucess to count {} on {} result is {}.", indName, timeSeries, count);
return count;
}
@Override
public Response toResponse(JerseyViolationException exception) {
LOGGER.info(exception.getMessage());
ConstraintViolation<?> firstException = exception.getConstraintViolations().iterator().next();
String fieldName = getApiFieldName(firstException.getPropertyPath());
PaymentError paymentError;
if (firstException.getConstraintDescriptor() != null &&
firstException.getConstraintDescriptor().getAnnotation() != null &&
firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotBlank.class ||
firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotEmpty.class ||
firstException.getConstraintDescriptor().getAnnotation().annotationType() == NotNull.class) {
paymentError = PaymentError.aPaymentError(fieldName, CREATE_PAYMENT_MISSING_FIELD_ERROR);
} else {
paymentError = PaymentError.aPaymentError(fieldName, CREATE_PAYMENT_VALIDATION_ERROR, firstException.getMessage());
}
return Response.status(422)
.entity(paymentError)
.build();
}
@Override
@Path("/room")
@GET
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Get room according to indoor location", httpMethod="GET",response=RoomDTO.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Room belongs to location", response=RoomDTO.class),
@ApiResponse(code = 400, message = "Invalid input parameter"),
@ApiResponse(code = 404, message = "Room not found"),
@ApiResponse(code = 500, message = "Problem in the system")})
public Response getRoomByLocation(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(value="Longitude of location", required=true) @Min(-180) @Max(180) @NotNull @QueryParam("longitude") Double longitude,
@ApiParam(value="Latitude of location", required=true) @Min(-90) @Max(90) @NotNull @QueryParam("latitude") Double latitude,
@ApiParam(value = "Floor of location", required = true) @NotNull @QueryParam("floor") Integer floor) throws AssemblyException, RoomNotFoundException{
validations.checkIsNotNullAndNotBlank(appIdentifier);
validations.checkMin(-180.0, longitude);
validations.checkMax(180.0, longitude);
validations.checkMin(-90.0, latitude);
validations.checkMax(90.0, latitude);
validations.checkIsNotNull(floor);
Feature room=searchManager.getRoomByLocation(appIdentifier, longitude, latitude, floor);
RoomDTO roomDTO=roomAssembler.createDataTransferObject(room);
return Response.ok(roomDTO).build();
}
@RequestMapping(value="/distinctcount", method={RequestMethod.POST, RequestMethod.GET})
public @ResponseBody Map<Integer, Integer> distinctCount(@NotBlank @RequestParam String indName,
@NotBlank @RequestParam(required=false) Boolean isDim,
@RequestParam(required=false) String filterDims,
@RequestParam String groupbyDim,
@NotBlank @RequestParam String... timeSeries) throws Throwable {
LOGGER.info("Try to distinct-count {} on {} with filter {}.", indName, ObjectUtils.getDisplayString(timeSeries), filterDims);
long timing = System.currentTimeMillis();
Map<String, List<Integer>> filter = (filterDims == null || "".equals(filterDims)) ? null
: objectMapper.readValue(filterDims, new TypeReference<Map<String, List<Integer>>>() {});
Map<Integer, Integer> distinct = manager.aggs(timeSeries).discnt(indName, isDim == null ? true : isDim, groupbyDim, filter);
LOGGER.info("Sucess to distinct-count {} on {} result size is {} using {}ms.", indName, timeSeries, distinct.size(), System.currentTimeMillis() - timing);
LOGGER.debug("Sucess to distinct-count {} on {} result is {}.", indName, timeSeries, distinct);
return distinct;
}
@Override
@POST
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Store a feature", httpMethod="POST", response=FeatureDTO.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Feature was stored", response=FeatureDTO.class),
@ApiResponse(code = 400, message = "Latitude range out of index"),
@ApiResponse(code = 400, message = "Longitude range out of index"),
@ApiResponse(code = 400, message = "Geometry is invalid"),
@ApiResponse(code = 400, message = "Mongo GeoJSON format is not correct"),
@ApiResponse(code = 400, message = "Invalid input parameter (header)")})
public Response storeFeature(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(required=true, value="Feature") @Valid @NotNull FeatureDTO featureDTO) throws AssemblyException, MongoGeospatialException {
validations.checkIsNotNullAndNotBlank(appIdentifier);
validations.checkIsNotNull(featureDTO);
Feature feature = featureManager.storeFeature(appIdentifier, featureAssembler.createDomainObject(featureDTO));
FeatureDTO featureResponseDTO=featureAssembler.createDataTransferObject(feature);
return Response.ok(featureResponseDTO).build();
}
@Override
@Path("/{idFeature}")
@DELETE
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Delete a feature", httpMethod="DELETE")
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Feature was deleted"),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 404, message = "Feature was not found")})
public Response deleteFeature(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(required=true, value="Feature identifier") @NotBlank @NotNull @PathParam("idFeature") String idFeature) throws FeatureNotExistException {
// TODO Auto-generated method stub
validations.checkIsNotNullAndNotBlank(appIdentifier,idFeature);
featureManager.deleteFeature(appIdentifier, idFeature);
return Response.noContent().build();
}
@Override
@Path("/{idFeature}")
@GET
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Get a feature by id", httpMethod="GET", response=FeatureDTO.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Feature was found", response=FeatureDTO.class),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 404, message = "Feature was not found")})
public Response getFeatureByID(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(required=true, value="Feature identifier") @NotBlank @NotNull @PathParam("idFeature") String idFeature) throws AssemblyException, FeatureNotExistException {
// TODO Auto-generated method stub
validations.checkIsNotNullAndNotBlank(appIdentifier,idFeature);
Feature feature = featureManager.getFeatureByID(appIdentifier,idFeature);
FeatureDTO featureDTO=featureAssembler.createDataTransferObject(feature);
return Response.ok(featureDTO).build();
}
@Override
@GET
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Get .map file", httpMethod="GET", response=InputStream.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = ".map file was found", response=InputStream.class),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 404, message = ".map file was not found")})
public Response getMapFile(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier) throws MapFileNotExistsException{
validations.checkIsNotNullAndNotBlank(appIdentifier);
InputStream mapFile=mapFileManager.getMapFile(appIdentifier);
return Response.ok(mapFile).build();
}
@Override
@POST
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Get features according to query", httpMethod="POST", response=FeatureDTO.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Features were found", response=FeatureDTO.class),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 400, message = "Query is not correct")})
public Response getFeaturesByQuery(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(value = "Query", required = true) @NotBlank @NotNull String query,
@ApiParam(required=false,value="Layer",allowableValues="ALL,MAP,FEATURES",defaultValue="ALL") @QueryParam("layer") @DefaultValue("ALL") LayerDTO layer,
@ApiParam(required=false,value="Index of page",defaultValue="0") @QueryParam("pageIndex") @DefaultValue("0") Integer pageIndex,
@ApiParam(required=false,value="Size of page",defaultValue="20") @QueryParam("pageSize") @DefaultValue("20") Integer pageSize,
@ApiParam(required=false,value="Order field") @QueryParam("orderField") String orderField,
@ApiParam(required=false,value="Order",allowableValues="ASC,DESC") @DefaultValue("ASC") @QueryParam("order") String order) throws AssemblyException, QueryException {
validations.checkIsNotNullAndNotBlank(appIdentifier,query);
validations.checkIsNotNull(layer);
validations.checkMin(0, pageIndex);
validations.checkMin(1, pageSize);
Collection<Feature> features = null;
if(StringUtils.isEmpty(orderField)){
features = searchManager.getFeaturesByQuery(appIdentifier, query, layer, pageIndex, pageSize);
}else{
features = searchManager.getFeaturesByQuery(appIdentifier, query, layer, pageIndex, pageSize, orderField, order);
}
Collection<FeatureDTO> collectionFeatureDTO=featureAssembler.createDataTransferObjects(features);
return Response.ok(collectionFeatureDTO).build();
}
@NotBlank(message="岗位名称不能为空")
@Length(min=0, max=100, message="岗位名称长度不能超过 100 个字符")
public String getPostName() {
return postName;
}
@NotBlank(message="公司代码不能为空")
@Pattern(regexp="[a-zA-Z0-9_]{0,30}", message="代码长度不能大于 30 个字符,并且只能包含字母、数字、下划线")
public String getViewCode() {
return viewCode;
}
@NotBlank(message="公司名称不能为空")
@Length(min=0, max=200, message="公司名称长度不能超过 200 个字符")
public String getCompanyName() {
return companyName;
}
@NotBlank(message="类型不能为空")
@Length(min=0, max=1, message="类型长度不能超过 1 个字符")
public String getAreaType() {
return areaType;
}
@NotBlank(message="日志类型不能为空")
@Length(min=0, max=1, message="日志类型长度不能超过 1 个字符")
public String getLogType() {
return logType;
}
@NotBlank
String getLongname();
@NotBlank(message="操作IP地址不能为空")
@Length(min=0, max=255, message="操作IP地址长度不能超过 255 个字符")
public String getRemoteAddr() {
return remoteAddr;
}
@NotBlank
String getLabel();
@Override
@Size(max = 30, message = "string.size.invalid")
@NotBlank(message = "permission.code.notBlank")
public String getCode() {
return super.getCode();
}
@NotBlank(message="机构名称不能为空")
@Length(min=0, max=100, message="机构名称长度不能超过 100 个字符")
public String getOfficeName() {
return officeName;
}
@NotBlank(message="机构全称不能为空")
@Length(min=0, max=200, message="机构全称长度不能超过 200 个字符")
public String getFullName() {
return fullName;
}
/** The path in HDFS to create. */
@NotBlank
@AvailableSubstitutions(type={PARAMETERS, USER, GROUP, PRINCIPAL})
String getPath();
@NotBlank(message = "登录名不能为空")
public String getLoginName() {
return loginName;
}
@JsonCreator
public TagInput(@NotBlank @JsonProperty("name") String name) {
this.name = name;
}
/**
*
* get方法
*
*/
@NotNull(message = "必须填写ZooKeeper名字")
@NotBlank(message = "必须填写ZooKeeper名字")
public String getzk_name(){
return this.zk_name;
}
@NotBlank
public String getString() {
return "";
}
@NotBlank
String getClientId();
@NotBlank
String getAccessToken();
@NotBlank
String getRefreshToken();
/**
* @return 表单名称
*/
@ApiModelProperty(value = "表单名称", required = true, example = "测试表单")
@NotBlank(groups = CreateGroup.class)
String getName();