Commits

Rafael Goncalves committed 505f479

Big Code cleanup.

Comments (0)

Files changed (157)

     <build>
         <plugins>
             <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>tomcat-maven-plugin</artifactId>
+                <version>1.1</version>
+                <configuration>
+                    <path>/VisionDataset</path>
+                    <password>tomcat123</password>
+                    <username>tomcat</username>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>org.mortbay.jetty</groupId>
                 <artifactId>maven-jetty-plugin</artifactId>
                 <version>6.1.21</version>
                 <configuration>
                     <scanIntervalSeconds>10</scanIntervalSeconds>
+                    <contextPath>/VisionDataset</contextPath>
                 </configuration>
             </plugin>
         </plugins>
     	<url>www.ime.usp.br</url>
     </organization>
     <url>http://www.vision.ime.usp.br/VisionDataset/</url>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>findbugs-maven-plugin</artifactId>
+                <version>2.3.3-SNAPSHOT</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <version>2.6</version>
+                <configuration>
+                    <configLocation>config/avalon_checks.xml</configLocation>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
 </project>

src/main/java/br/usp/ime/vision/dataset/actions/AbstractAction.java

  * 
  * @author Bruno Klava
  */
-public class AbstractAction extends ActionSupport
-		implements
-			SessionAware,
-			ServletRequestAware {
+public class AbstractAction extends ActionSupport implements SessionAware,
+        ServletRequestAware {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+    public static String USER_SESSION_PARAMETER = "user";
+    protected static final String UNAUTHORIZED_ACTION = "unauthorizedAction";
+    protected static final String INVALID_REQUEST = "invalidRequest";
+    private Map<String, Object> session;
+    private HttpServletRequest servletRequest;
 
-	public static String USER_SESSION_PARAMETER = "user";
+    // private String getLink(String actionURL) {
+    // String url = getServletRequest().getRequestURL().toString();
+    // url = url.substring(0,
+    // url.lastIndexOf(getServletRequest().getServletPath()));
+    // url += actionURL;
+    // return url;
+    // }
+    public String cancel() {
+        return "cancel";
+    }
 
-	protected static final String UNAUTHORIZED_ACTION = "unauthorizedAction";
+    protected String getLinkAction(final String action, final User user) {
+        // String actionURL = "/" + action + "?username=" + user.getUsername()
+        // + "&code=" + user.getConfirmationCode();
+        // return getLink(actionURL);
+        final String actionURL = action + "?username=" + user.getUsername()
+                + "&code=" + user.getConfirmationCode();
+        return Configs.getServerURL() + actionURL;
+    }
 
-	protected static final String INVALID_REQUEST = "invalidRequest";
+    private String getLinkConfirmation(final User user) {
+        return getLinkAction("ConfirmEmail", user);
+    }
 
-	private Map<String, Object> session;
+    public User getLoggedUser() {
+        return (User) getSession().get(USER_SESSION_PARAMETER);
+    }
 
-	private HttpServletRequest servletRequest;
- 
-	public void setSession(Map<String, Object> session) {
-		this.session = session;
-	}
+    public HttpServletRequest getServletRequest() {
+        return servletRequest;
+    }
 
-	public Map<String, Object> getSession() {
-		return session;
-	}
+    public Map<String, Object> getSession() {
+        return session;
+    }
 
-	public void setServletRequest(HttpServletRequest servletRequest) {
-		this.servletRequest = servletRequest;
-	}
+    public boolean isLoggedUserAdmin() {
+        final User user = getLoggedUser();
+        if (user == null) {
+            return false;
+        }
+        return user.isAdmin();
+    }
 
-	public HttpServletRequest getServletRequest() {
-		return servletRequest;
-	}
+    protected boolean sendConfirmationEmail(final User user) {
+        final String subject = Messages.getMessage("emailConfirmation.subject");
+        final String message = Messages.getMessage("emailConfirmation.message",
+                getLinkConfirmation(user));
 
-	public User getLoggedUser() {
-		return (User) getSession().get(USER_SESSION_PARAMETER);
-	}
+        return Email.sendEmail(user.getEmail(), subject, message);
+    }
 
-	public boolean isLoggedUserAdmin() {
-		User user = getLoggedUser();
-		if (user == null) {
-			return false;
-		}
-		return user.isAdmin();
-	}
+    public void setServletRequest(final HttpServletRequest servletRequest) {
+        this.servletRequest = servletRequest;
+    }
 
-	protected boolean sendConfirmationEmail(User user) {
-		String subject = Messages.getMessage("emailConfirmation.subject");
-		String message = Messages.getMessage("emailConfirmation.message",
-				getLinkConfirmation(user));
-
-		return Email.sendEmail(user.getEmail(), subject, message);
-	}
-
-	private String getLinkConfirmation(User user) {
-		return getLinkAction("ConfirmEmail", user);
-	}
-
-	protected String getLinkAction(String action, User user) {
-		// String actionURL = "/" + action + "?username=" + user.getUsername()
-		// + "&code=" + user.getConfirmationCode();
-		// return getLink(actionURL);
-		String actionURL = action + "?username=" + user.getUsername()
-				+ "&code=" + user.getConfirmationCode();
-		return Configs.getServerURL() + actionURL;
-	}
-
-	// private String getLink(String actionURL) {
-	// String url = getServletRequest().getRequestURL().toString();
-	// url = url.substring(0,
-	// url.lastIndexOf(getServletRequest().getServletPath()));
-	// url += actionURL;
-	// return url;
-	// }
-
-	public String cancel() {
-		return "cancel";
-	}
-
+    public void setSession(final Map<String, Object> session) {
+        this.session = session;
+    }
 }

src/main/java/br/usp/ime/vision/dataset/actions/InvalidRequest.java

  */
 public class InvalidRequest extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	@Override
-	public String execute() throws Exception {
-		addActionError(Messages.getMessage("invalidRequest"));
-		return SUCCESS;
-	}
+    @Override
+    public String execute() throws Exception {
+        addActionError(Messages.getMessage("invalidRequest"));
+        return SUCCESS;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/UnauthorizedAction.java

  */
 public class UnauthorizedAction extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	@Override
-	public String execute() throws Exception {
-		addActionError(Messages.getMessage("unauthorizedAction"));
-		return SUCCESS;
-	}
+    @Override
+    public String execute() throws Exception {
+        addActionError(Messages.getMessage("unauthorizedAction"));
+        return SUCCESS;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/admin/AuthorizeAccount.java

  */
 public class AuthorizeAccount extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private String username;
+    private String username;
 
-	public String getUsername() {
-		return username;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUsername(String username) {
-		this.username = username;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        if (DAOFactory.getUserDao().authorizeAccount(getUsername())) {
+            addActionMessage(Messages.getMessage("success.authorize.account",
+                    getUsername()));
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+            final User user = DAOFactory.getUserDao().getUserByUsername(
+                    getUsername());
+            Email.sendEmail(user.getEmail(),
+                    Messages.getMessage("emailAccountAuthorized.subject"),
+                    Messages.getMessage("emailAccountAuthorized.message"));
 
-		if (DAOFactory.getUserDao().authorizeAccount(getUsername())) {
-			addActionMessage(Messages.getMessage("success.authorize.account",
-					getUsername()));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.authorize.account",
+                    getUsername()));
+            return ERROR;
+        }
+    }
 
-			User user = DAOFactory.getUserDao()
-					.getUserByUsername(getUsername());
-			Email.sendEmail(user.getEmail(),
-					Messages.getMessage("emailAccountAuthorized.subject"),
-					Messages.getMessage("emailAccountAuthorized.message"));
+    public String getUsername() {
+        return username;
+    }
 
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.authorize.account",
-					getUsername()));
-			return ERROR;
-		}
-	}
+    public void setUsername(final String username) {
+        this.username = username;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/admin/ChangeUserActiveStatus.java

  */
 public class ChangeUserActiveStatus extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int userId;
+    private int userId;
 
-	private boolean active;
+    private boolean active;
 
-	public int getUserId() {
-		return userId;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUserId(int userId) {
-		this.userId = userId;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	public boolean isActive() {
-		return active;
-	}
+        if (DAOFactory.getUserDao().changeUserActiveStatus(getUserId(),
+                isActive())) {
+            if (isActive()) {
+                addActionMessage(Messages
+                        .getMessage("success.activate.account"));
+            } else {
+                addActionMessage(Messages
+                        .getMessage("success.deactivate.account"));
+            }
+            return SUCCESS;
+        } else {
+            if (isActive()) {
+                addActionError(Messages.getMessage("error.activate.account"));
+            } else {
+                addActionError(Messages.getMessage("error.deactivate.account"));
+            }
+            return ERROR;
+        }
+    }
 
-	public void setActive(boolean active) {
-		this.active = active;
-	}
+    public int getUserId() {
+        return userId;
+    }
 
-	@Override
-	public String execute() throws Exception {
+    public boolean isActive() {
+        return active;
+    }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public void setActive(final boolean active) {
+        this.active = active;
+    }
 
-		if (DAOFactory.getUserDao().changeUserActiveStatus(getUserId(),
-				isActive())) {
-			if (isActive()) {
-				addActionMessage(Messages
-						.getMessage("success.activate.account"));
-			} else {
-				addActionMessage(Messages
-						.getMessage("success.deactivate.account"));
-			}
-			return SUCCESS;
-		} else {
-			if (isActive()) {
-				addActionError(Messages.getMessage("error.activate.account"));
-			} else {
-				addActionError(Messages.getMessage("error.deactivate.account"));
-			}
-			return ERROR;
-		}
-	}
+    public void setUserId(final int userId) {
+        this.userId = userId;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/admin/ListUsers.java

  */
 public class ListUsers extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private List<User> users;
+    private List<User> users;
 
-	public List<User> getUsers() {
-		return users;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUsers(List<User> users) {
-		this.users = users;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        setUsers(DAOFactory.getUserDao().listUsers());
+        return SUCCESS;
+    }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public List<User> getUsers() {
+        return users;
+    }
 
-		setUsers(DAOFactory.getUserDao().listUsers());
-		return SUCCESS;
-	}
+    public void setUsers(final List<User> users) {
+        this.users = users;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/admin/RemoveUser.java

  */
 public class RemoveUser extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private String username;
+    private String username;
 
-	public String getUsername() {
-		return username;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUsername(String username) {
-		this.username = username;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        if (DAOFactory.getUserDao().removeUser(getUsername())) {
+            addActionMessage(Messages.getMessage("success.remove.user",
+                    getUsername()));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.remove.user",
+                    getUsername()));
+            return ERROR;
+        }
+    }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public String getUsername() {
+        return username;
+    }
 
-		if (DAOFactory.getUserDao().removeUser(getUsername())) {
-			addActionMessage(Messages.getMessage("success.remove.user",
-					getUsername()));
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.remove.user",
-					getUsername()));
-			return ERROR;
-		}
-	}
+    public void setUsername(final String username) {
+        this.username = username;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/admin/SetUserPermission.java

  */
 public class SetUserPermission extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private String username;
+    private String username;
 
-	private int permission;
+    private int permission;
 
-	public String getUsername() {
-		return username;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUsername(String username) {
-		this.username = username;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	public int getPermission() {
-		return permission;
-	}
+        if (DAOFactory.getUserDao().setPermission(getUsername(),
+                getPermission())) {
+            addActionMessage(Messages.getMessage("success.permission.user",
+                    User.getPermissionString(getPermission()), getUsername()));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.permission.user",
+                    User.getPermissionString(getPermission()), getUsername()));
+            return ERROR;
+        }
+    }
 
-	public void setPermission(int permission) {
-		this.permission = permission;
-	}
+    public int getPermission() {
+        return permission;
+    }
 
-	@Override
-	public String execute() throws Exception {
+    public String getUsername() {
+        return username;
+    }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public void setPermission(final int permission) {
+        this.permission = permission;
+    }
 
-		if (DAOFactory.getUserDao().setPermission(getUsername(),
-				getPermission())) {
-			addActionMessage(Messages.getMessage("success.permission.user",
-					User.getPermissionString(getPermission()), getUsername()));
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.permission.user",
-					User.getPermissionString(getPermission()), getUsername()));
-			return ERROR;
-		}
-	}
+    public void setUsername(final String username) {
+        this.username = username;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/AlbumAction.java

  */
 public abstract class AlbumAction extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int albumId;
+    private int albumId;
 
-	protected Album album;
+    protected Album album;
 
-	public int getAlbumId() {
-		return albumId;
-	}
+    public Album getAlbum() {
+        if (album == null) {
+            album = DAOFactory.getAlbumDao().getAlbum(getAlbumId());
+        }
+        return album;
+    }
 
-	public void setAlbumId(int albumId) {
-		this.albumId = albumId;
-	}
+    public int getAlbumId() {
+        return albumId;
+    }
 
-	public Album getAlbum() {
-		if (album == null) {
-			album = DAOFactory.getAlbumDao().getAlbum(getAlbumId());
-		}
-		return album;
-	}
+    /**
+     * Verifies if the logged {@link User} has create permission on the selected
+     * {@link Album}.
+     * 
+     * @return <code>true</code> if the logged {@link User} has create
+     *         permission on the selected {@link Album}
+     */
+    public boolean isUserHasCreatePermission() {
 
-	/**
-	 * Verifies if the logged {@link User} has view permission on the selected
-	 * {@link Album}.
-	 * 
-	 * @return <code>true</code> if the logged {@link User} has view permission
-	 *         on the selected {@link Album}
-	 */
-	public boolean isUserHasViewPermission() {
+        if (isLoggedUserAdmin()) {
+            return true;
+        }
 
-		if (isLoggedUserAdmin()) {
-			return true;
-		}
+        final User user = getLoggedUser();
 
-		if (getAlbum().isPublicView()) {
-			return true;
-		}
+        if (user == null) {
+            return false;
+        }
 
-		User user = getLoggedUser();
+        if (getAlbum().isUsersCreate()) {
+            return true;
+        }
 
-		if (user == null) {
-			return false;
-		}
+        if (getAlbum().isRestrictedCreate()
+                && DAOFactory.getAlbumDao().userHasPermissionOnAlbum(
+                        getAlbum().getRootAlbum().getId(), user.getId())) {
+            return true;
+        }
 
-		if (getAlbum().isUsersView()) {
-			return true;
-		}
+        return false;
 
-		if (getAlbum().isRestrictedView()
-				&& DAOFactory.getAlbumDao().userHasPermissionOnAlbum(
-						getAlbum().getRootAlbum().getId(), user.getId())) {
-			return true;
-		}
+    }
 
-		return false;
+    /**
+     * Verifies if the logged {@link User} has view permission on the selected
+     * {@link Album}.
+     * 
+     * @return <code>true</code> if the logged {@link User} has view permission
+     *         on the selected {@link Album}
+     */
+    public boolean isUserHasViewPermission() {
 
-	}
+        if (isLoggedUserAdmin()) {
+            return true;
+        }
 
-	/**
-	 * Verifies if the logged {@link User} has create permission on the selected
-	 * {@link Album}.
-	 * 
-	 * @return <code>true</code> if the logged {@link User} has create
-	 *         permission on the selected {@link Album}
-	 */
-	public boolean isUserHasCreatePermission() {
+        if (getAlbum().isPublicView()) {
+            return true;
+        }
 
-		if (isLoggedUserAdmin()) {
-			return true;
-		}
+        final User user = getLoggedUser();
 
-		User user = getLoggedUser();
+        if (user == null) {
+            return false;
+        }
 
-		if (user == null) {
-			return false;
-		}
+        if (getAlbum().isUsersView()) {
+            return true;
+        }
 
-		if (getAlbum().isUsersCreate()) {
-			return true;
-		}
+        if (getAlbum().isRestrictedView()
+                && DAOFactory.getAlbumDao().userHasPermissionOnAlbum(
+                        getAlbum().getRootAlbum().getId(), user.getId())) {
+            return true;
+        }
 
-		if (getAlbum().isRestrictedCreate()
-				&& DAOFactory.getAlbumDao().userHasPermissionOnAlbum(
-						getAlbum().getRootAlbum().getId(), user.getId())) {
-			return true;
-		}
+        return false;
 
-		return false;
+    }
 
-	}
+    public void setAlbumId(final int albumId) {
+        this.albumId = albumId;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/AlbumDetail.java

  */
 public class AlbumDetail extends AlbumAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	@Override
-	public String execute() throws Exception {
+    @Override
+    public String execute() throws Exception {
 
-		if (getAlbum() == null) {
-			return INVALID_REQUEST;
-		}
+        if (getAlbum() == null) {
+            return INVALID_REQUEST;
+        }
 
-		if (!isUserHasViewPermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+        if (!isUserHasViewPermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-		return SUCCESS;
+        return SUCCESS;
 
-	}
+    }
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/AlbumPermissions.java

  */
 public class AlbumPermissions extends AbstractAction {
 
-	private static final long serialVersionUID = 1L;
+    public class Permission {
 
-	public List<Permission> getAlbumViewPermissions() {
-		List<Permission> permissions = new ArrayList<Permission>();
-		permissions.add(new Permission(Constants.ALBUM_PUBLIC_VIEW, Messages
-				.getMessage("album.permission.view.public")));
-		permissions.add(new Permission(Constants.ALBUM_USERS_VIEW, Messages
-				.getMessage("album.permission.view.users")));
-		permissions.add(new Permission(Constants.ALBUM_PRIVATE_VIEW, Messages
-				.getMessage("album.permission.view.private")));
-		return permissions;
-	}
+        private int key;
 
-	public List<Permission> getAlbumCreatePermissions() {
-		List<Permission> permissions = new ArrayList<Permission>();
-		permissions.add(new Permission(Constants.ALBUM_USERS_CREATE, Messages
-				.getMessage("album.permission.create.users")));
-		permissions.add(new Permission(Constants.ALBUM_PRIVATE_CREATE, Messages
-				.getMessage("album.permission.create.private")));
-		return permissions;
-	}
+        private String value;
 
-	public class Permission {
+        public Permission(final int key, final String value) {
+            this.key = key;
+            this.value = value;
+        }
 
-		private int key;
+        public int getKey() {
+            return key;
+        }
 
-		private String value;
+        public String getValue() {
+            return value;
+        }
 
-		public Permission(int key, String value) {
-			this.key = key;
-			this.value = value;
-		}
+        public void setKey(final int key) {
+            this.key = key;
+        }
 
-		public int getKey() {
-			return key;
-		}
+        public void setValue(final String value) {
+            this.value = value;
+        }
 
-		public void setKey(int key) {
-			this.key = key;
-		}
+    }
 
-		public String getValue() {
-			return value;
-		}
+    private static final long serialVersionUID = 1L;
 
-		public void setValue(String value) {
-			this.value = value;
-		}
+    public List<Permission> getAlbumCreatePermissions() {
+        final List<Permission> permissions = new ArrayList<Permission>();
+        permissions.add(new Permission(Constants.ALBUM_USERS_CREATE, Messages
+                .getMessage("album.permission.create.users")));
+        permissions.add(new Permission(Constants.ALBUM_PRIVATE_CREATE, Messages
+                .getMessage("album.permission.create.private")));
+        return permissions;
+    }
 
-	}
+    public List<Permission> getAlbumViewPermissions() {
+        final List<Permission> permissions = new ArrayList<Permission>();
+        permissions.add(new Permission(Constants.ALBUM_PUBLIC_VIEW, Messages
+                .getMessage("album.permission.view.public")));
+        permissions.add(new Permission(Constants.ALBUM_USERS_VIEW, Messages
+                .getMessage("album.permission.view.users")));
+        permissions.add(new Permission(Constants.ALBUM_PRIVATE_VIEW, Messages
+                .getMessage("album.permission.view.private")));
+        return permissions;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/ChangeAlbumOwner.java

  */
 public class ChangeAlbumOwner extends AlbumAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int userId;
+    private int userId;
 
-	private List<User> users;
+    private List<User> users;
 
-	public int getUserId() {
-		return userId;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setUserId(int userId) {
-		this.userId = userId;
-	}
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	public List<User> getUsers() {
-		return users;
-	}
+        if (DAOFactory.getAlbumDao()
+                .changeAlbumOwner(getAlbumId(), getUserId())) {
+            addActionMessage(Messages.getMessage("success.change.owner"));
+            return SUCCESS;
 
-	public void setUsers(List<User> users) {
-		this.users = users;
-	}
+        } else {
+            addActionError(Messages.getMessage("error.change.owner"));
+            return INPUT;
+        }
 
-	public String populateUsers() throws Exception {
+    }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public int getUserId() {
+        return userId;
+    }
 
-		setUsers(DAOFactory.getUserDao().listUsers());
+    public List<User> getUsers() {
+        return users;
+    }
 
-		return SUCCESS;
-	}
+    public String populateUsers() throws Exception {
 
-	@Override
-	public String execute() throws Exception {
+        if (!isLoggedUserAdmin()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-		if (!isLoggedUserAdmin()) {
-			return UNAUTHORIZED_ACTION;
-		}
+        setUsers(DAOFactory.getUserDao().listUsers());
 
-		if (DAOFactory.getAlbumDao()
-				.changeAlbumOwner(getAlbumId(), getUserId())) {
-			addActionMessage(Messages.getMessage("success.change.owner"));
-			return SUCCESS;
+        return SUCCESS;
+    }
 
-		} else {
-			addActionError(Messages.getMessage("error.change.owner"));
-			return INPUT;
-		}
+    public void setUserId(final int userId) {
+        this.userId = userId;
+    }
 
-	}
+    public void setUsers(final List<User> users) {
+        this.users = users;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/CreateAlbum.java

  */
 public class CreateAlbum extends CreateAlbumData {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private Album album;
+    private Album album;
 
-	private String idsUsersPermission;
+    private String idsUsersPermission;
 
-	public Album getAlbum() {
-		return album;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setAlbum(Album album) {
-		this.album = album;
-	}
+        final User user = getLoggedUser();
 
-	public String getIdsUsersPermission() {
-		return idsUsersPermission;
-	}
+        if ((user == null) || !user.isCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	public void setIdsUsersPermission(String idsUsersPermission) {
-		this.idsUsersPermission = idsUsersPermission;
-	}
+        getAlbum().setOwnerId(user.getId());
 
-	@Override
-	public String execute() throws Exception {
+        final int albumId = DAOFactory.getAlbumDao().createAlbum(getAlbum());
 
-		User user = getLoggedUser();
+        boolean success = false;
 
-		if (user == null || !user.isCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+        if (albumId != 0) {
 
-		getAlbum().setOwnerId(user.getId());
+            success = true;
 
-		int albumId = DAOFactory.getAlbumDao().createAlbum(getAlbum());
+            int[] intIds;
+            if (!StringUtils.isEmpty(idsUsersPermission)) {
+                final String[] stringIds = idsUsersPermission.split(",");
+                intIds = new int[stringIds.length];
+                int i = 0;
+                for (final String s : stringIds) {
+                    intIds[i++] = Integer.parseInt(s);
+                }
+            } else {
+                intIds = new int[0];
+            }
 
-		boolean success = false;
+            for (final int idUser : intIds) {
+                if (!DAOFactory.getAlbumDao().addRestrictedPermission(albumId,
+                        idUser)) {
+                    success = false;
+                    break;
+                }
+            }
 
-		if (albumId != 0) {
+        }
 
-			success = true;
+        if (success) {
+            addActionMessage(Messages.getMessage("success.create.album",
+                    getAlbum().getName()));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.create.album", getAlbum()
+                    .getName()));
+            return INPUT;
+        }
 
-			int[] intIds;
-			if (!StringUtils.isEmpty(idsUsersPermission)) {
-				String[] stringIds = idsUsersPermission.split(",");
-				intIds = new int[stringIds.length];
-				int i = 0;
-				for (String s : stringIds) {
-					intIds[i++] = Integer.parseInt(s);
-				}
-			} else {
-				intIds = new int[0];
-			}
+    }
 
-			for (int idUser : intIds) {
-				if (!DAOFactory.getAlbumDao().addRestrictedPermission(albumId,
-						idUser)) {
-					success = false;
-					break;
-				}
-			}
+    public Album getAlbum() {
+        return album;
+    }
 
-		}
+    public String getIdsUsersPermission() {
+        return idsUsersPermission;
+    }
 
-		if (success) {
-			addActionMessage(Messages.getMessage("success.create.album",
-					getAlbum().getName()));
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.create.album", getAlbum()
-					.getName()));
-			return INPUT;
-		}
+    public void setAlbum(final Album album) {
+        this.album = album;
+    }
 
-	}
+    public void setIdsUsersPermission(final String idsUsersPermission) {
+        this.idsUsersPermission = idsUsersPermission;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/CreateAlbumData.java

  */
 public class CreateAlbumData extends AlbumPermissions {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private List<User> users;
+    private List<User> users;
 
-	public List<User> getUsers() {
-		if (users == null) {
-			users = DAOFactory.getUserDao().listUsersExcept(
-					getLoggedUser().getId());
-		}
-		return users;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	@Override
-	public String execute() throws Exception {
+        final User user = getLoggedUser();
 
-		User user = getLoggedUser();
+        if ((user == null) || !user.isCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-		if (user == null || !user.isCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+        return SUCCESS;
 
-		return SUCCESS;
+    }
 
-	}
+    public List<User> getUsers() {
+        if (users == null) {
+            users = DAOFactory.getUserDao().listUsersExcept(
+                    getLoggedUser().getId());
+        }
+        return users;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/CreateSubAlbum.java

  */
 public class CreateSubAlbum extends CreateSubAlbumData {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private String albumName;
+    private String albumName;
 
-	public String getAlbumName() {
-		return albumName;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setAlbumName(String albumName) {
-		this.albumName = albumName;
-	}
+        if (!isUserHasCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        final SubAlbum album = new SubAlbum();
+        album.setName(getAlbumName());
+        album.setOwnerId(getLoggedUser().getId());
+        album.setParentId(getParentId());
 
-		if (!isUserHasCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+        final int albumId = DAOFactory.getAlbumDao().createAlbum(album);
 
-		SubAlbum album = new SubAlbum();
-		album.setName(getAlbumName());
-		album.setOwnerId(getLoggedUser().getId());
-		album.setParentId(getParentId());
+        if (albumId != 0) {
+            addActionMessage(Messages.getMessage("success.create.album",
+                    getAlbumName()));
+            return SUCCESS;
 
-		int albumId = DAOFactory.getAlbumDao().createAlbum(album);
+        } else {
+            addActionError(Messages.getMessage("error.create.album",
+                    getAlbumName()));
+            return INPUT;
+        }
 
-		if (albumId != 0) {
-			addActionMessage(Messages.getMessage("success.create.album",
-					getAlbumName()));
-			return SUCCESS;
+    }
 
-		} else {
-			addActionError(Messages.getMessage("error.create.album",
-					getAlbumName()));
-			return INPUT;
-		}
+    public String getAlbumName() {
+        return albumName;
+    }
 
-	}
+    public void setAlbumName(final String albumName) {
+        this.albumName = albumName;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/CreateSubAlbumData.java

  */
 public class CreateSubAlbumData extends AlbumAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int parentId;
+    private int parentId;
 
-	private Album parent;
+    private Album parent;
 
-	public int getParentId() {
-		return parentId;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setParentId(int parentId) {
-		this.parentId = parentId;
-	}
+        if (!isUserHasCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	public Album getParent() {
-		if (parent == null) {
-			parent = DAOFactory.getAlbumDao().getAlbum(getParentId());
-		}
-		return parent;
-	}
+        return SUCCESS;
 
-	public List<Album> getParents() {
-		return getParent().getAlbumsChain();
-	}
+    }
 
-	@Override
-	public Album getAlbum() {
-		return getParent();
-	}
+    @Override
+    public Album getAlbum() {
+        return getParent();
+    }
 
-	@Override
-	public String execute() throws Exception {
+    public Album getParent() {
+        if (parent == null) {
+            parent = DAOFactory.getAlbumDao().getAlbum(getParentId());
+        }
+        return parent;
+    }
 
-		if (!isUserHasCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public int getParentId() {
+        return parentId;
+    }
 
-		return SUCCESS;
+    public List<Album> getParents() {
+        return getParent().getAlbumsChain();
+    }
 
-	}
+    public void setParentId(final int parentId) {
+        this.parentId = parentId;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/DeleteAlbum.java

  */
 public class DeleteAlbum extends AlbumAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int parentId;
+    private int parentId;
 
-	public int getParentId() {
-		return parentId;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setParentId(int parentId) {
-		this.parentId = parentId;
-	}
+        if (!isUserHasCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        if (getAlbum().deleteAlbum()) {
+            addActionMessage(Messages.getMessage("success.delete.album",
+                    getAlbum().getName()));
 
-		if (!isUserHasCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+            if (getAlbum() instanceof SubAlbum) {
+                final SubAlbum subAlbum = (SubAlbum) getAlbum();
+                setParentId(subAlbum.getParentId());
+                return SUCCESS;
+            } else {
+                return "listAlbums";
+            }
 
-		if (getAlbum().deleteAlbum()) {
-			addActionMessage(Messages.getMessage("success.delete.album",
-					getAlbum().getName()));
+        } else {
+            addActionError(Messages.getMessage("error.delete.album", getAlbum()
+                    .getName()));
+            return ERROR;
+        }
+    }
 
-			if (getAlbum() instanceof SubAlbum) {
-				SubAlbum subAlbum = (SubAlbum) getAlbum();
-				setParentId(subAlbum.getParentId());
-				return SUCCESS;
-			} else {
-				return "listAlbums";
-			}
+    public int getParentId() {
+        return parentId;
+    }
 
-		} else {
-			addActionError(Messages.getMessage("error.delete.album", getAlbum()
-					.getName()));
-			return ERROR;
-		}
-	}
+    public void setParentId(final int parentId) {
+        this.parentId = parentId;
+    }
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/DeleteImage.java

  */
 public class DeleteImage extends AlbumAction {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private int imageId;
+    private int imageId;
 
-	public int getImageId() {
-		return imageId;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setImageId(int imageId) {
-		this.imageId = imageId;
-	}
+        final Album album = DAOFactory.getAlbumDao().getAlbum(getAlbumId());
+        final Image image = DAOFactory.getAlbumDao().getImage(getImageId());
 
-	@Override
-	public String execute() throws Exception {
+        if ((album == null) || (image == null)
+                || (image.getAlbumId() != getAlbumId())) {
+            return INVALID_REQUEST;
+        }
 
-		Album album = DAOFactory.getAlbumDao().getAlbum(getAlbumId());
-		Image image = DAOFactory.getAlbumDao().getImage(getImageId());
+        if (!isUserHasCreatePermission()) {
+            return UNAUTHORIZED_ACTION;
+        }
 
-		if (album == null || image == null
-				|| image.getAlbumId() != getAlbumId()) {
-			return INVALID_REQUEST;
-		}
+        if (image.deleteImage()) {
+            addActionMessage(Messages.getMessage("success.delete.image",
+                    getImageId()));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.delete.image",
+                    getImageId()));
+            return ERROR;
+        }
+    }
 
-		if (!isUserHasCreatePermission()) {
-			return UNAUTHORIZED_ACTION;
-		}
+    public int getImageId() {
+        return imageId;
+    }
 
-		if (image.deleteImage()) {
-			addActionMessage(Messages.getMessage("success.delete.image",
-					getImageId()));
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.delete.image",
-					getImageId()));
-			return ERROR;
-		}
-	}
+    public void setImageId(final int imageId) {
+        this.imageId = imageId;
+    }
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/EditAlbumPermissions.java

  */
 public class EditAlbumPermissions extends AlbumPermissions {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private static final Logger logger = LoggerFactory
-			.getLogger(EditAlbumPermissions.class);
+    private static final Logger logger = LoggerFactory
+            .getLogger(EditAlbumPermissions.class);
 
-	private Album album;
+    private Album album;
 
-	private String idsUsersPermission;
+    private String idsUsersPermission;
 
-	public Album getAlbum() {
-		return album;
-	}
+    @Override
+    public String execute() throws Exception {
 
-	public void setAlbum(Album album) {
-		this.album = album;
-	}
+        final User user = getLoggedUser();
 
-	public String getIdsUsersPermission() {
-		return idsUsersPermission;
-	}
+        final Album album = DAOFactory.getAlbumDao().getAlbum(
+                getAlbum().getId());
 
-	public void setIdsUsersPermission(String idsUsersPermission) {
-		this.idsUsersPermission = idsUsersPermission;
-	}
+        if ((user == null)
+                || !((album.getOwnerId() == user.getId()) || isLoggedUserAdmin())) {
+            logger.debug("User {} cannot edit permissions on album {}", user,
+                    album);
+            return UNAUTHORIZED_ACTION;
+        }
 
-	@Override
-	public String execute() throws Exception {
+        int[] intIds;
+        if (!StringUtils.isEmpty(idsUsersPermission)) {
+            final String[] stringIds = idsUsersPermission.split(",");
+            intIds = new int[stringIds.length];
+            int i = 0;
+            for (final String s : stringIds) {
+                intIds[i++] = Integer.parseInt(s);
+            }
+        } else {
+            intIds = new int[0];
+        }
 
-		User user = getLoggedUser();
+        boolean success = true;
+        if (DAOFactory.getAlbumDao().setAlbumPermissions(getAlbum().getId(),
+                getAlbum().getViewPermission(),
+                getAlbum().getCreatePermission())) {
+            for (final int idUser : intIds) {
+                if (!DAOFactory.getAlbumDao().addRestrictedPermission(
+                        getAlbum().getId(), idUser)) {
+                    success = false;
+                    break;
+                }
+            }
+        } else {
+            success = false;
+        }
 
-		Album album = DAOFactory.getAlbumDao().getAlbum(getAlbum().getId());
+        if (success) {
+            addActionMessage(Messages.getMessage("success.album.permissions"));
+            return SUCCESS;
+        } else {
+            addActionError(Messages.getMessage("error.album.permissions"));
+            return ERROR;
+        }
 
-		if (user == null
-				|| !(album.getOwnerId() == user.getId() || isLoggedUserAdmin())) {
-			logger.debug("User {} cannot edit permissions on album {}", user,
-					album);
-			return UNAUTHORIZED_ACTION;
-		}
+    }
 
-		int[] intIds;
-		if (!StringUtils.isEmpty(idsUsersPermission)) {
-			String[] stringIds = idsUsersPermission.split(",");
-			intIds = new int[stringIds.length];
-			int i = 0;
-			for (String s : stringIds) {
-				intIds[i++] = Integer.parseInt(s);
-			}
-		} else {
-			intIds = new int[0];
-		}
+    public Album getAlbum() {
+        return album;
+    }
 
-		boolean success = true;
-		if (DAOFactory.getAlbumDao().setAlbumPermissions(getAlbum().getId(),
-				getAlbum().getViewPermission(),
-				getAlbum().getCreatePermission())) {
-			for (int idUser : intIds) {
-				if (!DAOFactory.getAlbumDao().addRestrictedPermission(
-						getAlbum().getId(), idUser)) {
-					success = false;
-					break;
-				}
-			}
-		} else {
-			success = false;
-		}
+    public String getIdsUsersPermission() {
+        return idsUsersPermission;
+    }
 
-		if (success) {
-			addActionMessage(Messages.getMessage("success.album.permissions"));
-			return SUCCESS;
-		} else {
-			addActionError(Messages.getMessage("error.album.permissions"));
-			return ERROR;
-		}
+    public void setAlbum(final Album album) {
+        this.album = album;
+    }
 
-	}
+    public void setIdsUsersPermission(final String idsUsersPermission) {
+        this.idsUsersPermission = idsUsersPermission;
+    }
 
 }

src/main/java/br/usp/ime/vision/dataset/actions/album/EditAlbumPermissionsData.java

 import br.usp.ime.vision.dataset.entities.User;
 
 /**
- * Action to populate the view with necessary data for changing the {@link User}s
- * creation/visualization permissions on an {@link Album}.
+ * Action to populate the view with necessary data for changing the {@link User}
+ * s creation/visualization permissions on an {@link Album}.
  * 
  * @author Bruno Klava
  */
 public class EditAlbumPermissionsData extends AlbumPermissions {