private static void setupUsers(DaoFactory factory, String gridId, File baseDir) throws Exception { baseDir = new File(new File(new File(baseDir, "grids"), gridId), "users"); UserDao dao = factory.createUserDao(); for (File f : baseDir.listFiles(new RegexFileNameFilter(".*\\.json$"))) { User u = new LangridJSON(baseDir, FilenameUtil.getIdFromFileName(f)) .parse(new FileInputStream(f), User.class); u.setPassword(MessageDigestUtil.digestBySHA512(u.getPassword())); dao.addUser(u); } }
/* * (non-Javadoc) * @see jp.go.nict.langrid.p2pgridbasis.dao#updateData(jp.go.nict.langrid.p2pgridbasis.data.Data) */ public synchronized boolean updateDataTarget(Data data) throws UnmatchedDataTypeException, DataDaoException { logger.debug("[user] :" + data.getId()); if (data.getClass().equals(UserData.class) == false) { throw new UnmatchedDataTypeException(UserData.class.toString(), data.getClass().toString()); } if (data.getAttributes().getKeys().contains("IsDeleted") && data.getAttributes().getValue("IsDeleted").equals("true")) { logger.debug("Delete"); boolean updated = false; try { UserData userData = (UserData) data; User user = userData.getUser(); removeEntityListener(); dao.deleteUser(user.getGridId(), user.getUserId()); updated = true; setEntityListener(); getController().baseSummaryAdd(data); } catch (ParseException e) { throw new DataDaoException(e); } catch (UserNotFoundException e) { // // try { getController().baseSummaryAdd(data); } catch (ControllerException e1) { e1.printStackTrace(); } } catch (DaoException e) { throw new DataDaoException(e); } catch (ControllerException e) { throw new DataDaoException(e); } return updated; } User user = null; try { UserData userData = (UserData) data; user = userData.getUser(); removeEntityListener(); if (dao.isUserExist(user.getGridId(), user.getUserId())) { logger.debug("UpDate"); daoContext.updateEntity(user); } else { logger.debug("New"); dao.addUser(user); } setEntityListener(); getController().baseSummaryAdd(data); return true; } catch (ParseException e) { throw new DataDaoException(e); } catch (DaoException e) { throw new DataDaoException(e); } catch (ControllerException e) { throw new DataDaoException(e); } }