Skip to content

Commit

Permalink
#7768: Using Navtool not as static
Browse files Browse the repository at this point in the history
  • Loading branch information
oarrietadotcms committed May 21, 2015
1 parent e5002c3 commit 8b51b98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/com/dotmarketing/viewtools/navigation/NavTool.java
Expand Up @@ -57,17 +57,17 @@ public void init(Object initData) {
}

protected NavResult getNav(Host host, String path) throws DotDataException, DotSecurityException {
return getNav(host, path, this.currentLanguage);
return getNav(host, path, this.currentLanguage, this.systemUser);
}

protected NavResult getNav(Host host, String path, long languageId) throws DotDataException, DotSecurityException {
protected NavResult getNav(Host host, String path, long languageId, User systemUserParam) throws DotDataException, DotSecurityException {

if(path != null && path.contains(".")){
path = path.substring(0, path.lastIndexOf("/"));
}


Folder folder=!path.equals("/") ? APILocator.getFolderAPI().findFolderByPath(path, host, systemUser, true) : APILocator.getFolderAPI().findSystemFolder();
Folder folder=!path.equals("/") ? APILocator.getFolderAPI().findFolderByPath(path, host, systemUserParam, true) : APILocator.getFolderAPI().findSystemFolder();
if(folder==null || !UtilMethods.isSet(folder.getIdentifier()))
return null;

Expand All @@ -82,7 +82,7 @@ protected NavResult getNav(Host host, String path, long languageId) throws DotDa
if(!folder.getInode().equals(FolderAPI.SYSTEM_FOLDER)) {
Identifier ident=APILocator.getIdentifierAPI().find(folder);
parentId=ident.getParentPath().equals("/") ?
FolderAPI.SYSTEM_FOLDER : APILocator.getFolderAPI().findFolderByPath(ident.getParentPath(), host, systemUser, false).getInode();
FolderAPI.SYSTEM_FOLDER : APILocator.getFolderAPI().findFolderByPath(ident.getParentPath(), host, systemUserParam, false).getInode();
} else {
parentId=null;
}
Expand All @@ -102,7 +102,7 @@ protected NavResult getNav(Host host, String path, long languageId) throws DotDa
if(path.equals("/"))
menuItems = APILocator.getFolderAPI().findSubFolders(host, true);
else
menuItems = APILocator.getFolderAPI().findMenuItems(folder, systemUser, true);
menuItems = APILocator.getFolderAPI().findMenuItems(folder, systemUserParam, true);

for(Object item : menuItems) {
if(item instanceof Folder) {
Expand Down Expand Up @@ -184,7 +184,7 @@ else if(item instanceof IFileAsset) {
}

public NavResult getNav() throws DotDataException, DotSecurityException {
return getNav((String)request.getAttribute("javax.servlet.forward.request_uri"));
return getNav((String) request.getAttribute("javax.servlet.forward.request_uri"));
}

public NavResult getNav(String path) throws DotDataException, DotSecurityException {
Expand All @@ -204,7 +204,7 @@ public NavResult getNav(String path, long languageId) throws DotDataException, D
if(host==null)
host = currenthost;

return getNav(host,path,languageId);
return getNav(host,path,languageId, systemUser);
}

private Host getHostFromPath(String path) throws DotDataException, DotSecurityException{
Expand Down
10 changes: 6 additions & 4 deletions test/com/dotmarketing/viewtools/navigation/NavToolTest.java
Expand Up @@ -32,12 +32,14 @@ public void testAboutUs() throws Exception { // https://github.com/dotCMS/core/i
//Using Identifier to get the path.
Identifier aboutUsIdentifier=APILocator.getIdentifierAPI().find(aboutUsFolder);

NavResult navResult = NavTool.getNav(demoHost, aboutUsIdentifier.getPath(), 1);
NavTool navTool = new NavTool();

NavResult navResult = navTool.getNav(demoHost, aboutUsIdentifier.getPath(), 1, user);

//We are expecting 4 children result for English Language.
int englishResultChildren = navResult.getChildren().size();

navResult = NavTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2);
navResult = navTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2, user);

//We are expecting 2 children result for Spanish Language.
int spanishResultChildren = navResult.getChildren().size();
Expand Down Expand Up @@ -68,7 +70,7 @@ public void testAboutUs() throws Exception { // https://github.com/dotCMS/core/i
contentletsCreated.add(working);
}

navResult = NavTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2);
navResult = navTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2, user);

//Now We are expecting same children result for Spanish Language that English Language.
assertEquals(englishResultChildren, navResult.getChildren().size());
Expand All @@ -79,7 +81,7 @@ public void testAboutUs() throws Exception { // https://github.com/dotCMS/core/i
APILocator.getContentletAPI().delete(contentletsCreated, user, false);

//We should back to 2 in Spanish Nav.
navResult = NavTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2);
navResult = navTool.getNav(demoHost, aboutUsIdentifier.getPath(), 2, user);

//Now We are expecting original amount children result for Spanish Language.
assertEquals(spanishResultChildren, navResult.getChildren().size());
Expand Down

0 comments on commit 8b51b98

Please sign in to comment.