* {@inheritDoc}
*/
@Override
public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext)
{
PostSplitActivityAndCommentsRequest request = (PostSplitActivityAndCommentsRequest) inActionContext
.getActionContext().getParams();
// get the entity whose stream to post to
DomainMapper<Long, String> uniqueIdDAO = uniqueIdDAOs.get(request.getEntityType());
if (uniqueIdDAO == null)
{
throw new ValidationException("Request to post to unsupported stream type " + request.getEntityType());
}
String uniqueId = uniqueIdDAO.execute(request.getEntityId());
// split the text
List<String> pieces = textSplitter.split(request.getText());
if (pieces.isEmpty())
{
throw new ValidationException("Text to post must not be empty.");
}
// post the activity
ActivityDTO activityToPost = new ActivityDTO();
activityToPost.setBaseObjectType(BaseObjectType.NOTE);
activityToPost.setVerb(ActivityVerb.POST);
activityToPost.setDestinationStream(new StreamEntityDTO(request.getEntityType(), uniqueId));
activityToPost.setBaseObjectProperties(new HashMap<String, String>(Collections.singletonMap("content",
pieces.get(0))));
TaskHandlerAction postActivityAction = postActivityActions.get(request.getEntityType());
ActivityDTO postedActivity = (ActivityDTO) executor.execute(postActivityAction, inActionContext,
new PostActivityRequest(activityToPost));
// post the comments
for (String piece : pieces.subList(1, pieces.size()))