@Test public void testResolveDocumentReferenceWhenMissingParents() { EntityReference reference = resolver.resolve(new EntityReference("page", EntityType.DOCUMENT), EntityType.DOCUMENT); Assert.assertEquals("defspace", reference.getParent().getName()); Assert.assertEquals(EntityType.SPACE, reference.getParent().getType()); Assert.assertEquals("defwiki", reference.getParent().getParent().getName()); Assert.assertEquals(EntityType.WIKI, reference.getParent().getParent().getType()); }
public EntityReference resolve(EntityReference referenceToResolve, EntityType type) { EntityReference normalizedReference; if (type.ordinal() > referenceToResolve.getType().ordinal()) { normalizedReference = new EntityReference(getDefaultValue(type), type, referenceToResolve.clone()); } else { normalizedReference = referenceToResolve.clone(); } EntityReference reference = normalizedReference; while (reference != null) { List<EntityType> types = this.nextAllowedEntityTypes.get(reference.getType()); if (reference.getParent() != null && !types.isEmpty() && !types.contains(reference.getParent().getType())) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0), reference.getParent()); reference.setParent(newReference); } else if (reference.getParent() == null && !types.isEmpty()) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0)); reference.setParent(newReference); } else if (reference.getParent() != null && types.isEmpty()) { throw new InvalidEntityReferenceException("Invalid reference [" + referenceToResolve + "]"); } reference = reference.getParent(); } if (type.ordinal() < referenceToResolve.getType().ordinal()) { normalizedReference = normalizedReference.extractReference(type); } return normalizedReference; }
DefaultReferenceEntityReferenceResolver implements EntityReferenceResolver<EntityReference> { public EntityReference resolve(EntityReference referenceToResolve, EntityType type) { EntityReference normalizedReference; if (type.ordinal() > referenceToResolve.getType().ordinal()) { normalizedReference = new EntityReference(getDefaultValue(type), type, referenceToResolve.clone()); } else { normalizedReference = referenceToResolve.clone(); } EntityReference reference = normalizedReference; while (reference != null) { List<EntityType> types = this.nextAllowedEntityTypes.get(reference.getType()); if (reference.getParent() != null && !types.isEmpty() && !types.contains(reference.getParent().getType())) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0), reference.getParent()); reference.setParent(newReference); } else if (reference.getParent() == null && !types.isEmpty()) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0)); reference.setParent(newReference); } else if (reference.getParent() != null && types.isEmpty()) { throw new InvalidEntityReferenceException("Invalid reference [" + referenceToResolve + "]"); } reference = reference.getParent(); } if (type.ordinal() < referenceToResolve.getType().ordinal()) { normalizedReference = normalizedReference.extractReference(type); } return normalizedReference; } }
DefaultReferenceEntityReferenceResolver implements EntityReferenceResolver<EntityReference> { public EntityReference resolve(EntityReference referenceToResolve, EntityType type) { EntityReference normalizedReference; if (type.ordinal() > referenceToResolve.getType().ordinal()) { normalizedReference = new EntityReference(getDefaultValue(type), type, referenceToResolve.clone()); } else { normalizedReference = referenceToResolve.clone(); } EntityReference reference = normalizedReference; while (reference != null) { List<EntityType> types = this.nextAllowedEntityTypes.get(reference.getType()); if (reference.getParent() != null && !types.isEmpty() && !types.contains(reference.getParent().getType())) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0), reference.getParent()); reference.setParent(newReference); } else if (reference.getParent() == null && !types.isEmpty()) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0)); reference.setParent(newReference); } else if (reference.getParent() != null && types.isEmpty()) { throw new InvalidEntityReferenceException("Invalid reference [" + referenceToResolve + "]"); } reference = reference.getParent(); } if (type.ordinal() < referenceToResolve.getType().ordinal()) { normalizedReference = normalizedReference.extractReference(type); } return normalizedReference; }  }
DefaultReferenceEntityReferenceResolver implements EntityReferenceResolver<EntityReference> { public EntityReference resolve(EntityReference referenceToResolve, EntityType type) { EntityReference normalizedReference; if (type.ordinal() > referenceToResolve.getType().ordinal()) { normalizedReference = new EntityReference(getDefaultValue(type), type, referenceToResolve.clone()); } else { normalizedReference = referenceToResolve.clone(); } EntityReference reference = normalizedReference; while (reference != null) { List<EntityType> types = this.nextAllowedEntityTypes.get(reference.getType()); if (reference.getParent() != null && !types.isEmpty() && !types.contains(reference.getParent().getType())) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0), reference.getParent()); reference.setParent(newReference); } else if (reference.getParent() == null && !types.isEmpty()) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0)); reference.setParent(newReference); } else if (reference.getParent() != null && types.isEmpty()) { throw new InvalidEntityReferenceException("Invalid reference [" + referenceToResolve + "]"); } reference = reference.getParent(); } if (type.ordinal() < referenceToResolve.getType().ordinal()) { normalizedReference = normalizedReference.extractReference(type); } return normalizedReference; }  EntityReference resolve(EntityReference referenceToResolve, EntityType type); }
DefaultReferenceEntityReferenceResolver implements EntityReferenceResolver<EntityReference> { public EntityReference resolve(EntityReference referenceToResolve, EntityType type) { EntityReference normalizedReference; if (type.ordinal() > referenceToResolve.getType().ordinal()) { normalizedReference = new EntityReference(getDefaultValue(type), type, referenceToResolve.clone()); } else { normalizedReference = referenceToResolve.clone(); } EntityReference reference = normalizedReference; while (reference != null) { List<EntityType> types = this.nextAllowedEntityTypes.get(reference.getType()); if (reference.getParent() != null && !types.isEmpty() && !types.contains(reference.getParent().getType())) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0), reference.getParent()); reference.setParent(newReference); } else if (reference.getParent() == null && !types.isEmpty()) { EntityReference newReference = new EntityReference( getDefaultValue(types.get(0)), types.get(0)); reference.setParent(newReference); } else if (reference.getParent() != null && types.isEmpty()) { throw new InvalidEntityReferenceException("Invalid reference [" + referenceToResolve + "]"); } reference = reference.getParent(); } if (type.ordinal() < referenceToResolve.getType().ordinal()) { normalizedReference = normalizedReference.extractReference(type); } return normalizedReference; }  EntityReference resolve(EntityReference referenceToResolve, EntityType type);  }