MappingFieldFactory { public MetaObject build(KObject kObject) { ElasticMetaObject metaObject = new ElasticMetaObject(kObject.getType()); metaObject.addProperty(new ElasticMetaProperty(MetaObject.META_OBJECT_ID, kObject.getId(), new HashSet<>(Arrays.asList(String.class)))); metaObject.addProperty(new ElasticMetaProperty(MetaObject.META_OBJECT_TYPE, kObject.getType().getName(), new HashSet<>(Arrays.asList(String.class)))); metaObject.addProperty(new ElasticMetaProperty(MetaObject.META_OBJECT_KEY, kObject.getKey(), new HashSet<>(Arrays.asList(String.class)))); metaObject.addProperty(new ElasticMetaProperty(MetaObject.META_OBJECT_CLUSTER_ID, kObject.getClusterId(), new HashSet<>(Arrays.asList(String.class)))); metaObject.addProperty(new ElasticMetaProperty(MetaObject.META_OBJECT_SEGMENT_ID, kObject.getSegmentId(), new HashSet<>(Arrays.asList(String.class)))); final StringBuilder allText = new StringBuilder(kObject.getKey()).append('\n'); if (kObject.getProperties() != null) { kObject.getProperties().forEach(kProperty -> { List<ElasticMetaProperty> properties = build(kProperty); properties.forEach(elasticMetaProperty -> { metaObject.addProperty(elasticMetaProperty); if (elasticMetaProperty.isSearchable() && !elasticMetaProperty.isBoolean()) { allText.append(elasticMetaProperty.getValue()).append('\n'); } }); }); } if (kObject.fullText()) { metaObject.addProperty(new ElasticMetaProperty(FULL_TEXT_FIELD, allText.toString().toLowerCase(), new HashSet<>(Arrays.asList(String.class)), false, true)); } return metaObject; } MappingFieldFactory(ElasticSearchMappingStore elasticMetaModel); MetaObject build(KObject kObject); KObject fromDocument(Map<String, ?> document); static final String CHECKIN_COMMENT; static final String LAST_MODIFIED_BY; static final String CREATED_BY; static final String CREATED_DATE; static final String LAST_MODIFIED_DATE; }
@Test public void testCreateMetaObject() { KObjectImpl kobject = new KObjectImpl("1", "java", "cluster", "segment", "key", Arrays.asList(), true); ElasticMetaObject metaObject = (ElasticMetaObject) this.fieldFactory.build(kobject); assertEquals("cluster", ((ElasticMetaProperty) metaObject.getProperty(MetaObject.META_OBJECT_CLUSTER_ID).get()).getValue()); assertEquals(false, metaObject.getProperty(MetaObject.META_OBJECT_CLUSTER_ID).get().isSearchable()); }