Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1018 - HAL Forms properties customizable via annotations on represen…
…tation model classes. We now consider additional Jackson and JSR-303 annotations on representation models to enrich the HAL Forms template properties with additional information: - @NotNull on a property flips its `required` flag to `true`. - The "regexp" attribute of @pattern on a property is forwarded into the "regex" field. - @JsonProperty(Access.READ_ONLY) on a property is translated into the "readOnly" flag. The default for the "required" flag have been changed to false even for PUT and POST as whether they're required or not is completely determined by the model, not the HTTP method. All of this is backed by significant refactoring in the way that Affordance instances are build internally. The new API is centered around the Affordances type in the mediatype package. The methods on Link to create the Affordance` from its details have been removed and replaced by builder style APIs on Affordance. AffordanceModelFactory has been moved to the mediatype as well. PropertyUtils has been significantly revamped to expose a PayloadMetadata/PropertyMetadata model to abstract the individual traits of a property. This allows to optionally plug in the support for JSR-303 annotations. AffordanceModelFactory has been refactored to rather work with those instead of ResolvableType.
- Loading branch information
Showing
48 changed files
with
2,277 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/docs/java/org/springframework/hateoas/AffordancesSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.hateoas; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; | ||
|
||
import lombok.var; | ||
|
||
import org.springframework.hateoas.SimpleRepresentationModelAssemblerTest.Employee; | ||
import org.springframework.hateoas.mediatype.Affordances; | ||
import org.springframework.http.HttpMethod; | ||
|
||
/** | ||
* Manual usage of {@link Affordances}. | ||
* | ||
* @author Oliver Drotbohm | ||
*/ | ||
public class AffordancesSample { | ||
|
||
void manualAffordance() { | ||
|
||
// tag::affordances[] | ||
var methodInvocation = methodOn(EmployeeController.class).all(); | ||
|
||
var link = Affordances.of(linkTo(methodInvocation).withSelfRel()) // <1> | ||
|
||
.afford(HttpMethod.POST) // <2> | ||
.withInputAndOutput(Employee.class) // | ||
.withName("createEmployee") // | ||
|
||
.andAfford(HttpMethod.GET) // <3> | ||
.withOutput(Employee.class) // | ||
.addParameters(// | ||
QueryParameter.optional("name"), // | ||
QueryParameter.optional("role")) // | ||
.withName("search") // | ||
|
||
.toLink(); | ||
// end::affordances[] | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/docs/java/org/springframework/hateoas/EmployeeModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.hateoas; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
|
||
/** | ||
* @author Oliver Drotbohm | ||
*/ | ||
// tag:hal-forms-model[] | ||
@Data | ||
public class EmployeeModel extends RepresentationModel<EmployeeModel> { | ||
|
||
@NotNull // | ||
private String name; | ||
|
||
@Pattern(regexp = "[A-Z_]") // | ||
private String role; | ||
} | ||
// end:hal-forms-model[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.