use of org.olat.portfolio.model.structel.ElementType in project OpenOLAT by OpenOLAT.
the class EPStructureManager method getStructureElementsForUser.
protected List<PortfolioStructure> getStructureElementsForUser(IdentityRef ident, ElementType... types) {
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" as stEl").append(" inner join stEl.groups as relGroup on relGroup.defaultGroup=true").append(" inner join relGroup.group as baseGroup").append(" where exists (select membership from bgroupmember as membership ").append(" where baseGroup=membership.group and membership.identity.key=:identityKey and membership.role='").append(GroupRoles.owner.name()).append("'").append(" )");
if (types != null && types.length > 0) {
sb.append(" and type(stEl) in (");
boolean first = true;
for (ElementType type : types) {
if (first)
first = false;
else
sb.append(",");
sb.append(getImplementation(type).getName());
}
sb.append(")");
}
return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), PortfolioStructure.class).setParameter("identityKey", ident.getKey()).getResultList();
}
use of org.olat.portfolio.model.structel.ElementType in project OpenOLAT by OpenOLAT.
the class EPStructureManager method buildStructureElementsFromOthersLimitedQuery.
/**
* @param select
* @param choosenOwner
* @param limitFrom
* @param limitTo
* @param types
* @return
*/
private <U> TypedQuery<U> buildStructureElementsFromOthersLimitedQuery(Identity choosenOwner, Class<U> cl, ElementType... types) {
StringBuilder sb = new StringBuilder();
if (cl.equals(Number.class)) {
sb.append("select count(stEl) from ").append(EPStructureElement.class.getName()).append(" stEl ").append(" inner join stEl.olatResource as oRes ");
} else {
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl ").append(" inner join fetch stEl.olatResource as oRes ");
}
sb.append(" inner join stEl.groups as relGroup on relGroup.defaultGroup=true").append(" inner join relGroup.group as baseGroup");
sb.append(" where oRes in ( ").append(" select policy.olatResource from").append(" ").append(PolicyImpl.class.getName()).append(" as policy, ").append(" ").append(SecurityGroupImpl.class.getName()).append(" as sgi,").append(" ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmsi ").append(// implicit inner join
" where sgi = policy.securityGroup").append(// member of the security group
" and (sgmsi.securityGroup = sgi and sgmsi.identity =:ident) ").append(" and (policy.from is null or policy.from<=:date)").append(" and (policy.to is null or policy.to>=:date)").append(" )");
// remove owner
sb.append(" and not exists ( ").append("select sgi2 from bgroup as sgi2, bgroupmember as sgmsi2 ").append(" where baseGroup=sgi2 and sgmsi2.group=sgi2 and sgmsi2.identity=:ident").append(" )");
if (choosenOwner != null) {
sb.append(" and exists (select sgi.key from bgroup as sgi, bgroupmember as sgmsi ").append(" where sgmsi.group=baseGroup and sgmsi.identity=:owner").append(" )");
}
if (types != null && types.length > 0) {
sb.append(" and type(stEl) in (");
boolean first = true;
for (final ElementType type : types) {
if (first) {
first = false;
} else {
sb.append(",");
}
sb.append(getImplementation(type).getName());
}
sb.append(")");
}
return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), cl);
}
use of org.olat.portfolio.model.structel.ElementType in project openolat by klemens.
the class EPStructureManager method getStructureElementsFromOthersWithoutPublic.
protected List<PortfolioStructure> getStructureElementsFromOthersWithoutPublic(IdentityRef ident, IdentityRef choosenOwner, ElementType... types) {
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl ").append(" inner join fetch stEl.olatResource as oRes ").append(" inner join stEl.groups as relGroup on relGroup.defaultGroup=false").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as members").append(" where members.identity.key=:identityKey").append(" and (relGroup.validFrom is null or relGroup.validFrom<=:date)").append(" and (relGroup.validTo is null or relGroup.validTo>=:date)");
if (choosenOwner != null) {
sb.append(" and exists (select sgmsi from bgroupmember as sgmsi ").append(" where sgmsi.group=baseGroup and sgmsi.identity.key=:ownerKey").append(" )");
}
if (types != null && types.length > 0) {
sb.append(" and type(stEl) in (");
boolean first = true;
for (ElementType type : types) {
if (first)
first = false;
else
sb.append(",");
sb.append(getImplementation(type).getName());
}
sb.append(")");
}
TypedQuery<PortfolioStructure> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), PortfolioStructure.class).setParameter("identityKey", ident.getKey()).setParameter("date", new Date());
if (choosenOwner != null) {
query.setParameter("ownerKey", choosenOwner.getKey());
}
return query.getResultList();
}
use of org.olat.portfolio.model.structel.ElementType in project OpenOLAT by OpenOLAT.
the class EPStructureManager method getStructureElements.
protected List<PortfolioStructure> getStructureElements(int firstResult, int maxResults, ElementType... types) {
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl");
sb.append(" where type(stEl) in (");
boolean first = true;
for (ElementType type : types) {
if (first)
first = false;
else
sb.append(",");
sb.append(getImplementation(type).getName());
}
sb.append(")");
DBQuery query = dbInstance.createQuery(sb.toString());
if (firstResult > 0) {
query.setFirstResult(firstResult);
}
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
@SuppressWarnings("unchecked") List<PortfolioStructure> pStructs = query.list();
return pStructs;
}
use of org.olat.portfolio.model.structel.ElementType in project OpenOLAT by OpenOLAT.
the class EPStructureManager method getStructureElementsFromOthersWithoutPublic.
protected List<PortfolioStructure> getStructureElementsFromOthersWithoutPublic(IdentityRef ident, IdentityRef choosenOwner, ElementType... types) {
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl ").append(" inner join fetch stEl.olatResource as oRes ").append(" inner join stEl.groups as relGroup on relGroup.defaultGroup=false").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as members").append(" where members.identity.key=:identityKey").append(" and (relGroup.validFrom is null or relGroup.validFrom<=:date)").append(" and (relGroup.validTo is null or relGroup.validTo>=:date)");
if (choosenOwner != null) {
sb.append(" and exists (select sgmsi from bgroupmember as sgmsi ").append(" where sgmsi.group=baseGroup and sgmsi.identity.key=:ownerKey").append(" )");
}
if (types != null && types.length > 0) {
sb.append(" and type(stEl) in (");
boolean first = true;
for (ElementType type : types) {
if (first)
first = false;
else
sb.append(",");
sb.append(getImplementation(type).getName());
}
sb.append(")");
}
TypedQuery<PortfolioStructure> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), PortfolioStructure.class).setParameter("identityKey", ident.getKey()).setParameter("date", new Date());
if (choosenOwner != null) {
query.setParameter("ownerKey", choosenOwner.getKey());
}
return query.getResultList();
}
Aggregations