List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:com.FFLive.MySQLConnection.java
public Map<String, List<String>> statusCheck() { Main.log.log(4, "Checking Status of Stored Leagues... "); Map<String, List<String>> incomplete = new HashMap<String, List<String>>(); try {// www . ja va2 s . c o m //Check the status table Statement statement = conn.createStatement(); ResultSet status = statement.executeQuery("SELECT * from status"); Calendar now = Calendar.getInstance(); //Check Status Table for integrity while (status.next()) { int leagueID = status.getInt("LeagueID"); int gw = status.getInt("Gameweek"); Calendar startDate = (new DateParser(status.getString("starts"))).convertDate(); Calendar kickOff = (new DateParser(status.getString("kickOff"))).convertDate(); Calendar endDate = (new DateParser(status.getString("ends"))).convertDate(); Calendar postDate = (new DateParser(status.getString("ends"))).convertDate(); //Add 2 Hours on to make sure match has finished endDate.add(Calendar.HOUR_OF_DAY, 2); startDate.add(Calendar.MINUTE, 30); postDate.add(Calendar.DAY_OF_MONTH, 1); //Check the Times and update the status table if (status.getString("started").equals("Y")) { //GW Has Started, are teams store if (status.getString("teamsStored").equals("Y")) { //Teams Are Stored, has the gameweek now ended if (status.getString("ended").equals("Y")) { //Gameweek has now ended, has the post GW update been done if (status.getString("postGwUpdate").equals("Y")) { //All Done Nothing to Do. } else if (status.getString("postGwUpdate").equals("F")) { //Past the Post GW Update Time so Ignore } //Ended but is after post date? else if (now.after(postDate)) { //After Post Date, queue for post update if (!incomplete.containsKey("post")) { List<String> post = new ArrayList<String>(); post.add(leagueID + "," + gw); incomplete.put("post", post); } else { incomplete.get("post").add(leagueID + "," + gw); } } else { //Not after post date, updated players and scores List<String> prePost = new ArrayList<String>(); prePost.add(Integer.toString(gw)); incomplete.put("prePost", prePost); } } //Gameweek not marked as ended, check if now ended else if (now.after(endDate)) { //Gameweek has now ended, check if after post date if (now.after(postDate)) { //Started and ended, update status table generalStatusUpdate(leagueID, gw, "Y", "Y"); //Now is after post date, update status table and queue for post update if (!incomplete.containsKey("post")) { List<String> post = new ArrayList<String>(); post.add(leagueID + "," + gw); incomplete.put("post", post); } else { incomplete.get("post").add(leagueID + "," + gw); } } else { //Not after post date, update status table and mark to do nothing generalStatusUpdate(leagueID, gw, "Y", "Y"); List<String> prePost = new ArrayList<String>(); prePost.add(Integer.toString(gw)); incomplete.put("prePost", prePost); } } else { //Gameweek has stated but not ended, queue to go live if (!incomplete.containsKey("live")) { List<String> live = new ArrayList<String>(); live.add(leagueID + "," + gw); incomplete.put("live", live); } else { incomplete.get("live").add(leagueID + "," + gw); } } } else { //Gameweek Started but teams not stored, Queue for team update... //Has Gameweek now ended? if (now.after(endDate)) { //Gameweek has now ended, time for post? if (now.after(postDate)) { generalStatusUpdate(leagueID, gw, "Y", "Y"); //Has it already failed a status update if (status.getString("postGwUpdate").equals("F")) { //Therefore no teams but no status update, get teams for that gw if (!incomplete.containsKey("teams")) { List<String> teams = new ArrayList<String>(); teams.add(leagueID + "," + gw); incomplete.put("teams", teams); } else { incomplete.get("teams").add(leagueID + "," + gw); } } else { //After Post, Queue for Post and Update status table if (!incomplete.containsKey("post")) { List<String> post = new ArrayList<String>(); post.add(leagueID + "," + gw); incomplete.put("post", post); } else { incomplete.get("post").add(leagueID + "," + gw); } } } else { //Ended but not after post, queue for teams and update status generalStatusUpdate(leagueID, gw, "Y", "Y"); if (!incomplete.containsKey("teams")) { List<String> teams = new ArrayList<String>(); teams.add(leagueID + "," + gw); incomplete.put("teams", teams); } else { incomplete.get("teams").add(leagueID + "," + gw); } } } else { //Not Ended, Update Status and get teams and go live generalStatusUpdate(leagueID, gw, "Y", "N"); if (!incomplete.containsKey("teams")) { List<String> teams = new ArrayList<String>(); teams.add(leagueID + "," + gw); incomplete.put("teams", teams); } else { incomplete.get("teams").add(leagueID + "," + gw); } if (!incomplete.containsKey("live")) { List<String> live = new ArrayList<String>(); live.add(leagueID + "," + gw); incomplete.put("live", live); } else { incomplete.get("live").add(leagueID + "," + gw); } } } } //Started != Y else if (status.getString("teamsStored").equals("Y")) { //Gameweek not marked as Started, but teams are stored, check if gameweek has now started if (now.after(kickOff)) { //Games Have Kicked off and teams are stored, check if gameweek has ended. if (now.after(endDate)) { //Gameweek has now ended, check if it is time for post update if (now.after(postDate)) { //Now After Post Date, Queue for Post and Update Status Table generalStatusUpdate(leagueID, gw, "Y", "Y"); if (!incomplete.containsKey("post")) { List<String> post = new ArrayList<String>(); post.add(leagueID + "," + gw); incomplete.put("post", post); } else { incomplete.get("post").add(leagueID + "," + gw); } } else { //After End Date, not time for Post, Update Status Table and Update Scores generalStatusUpdate(leagueID, gw, "Y", "Y"); List<String> prePost = new ArrayList<String>(); prePost.add(Integer.toString(gw)); incomplete.put("prePost", prePost); } } else { //Not After End Date, Update Status Table to Started and Queue for Live generalStatusUpdate(leagueID, gw, "Y", "N"); if (!incomplete.containsKey("live")) { List<String> live = new ArrayList<String>(); live.add(leagueID + "," + gw); incomplete.put("live", live); } else { incomplete.get("live").add(leagueID + "," + gw); } } } //Gameweek Not Started, but teams stored, does gameweek start today? else if (startDate.get(Calendar.DAY_OF_MONTH) == now.get(Calendar.DAY_OF_MONTH) && startDate.get(Calendar.MONTH) == now.get(Calendar.MONTH)) { //Gameweek does start today, queue for wait, nothing to update the status with if (!incomplete.containsKey("wait")) { List<String> wait = new ArrayList<String>(); wait.add("Matches to Kick-Off.."); incomplete.put("wait", wait); } else { incomplete.get("wait").add("Matches to Kick-Off.."); } } else { //Else Gameweek does not start today, nothing to do } } //Started != Y and teamStored != Y //Check Dates //Check is after Start Date, if it isnt, then it is pre gameweek and nothing to do else if (now.after(startDate)) { //After StartDate, is after kick off if (now.after(kickOff)) { //After Kick Off, is after End Date? if (now.after(endDate)) { //After End date, is after postUpdate? if (now.after(postDate)) { //After Post Date, Update Status table and queue for post generalStatusUpdate(leagueID, gw, "Y", "Y"); if (!incomplete.containsKey("post")) { List<String> post = new ArrayList<String>(); post.add(leagueID + "," + gw); incomplete.put("post", post); } else { incomplete.get("post").add(leagueID + "," + gw); } } else { //After End Date, update Status and update scores generalStatusUpdate(leagueID, gw, "Y", "Y"); List<String> prePost = new ArrayList<String>(); prePost.add(Integer.toString(gw)); incomplete.put("prePost", prePost); } } else { //After kick off but before end date, update status table queue for live and teams generalStatusUpdate(leagueID, gw, "Y", "N"); if (!incomplete.containsKey("teams")) { List<String> teams = new ArrayList<String>(); teams.add(leagueID + "," + gw); incomplete.put("teams", teams); } else { incomplete.get("teams").add(leagueID + "," + gw); } if (!incomplete.containsKey("live")) { List<String> live = new ArrayList<String>(); live.add(leagueID + "," + gw); incomplete.put("live", live); } else { incomplete.get("live").add(leagueID + "," + gw); } } } else { //Not after kick off but after started, queue for teams and wait if (!incomplete.containsKey("teams")) { List<String> teams = new ArrayList<String>(); teams.add(leagueID + "," + gw); incomplete.put("teams", teams); } else { incomplete.get("teams").add(leagueID + "," + gw); } if (!incomplete.containsKey("wait")) { List<String> wait = new ArrayList<String>(); wait.add("Matches to Kick-Off.."); incomplete.put("wait", wait); } else { incomplete.get("wait").add("Matches to Kick-Off.."); } } } else if (startDate.get(Calendar.DAY_OF_MONTH) == now.get(Calendar.DAY_OF_MONTH) && startDate.get(Calendar.MONTH) == now.get(Calendar.MONTH)) { //Gameweek does start today, queue for wait, nothing to update the status with if (!incomplete.containsKey("wait")) { List<String> wait = new ArrayList<String>(); wait.add("Teams to be finalised"); incomplete.put("wait", wait); } else { incomplete.get("wait").add("Teams to be finalised"); } } else { //Pre Gameweek and nothing to do. } } statement.close(); } catch (SQLException sql) { Main.log.ln(1); Main.log.log(1, "Critical Error Updating Status.. " + sql + "\n"); Main.log.log(9, sql); System.exit(1003); } catch (NullPointerException n) { Main.log.ln(1); Main.log.log(1, "Critical Data is Missing from the DB, Try Again or Backup and Delete this Table\n"); Main.log.log(1, n.toString()); System.exit(1005); } Main.log.log(4, "Done!\n", 0); return incomplete; }
From source file:org.simbasecurity.core.saml.SAMLResponseHandlerImpl.java
@Override public boolean isValid(String... requestId) { try {/*from www. j a v a 2 s .c om*/ Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC")); if (this.document == null) { throw new Exception("SAML Response is not loaded"); } if (this.currentUrl == null || this.currentUrl.isEmpty()) { throw new Exception("The URL of the current host was not established"); } // Check SAML version if (!rootElement.getAttribute("Version").equals("2.0")) { throw new Exception("Unsupported SAML Version."); } // Check ID in the response if (!rootElement.hasAttribute("ID")) { throw new Exception("Missing ID attribute on SAML Response."); } checkStatus(); if (!this.validateNumAssertions()) { throw new Exception("SAML Response must contain 1 Assertion."); } NodeList signNodes = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); ArrayList<String> signedElements = new ArrayList<>(); for (int i = 0; i < signNodes.getLength(); i++) { signedElements.add(signNodes.item(i).getParentNode().getLocalName()); } if (!signedElements.isEmpty()) { if (!this.validateSignedElements(signedElements)) { throw new Exception("Found an unexpected Signature Element. SAML Response rejected"); } } Document res = Utils.validateXML(this.document, "saml-schema-protocol-2.0.xsd"); if (res == null) { throw new Exception("Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd"); } if (rootElement.hasAttribute("InResponseTo")) { String responseInResponseTo = document.getDocumentElement().getAttribute("InResponseTo"); if (requestId.length > 0 && responseInResponseTo.compareTo(requestId[0]) != 0) { throw new Exception("The InResponseTo of the Response: " + responseInResponseTo + ", does not match the ID of the AuthNRequest sent by the SP: " + requestId[0]); } } // Validate Assertion timestamps if (!this.validateTimestamps()) { throw new Exception("Timing issues (please check your clock settings)"); } // EncryptedAttributes are not supported NodeList encryptedAttributeNodes = this .queryAssertion("/saml:AttributeStatement/saml:EncryptedAttribute"); if (encryptedAttributeNodes.getLength() > 0) { throw new Exception("There is an EncryptedAttribute in the Response and this SP not support them"); } // Check destination // TODO: lenneh: bktis: currentUrl is http:// and the destination is https:// // if (rootElement.hasAttribute("Destination")) { // String destinationUrl = rootElement.getAttribute("Destination"); // if (destinationUrl != null) { // if (!destinationUrl.equals(currentUrl)) { // throw new Exception("The response was received at " + currentUrl + " instead of " + destinationUrl); // } // } // } // Check Audience // TODO: lenneh: bktis: currentUrl is http:// and audienceUrl is https:// // Set<String> validAudiences = this.getAudiences(); // // if (validAudiences.isEmpty() || !this.audienceUrl.equals(currentUrl)) { // throw new Exception(this.audienceUrl + " is not a valid audience for this Response"); // } // Check the issuers Set<String> issuers = this.getIssuers(); for (String issuer : issuers) { if (issuer.isEmpty()) { throw new Exception("Invalid issuer in the Assertion/Response"); } } // Check the session Expiration Calendar sessionExpiration = this.getSessionNotOnOrAfter(); if (sessionExpiration != null) { if (now.equals(sessionExpiration) || now.after(sessionExpiration)) { throw new Exception( "The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response"); } } // Check SubjectConfirmation, at least one SubjectConfirmation must be valid boolean validSubjectConfirmation = true; NodeList subjectConfirmationNodes = this.queryAssertion("/saml:Subject/saml:SubjectConfirmation"); for (int i = 0; i < subjectConfirmationNodes.getLength(); i++) { Node scn = subjectConfirmationNodes.item(i); Node method = scn.getAttributes().getNamedItem("Method"); if (method != null && !method.getNodeValue().equals(SAMLConstants.CM_BEARER)) { continue; } NodeList subjectConfirmationDataNodes = scn.getChildNodes(); for (int c = 0; c < subjectConfirmationDataNodes.getLength(); c++) { Node subjectConfirmationData = subjectConfirmationDataNodes.item(c); if (subjectConfirmationData.getNodeType() == Node.ELEMENT_NODE && subjectConfirmationData.getLocalName().equals("SubjectConfirmationData")) { // TODO: lenneh: bktis: currentUrl is http:// and the recipient is https:// // Node recipient = subjectConfirmationData.getAttributes().getNamedItem("Recipient"); // if (recipient != null && !recipient.getNodeValue().equals(currentUrl)) { // validSubjectConfirmation = false; // } Node notOnOrAfter = subjectConfirmationData.getAttributes().getNamedItem("NotOnOrAfter"); if (notOnOrAfter != null) { Calendar noa = javax.xml.bind.DatatypeConverter .parseDateTime(notOnOrAfter.getNodeValue()); if (now.equals(noa) || now.after(noa)) { validSubjectConfirmation = false; } } Node notBefore = subjectConfirmationData.getAttributes().getNamedItem("NotBefore"); if (notBefore != null) { Calendar nb = javax.xml.bind.DatatypeConverter.parseDateTime(notBefore.getNodeValue()); if (now.before(nb)) { validSubjectConfirmation = false; } } } } } if (!validSubjectConfirmation) { throw new Exception("A valid SubjectConfirmation was not found on this Response"); } if (signedElements.isEmpty()) { throw new Exception("No Signature found. SAML Response rejected"); } else { if (!Utils.validateSign(signNodes.item(0), certificate)) { throw new Exception("Signature validation failed. SAML Response rejected"); } } return true; } catch (Error e) { error.append(e.getMessage()); return false; } catch (Exception e) { e.printStackTrace(); error.append(e.getMessage()); return false; } }
From source file:rems.Global.java
public static boolean isTransPrmttd(int accntID, String trnsdate, double amnt, String outptMsg[]) { try {// ww w. ja v a 2s . c o m //trnsdate = DateTime.ParseExact( //trnsdate, "dd-MMM-yyyy HH:mm:ss", //System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss"); //Transaction date must be >= the latest prd start date if (accntID <= 0 || trnsdate.equals("")) { return false; } SimpleDateFormat frmtr = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); SimpleDateFormat frmtr1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat frmtr2 = new SimpleDateFormat("dd-MMM-yyyy"); SimpleDateFormat frmtr3 = new SimpleDateFormat("dddd"); Calendar trnsDte = Calendar.getInstance(); trnsDte.setTime(frmtr.parse(trnsdate)); Calendar dte1 = Calendar.getInstance(); dte1.setTime(frmtr.parse(Global.getLtstPrdStrtDate())); Calendar dte1Or = Calendar.getInstance(); dte1Or.setTime(frmtr.parse(Global.getLastPrdClseDate())); Calendar dte2 = Calendar.getInstance(); dte2.setTime(frmtr.parse(Global.getLtstPrdEndDate())); if (trnsDte.equals(dte1Or) || trnsDte.before(dte1Or)) { outptMsg[0] += "Transaction Date cannot be On or Before " + frmtr.format(dte1Or); return false; } if (trnsDte.before(dte1)) { outptMsg[0] += "Transaction Date cannot be before " + frmtr.format(dte1); return false; } if (trnsDte.after(dte2)) { outptMsg[0] += "Transaction Date cannot be after " + frmtr.format(dte2); return false; } //Check if trnsDate exists in an Open Period long prdHdrID = Global.getPrdHdrID(Global.UsrsOrg_ID); //Global.showMsg(Global.Org_iString.valueOf(d) + "-" + prdHdrID.ToString(), 0); if (prdHdrID > 0) { //Global.showMsg(trnsDte.ToString("yyyy-MM-dd HH:mm:ss") + "-" + prdHdrID.ToString(), 0); if (Global.getTrnsDteOpenPrdLnID(prdHdrID, frmtr1.format(trnsDte)) < 0) { outptMsg[0] += "Cannot use a Transaction Date (" + frmtr.format(trnsDte) + ") which does not exist in any OPEN period!"; return false; } //Check if Date is not in Disallowed Dates String noTrnsDatesLov = Global.getGnrlRecNm("accb.accb_periods_hdr", "periods_hdr_id", "no_trns_dates_lov_nm", prdHdrID); String noTrnsDayLov = Global.getGnrlRecNm("accb.accb_periods_hdr", "periods_hdr_id", "no_trns_wk_days_lov_nm", prdHdrID); //Global.showMsg(noTrnsDatesLov + "-" + noTrnsDayLov + "-" + trnsDte.ToString("dddd").ToUpper() + "-" + trnsDte.ToString("dd-MMM-yyyy").ToUpper(), 0); if (!noTrnsDatesLov.equals("")) { if (Global.getEnbldPssblValID(frmtr2.format(trnsDte).toUpperCase(), Global.getEnbldLovID(noTrnsDatesLov)) > 0) { outptMsg[0] += "Transactions on this Date (" + frmtr.format(trnsDte) + ") have been banned on this system!"; return false; } } //Check if Day of Week is not in Disaalowed days if (!noTrnsDatesLov.equals("")) { if (Global.getEnbldPssblValID(frmtr3.format(trnsDte).toUpperCase(), Global.getEnbldLovID(noTrnsDayLov)) > 0) { outptMsg[0] += "Transactions on this Day of Week (" + frmtr3.format(trnsDte) + ") have been banned on this system!"; return false; } } } //Amount must not disobey budget settings on that account long actvBdgtID = Global.getActiveBdgtID(Global.UsrsOrg_ID); double amntLmt = Global.getAcntsBdgtdAmnt(actvBdgtID, accntID, frmtr.format(trnsDte)); Calendar bdte1 = Calendar.getInstance(); bdte1.setTime(frmtr.parse(Global.getAcntsBdgtStrtDte(actvBdgtID, accntID, frmtr.format(trnsDte)))); Calendar bdte2 = Calendar.getInstance(); bdte2.setTime(frmtr.parse(Global.getAcntsBdgtEndDte(actvBdgtID, accntID, frmtr.format(trnsDte)))); double crntBals = Global.getTrnsSum(accntID, frmtr.format(bdte1), frmtr.format(bdte2), "1"); String actn = Global.getAcntsBdgtLmtActn(actvBdgtID, accntID, trnsdate); if ((amnt + crntBals) > amntLmt) { if (actn.equals("Disallow")) { outptMsg[0] += "This transaction will cause budget on \r\nthe chosen account to be exceeded! "; return false; } else if (actn.equals("Warn")) { outptMsg[0] += "This is just to WARN you that the budget on \r\nthe chosen account will be exceeded!"; return true; } else if (actn.equals("Congratulate")) { outptMsg[0] += "This is just to CONGRATULATE you for exceeding the targetted Amount! "; return true; } else { return true; } } return true; } catch (Exception ex) { outptMsg[0] += Arrays.toString(ex.getStackTrace()) + "\r\n" + ex.getMessage(); return false; } }
From source file:org.nuxeo.cm.demo.UpdateDemoData.java
private void _UpdateData() throws Exception { // First, we want to delete the "Nice Claim". Because updating it is // useless//from ww w .j a va2 s .co m // and also because it generates some "ausitCoreListener" error about // the // thing not finding the document _niceClaimDelete(); // Now, get all the claims String nxql = "SELECT * FROM InsuranceClaim"; nxql += " WHERE ecm:isCheckedInVersion = 0"; nxql += " AND ecm:currentLifeCycleState != 'deleted'"; DocumentModelList allDocs = _session.query(nxql); _doLog("Update demo data: " + allDocs.size() + "document(s) to update"); // ============================================================ // Update existing cases // ============================================================ for (DocumentModel oneDoc : allDocs) { Calendar aDate, startDate, creationDate, modifDate; String creator; updateLifecycleState(oneDoc); int lfs = _lifecycleStateStrToInt(oneDoc.getCurrentLifeCycleState().toLowerCase()); String creationDateStr; // Half in previous month creationDate = (Calendar) _today.clone(); switch (lfs) { case kLFS_ARCHIVED: creationDate.add(Calendar.DATE, _randomInt(30, 90) * -1); break; case kLFS_RECEIVED: creationDate.add(Calendar.DATE, _randomInt(2, 20) * -1); break; case kLFS_CHECK_CONTRACT: creationDate.add(Calendar.DATE, _randomInt(5, 30) * -1); break; case kLFS_OPENED: creationDate.add(Calendar.DATE, _randomInt(20, 40) * -1); break; case kLFS_COMPLETED: creationDate.add(Calendar.DATE, _randomInt(20, 40) * -1); break; case kLFS_EVALUATED: creationDate.add(Calendar.DATE, _randomInt(50, 80) * -1); break; case kLFS_DECISION_MADE: creationDate.add(Calendar.DATE, _randomInt(30, 90) * -1); break; default: creationDate.add(Calendar.DATE, _randomInt(31, 90) * -1); break; } creationDateStr = _yyyyMMdd.format(creationDate.getTime()); oneDoc.setPropertyValue("dc:created", creationDate); oneDoc.setPropertyValue("incl:date_received", creationDate); // We don't want to build the exact same due_date as the Studio // project does // because we want mixed due_date for our JavaScript dashboard /* * String claimKind = (String) oneDoc.getPropertyValue("incl:incident_kind"); * if(claimKind.equals("building-fire")) { aDate = _buildDate(creationDate, 90); } else * if(claimKind.equals("breakdown")) { aDate = _buildDate(creationDate, 10); } else { aDate = * _buildDate(creationDate, 30); } */ // Say about 25% are past due (not always: If the case is closed, // archived // the dashboard does not even look at the due_date) if (_randomInt(1, 4) == 1) { aDate = _buildDate(_today, _randomInt(1, 10) * -1); } else { aDate = _buildDate(_today, _randomInt(1, 30), true); } oneDoc.setPropertyValue("incl:due_date", aDate); creator = kUSERS[_randomInt(0, kMAX_FOR_USERS_RANDOM)]; oneDoc.setPropertyValue("dc:creator", creator); // Update the title and incident_id _updateTitle(oneDoc, creationDateStr); // Opening date of the case to this date, eventually 1-3 days before // "incl:date_received" startDate = (Calendar) creationDate.clone(); int daysBefore = _randomInt(0, 3); if (daysBefore != 0) { startDate.add(Calendar.DATE, daysBefore * -1); } oneDoc.setPropertyValue("incl:incident_date", startDate); // Update contract start/end date. Say a range of one year with // today // in this range aDate = _buildDate(creationDate, _randomInt(30, 180) * -1); oneDoc.setPropertyValue("incl:contract_start", aDate); aDate.add(Calendar.DATE, 365); oneDoc.setPropertyValue("incl:contract_end", aDate); // If the case is closed, change the date of the closing // We also set the modifDate here because it is == closing date if // accurate // For Kibana stats, have modif dates in the last 3 months // IMPORTANT: This will not be accurate with the creation date, // it may happen the creation date becomes > modification modifDate = _buildDate(_today, _randomInt(0, 90) * -1); /* * if (lfs == kLFS_ARCHIVED) { aDate = _buildDate(_today, _randomInt(5, 90) * -1); * oneDoc.setPropertyValue("incl:date_closed", aDate); modifDate = (Calendar) aDate.clone(); } else { // Let * say it was modified recently... modifDate = _buildDate(_today, _randomInt(0, 10) * -1); } */ _updateModificationInfo(oneDoc, kUSERS[_randomInt(0, kMAX_FOR_USERS_RANDOM)], modifDate); // Update first/last names oneDoc.setPropertyValue("pein:first_name", randomPeopleNames.getAFirstName(RandomFirstLastNames.GENDER.ANY)); oneDoc.setPropertyValue("pein:last_name", randomPeopleNames.getALastName()); String city = kCITIES[_randomInt(0, kCITIES_MAX)]; oneDoc.setPropertyValue("incl:incident_city", city); oneDoc.setPropertyValue("incl:incident_us_state", citiesAndStates.get(city)); // Yes the country is totally random and does not match the city or state; it's just a demo! :) String country = kCOUNTRIES[_randomInt(0, kCOUNTRIES_MAX)]; oneDoc.setPropertyValue("incl:incident_country", country); if (hasAccidentTypology) { String kind = (String) oneDoc.getPropertyValue("incl:incident_kind"); if (kind != null && kind.equals("accident")) { oneDoc.setPropertyValue("incl:typology", ACC_TYPOLOGY[_randomInt(0, ACC_TYPOLOGY_MAX)]); } } // Now update some info of the children, if any DocumentModelList children = _session.getChildren(oneDoc.getRef()); for (DocumentModel oneChild : children) { // Did not dig into the problem, but calling... // oneChild.setPropertyValue("dc:created", creationDate); // ...leads to a "property not found" error. The workaround // I found was about using setProperty() instead. oneChild.setProperty("dublincore", "created", creationDate); oneChild.setProperty("dublincore", "creator", creator); aDate = _buildDate(creationDate, _randomInt(0, 10)); oneChild.setProperty("dublincore", "modified", aDate); oneChild.setProperty("dublincore", "lastContributor", kUSERS[_randomInt(0, kMAX_FOR_USERS_RANDOM)]); _session.saveDocument(oneChild); // Don't want to handle MailFolder (which is, actually, not used // in the demo) // We also don't handle recursivity, sub-sub-folders, etc. if (oneChild.isFolder() && oneChild.getType().toLowerCase().indexOf("mail") < 0) { DocumentModelList grandChildren = _session.getChildren(oneChild.getRef()); for (DocumentModel oneGrandChild : grandChildren) { if (oneChild.isFolder()) { oneGrandChild.setPropertyValue("dc:created", creationDate); // Nothing more } else { aDate = (Calendar) creationDate.clone(); aDate.add(Calendar.DATE, _randomInt(0, 30)); if (aDate.after(_today)) { aDate = (Calendar) _today.clone(); aDate.add(Calendar.DATE, _randomInt(0, 3) * -1); } oneGrandChild.setPropertyValue("dc:created", aDate); oneGrandChild.setProperty("dublincore", "creator", creator); oneGrandChild.setProperty("dublincore", "modified", creationDate); oneGrandChild.setProperty("dublincore", "lastContributor", kUSERS[_randomInt(0, kMAX_FOR_USERS_RANDOM)]); oneGrandChild.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); } _session.saveDocument(oneGrandChild); } } } oneDoc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); // Make sure events are not triggered oneDoc.putContextData("UpdatingData_NoEventPlease", true); _saveDocument(oneDoc); } // for (DocumentModel oneDoc : allDocs) _doLog("Last commit. Total InsuranceClaim handled: " + _saveCounter); _session.save(); // ============================================================ // Create a nice case // ============================================================ _niceClaimCreate(); _session.save(); _doLog("End of update demo data"); }
From source file:com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance.java
/** * Check recom.//from www .j a va2 s. c o m * @param recsHave the recs have * @param recsLeft the recs left */ private void checkRecom(final int recsHave, final int recsLeft) { final Calendar check = Calendar.getInstance(); check.setTimeInMillis(_lastRecomUpdate); check.add(Calendar.DAY_OF_MONTH, 1); final Calendar min = Calendar.getInstance(); _recomHave = recsHave; _recomLeft = recsLeft; if (getStat().getLevel() < 10 || check.after(min)) return; restartRecom(); }