Skip to content

Commit

Permalink
Merge pull request #736 from caelum/ot-messagesbyseverity
Browse files Browse the repository at this point in the history
Initial support new messages grouped by severity
  • Loading branch information
Turini committed Aug 13, 2014
2 parents e8e9713 + df331cf commit 88a8434
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import com.google.common.collect.ForwardingList;

/**
* Class that represents an error list.
* Class that represents an message list, allowing to use methods
* to groupping message by category.
*
* @author Otávio Scherer Garcia
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/***
* Copyright (c) 2009 Caelum - www.caelum.com.br/opensource All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.caelum.vraptor.validator;

import java.util.ArrayList;
Expand All @@ -8,6 +23,19 @@
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
* Managed class that stores all application messages like errors, warnings and info. This
* class is useful to display messages categorized by severity in your view. To choose a severity
* you can construct your message like this:
*
* <code>
* Message message = new SimpleMessage("name", "An info message", Severity.INFO);
* validation.add(message); // will stored as INFO severity
* </code>
*
* @since 4.1
* @author Otávio S Garcia
*/
@Named
@RequestScoped
public class Messages {
Expand All @@ -21,7 +49,7 @@ public Messages add(Message message) {

private List<Message> get(Severity severity) {
if (!messages.containsKey(severity)) {
messages.put(severity, new MessageList(new ArrayList<Message>()));
messages.put(severity, createMessageList());
}
return messages.get(severity);
}
Expand All @@ -34,7 +62,20 @@ public List<Message> getInfo() {
return get(Severity.INFO);
}

public List<Message> getWarn() {
public List<Message> getWarnings() {
return get(Severity.WARN);
}

public List<Message> getAll() {
List<Message> allMessages = new ArrayList();
allMessages.addAll(get(Severity.ERROR));
allMessages.addAll(get(Severity.WARN));
allMessages.addAll(get(Severity.INFO));

return new MessageList(allMessages);
}

private MessageList createMessageList() {
return new MessageList(new ArrayList<Message>());
}
}

0 comments on commit 88a8434

Please sign in to comment.