Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ralscha committed Jan 10, 2025
1 parent b969911 commit ba7023f
Show file tree
Hide file tree
Showing 41 changed files with 813 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public static EdFormPostResult create(BindingResult bindingResult) {
}

public static EdFormPostResult create(BindingResult bindingResult, boolean success) {
return ImmutableEdFormPostResult.builder().addErrors(null, null, bindingResult)
.putResult(SUCCESS_PROPERTY, success).build();
return ImmutableEdFormPostResult.builder()
.addErrors(null, null, bindingResult)
.putResult(SUCCESS_PROPERTY, success)
.build();
}

public static EdFormPostResult create(Locale locale, MessageSource messageSource, BindingResult bindingResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void buildAndWrite() {

try {
RouterController routerController = RequestContextUtils.findWebApplicationContext(this.request)
.getBean(RouterController.class);
.getBean(RouterController.class);

routerController.writeJsonResponse(this.request, this.response, this.extDirectResponse, this.jsonView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void poll(@PathVariable("beanName") String beanName, @PathVariable("metho

try {

Object[] parameters = this.configurationService.getParametersResolver().prepareParameters(request,
response, locale, methodInfo);
Object[] parameters = this.configurationService.getParametersResolver()
.prepareParameters(request, response, locale, methodInfo);

if (this.configurationService.getConfiguration().isSynchronizeOnSession()
|| methodInfo.isSynchronizeOnSession()) {
Expand Down Expand Up @@ -230,7 +230,7 @@ else if (methodInfo != null && methodInfo.getHandlerMethod() != null) {
Map<String, Object> model = modelAndView.getModel();
if (model.containsKey("extDirectFormPostResult")) {
ExtDirectFormPostResult formPostResult = (ExtDirectFormPostResult) model
.get("extDirectFormPostResult");
.get("extDirectFormPostResult");
directResponse.setResult(formPostResult.getResult());
directResponse.setJsonView(getJsonView(formPostResult, methodInfo.getJsonView()));
}
Expand Down Expand Up @@ -260,8 +260,8 @@ else if (model.containsKey("edFormPostResult")) {
consumes = MediaType.APPLICATION_JSON_VALUE)
public void router(HttpServletRequest request, HttpServletResponse response, Locale locale) throws IOException {

Object requestData = this.configurationService.getJsonHandler().readValue(request.getInputStream(),
Object.class);
Object requestData = this.configurationService.getJsonHandler()
.readValue(request.getInputStream(), Object.class);

List<ExtDirectRequest> directRequests = null;
if (requestData instanceof Map) {
Expand All @@ -271,8 +271,8 @@ public void router(HttpServletRequest request, HttpServletResponse response, Loc
else if (requestData instanceof List) {
directRequests = new ArrayList<>();
for (Object oneRequest : (List<?>) requestData) {
directRequests.add(
this.configurationService.getJsonHandler().convertValue(oneRequest, ExtDirectRequest.class));
directRequests
.add(this.configurationService.getJsonHandler().convertValue(oneRequest, ExtDirectRequest.class));
}
}

Expand All @@ -281,11 +281,11 @@ else if (requestData instanceof List) {
handleMethodCallOne(directRequests.get(0), request, response, locale);
}
else if (this.configurationService.getConfiguration()
.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.SEQUENTIAL) {
.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.SEQUENTIAL) {
handleMethodCallsSequential(directRequests, request, response, locale);
}
else if (this.configurationService.getConfiguration()
.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT) {
.getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT) {
handleMethodCallsConcurrent(directRequests, request, response, locale);
}
}
Expand All @@ -298,8 +298,8 @@ private void handleMethodCallsConcurrent(List<ExtDirectRequest> directRequests,
List<Future<ExtDirectResponse>> futures = new ArrayList<>(directRequests.size());
for (ExtDirectRequest directRequest : directRequests) {
Callable<ExtDirectResponse> callable = createMethodCallCallable(directRequest, request, response, locale);
futures.add(
this.configurationService.getConfiguration().getBatchedMethodsExecutorService().submit(callable));
futures
.add(this.configurationService.getConfiguration().getBatchedMethodsExecutorService().submit(callable));
}

ObjectMapper objectMapper = this.configurationService.getJsonHandler().getMapper();
Expand All @@ -315,7 +315,7 @@ private void handleMethodCallsConcurrent(List<ExtDirectRequest> directRequests,
}
else {
String jsonResult = objectMapper.writerWithView(jsonView)
.writeValueAsString(directResponse.getResult());
.writeValueAsString(directResponse.getResult());
directResponses.add(new ExtDirectResponseRaw(directResponse, jsonResult));
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ private void handleMethodCallsSequential(List<ExtDirectRequest> directRequests,
}
else {
String jsonResult = objectMapper.writerWithView(jsonView)
.writeValueAsString(directResponse.getResult());
.writeValueAsString(directResponse.getResult());
directResponses.add(new ExtDirectResponseRaw(directResponse, jsonResult));
}
}
Expand Down Expand Up @@ -559,8 +559,8 @@ public void writeJsonResponse(HttpServletResponse response, Object responseObjec
jsonGenerator.close();
}
else {
JsonGenerator jsonGenerator = objectMapper.getFactory().createGenerator(outputStream,
JsonEncoding.UTF8);
JsonGenerator jsonGenerator = objectMapper.getFactory()
.createGenerator(outputStream, JsonEncoding.UTF8);
if (jsonView == null) {
objectMapper.writeValue(jsonGenerator, responseObject);
}
Expand All @@ -577,8 +577,8 @@ public void writeJsonResponse(HttpServletResponse response, Object responseObjec
private Object processRemotingRequest(HttpServletRequest request, HttpServletResponse response, Locale locale,
ExtDirectRequest directRequest, MethodInfo methodInfo) throws Exception {

Object[] parameters = this.configurationService.getParametersResolver().resolveParameters(request, response,
locale, directRequest, methodInfo);
Object[] parameters = this.configurationService.getParametersResolver()
.resolveParameters(request, response, locale, directRequest, methodInfo);

if (this.configurationService.getConfiguration().isSynchronizeOnSession()
|| methodInfo.isSynchronizeOnSession()) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/ch/ralscha/extdirectspring/util/MethodInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ private Action extractDocumentationAnnotations(ExtDirectMethodDocumentation docu
: docParameters.descriptions();
if (params.length == descriptions.length) {
for (int i = 0; i < params.length; i++) {
actionDoc.getParameters().put(params[i],
descriptions[i] == null ? "No description" : descriptions[i]);
actionDoc.getParameters()
.put(params[i], descriptions[i] == null ? "No description" : descriptions[i]);
}
}
else {
LogFactory.getLog(MethodInfo.class).info(
"Documentation: skip generation of parameters, params size is different from descriptions size");
LogFactory.getLog(MethodInfo.class)
.info("Documentation: skip generation of parameters, params size is different from descriptions size");
}
}
ExtDirectDocReturn docReturn = documentation.returnMethod();
Expand All @@ -236,13 +236,13 @@ private Action extractDocumentationAnnotations(ExtDirectMethodDocumentation docu
: docReturn.descriptions();
if (properties.length == descriptions.length) {
for (int i = 0; i < properties.length; i++) {
actionDoc.getReturnMethod().put(properties[i],
descriptions[i] == null ? "No description" : descriptions[i]);
actionDoc.getReturnMethod()
.put(properties[i], descriptions[i] == null ? "No description" : descriptions[i]);
}
}
else {
LogFactory.getLog(MethodInfo.class).info(
"Documentation: skip generation of return method properties, properties size is different from descriptions size");
LogFactory.getLog(MethodInfo.class)
.info("Documentation: skip generation of return method properties, properties size is different from descriptions size");
}
}
return actionDoc;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/ch/ralscha/extdirectspring/util/ParameterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ParameterInfo(Class<?> clazz, Method method, int paramIndex) {

MethodParameter methodParam = new MethodParameter(method, paramIndex);
methodParam.initParameterNameDiscovery(discoverer);

this.name = methodParam.getParameterName();
this.typeDescriptor = new TypeDescriptor(methodParam);

Expand Down Expand Up @@ -129,10 +129,12 @@ else if (CookieValue.class.isInstance(paramAnn)) {
this.hasCookieValueAnnotation = true;
break;
}
else if (paramAnn.annotationType().getName()
.equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal")
|| paramAnn.annotationType().getName()
.equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) {
else if (paramAnn.annotationType()
.getName()
.equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal")
|| paramAnn.annotationType()
.getName()
.equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) {
this.hasAuthenticationPrincipalAnnotation = (Boolean) AnnotationUtils.getValue(paramAnn,
"errorOnInvalidType");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ else if (this.conversionService.canConvert(TypeDescriptor.forObject(value),
TypeFactory typeFactory = this.jsonHandler.getMapper().getTypeFactory();
if (methodParameter.getTypeDescriptor().isCollection()) {

JavaType elemType = typeFactory.constructType(
methodParameter.getTypeDescriptor().getElementTypeDescriptor().getType());
JavaType elemType = typeFactory
.constructType(methodParameter.getTypeDescriptor().getElementTypeDescriptor().getType());
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if (vars == null || vars.length != 1) {
Expand Down Expand Up @@ -553,8 +553,8 @@ else if (key.equals("group") && value != null && (value instanceof List || value
if (descriptor != null && descriptor.getWriteMethod() != null) {
try {

descriptor.getWriteMethod().invoke(to,
this.conversionService.convert(value, descriptor.getPropertyType()));
descriptor.getWriteMethod()
.invoke(to, this.conversionService.convert(value, descriptor.getPropertyType()));

foundParameters.add(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,26 @@ public class ExtDirectMethodTypeTest {
@Test
public void testSimpleIsValid() throws SecurityException {
assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method1", RemoteProviderSimple.class,
findMethod(RemoteProviderSimple.class, "method1"))).isTrue();
findMethod(RemoteProviderSimple.class, "method1")))
.isTrue();
assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method2", RemoteProviderSimple.class,
findMethod(RemoteProviderSimple.class, "method2"))).isTrue();
findMethod(RemoteProviderSimple.class, "method2")))
.isTrue();
assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method3", RemoteProviderSimple.class,
findMethod(RemoteProviderSimple.class, "method3"))).isTrue();
findMethod(RemoteProviderSimple.class, "method3")))
.isTrue();
assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method3WithError",
RemoteProviderSimple.class, findMethod(RemoteProviderSimple.class, "method3WithError"))).isFalse();
RemoteProviderSimple.class, findMethod(RemoteProviderSimple.class, "method3WithError")))
.isFalse();
}

@Test
public void testSimpleNamedIsValid() throws SecurityException {
for (Method method : RemoteProviderSimpleNamed.class.getMethods()) {
if (method.getName().startsWith("method")) {
assertThat(ExtDirectMethodType.SIMPLE_NAMED.isValid("remoteProviderSimpleNamed." + method.getName(),
RemoteProviderSimpleNamed.class, method)).isTrue();
RemoteProviderSimpleNamed.class, method))
.isTrue();
}
}
}
Expand All @@ -63,7 +68,8 @@ public void testFormLoadIsValid() throws SecurityException {
for (Method method : RemoteProviderFormLoad.class.getMethods()) {
if (method.getName().startsWith("method")) {
assertThat(ExtDirectMethodType.FORM_LOAD.isValid("remoteProviderFormLoad." + method.getName(),
RemoteProviderFormLoad.class, method)).isTrue();
RemoteProviderFormLoad.class, method))
.isTrue();
}
}
}
Expand All @@ -73,7 +79,8 @@ public void testStoreReadIsValid() throws SecurityException {
for (Method method : RemoteProviderStoreRead.class.getMethods()) {
if (method.getName().startsWith("method")) {
assertThat(ExtDirectMethodType.STORE_READ.isValid("remoteProviderStoreRead." + method.getName(),
RemoteProviderStoreRead.class, method)).isTrue();
RemoteProviderStoreRead.class, method))
.isTrue();
}
}
}
Expand All @@ -84,7 +91,8 @@ public void testStoreModifyIsValid() throws SecurityException {
if (method.getName().startsWith("create") || method.getName().startsWith("update")
|| method.getName().startsWith("destroy")) {
assertThat(ExtDirectMethodType.STORE_MODIFY.isValid("remoteProviderStoreModify." + method.getName(),
RemoteProviderStoreModify.class, method)).isTrue();
RemoteProviderStoreModify.class, method))
.isTrue();
}
}

Expand All @@ -93,46 +101,62 @@ public void testStoreModifyIsValid() throws SecurityException {
@Test
public void testFormPostIsValid() throws SecurityException {
assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo1",
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo1"))).isFalse();
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo1")))
.isFalse();
assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo2",
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo2"))).isFalse();
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo2")))
.isFalse();
assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo3",
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo3"))).isFalse();
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo3")))
.isFalse();
assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo4",
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo4"))).isFalse();
WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo4")))
.isFalse();

assertThat(ExtDirectMethodType.FORM_POST.isValid("uploadService.upload", UploadService.class,
findMethod(UploadService.class, "upload"))).isTrue();
findMethod(UploadService.class, "upload")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("uploadService.uploadEd", UploadService.class,
findMethod(UploadService.class, "uploadEd"))).isTrue();
findMethod(UploadService.class, "uploadEd")))
.isTrue();

assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.updateInfo1", FormInfoController2.class,
findMethod(FormInfoController2.class, "updateInfo1"))).isTrue();
findMethod(FormInfoController2.class, "updateInfo1")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.updateInfo2", FormInfoController2.class,
findMethod(FormInfoController2.class, "updateInfo2"))).isTrue();
findMethod(FormInfoController2.class, "updateInfo2")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.invalidMethod", FormInfoController2.class,
findMethod(FormInfoController2.class, "invalidMethod"))).isFalse();
findMethod(FormInfoController2.class, "invalidMethod")))
.isFalse();

assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfo", FormInfoController.class,
findMethod(FormInfoController.class, "updateInfo"))).isTrue();
findMethod(FormInfoController.class, "updateInfo")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.upload", FormInfoController.class,
findMethod(FormInfoController.class, "upload"))).isTrue();
findMethod(FormInfoController.class, "upload")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.invalidMethod1", FormInfoController.class,
findMethod(FormInfoController.class, "invalidMethod1"))).isFalse();
findMethod(FormInfoController.class, "invalidMethod1")))
.isFalse();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.invalidMethod2", FormInfoController.class,
findMethod(FormInfoController.class, "invalidMethod2"))).isFalse();
findMethod(FormInfoController.class, "invalidMethod2")))
.isFalse();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfoDirect",
FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirect"))).isTrue();
FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirect")))
.isTrue();
assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfoDirectEd",
FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirectEd"))).isTrue();
FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirectEd")))
.isTrue();
}

@Test
public void testTreeLoadIsValid() throws SecurityException {
for (Method method : RemoteProviderTreeLoad.class.getMethods()) {
if (method.getName().startsWith("method")) {
assertThat(ExtDirectMethodType.TREE_LOAD.isValid("remoteProviderTreeLoad." + method.getName(),
RemoteProviderTreeLoad.class, method)).isTrue();
RemoteProviderTreeLoad.class, method))
.isTrue();
}
}
}
Expand All @@ -142,34 +166,37 @@ public void testPollIsValid() throws SecurityException {
for (Method method : PollProvider.class.getMethods()) {
if (method.getName().startsWith("message") || method.getName().startsWith("handleMessage")) {
assertThat(ExtDirectMethodType.POLL.isValid("pollProvider." + method.getName(), PollProvider.class,
method)).isTrue();
method))
.isTrue();
}
}
}

@Test
public void testFormPostJsonIsValid() throws SecurityException {
assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJson",
FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJson"))).isTrue();
FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJson")))
.isTrue();

assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJsonDirect",
FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirect"))).isTrue();
FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirect")))
.isTrue();

assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJsonDirectError",
FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirectError")))
.isTrue();
.isTrue();

assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid(
"formInfoController3.updateInfoJsonDirectNotRegisteredWithBindingResultAsParameter",
FormInfoController3.class,
findMethod(FormInfoController3.class, "updateInfoJsonDirectNotRegisteredWithBindingResultAsParameter")))
.isFalse();
.isFalse();

assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid(
"formInfoController3.updateInfoJsonDirectNotRegisteredWithMultipartFileAsParameter",
FormInfoController3.class,
findMethod(FormInfoController3.class, "updateInfoJsonDirectNotRegisteredWithMultipartFileAsParameter")))
.isFalse();
.isFalse();

}

Expand Down
Loading

0 comments on commit ba7023f

Please sign in to comment.