Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / UserServiceImpl.java
index f19dea8c366160e96c2fb2ff7ad9e4df16d9ad06..862f30e50709d00718ac42ebc01d4784fe9e7ead 100644 (file)
@@ -47,7 +47,7 @@ public class UserServiceImpl implements UserService {
        /**
         * The service logger.
         */
-       final static Logger logger = Logger.getLogger(UserServiceImpl.class);
+       protected final static Logger LOG = Logger.getLogger(UserServiceImpl.class);
 
        /**
         * Injected user DAO.
@@ -64,7 +64,7 @@ public class UserServiceImpl implements UserService {
         * @see org.splat.service.UserService#createUser(org.splat.dal.bo.kernel.User.Properties)
         */
        @Transactional
-       public User createUser(User.Properties uprop)
+       public User createUser(final User.Properties uprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException, RuntimeException {
                User nuser = new User(uprop);
@@ -74,21 +74,23 @@ public class UserServiceImpl implements UserService {
 
        // For the casting List<String>
        @Transactional
-       public Set<User> importUsers(File xfile) throws XMLException,
+       public Set<User> importUsers(final File xfile) throws XMLException,
                        MismatchException {
                String[] name = xfile.getName().split("\\x2E"); // Split by '.' (period) character
                String fext = name[name.length - 1];
 
-               if (!fext.equals("xml"))
+               if (!fext.equals("xml")) {
                        throw new MismatchException("filetype");
+               }
                try {
                        DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
                                        .newInstance();
                        DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
                        org.w3c.dom.Document inDoc = dBuilder.parse(xfile);
                        String xtag = inDoc.getDocumentElement().getNodeName();
-                       if (!xtag.equals("users"))
+                       if (!xtag.equals("users")) {
                                throw new MismatchException("filetype");
+                       }
                        org.w3c.dom.NodeList ulist = inDoc.getElementsByTagName("user");
 
                        // List<String> result = (List<String>) session
@@ -97,8 +99,9 @@ public class UserServiceImpl implements UserService {
                        List<User> users = getUserDAO().getAll();
                        HashSet<String> members = new HashSet<String>();
                        HashSet<User> imported = new HashSet<User>();
-                       for (Iterator<User> i = users.iterator(); i.hasNext();)
+                       for (Iterator<User> i = users.iterator(); i.hasNext();) {
                                members.add(i.next().getUsername());
+                       }
 
                        for (int i = 0; i < ulist.getLength(); i++) {
                                HashMap<String, Node> row = XDOM.getNamedChildNodes(ulist
@@ -107,8 +110,9 @@ public class UserServiceImpl implements UserService {
 
                                // Mandatory properties
                                String uname = row.get("username").getTextContent();
-                               if (members.contains(uname))
+                               if (members.contains(uname)) {
                                        continue; // This user already exists
+                               }
                                uprop.setUsername(uname)
                                                .setFirstName(row.get("first").getTextContent())
                                                .setName(row.get("last").getTextContent())
@@ -136,11 +140,14 @@ public class UserServiceImpl implements UserService {
                        }
                        return imported;
                } catch (IOException error) {
-                       throw new XMLException("XML users file not found");
+                       LOG.debug(error.getMessage(), error);
+                       throw new XMLException("XML users file not found"); //RKV: NOPMD: Original message is printed
                } catch (ParserConfigurationException e) {
-                       throw new XMLException("XML Organization parser not accessible");
+                       LOG.debug(e.getMessage(), e);
+                       throw new XMLException("XML Organization parser not accessible"); //RKV: NOPMD: Original message is printed
                } catch (Exception e) {
-                       throw new XMLException("XML users file not valid");
+                       LOG.debug(e.getMessage(), e);
+                       throw new XMLException("XML users file not valid"); //RKV: NOPMD: Original message is printed
                }
        }
 
@@ -157,17 +164,19 @@ public class UserServiceImpl implements UserService {
         *            the user whose manager is get
         * @return the manager of the given user, if defined
         */
-       public User getManagerOf(User user) {
+       public User getManagerOf(final User user) {
                User result = null;
                String orgname = user.getOrganizationName();
 
-               if (orgname.equals("Nx2"))
+               if (orgname.equals("Nx2")) {
                        return result;
-               if (orgname.equals("Nx1"))
+               }
+               if (orgname.equals("Nx1")) {
                        orgname = "Nx2";
-               else {
-                       if (user.getRoleNames().equals("customer"))
+               else {
+                       if (user.getRoleNames().equals("customer")) {
                                return result;
+                       }
                        orgname = "Nx1";
                }
                try {
@@ -187,12 +196,12 @@ public class UserServiceImpl implements UserService {
        }
 
        @Transactional(readOnly = true)
-       public User selectUser(String username) {
+       public User selectUser(final String username) {
                return getUserDAO().findByCriteria(
                                Restrictions.eq("username", username));
        }
 
-       public User selectUser(String username, String password) {
+       public User selectUser(final String username, final String password) {
                // WARNING: For not encoding the password here, we better call a selectUsersWhere(User.Properties),
                // but this requires a getPassword in User.Properties nested class.
                Criterion aCondition = Restrictions.eq("username", username);
@@ -209,12 +218,12 @@ public class UserServiceImpl implements UserService {
        }
 
        @Transactional(readOnly = true)
-       public User selectUser(long index) {
+       public User selectUser(final long index) {
                return getUserDAO().get(index);
        }
 
        @SuppressWarnings("unchecked")
-       public List<User> selectUsersWhere(User.Properties... uprop) {
+       public List<User> selectUsersWhere(final User.Properties... uprop) {
 //             StringBuffer query = new StringBuffer("FROM User");
 //             String separator = " where (";
 //             String value;
@@ -260,7 +269,7 @@ public class UserServiceImpl implements UserService {
         * @param userDAO
         *            the userDAO to set
         */
-       public void setUserDAO(UserDAO userDAO) {
+       public void setUserDAO(final UserDAO userDAO) {
                _userDAO = userDAO;
        }
 }