List of usage examples for org.apache.commons.lang StringUtils contains
public static boolean contains(String str, String searchStr)
Checks if String contains a search String, handling null
.
From source file:edu.ku.brc.specify.conversion.AgentConverter.java
/** * @param agentInfo/* w ww.j av a 2 s . co m*/ * @param namePair */ @SuppressWarnings("unchecked") protected void fixupForCollectors(final Division divisionArg, final Discipline disciplineArg) { //ParseAgentType parseType = ParseAgentType.LastNameOnlyLF; Session session = HibernateUtil.getNewSession(); Transaction trans = null; try { Division division = (Division) session.createQuery("FROM Division WHERE id = " + divisionArg.getId()) .list().iterator().next(); Discipline discipline = (Discipline) session .createQuery("FROM Discipline WHERE id = " + disciplineArg.getId()).list().iterator().next(); Agent createdByAgent = (Agent) session .createQuery("FROM Agent WHERE id = " + conv.getCreatorAgentIdForAgent(null)).list().iterator() .next(); tblWriter.log("<H4>Splitting Mutliple Collectors names into Multiple Agents</H4>"); tblWriter.startTable(); tblWriter.logHdr("New Agent ID", "Old Last Name", "Description"); Vector<Integer> agentToDelete = new Vector<Integer>(); conv.setProcess(0, agentHash.values().size()); int cnt = 0; for (AgentInfo agentInfo : agentHash.values()) { String lastNameText = agentInfo.getAgentType() != Agent.PERSON ? agentInfo.getName() : agentInfo.getLastName(); //String firstNameText = agentInfo.getFirstName(); if ((StringUtils.contains(lastNameText, ",") || StringUtils.contains(lastNameText, ";")) && !StringUtils.contains(lastNameText, "'")) { String sql = "SELECT c.CollectorID, c.CollectingEventID FROM collector c INNER JOIN agent ON c.AgentID = agent.AgentID WHERE agent.AgentID = " + agentInfo.getNewAgentId(); ResultSet rs = gStmt.executeQuery(sql); if (rs.next()) { int highestOrder = 0; Integer colID = rs.getInt(1); Integer ceId = rs.getInt(2); tblWriter.log(ceId + " / " + colID + " / " + agentInfo.getNewAgentId().toString(), lastNameText, " "); sql = "SELECT ce.CollectingEventID, c.CollectorID, c.OrderNumber, c.IsPrimary FROM collector c INNER JOIN collectingevent ce ON c.CollectingEventID = ce.CollectingEventID " + "WHERE c.CollectorID = " + colID + " ORDER BY c.OrderNumber DESC"; ResultSet rs2 = gStmt.executeQuery(sql); if (rs2.next()) { highestOrder = rs2.getInt(3); } rs.close(); CollectingEvent ce = (CollectingEvent) session .createQuery("FROM CollectingEvent WHERE id = " + ceId).list().get(0); Agent origAgent = (Agent) session .createQuery("FROM Agent WHERE id = " + agentInfo.getNewAgentId()).list().get(0); // Now process the multiple Collectors String[] lastNames = StringUtils.split(lastNameText, ",;"); //String[] firstNames = StringUtils.split(firstNameText, ",;"); for (int i = 0; i < lastNames.length; i++) { if (parseName(lastNames[i], nameTriple)) { String firstName = nameTriple.first; String middle = nameTriple.second; String lastName = nameTriple.third; List<Agent> agts = (List<Agent>) session.createQuery("FROM Agent WHERE firstName = " + (firstName != null ? "'" + firstName + "'" : "NULL") + " AND middleInitial = " + (middle != null ? "'" + middle + "'" : "NULL") + " AND lastName = " + (lastName != null ? "'" + lastName + "'" : "NULL")) .list(); Agent existingAgent = agts != null && agts.size() > 0 ? agts.get(0) : null; trans = session.beginTransaction(); if (i == 0) { if (existingAgent != null) { Collector collector = (Collector) session .createQuery("FROM Collector WHERE id = " + colID).list().get(0); collector.setAgent(existingAgent); existingAgent.getCollectors().add(collector); /*origAgent.getCollectors().clear(); origAgent.getDisciplines().clear(); for (Agent a : new ArrayList<Agent>(discipline.getAgents())) { if (a.getId().equals(origAgent.getId())) { discipline.getAgents().remove(a); break; } } for (Agent a : new ArrayList<Agent>(division.getMembers())) { if (a.getId().equals(origAgent.getId())) { division.getMembers().remove(a); break; } } origAgent.setDivision(null); origAgent.setCreatedByAgent(null); origAgent.setModifiedByAgent(null); //session.delete(origAgent);*/ tblWriter.log(agentInfo.getNewAgentId().toString(), firstName + ", " + lastName, "reusing collector,using existing agent"); agentToDelete.add(origAgent.getId()); session.saveOrUpdate(existingAgent); session.saveOrUpdate(collector); session.saveOrUpdate(division); session.saveOrUpdate(discipline); } else { origAgent.setFirstName(firstName); origAgent.setLastName(lastName); origAgent.setAgentType(Agent.PERSON); tblWriter.log(agentInfo.getNewAgentId().toString(), firstName + ", " + lastName, "resetting agent names - reclaiming"); session.saveOrUpdate(origAgent); } } else { highestOrder++; Agent agent; if (existingAgent == null) { agent = new Agent(); agent.initialize(); agent.setAgentType(Agent.PERSON); agent.setCreatedByAgent(createdByAgent); agent.setDivision(division); agent.setFirstName(nameTriple.first); agent.setMiddleInitial(nameTriple.second); agent.setLastName(nameTriple.third); division.getMembers().add(agent); tblWriter.log(agentInfo.getNewAgentId().toString(), firstName + ", " + lastName, "new agent, new collector"); } else { agent = existingAgent; tblWriter.log(agentInfo.getNewAgentId().toString(), firstName + ", " + lastName, "reusing, new collector"); } Collector collector = new Collector(); collector.initialize(); collector.setCreatedByAgent(createdByAgent); collector.setOrderNumber(highestOrder); ce.getCollectors().add(collector); collector.setCollectingEvent(ce); collector.setAgent(agent); agent.getCollectors().add(collector); collector.setIsPrimary(false); session.saveOrUpdate(agent); session.saveOrUpdate(collector); session.saveOrUpdate(division); session.saveOrUpdate(discipline); } trans.commit(); } } } rs.close(); } conv.setProcess(++cnt); } tblWriter.endTable(); Collections.sort(agentToDelete); tblWriter.log("<H4>Removing Original Agents</H4>"); tblWriter.startTable(); tblWriter.logHdr("New Agent ID", "LastName", "FirstName"); for (Integer id : agentToDelete) { System.out.println("Deleting Agent[" + id + "]"); List<Object[]> rows = BasicSQLUtils.query( "SELECT AgentID, LastName, MiddleInitial, FirstName FROM agent WHERE AgentID = " + id); Object[] row = rows.get(0); tblWriter.log(id.toString(), (row[1] == null ? " " : row[1].toString()) + (row[2] == null ? "" : " " + row[2].toString()), row[3] == null ? " " : row[3].toString()); updateStmtNewDB.executeUpdate("DELETE FROM agent WHERE AgentID = " + id); } tblWriter.endTable(); } catch (Exception ex) { try { if (trans != null) trans.rollback(); } catch (Exception ex1) { } ex.printStackTrace(); log.error(ex); } finally { session.close(); } }
From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java
/** * @param oldSQL/* ww w .j av a 2 s .c o m*/ * @param newSQL * @return * @throws SQLException */ private StatusType compareRecords(final String desc, final String oldCatNumArg, final String newCatNumArg, final String oldSQLArg, final String newSQLArg, final boolean nullsAreOK, final boolean notRetarded) throws SQLException { boolean dbg = false; if (dbg) { System.out.println(oldSQLArg); System.out.println(newSQLArg); } if (dbg) { System.out.println("\n" + desc); dump(desc, oldDBConn, compareTo6DBs ? newSQLArg : oldSQLArg); dump(desc, newDBConn, newSQLArg); } String oldCatNum = oldCatNumArg; String newCatNum = newCatNumArg; if (compareTo6DBs) { oldCatNum = newCatNumArg; } if (notRetarded) { getResultSetsNotRetarded(oldSQLArg, newSQLArg, oldCatNum, newCatNum); } else { getResultSets(oldSQLArg, newSQLArg); } try { boolean hasOldRec = oldDBRS.next(); boolean hasNewRec = newDBRS.next(); if (!hasOldRec && !hasNewRec) { return StatusType.COMPARE_OK; } if (!hasOldRec) { if (nullsAreOK) { log.error(desc + " - No Old Record for [" + oldCatNum + "]"); tblWriter.logErrors(oldCatNum, "No Old Record"); return StatusType.NO_OLD_REC; } return StatusType.COMPARE_OK; } if (!hasNewRec) { log.error(desc + " - No New Record for [" + newCatNum + "]"); tblWriter.logErrors(newCatNum, "No New Record"); return StatusType.NO_NEW_REC; } //check number of rows, if not equal don't try to compare oldDBRS.last(); newDBRS.last(); if (oldDBRS.getRow() != newDBRS.getRow()) { String msg = desc + " Cat Num [" + oldCatNum + "]: Sp5 DB has " + oldDBRS.getRow() + " related records. Sp6 DB has " + newDBRS.getRow(); log.error(msg); tblWriter.logErrors(newCatNum, msg); return oldDBRS.getRow() < newDBRS.getRow() ? StatusType.NO_NEW_REC : StatusType.NO_OLD_REC; } oldDBRS.first(); newDBRS.first(); String oldNewIdStr = oldCatNum + " / " + newCatNum; boolean checkForAgent = newSQL.indexOf("a.LastName") > -1; ResultSetMetaData oldRsmd = oldDBRS.getMetaData(); ResultSetMetaData newRsmd = newDBRS.getMetaData(); PartialDateConv datePair = new PartialDateConv(); Calendar cal = Calendar.getInstance(); StringBuilder errSB = new StringBuilder(); while (hasNewRec && hasOldRec) { errSB.setLength(0); int oldColInx = 0; int newColInx = 0; String idMsgStr = ""; int numCols = newRsmd.getColumnCount(); for (int col = 0; col < numCols; col++) { newColInx++; oldColInx++; if (dbg) { System.out.println("\ncol " + col + " / " + oldRsmd.getColumnCount()); System.out.println("newColInx " + newColInx); System.out.println("oldColInx " + oldColInx); System.out.println(oldRsmd.getColumnName(oldColInx)); System.out.println(newRsmd.getColumnName(newColInx)); } Object newObj = newDBRS.getObject(newColInx); Object oldObj = oldDBRS.getObject(oldColInx); if (oldObj == null && newObj == null) { String colName = newRsmd.getColumnName(newColInx); if (StringUtils.contains(colName, "Date") && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) { newColInx++; numCols--; if (compareTo6DBs) oldColInx++; } continue; } if (col == 0) { idMsgStr = String.format(" - Rec Ids[%s / %s] ", (oldObj != null ? oldObj : -1), (newObj != null ? newObj : -1)); continue; } String oldColName = oldRsmd.getColumnName(oldColInx); if (oldColName.equals("PreparationMethod") && newObj != null) { String newObjStr = newObj.toString(); if ((oldObj == null && !newObjStr.equalsIgnoreCase("Misc")) || (oldObj != null && !newObjStr.equalsIgnoreCase(oldObj.toString()))) { String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum [" + oldCatNum + "] Field [" + oldColName + "] oldObj[" + oldObj + "] newObj [" + newObj + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldCatNum, msg); return StatusType.OLD_VAL_NULL; } continue; } if (oldObj == null && !StringUtils.contains(oldColName, "LastName")) { if (!oldColName.equals("PreparationMethod") || !newObj.equals("Misc")) { String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum [" + oldCatNum + "] Field [" + oldColName + "] New Val[" + newObj + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldCatNum, msg); return StatusType.OLD_VAL_NULL; } } if (newObj == null) { String clsName = newRsmd.getColumnClassName(newColInx); String colName = newRsmd.getColumnName(newColInx); if (compareTo6DBs) { if (!clsName.equals("java.sql.Date") || oldObj != null) { String msg = "New Value was null and shouldn't have been for Key Value New CatNo[" + newCatNum + "] Field [" + colName + "] [" + oldObj + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(newCatNum, msg); return StatusType.NEW_VAL_NULL; } } else { if (!clsName.equals("java.sql.Date") || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) { String msg = "New Value was null and shouldn't have been for Key Value New CatNo[" + newCatNum + "] Field [" + colName + "] [" + oldObj + "]"; log.error(desc + " - " + msg); if (tblWriter != null && newCatNum != null && msg != null) tblWriter.logErrors(newCatNum, msg); dbg = true; return StatusType.NEW_VAL_NULL; } } if (StringUtils.contains(colName, "Date") && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) { newColInx++; numCols--; if (compareTo6DBs) oldColInx++; } continue; } //String colName = newRsmd.getColumnName(col); //System.out.println(newObj.getClass().getName()+" "+oldObj.getClass().getName()); if (newObj instanceof java.sql.Date) { boolean isPartialDate = false; Byte partialDateType = null; if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) { newColInx++; numCols--; partialDateType = newDBRS.getByte(newColInx); isPartialDate = true; } if (compareTo6DBs) { Object dateObj = oldDBRS.getObject(oldColInx); boolean isPartialDate2 = false; Byte partialDateType2 = null; if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) { oldColInx++; partialDateType2 = newDBRS.getByte(oldColInx); isPartialDate2 = true; } else { log.error("Next isn't DatePrecision and can't be!"); tblWriter.logErrors(oldNewIdStr, errSB.toString()); } if (!newObj.equals(dateObj) || (isPartialDate2 && !partialDateType2.equals(partialDateType))) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("] oldDate["); errSB.append(dateFormatter.format((Date) dateObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } else { int oldIntDate = oldDBRS.getInt(oldColInx); if (oldIntDate == 0) { continue; } BasicSQLUtils.getPartialDate(oldIntDate, datePair, false); if (partialDateType != null) { boolean ok = StringUtils.isNotEmpty(datePair.getPartial()) && StringUtils.isNumeric(datePair.getPartial()); if (!ok || (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue())) { errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial() + "] New [" + partialDateType.byteValue() + "]"); // error partial dates don't match } } cal.setTime((Date) newObj); if (StringUtils.isNotEmpty(datePair.getDateStr()) && !datePair.getDateStr().equalsIgnoreCase("null")) { int year = Integer.parseInt(datePair.getDateStr().substring(0, 4)); int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7)); int day = Integer.parseInt(datePair.getDateStr().substring(8, 10)); if (mon > 0) mon--; boolean isYearOK = true; int yr = cal.get(Calendar.YEAR); if (year != yr) { errSB.append("Year mismatch Old[" + year + "] New [" + yr + "] "); isYearOK = false; } if (mon != cal.get(Calendar.MONTH)) { errSB.append("Month mismatch Old[" + mon + "] New [" + cal.get(Calendar.MONTH) + "] "); } if (day != cal.get(Calendar.DAY_OF_MONTH)) { errSB.append("Day mismatch Old[" + day + "] New [" + cal.get(Calendar.DAY_OF_MONTH) + "] "); } if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } else { //String msg = "Date contains the string 'NULL'"; //log.error(msg); //tblWriter.logErrors(oldNewIdStr, msg); //return StatusType.BAD_DATE; } } } else if (newObj instanceof Float || newObj instanceof Double) { String s1 = String.format("%10.5f", newObj instanceof Float ? (Float) newObj : (Double) newObj); String s2 = String.format("%10.5f", oldObj instanceof Float ? (Float) oldObj : (Double) oldObj); if (!s1.equals(s2)) { String msg = idMsgStr + "Columns don't compare[" + s1 + "][" + s2 + "] [" + newRsmd.getColumnName(col) + "][" + oldRsmd.getColumnName(oldColInx) + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldNewIdStr, msg); return StatusType.NO_COMPARE; } } else { String newColName = newRsmd.getColumnName(newColInx); if (checkForAgent && StringUtils.contains(newColName, "LastName")) { String lastName = oldDBRS.getString(oldColInx); String agentName = oldDBRS.getString(oldColInx + 1); // The 'Name' Column String newLastName = newDBRS.getString(newColInx); if (!newLastName.equals(lastName) && !newLastName.equals(agentName)) { String msg = idMsgStr + "Name Columns don't compare[" + newObj + "][" + oldObj + "] [" + newColName + "][" + oldColName + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldNewIdStr, msg); log.error(oldSQLArg + "\n" + newSQLArg); return StatusType.NO_COMPARE; } } else if (StringUtils.contains(newColName, "YesNo")) { boolean yesNoNew = newDBRS.getBoolean(newColInx); boolean yesNoOld = oldDBRS.getInt(oldColInx) != 0; if (yesNoNew != yesNoOld) { String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare[" + yesNoNew + "][" + yesNoOld + "] [" + newColName + "][" + oldColName + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldNewIdStr, msg); return StatusType.NO_COMPARE; } } else if (!newObj.equals(oldObj)) { String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare[" + newObj + "][" + oldObj + "] [" + newColName + "][" + oldColName + "]"; log.error(desc + " - " + msg); tblWriter.logErrors(oldNewIdStr, msg); return StatusType.NO_COMPARE; /*boolean isOK = false; if (oldObj instanceof String) { String oldStr = (String)oldObj; String newStr = (String)newObj; String lof = "\\r\\n"; int inx = newStr.indexOf(lof); if (inx > -1) { String tok = oldStr.substring(0, inx); if (newStr.equals(tok)) { isOK = true; } } } if (!isOK) { log.error(desc+ " - Columns don't compare["+newObj+"]["+oldObj+"] ["+newRsmd.getColumnName(newColInx)+"]["+oldRsmd.getColumnName(oldColInx)+"]"); return false; }*/ } } } hasOldRec = oldDBRS.next(); hasNewRec = newDBRS.next(); if (!hasOldRec && !hasNewRec) { return StatusType.COMPARE_OK; } if (!hasOldRec) { log.error(desc + idMsgStr + " - No Old Record for [" + oldCatNum + "]"); tblWriter.logErrors(oldNewIdStr, "No Old Record for [" + oldCatNum + "]"); return StatusType.NO_OLD_REC; } if (!hasNewRec) { log.error(desc + idMsgStr + " No New Record for [" + newCatNum + "]"); tblWriter.logErrors(oldNewIdStr, "No New Record for [" + newCatNum + "]"); return StatusType.NO_NEW_REC; } } } finally { doneWithRS(); } return StatusType.COMPARE_OK; }
From source file:com.sfs.whichdoctor.dao.RotationDAOImpl.java
/** * Builds the accreditation summary./*from w w w . j ava 2 s . co m*/ * * @param personGUID the person guid * @param type the type * @return the collection */ @SuppressWarnings("unchecked") private Collection<HashMap<String, Integer>> buildAccreditationSummary(final int personGUID, final String type) { // Build a map to hold the accreditation summary Collection<HashMap<String, Integer>> accreditationSummary = new ArrayList<HashMap<String, Integer>>(); try { accreditationSummary = this.getJdbcTemplateWriter().query( this.getSQL().getValue("rotation/accreditationSummary"), new Object[] { personGUID, type }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { HashMap<String, Integer> summary = new HashMap<String, Integer>(); summary.put("Accreditation", rs.getInt("Accreditation")); summary.put("GUID", rs.getInt("GUID")); summary.put("AccreditationTypeId", rs.getInt("AccreditationTypeId")); summary.put("SpecialtyId", rs.getInt("SpecialtyId")); int trainingId = DEFAULT_ROTATION; String type = rs.getString("TrainingClass"); if (StringUtils.contains(type, "ontinuing")) { trainingId = CONTINUING_ROTATION; } if (StringUtils.contains(type, "nterrupt")) { trainingId = INTERRUPTED_ROTATION; } summary.put("TrainingId", trainingId); return summary; } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return accreditationSummary; }
From source file:edu.ku.brc.specify.web.SpecifyExplorer.java
/** * @param out//w w w .ja v a 2 s .c o m * @param ordered * @param unOrdered */ protected void fillRows(final PrintWriter out, final Hashtable<Integer, String> ordered, final Vector<String> unOrdered) { Vector<Integer> indexes = new Vector<Integer>(ordered.keySet()); Collections.sort(indexes); int cnt = 1; for (Integer index : indexes) { String row = ordered.get(index); if (row != null) { if (StringUtils.contains(row, "BRDRODDEVEN")) { out.println(StringUtils.replace(row, "BRDRODDEVEN", "brdr" + (((cnt + 1) % 2 == 0) ? "even" : "odd"))); } else { out.println(row); } cnt++; } } if (unOrdered != null) { for (String row : unOrdered) { if (StringUtils.contains(row, "BRDRODDEVEN")) { out.println(StringUtils.replace(row, "BRDRODDEVEN", "brdr" + (((cnt + 1) % 2 == 0) ? "even" : "odd"))); } else { out.println(row); } cnt++; } } }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractUsersController.java
@ResponseBody @RequestMapping(value = "/enable_services", method = RequestMethod.POST) public Map<String, String> enableServices( @RequestParam(value = "tenantparam", required = true) String tenantParam, @RequestParam(value = "userparam", required = true) String userParam, @RequestParam(value = "instances", required = true) String instances) { Map<String, String> responseMap = new HashMap<String, String>(); User user = userService.get(userParam); for (ServiceInstance serviceInstance : tenantService.getEnabledCSInstances(user.getTenant())) { if (StringUtils.contains(instances, serviceInstance.getUuid())) { userService.enableServices(user, serviceInstance); }//from ww w . j ava 2 s .c o m } return responseMap; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractUsersController.java
@ResponseBody @RequestMapping(value = "/enabled_services", method = RequestMethod.POST) public Map<String, String> getServiceProvisioningStatus( @RequestParam(value = "tenantparam", required = true) String tenantParam, @RequestParam(value = "userparam", required = true) String userParam, @RequestParam(value = "instances", required = true) String instances) { Map<String, String> responseMap = new HashMap<String, String>(); User user = userService.get(userParam); for (ServiceInstance serviceInstance : tenantService.getEnabledCSInstances(user.getTenant())) { if (StringUtils.contains(instances, serviceInstance.getUuid())) { UserHandle handle = userService.getLatestUserHandle(user.getUuid(), serviceInstance.getUuid()); responseMap.put(serviceInstance.getUuid(), handle != null ? handle.getState().name() : com.vmops.model.UserHandle.State.PROVISIONING.name()); }//from ww w . j av a2 s . c om } return responseMap; }
From source file:fr.paris.lutece.plugins.document.web.DocumentJspBean.java
/** * Saves the referer to redirect after the action is performed * @param request The request/* www. ja va 2s .co m*/ */ private void saveReferer(HttpServletRequest request) { String strFromUrl = request.getParameter(PARAMETER_FROM_URL); if (StringUtils.isNotBlank(strFromUrl)) { _strSavedReferer = strFromUrl.replace(CONSTANT_AND_HTML, CONSTANT_AND); } else { String strReferer = request.getHeader(PARAMETER_HEADER_REFERER); String strAdminMenuUrl = AppPathService.getAdminMenuUrl(); if (StringUtils.contains(strReferer, strAdminMenuUrl)) { _strSavedReferer = strAdminMenuUrl; } else if (StringUtils.contains(strReferer, _strFeatureUrl)) { _strSavedReferer = _strFeatureUrl; } } }
From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java
/** * @param oldNewIdStr/*w w w.j a va 2 s .c o m*/ * @param newColInx * @param oldColInx * @return * @throws SQLException */ private StatusType compareDates(final String oldNewIdStr, final int newColInx, final int oldColInx) throws SQLException { PartialDateConv datePair = new PartialDateConv(); Object newObj = newDBRS.getObject(newColInx); Object oldObj = oldDBRS.getObject(oldColInx); ResultSetMetaData newRsmd = newDBRS.getMetaData(); ResultSetMetaData oldRsmd = oldDBRS.getMetaData(); String newColName = newRsmd.getColumnName(newColInx); String oldColName = oldRsmd.getColumnName(oldColInx); if (newObj == null) { String clsName = newRsmd.getColumnClassName(newColInx); if (compareTo6DBs) { if (!clsName.equals("java.sql.Date") || oldObj != null) { String msg = "New Value was null and shouldn't have been for Key Value New Field [" + newColName + "] [" + oldObj + "]"; log.error(msg); tblWriter.logErrors(newColName, msg); return StatusType.NEW_VAL_NULL; } } else if (oldObj != null) { if (oldObj instanceof Number && ((Number) oldObj).intValue() == 0) { return StatusType.COMPARE_OK; } else if (!clsName.equals("java.sql.Date") || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) { String msg = "New Value was null and shouldn't have been for Key Value New Field [" + newColName + "] [" + oldObj + "]"; log.error(msg); tblWriter.logErrors(newColName, msg); return StatusType.NEW_VAL_NULL; } } else { return StatusType.COMPARE_OK; } } StringBuilder errSB = new StringBuilder(); //System.out.println(newObj.getClass().getName()+" "+oldObj.getClass().getName()); if (newObj instanceof java.sql.Date) { boolean isPartialDate = false; Byte partialDateType = null; if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) { partialDateType = newDBRS.getByte(newColInx); isPartialDate = true; } if (compareTo6DBs) { Object dateObj = oldDBRS.getObject(oldColInx); boolean isPartialDate2 = false; Byte partialDateType2 = null; if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) { partialDateType2 = newDBRS.getByte(oldColInx); isPartialDate2 = true; } else { log.error("Next isn't DatePrecision and can't be!"); tblWriter.logErrors(oldNewIdStr, errSB.toString()); } if (!newObj.equals(dateObj) || (isPartialDate2 && !partialDateType2.equals(partialDateType))) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("] oldDate["); errSB.append(dateFormatter.format((Date) dateObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } else { int oldIntDate = oldDBRS.getInt(oldColInx); if (oldIntDate == 0) { return StatusType.NO_OLD_REC; } BasicSQLUtils.getPartialDate(oldIntDate, datePair, false); if (partialDateType != null) { if (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue()) { errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial() + "] New [" + partialDateType.byteValue() + "]"); // error partial dates don't match } } Calendar cal = Calendar.getInstance(); cal.setTime((Date) newObj); int year = Integer.parseInt(datePair.getDateStr().substring(0, 4)); int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7)); int day = Integer.parseInt(datePair.getDateStr().substring(8, 10)); if (mon > 0) mon--; boolean isYearOK = true; int yr = cal.get(Calendar.YEAR); if (year != yr) { errSB.append("Year mismatch Old[" + year + "] New [" + yr + "] "); isYearOK = false; } if (mon != cal.get(Calendar.MONTH)) { errSB.append("Month mismatch Old[" + mon + "] New [" + cal.get(Calendar.MONTH) + "] "); } if (day != cal.get(Calendar.DAY_OF_MONTH)) { errSB.append("Day mismatch Old[" + day + "] New [" + cal.get(Calendar.DAY_OF_MONTH) + "] "); } if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } } return StatusType.COMPARE_OK; }
From source file:com.impetus.client.cassandra.schemamanager.CassandraSchemaManager.java
/** * Sets the column family properties.//from w ww. j a v a 2 s.c om * * @param cfDef * the cf def * @param cfProperties * the c f properties * @param builder * the builder */ private void setColumnFamilyProperties(CfDef cfDef, Properties cfProperties, StringBuilder builder) { if ((cfDef != null && cfProperties != null) || (builder != null && cfProperties != null)) { if (builder != null) { builder.append(CQLTranslator.WITH_CLAUSE); } onSetKeyValidation(cfDef, cfProperties, builder); onSetCompactionStrategy(cfDef, cfProperties, builder); onSetComparatorType(cfDef, cfProperties, builder); onSetSubComparator(cfDef, cfProperties, builder); // onSetReplicateOnWrite(cfDef, cfProperties, builder); onSetCompactionThreshold(cfDef, cfProperties, builder); onSetComment(cfDef, cfProperties, builder); onSetTableId(cfDef, cfProperties, builder); onSetGcGrace(cfDef, cfProperties, builder); onSetCaching(cfDef, cfProperties, builder); onSetBloomFilter(cfDef, cfProperties, builder); onSetRepairChance(cfDef, cfProperties, builder); onSetReadRepairChance(cfDef, cfProperties, builder); // Strip last AND clause. if (builder != null && StringUtils.contains(builder.toString(), CQLTranslator.AND_CLAUSE)) { builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length()); // builder.deleteCharAt(builder.length() - 2); } // Strip last WITH clause. if (builder != null && StringUtils.contains(builder.toString(), CQLTranslator.WITH_CLAUSE)) { builder.delete(builder.lastIndexOf(CQLTranslator.WITH_CLAUSE), builder.length()); // builder.deleteCharAt(builder.length() - 2); } } }
From source file:edu.ku.brc.specify.Specify.java
/** * Shows the About dialog./* ww w.java 2 s .c o m*/ */ public void doAbout() { AppContextMgr acm = AppContextMgr.getInstance(); boolean showDetailedAbout = acm.hasContext() && acm.getClassObject(Division.class) != null && acm.getClassObject(Discipline.class) != null && acm.getClassObject(Collection.class) != null; int baseNumRows = 14; String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null); if (serverName != null) { baseNumRows++; } CellConstraints cc = new CellConstraints(); PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g", "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows))); JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$ PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g")); iconPB.add(iconLabel, cc.xy(1, 2)); if (showDetailedAbout) { final ArrayList<String> values = new ArrayList<String>(); DBTableIdMgr tableMgr = DBTableIdMgr.getInstance(); boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered(); int y = 1; infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3)); y += 2; JLabel lbl = UIHelper.createLabel(databaseName); addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y)); addLabel(values, infoPB, lbl, cc.xy(3, y)); y += 2; lbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { openLocalPrefs(); } } }); int instId = Institution.getClassTableId(); addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(instId)), cc.xy(1, y)); addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()), cc.xy(3, y)); y += 2; addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(instId)), cc.xy(1, y)); String noGUID = "<No GUID>"; String guidStr = acm.getClassObject(Institution.class).getGuid(); addLabel(values, infoPB, lbl = UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y)); y += 2; lbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { openRemotePrefs(); } } }); addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())), cc.xy(1, y)); addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Division.class).getName()), cc.xy(3, y)); y += 2; lbl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { openGlobalPrefs(); } } }); addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()), cc.xy(3, y)); y += 2; addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()), cc.xy(3, y)); y += 2; addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(Collection.getClassTableId())), cc.xy(1, y)); guidStr = acm.getClassObject(Collection.class).getGuid(); addLabel(values, infoPB, UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y)); y += 2; //addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y)); //addLabel(values, infoPB, UIHelper.createLabel(appBuildVersion),cc.xy(3, y)); y += 2; addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y)); UIRegistry.loadAndPushResourceBundle("bld"); addLabel(values, infoPB, UIHelper.createLabel(getResourceString("build")), cc.xy(3, y)); y += 2; addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD_TM"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(getResourceString("buildtime")), cc.xy(3, y)); y += 2; UIRegistry.popResourceBundle(); addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"), cc.xy(3, y)); y += 2; String isaNumber = RegisterSpecify.getISANumber(); addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""), cc.xy(3, y)); y += 2; if (serverName != null) { addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""), cc.xy(3, y)); y += 2; } if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) { Vector<Object[]> list = BasicSQLUtils.query("select version() as ve"); if (list != null && list.size() > 0) { addLabel(values, infoPB, UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y)); y += 2; } } addLabel(values, infoPB, UIHelper.createFormLabel("Java Version"), cc.xy(1, y)); addLabel(values, infoPB, UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y)); y += 2; JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "Specify.CPY_ABT_TO_TT", null); //copyCBBtn.setBackground(Color.WHITE); //copyCBBtn.setOpaque(true); //copyCBBtn.setBorder(BorderFactory.createEtchedBorder()); copyCBBtn.setEnabled(true); PanelBuilder cbPB = new PanelBuilder(new FormLayout("f:p:g,p", "p")); cbPB.add(copyCBBtn, cc.xy(2, 1)); copyCBBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Copy to Clipboard StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.size(); i++) { sb.append(String.format("%s = %s\n", values.get(i), values.get(i + 1))); i++; } UIHelper.setTextToClipboard(sb.toString()); UIRegistry.displayInfoMsgDlgLocalized("Specify.CPY_ABT_TO_MSG"); } }); infoPB.add(cbPB.getPanel(), cc.xy(3, y)); y += 2; } String txt = getAboutText(appName, appVersion); JLabel txtLbl = createLabel(txt); txtLbl.setFont(UIRegistry.getDefaultFont()); final JEditorPane txtPane = new JEditorPane("text/html", txt); txtPane.setEditable(false); txtPane.setBackground(new JPanel().getBackground()); PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g")); pb.add(iconPB.getPanel(), cc.xy(1, 1)); pb.add(txtPane, cc.xy(3, 1)); Color bg = getBackground(); if (showDetailedAbout) { pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1)); pb.add(infoPB.getPanel(), cc.xy(7, 1)); } pb.setDefaultDialogBorder(); String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$ CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$ pb.getPanel()); String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$ aboutDlg.setOkLabel(okLabel); aboutDlg.createUI(); aboutDlg.pack(); // for some strange reason I can't get the dialog to size itself correctly Dimension size = aboutDlg.getSize(); size.height += 120; aboutDlg.setSize(size); txtPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { AttachmentUtils.openURI(event.getURL().toURI()); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); } } } }); UIHelper.centerAndShow(aboutDlg); }