Search in sources :

Example 1 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class PersistencePackageFactoryImpl method getClassNameForSection.

protected String getClassNameForSection(String sectionKey) {
    try {
        AdminSection section = adminNavigationService.findAdminSectionByURI("/" + sectionKey);
        String className = (section == null) ? sectionKey : section.getCeilingEntity();
        if (className == null) {
            throw new RuntimeException("Could not determine the class related to the following Section: " + section.getName());
        }
        SessionFactory sessionFactory = getEntityManager(className).unwrap(Session.class).getSessionFactory();
        Class<?>[] entities = dynamicDaoHelper.getAllPolymorphicEntitiesFromCeiling(Class.forName(className), sessionFactory, true, true);
        return entities[entities.length - 1].getName();
    } catch (ClassNotFoundException e) {
        throw ExceptionHelper.refineException(RuntimeException.class, RuntimeException.class, e);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) Session(org.hibernate.Session)

Example 2 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationDaoImpl method readAdminSectionByURI.

@Override
public AdminSection readAdminSectionByURI(String uri) {
    Query query = em.createNamedQuery("BC_READ_ADMIN_SECTION_BY_URI");
    query.setParameter("uri", uri);
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
    AdminSection adminSection = null;
    try {
        adminSection = (AdminSection) query.getSingleResult();
    } catch (NoResultException e) {
    // do nothing
    }
    return adminSection;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) NoResultException(javax.persistence.NoResultException)

Example 3 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationDaoImpl method readAdminSectionBySectionKey.

@Override
public AdminSection readAdminSectionBySectionKey(String sectionKey) {
    Query query = em.createNamedQuery("BC_READ_ADMIN_SECTION_BY_SECTION_KEY");
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
    query.setParameter("sectionKey", sectionKey);
    AdminSection adminSection = null;
    try {
        adminSection = (AdminSection) query.getSingleResult();
    } catch (NoResultException e) {
    // do nothing
    }
    return adminSection;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) NoResultException(javax.persistence.NoResultException)

Example 4 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationDaoImpl method readAllAdminSections.

@Override
public List<AdminSection> readAllAdminSections() {
    Query query = em.createNamedQuery("BC_READ_ALL_ADMIN_SECTIONS");
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
    List<AdminSection> sections = query.getResultList();
    return sections;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection)

Example 5 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationDaoImpl method readAdminSectionByClassAndSectionId.

@Override
public AdminSection readAdminSectionByClassAndSectionId(Class<?> clazz, String sectionId) {
    String className = clazz.getName();
    // Try to find a section for the exact input received
    List<AdminSection> sections = readAdminSectionForClassName(className);
    if (CollectionUtils.isEmpty(sections)) {
        // Most of the sections should match to the interface
        if (className.endsWith("Impl")) {
            className = className.substring(0, className.length() - 4);
            sections = readAdminSectionForClassName(className);
        }
    }
    if (!CollectionUtils.isEmpty(sections)) {
        AdminSection returnSection = sections.get(0);
        if (sectionId == null) {
            // if no sectionId was passed, ensure we are returning the correct section based on the request's sectionkey
            sectionId = getSectionKey(true);
        }
        if (sectionId != null) {
            if (!sectionId.startsWith("/")) {
                sectionId = "/" + sectionId;
            }
            for (AdminSection section : sections) {
                if (sectionId.equals(section.getUrl())) {
                    returnSection = section;
                    break;
                }
            }
        }
        return returnSection;
    }
    return null;
}
Also used : AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection)

Aggregations

AdminSection (org.broadleafcommerce.openadmin.server.security.domain.AdminSection)17 HashMap (java.util.HashMap)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 NoResultException (javax.persistence.NoResultException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 AdminModule (org.broadleafcommerce.openadmin.server.security.domain.AdminModule)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 IOException (java.io.IOException)1 DateFormatSymbols (java.text.DateFormatSymbols)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1