All Downloads are FREE. Search and download functionalities are using the official Maven repository.

groovity.portal.lib.portal.grvt Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * © 2018 Disney | ABC Television Group
 *
 * Licensed under the Apache License, Version 2.0 (the "Apache License")
 * with the following modification; you may not use this file except in
 * compliance with the Apache License and the following modification to it:
 * Section 6. Trademarks. is deleted and replaced with:
 *
 * 6. Trademarks. This License does not grant permission to use the trade
 *     names, trademarks, service marks, or product names of the Licensor
 *     and its affiliates, except as required to comply with Section 4(c) of
 *     the License and to reproduce the content of the NOTICE file.
 *
 * You may obtain a copy of the Apache License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Apache License with the above modification is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the Apache License for the specific
 * language governing permissions and limitations under the Apache License.
 *******************************************************************************/
import javax.servlet.http.HttpSession
import javax.websocket.Session
import com.disney.groovity.portal.PortalSitemap

static boolean bootstrapped = false;
static PortalSitemap _sitemap

static init(){
	_sitemap = new PortalSitemap(getClassLoader().groovity)
}

def getSitemap(){
	_sitemap.entries;
}

def getFolders(){
	_sitemap.folders;
}

def getSubfolders(String folder){
	folders.findAll{it.key.startsWith(folder) && it.key.substring(folder.length()).count('/')==1}
}
def getRootPages(){
	def user = request.userPrincipal
	sitemap.findAll{ 
			(( it.path.endsWith("/") || it.path.endsWith("/index")) 
				&& it.path.count("/")==2
			) || (it.path.count("/")==1 && !(it.path=='/') && !(it.path=='/index'))
		
		}.findAll{
		!it.roles || user?.hasRole(request.session, it.path, it.roles) || (!user && it.roles.contains('anon'))
	}.sort{it.order?:1 }
}
def getPages(String folder){
	def user = request.userPrincipal
	if(folder.endsWith('/index')){
		folder = folder.substring(0,folder.length()-6)
	}
	if(folder.endsWith('/')){
		folder = folder.substring(0,folder.length()-1)
	}
	def pages = folders.get(folder).findAll{ !it.path.endsWith('/index') && !it.path.endsWith('/') };
	pages = pages + getSubfolders(folder).findResults{ it.value.find{ it.path.endsWith('/index') || it.path.endsWith('/') }} 
	pages = pages.findAll{
		!it.roles || user?.hasRole(request.session, it.path, it.roles) || (!user && it.roles.contains('anon'))
	};
	pages.sort{it.order?:1}
	pages
}

@Function(info="Check if we need to bootstrap the DB")
public boolean isBootstrapped(){
	if(!bootstrapped){
		bootstrapped = load('/groovity/sql').sql('portalDB').firstRow("SELECT 1 from person LIMIT 1");
	}
	bootstrapped;
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy