@Test public void testEmbed() { try { studyDoc.embed(associationDoc); } catch (DocumentEmbeddingException e) { e.printStackTrace(); fail(); } }
public void embed(Document document) { try { Set<String> excludeNames = new HashSet<>(); BeanInfo objectInfo = Introspector.getBeanInfo(Document.class); for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) { excludeNames.add(descriptor.getName()); } try { BeanInfo docInfo = Introspector.getBeanInfo(document.getClass()); for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) { if (!excludeNames.contains(descriptor.getName())) { boolean isExcluded = false; Method readMethod = descriptor.getReadMethod(); readMethod.setAccessible(true); if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } else { try { Field field = document.getClass().getDeclaredField(descriptor.getName()); field.setAccessible(true); if (field.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } } catch (NoSuchFieldException e) { } } if (!isExcluded) { try { Method propertyAdderMethod = findPropertyAdder(descriptor); Object fieldToEmbed = descriptor.getReadMethod().invoke(document); propertyAdderMethod.invoke(this, fieldToEmbed); } catch (InvocationTargetException | IllegalAccessException e) { throw new DocumentEmbeddingException( "Failed to read property '" + descriptor.getName() + "'", e); } } } } } catch (IntrospectionException e) { throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e); } } catch (IntrospectionException e) { throw new DocumentEmbeddingException( "Failed to read Object.class when determining which properties to exclude", e); } }
EmbeddableDocument extends Document<O> { public void embed(Document document) { try { Set<String> excludeNames = new HashSet<>(); BeanInfo objectInfo = Introspector.getBeanInfo(Document.class); for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) { excludeNames.add(descriptor.getName()); } try { BeanInfo docInfo = Introspector.getBeanInfo(document.getClass()); for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) { if (!excludeNames.contains(descriptor.getName())) { boolean isExcluded = false; Method readMethod = descriptor.getReadMethod(); readMethod.setAccessible(true); if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } else { try { Field field = document.getClass().getDeclaredField(descriptor.getName()); field.setAccessible(true); if (field.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } } catch (NoSuchFieldException e) { } } if (!isExcluded) { try { Method propertyAdderMethod = findPropertyAdder(descriptor); Object fieldToEmbed = descriptor.getReadMethod().invoke(document); propertyAdderMethod.invoke(this, fieldToEmbed); } catch (InvocationTargetException | IllegalAccessException e) { throw new DocumentEmbeddingException( "Failed to read property '" + descriptor.getName() + "'", e); } } } } } catch (IntrospectionException e) { throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e); } } catch (IntrospectionException e) { throw new DocumentEmbeddingException( "Failed to read Object.class when determining which properties to exclude", e); } } }
EmbeddableDocument extends Document<O> { public void embed(Document document) { try { Set<String> excludeNames = new HashSet<>(); BeanInfo objectInfo = Introspector.getBeanInfo(Document.class); for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) { excludeNames.add(descriptor.getName()); } try { BeanInfo docInfo = Introspector.getBeanInfo(document.getClass()); for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) { if (!excludeNames.contains(descriptor.getName())) { boolean isExcluded = false; Method readMethod = descriptor.getReadMethod(); readMethod.setAccessible(true); if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } else { try { Field field = document.getClass().getDeclaredField(descriptor.getName()); field.setAccessible(true); if (field.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } } catch (NoSuchFieldException e) { } } if (!isExcluded) { try { Method propertyAdderMethod = findPropertyAdder(descriptor); Object fieldToEmbed = descriptor.getReadMethod().invoke(document); propertyAdderMethod.invoke(this, fieldToEmbed); } catch (InvocationTargetException | IllegalAccessException e) { throw new DocumentEmbeddingException( "Failed to read property '" + descriptor.getName() + "'", e); } } } } } catch (IntrospectionException e) { throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e); } } catch (IntrospectionException e) { throw new DocumentEmbeddingException( "Failed to read Object.class when determining which properties to exclude", e); } } EmbeddableDocument(O object); }
EmbeddableDocument extends Document<O> { public void embed(Document document) { try { Set<String> excludeNames = new HashSet<>(); BeanInfo objectInfo = Introspector.getBeanInfo(Document.class); for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) { excludeNames.add(descriptor.getName()); } try { BeanInfo docInfo = Introspector.getBeanInfo(document.getClass()); for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) { if (!excludeNames.contains(descriptor.getName())) { boolean isExcluded = false; Method readMethod = descriptor.getReadMethod(); readMethod.setAccessible(true); if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } else { try { Field field = document.getClass().getDeclaredField(descriptor.getName()); field.setAccessible(true); if (field.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } } catch (NoSuchFieldException e) { } } if (!isExcluded) { try { Method propertyAdderMethod = findPropertyAdder(descriptor); Object fieldToEmbed = descriptor.getReadMethod().invoke(document); propertyAdderMethod.invoke(this, fieldToEmbed); } catch (InvocationTargetException | IllegalAccessException e) { throw new DocumentEmbeddingException( "Failed to read property '" + descriptor.getName() + "'", e); } } } } } catch (IntrospectionException e) { throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e); } } catch (IntrospectionException e) { throw new DocumentEmbeddingException( "Failed to read Object.class when determining which properties to exclude", e); } } EmbeddableDocument(O object); void embed(Document document); }
EmbeddableDocument extends Document<O> { public void embed(Document document) { try { Set<String> excludeNames = new HashSet<>(); BeanInfo objectInfo = Introspector.getBeanInfo(Document.class); for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) { excludeNames.add(descriptor.getName()); } try { BeanInfo docInfo = Introspector.getBeanInfo(document.getClass()); for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) { if (!excludeNames.contains(descriptor.getName())) { boolean isExcluded = false; Method readMethod = descriptor.getReadMethod(); readMethod.setAccessible(true); if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } else { try { Field field = document.getClass().getDeclaredField(descriptor.getName()); field.setAccessible(true); if (field.isAnnotationPresent(NonEmbeddableField.class)) { isExcluded = true; } } catch (NoSuchFieldException e) { } } if (!isExcluded) { try { Method propertyAdderMethod = findPropertyAdder(descriptor); Object fieldToEmbed = descriptor.getReadMethod().invoke(document); propertyAdderMethod.invoke(this, fieldToEmbed); } catch (InvocationTargetException | IllegalAccessException e) { throw new DocumentEmbeddingException( "Failed to read property '" + descriptor.getName() + "'", e); } } } } } catch (IntrospectionException e) { throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e); } } catch (IntrospectionException e) { throw new DocumentEmbeddingException( "Failed to read Object.class when determining which properties to exclude", e); } } EmbeddableDocument(O object); void embed(Document document);  }