List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertToSqoop(Object val, HCatFieldSchema.Type fieldType, String javaColType, String hCatTypeString) throws IOException { if (val == null) { return null; }/*from w ww.j a v a2 s. c om*/ switch (fieldType) { case INT: case TINYINT: case SMALLINT: case FLOAT: case DOUBLE: val = convertNumberTypes(val, javaColType); if (val != null) { return val; } break; case BOOLEAN: val = convertBooleanTypes(val, javaColType); if (val != null) { return val; } break; case BIGINT: if (javaColType.equals(DATE_TYPE)) { return new Date((Long) val); } else if (javaColType.equals(TIME_TYPE)) { return new Time((Long) val); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp((Long) val); } else { val = convertNumberTypes(val, javaColType); if (val != null) { return val; } } break; case DATE: Date date = (Date) val; if (javaColType.equals(DATE_TYPE)) { return date; } else if (javaColType.equals(TIME_TYPE)) { return new Time(date.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(date.getTime()); } break; case TIMESTAMP: Timestamp ts = (Timestamp) val; if (javaColType.equals(DATE_TYPE)) { return new Date(ts.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return new Time(ts.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return ts; } break; case STRING: case VARCHAR: case CHAR: val = convertStringTypes(val, javaColType); if (val != null) { return val; } break; case BINARY: val = convertBinaryTypes(val, javaColType); if (val != null) { return val; } break; case DECIMAL: val = convertDecimalTypes(val, javaColType); if (val != null) { return val; } break; case ARRAY: case MAP: case STRUCT: default: throw new IOException("Cannot convert HCatalog type " + fieldType); } LOG.error("Cannot convert HCatalog object of " + " type " + hCatTypeString + " to java object type " + javaColType); return null; }
From source file:com.ToResultSet.java
@Path("/input") @GET/*from w ww . ja v a 2 s . c o m*/ @Produces(MediaType.APPLICATION_JSON) public String toResultSet(@QueryParam("budget") String x, @QueryParam("maxbudget") String y, @QueryParam("location") String location, @QueryParam("date") String minDateString) throws ParserConfigurationException, TransformerException, ParseException { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("Fehler bei MySQL-JDBC-Bridge" + e); } //SQL Query wird hier erzeugt je nach dem Daten, die angegeben werden try { int minBudget = 0; int maxBudget = 0; try { minBudget = Integer.valueOf(x); } catch (NumberFormatException e) { if (x.length() > 0) { return "Ihre Budget soll aus Zahlen bestehen"; } } try { maxBudget = Integer.valueOf(y); } catch (NumberFormatException e) { if (y.length() > 0) { return "Ihre Budget soll aus Zahlen bestehen"; } } try { test = Integer.valueOf(location); if (test >= 0) { return "Location soll aus String bestehen"; } } catch (Exception e) { } try { if (minDateString.substring(2, 3).contains("-") && minDateString.length() > 0) { return "Date Format soll yyyy-MM-dd"; } else { java.util.Date date1 = sdf.parse(minDateString); minDate = new java.sql.Date(date1.getTime()); } } catch (Exception e) { if (minDateString.length() > 0) return "Date Format soll yyyy-MM-dd"; } //Connection mit dem SQL wird erzeugt String url = "jdbc:mysql://" + host + "/" + dbName; connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/location?autoReconnect=true&useSSL=false", "root", "dreamhigh"); statement = connection.createStatement(); String sqlQuery = "Select * FROM " + dbTable; List<String> whereClause = new ArrayList<>(); if (minBudget > 0) { whereClause.add("Budget >= " + minBudget); } if (maxBudget > 0) { whereClause.add("Budget <= " + maxBudget); } if (minBudget > maxBudget && maxBudget > 0 && minBudget > 0) { return "Minimal Budget soll kleiner als Maximal Budget"; } if (minDate != null) { whereClause.add("Date >= '" + minDate + "'"); } if (location != null && !location.isEmpty()) { whereClause.add("Location = '" + location + "'"); } //Die Daten werden nach dem Budget absteigend sortiert if (whereClause.size() > 0) { sqlQuery += " WHERE " + StringUtils.join(whereClause, " AND ") + " ORDER BY Budget DESC"; } if (whereClause.size() == 0) { sqlQuery += " ORDER BY Budget DESC"; } resultSet = statement.executeQuery(sqlQuery); int spalten = resultSet.getMetaData().getColumnCount(); System.out.println("Anzahl Spalten: " + spalten); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element results = doc.createElement("Results"); doc.appendChild(results); connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/location?autoReconnect=true&useSSL=false", "root", "dreamhigh"); ResultSetMetaData rsmd = resultSet.getMetaData(); int colCount = rsmd.getColumnCount(); while (resultSet.next()) { String[] str = new String[8]; for (int k = 1; k <= spalten; k++) { str[k - 1] = resultSet.getString(k); result.add(resultSet.getString(k)); } //Result wird hier als XML zuerst erzeugt und dann Json Element row = doc.createElement("Row"); results.appendChild(row); for (int ii = 1; ii <= colCount; ii++) { String columnName = rsmd.getColumnName(ii); Object value = resultSet.getObject(ii); Element node = doc.createElement(columnName); if (value != null) { node.appendChild(doc.createTextNode(value.toString())); row.appendChild(node); } } } System.out.println(getDocumentAsXml(doc)); try { xmlJSONObj = XML.toJSONObject(getDocumentAsXml(doc)); outPut = xmlJSONObj.toString(4); System.out.println(outPut); return outPut; } catch (JSONException je) { } } catch (SQLException e) { System.out.println("Fehler bei Tabellenabfrage: " + e); } return outPut; }
From source file:edu.harvard.i2b2.ontology.dao.GetTermInfoDao.java
public List findByFullname(final GetTermInfoType termInfoType, List categories, ProjectType projectInfo, final String dbType) throws DataAccessException { DataSource ds = null;//from w w w . j a v a 2 s. c o m try { ds = OntologyUtil.getInstance().getDataSource("java:OntologyLocalDS"); } catch (I2B2Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds); // find return parameters String parameters = DEFAULT; if (termInfoType.getType().equals("core")) { parameters = CORE; } else if (termInfoType.getType().equals("all")) { parameters = ALL; } if (termInfoType.isBlob() == true) parameters = parameters + BLOB; //extract table code String tableCd = StringUtil.getTableCd(termInfoType.getSelf()); // table code to table name conversion // Get metadata schema name from properties file. String metadataSchema = ""; try { metadataSchema = OntologyUtil.getInstance().getMetaDataSchemaName(); } catch (I2B2Exception e1) { log.error(e1.getMessage()); } // table code to table name conversion String tableSql = "select distinct(c_table_name) from " + metadataSchema + "table_access where c_table_cd = ? "; ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = (rs.getString("c_table_name")); return name; } }; String tableName = jt.queryForObject(tableSql, map, tableCd); String path = StringUtil.getPath(termInfoType.getSelf()); // if(path.equals("\\Providers")) // path="\\RPDR\\Providers"; String searchPath = path; String hidden = ""; if (termInfoType.isHiddens() == false) hidden = " and c_visualattributes not like '_H%'"; String synonym = ""; if (termInfoType.isSynonyms() == false) synonym = " and c_synonym_cd = 'N'"; String sql = "select " + parameters + " from " + metadataSchema + tableName + " where c_fullname like ? "; sql = sql + hidden + synonym + " order by c_name "; // log.info(sql + path + level); final boolean obfuscatedUserFlag = Roles.getInstance().isRoleOfuscated(projectInfo); ParameterizedRowMapper<ConceptType> mapper = new ParameterizedRowMapper<ConceptType>() { public ConceptType mapRow(ResultSet rs, int rowNum) throws SQLException { ConceptType self = new ConceptType(); self.setName(rs.getString("c_name")); self.setBasecode(rs.getString("c_basecode")); self.setLevel(rs.getInt("c_hlevel")); self.setKey(rs.getString("c_fullname")); self.setSynonymCd(rs.getString("c_synonym_cd")); self.setVisualattributes(rs.getString("c_visualattributes")); Integer totalNum = rs.getInt("c_totalnum"); if (obfuscatedUserFlag == false) { self.setTotalnum(totalNum); } self.setFacttablecolumn(rs.getString("c_facttablecolumn")); self.setTablename(rs.getString("c_tablename")); self.setColumnname(rs.getString("c_columnname")); self.setColumndatatype(rs.getString("c_columndatatype")); self.setOperator(rs.getString("c_operator")); self.setDimcode(rs.getString("c_dimcode")); self.setTooltip(rs.getString("c_tooltip")); if (termInfoType.isBlob() == true) { if (rs.getClob("c_comment") == null) self.setComment(null); else { try { if (dbType.equals("POSTGRESQL")) self.setComment(rs.getString("c_comment")); else self.setComment(JDBCUtil.getClobString(rs.getClob("c_comment"))); } catch (IOException e1) { log.error(e1.getMessage()); self.setComment(null); } } if (rs.getClob("c_metadataxml") == null) { self.setMetadataxml(null); } else { String c_xml = null; try { if (dbType.equals("POSTGRESQL")) c_xml = rs.getString("c_metadataxml"); else c_xml = JDBCUtil.getClobString(rs.getClob("c_metadataxml")); } catch (IOException e1) { log.error(e1.getMessage()); self.setMetadataxml(null); } if ((c_xml != null) && (c_xml.trim().length() > 0) && (!c_xml.equals("(null)"))) { SAXBuilder parser = new SAXBuilder(); java.io.StringReader xmlStringReader = new java.io.StringReader(c_xml); Element rootElement = null; try { org.jdom.Document metadataDoc = parser.build(xmlStringReader); org.jdom.output.DOMOutputter out = new DOMOutputter(); Document doc = out.output(metadataDoc); rootElement = doc.getDocumentElement(); } catch (JDOMException e) { log.error(e.getMessage()); self.setMetadataxml(null); } catch (IOException e1) { log.error(e1.getMessage()); self.setMetadataxml(null); } if (rootElement != null) { XmlValueType xml = new XmlValueType(); xml.getAny().add(rootElement); self.setMetadataxml(xml); } } else { self.setMetadataxml(null); } } } if ((termInfoType.getType().equals("all"))) { DTOFactory factory = new DTOFactory(); // make sure date isnt null before converting to XMLGregorianCalendar Date date = rs.getDate("update_date"); if (date == null) self.setUpdateDate(null); else self.setUpdateDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("download_date"); if (date == null) self.setDownloadDate(null); else self.setDownloadDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("import_date"); if (date == null) self.setImportDate(null); else self.setImportDate(factory.getXMLGregorianCalendar(date.getTime())); self.setSourcesystemCd(rs.getString("sourcesystem_cd")); self.setValuetypeCd(rs.getString("valuetype_cd")); } return self; } }; // log.info(sql + " " + path + " " + level); List queryResult = null; try { queryResult = jt.query(sql, mapper, searchPath); } catch (DataAccessException e) { log.error(e.getMessage()); throw e; } log.debug("result size = " + queryResult.size()); //Fix the key so it equals "\\tableCd\fullname" if (queryResult != null) { Iterator itr = queryResult.iterator(); while (itr.hasNext()) { ConceptType self = (ConceptType) itr.next(); self.setKey("\\\\" + tableCd + self.getKey()); } } return queryResult; }
From source file:org.kuali.kra.budget.parameters.BudgetPeriodRule.java
private String compareDate(Date periodStartDate, Date periodEndDate, Date previousPeriodEndDate) { String returnErrorValue = null; LOG.info("prd st dt " + periodStartDate.getTime() + periodEndDate.getTime() + getProjectStartDate().getTime() + getProjectEndDate().getTime()); if (periodStartDate.after(getProjectEndDate())) { LOG.info("ERROR_PERIOD_START_AFTER_PROJECT_END" + periodStartDate + getProjectEndDate()); returnErrorValue = "ERROR_PERIOD_START_AFTER_PROJECT_END"; } else if (periodStartDate.before(getProjectStartDate())) { LOG.info("ERROR_PERIOD_START_BEFORE_PROJECT_START" + periodStartDate + getProjectStartDate()); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (periodEndDate.before(getProjectStartDate())) { LOG.info("ERROR_PERIOD_END_BEFORE_PROJECT_START" + periodEndDate + getProjectStartDate()); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PROJECT_START"; } else if (periodEndDate.after(getProjectEndDate())) { LOG.info("ERROR_PERIOD_END_AFTER_PROJECT_END" + periodEndDate + getProjectEndDate()); returnErrorValue = "ERROR_PERIOD_END_AFTER_PROJECT_END"; } else if (periodStartDate.after(periodEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PERIOD_END" + periodStartDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_START_AFTER_PERIOD_END"; } else if (previousPeriodEndDate != null && !periodStartDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodStartDate); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PREVIOUS_END"; } else if (previousPeriodEndDate != null && !periodEndDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_END_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PREVIOUS_END"; }/*from ww w.j a v a 2s. c o m*/ return returnErrorValue; }
From source file:abelymiguel.miralaprima.GetPrima.java
private Timestamp getTimestamp() { Timestamp date_added;//w w w .ja v a 2 s .c om java.util.Date date = new java.util.Date(); date_added = new Timestamp(date.getTime()); return date_added; }
From source file:com.project.implementation.ReservationImplementation.java
public String makeReservation(GuestDTO guestDTO, Integer no_of_rooms_Int, Date checkin_date, Date checkout_date) {/*from w w w . ja v a 2 s.com*/ Integer guestID = 0, guestCount; String room_selected = guestDTO.getRoom_no_selected(); Guest guestObject = new Guest(); try { org.apache.commons.beanutils.BeanUtils.copyProperties(guestObject, guestDTO); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } //check email id if exist guestID = guestDAO.checkGuestExist(guestDTO.getGuest_email(), guestDTO.getLicense_no()); System.out.println("guestID: " + guestID); //if email id, license exist if (!(guestID == 0)) { System.out.println("value = "); //update details guestCount = guestDAO.updateUserDetails(guestID, guestDTO.getGuest_name(), guestDTO.getStreet(), guestDTO.getCity(), guestDTO.getState(), guestDTO.getZip()); if (guestCount != 0) guestObject = guestDAO.getGuestRecord(guestID); } else { guestObject = guestDAO.save(guestObject); } String randomDate = FastDateFormat.getInstance("dd-MM-yyyy").format(System.currentTimeMillis()); UUID id = UUID.randomUUID(); String token_no = String.valueOf(id); //System.out.println(sensor_id); // String token_no = guestObject.getLicense_no() + guestObject.getGuest_id()+randomDate; java.util.Date todayUtilDate = Calendar.getInstance().getTime();//2015-12-05 java.sql.Date todaySqlDate = new java.sql.Date(todayUtilDate.getTime()); Reservation reservationObject = new Reservation(); // reservationObject.setReservation_id(0); reservationObject.setGuest_id(guestObject.getGuest_id()); reservationObject.setReservation_token(token_no); reservationObject.setReservation_date(todaySqlDate); reservationObject.setReservation_status(ReservationStatus.R); reservationObject = reservationDAO.save(reservationObject); // Integer reservation_id = reservationObject.getReservation_id(); String[] resultStringArray = guestDTO.getRoom_no_selected().split(","); ArrayList<Integer> arrRooms = new ArrayList<Integer>(); for (String str : resultStringArray) { arrRooms.add(Integer.parseInt(str)); CheckinRoomMapping checkinRoomMappingObject = new CheckinRoomMapping(); checkinRoomMappingObject.setReservation(reservationObject); checkinRoomMappingObject.setRoom_no(Integer.parseInt(str)); checkinRoomMappingObject.setCheckin_date(checkin_date); checkinRoomMappingObject.setCheckout_date(checkout_date); checkinRoomMappingObject.setGuest_count(0); checkinRoomMappingObject.setMappingId(0); checkinRoomMappingDAO.save(checkinRoomMappingObject); } //add email code start here final String from = "express.minihotel@gmail.com"; String to = guestObject.getGuest_email(); String body = "Hello " + guestObject.getGuest_name() + ", <br/><br></br>Your reservation has been confirmed.Your reservation ID is <font color='red'><b>" + token_no + "</b></font>.</br>Please bring the Driving License for verification at the time of Check In.</br><br></br>" + "<b>Note:</b>If you want to cancel the reservation, " + "please <a href=\'http://52.53.255.195:8080/CmpE275Team07Fall2015TermProject/v1/cancelReservation?reservation_token=" + token_no + "\'>Click Here</a><br></br>--<i>Express Hotel</i>"; String subject = "Express Hotel Reservation Confirmation <" + token_no + ">"; final String password = "Minihotel@2015"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, password); } }); try { MimeMessage email = new MimeMessage(session); email.setFrom(new InternetAddress(from)); email.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to)); email.setSubject(subject); email.setContent(body, "text/html"); Transport.send(email); } catch (MessagingException e) { throw new RuntimeException(e); } //email code end here return token_no; }
From source file:com.ToResultSet.java
@Path("/tabelle") @GET/*from w w w . j a va 2 s .c om*/ public String toResultSetTabelle(@QueryParam("budget") String x, @QueryParam("maxbudget") String y, @QueryParam("location") String location, @QueryParam("date") String minDateString) throws ParserConfigurationException, TransformerException, ParseException { ArrayList<String[]> result1 = new ArrayList<String[]>(); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("Fehler bei MySQL-JDBC-Bridge" + e); } //SQL Query wird hier erzeugt je nach dem Daten, die angegeben werden try { int minBudget = 0; int maxBudget = 0; try { minBudget = Integer.valueOf(x); } catch (NumberFormatException e) { if (x.length() > 0) { return "Ihre Budget soll aus Zahlen bestehen"; } } try { maxBudget = Integer.valueOf(y); } catch (NumberFormatException e) { if (y.length() > 0) { return "Ihre Budget soll aus Zahlen bestehen"; } } try { test = Integer.valueOf(location); if (test >= 0) { return "Location soll aus String bestehen"; } } catch (Exception e) { } try { if (minDateString.substring(2, 3).contains("-") && minDateString.length() > 0) { return "Date Format soll yyyy-MM-dd"; } else { java.util.Date date1 = sdf.parse(minDateString); minDate = new java.sql.Date(date1.getTime()); } } catch (Exception e) { if (minDateString.length() > 0) return "Date Format soll yyyy-MM-dd"; } //Connection mit dem SQL wird erzeugt String url = "jdbc:mysql://" + host + "/" + dbName; connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/location?autoReconnect=true&useSSL=false", "root", "dreamhigh"); statement = connection.createStatement(); String sqlQuery = "Select * FROM " + dbTable; List<String> whereClause = new ArrayList<>(); if (minBudget > 0) { whereClause.add("Budget >= " + minBudget); } if (maxBudget > 0) { whereClause.add("Budget <= " + maxBudget); } if (minBudget > maxBudget && maxBudget > 0 && minBudget > 0) { return "Minimal Budget soll kleiner als Maximal Budget"; } if (minDate != null) { whereClause.add("Date >= '" + minDate + "'"); } if (location != null && !location.isEmpty()) { whereClause.add("Location = '" + location + "'"); } //Die Daten werden nach dem Budget absteigend sortiert if (whereClause.size() > 0) { sqlQuery += " WHERE " + StringUtils.join(whereClause, " AND ") + " ORDER BY Budget DESC"; } if (whereClause.size() == 0) { sqlQuery += " ORDER BY Budget DESC"; } resultSet = statement.executeQuery(sqlQuery); int spalten = resultSet.getMetaData().getColumnCount(); System.out.println("Anzahl Spalten: " + spalten); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); Element results = doc.createElement("Results"); doc.appendChild(results); connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/location?autoReconnect=true&useSSL=false", "root", "dreamhigh"); ResultSetMetaData rsmd = resultSet.getMetaData(); int colCount = rsmd.getColumnCount(); while (resultSet.next()) { String[] str = new String[6]; for (int k = 1; k <= spalten; k++) { str[k - 1] = resultSet.getString(k); if (result1.contains(str) == false) { result1.add(str); } } } //HTML Datei wird mit Hilfe von String Builder erzeugt sb.append("<html><body>"); for (Iterator iter = result1.iterator(); iter.hasNext();) { String[] str = (String[]) iter.next(); sb.append("<br>"); sb.append("<br>"); for (int i = 0; i < str.length; i++) { sb.append(System.lineSeparator()); if (i == 0) { sb.append("Link : <a href=" + str[i] + ">" + str[i] + "</a><br>"); } if (i == 1) { sb.append("Budget : " + str[i] + "<br>"); } if (i == 2) { sb.append("Location : " + str[i] + "<br>"); } if (i == 3) { sb.append("Qm : " + str[i] + "<br>"); } if (i == 4) { sb.append("Room : " + str[i] + "<br>"); } if (i == 5) { sb.append("Date : " + str[i] + "<br>"); } } } sb.append("</body>"); sb.append("</html>"); outPut = sb.toString(); } catch (SQLException e) { System.out.println("Fehler bei Tabellenabfrage: " + e); } return outPut = sb.toString(); }
From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java
private String compareDate(Budget budget, Date periodStartDate, Date periodEndDate, Date previousPeriodEndDate) { String returnErrorValue = null; LOG.info("prd st dt " + periodStartDate.getTime() + periodEndDate.getTime() + budget.getStartDate().getTime() + budget.getEndDate().getTime()); Date budgetEndDate = new Date(budget.getBudgetEndDate().getTime()); Date budgetStartDate = new Date(budget.getBudgetStartDate().getTime()); if (periodStartDate.after(budgetEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PROJECT_END" + periodStartDate + budget.getEndDate()); returnErrorValue = "ERROR_PERIOD_START_AFTER_PROJECT_END"; } else if (periodStartDate.before(budgetStartDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PROJECT_START" + periodStartDate + budget.getStartDate()); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (periodEndDate.before(budget.getStartDate())) { LOG.info("ERROR_PERIOD_END_BEFORE_PROJECT_START" + periodEndDate + budget.getStartDate()); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PROJECT_START"; } else if (periodEndDate.after(budgetEndDate)) { LOG.info("ERROR_PERIOD_END_AFTER_PROJECT_END" + periodEndDate + budget.getEndDate()); returnErrorValue = "ERROR_PERIOD_END_AFTER_PROJECT_END"; } else if (periodStartDate.after(periodEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PERIOD_END" + periodStartDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_START_AFTER_PERIOD_END"; } else if (previousPeriodEndDate != null && !periodStartDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodStartDate); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PREVIOUS_END"; } else if (previousPeriodEndDate != null && !periodEndDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_END_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PREVIOUS_END"; }//from w w w . ja v a2 s. com return returnErrorValue; }
From source file:edu.harvard.i2b2.ontology.dao.GetNameInfoDao.java
public List findNameInfo(final VocabRequestType vocabType, List categories, ProjectType projectInfo, final String dbType) throws DataAccessException { DataSource ds = null;//from ww w .j av a2 s . c o m try { ds = OntologyUtil.getInstance().getDataSource("java:OntologyLocalDS"); } catch (I2B2Exception e2) { log.error(e2.getMessage()); } SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds); // find return parameters String parameters = DEFAULT; if (vocabType.getType().equals("core")) { parameters = CORE; } else if (vocabType.getType().equals("all")) { parameters = ALL; } if (vocabType.isBlob() == true) parameters = parameters + BLOB; //extract table code String tableCd = vocabType.getCategory(); // table code to table name conversion // Get metadata schema name from properties file. String metadataSchema = ""; try { metadataSchema = OntologyUtil.getInstance().getMetaDataSchemaName(); } catch (I2B2Exception e1) { log.error(e1.getMessage()); } // table code to table name conversion String tableSql = "select distinct(c_table_name) from " + metadataSchema + "table_access where c_table_cd = ? "; ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = (rs.getString("c_table_name")); return name; } }; String table = jt.queryForObject(tableSql, map, tableCd); String nameInfoSql = null; String compareName = null; if (vocabType.getMatchStr().getStrategy().equals("exact")) { nameInfoSql = "select " + parameters + " from " + metadataSchema + table + " where upper(c_name) = ? "; compareName = vocabType.getMatchStr().getValue().toUpperCase(); } else if (vocabType.getMatchStr().getStrategy().equals("left")) { nameInfoSql = "select " + parameters + " from " + metadataSchema + table + " where upper(c_name) like ? "; compareName = vocabType.getMatchStr().getValue().toUpperCase() + "%"; } else if (vocabType.getMatchStr().getStrategy().equals("right")) { nameInfoSql = "select " + parameters + " from " + metadataSchema + table + " where upper(c_name) like ? "; compareName = "%" + vocabType.getMatchStr().getValue().toUpperCase(); } else if (vocabType.getMatchStr().getStrategy().equals("contains")) { nameInfoSql = "select " + parameters + " from " + metadataSchema + table + " where upper(c_name) like ? "; compareName = "%" + vocabType.getMatchStr().getValue().toUpperCase() + "%"; } String hidden = ""; if (vocabType.isHiddens() == false) hidden = " and c_visualattributes not like '_H%'"; String synonym = ""; if (vocabType.isSynonyms() == false) synonym = " and c_synonym_cd = 'N'"; nameInfoSql = nameInfoSql + hidden + synonym + " order by c_name "; final boolean obfuscatedUserFlag = Roles.getInstance().isRoleOfuscated(projectInfo); ParameterizedRowMapper<ConceptType> mapper = new ParameterizedRowMapper<ConceptType>() { public ConceptType mapRow(ResultSet rs, int rowNum) throws SQLException { ConceptType entry = new ConceptType(); entry.setName(rs.getString("c_name")); if (!(vocabType.getType().equals("default"))) { entry.setKey(rs.getString("c_fullname")); entry.setBasecode(rs.getString("c_basecode")); entry.setLevel(rs.getInt("c_hlevel")); entry.setSynonymCd(rs.getString("c_synonym_cd")); entry.setVisualattributes(rs.getString("c_visualattributes")); Integer totalNum = rs.getInt("c_totalnum"); if (obfuscatedUserFlag == false) { entry.setTotalnum(totalNum); } entry.setFacttablecolumn(rs.getString("c_facttablecolumn")); entry.setTablename(rs.getString("c_tablename")); entry.setColumnname(rs.getString("c_columnname")); entry.setColumndatatype(rs.getString("c_columndatatype")); entry.setOperator(rs.getString("c_operator")); entry.setDimcode(rs.getString("c_dimcode")); entry.setTooltip(rs.getString("c_tooltip")); } if (vocabType.isBlob() == true) { if (rs.getClob("c_comment") == null) entry.setComment(null); else { try { if (dbType.equals("POSTGRESQL")) entry.setComment(rs.getString("c_comment")); else entry.setComment(JDBCUtil.getClobString(rs.getClob("c_comment"))); } catch (IOException e1) { log.error(e1.getMessage()); entry.setComment(null); } } if (rs.getClob("c_metadataxml") == null) { entry.setMetadataxml(null); } else { String c_xml = null; try { if (dbType.equals("POSTGRESQL")) c_xml = rs.getString("c_comment"); else c_xml = JDBCUtil.getClobString(rs.getClob("c_metadataxml")); } catch (IOException e1) { log.error(e1.getMessage()); entry.setMetadataxml(null); } if ((c_xml != null) && (c_xml.trim().length() > 0) && (!c_xml.equals("(null)"))) { SAXBuilder parser = new SAXBuilder(); java.io.StringReader xmlStringReader = new java.io.StringReader(c_xml); Element rootElement = null; try { org.jdom.Document metadataDoc = parser.build(xmlStringReader); org.jdom.output.DOMOutputter out = new DOMOutputter(); Document doc = out.output(metadataDoc); rootElement = doc.getDocumentElement(); } catch (JDOMException e) { log.error(e.getMessage()); entry.setMetadataxml(null); } catch (IOException e1) { log.error(e1.getMessage()); entry.setMetadataxml(null); } if (rootElement != null) { XmlValueType xml = new XmlValueType(); xml.getAny().add(rootElement); entry.setMetadataxml(xml); } } else { entry.setMetadataxml(null); } } } if ((vocabType.getType().equals("all"))) { DTOFactory factory = new DTOFactory(); // make sure date isnt null before converting to XMLGregorianCalendar Date date = rs.getDate("update_date"); if (date == null) entry.setUpdateDate(null); else entry.setUpdateDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("download_date"); if (date == null) entry.setDownloadDate(null); else entry.setDownloadDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("import_date"); if (date == null) entry.setImportDate(null); else entry.setImportDate(factory.getXMLGregorianCalendar(date.getTime())); entry.setSourcesystemCd(rs.getString("sourcesystem_cd")); entry.setValuetypeCd(rs.getString("valuetype_cd")); } return entry; } }; List queryResult = null; try { queryResult = jt.query(nameInfoSql, mapper, compareName); } catch (DataAccessException e) { log.error(e.getMessage()); throw e; } log.debug("result size = " + queryResult.size()); // Fix the key so it equals "\\tableCd\fullname" if (queryResult != null) { Iterator itr = queryResult.iterator(); while (itr.hasNext()) { ConceptType entry = (ConceptType) itr.next(); entry.setKey("\\\\" + tableCd + entry.getKey()); } } return queryResult; }
From source file:edu.harvard.i2b2.ontology.dao.GetChildrenDao.java
public List findChildrenByParent(final GetChildrenType childrenType, final List categories, final ProjectType projectInfo) throws DataAccessException { DataSource ds = null;/*w w w . ja v a 2s. c o m*/ try { ds = OntologyUtil.getInstance().getDataSource("java:OntologyLocalDS"); } catch (I2B2Exception e2) { log.error(e2.getMessage()); } SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds); // find return parameters String parameters = DEFAULT; if (childrenType.getType().equals("core")) { parameters = CORE; } else if (childrenType.getType().equals("all")) { parameters = ALL; } if (childrenType.isBlob() == true) parameters = parameters + BLOB; //extract table code String tableCd = StringUtil.getTableCd(childrenType.getParent()); // table code to table name conversion // Get metadata schema name from properties file. String metadataSchema = ""; try { metadataSchema = OntologyUtil.getInstance().getMetaDataSchemaName(); } catch (I2B2Exception e1) { log.error(e1.getMessage()); } String tableSql = "select distinct(c_table_name) from " + metadataSchema + "table_access where c_table_cd = ? "; ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = (rs.getString("c_table_name")); return name; } }; String tableName = jt.queryForObject(tableSql, map, tableCd); String path = StringUtil.getPath(childrenType.getParent()); String searchPath = path + "%"; // Lookup to get chlevel + 1 --- dont allow synonyms so we only get one result back String levelSql = "select c_hlevel from " + metadataSchema + tableName + " where c_fullname like ? and c_synonym_cd = 'N'"; int level = 0; try { level = jt.queryForInt(levelSql, path); } catch (DataAccessException e1) { // should only get 1 result back (path == c_fullname which should be unique) log.error(e1.getMessage()); throw e1; } String hidden = ""; if (childrenType.isHiddens() == false) hidden = " and c_visualattributes not like '_H%'"; String synonym = ""; if (childrenType.isSynonyms() == false) synonym = " and c_synonym_cd = 'N'"; String sql = "select " + parameters + " from " + metadataSchema + tableName + " where c_fullname like ? and c_hlevel = ? "; sql = sql + hidden + synonym + " order by c_name "; // log.info(sql + path + level); final boolean obfuscatedUserFlag = Roles.getInstance().isRoleOfuscated(projectInfo); ParameterizedRowMapper<ConceptType> mapper = new ParameterizedRowMapper<ConceptType>() { public ConceptType mapRow(ResultSet rs, int rowNum) throws SQLException { ConceptType child = new ConceptType(); child.setName(rs.getString("c_name")); child.setBasecode(rs.getString("c_basecode")); child.setLevel(rs.getInt("c_hlevel")); child.setKey(rs.getString("c_fullname")); child.setSynonymCd(rs.getString("c_synonym_cd")); child.setVisualattributes(rs.getString("c_visualattributes")); Integer totalNum = rs.getInt("c_totalnum"); if (obfuscatedUserFlag == false) { child.setTotalnum(totalNum); } child.setFacttablecolumn(rs.getString("c_facttablecolumn")); child.setTablename(rs.getString("c_tablename")); child.setColumnname(rs.getString("c_columnname")); child.setColumndatatype(rs.getString("c_columndatatype")); child.setOperator(rs.getString("c_operator")); child.setDimcode(rs.getString("c_dimcode")); child.setTooltip(rs.getString("c_tooltip")); if (childrenType.isBlob() == true) { try { if (rs.getClob("c_comment") == null) child.setComment(null); else child.setComment(JDBCUtil.getClobString(rs.getClob("c_comment"))); } catch (IOException e) { log.error(e.getMessage()); child.setComment(null); } if (rs.getClob("c_metadataxml") == null) { child.setMetadataxml(null); } else { String c_xml = null; try { c_xml = JDBCUtil.getClobString(rs.getClob("c_metadataxml")); } catch (IOException e) { log.error(e.getMessage()); child.setMetadataxml(null); } if ((c_xml != null) && (c_xml.trim().length() > 0) && (!c_xml.equals("(null)"))) { SAXBuilder parser = new SAXBuilder(); java.io.StringReader xmlStringReader = new java.io.StringReader(c_xml); Element rootElement = null; try { org.jdom.Document metadataDoc = parser.build(xmlStringReader); org.jdom.output.DOMOutputter out = new DOMOutputter(); Document doc = out.output(metadataDoc); rootElement = doc.getDocumentElement(); } catch (JDOMException e) { log.error(e.getMessage()); child.setMetadataxml(null); } catch (IOException e1) { log.error(e1.getMessage()); child.setMetadataxml(null); } if (rootElement != null) { XmlValueType xml = new XmlValueType(); xml.getAny().add(rootElement); child.setMetadataxml(xml); } } else { child.setMetadataxml(null); } } } if ((childrenType.getType().equals("all"))) { DTOFactory factory = new DTOFactory(); // make sure date isnt null before converting to XMLGregorianCalendar Date date = rs.getDate("update_date"); if (date == null) child.setUpdateDate(null); else child.setUpdateDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("download_date"); if (date == null) child.setDownloadDate(null); else child.setDownloadDate(factory.getXMLGregorianCalendar(date.getTime())); date = rs.getDate("import_date"); if (date == null) child.setImportDate(null); else child.setImportDate(factory.getXMLGregorianCalendar(date.getTime())); child.setSourcesystemCd(rs.getString("sourcesystem_cd")); child.setValuetypeCd(rs.getString("valuetype_cd")); } return child; } }; //log.info(sql + " " + path + " " + level); List queryResult = null; try { queryResult = jt.query(sql, mapper, searchPath, (level + 1)); } catch (DataAccessException e) { log.error(e.getMessage()); throw e; } log.debug("result size = " + queryResult.size()); // Fix the key so it equals "\\tableCd\fullname" if (queryResult != null) { Iterator it = queryResult.iterator(); while (it.hasNext()) { ConceptType child = (ConceptType) it.next(); child.setKey("\\\\" + tableCd + child.getKey()); } } return queryResult; // tested statement with aqua data studio verified output from above against this. // select c_fullname, c_name, c_synonym_cd, c_visualattributes from metadata.testrpdr // where c_fullname like '\RPDR\Diagnoses\Circulatory system (390-459)\Arterial vascular disease (440-447)\(446) Polyarteritis nodosa and al%' // and c_hlevel = 5 and c_visualattributes not like '_H%' and c_synonym_cd = 'N' // verified both with and without hiddens and synonyms. // clob test level = 4 // <parent>\\testrpdr\RPDR\HealthHistory\PHY\Health Maintenance\Mammogram\Mammogram - Deferred</parent> }