@Test public void toRestHierarchyFromSpaceWithoutPrettyNames() { SpaceReference spaceReference = new SpaceReference("dev", "API"); when(this.xwiki.getURL(spaceReference.getParent(), this.xcontext)).thenReturn("wiki URL"); when(this.xwiki.getURL(spaceReference, this.xcontext)).thenReturn("space URL"); Hierarchy hierarchy = this.modelFactory.toRestHierarchy(spaceReference, false); assertEquals(2, hierarchy.getItems().size()); HierarchyItem item = hierarchy.getItems().get(0); assertEquals(item.getLabel(), item.getName()); assertEquals("dev", item.getName()); assertEquals("wiki", item.getType()); assertEquals("wiki URL", item.getUrl()); item = hierarchy.getItems().get(1); assertEquals(item.getLabel(), item.getName()); assertEquals("API", item.getName()); assertEquals("space", item.getType()); assertEquals("space URL", item.getUrl()); }
public Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames) { XWikiContext xcontext = this.xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); Hierarchy hierarchy = new Hierarchy(); for (EntityReference entityReference : targetEntityReference.getReversedReferenceChain()) { HierarchyItem hierarchyItem = new HierarchyItem(); hierarchyItem.setName(entityReference.getName()); hierarchyItem.setLabel(entityReference.getName()); hierarchyItem.setType(entityReference.getType().getLowerCase()); hierarchyItem.setUrl(xwiki.getURL(entityReference, xcontext)); if (withPrettyNames) { try { if (entityReference.getType() == EntityType.SPACE || entityReference.getType() == EntityType.DOCUMENT) { XWikiDocument document = xwiki.getDocument(entityReference, xcontext).getTranslatedDocument(xcontext); hierarchyItem.setLabel(document.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); hierarchyItem.setUrl(xwiki.getURL(document.getDocumentReferenceWithLocale(), xcontext)); } else if (entityReference.getType() == EntityType.WIKI) { WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(entityReference.getName()); if (wikiDescriptor != null) { hierarchyItem.setLabel(wikiDescriptor.getPrettyName()); } } } catch (Exception e) { this.logger.warn( "Failed to get the pretty name of entity [{}]. Continue using the entity name. Root cause is [{}].", entityReference, ExceptionUtils.getRootCauseMessage(e)); } } hierarchy.withItems(hierarchyItem); } return hierarchy; }
ModelFactory { public Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames) { XWikiContext xcontext = this.xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); Hierarchy hierarchy = new Hierarchy(); for (EntityReference entityReference : targetEntityReference.getReversedReferenceChain()) { HierarchyItem hierarchyItem = new HierarchyItem(); hierarchyItem.setName(entityReference.getName()); hierarchyItem.setLabel(entityReference.getName()); hierarchyItem.setType(entityReference.getType().getLowerCase()); hierarchyItem.setUrl(xwiki.getURL(entityReference, xcontext)); if (withPrettyNames) { try { if (entityReference.getType() == EntityType.SPACE || entityReference.getType() == EntityType.DOCUMENT) { XWikiDocument document = xwiki.getDocument(entityReference, xcontext).getTranslatedDocument(xcontext); hierarchyItem.setLabel(document.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); hierarchyItem.setUrl(xwiki.getURL(document.getDocumentReferenceWithLocale(), xcontext)); } else if (entityReference.getType() == EntityType.WIKI) { WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(entityReference.getName()); if (wikiDescriptor != null) { hierarchyItem.setLabel(wikiDescriptor.getPrettyName()); } } } catch (Exception e) { this.logger.warn( "Failed to get the pretty name of entity [{}]. Continue using the entity name. Root cause is [{}].", entityReference, ExceptionUtils.getRootCauseMessage(e)); } } hierarchy.withItems(hierarchyItem); } return hierarchy; } }
ModelFactory { public Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames) { XWikiContext xcontext = this.xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); Hierarchy hierarchy = new Hierarchy(); for (EntityReference entityReference : targetEntityReference.getReversedReferenceChain()) { HierarchyItem hierarchyItem = new HierarchyItem(); hierarchyItem.setName(entityReference.getName()); hierarchyItem.setLabel(entityReference.getName()); hierarchyItem.setType(entityReference.getType().getLowerCase()); hierarchyItem.setUrl(xwiki.getURL(entityReference, xcontext)); if (withPrettyNames) { try { if (entityReference.getType() == EntityType.SPACE || entityReference.getType() == EntityType.DOCUMENT) { XWikiDocument document = xwiki.getDocument(entityReference, xcontext).getTranslatedDocument(xcontext); hierarchyItem.setLabel(document.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); hierarchyItem.setUrl(xwiki.getURL(document.getDocumentReferenceWithLocale(), xcontext)); } else if (entityReference.getType() == EntityType.WIKI) { WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(entityReference.getName()); if (wikiDescriptor != null) { hierarchyItem.setLabel(wikiDescriptor.getPrettyName()); } } } catch (Exception e) { this.logger.warn( "Failed to get the pretty name of entity [{}]. Continue using the entity name. Root cause is [{}].", entityReference, ExceptionUtils.getRootCauseMessage(e)); } } hierarchy.withItems(hierarchyItem); } return hierarchy; } ModelFactory(); }
ModelFactory { public Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames) { XWikiContext xcontext = this.xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); Hierarchy hierarchy = new Hierarchy(); for (EntityReference entityReference : targetEntityReference.getReversedReferenceChain()) { HierarchyItem hierarchyItem = new HierarchyItem(); hierarchyItem.setName(entityReference.getName()); hierarchyItem.setLabel(entityReference.getName()); hierarchyItem.setType(entityReference.getType().getLowerCase()); hierarchyItem.setUrl(xwiki.getURL(entityReference, xcontext)); if (withPrettyNames) { try { if (entityReference.getType() == EntityType.SPACE || entityReference.getType() == EntityType.DOCUMENT) { XWikiDocument document = xwiki.getDocument(entityReference, xcontext).getTranslatedDocument(xcontext); hierarchyItem.setLabel(document.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); hierarchyItem.setUrl(xwiki.getURL(document.getDocumentReferenceWithLocale(), xcontext)); } else if (entityReference.getType() == EntityType.WIKI) { WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(entityReference.getName()); if (wikiDescriptor != null) { hierarchyItem.setLabel(wikiDescriptor.getPrettyName()); } } } catch (Exception e) { this.logger.warn( "Failed to get the pretty name of entity [{}]. Continue using the entity name. Root cause is [{}].", entityReference, ExceptionUtils.getRootCauseMessage(e)); } } hierarchy.withItems(hierarchyItem); } return hierarchy; } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self); }
ModelFactory { public Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames) { XWikiContext xcontext = this.xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); Hierarchy hierarchy = new Hierarchy(); for (EntityReference entityReference : targetEntityReference.getReversedReferenceChain()) { HierarchyItem hierarchyItem = new HierarchyItem(); hierarchyItem.setName(entityReference.getName()); hierarchyItem.setLabel(entityReference.getName()); hierarchyItem.setType(entityReference.getType().getLowerCase()); hierarchyItem.setUrl(xwiki.getURL(entityReference, xcontext)); if (withPrettyNames) { try { if (entityReference.getType() == EntityType.SPACE || entityReference.getType() == EntityType.DOCUMENT) { XWikiDocument document = xwiki.getDocument(entityReference, xcontext).getTranslatedDocument(xcontext); hierarchyItem.setLabel(document.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); hierarchyItem.setUrl(xwiki.getURL(document.getDocumentReferenceWithLocale(), xcontext)); } else if (entityReference.getType() == EntityType.WIKI) { WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(entityReference.getName()); if (wikiDescriptor != null) { hierarchyItem.setLabel(wikiDescriptor.getPrettyName()); } } } catch (Exception e) { this.logger.warn( "Failed to get the pretty name of entity [{}]. Continue using the entity name. Root cause is [{}].", entityReference, ExceptionUtils.getRootCauseMessage(e)); } } hierarchy.withItems(hierarchyItem); } return hierarchy; } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self);  }