Skip to content

Commit

Permalink
WW-5411 General code clean up using modern language features
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Jul 25, 2024
1 parent aec78dd commit 35d9c0b
Show file tree
Hide file tree
Showing 378 changed files with 2,541 additions and 2,407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,85 +33,85 @@

import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
* TestDataProvider.
*/
@Service
public class TestDataProvider implements Serializable, InitializingBean {

@Serial
private static final long serialVersionUID = 1L;
private static final Logger log = LogManager.getLogger(TestDataProvider.class);
@Serial
private static final long serialVersionUID = 1L;
private static final Logger log = LogManager.getLogger(TestDataProvider.class);

public static final String[] POSITIONS = {
"Developer",
"System Architect",
"Sales Manager",
"CEO"
};
public static final String[] POSITIONS = {
"Developer",
"System Architect",
"Sales Manager",
"CEO"
};

public static final String[] LEVELS = {
"Junior",
"Senior",
"Master"
};
public static final String[] LEVELS = {
"Junior",
"Senior",
"Master"
};

private static final Skill[] TEST_SKILLS = {
new Skill("WW-SEN", "Struts Senior Developer"),
new Skill("WW-JUN", "Struts Junior Developer"),
new Skill("SPRING-DEV", "Spring Developer")
};
private static final Skill[] TEST_SKILLS = {
new Skill("WW-SEN", "Struts Senior Developer"),
new Skill("WW-JUN", "Struts Junior Developer"),
new Skill("SPRING-DEV", "Spring Developer")
};

public static final Employee[] TEST_EMPLOYEES = {
new Employee(1L, "Alan", "Smithee", new Date(), 2000f, true, POSITIONS[0],
TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
new Employee(2L, "Robert", "Robson", new Date(), 10000f, false, POSITIONS[1],
TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1, TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
};
public static final Employee[] TEST_EMPLOYEES = {
new Employee(1L, "Alan", "Smithee", new Date(), 2000f, true, POSITIONS[0],
TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
new Employee(2L, "Robert", "Robson", new Date(), 10000f, false, POSITIONS[1],
TEST_SKILLS[1], List.of(TEST_SKILLS).subList(1, TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
};

@Autowired
private SkillDao skillDao;
@Autowired
private SkillDao skillDao;

@Autowired
private EmployeeDao employeeDao;
@Autowired
private EmployeeDao employeeDao;

protected void addTestSkills() {
try {
protected void addTestSkills() {
try {
for (Skill testSkill : TEST_SKILLS) {
skillDao.merge(testSkill);
}
if (log.isInfoEnabled()) {
log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
}
} catch (StorageException e) {
if (log.isInfoEnabled()) {
log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
}
} catch (StorageException e) {
log.error("TestDataProvider - [addTestSkills]: Exception caught: {}", e.getMessage());
}
}
}
}

protected void addTestEmployees() {
try {
protected void addTestEmployees() {
try {
for (Employee testEmployee : TEST_EMPLOYEES) {
employeeDao.merge(testEmployee);
}
if (log.isInfoEnabled()) {
log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
}
} catch (StorageException e) {
if (log.isInfoEnabled()) {
log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
}
} catch (StorageException e) {
log.error("TestDataProvider - [addTestEmployees]: Exception caught: {}", e.getMessage());
}
}
}
}

protected void addTestData() {
addTestSkills();
addTestEmployees();
}
protected void addTestData() {
addTestSkills();
addTestEmployees();
}

@Override
public void afterPropertiesSet() throws Exception {
addTestData();
}
@Override
public void afterPropertiesSet() throws Exception {
addTestData();
}

}
12 changes: 6 additions & 6 deletions core/src/main/java/com/opensymphony/xwork2/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public interface Action {
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success";
String SUCCESS = "success";

/**
* The action execution was successful but do not
* show a view. This is useful for actions that are
* handling the view in another fashion like redirect.
*/
public static final String NONE = "none";
String NONE = "none";

/**
* The action execution was a failure.
* Show an error view, possibly asking the
* user to retry entering data.
*/
public static final String ERROR = "error";
String ERROR = "error";

/**
* <p>
Expand All @@ -64,14 +64,14 @@ public interface Action {
* should try providing input again.
* </p>
*/
public static final String INPUT = "input";
String INPUT = "input";

/**
* The action could not execute, since the
* user most was not logged in. The login view
* should be shown.
*/
public static final String LOGIN = "login";
String LOGIN = "login";


/**
Expand All @@ -83,6 +83,6 @@ public interface Action {
* <b>Note:</b> Application level exceptions should be handled by returning
* an error value, such as <code>Action.ERROR</code>.
*/
public String execute() throws Exception;
String execute() throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -259,7 +258,7 @@ public int hashCode() {
private boolean isInChainHistory(String namespace, String actionName, String methodName) {
LinkedList<? extends String> chainHistory = ActionChainResult.getChainHistory();
Set<String> skipActionsList = new HashSet<>();
if (skipActions != null && skipActions.length() > 0) {
if (skipActions != null && !skipActions.isEmpty()) {
String finalSkipActions = translateVariables(skipActions);
skipActionsList.addAll(TextParseUtil.commaDelimitedStringToSet(finalSkipActions));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
*/
public interface ActionEventListener {
/**
* Called after an action has been created.
*
* Called after an action has been created.
*
* @param action The action
* @param stack The current value stack
* @return The action to use
*/
public Object prepare(Object action, ValueStack stack);
Object prepare(Object action, ValueStack stack);

/**
* Called when an exception is thrown by the action
*
*
* @param t The exception/error that was thrown
* @param stack The current value stack
* @return A result code to execute, can be null
*/
public String handleException(Throwable t, ValueStack stack);
String handleException(Throwable t, ValueStack stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;

/**
* This is a composite {@link TextProvider} that takes in an array or {@link java.util.List} of {@link TextProvider}s, it will
Expand All @@ -35,7 +39,7 @@ public class CompositeTextProvider implements TextProvider {

private static final Logger LOG = LogManager.getLogger(CompositeTextProvider.class);

private List<TextProvider> textProviders = new ArrayList<>();
private final List<TextProvider> textProviders = new ArrayList<>();

/**
* Instantiates a {@link CompositeTextProvider} with some predefined <code>textProviders</code>.
Expand Down Expand Up @@ -64,6 +68,7 @@ public CompositeTextProvider(TextProvider[] textProviders) {
* @see com.opensymphony.xwork2.TextProvider#hasKey(String)
*
*/
@Override
public boolean hasKey(String key) {
// if there's a key in either text providers we are ok, else try the next text provider
for (TextProvider tp : textProviders) {
Expand All @@ -82,6 +87,7 @@ public boolean hasKey(String key) {
* @return The i18n text for the requested key.
* @see com.opensymphony.xwork2.TextProvider#getText(String)
*/
@Override
public String getText(String key) {
return getText(key, key, Collections.emptyList());
}
Expand All @@ -95,6 +101,7 @@ public String getText(String key) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String)
*/
@Override
public String getText(String key, String defaultValue) {
return getText(key, defaultValue, Collections.emptyList());
}
Expand All @@ -110,12 +117,9 @@ public String getText(String key, String defaultValue) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, String)
*/
@Override
public String getText(String key, String defaultValue, final String obj) {
return getText(key, defaultValue, new ArrayList<Object>() {
{
add(obj);
}
});
return getText(key, defaultValue, List.of(obj));
}

/**
Expand All @@ -127,6 +131,7 @@ public String getText(String key, String defaultValue, final String obj) {
* @return the first valid message for the key
* @see com.opensymphony.xwork2.TextProvider#getText(String, java.util.List)
*/
@Override
public String getText(String key, List<?> args) {
return getText(key, key, args);
}
Expand All @@ -140,6 +145,7 @@ public String getText(String key, List<?> args) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String[])
*/
@Override
public String getText(String key, String[] args) {
return getText(key, key, args);
}
Expand All @@ -155,6 +161,7 @@ public String getText(String key, String[] args) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, java.util.List)
*/
@Override
public String getText(String key, String defaultValue, List<?> args) {
// if there's one text provider that gives us a msg not the same as defaultValue
// for this key, we are ok, else try the next
Expand All @@ -179,6 +186,7 @@ public String getText(String key, String defaultValue, List<?> args) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, String[])
*/
@Override
public String getText(String key, String defaultValue, String[] args) {
// if there's one text provider that gives us a msg not the same as defaultValue
// for this key, we are ok, else try the next
Expand All @@ -204,6 +212,7 @@ public String getText(String key, String defaultValue, String[] args) {
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, java.util.List, com.opensymphony.xwork2.util.ValueStack)
*/
@Override
public String getText(String key, String defaultValue, List<?> args, ValueStack stack) {
// if there's one text provider that gives us a msg not the same as defaultValue
// for this key, we are ok, else try the next
Expand All @@ -228,6 +237,7 @@ public String getText(String key, String defaultValue, List<?> args, ValueStack
* @return the first valid message for the key or default value
* @see com.opensymphony.xwork2.TextProvider#getText(String, String, String[], com.opensymphony.xwork2.util.ValueStack)
*/
@Override
public String getText(String key, String defaultValue, String[] args, ValueStack stack) {
// if there's one text provider that gives us a msg not the same as defaultValue
// for this key, we are ok, else try the next
Expand All @@ -249,6 +259,7 @@ public String getText(String key, String defaultValue, String[] args, ValueStack
* @return the resource bundle found for bundle name
* @see TextProvider#getTexts(String)
*/
@Override
public ResourceBundle getTexts(String bundleName) {
// if there's one text provider that gives us a non-null resource bundle for this bundleName, we are ok, else try the next
// text provider
Expand All @@ -267,6 +278,7 @@ public ResourceBundle getTexts(String bundleName) {
* @return the resource bundle
* @see TextProvider#getTexts()
*/
@Override
public ResourceBundle getTexts() {
// if there's one text provider that gives us a non-null resource bundle, we are ok, else try the next
// text provider
Expand Down
Loading

0 comments on commit 35d9c0b

Please sign in to comment.