/** * Trim attributes of the object node to return. * * @param objectNode The object node to return. * @return The trimmed object node ready to return to the client. */ public ObjectNode trimObjectNode(final ObjectNode objectNode) { return trimObjectNode(objectNode, Path.root()); }
/** * Creates a path to the root of the JSON object that contains all the * extension attributes of an extension schema defined by the provided class. * * @param extensionClass The the extension class that defines the extension * schema. * @param <T> The generic type parameter of the Java class used to represent * the extension. * * @return The path to the root of the JSON object that contains all the * extension attributes of an extension schema. */ public static <T> Path root(final Class<T> extensionClass) { return root(SchemaUtils.getSchemaUrn(extensionClass)); }
/** * Creates a path to the root of the JSON object that contains all the * extension attributes of an extension schema defined by the provided class. * * @param extensionClass The the extension class that defines the extension * schema. * @param <T> The generic type parameter of the Java class used to represent * the extension. * * @return The path to the root of the JSON object that contains all the * extension attributes of an extension schema. */ public static <T> Path root(final Class<T> extensionClass) { return root(SchemaUtils.getSchemaUrn(extensionClass)); }
private Path computeDiffPath( final Path parentPath, final String sourceKey, final JsonNode sourceNode) { return parentPath.isRoot() && SchemaUtils.isUrn(sourceKey) ? Path.root(sourceKey) : parentPath.attribute(sourceKey); }
private Path computeDiffPath( final Path parentPath, final String sourceKey, final JsonNode sourceNode) { return parentPath.isRoot() && SchemaUtils.isUrn(sourceKey) ? Path.root(sourceKey) : parentPath.attribute(sourceKey); }
/** * Normalize a path by removing the schema URN for core attributes. * * @param path The path to normalize. * @return The normalized path. */ public Path normalizePath(final Path path) { if(path.getSchemaUrn() != null && coreSchema != null && path.getSchemaUrn().equalsIgnoreCase(coreSchema.getId())) { return Path.root().attribute(path); } return path; }
/** * {@inheritDoc} */ @Override public void apply(final ObjectNode node) throws ScimException { JsonUtils.replaceValue(getPath() == null ? Path.root() : getPath(), node, value); addMissingSchemaUrns(node); }
/** * {@inheritDoc} */ @Override public void apply(final ObjectNode node) throws ScimException { JsonUtils.addValue(getPath() == null ? Path.root() : getPath(), node, value); addMissingSchemaUrns(node); }
/** * {@inheritDoc} */ @Override public void apply(final ObjectNode node) throws ScimException { JsonUtils.addValue(getPath() == null ? Path.root() : getPath(), node, value); addMissingSchemaUrns(node); }
/** * {@inheritDoc} */ @Override public void apply(final ObjectNode node) throws ScimException { JsonUtils.replaceValue(getPath() == null ? Path.root() : getPath(), node, value); addMissingSchemaUrns(node); }
ObjectNode targetToAdd = target.deepCopy(); ObjectNode targetToReplace = target.deepCopy(); diff(Path.root(), source, targetToAdd, targetToReplace, ops, removeMissing); if(targetToReplace.size() > 0)
ObjectNode targetToAdd = target.deepCopy(); ObjectNode targetToReplace = target.deepCopy(); diff(Path.root(), source, targetToAdd, targetToReplace, ops, removeMissing); if(targetToReplace.size() > 0)
/** * Tests json generation of the schema annotation. * @throws Exception thrown if an error occurs. */ @Test public void testJsonGeneration_annotations() throws Exception { CoreClass_User user = getBasicUser(); String userString = JsonUtils.getObjectWriter().writeValueAsString(user); JsonNode userNode = JsonUtils.getObjectReader().readTree(userString); // check some of the basic fields Assert.assertEquals(userNode.path("userName").asText(), user.getUserName()); Assert.assertEquals(userNode.path("id").asText(), user.getId()); Assert.assertEquals(userNode.path("externalId").asText(), user.getExternalId()); // check the schemas Assert.assertEquals( JsonUtils.getObjectReader().treeToValue(userNode.path("schemas"), HashSet.class), user.getSchemaUrns()); // check the extension values Assert.assertEquals( userNode.path("urn:pingidentity:schemas:FavoriteColor"). path("favoriteColor").asText(), JsonUtils.nodeToValue(user.getExtensionValues( Path.root(ExtensionClass.class)).get(0), ExtensionClass.class).getFavoriteColor()); }
Path path = Path.root(); if(patchOperation.getPath() != null)
/** * Tests getting extensions from a generic scim object. * @throws Exception thrown if an error occurs. */ @Test public void testGetExtensionAsGenericScimObject() throws Exception { GenericScimResource commonScimObject = getGenericUser(); ExtensionClass extensionClass = JsonUtils.nodeToValue( commonScimObject.getValue(Path.root(ExtensionClass.class)), ExtensionClass.class); Map extensionAttrs = JsonUtils.nodeToValue( commonScimObject.getValue( "urn:pingidentity:schemas:FavoriteColor:"), Map.class); Assert.assertEquals(extensionClass.getFavoriteColor(), "extension:favoritecolor"); Assert.assertEquals(extensionAttrs.get("favoriteColor"), extensionClass.getFavoriteColor()); }
/** * Test de-serializing the full core user representation copied from * draft-ietf-scim-core-schema-20. * * @throws Exception if an error occurs. */ @Test public void testSpecFullRepresentation() throws Exception { UserResource userResource = JsonUtils.getObjectReader().forType(UserResource.class).readValue( fullRepresentation); assertNotNull(userResource.getName()); assertNotNull(userResource.getName().getGivenName()); assertNotNull(userResource.getEmails()); assertNotNull(userResource.getEmails().get(0).getValue()); assertNotNull(userResource.getEmails().get(1).getValue()); EnterpriseUserExtension enterpriseUserExtension = JsonUtils.nodeToValue(userResource.getExtensionValues( Path.root(EnterpriseUserExtension.class)).get(0), EnterpriseUserExtension.class); assertNotNull(enterpriseUserExtension); String serializedString = JsonUtils.getObjectWriter().writeValueAsString( userResource); assertEquals( JsonUtils.getObjectReader().forType(UserResource.class).readValue( serializedString), userResource); }
new EnterpriseUserExtension().setEmployeeNumber("1234"); newUser.replaceExtensionValue( Path.root(EnterpriseUserExtension.class), JsonUtils.valueToNode(extension)); Path.root(EnterpriseUserExtension.class)).get(0), EnterpriseUserExtension.class), extension); Path.root(EnterpriseUserExtension.class).attribute("employeeNumber")) .get(0).textValue(), "1234");
Path.root().attribute("test").attribute("test"))), null); assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
/** * Create a user (test class) with an extension. * @return a user for tests. * @throws URISyntaxException thrown if an error occurs. */ private CoreClass_User getBasicUser() throws URISyntaxException, ScimException { CoreClass_Name name = new CoreClass_Name(); name.setFirst("name:first"); name.setMiddle("name:middle"); name.setLast("name:last"); Meta meta = new Meta(); meta.setCreated(new GregorianCalendar()); meta.setLastModified(new GregorianCalendar()); meta.setLocation(new URI("http://here/user")); meta.setResourceType("some resource type"); meta.setVersion("1.0"); ExtensionClass extensionClass = new ExtensionClass(); extensionClass.setFavoriteColor("extension:favoritecolor"); CoreClass_User user = new CoreClass_User(); user.setPassword("user:password"); user.setUserName("user:username"); user.setName(name); user.setId("user:id"); user.setExternalId("user:externalId"); user.setMeta(meta); user.replaceExtensionValue(Path.root(extensionClass.getClass()), JsonUtils.valueToNode(extensionClass)); return user; }