Code with Finding: |
class ActionBuilderImpl {
@SuppressWarnings("unchecked")
public String buildAction(final ManagerAction action, final String internalActionId)
{
StringBuffer sb = new StringBuffer();
sb.append("action: ");
sb.append(action.getAction());
sb.append(LINE_SEPARATOR);
if (internalActionId != null)
{
sb.append("actionid: ");
sb.append(ManagerUtil.addInternalActionId(action.getActionId(), internalActionId));
sb.append(LINE_SEPARATOR);
}
else if (action.getActionId() != null)
{
sb.append("actionid: ");
sb.append(action.getActionId());
sb.append(LINE_SEPARATOR);
}
/*
* When using the Reflection API to get all of the getters for building
* actions to send, we ignore some of the getters
*/
Set<String> ignore = new HashSet<String>();
ignore.add("class");
ignore.add("action");
ignore.add("actionid");
ignore.add(ATTRIBUTES_PROPERTY_NAME);
// if this is a user event action, we need to grab the internal event,
// otherwise do below as normal
if (action instanceof UserEventAction)
{
UserEvent userEvent = ((UserEventAction) action).getUserEvent();
appendUserEvent(sb, userEvent);
// eventually we may want to add more Map keys for events to ignore
// when appending
appendGetters(sb, userEvent, ignore);
}
else
{
appendGetters(sb, action, ignore);
}
// actions that have the special getAttributes method will
// have their Map appended without a singular key or separator
Map<String, Method> getters = ReflectionUtil.getGetters(action.getClass());
if(getters.containsKey(ATTRIBUTES_PROPERTY_NAME))
{
Method getter = getters.get(ATTRIBUTES_PROPERTY_NAME);
Object value = null;
try
{
value = getter.invoke(action);
}
catch (Exception ex)
{
logger.error("Unable to retrieve property '" + ATTRIBUTES_PROPERTY_NAME + "' of " + action.getClass(), ex);
}
if(value instanceof Map)
{
Map<Object,Object> attributes = (Map<Object, Object>)value;
for (Map.Entry<Object, Object> entry : attributes.entrySet())
{
appendString(sb, entry.getKey() == null ? "null" : entry.getKey().toString(),
entry.getValue() == null ? "null" : entry.getValue().toString());
}
}
}
sb.append(LINE_SEPARATOR);
return sb.toString();
}
}
|