// Path: src/java/is/idega/idegaweb/egov/company/EgovCompanyConstants.java
// public class EgovCompanyConstants {
// 
// 	private EgovCompanyConstants() {}
// 
// 	public static final String IW_BUNDLE_IDENTIFIER = "is.idega.idegaweb.egov.company";
// 
// 	public static final String COMPANY_SUPER_ADMIN_ROLE = "company_super_admin";
// 	public static final String COMPANY_ADMIN_ROLE = "company_admin";
// 	public static final String COMPANY_EMPLOYEE_ROLE = "company_staff";
// 
// 	public static final List<String> ALL_COMPANY_ROLES = Collections.unmodifiableList(Arrays.asList(
// 			StandardRoles.ROLE_KEY_COMPANY,
// 			COMPANY_SUPER_ADMIN_ROLE,
// 			COMPANY_ADMIN_ROLE,
// 			COMPANY_EMPLOYEE_ROLE
// 	));
// 
// 	public static final String GROUP_TYPE_COMPANY_ADMINS = "iw_company_admins_group";
// 	public static final String GROUP_TYPE_COMPANY_STAFF = "iw_company_staff_group";
// 	public static final List<String> ALL_COMPANY_TYPES = Collections.unmodifiableList(Arrays.asList(
// 			CompanyConstants.GROUP_TYPE_COMPANY,
// 			GROUP_TYPE_COMPANY_ADMINS,
// 			GROUP_TYPE_COMPANY_STAFF
// 	));
// 
// 	public static final String CASE_CODE_KEY = "COMPORT";
// 
// 	public static final String CONTENT_CODE_REQUEST_INFORMATION = "prm_company_code_request_information";
// 
// 	public static final Integer APPLICATION_TYPE_APPROVED = 0;
// 	public static final Integer APPLICATION_TYPE_REJECTED = 1;
// 	public static final Integer APPLICATION_TYPE_UNHANDLED = 2;
// 
// 	public static final String USER_LOGIN_METADATA = "userLoginEnabledMetaDataForCompanyPortal";
// 
// 	public static final String COMPANY_PORTAL_ROOT_GROUP = "Company Portal";
// 	public static final String COMPANY_ADMINS_GROUP_IN_COMPANY_PORTAL = "Company Admins";
// 	public static final String COMPANY_SUPER_ADMINS_GROUP_IN_COMPANY_PORTAL = "Company Super Admins";
// 
// 	public static final String COMPANY_PORTAL_HOME_PAGE_APPLICATION_PROPERTY = "companyPortalHomePage";
// 	public static final String COMPANY_STAFF_HOME_PAGE_APPLICATION_PROPERTY = "companyStaffHomePage";
// 
// 	public static final String COMPANY_PORTAL_CURRENT_COMPANY_ATTRIBUTE = "companyPortalCurrentCompanyId";
// 
// 	public static final String COMPANY_PERSONAL_ID_METADATA = "COMPANY_PERSONAL_ID";
// }
// 
// Path: src/java/is/idega/idegaweb/egov/company/data/CompanyApplication.java
// public interface CompanyApplication extends Case, Application {
// 	
// 	public Company getCompany();
// 	
// 	public void setCompany(Company company);
// 	
// 	public User getAdminUser();
// 	
// 	public User getApplicantUser();
// 	
// 	public void setAdminUser(User user);
// 	
// 	public void setApplicantUser(User user);
// 	
// 	public CompanyType getType();
// 	
// 	public void setType(CompanyType type);
// 	
// 	public String getCaseCodeKey();
// 	
// 	public ICFile getContract();
// 	
// 	public void setContract(ICFile contract);
// 	
// }


import is.idega.idegaweb.egov.company.EgovCompanyConstants;
import is.idega.idegaweb.egov.company.data.CompanyApplication;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.business.IBORuntimeException;
import com.idega.company.CompanyConstants;
import com.idega.company.business.CompanyBusiness;
import com.idega.company.data.Company;
import com.idega.core.builder.data.ICPage;
import com.idega.core.business.DefaultSpringBean;
import com.idega.core.data.ICTreeNode;
import com.idega.idegaweb.IWApplicationContext;
import com.idega.idegaweb.IWMainApplication;
import com.idega.idegaweb.IWResourceBundle;
import com.idega.presentation.IWContext;
import com.idega.user.business.GroupBusiness;
import com.idega.user.business.UserBusiness;
import com.idega.user.data.Group;
import com.idega.user.data.User;
import com.idega.user.util.UserComparator;
import com.idega.util.CoreConstants;
import com.idega.util.CoreUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringUtil;
import com.idega.util.expression.ELUtil;
		if (group == null || user == null) {
			return false;
		}
		List<Group> allUserCompanies = getAllUserCompanies(user);
		if (ListUtil.isEmpty(allUserCompanies)) {
			return false;
		}

		String groupType = group.getGroupType();
		if (StringUtil.isEmpty(groupType)) {
			return false;
		}

		if (CompanyConstants.GROUP_TYPE_COMPANY.equals(groupType)) {
			return allUserCompanies.contains(group);
		}

		Group companyGroup = null;
		if (EgovCompanyConstants.GROUP_TYPE_COMPANY_STAFF.equals(groupType) || EgovCompanyConstants.GROUP_TYPE_COMPANY_ADMINS.equals(groupType)) {
			companyGroup = getParentGroup(group, CompanyConstants.GROUP_TYPE_COMPANY, null);
		}

		if (companyGroup == null) {
			return false;
		}
		return allUserCompanies.contains(companyGroup);
	}

	@Override
	public Company getCompanyForUser(User user) {
// Path: src/java/is/idega/idegaweb/egov/company/EgovCompanyConstants.java
// public class EgovCompanyConstants {
// 
// 	private EgovCompanyConstants() {}
// 
// 	public static final String IW_BUNDLE_IDENTIFIER = "is.idega.idegaweb.egov.company";
// 
// 	public static final String COMPANY_SUPER_ADMIN_ROLE = "company_super_admin";
// 	public static final String COMPANY_ADMIN_ROLE = "company_admin";
// 	public static final String COMPANY_EMPLOYEE_ROLE = "company_staff";
// 
// 	public static final List<String> ALL_COMPANY_ROLES = Collections.unmodifiableList(Arrays.asList(
// 			StandardRoles.ROLE_KEY_COMPANY,
// 			COMPANY_SUPER_ADMIN_ROLE,
// 			COMPANY_ADMIN_ROLE,
// 			COMPANY_EMPLOYEE_ROLE
// 	));
// 
// 	public static final String GROUP_TYPE_COMPANY_ADMINS = "iw_company_admins_group";
// 	public static final String GROUP_TYPE_COMPANY_STAFF = "iw_company_staff_group";
// 	public static final List<String> ALL_COMPANY_TYPES = Collections.unmodifiableList(Arrays.asList(
// 			CompanyConstants.GROUP_TYPE_COMPANY,
// 			GROUP_TYPE_COMPANY_ADMINS,
// 			GROUP_TYPE_COMPANY_STAFF
// 	));
// 
// 	public static final String CASE_CODE_KEY = "COMPORT";
// 
// 	public static final String CONTENT_CODE_REQUEST_INFORMATION = "prm_company_code_request_information";
// 
// 	public static final Integer APPLICATION_TYPE_APPROVED = 0;
// 	public static final Integer APPLICATION_TYPE_REJECTED = 1;
// 	public static final Integer APPLICATION_TYPE_UNHANDLED = 2;
// 
// 	public static final String USER_LOGIN_METADATA = "userLoginEnabledMetaDataForCompanyPortal";
// 
// 	public static final String COMPANY_PORTAL_ROOT_GROUP = "Company Portal";
// 	public static final String COMPANY_ADMINS_GROUP_IN_COMPANY_PORTAL = "Company Admins";
// 	public static final String COMPANY_SUPER_ADMINS_GROUP_IN_COMPANY_PORTAL = "Company Super Admins";
// 
// 	public static final String COMPANY_PORTAL_HOME_PAGE_APPLICATION_PROPERTY = "companyPortalHomePage";
// 	public static final String COMPANY_STAFF_HOME_PAGE_APPLICATION_PROPERTY = "companyStaffHomePage";
// 
// 	public static final String COMPANY_PORTAL_CURRENT_COMPANY_ATTRIBUTE = "companyPortalCurrentCompanyId";
// 
// 	public static final String COMPANY_PERSONAL_ID_METADATA = "COMPANY_PERSONAL_ID";
// }
// 
// Path: src/java/is/idega/idegaweb/egov/company/data/CompanyApplication.java
// public interface CompanyApplication extends Case, Application {
// 	
// 	public Company getCompany();
// 	
// 	public void setCompany(Company company);
// 	
// 	public User getAdminUser();
// 	
// 	public User getApplicantUser();
// 	
// 	public void setAdminUser(User user);
// 	
// 	public void setApplicantUser(User user);
// 	
// 	public CompanyType getType();
// 	
// 	public void setType(CompanyType type);
// 	
// 	public String getCaseCodeKey();
// 	
// 	public ICFile getContract();
// 	
// 	public void setContract(ICFile contract);
// 	
// }


// Path: src/java/is/idega/idegaweb/egov/company/business/CompanyPortalBusinessBean.java
import is.idega.idegaweb.egov.company.EgovCompanyConstants;
import is.idega.idegaweb.egov.company.data.CompanyApplication;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.business.IBORuntimeException;
import com.idega.company.CompanyConstants;
import com.idega.company.business.CompanyBusiness;
import com.idega.company.data.Company;
import com.idega.core.builder.data.ICPage;
import com.idega.core.business.DefaultSpringBean;
import com.idega.core.data.ICTreeNode;
import com.idega.idegaweb.IWApplicationContext;
import com.idega.idegaweb.IWMainApplication;
import com.idega.idegaweb.IWResourceBundle;
import com.idega.presentation.IWContext;
import com.idega.user.business.GroupBusiness;
import com.idega.user.business.UserBusiness;
import com.idega.user.data.Group;
import com.idega.user.data.User;
import com.idega.user.util.UserComparator;
import com.idega.util.CoreConstants;
import com.idega.util.CoreUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringUtil;
import com.idega.util.expression.ELUtil;

		if (group == null || user == null) {
			return false;
		}
		List<Group> allUserCompanies = getAllUserCompanies(user);
		if (ListUtil.isEmpty(allUserCompanies)) {
			return false;
		}

		String groupType = group.getGroupType();
		if (StringUtil.isEmpty(groupType)) {
			return false;
		}

		if (CompanyConstants.GROUP_TYPE_COMPANY.equals(groupType)) {
			return allUserCompanies.contains(group);
		}

		Group companyGroup = null;
		if (EgovCompanyConstants.GROUP_TYPE_COMPANY_STAFF.equals(groupType) || EgovCompanyConstants.GROUP_TYPE_COMPANY_ADMINS.equals(groupType)) {
			companyGroup = getParentGroup(group, CompanyConstants.GROUP_TYPE_COMPANY, null);
		}

		if (companyGroup == null) {
			return false;
		}
		return allUserCompanies.contains(companyGroup);
	}

	@Override
	public Company getCompanyForUser(User user) {
		if (user == null) {