Skip to content

Commit

Permalink
Fixes issue #40 - Fix code smell (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Apr 2, 2023
1 parent f91c741 commit 9f82c01
Showing 1 changed file with 20 additions and 12 deletions.
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

0 comments on commit 9f82c01

Please sign in to comment.