@Test public void testGetTraningDataByCrisisAndAttribute() { List<TrainingDataDTO> trainingDataDTOs = miscResourceFacadeImp.getTraningDataByCrisisAndAttribute(crisisDTO.getCrisisID(), modelFamilyDTO.getModelFamilyId(), 0, 1, null, null); assertNotNull(trainingDataDTOs); assertTrue("Training DTOs", trainingDataDTOs.size() == 1); }
@SuppressWarnings("unchecked") @Override public List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit, String sortColumn, String sortDirection) { List<TrainingDataDTO> trainingDataList = new ArrayList<TrainingDataDTO>(); String orderSQLPart = ""; if (sortColumn != null && !sortColumn.isEmpty()){ if (sortDirection != null && !sortDirection.isEmpty()) { if ("ASC".equals(sortDirection)) { sortDirection = "ASC"; } else { sortDirection = "DESC"; } } else { sortDirection = "DESC"; } orderSQLPart += " ORDER BY " + sortColumn + " " + sortDirection + " "; } else{ orderSQLPart += " ORDER BY dnl.timestamp DESC"; } String sql = " SELECT distinct lbl.nominalLabelID, lbl.name labelName, d.data tweetJSON, u.id, u.user_name labelerName, dnl.timestamp, d.documentID " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " JOIN account u on u.id = dnl.userID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID " + orderSQLPart + " LIMIT :fromRecord, :limit"; String sqlCount = " SELECT count(1) " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID"; try { Integer totalRows = null; Session session = getCurrentSession(); Query queryCount = session.createSQLQuery(sqlCount); queryCount.setParameter("modelFamilyID", modelFamilyID.intValue()); queryCount.setParameter("crisisID", crisisID.intValue()); Object res = queryCount.uniqueResult(); if (res != null) { totalRows = Integer.parseInt(res.toString()); } logger.info("getTraningDataByCrisisAndAttribute: rows count = " + res); if (totalRows != null && totalRows > 0) { Query query = session.createSQLQuery(sql); query.setParameter("crisisID", crisisID.intValue()); query.setParameter("modelFamilyID", modelFamilyID.intValue()); query.setParameter("fromRecord", fromRecord); query.setParameter("limit", limit); List<Object[]> rows = query.list(); TrainingDataDTO trainingDataRow = null; for (Object[] row : rows) { trainingDataRow = new TrainingDataDTO(); trainingDataRow.setLabelID(((BigInteger) row[0]).intValue()); trainingDataRow.setLabelName((String) row[1]); trainingDataRow.setTweetJSON((String) row[2]); trainingDataRow.setLabelerID(((BigInteger) row[3]).intValue()); trainingDataRow.setLabelerName((String) row[4]); trainingDataRow.setLabeledTime(((Date) row[5])); trainingDataRow.setDocumentID(((BigInteger) row[6]).longValue()); trainingDataRow.setTotalRows(totalRows); trainingDataList.add(trainingDataRow); } } logger.info("Fetched training data list size: " + (trainingDataList != null ? trainingDataList.size() : 0)); return trainingDataList; } catch (Exception e) { logger.error("exception", e); return null; } }
MiscResourceFacadeImp extends CoreDBServiceFacadeImp<Document, Long> implements MiscResourceFacade { @SuppressWarnings("unchecked") @Override public List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit, String sortColumn, String sortDirection) { List<TrainingDataDTO> trainingDataList = new ArrayList<TrainingDataDTO>(); String orderSQLPart = ""; if (sortColumn != null && !sortColumn.isEmpty()){ if (sortDirection != null && !sortDirection.isEmpty()) { if ("ASC".equals(sortDirection)) { sortDirection = "ASC"; } else { sortDirection = "DESC"; } } else { sortDirection = "DESC"; } orderSQLPart += " ORDER BY " + sortColumn + " " + sortDirection + " "; } else{ orderSQLPart += " ORDER BY dnl.timestamp DESC"; } String sql = " SELECT distinct lbl.nominalLabelID, lbl.name labelName, d.data tweetJSON, u.id, u.user_name labelerName, dnl.timestamp, d.documentID " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " JOIN account u on u.id = dnl.userID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID " + orderSQLPart + " LIMIT :fromRecord, :limit"; String sqlCount = " SELECT count(1) " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID"; try { Integer totalRows = null; Session session = getCurrentSession(); Query queryCount = session.createSQLQuery(sqlCount); queryCount.setParameter("modelFamilyID", modelFamilyID.intValue()); queryCount.setParameter("crisisID", crisisID.intValue()); Object res = queryCount.uniqueResult(); if (res != null) { totalRows = Integer.parseInt(res.toString()); } logger.info("getTraningDataByCrisisAndAttribute: rows count = " + res); if (totalRows != null && totalRows > 0) { Query query = session.createSQLQuery(sql); query.setParameter("crisisID", crisisID.intValue()); query.setParameter("modelFamilyID", modelFamilyID.intValue()); query.setParameter("fromRecord", fromRecord); query.setParameter("limit", limit); List<Object[]> rows = query.list(); TrainingDataDTO trainingDataRow = null; for (Object[] row : rows) { trainingDataRow = new TrainingDataDTO(); trainingDataRow.setLabelID(((BigInteger) row[0]).intValue()); trainingDataRow.setLabelName((String) row[1]); trainingDataRow.setTweetJSON((String) row[2]); trainingDataRow.setLabelerID(((BigInteger) row[3]).intValue()); trainingDataRow.setLabelerName((String) row[4]); trainingDataRow.setLabeledTime(((Date) row[5])); trainingDataRow.setDocumentID(((BigInteger) row[6]).longValue()); trainingDataRow.setTotalRows(totalRows); trainingDataList.add(trainingDataRow); } } logger.info("Fetched training data list size: " + (trainingDataList != null ? trainingDataList.size() : 0)); return trainingDataList; } catch (Exception e) { logger.error("exception", e); return null; } } }
MiscResourceFacadeImp extends CoreDBServiceFacadeImp<Document, Long> implements MiscResourceFacade { @SuppressWarnings("unchecked") @Override public List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit, String sortColumn, String sortDirection) { List<TrainingDataDTO> trainingDataList = new ArrayList<TrainingDataDTO>(); String orderSQLPart = ""; if (sortColumn != null && !sortColumn.isEmpty()){ if (sortDirection != null && !sortDirection.isEmpty()) { if ("ASC".equals(sortDirection)) { sortDirection = "ASC"; } else { sortDirection = "DESC"; } } else { sortDirection = "DESC"; } orderSQLPart += " ORDER BY " + sortColumn + " " + sortDirection + " "; } else{ orderSQLPart += " ORDER BY dnl.timestamp DESC"; } String sql = " SELECT distinct lbl.nominalLabelID, lbl.name labelName, d.data tweetJSON, u.id, u.user_name labelerName, dnl.timestamp, d.documentID " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " JOIN account u on u.id = dnl.userID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID " + orderSQLPart + " LIMIT :fromRecord, :limit"; String sqlCount = " SELECT count(1) " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID"; try { Integer totalRows = null; Session session = getCurrentSession(); Query queryCount = session.createSQLQuery(sqlCount); queryCount.setParameter("modelFamilyID", modelFamilyID.intValue()); queryCount.setParameter("crisisID", crisisID.intValue()); Object res = queryCount.uniqueResult(); if (res != null) { totalRows = Integer.parseInt(res.toString()); } logger.info("getTraningDataByCrisisAndAttribute: rows count = " + res); if (totalRows != null && totalRows > 0) { Query query = session.createSQLQuery(sql); query.setParameter("crisisID", crisisID.intValue()); query.setParameter("modelFamilyID", modelFamilyID.intValue()); query.setParameter("fromRecord", fromRecord); query.setParameter("limit", limit); List<Object[]> rows = query.list(); TrainingDataDTO trainingDataRow = null; for (Object[] row : rows) { trainingDataRow = new TrainingDataDTO(); trainingDataRow.setLabelID(((BigInteger) row[0]).intValue()); trainingDataRow.setLabelName((String) row[1]); trainingDataRow.setTweetJSON((String) row[2]); trainingDataRow.setLabelerID(((BigInteger) row[3]).intValue()); trainingDataRow.setLabelerName((String) row[4]); trainingDataRow.setLabeledTime(((Date) row[5])); trainingDataRow.setDocumentID(((BigInteger) row[6]).longValue()); trainingDataRow.setTotalRows(totalRows); trainingDataList.add(trainingDataRow); } } logger.info("Fetched training data list size: " + (trainingDataList != null ? trainingDataList.size() : 0)); return trainingDataList; } catch (Exception e) { logger.error("exception", e); return null; } } MiscResourceFacadeImp(); }
MiscResourceFacadeImp extends CoreDBServiceFacadeImp<Document, Long> implements MiscResourceFacade { @SuppressWarnings("unchecked") @Override public List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit, String sortColumn, String sortDirection) { List<TrainingDataDTO> trainingDataList = new ArrayList<TrainingDataDTO>(); String orderSQLPart = ""; if (sortColumn != null && !sortColumn.isEmpty()){ if (sortDirection != null && !sortDirection.isEmpty()) { if ("ASC".equals(sortDirection)) { sortDirection = "ASC"; } else { sortDirection = "DESC"; } } else { sortDirection = "DESC"; } orderSQLPart += " ORDER BY " + sortColumn + " " + sortDirection + " "; } else{ orderSQLPart += " ORDER BY dnl.timestamp DESC"; } String sql = " SELECT distinct lbl.nominalLabelID, lbl.name labelName, d.data tweetJSON, u.id, u.user_name labelerName, dnl.timestamp, d.documentID " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " JOIN account u on u.id = dnl.userID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID " + orderSQLPart + " LIMIT :fromRecord, :limit"; String sqlCount = " SELECT count(1) " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID"; try { Integer totalRows = null; Session session = getCurrentSession(); Query queryCount = session.createSQLQuery(sqlCount); queryCount.setParameter("modelFamilyID", modelFamilyID.intValue()); queryCount.setParameter("crisisID", crisisID.intValue()); Object res = queryCount.uniqueResult(); if (res != null) { totalRows = Integer.parseInt(res.toString()); } logger.info("getTraningDataByCrisisAndAttribute: rows count = " + res); if (totalRows != null && totalRows > 0) { Query query = session.createSQLQuery(sql); query.setParameter("crisisID", crisisID.intValue()); query.setParameter("modelFamilyID", modelFamilyID.intValue()); query.setParameter("fromRecord", fromRecord); query.setParameter("limit", limit); List<Object[]> rows = query.list(); TrainingDataDTO trainingDataRow = null; for (Object[] row : rows) { trainingDataRow = new TrainingDataDTO(); trainingDataRow.setLabelID(((BigInteger) row[0]).intValue()); trainingDataRow.setLabelName((String) row[1]); trainingDataRow.setTweetJSON((String) row[2]); trainingDataRow.setLabelerID(((BigInteger) row[3]).intValue()); trainingDataRow.setLabelerName((String) row[4]); trainingDataRow.setLabeledTime(((Date) row[5])); trainingDataRow.setDocumentID(((BigInteger) row[6]).longValue()); trainingDataRow.setTotalRows(totalRows); trainingDataList.add(trainingDataRow); } } logger.info("Fetched training data list size: " + (trainingDataList != null ? trainingDataList.size() : 0)); return trainingDataList; } catch (Exception e) { logger.error("exception", e); return null; } } MiscResourceFacadeImp(); @SuppressWarnings("unchecked") @Override List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit,
			String sortColumn, String sortDirection); @SuppressWarnings("unchecked") @Override ItemToLabelDTO getItemToLabel(Long crisisID, Long modelFamilyID); @SuppressWarnings("unchecked") @Override Map<Long, Long> getTrainingCountForCrisis(Long crisisID); }
MiscResourceFacadeImp extends CoreDBServiceFacadeImp<Document, Long> implements MiscResourceFacade { @SuppressWarnings("unchecked") @Override public List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit, String sortColumn, String sortDirection) { List<TrainingDataDTO> trainingDataList = new ArrayList<TrainingDataDTO>(); String orderSQLPart = ""; if (sortColumn != null && !sortColumn.isEmpty()){ if (sortDirection != null && !sortDirection.isEmpty()) { if ("ASC".equals(sortDirection)) { sortDirection = "ASC"; } else { sortDirection = "DESC"; } } else { sortDirection = "DESC"; } orderSQLPart += " ORDER BY " + sortColumn + " " + sortDirection + " "; } else{ orderSQLPart += " ORDER BY dnl.timestamp DESC"; } String sql = " SELECT distinct lbl.nominalLabelID, lbl.name labelName, d.data tweetJSON, u.id, u.user_name labelerName, dnl.timestamp, d.documentID " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " JOIN account u on u.id = dnl.userID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID " + orderSQLPart + " LIMIT :fromRecord, :limit"; String sqlCount = " SELECT count(1) " + " FROM document_nominal_label dnl " + " JOIN nominal_label lbl on lbl.nominalLabelID=dnl.nominalLabelID " + " JOIN model_family mf on mf.nominalAttributeID=lbl.nominalAttributeID " + " JOIN document d on d.documentID = dnl.documentID " + " WHERE mf.modelFamilyID = :modelFamilyID AND d.crisisID = :crisisID"; try { Integer totalRows = null; Session session = getCurrentSession(); Query queryCount = session.createSQLQuery(sqlCount); queryCount.setParameter("modelFamilyID", modelFamilyID.intValue()); queryCount.setParameter("crisisID", crisisID.intValue()); Object res = queryCount.uniqueResult(); if (res != null) { totalRows = Integer.parseInt(res.toString()); } logger.info("getTraningDataByCrisisAndAttribute: rows count = " + res); if (totalRows != null && totalRows > 0) { Query query = session.createSQLQuery(sql); query.setParameter("crisisID", crisisID.intValue()); query.setParameter("modelFamilyID", modelFamilyID.intValue()); query.setParameter("fromRecord", fromRecord); query.setParameter("limit", limit); List<Object[]> rows = query.list(); TrainingDataDTO trainingDataRow = null; for (Object[] row : rows) { trainingDataRow = new TrainingDataDTO(); trainingDataRow.setLabelID(((BigInteger) row[0]).intValue()); trainingDataRow.setLabelName((String) row[1]); trainingDataRow.setTweetJSON((String) row[2]); trainingDataRow.setLabelerID(((BigInteger) row[3]).intValue()); trainingDataRow.setLabelerName((String) row[4]); trainingDataRow.setLabeledTime(((Date) row[5])); trainingDataRow.setDocumentID(((BigInteger) row[6]).longValue()); trainingDataRow.setTotalRows(totalRows); trainingDataList.add(trainingDataRow); } } logger.info("Fetched training data list size: " + (trainingDataList != null ? trainingDataList.size() : 0)); return trainingDataList; } catch (Exception e) { logger.error("exception", e); return null; } } MiscResourceFacadeImp(); @SuppressWarnings("unchecked") @Override List<TrainingDataDTO> getTraningDataByCrisisAndAttribute(Long crisisID, Long modelFamilyID, int fromRecord, int limit,
			String sortColumn, String sortDirection); @SuppressWarnings("unchecked") @Override ItemToLabelDTO getItemToLabel(Long crisisID, Long modelFamilyID); @SuppressWarnings("unchecked") @Override Map<Long, Long> getTrainingCountForCrisis(Long crisisID);  }