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

org.nuiton.web.security.GeneratedSecurityRoleTopiaDao Maven / Gradle / Ivy

There is a newer version: 1.20
Show newest version
package org.nuiton.web.security;

/*-
 * #%L
 * Nuiton Web :: Nuiton Security
 * %%
 * Copyright (C) 2010 - 2017 CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import org.hibernate.Session;
import org.nuiton.topia.persistence.TopiaDao;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaException;
import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
import org.nuiton.topia.persistence.internal.support.HibernateTopiaJpaSupport;
import org.nuiton.topia.persistence.support.TopiaHibernateSupport;
import org.nuiton.web.AbstractSecurityTopiaDao;
import org.nuiton.web.SecurityEntityEnum;

@Generated(value = "org.nuiton.topia.templates.EntityDaoTransformer", date = "Thu Sep 07 10:56:15 CEST 2017")
public abstract class GeneratedSecurityRoleTopiaDao extends AbstractSecurityTopiaDao {

    @Override
    public Class getEntityClass() {
        return (Class) SecurityRole.class;
    }

    @Override
    public SecurityEntityEnum getTopiaEntityEnum() {
        return SecurityEntityEnum.SecurityRole;
    }

    @Override
    public void delete(E entity) {
        if ( ! entity.isPersisted()) {
            throw new IllegalArgumentException("entity " + entity  + " is not persisted, you can't delete it");
        }

        TopiaHibernateSupport hibernateSupport = ((HibernateTopiaJpaSupport) topiaJpaSupport).getHibernateSupport();
        Session hibernateSession = hibernateSupport.getHibernateSession();

        {
            String sql = "SELECT main.* " +
                    " FROM securityUser main, securityrole_securityuser secondary " +
                    " WHERE main.topiaId=secondary.securityUser " +
                    " AND secondary.securityRole='" + entity.getTopiaId() + "'";
            List list = hibernateSession
                    .createSQLQuery(sql)
                    .addEntity("main", SecurityEntityEnum.SecurityUser.getImplementation())
                    .list();

            for (SecurityUser item : list) {
                item.removeSecurityRole(entity);
            }
        }

        super.delete(entity);
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forNameIn(Collection v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forIn(SecurityRole.PROPERTY_NAME, (Collection) v);
        return result;
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forNameEquals(String v) {
        TopiaQueryBuilderAddCriteriaOrRunQueryStep result = forEquals(SecurityRole.PROPERTY_NAME, v);
        return result;
    }

    @Deprecated
    public E findByName(String v) {
        return forNameEquals(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllByName(String v) {
        return forNameEquals(v).findAll();
    }

    public TopiaQueryBuilderAddCriteriaOrRunQueryStep forPermissionsContains(String v) {
        return forContains(SecurityRole.PROPERTY_PERMISSIONS, v);
    }

    @Deprecated
    public E findContainsPermissions(String v) {
        return forPermissionsContains(v).findAnyOrNull();
    }

    @Deprecated
    public List findAllContainsPermissions(String v) {
        return forPermissionsContains(v).findAll();
    }

    @Override
    public  List findUsages(Class type, E entity) {
        List result = new LinkedList();
        List tmp;

        if (type == SecurityUser.class) {
            SecurityUserTopiaDao dao =
                topiaDaoSupplier.getDao(SecurityUser.class, SecurityUserTopiaDao.class);
            tmp = dao.forSecurityRoleContains(entity).findAll();
            result.addAll(tmp);
        }

        return (List) result;
    }

    @Override
    public Map, List> findAllUsages(E entity) {
        Map,List> result;
        result = new HashMap, List>(1);

        List list;

        list = findUsages(SecurityUser.class, entity);
        if (!list.isEmpty()) {
            result.put(SecurityUser.class, list);
        }

        return result;
    }

    @Override
    public List getAggregate(E entity) throws TopiaException {
        List tmp = new ArrayList();

        // pour tous les attributs rechecher les composites et les class d'asso
        // on les ajoute dans tmp

        // on refait un tour sur chaque entity de tmp pour recuperer leur
        // composite
        List result = new ArrayList();
        for (TopiaEntity e : tmp) {
            result.add(e);
            TopiaDao dao = (TopiaDao) topiaDaoSupplier.getDao(e.getClass());
            result.addAll(dao.getAggregate(e));
        }
        return result;
    }

    @Override
    public List getComposite(E entity) throws TopiaException {
        List tmp = new ArrayList();

        // pour tous les attributs rechecher les composites et les class d'asso
        // on les ajoute dans tmp

        // on refait un tour sur chaque entity de tmp pour recuperer leur
        // composite
        List result = new ArrayList();
        for (TopiaEntity e : tmp) {
            if (e != null) {
                result.add(e);
                TopiaDao dao = (TopiaDao) topiaDaoSupplier.getDao(e.getClass());
                result.addAll(dao.getComposite(e));
            }
        }
        return result;
    }

} //GeneratedSecurityRoleTopiaDao