List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:com.google.samples.apps.iosched.gcm.command.NotificationCommand.java
private void processCommand(Context context, NotificationCommandModel command) { // Check format if (!"1.0.00".equals(command.format)) { LOGW(TAG, "GCM notification command has unrecognized format: " + command.format); return;/*w w w . j a v a 2 s. co m*/ } // Check app version if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) { LOGD(TAG, "Command has version range."); int minVersion = 0; int maxVersion = Integer.MAX_VALUE; try { if (!TextUtils.isEmpty(command.minVersion)) { minVersion = Integer.parseInt(command.minVersion); } if (!TextUtils.isEmpty(command.maxVersion)) { maxVersion = Integer.parseInt(command.maxVersion); } LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion); PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); LOGD(TAG, "My version code: " + pinfo.versionCode); if (pinfo.versionCode < minVersion) { LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode + " < " + minVersion); return; } if (pinfo.versionCode > maxVersion) { LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode + " > " + maxVersion); return; } } catch (NumberFormatException ex) { LOGE(TAG, "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion); return; } catch (Exception ex) { LOGE(TAG, "Unexpected problem doing version check.", ex); return; } } // Check if we are the right audience LOGD(TAG, "Checking audience: " + command.audience); if ("remote".equals(command.audience)) { if (SettingsUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site"); return; } else { LOGD(TAG, "Relevant (attendee is remote)."); } } else if ("local".equals(command.audience)) { if (!SettingsUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote."); return; } else { LOGD(TAG, "Relevant (attendee is local)."); } } else if ("all".equals(command.audience)) { LOGD(TAG, "Relevant (audience is 'all')."); } else { LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience); return; } // Check if it expired Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry); if (expiry == null) { LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry); return; } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) { LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString()); return; } else { LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")"); } // decide the intent that will be fired when the user clicks the notification Intent intent; if (TextUtils.isEmpty(command.dialogText)) { // notification leads directly to the URL, no dialog if (TextUtils.isEmpty(command.url)) { intent = new Intent(context, MyScheduleActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); } else { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url)); } } else { // use a dialog intent = new Intent(context, MyScheduleActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE, command.dialogTitle == null ? "" : command.dialogTitle); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE, command.dialogText == null ? "" : command.dialogText); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES, command.dialogYes == null ? "OK" : command.dialogYes); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, command.dialogNo == null ? "" : command.dialogNo); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, command.url == null ? "" : command.url); } final String title = TextUtils.isEmpty(command.title) ? context.getString(R.string.app_name) : command.title; final String message = TextUtils.isEmpty(command.message) ? "" : command.message; // fire the notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_stat_notification).setTicker(command.message) .setContentTitle(title).setContentText(message) //.setColor(context.getResources().getColor(R.color.theme_primary)) // Note: setColor() is available in the support lib v21+. // We commented it out because we want the source to compile // against support lib v20. If you are using support lib // v21 or above on Android L, uncomment this line. .setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)) .setAutoCancel(true).build()); }
From source file:com.meetingcpp.sched.gcm.command.NotificationCommand.java
private void processCommand(Context context, NotificationCommandModel command) { // Check format if (!"1.0.00".equals(command.format)) { LOGW(TAG, "GCM notification command has unrecognized format: " + command.format); return;//from w ww. j a v a2 s . c o m } // Check app version if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) { LOGD(TAG, "Command has version range."); int minVersion = 0; int maxVersion = Integer.MAX_VALUE; try { if (!TextUtils.isEmpty(command.minVersion)) { minVersion = Integer.parseInt(command.minVersion); } if (!TextUtils.isEmpty(command.maxVersion)) { maxVersion = Integer.parseInt(command.maxVersion); } LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion); PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); LOGD(TAG, "My version code: " + pinfo.versionCode); if (pinfo.versionCode < minVersion) { LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode + " < " + minVersion); return; } if (pinfo.versionCode > maxVersion) { LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode + " > " + maxVersion); return; } } catch (NumberFormatException ex) { LOGE(TAG, "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion); return; } catch (Exception ex) { LOGE(TAG, "Unexpected problem doing version check.", ex); return; } } // Check if we are the right audience LOGD(TAG, "Checking audience: " + command.audience); if ("remote".equals(command.audience)) { if (SettingsUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site"); return; } else { LOGD(TAG, "Relevant (attendee is remote)."); } } else if ("local".equals(command.audience)) { if (!SettingsUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote."); return; } else { LOGD(TAG, "Relevant (attendee is local)."); } } else if ("all".equals(command.audience)) { LOGD(TAG, "Relevant (audience is 'all')."); } else { LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience); return; } // Check if it expired Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry); if (expiry == null) { LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry); return; } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) { LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString()); return; } else { LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")"); } // decide the intent that will be fired when the user clicks the notification Intent intent; if (TextUtils.isEmpty(command.dialogText)) { // notification leads directly to the URL, no dialog if (TextUtils.isEmpty(command.url)) { intent = new Intent(context, MyScheduleActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); } else { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url)); } } else { // use a dialog intent = new Intent(context, MyScheduleActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE, command.dialogTitle == null ? "" : command.dialogTitle); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE, command.dialogText == null ? "" : command.dialogText); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES, command.dialogYes == null ? "OK" : command.dialogYes); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, command.dialogNo == null ? "" : command.dialogNo); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, command.url == null ? "" : command.url); } final String title = TextUtils.isEmpty(command.title) ? context.getString(R.string.app_name) : command.title; final String message = TextUtils.isEmpty(command.message) ? "" : command.message; // fire the notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_stat_notification).setTicker(command.message) .setContentTitle(title).setContentText(message) //.setColor(context.getResources().getColor(R.color.theme_primary)) // Note: setColor() is available in the support lib v21+. // We commented it out because we want the source to compile // against support lib v20. If you are using support lib // v21 or above on Android L, uncomment this line. .setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)) .setAutoCancel(true).build()); }
From source file:samples.json.KinesisMessageModel.java
public String getTimenow() { Date currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); return currentTimestamp.toString(); }
From source file:net.alexjf.tmm.activities.MoneyNodeDetailsActivity.java
public void onDateIntervalChanged(Date startDate, Date endDate) { dateIntervalSet = true;//from www. j a v a2 s . co m this.startDate = startDate; this.endDate = endDate; if (startDate != null) { Log.d("TMM", "Selected new date interval: " + startDate.toString() + "-" + endDate.toString()); } else { Log.d("TMM", "Selected new date interval: all time"); } updateData(); }
From source file:com.google.samples.apps.sergio.gcm.command.NotificationCommand.java
private void processCommand(Context context, NotificationCommandModel command) { // Check format if (!"1.0.00".equals(command.format)) { LOGW(TAG, "GCM notification command has unrecognized format: " + command.format); return;// w w w . j a v a2 s . c o m } // Check app version if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) { LOGD(TAG, "Command has version range."); int minVersion = 0; int maxVersion = Integer.MAX_VALUE; try { if (!TextUtils.isEmpty(command.minVersion)) { minVersion = Integer.parseInt(command.minVersion); } if (!TextUtils.isEmpty(command.maxVersion)) { maxVersion = Integer.parseInt(command.maxVersion); } LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion); PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); LOGD(TAG, "My version code: " + pinfo.versionCode); if (pinfo.versionCode < minVersion) { LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode + " < " + minVersion); return; } if (pinfo.versionCode > maxVersion) { LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode + " > " + maxVersion); return; } } catch (NumberFormatException ex) { LOGE(TAG, "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion); return; } catch (Exception ex) { LOGE(TAG, "Unexpected problem doing version check.", ex); return; } } // Check if we are the right audience LOGD(TAG, "Checking audience: " + command.audience); if ("remote".equals(command.audience)) { if (PrefUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site"); return; } else { LOGD(TAG, "Relevant (attendee is remote)."); } } else if ("local".equals(command.audience)) { if (!PrefUtils.isAttendeeAtVenue(context)) { LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote."); return; } else { LOGD(TAG, "Relevant (attendee is local)."); } } else if ("all".equals(command.audience)) { LOGD(TAG, "Relevant (audience is 'all')."); } else { LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience); return; } // Check if it expired Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry); if (expiry == null) { LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry); return; } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) { LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString()); return; } else { LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")"); } // decide the intent that will be fired when the user clicks the notification Intent intent; if (TextUtils.isEmpty(command.dialogText)) { // notification leads directly to the URL, no dialog if (TextUtils.isEmpty(command.url)) { intent = new Intent(context, MyScheduleActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); } else { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url)); } } else { // use a dialog intent = new Intent(context, MyScheduleActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE, command.dialogTitle == null ? "" : command.dialogTitle); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE, command.dialogText == null ? "" : command.dialogText); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES, command.dialogYes == null ? "OK" : command.dialogYes); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, command.dialogNo == null ? "" : command.dialogNo); intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, command.url == null ? "" : command.url); } final String title = TextUtils.isEmpty(command.title) ? context.getString(R.string.app_name) : command.title; final String message = TextUtils.isEmpty(command.message) ? "" : command.message; // fire the notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_stat_notification).setTicker(command.message) .setContentTitle(title).setContentText(message) //.setColor(context.getResources().getColor(R.color.theme_primary)) // Note: setColor() is available in the support lib v21+. // We commented it out because we want the source to compile // against support lib v20. If you are using support lib // v21 or above on Android L, uncomment this line. .setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)) .setAutoCancel(true).build()); }
From source file:com.falcon.hosting.restful.V1.java
@Path("user") @POST// ww w .j a va2s.c o m @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public String getUserDetailInfo(String data) throws JSONException { JSONObject json_object = new JSONObject(data); String email = json_object.getString("email"); User user = service.getUserByEmail(email); Map<String, Object> responsedUser = new HashMap<String, Object>(); responsedUser.put("firstname", user.getFirstname()); responsedUser.put("lastname", user.getLastname()); responsedUser.put("email", user.getEmail()); responsedUser.put("phone", user.getPhoneNumber()); if (user.getDriver() != null) { // driver User Date dob = user.getDriver().getDate_of_birth(); String strDob = ""; if (dob != null) strDob = dob.toString(); // get information responsedUser.put("userType", "driver"); responsedUser.put("dob", strDob); responsedUser.put("bankAccountNumber", user.getDriver().getBankAccountNumber()); responsedUser.put("bankName", user.getDriver().getBankName()); responsedUser.put("userImage", user.getDriver().getImage()); // get address for driver user Address address = user.getDriver().getAddress(); String house = ""; String street = ""; String city = ""; String state = ""; String zipcode = ""; if (address != null) { house = address.getHouse().getNumber(); street = address.getStreet().getName(); city = address.getCity().getName(); state = address.getState().getAbbreviation(); zipcode = "" + address.getZipcode().getZipcode(); } responsedUser.put("house", house); responsedUser.put("street", street); responsedUser.put("city", city); responsedUser.put("state", state); responsedUser.put("zipcode", zipcode); // get jobs related to user List<Job> jobs = user.getDriver().getJobs(); List<Map> jobsList = getJobList(jobs); // get all jobs from this user responsedUser.put("jobs", jobsList); // get current vehicle Vehicle currentVehicle = user.getDriver().getCurrentVehicle(); if (currentVehicle != null) { Map<String, String> currentVehicleMap = new HashMap<String, String>(); currentVehicleMap.put("make", currentVehicle.getMake().getName()); currentVehicleMap.put("model", currentVehicle.getModel().getName()); currentVehicleMap.put("year", "" + currentVehicle.getYear()); currentVehicleMap.put("licensePlate", currentVehicle.getLicensePlateNumber()); currentVehicleMap.put("capacity", "" + currentVehicle.getCapacity()); responsedUser.put("currentVehicle", currentVehicleMap); } // get all user's vehicles except current vehicle List<Vehicle> vehicles = user.getDriver().getVehicles(); vehicles.remove(currentVehicle); List<Map> vehiclesList = new ArrayList<Map>(); if (vehicles != null) { for (Vehicle vehicle : vehicles) { Map<String, String> vehicleMap = new HashMap<String, String>(); vehicleMap.put("make", vehicle.getMake().getName()); vehicleMap.put("model", vehicle.getModel().getName()); vehicleMap.put("year", "" + vehicle.getYear()); vehicleMap.put("licensePlate", vehicle.getLicensePlateNumber()); vehicleMap.put("capacity", "" + vehicle.getCapacity()); vehiclesList.add(vehicleMap); } } responsedUser.put("vehicles", vehiclesList); } else { // customer user Customer customer = user.getCustomer(); responsedUser.put("userType", "customer"); responsedUser.put("creditCardNumber", customer.getCcvNumber()); responsedUser.put("expiration", customer.getExpiration()); responsedUser.put("ccv", customer.getCcvNumber()); responsedUser.put("zipcode", customer.getZipcode() != null ? customer.getZipcode().getZipcode() : 0); List<Job> jobs = customer.getJobs(); List<Map> jobsList = getJobList(jobs); responsedUser.put("jobs", jobsList); } Gson gson = new Gson(); return gson.toJson(responsedUser); }
From source file:com.gst.infrastructure.entityaccess.service.FineractEntityAccessWriteServiceImpl.java
@Override @Transactional//from w w w. jav a 2 s. c o m public CommandProcessingResult createEntityToEntityMapping(Long relId, JsonCommand command) { try { this.fromApiJsonDeserializer.validateForCreate(command.json()); final FineractEntityRelation mapId = this.fineractEntityRelationRepositoryWrapper .findOneWithNotFoundDetection(relId); final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType); final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType); final Date startDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate); final Date endDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate); fromApiJsonDeserializer.checkForEntity(relId.toString(), fromId, toId); if (startDate != null && endDate != null) { if (endDate.before(startDate)) { throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString()); } } final FineractEntityToEntityMapping newMap = FineractEntityToEntityMapping.newMap(mapId, fromId, toId, startDate, endDate); this.fineractEntityToEntityMappingRepository.save(newMap); return new CommandProcessingResultBuilder().withEntityId(newMap.getId()) .withCommandId(command.commandId()).build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:samples.json.KinesisMessageModel.java
public void setTimenow(String timenow) { Date currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); this.timenow = currentTimestamp.toString(); }
From source file:com.emr.utilities.CSVLoader.java
/** * Parse CSV file using OpenCSV library and load in * given database table. //from w w w.java 2s.co m * @param csvFile {@link String} Input CSV file * @param tableName {@link String} Database table name to import data * @param truncateBeforeLoad {@link boolean} Truncate the table before inserting * new records. * @param destinationColumns {@link String[]} Array containing the destination columns */ public void loadCSV(String csvFile, String tableName, boolean truncateBeforeLoad, String[] destinationColumns, List columnsToBeMapped) throws Exception { CSVReader csvReader = null; if (null == this.connection) { throw new Exception("Not a valid connection."); } try { csvReader = new CSVReader(new FileReader(csvFile), this.seprator); } catch (Exception e) { String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e); JOptionPane.showMessageDialog(null, "Error occured while executing file. Error Details: " + stacktrace, "File Error", JOptionPane.ERROR_MESSAGE); throw new Exception("Error occured while executing file. " + stacktrace); } String[] headerRow = csvReader.readNext(); if (null == headerRow) { throw new FileNotFoundException( "No columns defined in given CSV file." + "Please check the CSV file format."); } //Get indices of columns to be mapped List mapColumnsIndices = new ArrayList(); for (Object o : columnsToBeMapped) { String column = (String) o; column = column.substring(column.lastIndexOf(".") + 1, column.length()); int i; for (i = 0; i < headerRow.length; i++) { if (headerRow[i].equals(column)) { mapColumnsIndices.add(i); } } } String questionmarks = StringUtils.repeat("?,", headerRow.length); questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1); String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName); query = query.replaceFirst(KEYS_REGEX, StringUtils.join(destinationColumns, ",")); query = query.replaceFirst(VALUES_REGEX, questionmarks); String log_query = query.substring(0, query.indexOf("VALUES(")); String[] nextLine; Connection con = null; PreparedStatement ps = null; PreparedStatement ps2 = null; PreparedStatement reader = null; ResultSet rs = null; try { con = this.connection; con.setAutoCommit(false); ps = con.prepareStatement(query); File file = new File("sqlite/db"); if (!file.exists()) { file.createNewFile(); } db = new SQLiteConnection(file); db.open(true); //if destination table==person, also add an entry in the table person_identifier //get column indices for the person_id and uuid columns int person_id_column_index = -1; int uuid_column_index = -1; int maxLength = 100; int firstname_index = -1; int middlename_index = -1; int lastname_index = -1; int clanname_index = -1; int othername_index = -1; if (tableName.equals("person")) { int i; ps2 = con.prepareStatement( "insert ignore into person_identifier(person_id,identifier_type_id,identifier) values(?,?,?)"); for (i = 0; i < headerRow.length; i++) { if (headerRow[i].equals("person_id")) { person_id_column_index = i; } if (headerRow[i].equals("uuid")) { uuid_column_index = i; } /*if(headerRow[i].equals("first_name")){ System.out.println("Found firstname index: " + i); firstname_index=i; } if(headerRow[i].equals("middle_name")){ System.out.println("Found firstname index: " + i); middlename_index=i; } if(headerRow[i].equals("last_name")){ System.out.println("Found firstname index: " + i); lastname_index=i; } if(headerRow[i].equals("clan_name")){ System.out.println("Found firstname index: " + i); clanname_index=i; } if(headerRow[i].equals("other_name")){ System.out.println("Found firstname index: " + i); othername_index=i; }*/ } } if (truncateBeforeLoad) { //delete data from table before loading csv try (Statement stmnt = con.createStatement()) { stmnt.execute("DELETE FROM " + tableName); stmnt.close(); } } if (tableName.equals("person")) { try (Statement stmt2 = con.createStatement()) { stmt2.execute( "ALTER TABLE person CHANGE COLUMN first_name first_name VARCHAR(50) NULL DEFAULT NULL AFTER person_guid,CHANGE COLUMN middle_name middle_name VARCHAR(50) NULL DEFAULT NULL AFTER first_name,CHANGE COLUMN last_name last_name VARCHAR(50) NULL DEFAULT NULL AFTER middle_name;"); stmt2.close(); } } final int batchSize = 1000; int count = 0; Date date = null; while ((nextLine = csvReader.readNext()) != null) { if (null != nextLine) { int index = 1; int person_id = -1; String uuid = ""; int identifier_type_id = 3; if (tableName.equals("person")) { reader = con.prepareStatement( "select identifier_type_id from identifier_type where identifier_type_name='UUID'"); rs = reader.executeQuery(); if (!rs.isBeforeFirst()) { //no uuid row //insert it Integer numero = 0; Statement stmt = con.createStatement(); numero = stmt.executeUpdate( "insert into identifier_type(identifier_type_id,identifier_type_name) values(50,'UUID')", Statement.RETURN_GENERATED_KEYS); ResultSet rs2 = stmt.getGeneratedKeys(); if (rs2.next()) { identifier_type_id = rs2.getInt(1); } rs2.close(); stmt.close(); } else { while (rs.next()) { identifier_type_id = rs.getInt("identifier_type_id"); } } } int counter = 1; String temp_log = log_query + "VALUES("; //string to be logged for (String string : nextLine) { //if current index is in the list of columns to be mapped, we apply that mapping for (Object o : mapColumnsIndices) { int i = (int) o; if (index == (i + 1)) { //apply mapping to this column string = applyDataMapping(string); } } if (tableName.equals("person")) { //get person_id and uuid if (index == (person_id_column_index + 1)) { person_id = Integer.parseInt(string); } if (index == (uuid_column_index + 1)) { uuid = string; } } //check if string is a date if (string.matches("\\d{2}-[a-zA-Z]{3}-\\d{4} \\d{2}:\\d{2}:\\d{2}") || string.matches("\\d{2}-[a-zA-Z]{3}-\\d{4}")) { java.sql.Date dt = formatDate(string); temp_log = temp_log + "'" + dt.toString() + "'"; ps.setDate(index++, dt); } else { if ("".equals(string)) { temp_log = temp_log + "''"; ps.setNull(index++, Types.NULL); } else { temp_log = temp_log + "'" + string + "'"; ps.setString(index++, string); } } if (counter < headerRow.length) { temp_log = temp_log + ","; } else { temp_log = temp_log + ");"; System.out.println(temp_log); } counter++; } if (tableName.equals("person")) { if (!"".equals(uuid) && person_id != -1) { ps2.setInt(1, person_id); ps2.setInt(2, identifier_type_id); ps2.setString(3, uuid); ps2.addBatch(); } } ps.addBatch(); } if (++count % batchSize == 0) { ps.executeBatch(); if (tableName.equals("person")) { ps2.executeBatch(); } } } ps.executeBatch(); // insert remaining records if (tableName.equals("person")) { ps2.executeBatch(); } con.commit(); } catch (Exception e) { if (con != null) con.rollback(); if (db != null) db.dispose(); String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e); JOptionPane.showMessageDialog(null, "Error occured while executing file. Error Details: " + stacktrace, "File Error", JOptionPane.ERROR_MESSAGE); throw new Exception("Error occured while executing file. " + stacktrace); } finally { if (null != reader) reader.close(); if (null != ps) ps.close(); if (null != ps2) ps2.close(); if (null != con) con.close(); csvReader.close(); } }
From source file:com.bigbug.android.pp.gcm.command.NotificationCommand.java
private void processCommand(Context context, NotificationCommandModel command) { // Check format if (!"1.0.00".equals(command.format)) { LOGW(TAG, "GCM notification command has unrecognized format: " + command.format); return;/*www . j a v a 2 s .c o m*/ } // Check app version if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) { LOGD(TAG, "Command has version range."); int minVersion = 0; int maxVersion = Integer.MAX_VALUE; try { if (!TextUtils.isEmpty(command.minVersion)) { minVersion = Integer.parseInt(command.minVersion); } if (!TextUtils.isEmpty(command.maxVersion)) { maxVersion = Integer.parseInt(command.maxVersion); } LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion); PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); LOGD(TAG, "My version code: " + pinfo.versionCode); if (pinfo.versionCode < minVersion) { LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode + " < " + minVersion); return; } if (pinfo.versionCode > maxVersion) { LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode + " > " + maxVersion); return; } } catch (NumberFormatException ex) { LOGE(TAG, "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion); return; } catch (Exception ex) { LOGE(TAG, "Unexpected problem doing version check.", ex); return; } } // Check if we are the right audience LOGD(TAG, "Checking audience: " + command.audience); if ("remote".equals(command.audience)) { // if (PrefUtils.isAttendeeAtVenue(context)) { // LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site"); // return; // } else { // LOGD(TAG, "Relevant (attendee is remote)."); // } } else if ("local".equals(command.audience)) { // if (!PrefUtils.isAttendeeAtVenue(context)) { // LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote."); // return; // } else { // LOGD(TAG, "Relevant (attendee is local)."); // } } else if ("all".equals(command.audience)) { LOGD(TAG, "Relevant (audience is 'all')."); } else { LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience); return; } // Check if it expired Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry); if (expiry == null) { LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry); return; } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) { LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString()); return; } else { LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")"); } // decide the intent that will be fired when the user clicks the notification Intent intent; if (TextUtils.isEmpty(command.dialogText)) { // notification leads directly to the URL, no dialog // if (TextUtils.isEmpty(command.url)) { // intent = new Intent(context, MyScheduleActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | // Intent.FLAG_ACTIVITY_SINGLE_TOP); // } else { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url)); // } } else { // use a dialog // intent = new Intent(context, MyScheduleActivity.class).setFlags( // Intent.FLAG_ACTIVITY_CLEAR_TOP | // Intent.FLAG_ACTIVITY_SINGLE_TOP | // Intent.FLAG_ACTIVITY_NEW_TASK | // Intent.FLAG_ACTIVITY_CLEAR_TASK); // intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE, // command.dialogTitle == null ? "" : command.dialogTitle); // intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE, // command.dialogText == null ? "" : command.dialogText); // intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES, // command.dialogYes == null ? "OK" : command.dialogYes); // intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, // command.dialogNo == null ? "" : command.dialogNo); // intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, // command.url == null ? "" : command.url); } final String title = TextUtils.isEmpty(command.title) ? context.getString(R.string.app_name) : command.title; final String message = TextUtils.isEmpty(command.message) ? "" : command.message; // fire the notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_stat_notification).setTicker(command.message) .setContentTitle(title).setContentText(message) //.setColor(context.getResources().getColor(R.color.theme_primary)) // Note: setColor() is available in the support lib v21+. // We commented it out because we want the source to compile // against support lib v20. If you are using support lib // v21 or above on Android L, uncomment this line. // .setContentIntent(PendingIntent.getActivity(context, 0, intent, // PendingIntent.FLAG_CANCEL_CURRENT)) .setAutoCancel(true).build()); }