Search in sources :

Example 6 with UserSystem

use of org.cerberus.crud.entity.UserSystem in project cerberus-source by cerberustesting.

the class FactoryUserSystem method create.

@Override
public UserSystem create(String login, String system) {
    UserSystem result = new UserSystem();
    result.setLogin(login);
    result.setSystem(system);
    return result;
}
Also used : UserSystem(org.cerberus.crud.entity.UserSystem) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem)

Example 7 with UserSystem

use of org.cerberus.crud.entity.UserSystem in project cerberus-source by cerberustesting.

the class UserSystemService method updateSystemsByUser.

@Override
public Answer updateSystemsByUser(User user, List<UserSystem> newGroups) {
    Answer a = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "UPDATE"));
    AnswerList an = this.readByUser(user.getLogin());
    if (an.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        List<UserSystem> oldGroups = an.getDataList();
        // delete if don't exist in new
        for (UserSystem old : oldGroups) {
            if (!newGroups.contains(old)) {
                Answer del = userSystemDAO.remove(old);
                if (!del.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    a = del;
                }
            }
        }
        // insert if don't exist in old
        for (UserSystem group : newGroups) {
            if (!oldGroups.contains(group)) {
                Answer add = userSystemDAO.create(group);
                if (!add.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    a = add;
                }
            }
        }
    }
    return a;
}
Also used : Answer(org.cerberus.util.answer.Answer) AnswerList(org.cerberus.util.answer.AnswerList) UserSystem(org.cerberus.crud.entity.UserSystem) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 8 with UserSystem

use of org.cerberus.crud.entity.UserSystem in project cerberus-source by cerberustesting.

the class UserSystemDAO method findUserSystemBySystem.

@Override
public List<UserSystem> findUserSystemBySystem(String system) throws CerberusException {
    List<UserSystem> list = null;
    final String query = "SELECT * FROM usersystem u WHERE u.`system` = ? ";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, system);
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<UserSystem>();
                while (resultSet.next()) {
                    UserSystem user = this.loadUserSystemFromResultSet(resultSet);
                    list.add(user);
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return list;
}
Also used : UserSystem(org.cerberus.crud.entity.UserSystem) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 9 with UserSystem

use of org.cerberus.crud.entity.UserSystem in project cerberus-source by cerberustesting.

the class UserSystemDAO method findUserSystemByKey.

@Override
public UserSystem findUserSystemByKey(String login, String system) throws CerberusException {
    UserSystem result = null;
    final String query = "SELECT * FROM usersystem u WHERE u.`login` = ? and u.`system` = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, login);
            preStat.setString(2, system);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = this.loadUserSystemFromResultSet(resultSet);
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return result;
}
Also used : UserSystem(org.cerberus.crud.entity.UserSystem) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 10 with UserSystem

use of org.cerberus.crud.entity.UserSystem in project cerberus-source by cerberustesting.

the class GetUsers method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String echo = request.getParameter("sEcho");
    // data that will be shown in the table
    JSONArray data = new JSONArray();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IUserService userService = appContext.getBean(UserService.class);
    IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
    IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
    try {
        JSONObject jsonResponse = new JSONObject();
        try {
            for (User myUser : userService.findallUser()) {
                JSONObject u = new JSONObject();
                u.put("login", myUser.getLogin());
                u.put("name", myUser.getName());
                u.put("team", myUser.getTeam());
                u.put("defaultSystem", myUser.getDefaultSystem());
                u.put("request", myUser.getRequest());
                u.put("email", myUser.getEmail());
                JSONArray groups = new JSONArray();
                for (UserGroup group : userGroupService.findGroupByKey(myUser.getLogin())) {
                    groups.put(group.getGroup());
                }
                u.put("group", groups);
                JSONArray systems = new JSONArray();
                for (UserSystem sys : userSystemService.findUserSystemByUser(myUser.getLogin())) {
                    systems.put(sys.getSystem());
                }
                u.put("system", systems);
                data.put(u);
            }
        } catch (CerberusException ex) {
            response.setContentType("text/html");
            response.getWriter().print(ex.getMessageError().getDescription());
        }
        jsonResponse.put("aaData", data);
        jsonResponse.put("sEcho", echo);
        jsonResponse.put("iTotalRecords", data.length());
        jsonResponse.put("iTotalDisplayRecords", data.length());
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
        LOG.warn(e);
        response.setContentType("text/html");
        response.getWriter().print(e.getMessage());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) JSONObject(org.json.JSONObject) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IUserGroupService(org.cerberus.crud.service.IUserGroupService) IUserSystemService(org.cerberus.crud.service.IUserSystemService) UserGroup(org.cerberus.crud.entity.UserGroup)

Aggregations

UserSystem (org.cerberus.crud.entity.UserSystem)12 IFactoryUserSystem (org.cerberus.crud.factory.IFactoryUserSystem)7 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 User (org.cerberus.crud.entity.User)5 UserGroup (org.cerberus.crud.entity.UserGroup)5 IUserGroupService (org.cerberus.crud.service.IUserGroupService)5 IUserService (org.cerberus.crud.service.IUserService)5 IUserSystemService (org.cerberus.crud.service.IUserSystemService)5 JSONArray (org.json.JSONArray)5 JSONObject (org.json.JSONObject)5 CerberusException (org.cerberus.exception.CerberusException)4 AnswerList (org.cerberus.util.answer.AnswerList)4 MessageEvent (org.cerberus.engine.entity.MessageEvent)3 JSONException (org.json.JSONException)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ArrayList (java.util.ArrayList)2 UserService (org.cerberus.crud.service.impl.UserService)2