private Json prepareReturn(Json user) { if (user.isArray()) { for (Json u : user.asJsonList()) prepareReturn(u); } else { user.delAt("hasPassword"); // TODO: can we get rid of this? the fear that somewhere on the client // it is being used, but it shouldn't be. if (user.has("hasUsername")) user.set("username", user.at("hasUsername")); } return user; }
private Json getAccessPolicies(Json groups) { if (!groups.isArray()) throw new IllegalArgumentException("Expected Array of cirmusergroups. e.g. legacy:311.."); Json cirmUserGroupsWithAccessPolicies = Json.array(); for (Json iri : groups.asJsonList()) { OWLIndividual group = dataFactory().getOWLNamedIndividual(fullIri(iri.asString())); // Here we need to make sure that the serialization stops at e.g. // individuals that are the objects of an AccessPolicy! Json groupWithAccessPolicies = OWL.toJSON(group, stopExpansionCondition); cirmUserGroupsWithAccessPolicies.add(groupWithAccessPolicies); } // Array of cirm groups with all access policy information serialized. return cirmUserGroupsWithAccessPolicies; // userdata.set("cirmusergroups", // cirmUserGroupsWithAccessPolicies); }
@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(); }