javax.validation.constraints.Size Java Examples
The following examples show how to use
javax.validation.constraints.Size.
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: PersonController.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@RequestMapping(path = "/personByLastName", method = RequestMethod.GET) public List<Person> findByLastName(@RequestParam(name = "lastName", required = true) @NotNull @NotBlank @Size(max = 10) String lastName) { List<Person> hardCoded = new ArrayList<>(); Person person = new Person(); person.setAge(20); person.setCreditCardNumber("4111111111111111"); person.setEmail("[email protected]"); person.setEmail1("[email protected]"); person.setFirstName("Somefirstname"); person.setLastName(lastName); person.setId(1); hardCoded.add(person); return hardCoded; }
Example #2
Source File: DeviceTypeManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@GET @Override @Path("/{type}/features") public Response getFeatures(@PathParam("type") @Size(max = 45) String type, @HeaderParam("If-Modified-Since") String ifModifiedSince) { List<Feature> features; DeviceManagementProviderService dms; try { dms = DeviceMgtAPIUtils.getDeviceManagementService(); FeatureManager fm = dms.getFeatureManager(type); if (fm == null) { return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " + "registered with the given type '" + type + "'").build()).build(); } features = fm.getFeatures(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the list of features of '" + type + "' device type"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } return Response.status(Response.Status.OK).entity(features).build(); }
Example #3
Source File: Food.java From micronaut-data with Apache License 2.0 | 6 votes |
@Creator public Food( UUID fid, @Size(max = 36) @NotNull String key, @Size(max = 9999) @NotNull int carbohydrates, @Size(max = 9999) @NotNull int portionGrams, Date createdOn, Date updatedOn, @Nullable Meal meal) { this.fid = fid; this.key = key; this.carbohydrates = carbohydrates; this.portionGrams = portionGrams; this.createdOn = createdOn; this.updatedOn = updatedOn; this.meal = meal; }
Example #4
Source File: Jsr303ExtensionTest.java From raml-java-tools with Apache License 2.0 | 6 votes |
@Test public void forArraysMaxOnly() throws Exception { when(array.minItems()).thenReturn(null); when(array.maxItems()).thenReturn(5); FieldSpec.Builder builder = FieldSpec.builder(ParameterizedTypeName.get(List.class, String.class), "champ", Modifier.PUBLIC); Jsr303Extension ext = new Jsr303Extension(); ext.fieldBuilt(objectPluginContext, array, builder, EventType.IMPLEMENTATION); assertEquals(1, builder.build().annotations.size()); assertEquals(Size.class.getName(), builder.build().annotations.get(0).type.toString()); assertEquals(1, builder.build().annotations.get(0).members.size()); assertEquals("5", builder.build().annotations.get(0).members.get("max").get(0).toString()); }
Example #5
Source File: PersonController2.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@RequestMapping(path = "/personByLastName2", method = RequestMethod.GET) public List<Person> findByLastName(@RequestParam(name = "lastName", required = true) @NotNull @NotBlank @Size(max = 10) String lastName) { List<Person> hardCoded = new ArrayList<>(); Person person = new Person(); person.setAge(20); person.setCreditCardNumber("4111111111111111"); person.setEmail("[email protected]"); person.setEmail1("[email protected]"); person.setFirstName("Somefirstname"); person.setLastName(lastName); person.setId(1); hardCoded.add(person); return hardCoded; }
Example #6
Source File: DeviceManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
/** * Change device status. * * @param type Device type * @param id Device id * @param newsStatus Device new status * @return {@link Response} object */ @PUT @Path("/{type}/{id}/changestatus") public Response changeDeviceStatus(@PathParam("type") @Size(max = 45) String type, @PathParam("id") @Size(max = 45) String id, @QueryParam("newStatus") EnrolmentInfo.Status newsStatus) { RequestValidationUtil.validateDeviceIdentifier(type, id); DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, type); Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier, false); if (persistedDevice == null) { return Response.status(Response.Status.NOT_FOUND).build(); } boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus); return Response.status(Response.Status.OK).entity(response).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while changing device status of type : " + type + " and " + "device id : " + id; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } }
Example #7
Source File: UserManagementAdminServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@DELETE @Path("/type/{device-type}/id/{device-id}") @Override public Response deleteDevice(@PathParam("device-type") @Size(max = 45) String deviceType, @PathParam("device-id") @Size(max = 45) String deviceId) { try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); DeviceMgtAPIUtils.getPrivacyComplianceProvider().deleteDeviceDetails(deviceIdentifier); return Response.status(Response.Status.OK).build(); } catch (PrivacyComplianceException e) { String msg = "Error occurred while deleting the devices information."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } }
Example #8
Source File: PersonController.java From springdoc-openapi with Apache License 2.0 | 6 votes |
@RequestMapping(path = "/personByLastName", method = RequestMethod.GET) public List<Person> findByLastName(@RequestParam(name = "lastName", required = true) @NotNull @NotBlank @Size(max = 10) String lastName) { List<Person> hardCoded = new ArrayList<>(); Person person = new Person(); person.setAge(20); person.setCreditCardNumber("4111111111111111"); person.setEmail("[email protected]"); person.setEmail1("[email protected]"); person.setFirstName("Somefirstname"); person.setLastName(lastName); person.setId(1); hardCoded.add(person); return hardCoded; }
Example #9
Source File: HelloResource.java From boost with Eclipse Public License 1.0 | 5 votes |
@GET @Path("/{dataIn}") @Produces("text/plain") public String getInformationWithString(@PathParam("dataIn") @Size(min = 2, max = 10) String dataIn) throws Exception, IOException { return ("Hello World From Your Friends at Liberty Boost EE! Your passed in string data is: " + dataIn); }
Example #10
Source File: ActivityProviderServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@GET @Override @Path("/{id}") public Response getActivity(@PathParam("id") @Size(max = 45) String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) { Activity activity; DeviceManagementProviderService dmService; Response response = validateAdminUser(); if (response == null) { try { RequestValidationUtil.validateActivityId(id); dmService = DeviceMgtAPIUtils.getDeviceManagementService(); activity = dmService.getOperationByActivityId(id); if (activity == null) { return Response.status(404).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " + "found upon the provided activity id '" + id + "'").build()).build(); } return Response.status(Response.Status.OK).entity(activity).build(); } catch (OperationManagementException e) { String msg = "ErrorResponse occurred while fetching the activity for the supplied id."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } else { return response; } }
Example #11
Source File: TopicsController.java From pulsar-manager with Apache License 2.0 | 5 votes |
@ApiOperation(value = "Query topic stats info by tenant and namespace") @ApiResponses({ @ApiResponse(code = 200, message = "ok"), @ApiResponse(code = 500, message = "Internal server error") }) @RequestMapping(value = "/topics/{tenant}/{namespace}/stats", method = RequestMethod.GET) public Map<String, Object> getTopicsStats( @ApiParam(value = "page_num", defaultValue = "1", example = "1") @RequestParam(name = "page_num", defaultValue = "1") @Min(value = 1, message = "page_num is incorrect, should be greater than 0.") Integer pageNum, @ApiParam(value = "page_size", defaultValue = "10", example = "10") @RequestParam(name="page_size", defaultValue = "10") @Range(min = 1, max = 1000, message = "page_size is incorrect, should be greater than 0 and less than 1000.") Integer pageSize, @ApiParam(value = "The name of tenant") @Size(min = 1, max = 255) @PathVariable String tenant, @ApiParam(value = "The name of namespace") @Size(min = 1, max = 255) @PathVariable String namespace) { String env = request.getHeader("environment"); String serviceUrl = environmentCacheService.getServiceUrl(request); return topicsService.getTopicStats( pageNum, pageSize, tenant, namespace, env, serviceUrl); }
Example #12
Source File: WriteArticle.java From jakduk-api with MIT License | 5 votes |
public WriteArticle(@Size(min = 1, max = 60) @NotEmpty String subject, @Size(min = 5) @NotEmpty String content, String categoryCode, List<GalleryOnBoard> galleries) { this.subject = subject; this.content = content; this.categoryCode = categoryCode; this.galleries = galleries; }
Example #13
Source File: BeanValidationProcessor.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
@PostConstruct public void init() { validationAnnotations = new HashSet<>(); validationAnnotations.addAll(Arrays.asList(NotNull.class, Size.class, Pattern.class, DecimalMin.class, DecimalMax.class, Min.class, Max.class)); }
Example #14
Source File: UserManagementAdminServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@POST @Path("/{username}/credentials") @Override public Response resetUserPassword(@PathParam("username") @Size(max = 45) String user, @QueryParam("domain") String domain, PasswordResetWrapper credentials) { if (domain != null && !domain.isEmpty()) { user = domain + '/' + user; } return CredentialManagementResponseBuilder.buildResetPasswordResponse(user, credentials); }
Example #15
Source File: ValueIsNotAnyOf.java From onedev with MIT License | 5 votes |
@Editable @ChoiceProvider("getValueChoices") @OmitName @Size(min=1, message="At least one value needs to be specified") public List<String> getValues() { return values; }
Example #16
Source File: BlueprintV4ViewResponse.java From cloudbreak with Apache License 2.0 | 5 votes |
@NotNull @Size(max = 100, min = 1, message = "The length of the blueprint's name has to be in range of 1 to 100 and should not contain semicolon " + "and percentage character.") @Pattern(regexp = "^[^;\\/%]*$") public String getName() { return super.getName(); }
Example #17
Source File: OpenApiClientGenerator.java From spring-openapi with MIT License | 5 votes |
private FieldSpec.Builder getStringBasedSchemaField(String fieldName, Schema innerSchema, TypeSpec.Builder typeSpecBuilder) { if (innerSchema.getFormat() == null) { ClassName stringClassName = ClassName.get(JAVA_LANG_PKG, "String"); FieldSpec.Builder fieldBuilder = FieldSpec.builder(stringClassName, fieldName, Modifier.PRIVATE); if (innerSchema.getPattern() != null) { fieldBuilder.addAnnotation(AnnotationSpec.builder(Pattern.class) .addMember("regexp", "$S", innerSchema.getPattern()) .build() ); } if (innerSchema.getMinLength() != null || innerSchema.getMaxLength() != null) { AnnotationSpec.Builder sizeAnnotationBuilder = AnnotationSpec.builder(Size.class); if (innerSchema.getMinLength() != null) { sizeAnnotationBuilder.addMember("min", "$L", innerSchema.getMinLength()); } if (innerSchema.getMaxLength() != null) { sizeAnnotationBuilder.addMember("max", "$L", innerSchema.getMaxLength()); } fieldBuilder.addAnnotation(sizeAnnotationBuilder.build()); } enrichWithGetSet(typeSpecBuilder, stringClassName, fieldName); return fieldBuilder; } else if (equalsIgnoreCase(innerSchema.getFormat(), "date")) { ClassName localDateClassName = ClassName.get(JAVA_TIME_PKG, "LocalDate"); enrichWithGetSet(typeSpecBuilder, localDateClassName, fieldName); return FieldSpec.builder(localDateClassName, fieldName, Modifier.PRIVATE); } else if (equalsIgnoreCase(innerSchema.getFormat(), "date-time")) { ClassName localDateTimeClassName = ClassName.get(JAVA_TIME_PKG, "LocalDateTime"); enrichWithGetSet(typeSpecBuilder, localDateTimeClassName, fieldName); return FieldSpec.builder(localDateTimeClassName, fieldName, Modifier.PRIVATE); } throw new IllegalArgumentException(String.format("Error parsing string based property [%s]", fieldName)); }
Example #18
Source File: SizeConstraintsTest.java From rest-schemagen with Apache License 2.0 | 5 votes |
@Test public void defaultOperation() { final Optional<Integer> max = Optional.of(7); final Optional<Integer> min = Optional.of(4); Size size = mock(Size.class); when(size.max()).thenReturn(max.get()); when(size.min()).thenReturn(min.get()); final SizeConstraints sizeConstraints = new SizeConstraints(size); assertThat(sizeConstraints.getMax()).isEqualTo(max); assertThat(sizeConstraints.getMin()).isEqualTo(min); }
Example #19
Source File: ParameterScanTests.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Widget update(@FormParam("form-param2") @Size(max = 10) String formParam2, @FormParam("qualifiers") java.util.SortedSet<String> qualifiers) { return null; }
Example #20
Source File: AccountsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * @param email An email. * @return The public keys of the account corresponding to the introduced email. */ @GetMapping("/public-keys") public AccountDto getAccountPublicKeys( @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { return accountsService.getAndCheckAccountPublicKeysByEmail(email); }
Example #21
Source File: HealthResource.java From generator-jvm with MIT License | 5 votes |
String linkTo(@Size(min = 1) final String... args) { return uriInfo.getBaseUriBuilder() .path(HealthResource.class) .path(HealthResource.class, args[0]) .build(args[1]) .toString(); }
Example #22
Source File: AbstractRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Calculate size. * * @param annos the annos * @param schema the schema */ private void calculateSize(Map<String, Annotation> annos, Schema<?> schema) { if (annos.containsKey(Size.class.getName())) { Size size = (Size) annos.get(Size.class.getName()); if (OPENAPI_ARRAY_TYPE.equals(schema.getType())) { schema.setMinItems(size.min()); schema.setMaxItems(size.max()); } else if (OPENAPI_STRING_TYPE.equals(schema.getType())) { schema.setMinLength(size.min()); schema.setMaxLength(size.max()); } } }
Example #23
Source File: PersonService.java From microshed-testing with Apache License 2.0 | 5 votes |
@POST public Long createPerson(@QueryParam("name") @NotEmpty @Size(min = 2, max = 50) String name, @QueryParam("age") @PositiveOrZero int age) { Person p = new Person(name, age); personRepo.put(p.id, p); return p.id; }
Example #24
Source File: AllianceController.java From retro-game with GNU Affero General Public License v3.0 | 5 votes |
@PostMapping("/alliance/manage/logo/save") @PreAuthorize("hasPermission(#bodyId, 'ACCESS')") @Activity(bodies = "#bodyId") public String manageLogoSave(@RequestParam(name = "body") long bodyId, @RequestParam(name = "alliance") long allianceId, @RequestParam @URL @Size(max = 128) String url) { allianceService.saveLogo(bodyId, allianceId, url); return "redirect:/alliance/manage?body=" + bodyId + "&alliance=" + allianceId; }
Example #25
Source File: PersonService.java From microshed-testing with Apache License 2.0 | 5 votes |
@POST public Long createPerson(@QueryParam("name") @NotEmpty @Size(min = 2, max = 50) String name, @QueryParam("age") @PositiveOrZero int age) { Person p = new Person(name, age); personRepo.put(p.id, p); return p.id; }
Example #26
Source File: ParameterScanTests.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) @Parameter(name = "id", in = ParameterIn.PATH, style = ParameterStyle.MATRIX, description = "Additional information for id2") public Widget get(@MatrixParam("m1") @DefaultValue("default-m1") String m1, @MatrixParam("m2") @Size(min = 20) String m2) { return null; }
Example #27
Source File: RegistrationsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * @param token A registration token. * @return The Registration corresponding to the introduced token. */ @GetMapping() public RegistrationDto getRegistration( @RequestParam(name = "token", required = true) @NotBlank @Pattern(regexp = ALPHANUMERIC_PATTERN) @Size(min = ALPHANUMERIC_64BYTES_LENGTH, max = ALPHANUMERIC_64BYTES_LENGTH) String token) { return registrationsService.getAndCheckRegistrationByToken(token); }
Example #28
Source File: MyResource.java From parsec-libraries with Apache License 2.0 | 5 votes |
@Path("myresource/{id1}") @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public String postIt( @NotNull @Size(min=5,max=10,message="'${validatedValue}' min {min}") @PathParam("id1") String value1, @Valid MyDto dto ) { return "OK-" + value1; }
Example #29
Source File: IncludeIssueFields.java From onedev with MIT License | 5 votes |
@Editable(name="Fields") @ChoiceProvider("getFieldChoices") @OmitName @Size(min=1, message = "At least one field needs to be specified") public List<String> getIncludeFields() { return includeFields; }
Example #30
Source File: SharedSecretsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Forgets a shared secret ex member. * * @param secretId The secret ID of the shared secret. * @param email The email of the ex member. * @return Object indicating if the execution was successful. */ @DeleteMapping("/sent/{secret-id}/ex-member") public SuccessDto forgetSharedSecretExMember( @PathVariable(name = "secret-id", required = true) @NotNull UUID secretId, @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { sharedSecretsService.forgetSharedSecretExMember(sessionAccount.getAccountId(), secretId, email); return new SuccessDto(true); }