Question: public Message createMessage ( Message message, Optional account ) { LOGGER.debug ( Creating message: { } , message ) ; / / Ensure

public Message createMessage(Message message, Optional account){
LOGGER.debug("Creating message: {}", message);
// Ensure that the account exists
if (!account.isPresent()){
LOGGER.error("Account must exist when posting a new message");
throw new IllegalArgumentException("Account must exist when posting a new message");
}
// Validate the message
validateMessage(message);
// Check account permission
checkAccountPermission(account.get(), message.getPosted_by());
// Insert the message into the database
Message createdMessage = messageDAO.insert(message);
LOGGER.info("Created message: {}", createdMessage);
return createdMessage;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!