/** * Wrapper method to send Invite to a user to become colleague * * @param profile profile of the user to whom the invite is to be sent * @param inviteMsg Invite message to the other user * @return value is true if invite is sent successfully else value is false * @throws ProfileServiceException */ public boolean sendInvite(Profile profile, String inviteMsg) throws ProfileServiceException { if (logger.isLoggable(Level.FINEST)) { logger.entering(sourceClass, "getColleagues", inviteMsg); } if (profile == null) { throw new IllegalArgumentException(StringUtil.format("A null profile was passed")); } Map<String, String> parameters = new HashMap<String, String>(); String url = resolveProfileUrl( ProfileEntity.NONADMIN.getProfileEntityType(), ProfileType.CONNECTIONS.getProfileType()); if (isEmail(profile.getReqId())) { parameters.put(ProfileRequestParams.EMAIL, profile.getReqId()); } else { parameters.put(ProfileRequestParams.USERID, profile.getReqId()); } parameters.put("connectionType", "colleague"); XMLProfilesPayloadBuilder builder = XMLProfilesPayloadBuilder.INSTANCE; Object content = builder.generateInviteRequestPayload(inviteMsg); // getClientService().post(url, parameters, content); boolean result = executePost(url, parameters, null, content, null); if (logger.isLoggable(Level.FINEST)) { logger.exiting(sourceClass, "getColleagues"); } return result; }
/** * Get a connection from a connection manager. * * @param context * @param name * @param shared * @return * @throws SQLException */ public static Connection createManagedConnection( FacesContext context, UIComponent from, String name) throws SQLException { if (from == null) { from = context.getViewRoot(); } final IJdbcConnectionManager manager = findConnectionManager(context, from, name); if (manager == null) { throw new FacesExceptionEx( null, StringUtil.format( "Unknown {0} {1}", "ConnectionManager", name)); // $NLX-JdbcUtil.Unknown01-1$ // $NON-NLS-2$ } return manager.getConnection(); }
/** Read a SQL file from the resources. */ public static String readSqlFile(String fileName) { if (StringUtil.isNotEmpty(fileName)) { final Application app = Application.get(); final VFSObjectCache c = app.getVFSCache(); try { String fullPath = JDBC_ROOT + VFS.SEPARATOR + fileName; if (!fullPath.endsWith(".sql")) { // $NON-NLS-1$ fullPath = fullPath + ".sql"; // $NON-NLS-1$ } return (String) c.get( fullPath, new VFSObjectCache.ObjectLoader() { // $NON-NLS-1$ @Override public Object loadObject(VFSFile file) throws VFSException { if (file.exists()) { try { final String s = file.loadAsString(); return s; } catch (final Exception ex) { throw new VFSException( ex, StringUtil.format( "Error while reading {0} Query {1}", "SQL", file)); // $NLX-JdbcUtil.Errorwhilereading0Query1-1$ // $NON-NLS-2$ } } throw new VFSException( null, StringUtil.format( "{0) file {1} does not exist", "SQL Query", file)); // $NLX-JdbcUtil.0file1doesnotexist-1$ // $NON-NLS-2$ } }); } catch (final VFSException ex) { throw new FacesExceptionEx( ex, StringUtil.format( "Error while loading {0} query file {1}", "SQL", fileName)); // $NLX-JdbcUtil.Errorwhileloading0queryfile1-1$ // $NON-NLS-2$ } } return null; }
/** * Convert an integer to an Hexa string and pad the result with '0' * * @param value the int to convert * @param nChars the number of characters of the result * @return the resulting string * @ibm-api * @throws NumberFormatException if nChars is less that the actual number of characters needed */ public static final String toUnsignedHex(int value, int nChars) { FastStringBuffer b = new FastStringBuffer(); // String s = Integer.toHexString(value); for (int i = 7; i >= 0; i--) { int v = (value >>> (i * 4)) & 0x0F; if (b.length() > 0 || v != 0 || i < nChars || i == 0) { b.append(hexChar(v)); } } if (nChars > 0 && b.length() > nChars) { throw new NumberFormatException( StringUtil.format( "Hexadecimal number {0} too big to fit in '{1}' characters", // $NLS-StringUtil.StringUtil.HexNumTooBig.Exception-1$ StringUtil.toString(value), StringUtil.toString(nChars))); } return b.toString(); }
public static List<String> listTables( Connection c, String schema, String tableName, String[] types) throws SQLException { final ResultSet tables = c.getMetaData().getTables(null, schema, tableName, types); try { final ArrayList<String> l = new ArrayList<String>(); while (tables.next()) { final String sc = tables.getString("TABLE_SCHEM"); // $NON-NLS-1$ final String tb = tables.getString("TABLE_NAME"); // $NON-NLS-1$ if (StringUtil.isEmpty(sc)) { l.add(tb); } else { l.add(StringUtil.format("{0}.{1}", sc, tb)); } } return l; } finally { tables.close(); } }
public static String getCountQuery(String q) throws SQLException { // This function transforms a query into another query that actually // counts the number // of entry. It actually replaced the selection of the columns by a // count(*) // The query must be of the form // SELECT xxxx FROM <whatever> // Note that it might not be optimal is all the cases. Also, the // replacement is currently // done using basic string replacement, while a more robust code should // actually fully // parse the SQL. final int sel = StringUtil.indexOfIgnoreCase(q, "select", 0); // $NON-NLS-1$ final int from = StringUtil.indexOfIgnoreCase(q, "from", 0); // $NON-NLS-1$ if (sel < 0 || from < sel) { throw new SQLException( StringUtil.format( "Unable to create a 'count' query for the {0} {1}", "SQL", q)); // $NLX-JdbcUtil.Unabletocreateacountqueryforthe01-1$ // $NON-NLS-2$ } return q.substring(0, sel + 6) + " count(*) " + q.substring(from); // $NON-NLS-1$ }
/** * Wrapper method to get user's colleagues * * @param profile profile of the user whose contacts are to be returned * @param parameters list of query string parameters to pass to API * @return Profiles of User's colleagues * @throws ProfileServiceException */ public Profile[] getColleagues(Profile profile, Map<String, String> parameters) throws ProfileServiceException { if (logger.isLoggable(Level.FINEST)) { logger.entering(sourceClass, "getColleagues", parameters); } if (profile == null) { throw new IllegalArgumentException(StringUtil.format("A null profile was passed")); } Document data = null; Profile[] colleagues = null; if (parameters == null) parameters = new HashMap<String, String>(); String url = resolveProfileUrl( ProfileEntity.NONADMIN.getProfileEntityType(), ProfileType.CONNECTIONS.getProfileType()); if (isEmail(profile.getReqId())) { parameters.put(ProfileRequestParams.EMAIL, profile.getReqId()); } else { parameters.put(ProfileRequestParams.USERID, profile.getReqId()); } if (parameters.get("connectionType") != null) // this is to remove any other values put in by sample user in following parameters.remove("connectionType"); // mandatory parameters if (parameters.get("outputType") != null) parameters.remove("outputType"); parameters.put("connectionType", "colleague"); parameters.put("outputType", "profile"); data = executeGet(url, parameters, ClientService.FORMAT_XML); colleagues = Converter.convertToProfiles(this, data); if (logger.isLoggable(Level.FINEST)) { logger.exiting(sourceClass, "getColleagues"); } return colleagues; }
public void traceEventp(Object clazz, String methodName, String msg, Object... parameters) { if (isTraceEventEnabled()) { logp(clazz, methodName, null, Level.FINE, StringUtil.format(msg, parameters), null); } }
// traceEvent public void traceEvent(String msg, Object... parameters) { if (isTraceEventEnabled()) { log(null, Level.FINE, StringUtil.format(msg, parameters), null); } }
public void errorp( Object clazz, String methodName, Throwable t, String msg, Object... parameters) { if (isErrorEnabled()) { logp(clazz, methodName, t, Level.SEVERE, StringUtil.format(msg, parameters), null); } }
public void error(Throwable t, String msg, Object... parameters) { if (isErrorEnabled()) { log(t, Level.SEVERE, StringUtil.format(msg, parameters), null); } }
public void warnp( Object clazz, String methodName, Throwable t, String msg, Object... parameters) { if (isWarnEnabled()) { logp(clazz, methodName, t, Level.WARNING, StringUtil.format(msg, parameters), null); } }
public void warn(Throwable t, String msg, Object... parameters) { if (isWarnEnabled()) { log(t, Level.WARNING, StringUtil.format(msg, parameters), null); } }
public void info(Throwable t, String msg, Object... parameters) { if (isInfoEnabled()) { log(t, Level.INFO, StringUtil.format(msg, parameters), null); } }
public void traceDebug(Throwable t, String msg, Object... parameters) { if (isTraceDebugEnabled()) { log(t, Level.FINEST, StringUtil.format(msg, parameters), null); } }
public void traceDebugp( Object clazz, String methodName, Throwable t, String msg, Object... parameters) { if (isTraceDebugEnabled()) { logp(clazz, methodName, t, Level.FINEST, StringUtil.format(msg, parameters), null); } }
public void infop( Object clazz, String methodName, Throwable t, String msg, Object... parameters) { if (isInfoEnabled()) { logp(clazz, methodName, t, Level.INFO, StringUtil.format(msg, parameters), null); } }