/** * Searches a user by ID. If multiple realms are configured, each will be tried according to their * ordinal number configuration. Only the first found is returned. */ public Json searchUserById(String id) { if (id == null || id.length() == 0) return Json.array(); for (String providerName : orderedProviders()) { UserProvider P = provider(providerName); Json user = P.get(id); if (!user.isNull()) return user; } return Json.nil(); }
@SuppressWarnings({"unchecked", "rawtypes"}) public <T> T value(Json x) { if (x == null || x.isNull()) return null; else if (x.isPrimitive()) return (T) x.getValue(); else if (x.isArray()) // what to do here ... this is some sort of collection?? return (T) x.getValue(); else if (x.has("java.lang.Enum")) { try { return (T) Enum.valueOf( (Class<Enum>) Class.forName(x.at("java.lang.Enum").asString()), x.at("value").asString()); } catch (Exception t) { throw new RuntimeException(t); } } else if (x.has("javaArrayType")) { String fullName = shortNameMap.getX(x.at("javaArrayType").asString()); if (fullName == null) fullName = x.at("javaArrayType").asString(); try { Class<?> cl = Class.forName(fullName); JsonConverter converter = converterMap.get(fullName); Object A = Array.newInstance(cl, x.at("array").asJsonList().size()); for (int i = 0; i < x.at("array").asJsonList().size(); i++) { Json j = x.at("array").at(i); Array.set(A, i, j.isNull() ? null : converter != null ? converter.from(j) : value(j)); } return (T) A; } catch (Exception ex) { throw new RuntimeException(ex); } } else if (x.has("javaType")) { String fullName = shortNameMap.getX(x.at("javaType").asString()); if (fullName == null) fullName = x.at("javaType").asString(); JsonConverter converter = converterMap.get(fullName); if (converter != null) return (T) converter.from(converter instanceof BeanJsonConverter ? x : x.at("value")); else return (T) beanConverter.from(x); // .at("value")); } else return (T) x.getValue(); }
/** * This is a general method to retrieve information about a particular user. Because it's * expensive to fill out all information we can get about a user, the request is a more complex * object that specifies what is to be provided. In this way, a client can request all that is * needed and only that which is needed in a single network round-trip. * * <p>The basic profile (first name, email etc.) is returned regardless. Here are the expected * properties of the JSON <code>request</code> parameter that control what else is returned: * * <ul> * <li>username - mandatory...of course * <li>groups - true/false whether to include the list of groups the user belongs to * <li>access - true/false whether to include the access policies for this user * </ul> * * @param request * @return */ @POST @Path("/profile") public Json userProfile(Json request) { try { if (!request.isObject() || !request.has("username")) return ko("bad request."); if (!request.has("provider") || request.is("provider", "")) request.set("provider", desc.at("authenticatesWith").at("hasName")); UserProvider providerImpl = provider(request.at("provider").asString()); Json profile = providerImpl.get(request.at("username").asString()); if (profile.isNull()) return ko("No profile"); if (request.is("groups", true) || request.is("access", true)) profile.set("groups", providerImpl.findGroups(request.at("username").asString())); if (request.is("access", true)) profile.set("access", getAccessPolicies(profile.at("groups"))); return ok().set("profile", prepareReturn(profile)); } catch (Throwable t) { if (!"unavailable" .equals(t.getMessage())) // error would have already been reported in the logs t.printStackTrace(System.err); return ko(t.getMessage()); } }
@Override public String resolve(String variableName, Json sr, Properties properties) { String activityLegacyCode; OWLLiteral variableLegacyCode = OWL.dataProperty( MessageManager.findIndividualFromVariable(variableName), "legacy:hasLegacyCode"); if (variableLegacyCode != null && variableLegacyCode.getLiteral().length() > 0) activityLegacyCode = variableLegacyCode .getLiteral(); // look for a specific activity as defined with the variable else activityLegacyCode = properties.getProperty("LEGACY_CODE"); Json activity = SRJsonActivityUtil.getMostRecentActivityByLegacyCode(sr, activityLegacyCode); if (activity == null || activity.isNull()) { System.out.println( "Messaging - ActivityResolver: unable to find activity " + properties.getProperty("LEGACY_CODE") + " in SR " + sr); return null; } String result = null; if (VAR_SR_ACTIVITY_TYPE.equals(variableName)) result = SRJsonActivityUtil.getActivityTypeLabel(activity); else { if (variableName.contains("_OUTCOME")) { result = SRJsonActivityUtil.getHasOutcomeLabel(activity); } else if (variableName.contains("_DETAILS") || variableName.contains("_DTLS$$")) { result = SRJsonActivityUtil.getHasDetails(activity); } else if (variableName.contains("_DUE_DTE")) { result = SRJsonActivityUtil.getHasDueDate(activity, DATE_PATTERN); } else if (variableName.equals("$$SR_ACTIVITY_DATE_TIME$$")) { result = SRJsonActivityUtil.getHasDateCreated(activity, DATE_PATTERN); } else if (variableName.equals("$$SR_ACTIVITY_DUEDATE_SWR$$")) { result = SRJsonActivityUtil.getDueDate90Days(activity, DATE_PATTERN); } else if (variableName.contains("SR_ACTIVITY_CALLCREATED_D")) { result = SRJsonActivityUtil.getIsCreatedByName(activity); } else if (variableName.equals("$$SR_ASSIGNED_STAFF$$")) { result = SRJsonActivityUtil.getAssignedStaffName(activity); } else { System.out.println( "Messaging - ActivityResolver: unable to resolve variable" + variableName); } // Just a check if we already know the variable. if (VALIDATE_VARS_POST_RESOLUTION && !ActivityVariableValidator.isKnown(variableName)) System.err.println( "ActivityResolver resolved an unknown variable: " + variableName + " to value " + result); } if (DBG) { System.out.println( "ActivityResolver: Var " + variableName + " Result: " + result + " Act: " + activity + " Code: " + activityLegacyCode); } return result; }
public String getFullName(String userid) { if (userid == null || userid.isEmpty()) return ""; Json user = searchUserById(userid); if (user.isNull()) return ""; else return user.at("FirstName", "").asString() + " " + user.at("LastName", "").asString(); }