List of usage examples for java.sql Date valueOf
@SuppressWarnings("deprecation") public static Date valueOf(LocalDate date)
From source file:com.wso2telco.dep.reportingservice.southbound.SbHostObjectUtils.java
/** * Checks if is subscription valid for month. * * @param subAPI the sub api//w ww. j ava 2s .co m * @param year the year * @param month the month * @return true, if is subscription valid for month * @throws APIManagementException the API management exception * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception * @throws BusinessException */ private static boolean isSubscriptionValidForMonth(SubscribedAPI subAPI, String year, String month) throws BusinessException { BillingDAO billingDAO = new BillingDAO(); java.util.Date createdTime; try { createdTime = billingDAO.getSubscriptionCreatedTime(subAPI.getApplication().getId(), subAPI.getApiId()); } catch (Exception e) { throw new BusinessException(ReportingServiceError.INTERNAL_SERVER_ERROR); } Date reportDate = Date.valueOf(year + "-" + month + "-01"); Calendar calendar = Calendar.getInstance(); calendar.setTime(reportDate); // compare created time with 1st day of next month calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); if (createdTime != null) { return createdTime.before(calendar.getTime()); } else { return false; } }
From source file:com.mapr.db.utils.ImportCSV_MR.java
public DBDocument readAndImportCSV(String dataLine) { ArrayList<Object> values = new ArrayList<>(); int countColumnsInData = 0; if (dataLine.endsWith(conf.get("delimiter"))) { dataLine = dataLine.substring(0, dataLine.length() - 1); }//from w w w. ja va 2 s . c om String[] dataList = StringUtils.splitPreserveAllTokens(dataLine, conf.get("delimiter")); for (int i = 0; i < dataList.length; i++) { logger.info("Processing column " + i + " off " + dataList.length); System.out.println("Processing column " + i + " off " + dataList.length); String data = dataList[i]; logger.info("Processing data " + data); System.out.println("Processing data " + data); if (data.isEmpty()) { if (conf.getStrings("valueTypesInSchema")[i] == "String") { data = "null"; } else { data = "0"; } } printSchema(); switch (conf.getStrings("valueTypesInSchema")[i].toLowerCase()) { case "int": case "integer": case "bigint": case "long": values.add(countColumnsInData, Long.valueOf(data)); break; case "float": case "double": values.add(countColumnsInData, Double.valueOf(data)); break; case "date": values.add(countColumnsInData, Date.valueOf(data)); break; default: values.add(countColumnsInData, String.valueOf(data)); break; } countColumnsInData++; } return insertDocument(values, countColumnsInData, conf.get("tablePath")); }
From source file:org.gstplatform.infrastructure.report.service.PentahoReportingProcessServiceImpl.java
private void addParametersToReport(final MasterReport report, final Map<String, String> queryParams) { final AppUser currentUser = this.context.authenticatedUser(); try {//from w w w . ja v a2s .co m final ReportParameterValues rptParamValues = report.getParameterValues(); final ReportParameterDefinition paramsDefinition = report.getParameterDefinition(); /* * only allow integer, long, date and string parameter types and * assume all mandatory - could go more detailed like Pawel did in * Mifos later and could match incoming and pentaho parameters * better... currently assuming they come in ok... and if not an * error */ for (final ParameterDefinitionEntry paramDefEntry : paramsDefinition.getParameterDefinitions()) { final String paramName = paramDefEntry.getName(); if (!((paramName.equals("tenantUrl")) || (paramName.equals("userhierarchy") || (paramName.equals("username")) || (paramName.equals("password") || (paramName.equals("userid")))))) { logger.info("paramName:" + paramName); final String pValue = queryParams.get(paramName); if (StringUtils.isBlank(pValue)) { throw new PlatformDataIntegrityException("error.msg.reporting.error", "Pentaho Parameter: " + paramName + " - not Provided"); } final Class<?> clazz = paramDefEntry.getValueType(); logger.info("addParametersToReport(" + paramName + " : " + pValue + " : " + clazz.getCanonicalName() + ")"); if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Integer")) { rptParamValues.put(paramName, Integer.parseInt(pValue)); } else if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Long")) { rptParamValues.put(paramName, Long.parseLong(pValue)); } else if (clazz.getCanonicalName().equalsIgnoreCase("java.sql.Date")) { rptParamValues.put(paramName, Date.valueOf(pValue)); } else { rptParamValues.put(paramName, pValue); } } } // tenant database name and current user's office hierarchy // passed as parameters to allow multitenant penaho reporting // and // data scoping final FineractPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); final FineractPlatformTenantConnection tenantConnection = tenant.getConnection(); String tenantUrl = driverConfig.constructProtocol(tenantConnection.getSchemaServer(), tenantConnection.getSchemaServerPort(), tenantConnection.getSchemaName()); final String userhierarchy = currentUser.getOffice().getHierarchy(); logger.info("db URL:" + tenantUrl + " userhierarchy:" + userhierarchy); rptParamValues.put("userhierarchy", userhierarchy); final Long userid = currentUser.getId(); logger.info("db URL:" + tenantUrl + " userid:" + userid); rptParamValues.put("userid", userid); rptParamValues.put("tenantUrl", tenantUrl); rptParamValues.put("username", tenantConnection.getSchemaUsername()); rptParamValues.put("password", tenantConnection.getSchemaPassword()); } catch (final Exception e) { logger.error("error.msg.reporting.error:" + e.getMessage()); throw new PlatformDataIntegrityException("error.msg.reporting.error", e.getMessage()); } }
From source file:org.apache.hadoop.hive.serde2.RegexSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { Text rowText = (Text) blob; Matcher m = inputPattern.matcher(rowText.toString()); if (m.groupCount() != numColumns) { throw new SerDeException("Number of matching groups doesn't match the number of columns"); }//from w ww .j av a2s .co m // If do not match, ignore the line, return a row with all nulls. if (!m.matches()) { unmatchedRowsCount++; if (!alreadyLoggedNoMatch) { // Report the row if its the first time LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText); alreadyLoggedNoMatch = true; } return null; } // Otherwise, return the row. for (int c = 0; c < numColumns; c++) { try { String t = m.group(c + 1); TypeInfo typeInfo = columnTypes.get(c); // Convert the column to the correct type when needed and set in row obj PrimitiveTypeInfo pti = (PrimitiveTypeInfo) typeInfo; switch (pti.getPrimitiveCategory()) { case STRING: row.set(c, t); break; case BYTE: Byte b; b = Byte.valueOf(t); row.set(c, b); break; case SHORT: Short s; s = Short.valueOf(t); row.set(c, s); break; case INT: Integer i; i = Integer.valueOf(t); row.set(c, i); break; case LONG: Long l; l = Long.valueOf(t); row.set(c, l); break; case FLOAT: Float f; f = Float.valueOf(t); row.set(c, f); break; case DOUBLE: Double d; d = Double.valueOf(t); row.set(c, d); break; case BOOLEAN: Boolean bool; bool = Boolean.valueOf(t); row.set(c, bool); break; case TIMESTAMP: Timestamp ts; ts = Timestamp.valueOf(t); row.set(c, ts); break; case DATE: Date date; date = Date.valueOf(t); row.set(c, date); break; case DECIMAL: HiveDecimal bd = HiveDecimal.create(t); row.set(c, bd); break; case CHAR: HiveChar hc = new HiveChar(t, ((CharTypeInfo) typeInfo).getLength()); row.set(c, hc); break; case VARCHAR: HiveVarchar hv = new HiveVarchar(t, ((VarcharTypeInfo) typeInfo).getLength()); row.set(c, hv); break; default: throw new SerDeException("Unsupported type " + typeInfo); } } catch (RuntimeException e) { partialMatchedRowsCount++; if (!alreadyLoggedPartialMatch) { // Report the row if its the first row LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, " + " cannot find group " + c + ": " + rowText); alreadyLoggedPartialMatch = true; } row.set(c, null); } } return row; }
From source file:controller.PlayController.java
public List<Play> filterPlays(Play play, List<Play> plays) { Predicate<Play> selector = p -> p != null; String playName = play.getPlayName(); Integer ticketPrice = play.getTicketPrice(); if (playName != null && !playName.equals("")) { selector = selector.and(p -> p.getPlayName().equals(playName)); }// w ww . j av a2s. co m if (play.getStartTime() != null) { Time startTime = Time.valueOf(play.getStartTime().toString()); selector = selector.and(p -> (p.getStartTime().after(startTime) || p.getStartTime().equals(startTime))); } if (play.getEndTime() != null) { Time endTime = Time.valueOf(play.getEndTime().toString()); selector = selector.and(p -> (p.getEndTime().before(endTime) || p.getEndTime().equals(endTime))); } if (play.getStartDate() != null) { Date startDate = Date.valueOf(play.getStartDate().toString()); selector = selector.and(p -> p.getStartDate().equals(startDate)); } if (ticketPrice != 0) { selector = selector.and(p -> p.getTicketPrice() == ticketPrice); } return lambdaFilter(selector, plays); }
From source file:com.mss.msp.util.DateUtility.java
public Date getMysqlDate(String sourceDate) { Date sqlDate = Date .valueOf(new java.text.SimpleDateFormat("yyyy-MM-dd").format(convertStringToMySql(sourceDate))); return sqlDate; }
From source file:app.order.OrderController.java
public void setCheckWithFields(Check check) { check.setName(checkName.getText());// w w w .j av a2 s.c o m check.setAmount(Float.valueOf(checkAmount.getText())); check.setBank(checkBank.getValue()); check.setDueDate(Date.valueOf(checkDueDate.getValue())); if (check.getPaymentState() == null) check.setPaymentState(PaymentState.NONPAYE); }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertStringTypes(Object val, String javaColType) { String valStr = val.toString(); if (javaColType.equals(BIG_DECIMAL_TYPE)) { return new BigDecimal(valStr); } else if (javaColType.equals(DATE_TYPE) || javaColType.equals(TIME_TYPE) || javaColType.equals(TIMESTAMP_TYPE)) { // Oracle expects timestamps for Date also by default based on version // Just allow all date types to be assignment compatible if (valStr.length() == 10 && valStr.matches("^\\d{4}-\\d{2}-\\d{2}$")) { // Date in yyyy-mm-dd format Date d = Date.valueOf(valStr); if (javaColType.equals(DATE_TYPE)) { return d; } else if (javaColType.equals(TIME_TYPE)) { return new Time(d.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(d.getTime()); }//from w w w . j a v a 2s. co m } else if (valStr.length() == 8 && valStr.matches("^\\d{2}:\\d{2}:\\d{2}$")) { // time in hh:mm:ss Time t = Time.valueOf(valStr); if (javaColType.equals(DATE_TYPE)) { return new Date(t.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return t; } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(t.getTime()); } } else if (valStr.length() >= 19 && valStr.length() <= 26 && valStr.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d+)?$")) { // timestamp in yyyy-mm-dd hh:mm:ss Timestamp ts = Timestamp.valueOf(valStr); 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; } } else { return null; } } else if (javaColType.equals(STRING_TYPE)) { return valStr; } else if (javaColType.equals(BOOLEAN_TYPE)) { return Boolean.valueOf(valStr); } else if (javaColType.equals(BYTE_TYPE)) { return Byte.parseByte(valStr); } else if (javaColType.equals(SHORT_TYPE)) { return Short.parseShort(valStr); } else if (javaColType.equals(INTEGER_TYPE)) { return Integer.parseInt(valStr); } else if (javaColType.equals(LONG_TYPE)) { return Long.parseLong(valStr); } else if (javaColType.equals(FLOAT_TYPE)) { return Float.parseFloat(valStr); } else if (javaColType.equals(DOUBLE_TYPE)) { return Double.parseDouble(valStr); } return null; }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processSave(final HttpServletRequest req, final HttpServletResponse resp) { long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from ww w . j av a 2 s . co m } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, null); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } save(schemeId, userName, startDate, endDateExcluded); Long userCount = schemeUserCount(String.valueOf(schemeId)); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Assiging user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); prb.replace("#delete-schema-validation-dialog", (writer) -> { DeleteSchemaValidationComponent.INSTANCE.render(writer, resp.getLocale(), userCount); }); } }
From source file:com.ebay.nest.io.sede.RegexSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { Text rowText = (Text) blob; Matcher m = inputPattern.matcher(rowText.toString()); if (m.groupCount() != numColumns) { throw new SerDeException("Number of matching groups doesn't match the number of columns"); }//from ww w .j a v a 2s . c o m // If do not match, ignore the line, return a row with all nulls. if (!m.matches()) { unmatchedRowsCount++; if (!alreadyLoggedNoMatch) { // Report the row if its the first time LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText); alreadyLoggedNoMatch = true; } return null; } // Otherwise, return the row. for (int c = 0; c < numColumns; c++) { try { String t = m.group(c + 1); TypeInfo typeInfo = columnTypes.get(c); String typeName = typeInfo.getTypeName(); // Convert the column to the correct type when needed and set in row obj if (typeName.equals(serdeConstants.STRING_TYPE_NAME)) { row.set(c, t); } else if (typeName.equals(serdeConstants.TINYINT_TYPE_NAME)) { Byte b; b = Byte.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.SMALLINT_TYPE_NAME)) { Short s; s = Short.valueOf(t); row.set(c, s); } else if (typeName.equals(serdeConstants.INT_TYPE_NAME)) { Integer i; i = Integer.valueOf(t); row.set(c, i); } else if (typeName.equals(serdeConstants.BIGINT_TYPE_NAME)) { Long l; l = Long.valueOf(t); row.set(c, l); } else if (typeName.equals(serdeConstants.FLOAT_TYPE_NAME)) { Float f; f = Float.valueOf(t); row.set(c, f); } else if (typeName.equals(serdeConstants.DOUBLE_TYPE_NAME)) { Double d; d = Double.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.BOOLEAN_TYPE_NAME)) { Boolean b; b = Boolean.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) { Timestamp ts; ts = Timestamp.valueOf(t); row.set(c, ts); } else if (typeName.equals(serdeConstants.DATE_TYPE_NAME)) { Date d; d = Date.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.DECIMAL_TYPE_NAME)) { HiveDecimal bd; bd = new HiveDecimal(t); row.set(c, bd); } else if (typeInfo instanceof PrimitiveTypeInfo && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory() == PrimitiveCategory.VARCHAR) { VarcharTypeParams varcharParams = (VarcharTypeParams) ParameterizedPrimitiveTypeUtils .getTypeParamsFromTypeInfo(typeInfo); HiveVarchar hv = new HiveVarchar(t, varcharParams != null ? varcharParams.length : -1); row.set(c, hv); } } catch (RuntimeException e) { partialMatchedRowsCount++; if (!alreadyLoggedPartialMatch) { // Report the row if its the first row LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, " + " cannot find group " + c + ": " + rowText); alreadyLoggedPartialMatch = true; } row.set(c, null); } } return row; }