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;
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations