Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #40 - Fix code smell #41

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
*/
package com.manorrock.oyena.lifecycle.action;

import static com.manorrock.oyena.lifecycle.action.ActionMappingType.EXACT;
import static com.manorrock.oyena.lifecycle.action.ActionMappingType.EXTENSION;
import static com.manorrock.oyena.lifecycle.action.ActionMappingType.PREFIX;
import static com.manorrock.oyena.lifecycle.action.ActionMappingType.REGEX;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Any;
import static jakarta.enterprise.inject.Any.Literal.INSTANCE;
import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.enterprise.inject.spi.Bean;
Expand Down Expand Up @@ -57,6 +61,7 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
Class clazz = bean.getBeanClass();
AnnotatedType annotatedType = CDI.current().getBeanManager().createAnnotatedType(clazz);
Set<AnnotatedMethod> annotatedMethodSet = annotatedType.getMethods();
boolean done = false;
for (AnnotatedMethod method : annotatedMethodSet) {
if (method.isAnnotationPresent(ActionMapping.class)) {
ActionMapping requestMapping = method.getAnnotation(ActionMapping.class);
Expand All @@ -68,9 +73,9 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
result.setBean(bean);
result.setMethod(method.getJavaMember());
result.setActionMapping(mapping);
result.setMappingType(ActionMappingType.EXACT);
result.setMappingType(EXACT);
result.setPathInfo(pathInfo);
break;
done = true;
} else if (mapping.endsWith("*")) {
mapping = mapping.substring(0, mapping.length() - 1);
if (pathInfo.startsWith(mapping)) {
Expand All @@ -79,13 +84,13 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
result.setBean(bean);
result.setMethod(method.getJavaMember());
result.setActionMapping(mapping);
result.setMappingType(ActionMappingType.PREFIX);
result.setMappingType(PREFIX);
result.setPathInfo(pathInfo);
} else if (mapping.length() > result.getLength()) {
result.setBean(bean);
result.setMethod(method.getJavaMember());
result.setActionMapping(mapping);
result.setMappingType(ActionMappingType.PREFIX);
result.setMappingType(PREFIX);
result.setPathInfo(pathInfo);
}
}
Expand All @@ -96,9 +101,9 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
result.setBean(bean);
result.setMethod(method.getJavaMember());
result.setActionMapping(mapping);
result.setMappingType(ActionMappingType.EXTENSION);
result.setMappingType(EXTENSION);
result.setPathInfo(pathInfo);
break;
done = true;
}
} else if (mapping.startsWith("regex:")) {
mapping = mapping.substring("regex:".length());
Expand All @@ -107,16 +112,19 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
result.setBean(bean);
result.setMethod(method.getJavaMember());
result.setActionMapping(mapping);
result.setMappingType(ActionMappingType.REGEX);
result.setMappingType(REGEX);
result.setPathInfo(pathInfo);
break;
done = true;
}
}
}
}
if (result != null
&& (result.getMappingType().equals(ActionMappingType.EXACT)
|| (result.getMappingType().equals(ActionMappingType.EXTENSION)))) {
&& (result.getMappingType().equals(EXACT)
|| (result.getMappingType().equals(EXTENSION)))) {
done = true;
}
if (done) {
break;
}
}
Expand All @@ -130,7 +138,7 @@ private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext
*/
private Iterator<Bean<?>> getBeans() {
Set<Bean<?>> beans = CDI.current().getBeanManager().getBeans(
Object.class, Any.Literal.INSTANCE);
Object.class, INSTANCE);
return beans.iterator();
}

Expand Down