List of usage examples for org.joda.time LocalDateTime now
public static LocalDateTime now()
ISOChronology
in the default time zone. From source file:org.filteredpush.qc.date.DwCEventDQ.java
License:Apache License
/** * Given a year, evaluate whether that year falls in the range between a provided lower bound and the current * year, inclusive of the lower bound and the current year. If null is provided for lowerBound, then the value * 1700 will be used as the lower bound. This implementation uses the year from the local date/time as the upper * bound, and will give different answers for values of year within 1 of the current year when run in different * time zones within one day of a year boundary (i.e. this test is not suitable for fine grained evaluations of * time)./*from w w w .j ava2s. c om*/ * * TG2-VALIDATION_YEAR_OUTOFRANGE * * @param year to evaluate * @param lowerBound integer for lower bound of range of in range years, if null 1700 will be used. * @return an DQValidationResponse object describing whether the provided value is in range. */ @Provides(value = "urn:uuid:ad0c8855-de69-4843-a80c-a5387d20fbc8") // GUID for DAY_INVALID/DAY_IN_RANGE @Validation(label = "VALIDATION_YEAR_OUTOFRANGE", description = "The value of dwc:year is between a designated minimum value and the current year, inclusive") @Specification(value = "The value of dwc:year is between a designated minimum value and the current year, inclusive The value of dwc:year is a number.") public static DQResponse<ComplianceValue> isYearInRange(@ActedUpon(value = "dwc:year") String year, @Parameter(name = "validationYearLowerBound") Integer lowerBound) { DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>(); if (lowerBound == null) { lowerBound = 1700; } Integer upperBound = LocalDateTime.now().getYear(); if (DateUtils.isEmpty(year)) { result.addComment("No value provided for dwc:year."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { try { int numericYear = Integer.parseInt(year.trim()); if (numericYear < lowerBound || numericYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:year '" + year + "' is not an integer in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:year '" + year + "' is an integer in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } result.setResultState(ResultState.RUN_HAS_RESULT); } catch (NumberFormatException e) { logger.debug(e.getMessage()); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); result.addComment("Unable to parse dwc:year as an integer:" + e.getMessage()); } } return result; }
From source file:org.filteredpush.qc.date.DwCEventDQ.java
License:Apache License
/** * Given an eventDate check to see if that event date falls entirely outside a range from a * specified lower bound (1700-01-01 by default) and the present. * //from w ww . j a va 2 s. c om * TODO: This may or may not be consistent with the standard test, current implementation here fails * only if the eventDate has no overlap with the lowerBound to the present, not if the eventDate has * any overlap outside the lowerBound to the present. * TG2-VALIDATION_EVENTDATE_OUTOFRANGE ? probably not * * * @param eventDate to check * @param lowerBound integer representing the year to use as the lower boundary, if null, then uses 1700 * @param useLowerBound if false, no lower limit, otherwise uses supplied lower bound. * @return an DQValidationResponse object describing whether the provided value is in range. */ @Provides(value = "urn:uuid:bc8d1ffb-d074-4b4b-919c-f0c8fbe1a618") // new guid, probably not the test as specified @Validation(label = "VALIDATION_EVENTDATE_WHOLLYOUTOFRANGE", description = "The range of dwc:eventDate does not fall entirely into the future and optionally does not fall entirely before a date designated when the test is run") @Specification(value = "The range of dwc:eventDate is not entirely the future and optionally does not entirely fall before a date designated when the test is run The field dwc:eventDate is not EMPTY.") public static DQResponse<ComplianceValue> isEventDateInRange( @ActedUpon(value = "dwc:eventDate") String eventDate, @Parameter(name = "whollyOutOfRangeLowerBound") Integer lowerBound, @Parameter(name = "whollyOutOfRangeUseLowerBound") Boolean useLowerBound) { DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>(); // TODO: Implementation may be too tightly bound to year, may need to extract first/last day for finer granularity test if (lowerBound == null) { lowerBound = 1700; } if (useLowerBound == null) { useLowerBound = true; } Integer upperBound = LocalDateTime.now().getYear(); if (DateUtils.isEmpty(eventDate)) { result.addComment("No value provided for dwc:eventDate."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { if (!DateUtils.eventDateValid(eventDate)) { result.addComment( "Value provided for dwc:eventDate [" + eventDate + "] not recognized as a valid date."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { int startYear = 0; Interval interval = DateUtils.extractInterval(eventDate); if (DateUtils.isRange(eventDate)) { int endYear = interval.getEnd().getYear(); startYear = interval.getStart().getYear(); if (useLowerBound) { if (endYear < lowerBound || startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is not a range spanning part of the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { if (startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is not a range spanning part of the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } } else { startYear = interval.getStart().getYear(); if (useLowerBound) { if (startYear < lowerBound || startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { if (startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is not after " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is after " + upperBound.toString() + " (current year)."); } } } result.setResultState(ResultState.RUN_HAS_RESULT); } } return result; }
From source file:org.filteredpush.qc.date.DwCEventDQ.java
License:Apache License
/** * Given an eventDate check to see if that event date crosses outside a range from a * specified lower bound (1700-01-01 by default) and the present. * //w w w . j av a 2 s. c om * TODO: This may or may not be consistent with the standard test * TG2-VALIDATION_EVENTDATE_OUTOFRANGE * * * @param eventDate to check * @param lowerBound integer representing the year to use as the lower boundary, if null, then uses 1700 * @param useLowerBound if false, no lower limit, otherwise uses supplied lower bound. * @return an DQValidationResponse object describing whether the provided value is in range. */ @Provides(value = "urn:uuid:3cff4dc4-72e9-4abe-9bf3-8a30f1618432") @Validation(label = "VALIDATION_EVENTDATE_EXTENDSOUTOFRANGE", description = "The range of dwc:eventDate does not extend into the future and optionally does not extend before a date designated when the test is run") @Specification(value = "The range of dwc:eventDate does not extend into the future and optionally does not extend before a date designated when the test is run The field dwc:eventDate is not EMPTY.") public static DQResponse<ComplianceValue> isEventDateAtAllInRange( @ActedUpon(value = "dwc:eventDate") String eventDate, @Parameter(name = "extendsOutOfRangeLowerBound") Integer lowerBound, @Parameter(name = "extendsOutOfRangeUseLowerBound") Boolean useLowerBound) { DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>(); // TODO: Implementation may be too tightly bound to year, may need to extract first/last day for finer granularity test if (lowerBound == null) { lowerBound = 1700; } if (useLowerBound == null) { useLowerBound = true; } Integer upperBound = LocalDateTime.now().getYear(); if (DateUtils.isEmpty(eventDate)) { result.addComment("No value provided for dwc:eventDate."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { if (!DateUtils.eventDateValid(eventDate)) { result.addComment( "Value provided for dwc:eventDate [" + eventDate + "] not recognized as a valid date."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { int startYear = 0; Interval interval = DateUtils.extractInterval(eventDate); if (DateUtils.isRange(eventDate)) { int endYear = interval.getEnd().getYear(); startYear = interval.getStart().getYear(); if (endYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' extends outside the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { if (useLowerBound) { if (startYear < lowerBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' extends outside the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } } else { startYear = interval.getStart().getYear(); if (useLowerBound) { if (startYear < lowerBound || startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { if (startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is not after " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is after " + upperBound.toString() + " (current year)."); } } } result.setResultState(ResultState.RUN_HAS_RESULT); } } return result; }
From source file:org.mifosplatform.infrastructure.dataqueries.domain.DashboardMetrics.java
License:Mozilla Public License
public DashboardMetrics(final BigDecimal metricValue, final String metricName, final Long officeId, final Long staffId, final String monthYear) { this.metricValue = metricValue; this.metricName = metricName; this.runDate = LocalDateTime.now().toDate(); this.officeId = officeId; this.staffId = staffId; this.monthYear = monthYear; }
From source file:org.mobicents.servlet.restcomm.RvdProjectsMigrator.java
License:Open Source License
private String getTimeStamp() { LocalDateTime date = LocalDateTime.now(); DateTimeZone tz = DateTimeZone.getDefault(); return new Timestamp(date.toDateTime(tz).toDateTime(DateTimeZone.UTC).getMillis()).toString(); }
From source file:org.multibit.viewsystem.swing.WalletAssetSummaryTableModel.java
License:MIT License
@Override public Object getValueAt(int row, int column) { WalletAssetTableData rowObj = null;/*from w w w. ja v a 2 s .c om*/ if (row >= 0 && row < walletAssetData.size()) { rowObj = walletAssetData.get(row); } if (rowObj == null) { return null; } CSBitcoinAssetTableData btcObj = null; boolean isBitcoin = (rowObj instanceof CSBitcoinAssetTableData); if (isBitcoin) { btcObj = (CSBitcoinAssetTableData) rowObj; } CSAsset asset = rowObj.getAsset(); CSAsset.CSAssetState assetState = CSAsset.CSAssetState.INVALID; if (asset != null) { assetState = asset.getAssetState(); } //boolean noDetailsFlag = assetState. // NOTE: If asset is null, this should be the Bitcoin object. /* Get the balance and spendable balance of the asset. */ boolean showAssetSpendableFlag = false; boolean showAssetUpdatingNowFlag = false; Wallet wallet = bitcoinController.getModel().getActiveWallet(); Wallet.CoinSpark.AssetBalance assetBalance = null; if (asset != null) { int id = asset.getAssetID(); assetBalance = wallet.CS.getAssetBalance(id); showAssetSpendableFlag = (assetBalance.total.compareTo(assetBalance.spendable) != 0); showAssetUpdatingNowFlag = assetBalance.updatingNow; } int threshold = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; String sendAssetWithJustOneConfirmation = controller.getModel() .getUserPreference("sendAssetWithJustOneConfirmation"); if (Boolean.TRUE.toString().equals(sendAssetWithJustOneConfirmation)) { threshold = 1; } int lastHeight = 0; if (wallet != null) lastHeight = wallet.getLastBlockSeenHeight(); int numConfirms = 0; CoinSparkAssetRef assetRef = null; if (asset != null) assetRef = asset.getAssetReference(); if (assetRef != null) { int blockIndex = (int) assetRef.getBlockNum(); numConfirms = lastHeight - blockIndex + 1; // 0 means no confirmation, 1 is yes for sa } int numConfirmsStillRequired = threshold - numConfirms; // Switch on string, makes it easier for us to re-order columns without // having to reorganize the case statements. // http://stackoverflow.com/questions/338206/switch-statement-with-strings-in-java switch (COLUMN_HEADER_KEYS[column]) { case COLUMN_DESCRIPTION: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } // is the symbol industry group wants to use in 2014. // If there is no tooltip, no description, than dont show icon. String s = asset.getDescription(); if (s != null && !"".equals(s)) { String units = asset.getUnits(); // mandatory field but we are getting null sometimes if (units != null) { s = s + "<br><br>1 unit = " + units; } ImageIcon icon = ImageLoader.fatCow16(ImageLoader.FATCOW.information); map.put("icon", icon); map.put("tooltip", s); } ; return map; } case COLUMN_ISSUER: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } String issuerName = asset.getIssuer(); if (issuerName != null) { ImageIcon icon = ImageLoader.fatCow16(ImageLoader.FATCOW.ceo); map.put("icon", icon); String tip = "Asset issued by " + asset.getIssuer(); map.put("tooltip", tip); } return map; } case COLUMN_SPENDABLE: { HashMap<String, Object> map = new HashMap<>(); String s = ""; if (isBitcoin) { s = btcObj.syncText; if (s == null) { s = btcObj.spendableText; } else { if (btcObj.syncPercentText != null) { s = s + " " + btcObj.syncPercentText; } } //if (btcObj.syncPercentToolTipText) if (s == null) { s = ""; } } else if (asset != null && showAssetSpendableFlag) { s = "(" + CSMiscUtils.getFormattedDisplayStringForRawUnits(asset, assetBalance.spendable) + " spendable)"; } // Replace asset spendable flag if new asset needs more confirmaions // and this asset is almost ready to be sent i.e. has name, quantity. // Does not make sense to show this if asset files need to be uploaded. if (!isBitcoin && numConfirmsStillRequired > 0 && asset != null && asset.getName() != null) { int n = numConfirmsStillRequired; // we dont want to show high number if wallet is resyncing from start. if (n > NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD) { n = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; } s = "(Waiting for " + n + " confirmation" + ((n > 1) ? "s)" : ")"); } map.put("label", s); return map; } case COLUMN_EXPIRY: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } String tip = null; Date issueDate = asset.getIssueDate(); if (issueDate != null) { LocalDateTime issueDateTime = new DateTime(issueDate).toLocalDateTime(); tip = "Issued on " + issueDateTime.toString("d MMM y, HH:mm:ss") + "."; } else { tip = "No issue date given."; } Date d = asset.getExpiryDate(); ImageIcon icon = null; String s = null; if (d != null) { LocalDateTime expiryDateTime = new DateTime(d).toLocalDateTime(); tip = tip + " Expires on " + expiryDateTime.toString("d MMM y, HH:mm:ss") + "."; LocalDateTime now = LocalDateTime.now(); //For testing, plusDays and minusDays. //expiryDateTime = now.minusDays(600); Days daysDifference = Days.daysBetween(expiryDateTime, now); //, expiryDateTime); int daysBetween = daysDifference.getDays(); int weeksBetween = daysDifference.toStandardWeeks().getWeeks(); daysBetween = Math.abs(daysBetween); weeksBetween = Math.abs(weeksBetween); String diff = null; if (daysBetween <= 13) { diff = daysBetween + " days"; } else if (weeksBetween <= 12) { diff = weeksBetween + " weeks"; } else { diff = Math.abs(weeksBetween / 4) + " months"; } if (now.compareTo(expiryDateTime) > 0) { s = "Expired " + diff + " ago"; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.skull_old); if (daysBetween <= 7) { s = s + " (" + expiryDateTime.toString("d MMM y h:mm a z") + ")"; } else { s = s + " (" + expiryDateTime.toString("d MMM y") + ")"; } } else { s = "Expires on " + expiryDateTime.toString("d MMM y"); //expiryDateTime.toString("d MMM y, HH:mm:ss") + "."; if (daysBetween <= 30) { // s = "Expires in " + diff; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.fire); // s = s + " (" + expiryDateTime.toString("d MMM, h:mm a z") + ")"; } else { // s = "Expires in " + diff; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.clock); // s = s + " (" + expiryDateTime.toString("d MMM y") + ")"; } } } else { // No expiry date info. icon = null; s = null; tip = null; // If also no issue date info, that means we have not loaded the asset page yet if (issueDate != null) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.thumb_up); s = "Does not expire"; } } // Expired!!! skull icon? thumbs down. map.put("icon", icon); map.put("text", s); map.put("tooltip", tip); return map; } case COLUMN_REFRESH: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; String tip = null; if (assetState == CSAsset.CSAssetState.REFRESH) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.hourglass); tip = "Refreshing..."; } else { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.arrow_refresh_small); tip = "Click to manually refresh the status of the asset"; } map.put("tooltip", tip); map.put("icon", icon); return map; } case COLUMN_QUANTITY: { if (isBitcoin) { String s = btcObj.balanceText; if (s == null) { s = ""; } return s; } if (asset.getName() == null) { return ""; // TODO: Change to webPageJSON==null } String displayString = CSMiscUtils.getFormattedDisplayStringForRawUnits(asset, assetBalance.total); if (showAssetUpdatingNowFlag) { if (assetBalance.total.equals(BigInteger.ZERO) == true) { displayString = "..."; } else { displayString += " + ..."; } } // For debugging, round-trip to see if values match. // BigInteger y = CSMiscUtils.getRawUnitsFromDisplayString(asset, displayString); // System.out.println("DISPLAY: " + displayString + " ----> RAW: " + y); return displayString; } case COLUMN_NAME: { HashMap map = new HashMap<>(); if (isBitcoin) { String s = btcObj.dataChangedText; if (s != null) { // Show important warning that wallet was changed by another process map.put("text", s); StyleRange style = new StyleRange(0, -1, Font.BOLD, Color.RED); map.put("style", style); map.put("tooltip", btcObj.dataChangedToolTipText); } else { map.put("text", "Bitcoin"); //map.put("text2", "(bitcoin.org)"); Font defaultFont = FontSizer.INSTANCE.getAdjustedDefaultFont(); map.put("style", new StyleRange(0, -1, defaultFont.getStyle())); } map.put("noaction", true); // disable action return map; } String name = asset.getNameShort(); // Short name is upto 16 chars, better for small table column. String domain = CSMiscUtils.getDomainHost(asset.getDomainURL()); boolean uploadFiles = false; if (name != null) { map.put("text", name); map.put("text2", "(" + domain + ")"); } else { String s; if (asset.getAssetSource() == CSAsset.CSAssetSource.GENESIS) { s = "Upload files to " + asset.getAssetWebPageURL(); uploadFiles = true; } else { if (domain == null) { s = "Locating new asset.."; } else { s = "Loading new asset from " + domain + "..."; } } map.put("text", s); StyleRange style = new StyleRange(0, -1, Font.PLAIN, Color.RED); map.put("style", style); map.put("noaction", true); // disable action } map.put("tooltip", "Click to visit the asset web page or the home page of the asset issuer."); if (uploadFiles) map.put("tooltip", map.get("text")); // for upload, it's long so show url. return map; } case COLUMN_CONFIRMATION: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; String tip = null; //CoinSparkAssetRef assetRef = asset.getAssetReference(); PeerGroup pg = this.bitcoinController.getMultiBitService().getPeerGroup(); //Wallet wallet = this.bitcoinController.getModel().getActiveWallet(); //int lastHeight = wallet.getLastBlockSeenHeight(); // FIXME: when resyncing, last seen height will be less than genesis block. // Do we have another source of latest block height of testnet3 or production? // txid could be null if user manually adds a bogus asset reference. String txid = asset.getGenTxID(); Transaction tx = null; if (txid != null) { tx = wallet.getTransaction(new Sha256Hash(txid)); } // System.out.println("New? --- asset ref = " + asset.getAssetReference()); // System.out.println(" --- name = " + asset.getName()); // System.out.println(" --- transaction = " + tx); // System.out.println(" --- CSAsset has txid = " + txid); // System.out.println(" --- CSAsset has genesis = " + asset.getGenesis()); // tx can be null. // trying to find block, not found, // A regular CoinSpark transaction, where the wallet does not have the blockheader // for genesis transaction, must get the block, and get the transaction at the // index mentioned in asset ref. if (assetRef != null && tx == null) { final int blockIndex = (int) assetRef.getBlockNum(); final PeerGroup peerGroup = pg; final WalletAssetSummaryTableModel thisModel = this; Block block = blockCache.get(blockIndex); if (block == null) { //System.out.println("FAILED, NEED TO GET BLOCK"); executorService.execute(new Runnable() { @Override public void run() { Block block = peerGroup.getBlock(blockIndex); if (block != null) { blockCache.put(blockIndex, block); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // System.out.println("GOT THE BLOCK SO NOW INFORMING TABLE MODEL OF CHANGE"); thisModel.fireTableDataChanged(); } }); } if (block == null) { /* In a situation where the .spvchain and .fbhchain were deleted, and they need to be recreated, we can get, the following error: ERROR o.coinspark.core.CSBlockHeaderStore - Cannot read block hash, header file too small: block 266131, file size 3840032 */ } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } //System.out.println("getBlock() for asset ref height " + n + " , returned: " + block); if (block != null) { tx = block.getTransactionByOffset((int) assetRef.getTxOffset()); if (tx == null) { // FIXME: We have an asset ref, but cannot get a valid transaction using the asset-ref and checking the genesis block header datda, so this is most likely an invalid asset. // System.out.println("Asset: Cannot find transaction with offset " + (int) assetRef.getTxnOffset() + " in block " + block.getHashAsString()); } } } int txHeight = 0; int numConfirmations = 0; int numBroadcasts = 0; String newAssetString = null; if (tx != null && assetRef != null) { TransactionConfidence confidence = tx.getConfidence(); numBroadcasts = confidence.getBroadcastByCount(); // System.out.println("confidence.getDepthInBlocks() = " + confidence.getDepthInBlocks()); if (confidence.getConfidenceType() == ConfidenceType.BUILDING) { txHeight = confidence.getAppearedAtChainHeight(); } else { // Note: assetRef could be NULL causing exception. txHeight = (int) assetRef.getBlockNum(); } numConfirmations = lastHeight - txHeight + 1; // 0 means no confirmation, 1 is yes for same block. String issueString = null; Date issueDate = asset.getIssueDate(); String sinceString = null; if (issueDate != null) { LocalDateTime issueDateTime = new DateTime(issueDate).toLocalDateTime(); issueString = "Date of issue was " + issueDateTime.toString("d MMM y, HH:mm:ss z"); // Compute the 'minutes/hours/days/weeks ago' string. LocalDateTime now = LocalDateTime.now(); Minutes theDiff = Minutes.minutesBetween(issueDateTime, now); //Days daysDifference = Days.daysBetween(issueDateTime, now); int minutesBetween = theDiff.getMinutes(); int hoursBetween = theDiff.toStandardHours().getHours(); int daysBetween = theDiff.toStandardDays().getDays(); int weeksBetween = theDiff.toStandardWeeks().getWeeks(); minutesBetween = Math.abs(minutesBetween); hoursBetween = Math.abs(hoursBetween); daysBetween = Math.abs(daysBetween); weeksBetween = Math.abs(weeksBetween); if (minutesBetween <= 120) { sinceString = minutesBetween + " minutes"; } else if (hoursBetween <= 48) { sinceString = hoursBetween + " hours"; } else if (daysBetween <= 14) { sinceString = daysBetween + " days"; } else { sinceString = weeksBetween + " weeks"; } } else { // TODO: Find a new issue date, or date of first insert into blockchain? // Transaction.getUpdateTime() first seen // tx.getUpdateTime() issueString = "No issue date given"; } // issue date is null when tx is null, getUpdateTime returning junk. tip = String.format("Issued %s ago, at block height %d, number of confirmations %d (%s)", sinceString, txHeight, numConfirmations, issueString); newAssetString = String.format( "Asset issued only %s ago, caution recommended.<br>Issued at block height %d, number of confirmations %d (%s)", sinceString, txHeight, numConfirmations, issueString); } if (assetRef == null) { // Fix for... GDG Issue 8: If an asset does not yet have an asset ref, the reason can only be that it's a genesis that has not yet been confirmed. icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); tip = "Awaiting new asset confirmation..."; } else if (asset.getName() != null && numConfirmations < 0) { // <= icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); // If the computer is not online, that should be the message StatusEnum state = this.multiBitFrame.getOnlineStatus(); if (state != StatusEnum.ONLINE) { tip = "Waiting to connect to network"; } else { int n = NUMBER_OF_CONFIRMATIONS_TO_SEND_ASSET_THRESHOLD; if (numConfirmsStillRequired < n) n = numConfirmsStillRequired; tip = "Waiting for wallet to sync blocks, need " + n + " more confirmations"; // tip is usually null now. : " + tip; } } else if (tx == null) { // Example: manually add an asset-ref which is bogus. tip = "Searching for the asset's genesis transaction"; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.find); // if (asset.getAssetSource() == CSAsset.CSAssetSource.GENESIS) { // } } else if (assetState == CSAsset.CSAssetState.ASSET_SPECS_NOT_FOUND || assetState == CSAsset.CSAssetState.ASSET_SPECS_NOT_PARSED || assetState == CSAsset.CSAssetState.ASSET_WEB_PAGE_NOT_FOUND || assetState == CSAsset.CSAssetState.REQUIRED_FIELD_MISSING) { tip = "Waiting for asset files to be uploaded."; if (asset.getAssetState() == CSAsset.CSAssetState.REQUIRED_FIELD_MISSING) { tip = "Asset files are missing required data."; } icon = ImageLoader.fatCow16(ImageLoader.FATCOW.server_error); } else if (assetState == CSAsset.CSAssetState.HASH_MISMATCH) { tip = "Caution: asset details do not match what was encoded by issuer.<br><br>" + tip; icon = ImageLoader.fatCow16(ImageLoader.FATCOW.warning); } else if (assetState == CSAsset.CSAssetState.REFRESH) { tip = null; icon = null; // tip = "Refreshing..."; // icon = ImageLoader.fatCow16(ImageLoader.FATCOW.hourglass); } else if (tx != null && asset.getName() != null && numConfirmations >= 1 && numConfirmations < 1008) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.new_new); tip = newAssetString; } else if (tx != null && numConfirmations >= 1008) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.tick_shield); } map.put("tooltip", tip); map.put("icon", icon); return map; } case COLUMN_CONTRACT: { HashMap<String, Object> map = new HashMap<>(); if (isBitcoin) { return map; } ImageIcon icon = null; //null; // TODO: Change to webPageJSON==null String tip = null; if (assetState != CSAsset.CSAssetState.VALID && asset.getContractPath() != null) { //(asset.getName() == null && icon = ImageLoader.fatCow16(ImageLoader.FATCOW.page_white_error); tip = "Click to read the cached copy of the contract"; } else if (assetState == CSAsset.CSAssetState.VALID) { icon = ImageLoader.fatCow16(ImageLoader.FATCOW.page_white_text); tip = "Click to read the contract at the web site of the issuer"; } if (tip != null && icon != null) { map.put("tooltip", tip); map.put("icon", icon); } return map; } // case "walletAssetTableColumn.issuer": // return asset.getIssuer(); // case "walletAssetTableColumn.issueDate": // return asset.getIssueDate(); // case "walletAssetTableColumn.contractUrl": // return asset.getContractUrl(); default: return null; // return rowObj.getDescription(); // case 3: // // Amount in BTC // BigInteger debitAmount = rowObj.getDebit(); // if (debitAmount != null && debitAmount.compareTo(BigInteger.ZERO) > 0) { // return controller.getLocaliser().bitcoinValueToString(debitAmount.negate(), false, true); // } // // BigInteger creditAmount = rowObj.getCredit(); // if (creditAmount != null) { // return controller.getLocaliser().bitcoinValueToString(creditAmount, false, true); // } // // return null; // case 4: // // Amount in fiat // if (rowObj.getDebit() != null && rowObj.getDebit().compareTo(BigInteger.ZERO) > 0) { // Money debitAmountFiat = CurrencyConverter.INSTANCE.convertFromBTCToFiat(rowObj.getDebit()); // if (debitAmountFiat != null) { // return CurrencyConverter.INSTANCE.getFiatAsLocalisedString(debitAmountFiat.negated(), false, false); // } // } // // Money creditAmountFiat = CurrencyConverter.INSTANCE.convertFromBTCToFiat(rowObj.getCredit()); // if (creditAmountFiat != null) { // return CurrencyConverter.INSTANCE.getFiatAsLocalisedString(creditAmountFiat, false, false); // } // // return ""; } }
From source file:org.odk.collect.android.widgets.AbstractDateWidget.java
License:Apache License
protected void setDateToCurrent() { date = LocalDateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
From source file:org.openmrs.module.referencedemodata.ReferenceDemoDataActivator.java
License:Open Source License
private Visit createDemoVisit(Patient patient, List<VisitType> visitTypes, Location location, boolean shortVisit) { LocalDateTime visitStart = LocalDateTime.now().minus(Period.days(randomBetween(0, 365 * 2)).withHours(3)); // past 2 years if (!shortVisit) { visitStart = visitStart.minus(Period.days(ADMISSION_DAYS_MAX + 1)); // just in case the start is today, back it up a few days. }/*from ww w. j a v a 2 s . co m*/ Visit visit = new Visit(patient, randomArrayEntry(visitTypes), visitStart.toDate()); visit.setLocation(location); LocalDateTime vitalsTime = visitStart.plus(Period.minutes(randomBetween(1, 60))); visit.addEncounter(createDemoVitalsEncounter(patient, vitalsTime.toDate())); LocalDateTime visitNoteTime = visitStart.plus(Period.minutes(randomBetween(60, 120))); visit.addEncounter(createVisitNote(patient, visitNoteTime.toDate(), location)); if (shortVisit) { LocalDateTime visitEndTime = visitNoteTime.plus(Period.minutes(30)); visit.setStopDatetime(visitEndTime.toDate()); } else { // admit now and discharge a few days later Location admitLocation = Context.getLocationService().getLocation("Inpatient Ward"); visit.addEncounter(createEncounter("Admission", patient, visitNoteTime.toDate(), admitLocation)); LocalDateTime dischargeDateTime = visitNoteTime .plus(Period.days(randomBetween(ADMISSION_DAYS_MIN, ADMISSION_DAYS_MAX))); visit.addEncounter(createEncounter("Discharge", patient, dischargeDateTime.toDate(), admitLocation)); visit.setStopDatetime(dischargeDateTime.toDate()); } return visit; }
From source file:org.opentestsystem.delivery.testadmin.service.impl.ParticipationSummaryReportServiceImpl.java
License:Open Source License
private ParticipationSummaryReport populateSummaryReport(final Sb11Entity entity, final Sb11Entity parentEntity, final String assessmentId, final long totalStudents, final long optedOutCount, final long scheduledCount, final long startedCount, final long completedCount, final Assessment assessment) { final DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); final String reportDate = dateFormat.print(LocalDateTime.now()); final ParticipationSummaryReport participationReport = new ParticipationSummaryReport(); participationReport.setCurrentDateTime(reportDate); participationReport.setTestName(assessment.getTestName()); participationReport.setTotalCount(totalStudents); participationReport.setScheduledCount(scheduledCount); participationReport.setOptedOutCount(optedOutCount); participationReport.setCompletedCount(completedCount); participationReport.setStartedCount(startedCount); participationReport.setEntityId(entity.getEntityId()); participationReport.setEntityName(entity.getEntityName()); if (entity.getFormatType() != FormatType.CLIENT) { participationReport.setParentEntityType(entity.getParentEntityType()); participationReport.setParentEntityId(parentEntity.getEntityId()); participationReport.setParentEntityName(parentEntity.getEntityName()); }/* w w w . ja v a2s .co m*/ return participationReport; }
From source file:org.owasp.dependencytrack.tasks.NistDataMirrorUpdater.java
License:Open Source License
@Override public void onApplicationEvent(NistDataMirrorUpdateRequestedEvent event) { doUpdates(Calendar.getInstance().get(Calendar.YEAR), LocalDateTime.now()); }