@Test public void propertyValueIsCheckedWhenSearchingCategories() throws XWikiException { XWikiDocument doc = mock(XWikiDocument.class); ListProperty prop = mock(ListProperty.class); when(prop.getName()).thenReturn(TYPE_PHENOTYPE); List<BaseObject> categories = new ArrayList<>(); BaseObject category = mock(BaseObject.class); StringProperty temp = new StringProperty(); temp.setValue(TYPE_PHENOTYPE); when(category.get("target_property_name")).thenReturn(temp); temp = new StringProperty(); temp.setValue("HP:0000123"); when(category.get("target_property_value")).thenReturn(temp); List<String> specifiedCategories = new ArrayList<>(); specifiedCategories.add(HP0012211); specifiedCategories.add(HP0000082); when(category.getListValue("target_property_category")).thenReturn(specifiedCategories); categories.add(category); when(doc.getXObjects(new EntityReference("PhenotypeCategoryClass", EntityType.DOCUMENT, Constants.CODE_SPACE_REFERENCE))).thenReturn(categories); JSONObject json = new PhenoTipsFeature(doc, prop, HP0000100).toJSON(); Assert.assertFalse(json.has("categories")); }
@Override public JSONObject toJSON() { JSONObject result = super.toJSON(); result.put(TYPE_JSON_KEY_NAME, getType()); result.put(OBSERVED_JSON_KEY_NAME, (this.present ? JSON_PRESENTSTATUS_YES : JSON_PRESENTSTATUS_NO)); if (!this.metadata.isEmpty()) { JSONArray metadataList = new JSONArray(); for (FeatureMetadatum metadatum : this.metadata.values()) { metadataList.put(metadatum.toJSON()); } result.put(METADATA_JSON_KEY_NAME, metadataList); } if (StringUtils.isNotBlank(this.notes)) { result.put(NOTES_JSON_KEY_NAME, this.notes); } if (!this.categories.isEmpty()) { JSONArray categoriesList = new JSONArray(); try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject); } } } catch (ComponentLookupException ex) { } result.put(CATEGORIES_JSON_KEY_NAME, categoriesList); } return result; }
PhenoTipsFeature extends AbstractPhenoTipsVocabularyProperty implements Feature { @Override public JSONObject toJSON() { JSONObject result = super.toJSON(); result.put(TYPE_JSON_KEY_NAME, getType()); result.put(OBSERVED_JSON_KEY_NAME, (this.present ? JSON_PRESENTSTATUS_YES : JSON_PRESENTSTATUS_NO)); if (!this.metadata.isEmpty()) { JSONArray metadataList = new JSONArray(); for (FeatureMetadatum metadatum : this.metadata.values()) { metadataList.put(metadatum.toJSON()); } result.put(METADATA_JSON_KEY_NAME, metadataList); } if (StringUtils.isNotBlank(this.notes)) { result.put(NOTES_JSON_KEY_NAME, this.notes); } if (!this.categories.isEmpty()) { JSONArray categoriesList = new JSONArray(); try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject); } } } catch (ComponentLookupException ex) { } result.put(CATEGORIES_JSON_KEY_NAME, categoriesList); } return result; } }
PhenoTipsFeature extends AbstractPhenoTipsVocabularyProperty implements Feature { @Override public JSONObject toJSON() { JSONObject result = super.toJSON(); result.put(TYPE_JSON_KEY_NAME, getType()); result.put(OBSERVED_JSON_KEY_NAME, (this.present ? JSON_PRESENTSTATUS_YES : JSON_PRESENTSTATUS_NO)); if (!this.metadata.isEmpty()) { JSONArray metadataList = new JSONArray(); for (FeatureMetadatum metadatum : this.metadata.values()) { metadataList.put(metadatum.toJSON()); } result.put(METADATA_JSON_KEY_NAME, metadataList); } if (StringUtils.isNotBlank(this.notes)) { result.put(NOTES_JSON_KEY_NAME, this.notes); } if (!this.categories.isEmpty()) { JSONArray categoriesList = new JSONArray(); try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject); } } } catch (ComponentLookupException ex) { } result.put(CATEGORIES_JSON_KEY_NAME, categoriesList); } return result; } PhenoTipsFeature(XWikiDocument doc, ListProperty property, String value);  PhenoTipsFeature(JSONObject json); }
PhenoTipsFeature extends AbstractPhenoTipsVocabularyProperty implements Feature { @Override public JSONObject toJSON() { JSONObject result = super.toJSON(); result.put(TYPE_JSON_KEY_NAME, getType()); result.put(OBSERVED_JSON_KEY_NAME, (this.present ? JSON_PRESENTSTATUS_YES : JSON_PRESENTSTATUS_NO)); if (!this.metadata.isEmpty()) { JSONArray metadataList = new JSONArray(); for (FeatureMetadatum metadatum : this.metadata.values()) { metadataList.put(metadatum.toJSON()); } result.put(METADATA_JSON_KEY_NAME, metadataList); } if (StringUtils.isNotBlank(this.notes)) { result.put(NOTES_JSON_KEY_NAME, this.notes); } if (!this.categories.isEmpty()) { JSONArray categoriesList = new JSONArray(); try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject); } } } catch (ComponentLookupException ex) { } result.put(CATEGORIES_JSON_KEY_NAME, categoriesList); } return result; } PhenoTipsFeature(XWikiDocument doc, ListProperty property, String value);  PhenoTipsFeature(JSONObject json); @Override String getType(); @Override boolean isPresent(); @Override String getValue(); @Override Map<String, ? extends FeatureMetadatum> getMetadata(); @Override String getNotes(); @Override String getPropertyName(); @Override List<String> getCategories(); @Override JSONObject toJSON(); }
PhenoTipsFeature extends AbstractPhenoTipsVocabularyProperty implements Feature { @Override public JSONObject toJSON() { JSONObject result = super.toJSON(); result.put(TYPE_JSON_KEY_NAME, getType()); result.put(OBSERVED_JSON_KEY_NAME, (this.present ? JSON_PRESENTSTATUS_YES : JSON_PRESENTSTATUS_NO)); if (!this.metadata.isEmpty()) { JSONArray metadataList = new JSONArray(); for (FeatureMetadatum metadatum : this.metadata.values()) { metadataList.put(metadatum.toJSON()); } result.put(METADATA_JSON_KEY_NAME, metadataList); } if (StringUtils.isNotBlank(this.notes)) { result.put(NOTES_JSON_KEY_NAME, this.notes); } if (!this.categories.isEmpty()) { JSONArray categoriesList = new JSONArray(); try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject); } } } catch (ComponentLookupException ex) { } result.put(CATEGORIES_JSON_KEY_NAME, categoriesList); } return result; } PhenoTipsFeature(XWikiDocument doc, ListProperty property, String value);  PhenoTipsFeature(JSONObject json); @Override String getType(); @Override boolean isPresent(); @Override String getValue(); @Override Map<String, ? extends FeatureMetadatum> getMetadata(); @Override String getNotes(); @Override String getPropertyName(); @Override List<String> getCategories(); @Override JSONObject toJSON(); static final String META_PROPERTY_NAME; static final String META_PROPERTY_VALUE; static final String META_PROPERTY_CATEGORIES; static final EntityReference CATEGORY_CLASS_REFERENCE; static final String NEGATIVE_PHENOTYPE_PREFIX; }