From 8fbca9e6defc166c43d4672fcd324e51f43d54d1 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 4 May 2018 12:33:31 +0200 Subject: [PATCH] OO-3296: implement inheritance of specific roles in an organization structure (user manager, learn resource manager) --- .../user/SystemRolesAndRightsController.java | 6 +- .../olat/admin/user/UserCreateController.java | 4 +- .../olat/admin/user/UserSearchController.java | 8 +- .../admin/user/UserSearchFlexiController.java | 8 +- .../org/olat/basesecurity/BaseSecurity.java | 2 +- .../basesecurity/BaseSecurityManager.java | 9 +- .../olat/basesecurity/GroupMembership.java | 4 + .../GroupMembershipInheritance.java | 34 + .../org/olat/basesecurity/GroupRoles.java | 14 + .../olat/basesecurity/OrganisationRoles.java | 19 +- .../basesecurity/OrganisationService.java | 41 +- .../olat/basesecurity/manager/GroupDAO.java | 53 + .../basesecurity/manager/OrganisationDAO.java | 33 + .../manager/OrganisationServiceImpl.java | 141 +- .../model/GroupMembershipImpl.java | 28 +- .../basesecurity/model/OrganisationNode.java | 43 + .../_spring/databaseCorecontext.xml | 2 +- .../java/org/olat/core/id/Organisation.java | 3 + src/main/java/org/olat/core/id/Roles.java | 4 + .../olat/core/id/context/HistoryManager.java | 23 +- .../core/util/mail/ui/EMailCalloutCtrl.java | 13 +- .../manager/BusinessGroupServiceImpl.java | 7 +- .../modules/coach/manager/CoachingDAO.java | 6 +- .../SharedFolderWebDAVMergeSource.java | 8 +- .../portfolio/manager/EPStructureManager.java | 2 +- .../olat/repository/RepositoryManager.java | 607 +- .../olat/repository/RepositoryService.java | 6 +- .../RepositorySearchController.java | 59 +- .../manager/RepositoryEntryAuthorQueries.java | 98 +- .../manager/RepositoryEntryQueries.java | 221 + .../manager/RepositoryEntryRelationDAO.java | 97 +- .../manager/RepositoryServiceImpl.java | 21 +- ...SearchAuthorRepositoryEntryViewParams.java | 11 - .../SearchRepositoryEntryParameters.java | 24 +- .../ui/author/AuthorListController.java | 18 +- .../CreateRepositoryEntryController.java | 5 +- .../ImportRepositoryEntryController.java | 8 +- .../RepositoryEditDescriptionController.java | 9 +- .../course/CoursesInfosWebService.java | 6 +- .../org/olat/upgrade/OLATUpgrade_13_0_0.java | 3 +- .../org/olat/user/ProfileFormController.java | 6 +- .../ui/admin/UserAdminMainController.java | 11 +- .../OrganisationUserManagementController.java | 7 +- .../database/mysql/alter_12_4_x_to_13_0_0.sql | 6 + .../database/mysql/setupDatabase.sql | 6880 ++++++++--------- .../oracle/alter_12_4_x_to_13_0_0.sql | 3 + .../database/oracle/setupDatabase.sql | 1 + .../postgresql/alter_12_4_x_to_13_0_0.sql | 4 + .../database/postgresql/setupDatabase.sql | 1 + .../manager/OrganisationDAOTest.java | 9 +- .../manager/OrganisationServiceTest.java | 124 + .../core/id/context/HistoryManagerTest.java | 29 + .../olat/core/id/context/resume_ver13a.xml | 260 + .../olat/core/id/context/resume_ver13b.xml | 64 + .../nodes/gta/rule/GTAReminderRuleTest.java | 33 +- .../manager/ReminderRuleEngineTest.java | 9 +- .../manager/EPStructureManagerTest.java | 2 +- .../RepositoryManagerQueryTest.java | 250 - .../repository/RepositoryManagerTest.java | 292 +- .../manager/RepositoryEntryQueriesTest.java | 469 ++ .../RepositoryEntryRelationDAOTest.java | 2 +- .../manager/RepositoryServiceImplTest.java | 2 +- .../java/org/olat/test/AllTestsJunit4.java | 2 +- 63 files changed, 5403 insertions(+), 4771 deletions(-) create mode 100644 src/main/java/org/olat/basesecurity/GroupMembershipInheritance.java create mode 100644 src/main/java/org/olat/basesecurity/model/OrganisationNode.java create mode 100644 src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java create mode 100644 src/test/java/org/olat/core/id/context/resume_ver13a.xml create mode 100644 src/test/java/org/olat/core/id/context/resume_ver13b.xml delete mode 100644 src/test/java/org/olat/repository/RepositoryManagerQueryTest.java create mode 100644 src/test/java/org/olat/repository/manager/RepositoryEntryQueriesTest.java diff --git a/src/main/java/org/olat/admin/user/SystemRolesAndRightsController.java b/src/main/java/org/olat/admin/user/SystemRolesAndRightsController.java index 792c4d031b9..b806bcc6cad 100644 --- a/src/main/java/org/olat/admin/user/SystemRolesAndRightsController.java +++ b/src/main/java/org/olat/admin/user/SystemRolesAndRightsController.java @@ -31,6 +31,7 @@ import java.util.List; import org.olat.admin.user.bulkChange.UserBulkChangeManager; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityModule; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; import org.olat.core.commons.persistence.DB; @@ -118,7 +119,8 @@ public class SystemRolesAndRightsController extends FormBasicController { organisations = organisationService.getOrganisations(editedIdentity, OrganisationRoles.values()); managerRoles = ureq.getUserSession().getRoles(); - manageableOrganisations = organisationService.getManageableOrganisations(getIdentity(), managerRoles, OrganisationRoles.usermanager); + manageableOrganisations = organisationService.getOrganisations(getIdentity(), managerRoles, + OrganisationRoles.administrator, OrganisationRoles.usermanager); initStatusKeysAndValues(); initForm(ureq); @@ -397,7 +399,7 @@ public class SystemRolesAndRightsController extends FormBasicController { private void doAddIdentityToOrganisation(Organisation organisation) { - organisationService.addMember(organisation, editedIdentity, OrganisationRoles.user); + organisationService.addMember(organisation, editedIdentity, OrganisationRoles.user, GroupMembershipInheritance.none); dbInstance.commit(); organisations = organisationService.getOrganisations(editedIdentity, OrganisationRoles.values()); diff --git a/src/main/java/org/olat/admin/user/UserCreateController.java b/src/main/java/org/olat/admin/user/UserCreateController.java index a8a29fd8b12..86ada37f253 100644 --- a/src/main/java/org/olat/admin/user/UserCreateController.java +++ b/src/main/java/org/olat/admin/user/UserCreateController.java @@ -175,8 +175,8 @@ class NewUserForm extends FormBasicController { super(ureq, wControl); setTranslator(translator); this.showPasswordFields = showPasswordFields; - manageableOrganisations = organisationService - .getManageableOrganisations(getIdentity(), ureq.getUserSession().getRoles(), OrganisationRoles.usermanager); + manageableOrganisations = organisationService.getOrganisations(getIdentity(), ureq.getUserSession().getRoles(), + OrganisationRoles.administrator, OrganisationRoles.usermanager); initForm(ureq); } diff --git a/src/main/java/org/olat/admin/user/UserSearchController.java b/src/main/java/org/olat/admin/user/UserSearchController.java index 32a80abb841..d0a8f1c2ec4 100644 --- a/src/main/java/org/olat/admin/user/UserSearchController.java +++ b/src/main/java/org/olat/admin/user/UserSearchController.java @@ -182,12 +182,8 @@ public class UserSearchController extends BasicController { myContent.put("usersearchPanel", searchPanel); UserSession usess = ureq.getUserSession(); - if(usess.getRoles().isOLATAdmin()) { - searchableOrganisations = null;//null mean all - } else { - searchableOrganisations = organisationService - .getSearchableOrganisations(getIdentity(), usess.getRoles(), OrganisationRoles.usermanager); - } + searchableOrganisations = organisationService.getOrganisations(getIdentity(), usess.getRoles(), + OrganisationRoles.valuesWithoutGuestAndInvitee()); Roles roles = usess.getRoles(); isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles); diff --git a/src/main/java/org/olat/admin/user/UserSearchFlexiController.java b/src/main/java/org/olat/admin/user/UserSearchFlexiController.java index 11061ff5d19..f868aec1e6b 100644 --- a/src/main/java/org/olat/admin/user/UserSearchFlexiController.java +++ b/src/main/java/org/olat/admin/user/UserSearchFlexiController.java @@ -137,12 +137,8 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { userSearchFormPropertyHandlers = userManager.getUserPropertyHandlersFor(UserSearchForm.class.getCanonicalName(), isAdministrativeUser); UserSession usess = ureq.getUserSession(); - if(usess.getRoles().isOLATAdmin()) { - searchableOrganisations = null;//null mean all - } else { - searchableOrganisations = organisationService - .getSearchableOrganisations(getIdentity(), usess.getRoles(), OrganisationRoles.usermanager); - } + searchableOrganisations = organisationService.getOrganisations(getIdentity(), usess.getRoles(), + OrganisationRoles.valuesWithoutGuestAndInvitee()); ListProvider provider = new UserSearchListProvider(searchableOrganisations); setListProvider(provider); diff --git a/src/main/java/org/olat/basesecurity/BaseSecurity.java b/src/main/java/org/olat/basesecurity/BaseSecurity.java index 060090f2238..dbcdb22b427 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurity.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurity.java @@ -55,7 +55,7 @@ public interface BaseSecurity { public Roles getRoles(IdentityRef identity); /** - * Get the list of roles as string without inheritence (an admin + * Get the list of roles as string without inheritance (an admin * has only admin role and not the user manager role...). * @param identity * @return diff --git a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java index 486a9541917..615d02aa74b 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java @@ -143,7 +143,7 @@ public class BaseSecurityManager implements BaseSecurity { boolean isInvitee = false; StringBuilder sb = new StringBuilder(); - sb.append("select org.key, membership.role from organisation as org ") + sb.append("select org.key, org.identifier, membership.role from organisation as org ") .append(" inner join org.group baseGroup") .append(" inner join baseGroup.members membership") .append(" where membership.identity.key=:identityKey"); @@ -168,7 +168,8 @@ public class BaseSecurityManager implements BaseSecurity { for(Object[] rawObject:rawObjects) { Long organisationKey = (Long)rawObject[0]; - String role = (String)rawObject[1]; + String organisationId = (String)rawObject[1]; + String role = (String)rawObject[2]; List<OrganisationRoles> roleList = orgToRoles .computeIfAbsent(new OrganisationRefImpl(organisationKey), key -> new ArrayList<>()); @@ -347,7 +348,7 @@ public class BaseSecurityManager implements BaseSecurity { private void updateRolesInSecurityGroup(Organisation organisation, Identity actingIdentity, Identity updatedIdentity, OrganisationRoles role, boolean hasBeen, boolean isNow) { if (!hasBeen && isNow) { // user not yet in security group, add him - organisationService.addMember(organisation, updatedIdentity, role); + organisationService.addMember(organisation, updatedIdentity, role, GroupMembershipInheritance.none); log.audit("User::" + (actingIdentity == null ? "unkown" : actingIdentity.getName()) + " added system role::" + role.name() + " to user::" + updatedIdentity.getName(), null); } else if (hasBeen && !isNow) { // user not anymore in security group, remove him @@ -445,7 +446,7 @@ public class BaseSecurityManager implements BaseSecurity { if(organisation == null) { organisationService.addMember(ident, OrganisationRoles.user); } else { - organisationService.addMember(organisation, ident, OrganisationRoles.user); + organisationService.addMember(organisation, ident, OrganisationRoles.user, GroupMembershipInheritance.none); } return ident; } diff --git a/src/main/java/org/olat/basesecurity/GroupMembership.java b/src/main/java/org/olat/basesecurity/GroupMembership.java index 13bc3dca43c..cb985045e2d 100644 --- a/src/main/java/org/olat/basesecurity/GroupMembership.java +++ b/src/main/java/org/olat/basesecurity/GroupMembership.java @@ -36,5 +36,9 @@ public interface GroupMembership { public String getRole(); public Identity getIdentity(); + + public GroupMembershipInheritance getInheritanceMode(); + + public void setInheritanceMode(GroupMembershipInheritance inheritanceMode); } diff --git a/src/main/java/org/olat/basesecurity/GroupMembershipInheritance.java b/src/main/java/org/olat/basesecurity/GroupMembershipInheritance.java new file mode 100644 index 00000000000..c00cfa8e065 --- /dev/null +++ b/src/main/java/org/olat/basesecurity/GroupMembershipInheritance.java @@ -0,0 +1,34 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.basesecurity; + +/** + * + * Initial date: 3 mai 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public enum GroupMembershipInheritance { + + none, + root,// + inherited + +} diff --git a/src/main/java/org/olat/basesecurity/GroupRoles.java b/src/main/java/org/olat/basesecurity/GroupRoles.java index 0ad5ce8836b..2e7a32e6ce5 100644 --- a/src/main/java/org/olat/basesecurity/GroupRoles.java +++ b/src/main/java/org/olat/basesecurity/GroupRoles.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.olat.core.util.StringHelper; + /** * * Initial date: 26.02.2014<br> @@ -48,4 +50,16 @@ public enum GroupRoles { } return Collections.emptyList(); } + + public static boolean isValue(String value) { + boolean isValue = false; + if(StringHelper.containsNonWhitespace(value)) { + for(GroupRoles role:GroupRoles.values()) { + if(role.name().equals(value)) { + isValue = true; + } + } + } + return isValue; + } } diff --git a/src/main/java/org/olat/basesecurity/OrganisationRoles.java b/src/main/java/org/olat/basesecurity/OrganisationRoles.java index 5a0ea7c3983..cd893cf75cd 100644 --- a/src/main/java/org/olat/basesecurity/OrganisationRoles.java +++ b/src/main/java/org/olat/basesecurity/OrganisationRoles.java @@ -42,15 +42,24 @@ public enum OrganisationRoles { invitee, guest; + public static boolean isValue(String value) { + boolean isValue = false; + if(StringHelper.containsNonWhitespace(value)) { + for(OrganisationRoles role:OrganisationRoles.values()) { + if(role.name().equals(value)) { + isValue = true; + } + } + } + return isValue; + } + public static boolean valid(String value) { if(!StringHelper.containsNonWhitespace(value)) { return false; } - try { - return OrganisationRoles.valueOf(value) != null; - } catch (Exception e) { - return false; - } + + return OrganisationRoles.isValue(value); } public static OrganisationRoles[] valuesWithoutGuestAndInvitee() { diff --git a/src/main/java/org/olat/basesecurity/OrganisationService.java b/src/main/java/org/olat/basesecurity/OrganisationService.java index bf70729e79f..95b36428202 100644 --- a/src/main/java/org/olat/basesecurity/OrganisationService.java +++ b/src/main/java/org/olat/basesecurity/OrganisationService.java @@ -37,20 +37,25 @@ public interface OrganisationService { public static final String DEFAULT_ORGANISATION_IDENTIFIER = "default-org"; + /** - * Create and persist a brand new organisation. + * Create a brand new organization. The membership inheritance + * will be automatically calculated and propagated. * - * @param displayName The display name + * @param displayName The name of the organization * @param identifier The identifier - * @return The persisted organisation + * @param description The description + * @param parentOrganisation The Parent organization if any + * @param type The type + * @return The persisted organization */ public Organisation createOrganisation(String displayName, String identifier, String description, Organisation parentOrganisation, OrganisationType type); /** * - * @param organisation A reference of the organisation - * @return A reloaded organisation + * @param organisation A reference of the organization + * @return A reloaded organization */ public Organisation getOrganisation(OrganisationRef organisation); @@ -71,13 +76,11 @@ public interface OrganisationService { * @param roles * @return */ - public List<Organisation> getSearchableOrganisations(IdentityRef member, Roles roles, OrganisationRoles additionalManagerRole); + //public List<Organisation> getSearchableOrganisations(IdentityRef member, Roles roles, OrganisationRoles additionalManagerRole); /** - * Return the organization the specified user - * is allow to manage. The method calculate with - * administrator and the specified additional role - * (user manager or learn resource manager) + * Return the organization the specified user is allow to see. + * An OpenOLAT admin. can see all organizations. * * * @param member The user @@ -85,21 +88,31 @@ public interface OrganisationService { * @param managerRole The additional manager * @return A list of organizations a user can manage */ - public List<Organisation> getManageableOrganisations(IdentityRef member, Roles roles, OrganisationRoles managerRole); + public List<Organisation> getOrganisations(IdentityRef member, Roles roles, OrganisationRoles... managerRole); public Organisation getDefaultOrganisation(); - public void addMember(Organisation organisation, Identity member, OrganisationRoles role); /** - * + * Add a membership without inheritance on the default organization. * * @param member The identity - * @param role The role in the organisation + * @param role The role in the organization */ public void addMember(Identity member, OrganisationRoles role); + /** + * Add a membership on the specified organization. The inheritance mode "root" + * will automatically be propagated to child-organizations as "inherithed". + * + * @param organisation The organization + * @param member The new member of the organization + * @param role The role in the organization + * @param inheritanceMode The inheritance mode (none, root) + */ + public void addMember(Organisation organisation, Identity member, OrganisationRoles role, GroupMembershipInheritance inheritanceMode); + public void removeMember(IdentityRef member, OrganisationRoles role); public void removeMember(Organisation organisation, IdentityRef member); diff --git a/src/main/java/org/olat/basesecurity/manager/GroupDAO.java b/src/main/java/org/olat/basesecurity/manager/GroupDAO.java index 3afe4493fda..9af367f4cb1 100644 --- a/src/main/java/org/olat/basesecurity/manager/GroupDAO.java +++ b/src/main/java/org/olat/basesecurity/manager/GroupDAO.java @@ -30,6 +30,7 @@ import javax.persistence.EntityManager; import org.olat.basesecurity.Grant; import org.olat.basesecurity.Group; import org.olat.basesecurity.GroupMembership; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.IdentityRef; import org.olat.basesecurity.model.GrantImpl; import org.olat.basesecurity.model.GroupImpl; @@ -84,12 +85,17 @@ public class GroupDAO { * reloaded. */ public GroupMembership addMembershipTwoWay(Group group, Identity identity, String role) { + return addMembershipTwoWay(group, identity, role, GroupMembershipInheritance.none); + } + + public GroupMembership addMembershipTwoWay(Group group, Identity identity, String role, GroupMembershipInheritance inheritanceMode) { GroupMembershipImpl membership = new GroupMembershipImpl(); membership.setCreationDate(new Date()); membership.setLastModified(new Date()); membership.setGroup(group); membership.setIdentity(identity); membership.setRole(role); + membership.setInheritanceMode(inheritanceMode); dbInstance.getCurrentEntityManager().persist(membership); Set<GroupMembership> members = ((GroupImpl)group).getMembers(); @@ -105,15 +111,33 @@ public class GroupDAO { * Create a membership without updating the set in the group. */ public void addMembershipOneWay(Group group, Identity identity, String role) { + addMembershipOneWay(group, identity, role, GroupMembershipInheritance.none); + } + + /** + * Create a membership without updating the set in the group. + * + * @param group + * @param identity + * @param role + * @param inheritanceMode + */ + public void addMembershipOneWay(Group group, Identity identity, String role, GroupMembershipInheritance inheritanceMode) { GroupMembershipImpl membership = new GroupMembershipImpl(); membership.setCreationDate(new Date()); membership.setLastModified(new Date()); membership.setGroup(group); membership.setIdentity(identity); membership.setRole(role); + membership.setInheritanceMode(inheritanceMode); dbInstance.getCurrentEntityManager().persist(membership); } + public GroupMembership updateInheritanceMode(GroupMembership membership, GroupMembershipInheritance inheritanceMode) { + ((GroupMembershipImpl)membership).setInheritanceMode(inheritanceMode); + return dbInstance.getCurrentEntityManager().merge(membership); + } + public int removeMemberships(Group group) { EntityManager em = dbInstance.getCurrentEntityManager(); List<GroupMembership> memberships = em.createNamedQuery("membershipsByGroup", GroupMembership.class) @@ -165,6 +189,10 @@ public class GroupDAO { .executeUpdate(); } + public void removeMembership(GroupMembership membership) { + dbInstance.getCurrentEntityManager().remove(membership); + } + public int countMembers(Group group) { Number count = dbInstance.getCurrentEntityManager() .createNamedQuery("countMembersByGroup", Number.class) @@ -191,6 +219,13 @@ public class GroupDAO { .getResultList(); } + public List<GroupMembership> getMemberships(Group group) { + return dbInstance.getCurrentEntityManager() + .createNamedQuery("membershipsByGroup", GroupMembership.class) + .setParameter("groupKey", group.getKey()) + .getResultList(); + } + public List<GroupMembership> getMemberships(Group group, String role) { return dbInstance.getCurrentEntityManager() .createNamedQuery("membershipsByGroupAndRole", GroupMembership.class) @@ -199,6 +234,24 @@ public class GroupDAO { .getResultList(); } + public List<GroupMembership> getMemberships(Group group, IdentityRef identity) { + return dbInstance.getCurrentEntityManager() + .createNamedQuery("membershipsByGroupAndIdentity", GroupMembership.class) + .setParameter("groupKey", group.getKey()) + .setParameter("identityKey", identity.getKey()) + .getResultList(); + } + + public GroupMembership getMembership(Group group, IdentityRef identity, String role) { + List<GroupMembership> memberships = dbInstance.getCurrentEntityManager() + .createNamedQuery("membershipByGroupIdentityAndRole", GroupMembership.class) + .setParameter("groupKey", group.getKey()) + .setParameter("identityKey", identity.getKey()) + .setParameter("role", role) + .getResultList(); + return memberships == null || memberships.isEmpty() ? null : memberships.get(0); + } + public boolean hasGrant(IdentityRef identity, String permission, OLATResource resource) { StringBuilder sb = new StringBuilder(); sb.append("select count(grant) from bgrant as grant") diff --git a/src/main/java/org/olat/basesecurity/manager/OrganisationDAO.java b/src/main/java/org/olat/basesecurity/manager/OrganisationDAO.java index 2e8a15990ad..b1f113bcc70 100644 --- a/src/main/java/org/olat/basesecurity/manager/OrganisationDAO.java +++ b/src/main/java/org/olat/basesecurity/manager/OrganisationDAO.java @@ -23,7 +23,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.persistence.TypedQuery; @@ -33,6 +35,7 @@ import org.olat.basesecurity.OrganisationService; import org.olat.basesecurity.OrganisationType; import org.olat.basesecurity.model.OrganisationImpl; import org.olat.basesecurity.model.OrganisationMember; +import org.olat.basesecurity.model.OrganisationNode; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; import org.olat.core.id.Organisation; @@ -253,6 +256,36 @@ public class OrganisationDAO { .getResultList(); } + public OrganisationNode getDescendantTree(Organisation rootOrganisation) { + OrganisationNode rootNode = new OrganisationNode(rootOrganisation); + + List<Organisation> descendants = getDescendants(rootOrganisation); + Map<Long,OrganisationNode> keyToOrganisations = new HashMap<>(); + for(Organisation descendant:descendants) { + keyToOrganisations.put(descendant.getKey(), new OrganisationNode(descendant)); + } + + for(Organisation descendant:descendants) { + Long key = descendant.getKey(); + if(key.equals(rootOrganisation.getKey())) { + continue; + } + + OrganisationNode node = keyToOrganisations.get(key); + Organisation parentOrganisation = descendant.getParent(); + Long parentKey = parentOrganisation.getKey(); + if(parentKey.equals(rootOrganisation.getKey())) { + //this is a root, or the user has not access to parent + rootNode.addChildrenNode(node); + } else { + OrganisationNode parentNode = keyToOrganisations.get(parentKey); + parentNode.addChildrenNode(node); + } + } + + return rootNode; + } + public boolean hasAnyRole(IdentityRef identity, String excludeRole) { StringBuilder sb = new StringBuilder(256); diff --git a/src/main/java/org/olat/basesecurity/manager/OrganisationServiceImpl.java b/src/main/java/org/olat/basesecurity/manager/OrganisationServiceImpl.java index df8315ee27c..9e494a6f51e 100644 --- a/src/main/java/org/olat/basesecurity/manager/OrganisationServiceImpl.java +++ b/src/main/java/org/olat/basesecurity/manager/OrganisationServiceImpl.java @@ -20,10 +20,14 @@ package org.olat.basesecurity.manager; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.olat.basesecurity.Group; +import org.olat.basesecurity.GroupMembership; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.IdentityRef; import org.olat.basesecurity.OrganisationManagedFlag; import org.olat.basesecurity.OrganisationRoles; @@ -31,11 +35,13 @@ import org.olat.basesecurity.OrganisationService; import org.olat.basesecurity.OrganisationType; import org.olat.basesecurity.model.OrganisationImpl; import org.olat.basesecurity.model.OrganisationMember; +import org.olat.basesecurity.model.OrganisationNode; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; import org.olat.core.id.Organisation; import org.olat.core.id.OrganisationRef; import org.olat.core.id.Roles; +import org.olat.core.logging.AssertException; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.springframework.beans.factory.InitializingBean; @@ -75,8 +81,19 @@ public class OrganisationServiceImpl implements OrganisationService, Initializin } @Override - public Organisation createOrganisation(String displayName, String identifier, String description, Organisation organisation, OrganisationType type) { - return organisationDao.createAndPersistOrganisation(displayName, identifier, description, organisation, type); + public Organisation createOrganisation(String displayName, String identifier, String description, Organisation parentOrganisation, OrganisationType type) { + Organisation organisation = organisationDao.createAndPersistOrganisation(displayName, identifier, description, parentOrganisation, type); + if(parentOrganisation != null) { + Group organisationGroup = organisation.getGroup(); + List<GroupMembership> memberships = groupDao.getMemberships(parentOrganisation.getGroup()); + for(GroupMembership membership:memberships) { + if(membership.getInheritanceMode() == GroupMembershipInheritance.inherited + || membership.getInheritanceMode() == GroupMembershipInheritance.root) { + groupDao.addMembershipOneWay(organisationGroup, membership.getIdentity(), membership.getRole(), GroupMembershipInheritance.inherited); + } + } + } + return organisation; } @Override @@ -118,46 +135,22 @@ public class OrganisationServiceImpl implements OrganisationService, Initializin } @Override - public List<Organisation> getSearchableOrganisations(IdentityRef member, Roles roles, OrganisationRoles additionalManagerRole) { - List<String> roleList = new ArrayList<>();// if user manager, descent organization tree - for(OrganisationRoles r:OrganisationRoles.values()) { - if(r != OrganisationRoles.guest) { - roleList.add(r.name()); - } + public List<Organisation> getOrganisations(IdentityRef member, Roles roles, OrganisationRoles... organisationRoles) { + if(organisationRoles == null || organisationRoles.length == 0 || organisationRoles[0] == null) { + return Collections.emptyList(); } - List<Organisation> organisations = organisationDao.getOrganisations(member, roleList); - Set<Organisation> organisationWithDescendants = new HashSet<>(); - for(Organisation organisation:organisations) { - organisationWithDescendants.add(organisation); - if(roles.hasRole(organisation, additionalManagerRole) - || roles.hasRole(organisation, OrganisationRoles.administrator)) { - List<Organisation> descendants = organisationDao.getDescendants(organisation); - organisationWithDescendants.addAll(descendants); - } + if(roles.isOLATAdmin()) { + return organisationDao.find(); } - - return new ArrayList<>(organisationWithDescendants); - } - - @Override - public List<Organisation> getManageableOrganisations(IdentityRef member, Roles roles, OrganisationRoles additionalManagerRole) { - Set<OrganisationRef> manageableRootOrganisations = new HashSet<>(); - manageableRootOrganisations.addAll(roles.getOrganisationsWithRoles(OrganisationRoles.administrator)); - manageableRootOrganisations.addAll(roles.getOrganisationsWithRoles(additionalManagerRole)); - - List<Organisation> organisations = organisationDao.getOrganisations(manageableRootOrganisations); - Set<Organisation> organisationWithDescendants = new HashSet<>(); - for(Organisation organisation:organisations) { - organisationWithDescendants.add(organisation); - if(roles.hasRole(organisation, additionalManagerRole) - || roles.hasRole(organisation, OrganisationRoles.administrator)) { - List<Organisation> descendants = organisationDao.getDescendants(organisation); - organisationWithDescendants.addAll(descendants); + + Set<OrganisationRef> organisations = new HashSet<>(); + for(OrganisationRoles organisationRole:organisationRoles) { + if(organisationRole != null) { + organisations.addAll(roles.getOrganisationsWithRoles(organisationRole)); } } - - return new ArrayList<>(organisationWithDescendants); + return organisationDao.getOrganisations(organisations); } @Override @@ -170,14 +163,14 @@ public class OrganisationServiceImpl implements OrganisationService, Initializin OrganisationImpl defOrganisation = (OrganisationImpl)getDefaultOrganisation(); if(!groupDao.hasRole(defOrganisation.getGroup(), identity, OrganisationRoles.guest.name())) { groupDao.removeMemberships(identity); - addMember(defOrganisation, identity, OrganisationRoles.guest); + addMember(defOrganisation, identity, OrganisationRoles.guest, GroupMembershipInheritance.none); } } @Override public void addMember(Identity member, OrganisationRoles role) { Organisation defOrganisation = getDefaultOrganisation(); - addMember(defOrganisation, member, role); + addMember(defOrganisation, member, role, GroupMembershipInheritance.none); } @Override @@ -187,23 +180,79 @@ public class OrganisationServiceImpl implements OrganisationService, Initializin } @Override - public void addMember(Organisation organisation, Identity member, OrganisationRoles role) { + public void addMember(Organisation organisation, Identity member, OrganisationRoles role, GroupMembershipInheritance inheritanceMode) { + if(inheritanceMode == GroupMembershipInheritance.inherited) { + throw new AssertException("Inherited are automatic"); + } + OrganisationImpl org = (OrganisationImpl)organisation; - if(!groupDao.hasRole(org.getGroup(), member, role.name())) { - groupDao.addMembershipOneWay(org.getGroup(), member, role.name()); + GroupMembership membership = groupDao.getMembership(org.getGroup(), member, role.name()); + if(membership == null) { + groupDao.addMembershipOneWay(org.getGroup(), member, role.name(), inheritanceMode); + } else if(membership.getInheritanceMode() != inheritanceMode) { + groupDao.updateInheritanceMode(membership, inheritanceMode); + } + + if(inheritanceMode == GroupMembershipInheritance.root) { + List<Organisation> descendants = organisationDao.getDescendants(organisation); + for(Organisation descendant:descendants) { + OrganisationImpl orgDescendant = (OrganisationImpl)descendant; + GroupMembership inheritedMembership = groupDao.getMembership(orgDescendant.getGroup(), member, role.name()); + if(inheritedMembership == null) { + groupDao.addMembershipOneWay(orgDescendant.getGroup(), member, role.name(), GroupMembershipInheritance.inherited); + } else if(inheritedMembership.getInheritanceMode() == GroupMembershipInheritance.none) { + groupDao.updateInheritanceMode(inheritedMembership, GroupMembershipInheritance.inherited); + } + } } } @Override public void removeMember(Organisation organisation, IdentityRef member) { - OrganisationImpl org = (OrganisationImpl)organisation; - groupDao.removeMembership(org.getGroup(), member); + List<GroupMembership> memberships = groupDao.getMemberships(organisation.getGroup(), member); + + OrganisationNode organisationTree = null; + + for(GroupMembership membership:memberships) { + if(membership.getInheritanceMode() == GroupMembershipInheritance.none) { + groupDao.removeMembership(membership); + } else if(membership.getInheritanceMode() == GroupMembershipInheritance.root) { + String role = membership.getRole(); + groupDao.removeMembership(membership); + + if(organisationTree == null) { + organisationTree = organisationDao.getDescendantTree(organisation); + } + for(OrganisationNode child:organisationTree.getChildrenNode()) { + removeInherithedMembership(child, member, role); + } + } + } } + + /** + * The method will recursively delete the inherithed membership. If it + * found a mebership marked as "root" or "none". It will stop. + * + * @param organisationNode The organization node + * @param member The user to remove + * @param role The role + */ + private void removeInherithedMembership(OrganisationNode organisationNode, IdentityRef member, String role) { + GroupMembership membership = groupDao + .getMembership(organisationNode.getOrganisation().getGroup(), member, role); + if(membership != null && membership.getInheritanceMode() == GroupMembershipInheritance.inherited) { + groupDao.removeMembership(membership); + for(OrganisationNode child:organisationNode.getChildrenNode()) { + removeInherithedMembership(child, member, role); + } + } + } + @Override public void removeMember(Organisation organisation, IdentityRef member, OrganisationRoles role) { - OrganisationImpl org = (OrganisationImpl)organisation; - groupDao.removeMembership(org.getGroup(), member, role.name()); + groupDao.removeMembership(organisation.getGroup(), member, role.name()); } @Override diff --git a/src/main/java/org/olat/basesecurity/model/GroupMembershipImpl.java b/src/main/java/org/olat/basesecurity/model/GroupMembershipImpl.java index c9a0de90f03..394c967f7f6 100644 --- a/src/main/java/org/olat/basesecurity/model/GroupMembershipImpl.java +++ b/src/main/java/org/olat/basesecurity/model/GroupMembershipImpl.java @@ -39,10 +39,12 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import org.olat.basesecurity.Group; import org.olat.basesecurity.GroupMembership; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.IdentityImpl; import org.olat.core.id.Identity; import org.olat.core.id.ModifiedInfo; import org.olat.core.id.Persistable; +import org.olat.core.util.StringHelper; /** * @@ -55,6 +57,7 @@ import org.olat.core.id.Persistable; @NamedQueries({ @NamedQuery(name="membershipsByGroup", query="select membership from bgroupmember as membership where membership.group.key=:groupKey"), @NamedQuery(name="membershipsByGroupAndRole", query="select membership from bgroupmember as membership where membership.group.key=:groupKey and membership.role=:role"), + @NamedQuery(name="membershipByGroupIdentityAndRole", query="select membership from bgroupmember as membership where membership.group.key=:groupKey and membership.identity.key=:identityKey and membership.role=:role"), @NamedQuery(name="deleteMembershipsByGroupAndRole", query="delete from bgroupmember as membership where membership.group.key=:groupKey and membership.role=:role"), @NamedQuery(name="membershipsByGroupAndIdentity", query="select membership from bgroupmember as membership where membership.group.key=:groupKey and membership.identity.key=:identityKey"), @NamedQuery(name="membershipsByGroupIdentityAndRole", query="select membership from bgroupmember as membership where membership.group.key=:groupKey and membership.identity.key=:identityKey and membership.role=:role"), @@ -91,6 +94,9 @@ public class GroupMembershipImpl implements GroupMembership, ModifiedInfo, Persi @Column(name="g_role", nullable=false, insertable=true, updatable=false) private String role; + @Column(name="g_inheritance_mode", nullable=false, insertable=true, updatable=false) + private String inheritanceModeString; + @ManyToOne(targetEntity=GroupImpl.class,fetch=FetchType.LAZY,optional=false) @JoinColumn(name="fk_group_id", nullable=false, insertable=true, updatable=false) private Group group; @@ -126,6 +132,7 @@ public class GroupMembershipImpl implements GroupMembership, ModifiedInfo, Persi this.lastModified = lastModified; } + @Override public String getRole() { return role; } @@ -134,6 +141,24 @@ public class GroupMembershipImpl implements GroupMembership, ModifiedInfo, Persi this.role = role; } + public String getInheritanceModeString() { + return inheritanceModeString; + } + + public void setInheritanceModeString(String inheritanceModeString) { + this.inheritanceModeString = inheritanceModeString; + } + + @Override + public GroupMembershipInheritance getInheritanceMode() { + return StringHelper.containsNonWhitespace(inheritanceModeString) + ? GroupMembershipInheritance.valueOf(inheritanceModeString) : GroupMembershipInheritance.none; + } + + public void setInheritanceMode(GroupMembershipInheritance mode) { + inheritanceModeString = mode == null ? GroupMembershipInheritance.none.name() : mode.name(); + } + public Group getGroup() { return group; } @@ -141,7 +166,8 @@ public class GroupMembershipImpl implements GroupMembership, ModifiedInfo, Persi public void setGroup(Group group) { this.group = group; } - + + @Override public Identity getIdentity() { return identity; } diff --git a/src/main/java/org/olat/basesecurity/model/OrganisationNode.java b/src/main/java/org/olat/basesecurity/model/OrganisationNode.java new file mode 100644 index 00000000000..2ea91a91cb8 --- /dev/null +++ b/src/main/java/org/olat/basesecurity/model/OrganisationNode.java @@ -0,0 +1,43 @@ +package org.olat.basesecurity.model; + +import java.util.ArrayList; +import java.util.List; + +import org.olat.core.id.Organisation; + +/** + * + * Initial date: 3 mai 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class OrganisationNode { + + private final Organisation organisation; + private OrganisationNode parentNode; + private final List<OrganisationNode> childrenNodes = new ArrayList<>(); + + public OrganisationNode(Organisation organisation) { + this.organisation = organisation; + } + + public Organisation getOrganisation() { + return organisation; + } + + public OrganisationNode getParentNode() { + return parentNode; + } + + public void setParentNode(OrganisationNode parentNode) { + this.parentNode = parentNode; + } + + public List<OrganisationNode> getChildrenNode() { + return childrenNodes; + } + + public void addChildrenNode(OrganisationNode childrenNode) { + childrenNodes.add(childrenNode); + } +} diff --git a/src/main/java/org/olat/core/commons/persistence/_spring/databaseCorecontext.xml b/src/main/java/org/olat/core/commons/persistence/_spring/databaseCorecontext.xml index 5a211cd82fc..56a25e8a490 100644 --- a/src/main/java/org/olat/core/commons/persistence/_spring/databaseCorecontext.xml +++ b/src/main/java/org/olat/core/commons/persistence/_spring/databaseCorecontext.xml @@ -170,7 +170,7 @@ <bean id="hikariHibernateProperties" class="org.olat.core.commons.persistence.DBVendorHibernatePropertiesSimplification"> <constructor-arg> <props> - <prop key="hibernate.connection.provider_class">com.zaxxer.hikari.hibernate.HikariConnectionProvider</prop> + <prop key="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</prop> <!-- Max pool size , mysql-default value is 100, If you need to support more connections, you should set a larger value for this variable in mysql config --> <prop key="hibernate.hikari.maximumPoolSize">${db.hibernate.hikari.maxsize}</prop> <prop key="hibernate.hikari.minimumIdle">4</prop> diff --git a/src/main/java/org/olat/core/id/Organisation.java b/src/main/java/org/olat/core/id/Organisation.java index 38c719ca9c6..528e5f39551 100644 --- a/src/main/java/org/olat/core/id/Organisation.java +++ b/src/main/java/org/olat/core/id/Organisation.java @@ -21,6 +21,7 @@ package org.olat.core.id; import java.util.List; +import org.olat.basesecurity.Group; import org.olat.basesecurity.OrganisationManagedFlag; /** @@ -60,5 +61,7 @@ public interface Organisation extends CreateInfo, ModifiedInfo, OrganisationRef public List<OrganisationRef> getParentLine(); public Organisation getRoot(); + + public Group getGroup(); } diff --git a/src/main/java/org/olat/core/id/Roles.java b/src/main/java/org/olat/core/id/Roles.java index d91faeb7337..2b624b6fa0f 100644 --- a/src/main/java/org/olat/core/id/Roles.java +++ b/src/main/java/org/olat/core/id/Roles.java @@ -91,6 +91,10 @@ public class Roles implements Serializable { return new Roles(false, false, false, false, false, false, false, false, false, false, false); } + public static final Roles authorRoles() { + return new Roles(false, false, false, true, false, false, false); + } + public void setRolesByOrganisation(List<RolesByOrganisation> rolesByOrganisations) { this.rolesByOrganisations = new ArrayList<>(rolesByOrganisations); } diff --git a/src/main/java/org/olat/core/id/context/HistoryManager.java b/src/main/java/org/olat/core/id/context/HistoryManager.java index 641a3438ea0..15993fb9a71 100644 --- a/src/main/java/org/olat/core/id/context/HistoryManager.java +++ b/src/main/java/org/olat/core/id/context/HistoryManager.java @@ -72,6 +72,8 @@ public class HistoryManager { historyReadStream.omitField(RepositoryEntry.class, "metaDataElements"); historyReadStream.omitField(RepositoryEntry.class, "version"); historyReadStream.omitField(RepositoryEntry.class, "organisations"); + historyReadStream.omitField(RepositoryEntry.class, "storedSnapshot"); + historyReadStream.omitField(RepositoryEntry.class, "statistics"); historyReadStream.omitField(org.olat.core.commons.persistence.PersistentObject.class, "version"); historyReadStream.alias("org.olat.core.util.resource.OresHelper$1", Resourceable.class); @@ -99,15 +101,16 @@ public class HistoryManager { } public HistoryPoint readHistoryPoint(Identity identity) { + File resumeXml = null; try { String pathHomePage = FolderConfig.getCanonicalRoot() + FolderConfig.getUserHomePage(identity.getName()); - File resumeXml = new File(pathHomePage, "resume.xml"); + resumeXml = new File(pathHomePage, "resume.xml"); return readHistory(resumeXml); } catch(ConversionException e) { - log.warn("Cannot read resume file: ", e); + log.warn("Cannot read resume file: " + resumeXml, e); return null; } catch (Exception e) { - log.error("Cannot read resume file: ", e); + log.error("Cannot read resume file: " + resumeXml, e); return null; } } @@ -116,8 +119,8 @@ public class HistoryManager { try { String pathHomePage = FolderConfig.getCanonicalRoot() + FolderConfig.getUserHomePage(identity.getName()); File resumeXml = new File(pathHomePage, "resume.xml"); - if(resumeXml.exists()) { - resumeXml.delete(); + if(resumeXml.exists() && !resumeXml.delete()) { + log.error("Cannot delete this resume file: " + resumeXml); } } catch (Exception e) { log.error("Can not delete history file", e); @@ -126,10 +129,12 @@ public class HistoryManager { protected HistoryPoint readHistory(File resumeXml) throws IOException { if(resumeXml.exists()) { - FileInputStream in = new FileInputStream(resumeXml); - HistoryPoint point = (HistoryPoint)historyReadStream.fromXML(in); - FileUtils.closeSafely(in); - return point; + try(FileInputStream in = new FileInputStream(resumeXml)) { + return (HistoryPoint)historyReadStream.fromXML(in); + } catch(IOException e) { + log.error("Cannot read this file: " + resumeXml, e); + throw e; + } } return null; } diff --git a/src/main/java/org/olat/core/util/mail/ui/EMailCalloutCtrl.java b/src/main/java/org/olat/core/util/mail/ui/EMailCalloutCtrl.java index d2d66784c29..d6bd3151077 100644 --- a/src/main/java/org/olat/core/util/mail/ui/EMailCalloutCtrl.java +++ b/src/main/java/org/olat/core/util/mail/ui/EMailCalloutCtrl.java @@ -83,13 +83,8 @@ public class EMailCalloutCtrl extends FormBasicController { boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(roles); boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles); if (autoCompleteAllowed) { - List<Organisation> searcheableOrganisations; - if(roles.isOLATAdmin()) { - searcheableOrganisations = null; - } else { - searcheableOrganisations = organisationService - .getSearchableOrganisations(getIdentity(), roles, OrganisationRoles.usermanager); - } + List<Organisation> searcheableOrganisations = organisationService.getOrganisations(getIdentity(), roles, + OrganisationRoles.valuesWithoutGuestAndInvitee()); ListProvider provider = new UserSearchListProvider(searcheableOrganisations); autocompleterC = new FlexiAutoCompleterController(ureq, getWindowControl(), provider, null, isAdministrativeUser, allowExternalAddress, 60, 3, null, mainForm); autocompleterC.setFormElement(false); @@ -137,7 +132,7 @@ public class EMailCalloutCtrl extends FormBasicController { @Override protected boolean validateFormLogic(UserRequest ureq) { - boolean allOk = true; + boolean allOk = super.validateFormLogic(ureq); if(emailEl != null) { emailEl.clearError(); @@ -147,7 +142,7 @@ public class EMailCalloutCtrl extends FormBasicController { } } - return allOk & super.validateFormLogic(ureq); + return allOk; } @Override diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index ed1c85d0729..9c746f4add2 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -113,6 +113,7 @@ import org.olat.repository.RepositoryEntryRelationType; import org.olat.repository.RepositoryEntryShort; import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryService; +import org.olat.repository.manager.RepositoryEntryQueries; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.model.RepositoryEntryToGroupRelation; import org.olat.repository.model.SearchRepositoryEntryParameters; @@ -158,6 +159,8 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD @Autowired private RepositoryEntryRelationDAO repositoryEntryRelationDao; @Autowired + private RepositoryEntryQueries repositoryEntryQueries; + @Autowired private RepositoryDeletionModule deletionManager; @Autowired private NotificationsManager notificationsManager; @@ -1585,7 +1588,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD float ratio = -1.0f; if(delegate != null) { - int numOfEntries = repositoryManager.countGenericANDQueryWithRolesRestriction(params); + int numOfEntries = repositoryEntryQueries.countEntries(params); ratio = 100.0f / numOfEntries; } @@ -1595,7 +1598,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD int batch = 25; List<RepositoryEntry> entries; do { - entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, batch, true); + entries = repositoryEntryQueries.searchEntries(params, counter, batch, true); for(RepositoryEntry re:entries) { countForCommit += 2 + dedupSingleRepositoryentry(ureqIdentity, re, coaches, participants, false); if(countForCommit > 25) { diff --git a/src/main/java/org/olat/modules/coach/manager/CoachingDAO.java b/src/main/java/org/olat/modules/coach/manager/CoachingDAO.java index 0cae6df0695..414cc95277a 100644 --- a/src/main/java/org/olat/modules/coach/manager/CoachingDAO.java +++ b/src/main/java/org/olat/modules/coach/manager/CoachingDAO.java @@ -392,7 +392,7 @@ public class CoachingDAO { .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as coach on coach.role in ('").append(GroupRoles.coach.name()).append("','").append(GroupRoles.owner.name()).append("')") .append(" where coach.identity.key=:coachKey and res.resName='CourseModule'") - .append(" and ((v.access=1 and v.membersOnly=true) ") + .append(" and ((v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true)") .append(" or (v.access >= ").append(RepositoryEntry.ACC_USERS).append(" and coach.role='").append(GroupRoles.coach.name()).append("')") .append(" or (v.access >= ").append(RepositoryEntry.ACC_OWNERS).append(" and coach.role='").append(GroupRoles.owner.name()).append("'))"); @@ -418,8 +418,8 @@ public class CoachingDAO { .append(" count(distinct pg_initial_launch.id) as pg_id") .append(" from o_repositoryentry sg_re ") .append(" inner join o_re_to_group togroup on (togroup.fk_entry_id = sg_re.repositoryentry_id)") - .append(" inner join o_bs_group_member sg_coach on (sg_coach.fk_group_id=togroup.fk_group_id and sg_coach.g_role = 'coach')") - .append(" inner join o_bs_group_member sg_participant on (sg_participant.fk_group_id=sg_coach.fk_group_id and sg_participant.g_role='participant')") + .append(" inner join o_bs_group_member sg_coach on (sg_coach.fk_group_id=togroup.fk_group_id and sg_coach.g_role = '").append(GroupRoles.coach.name()).append("')") + .append(" inner join o_bs_group_member sg_participant on (sg_participant.fk_group_id=sg_coach.fk_group_id and sg_participant.g_role='").append(GroupRoles.participant.name()).append("')") .append(" left join o_as_user_course_infos pg_initial_launch") .append(" on (pg_initial_launch.fk_resource_id = sg_re.fk_olatresource and pg_initial_launch.fk_identity = sg_participant.fk_identity_id)") .append(" where sg_coach.fk_identity_id=:coachKey and ( ") diff --git a/src/main/java/org/olat/modules/sharedfolder/SharedFolderWebDAVMergeSource.java b/src/main/java/org/olat/modules/sharedfolder/SharedFolderWebDAVMergeSource.java index 1a359750db5..58ff6275e8e 100644 --- a/src/main/java/org/olat/modules/sharedfolder/SharedFolderWebDAVMergeSource.java +++ b/src/main/java/org/olat/modules/sharedfolder/SharedFolderWebDAVMergeSource.java @@ -22,7 +22,6 @@ package org.olat.modules.sharedfolder; import static org.olat.modules.sharedfolder.SharedFolderWebDAVProvider.readOnlyCallback; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -36,6 +35,7 @@ import org.olat.core.util.vfs.VFSContainer; import org.olat.fileresource.types.SharedFolderFileResource; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; +import org.olat.repository.model.SearchRepositoryEntryParameters; /** @@ -83,9 +83,9 @@ public class SharedFolderWebDAVMergeSource extends WebDAVMergeSource { // If the first value in the list is '*', list all resource folders. if (firstItem != null && firstItem.equals("*")) { // fake role that represents normally logged in user - Roles registeredUserRole = new Roles(false, false, false, false, false, false, false); - List<String> types = Collections.singletonList(SharedFolderFileResource.TYPE_NAME); - List<RepositoryEntry> allEntries = repoManager.queryByTypeLimitAccess(getIdentity(), types, registeredUserRole); + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), Roles.userRoles(), SharedFolderFileResource.TYPE_NAME); + List<RepositoryEntry> allEntries = repoManager + .genericANDQueryWithRolesRestriction(params, 0, -1, false); for (RepositoryEntry entry : allEntries) { addReadonlyFolder(entry, sfm, addedEntries, containers); } diff --git a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java index 4e8c1a9867e..6f91aa8ed06 100755 --- a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java +++ b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java @@ -1337,7 +1337,7 @@ public class EPStructureManager { private EPStructureElement instantiateClone(PortfolioStructure source) { EPStructureElement targetEl = null; - //don't forget the inheritence + //don't forget the inheritance if (source instanceof EPPage) { targetEl = new EPPage(); targetEl.setTitle(((EPPage) source).getTitle()); diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index fef92df4b3d..3717bb43198 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -36,7 +36,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import javax.persistence.TypedQuery; @@ -45,7 +44,6 @@ import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.IdentityImpl; import org.olat.basesecurity.IdentityRef; import org.olat.basesecurity.OrganisationRoles; -import org.olat.basesecurity.OrganisationService; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.modules.bc.FolderConfig; import org.olat.core.commons.modules.bc.meta.MetaInfo; @@ -81,6 +79,7 @@ import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSManager; import org.olat.group.GroupLoggingAction; import org.olat.repository.manager.RepositoryEntryDAO; +import org.olat.repository.manager.RepositoryEntryQueries; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.manager.RepositoryEntryToOrganisationDAO; import org.olat.repository.model.RepositoryEntryLifecycle; @@ -89,6 +88,7 @@ import org.olat.repository.model.RepositoryEntryMembershipModifiedEvent; import org.olat.repository.model.RepositoryEntryPermissionChangeEvent; import org.olat.repository.model.RepositoryEntrySecurity; import org.olat.repository.model.RepositoryEntryShortImpl; +import org.olat.repository.model.RepositoryEntryToGroupRelation; import org.olat.repository.model.SearchRepositoryEntryParameters; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceManager; @@ -137,7 +137,7 @@ public class RepositoryManager { @Autowired private AutoAccessManager autoAccessManager; @Autowired - private OrganisationService organisationService; + private RepositoryEntryQueries repositoryEntryQueries; /** * @return Singleton. @@ -476,21 +476,18 @@ public class RepositoryManager { * @param a collection of external IDs to check if already existing * @return a list of already existing external IDs (or an emtpy list). */ - public List<String> lookupExistingExternalIds(Collection<String> externalIds) { - if (externalIds == null || externalIds.isEmpty()) { - return Collections.emptyList(); - } - - StringBuilder query = new StringBuilder(); - query.append("select v.externalId from ").append(RepositoryEntry.class.getName()).append(" as v ") - .append("where v.externalId in (:externalIds)"); + public List<String> lookupExistingExternalIds(Collection<String> externalIds) { + if (externalIds == null || externalIds.isEmpty()) { + return Collections.emptyList(); + } - List<String> existingExternalIds = - dbInstance.getCurrentEntityManager().createQuery(query.toString(), String.class) - .setParameter("externalIds", externalIds) - .getResultList(); + StringBuilder query = new StringBuilder(); + query.append("select v.externalId from ").append(RepositoryEntry.class.getName()).append(" as v ") + .append("where v.externalId in (:externalIds)"); - return existingExternalIds; + return dbInstance.getCurrentEntityManager().createQuery(query.toString(), String.class) + .setParameter("externalIds", externalIds) + .getResultList(); } /** @@ -505,11 +502,10 @@ public class RepositoryManager { .append(" where ores.key in (:resKeys)"); List<Long> resourceKeys = PersistenceHelper.toKeys(resources); - List<RepositoryEntryShort> shorties = dbInstance.getCurrentEntityManager() + return dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), RepositoryEntryShort.class) .setParameter("resKeys", resourceKeys) .getResultList(); - return shorties; } /** @@ -518,12 +514,11 @@ public class RepositoryManager { * @return */ public List<RepositoryEntryShortImpl> loadRepositoryEntryShortsByResource(Collection<Long> resIds, String resourceType) { - List<RepositoryEntryShortImpl> shorties = dbInstance.getCurrentEntityManager() + return dbInstance.getCurrentEntityManager() .createNamedQuery("loadRepositoryEntryShortsByResourceableIds", RepositoryEntryShortImpl.class) .setParameter("resIds", resIds) .setParameter("resName", resourceType) .getResultList(); - return shorties; } /** @@ -583,6 +578,7 @@ public class RepositoryManager { boolean isGroupWaiting = false; boolean isEntryAdmin = false; + boolean isLearnRessourceManager = false; boolean canLaunch = false; if (roles.isGuestOnly()) { @@ -596,35 +592,50 @@ public class RepositoryManager { for(Object[] roleAndDef:roleAndDefs) { String role = (String)roleAndDef[0]; Boolean def = (Boolean)roleAndDef[1]; - switch(GroupRoles.valueOf(role)) { - case owner: { - isOwner = true; - break; - } - case coach: { - boolean d = (def == null ? false : def.booleanValue()); - if(d) { - isCourseCoach = true; - } else { - isGroupCoach = true; + + if(GroupRoles.isValue(role)) { + switch(GroupRoles.valueOf(role)) { + case owner: { + isOwner = true; + break; } - break; - } - case participant: { - boolean d = (def == null ? false : def.booleanValue()); - if(d) { - isCourseParticipant = true; - } else { - isGroupParticipant = true; + case coach: { + boolean d = (def == null ? false : def.booleanValue()); + if(d) { + isCourseCoach = true; + } else { + isGroupCoach = true; + } + break; + } + case participant: { + boolean d = (def == null ? false : def.booleanValue()); + if(d) { + isCourseParticipant = true; + } else { + isGroupParticipant = true; + } + break; } - break; + case waiting: { + isGroupWaiting = true; + break; + } + default: break; } - case waiting: { - isGroupWaiting = true; - break; + } else if(OrganisationRoles.isValue(role)) { + + switch(OrganisationRoles.valueOf(role)) { + case learnresourcemanager: { + isLearnRessourceManager = true; + break; + } + case coach: { + isCourseCoach = true; + break; + } + default: break; } - case invitee: break; - } } @@ -639,7 +650,7 @@ public class RepositoryManager { isEntryAdmin = true; } // allow for institutional resource manager - else if (isInstitutionalRessourceManagerFor(identity, roles, re)) { + else if (isLearnRessourceManager) { canLaunch = true; isEntryAdmin = true; } @@ -650,12 +661,9 @@ public class RepositoryManager { // allow if access granted for users canLaunch = true; } else if (re.getAccess() == RepositoryEntry.ACC_OWNERS && re.isMembersOnly()) { - if(!canLaunch) { - //is member? - if(isGroupParticipant || isGroupCoach || - isCourseParticipant || isCourseCoach) { - canLaunch = true; - } + // check if it's a member + if(!canLaunch && (isGroupParticipant || isGroupCoach || isCourseParticipant || isCourseCoach)) { + canLaunch = true; } } } @@ -848,6 +856,7 @@ public class RepositoryManager { for(RepositoryEntryToOrganisation relation:copyRelations) { if(!organisations.contains(relation.getOrganisation())) { repositoryEntryToOrganisationDao.delete(relation); + repositoryEntryRelationDao.removeRelation(relation.getOrganisation().getGroup()); } else { currentOrganisations.add(relation.getOrganisation()); } @@ -858,6 +867,8 @@ public class RepositoryManager { RepositoryEntryToOrganisation newRelation = repositoryEntryToOrganisationDao .createRelation(organisation, reloadedRe, false); currentRelations.add(newRelation); + RepositoryEntryToGroupRelation relToGroup = repositoryEntryRelationDao.createRelation(organisation.getGroup(), reloadedRe); + reloadedRe.getGroups().add(relToGroup); } } } @@ -919,94 +930,6 @@ public class RepositoryManager { return count == null || count.isEmpty() || count.get(0) == null ? null : count.get(0).longValue(); } - /** - * Query by type, limit by ownership or role accessability. - * @param identity - * @param restrictedType The type cannot be empty, no type, no return - * @param roles - * @return - */ - public List<RepositoryEntry> queryByTypeLimitAccess(Identity identity, List<String> restrictedType, Roles roles) { - if(restrictedType == null | restrictedType.isEmpty()) return Collections.emptyList(); - if(roles.isOLATAdmin()) { - identity = null;//not need for the query as administrator - } - - StringBuilder sb = new StringBuilder(400); - sb.append("select distinct v from ").append(RepositoryEntry.class.getName()).append(" v ") - .append(" inner join fetch v.olatResource as res") - .append(" inner join fetch v.statistics as statistics") - .append(" left join fetch v.lifecycle as lifecycle") - .append(" where res.resName in (:restrictedType) and "); - - boolean setIdentity = false; - if (roles.isOLATAdmin()) { - sb.append("v.access>=").append(RepositoryEntry.ACC_OWNERS); // treat admin special b/c admin is author as well - } else { - setIdentity = appendAccessSubSelects(sb, identity, roles); - } - - TypedQuery<RepositoryEntry> query = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), RepositoryEntry.class) - .setParameter("restrictedType", restrictedType); - if(setIdentity) { - query.setParameter("identityKey", identity.getKey()); - } - return query.getResultList(); - } - - /** - * Query by type, limit by ownership or role accessability and institution. - * @param identity - * @param roles - * @param restrictedType The types cannot be empty, no type, nothing to return - * @return - */ - public List<RepositoryEntry> queryByTypeLimitAccess(Identity identity, Roles roles, List<String> restrictedType) { - if(restrictedType == null || restrictedType.isEmpty()) return Collections.emptyList(); - - List<RepositoryEntry> results = new ArrayList<>(); - if(!roles.isOLATAdmin() && roles.isLearnResourceManager()) { - List<Organisation> managedOrganisations = organisationService.getManageableOrganisations(identity, roles, OrganisationRoles.learnresourcemanager); - if(!managedOrganisations.isEmpty()) { - StringBuilder sb = new StringBuilder(400); - sb.append("select distinct v from ").append(RepositoryEntry.class.getName()).append(" v") - .append(" inner join fetch v.olatResource as res") - .append(" inner join fetch v.statistics as statistics") - .append(" left join fetch v.lifecycle as lifecycle") - .append(" inner join v.organisations as relToOrg") - .append(" where relToOrg.organisation.key in (:managedOrganisationsKey)") - .append(" and res.resName in (:restrictedType) and v.access = 1"); - - List<Long> managedOrganisationsKey = managedOrganisations - .stream().map(Organisation::getKey).collect(Collectors.toList()); - - List<RepositoryEntry> institutionalResults = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), RepositoryEntry.class) - .setParameter("restrictedType", restrictedType) - .setParameter("managedOrganisationsKey", managedOrganisationsKey) - .getResultList(); - results.addAll(institutionalResults); - } - } - - long start = System.currentTimeMillis(); - List<RepositoryEntry> genericResults = queryByTypeLimitAccess(identity, restrictedType, roles); - long timeQuery3 = System.currentTimeMillis() - start; - log.info("Repo-Perf: queryByTypeLimitAccess#3 takes " + timeQuery3); - - if(results.isEmpty()) { - results.addAll(genericResults); - } else { - for(RepositoryEntry genericResult:genericResults) { - if(!PersistenceHelper.listContainsObjectByKey(results, genericResult)) { - results.add(genericResult); - } - } - } - return results; - } - /** * Query by ownership, optionally limit by type. * @@ -1017,8 +940,8 @@ public class RepositoryManager { public List<RepositoryEntry> queryByOwner(IdentityRef identity, String... limitTypes) { if (identity == null) throw new AssertException("identity can not be null!"); StringBuilder sb = new StringBuilder(400); - sb.append("select v from repositoryentry v ") - .append(" inner join fetch v.olatResource as res ") + sb.append("select v from repositoryentry v") + .append(" inner join fetch v.olatResource as res") .append(" inner join fetch v.statistics as statistics") .append(" left join fetch v.lifecycle as lifecycle") .append(" inner join v.groups as relGroup on relGroup.defaultGroup=true") @@ -1033,7 +956,7 @@ public class RepositoryManager { .createQuery(sb.toString(), RepositoryEntry.class) .setParameter("identityKey", identity.getKey()); if(limitTypes != null && limitTypes.length > 0) { - List<String> types = new ArrayList<String>(); + List<String> types = new ArrayList<>(); for(String type:limitTypes) { types.add(type); } @@ -1093,7 +1016,7 @@ public class RepositoryManager { .createQuery(sb.toString(), RepositoryEntry.class) .setParameter("identityKey", identity.getKey()); if(limitTypes != null && limitTypes.length > 0) { - List<String> types = new ArrayList<String>(); + List<String> types = new ArrayList<>(); for(String type:limitTypes) { types.add(type); } @@ -1117,93 +1040,71 @@ public class RepositoryManager { } /** - * Search for resources that can be referenced by an author. This is the case: - * 1) the user is the owner of the resource - * 2) the user is author and the resource is at least visible to authors (BA) - * and the resource is set to canReference - * @param identity The user initiating the query - * @param roles The current users role set - * @param resourceTypes Limit search result to this list of repo types. Can be NULL - * @param displayName Limit search to this repo title. Can be NULL - * @param author Limit search to this user (Name, firstname, loginname). Can be NULL - * @param desc Limit search to description. Can be NULL - * @return List of repository entries - */ - public List<RepositoryEntry> queryReferencableResourcesLimitType(Identity identity, Roles roles, List<String> resourceTypes, - String displayName, String author, String desc) { - if (identity == null) { - throw new AssertException("identity can not be null!"); - } - if (!roles.isAuthor()) { - // if user has no author right he can not reference to any resource at all - return new ArrayList<>(); - } - return queryResourcesLimitType(identity, resourceTypes, displayName, author, desc, true, false); - } - - /** - * Search for resources that can be copied by an author. This is the case: - * 1) the user is the owner of the resource - * 2) the user is author and the resource is at least visible to authors (BA) - * and the resource is set to canCopy - * @param identity The user initiating the query - * @param roles The current users role set - * @param resourceTypes Limit search result to this list of repo types. Can be NULL - * @param displayName Limit search to this repo title. Can be NULL - * @param author Limit search to this user (Name, firstname, loginname). Can be NULL - * @param desc Limit search to description. Can be NULL - * @return List of repository entries + * This is an administrative query which need author, learn resource manager + * or higher permissions. + * + * @param identity + * @param roles + * @param resourceTypes + * @param displayName + * @param author + * @param desc + * @param checkCanReference + * @param checkCanCopy + * @return */ - public List<RepositoryEntry> queryCopyableResourcesLimitType(Identity identity, Roles roles, List<String> resourceTypes, - String displayName, String author, String desc) { - if (identity == null) { - throw new AssertException("identity can not be null!"); + public List<RepositoryEntry> queryResourcesLimitType(Identity identity, Roles roles, List<String> resourceTypes, + String displayName, String author, String desc, boolean checkCanReference, boolean checkCanCopy) { + if(!checkCanReference && !checkCanCopy) { + return Collections.emptyList(); } - if (!roles.isAuthor() && !roles.isOLATAdmin()) { - // if user has no author right he can not reference to any resource at all - return new ArrayList<>(); + if(!roles.isAuthor() && !roles.isLearnResourceManager() && !roles.isOLATAdmin()) { + return Collections.emptyList(); } - return queryResourcesLimitType(identity, resourceTypes, displayName, author, desc, false, true); - } - - public List<RepositoryEntry> queryResourcesLimitType(Identity identity, List<String> resourceTypes, - String displayName, String author, String desc, boolean checkCanReference, boolean checkCanCopy) { - - // cleanup some data: use null values if emtpy - if (resourceTypes != null && resourceTypes.size() == 0) resourceTypes = null; - if ( ! StringHelper.containsNonWhitespace(displayName)) displayName = null; - if ( ! StringHelper.containsNonWhitespace(author)) author = null; - if ( ! StringHelper.containsNonWhitespace(desc)) desc = null; // Build the query // 1) Joining tables StringBuilder query = new StringBuilder(400); - query.append("select distinct v from ").append(RepositoryEntry.class.getName()).append(" v ") + query.append("select distinct v from repositoryentry v ") .append(" inner join fetch v.olatResource as res" ) .append(" inner join fetch v.statistics as statistics") - .append(" left join fetch v.lifecycle as lifecycle"); - // 2) where clause - query.append(" where "); - // restrict on ownership or referencability flag - - int access; - if(identity != null) { - access = RepositoryEntry.ACC_OWNERS_AUTHORS; - query.append(" (v.access>=:access"); - if(checkCanReference) { - query.append(" and v.canReference=true"); - } - if(checkCanCopy) { - query.append(" and v.canCopy=true"); - } - query.append(" or (v.access>0 and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership ") - .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=:identityKey ") - .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("','").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')") - .append(" ))") - .append(" )"); + .append(" left join fetch v.lifecycle as lifecycle") + .append(" left join v.groups as relGroup") + .append(" left join relGroup.group as baseGroup") + .append(" left join baseGroup.members as membership"); + if(roles.isOLATAdmin()) { + query.append(" where v.access>=").append(RepositoryEntry.ACC_OWNERS); } else { - access = RepositoryEntry.ACC_OWNERS; - query.append(" v.access>=:access "); + query.append(" where membership.identity.key=:identityKey and ("); + // as owner + query.append("(v.access>=").append(RepositoryEntry.ACC_OWNERS) + .append(" and membership.role='").append(GroupRoles.owner.name()).append("')"); + + if(roles.isLearnResourceManager()) { + // as learn resource manager + query.append(" or (v.access>=").append(RepositoryEntry.ACC_OWNERS); + if(checkCanReference) { + query.append(" and v.canReference=true"); + } + if(checkCanCopy) { + query.append(" and v.canCopy=true"); + } + query.append(" and membership.role='").append(OrganisationRoles.learnresourcemanager.name()).append("')"); + } + + if(roles.isAuthor()) { + // as author + query.append(" or (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS); + if(checkCanReference) { + query.append(" and v.canReference=true"); + } + if(checkCanCopy) { + query.append(" and v.canCopy=true"); + } + query.append(" and membership.role='").append(OrganisationRoles.author.name()).append("')"); + + } + query.append(")"); } // restrict on type @@ -1237,19 +1138,22 @@ public class RepositoryManager { // create query an set query data TypedQuery<RepositoryEntry> dbquery = dbInstance.getCurrentEntityManager() .createQuery(query.toString(), RepositoryEntry.class); - if(identity != null) { + if(!roles.isOLATAdmin()) { dbquery.setParameter("identityKey", identity.getKey()); } - dbquery.setParameter("access", access); + if (author != null) { dbquery.setParameter("author", author); } + if (displayName != null) { dbquery.setParameter("displayname", displayName); } + if (desc != null) { dbquery.setParameter("desc", desc); } + if (resourceTypes != null) { dbquery.setParameter("resourcetypes", resourceTypes); } @@ -1266,8 +1170,8 @@ public class RepositoryManager { */ public List<RepositoryEntry> queryByOwnerLimitAccess(Identity identity, int limitAccess, Boolean membersOnly) { StringBuilder sb = new StringBuilder(); - sb.append("select v from ").append(RepositoryEntry.class.getName()).append(" v ") - .append(" inner join fetch v.olatResource as res ") + sb.append("select v from repositoryentry v") + .append(" inner join fetch v.olatResource as res") .append(" inner join fetch v.statistics as statistics") .append(" left join fetch v.lifecycle as lifecycle") .append(" inner join v.groups as relGroup on relGroup.defaultGroup=true") @@ -1275,7 +1179,7 @@ public class RepositoryManager { .append(" inner join baseGroup.members as membership on membership.role='").append(GroupRoles.owner.name()).append("'") .append(" where membership.identity.key=:identityKey and (v.access>=:limitAccess"); if(limitAccess != RepositoryEntry.ACC_OWNERS && membersOnly != null && membersOnly.booleanValue()) { - sb.append(" or (v.access=1 and v.membersOnly=true)"); + sb.append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true)"); } sb.append(")"); @@ -1296,237 +1200,13 @@ public class RepositoryManager { } return repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.owner.name()); } - - /** - * This query need the repository entry as v, v.olatResource as res - * and v.baseGroup as baseGroup - * @param sb - * @param identity - * @param roles - * @return - */ - public static boolean appendAccessSubSelects(StringBuilder sb, IdentityRef identity, Roles roles) { - sb.append("(v.access >= "); - if (roles.isAuthor()) { - sb.append(RepositoryEntry.ACC_OWNERS_AUTHORS); - } else if (roles.isGuestOnly()) { - sb.append(RepositoryEntry.ACC_USERS_GUESTS); - } else { - sb.append(RepositoryEntry.ACC_USERS); - } - - //+ membership - boolean setIdentity = false; - if(!roles.isGuestOnly() && identity != null) { - setIdentity = true; - //sub select are very quick - sb.append(" or (") - .append(" v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true") - .append(" and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership ") - .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=:identityKey ") - .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("','").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')") - .append(" )") - .append(" )"); - } - sb.append(")"); - return setIdentity; - } - + public int countGenericANDQueryWithRolesRestriction(SearchRepositoryEntryParameters params) { - TypedQuery<Number> dbQuery = createGenericANDQueryWithRolesRestriction(params, false, Number.class); - Number count = dbQuery.getSingleResult(); - return count.intValue(); + return repositoryEntryQueries.countEntries(params); } public List<RepositoryEntry> genericANDQueryWithRolesRestriction(SearchRepositoryEntryParameters params, int firstResult, int maxResults, boolean orderBy) { - TypedQuery<RepositoryEntry> dbQuery = createGenericANDQueryWithRolesRestriction(params, orderBy, RepositoryEntry.class); - dbQuery.setFirstResult(firstResult); - if(maxResults > 0) { - dbQuery.setMaxResults(maxResults); - } - return dbQuery.getResultList(); - } - - private <T> TypedQuery<T> createGenericANDQueryWithRolesRestriction(SearchRepositoryEntryParameters params, boolean orderBy, Class<T> type) { - String displayName = params.getDisplayName(); - String author = params.getAuthor(); - String desc = params.getDesc(); - final List<String> resourceTypes = params.getResourceTypes(); - final Identity identity = params.getIdentity(); - final Roles roles = params.getRoles(); - - boolean isLearnResourceManager = (!roles.isOLATAdmin() && roles.isLearnResourceManager()); - boolean var_author = StringHelper.containsNonWhitespace(author); - boolean var_displayname = StringHelper.containsNonWhitespace(displayName); - boolean var_desc = StringHelper.containsNonWhitespace(desc); - boolean var_resourcetypes = (resourceTypes != null && resourceTypes.size() > 0); - boolean count = Number.class.equals(type); - - StringBuilder query = new StringBuilder(); - if(count) { - query.append("select count(v.key) from ").append(RepositoryEntry.class.getName()).append(" v "); - query.append(" inner join v.olatResource as res"); - } else { - if(params.getParentEntry() != null) { - query.append("select v from ").append(CatalogEntry.class.getName()).append(" cei ") - .append(" inner join cei.parent parentCei") - .append(" inner join cei.repositoryEntry v") - .append(" inner join fetch v.olatResource as res") - .append(" inner join fetch v.statistics as statistics") - .append(" left join fetch v.lifecycle as lifecycle"); - } else { - query.append("select distinct v from ").append(RepositoryEntry.class.getName()).append(" v ") - .append(" inner join fetch v.olatResource as res") - .append(" inner join fetch v.statistics as statistics") - .append(" left join fetch v.lifecycle as lifecycle"); - } - } - - boolean setIdentity = false; - List<Long> managedOrganisationKeys = null; - - //access rules - if(roles.isOLATAdmin()) { - query.append(" where v.access!=0 "); - } else if(isLearnResourceManager) { - query.append(" where (v.access >="); - if (roles.isAuthor()) { - query.append(RepositoryEntry.ACC_OWNERS_AUTHORS); - } else if (roles.isGuestOnly()) { - query.append(RepositoryEntry.ACC_USERS_GUESTS); - } else{ - query.append(RepositoryEntry.ACC_USERS); - } - query.append(" or ("); - query.append("v.access=1 and exists (select relToOrg.key from repoentrytoorganisation as relToOrg") - .append(" where relToOrg.entry.key=v.key and relToOrg.organisation.key in (:managedOrganisationKeys)") - .append(")))"); - - List<Organisation> organisations = organisationService.getManageableOrganisations(identity, roles, OrganisationRoles.learnresourcemanager); - managedOrganisationKeys = organisations.stream().map(Organisation::getKey).collect(Collectors.toList()); - } else if (params.isOnlyOwnedResources()) { - query.append(" where (v.access>0 and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership ") - .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup") - .append(" and membership.identity.key=:identityKey and membership.role='").append(GroupRoles.owner.name()).append("'") - .append(" ))"); - setIdentity = true; - } else if (params.isOnlyExplicitMember()) { - query.append(" where (v.access>=").append(RepositoryEntry.ACC_USERS) - .append(" or (") - .append(" v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true") - .append(" and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership ") - .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=:identityKey ") - .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("','").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')") - .append(" )") - .append(" ))"); - - setIdentity = true; - } else { - query.append(" where "); - setIdentity = appendAccessSubSelects(query, identity, roles); - } - - if(params.getParentEntry() != null) { - query.append(" and parentCei.key=:parentCeiKey"); - } - - if (var_author) { // fuzzy author search - author = PersistenceHelper.makeFuzzyQueryString(author); - - query.append(" and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership, ") - .append(IdentityImpl.class.getName()).append(" as identity, ").append(UserImpl.class.getName()).append(" as user") - .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=identity.key and user.identity.key=identity.key") - .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") - .append(" and ("); - PersistenceHelper.appendFuzzyLike(query, "user.firstName", "author", dbInstance.getDbVendor()); - query.append(" or "); - PersistenceHelper.appendFuzzyLike(query, "user.lastName", "author", dbInstance.getDbVendor()); - query.append(" or "); - PersistenceHelper.appendFuzzyLike(query, "identity.name", "author", dbInstance.getDbVendor()); - query.append(" ))"); - } - - if (var_displayname) { - displayName = PersistenceHelper.makeFuzzyQueryString(displayName); - query.append(" and "); - PersistenceHelper.appendFuzzyLike(query, "v.displayname", "displayname", dbInstance.getDbVendor()); - } - - if (var_desc) { - desc = PersistenceHelper.makeFuzzyQueryString(desc); - query.append(" and "); - PersistenceHelper.appendFuzzyLike(query, "v.description", "desc", dbInstance.getDbVendor()); - } - - if (var_resourcetypes) { - query.append(" and res.resName in (:resourcetypes)"); - } - - if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { - query.append(" and v.key in (:entryKeys)"); - } - - if(params.getManaged() != null) { - if(params.getManaged().booleanValue()) { - query.append(" and v.managedFlagsString is not null"); - } else { - query.append(" and v.managedFlagsString is null"); - } - } - - if(StringHelper.containsNonWhitespace(params.getExternalId())) { - query.append(" and v.externalId=:externalId"); - } - - if(StringHelper.containsNonWhitespace(params.getExternalRef())) { - query.append(" and v.externalRef=:externalRef"); - } - - if(params.getMarked() != null) { - setIdentity = true; - query.append(" and v.key ").append(params.getMarked().booleanValue() ? "" : "not").append(" in (") - .append(" select mark.resId from ").append(MarkImpl.class.getName()).append(" mark ") - .append(" where mark.resName='RepositoryEntry' and mark.creator.key=:identityKey") - .append(" )"); - } - - if(!count && orderBy) { - query.append(" order by v.displayname, v.key ASC"); - } - - TypedQuery<T> dbQuery = dbInstance.getCurrentEntityManager().createQuery(query.toString(), type); - if(managedOrganisationKeys != null) { - dbQuery.setParameter("managedOrganisationKeys", managedOrganisationKeys); - } - if(params.getParentEntry() != null) { - dbQuery.setParameter("parentCeiKey", params.getParentEntry().getKey()); - } - if (var_author) { - dbQuery.setParameter("author", author); - } - if (var_displayname) { - dbQuery.setParameter("displayname", displayName); - } - if (var_desc) { - dbQuery.setParameter("desc", desc); - } - if (var_resourcetypes) { - dbQuery.setParameter("resourcetypes", resourceTypes); - } - if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { - dbQuery.setParameter("entryKeys", params.getRepositoryEntryKeys()); - } - if(StringHelper.containsNonWhitespace(params.getExternalId())) { - dbQuery.setParameter("externalId", params.getExternalId()); - } - if(StringHelper.containsNonWhitespace(params.getExternalRef())) { - dbQuery.setParameter("externalRef", params.getExternalRef()); - } - - if(setIdentity) { - dbQuery.setParameter("identityKey", identity.getKey()); - } - return dbQuery; + return repositoryEntryQueries.searchEntries(params, firstResult, maxResults, orderBy); } /** @@ -1559,7 +1239,7 @@ public class RepositoryManager { */ public void addOwners(Identity ureqIdentity, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) { List<Identity> addIdentities = iae.getAddIdentities(); - List<Identity> reallyAddedId = new ArrayList<Identity>(); + List<Identity> reallyAddedId = new ArrayList<>(); for (Identity identity : addIdentities) { if (!repositoryEntryRelationDao.hasRole(identity, re, GroupRoles.owner.name())) { repositoryEntryRelationDao.addRole(identity, re, GroupRoles.owner.name()); @@ -1651,7 +1331,7 @@ public class RepositoryManager { */ public void addTutors(Identity ureqIdentity, Roles ureqRoles, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) { List<Identity> addIdentities = iae.getAddIdentities(); - List<Identity> reallyAddedId = new ArrayList<Identity>(); + List<Identity> reallyAddedId = new ArrayList<>(); for (Identity identityToAdd : addIdentities) { if (!repositoryEntryRelationDao.hasRole(identityToAdd, re, GroupRoles.coach.name())) { @@ -1752,7 +1432,7 @@ public class RepositoryManager { */ public void addParticipants(Identity ureqIdentity, Roles ureqRoles, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) { List<Identity> addIdentities = iae.getAddIdentities(); - List<Identity> reallyAddedId = new ArrayList<Identity>(); + List<Identity> reallyAddedId = new ArrayList<>(); for (Identity identityToAdd : addIdentities) { if (!repositoryEntryRelationDao.hasRole(identityToAdd, re, GroupRoles.participant.name())) { @@ -1914,6 +1594,7 @@ public class RepositoryManager { return false; } + //TODO roles (add administration) List<OrganisationRef> learnResourceManagerOrganisations = roles.getOrganisationsWithRoles(OrganisationRoles.learnresourcemanager); List<OrganisationRef> repositoryOrganisations = repositoryEntryToOrganisationDao.getOrganisationReferences(repositoryEntry); for(OrganisationRef learnResourceManagerOrganisation:learnResourceManagerOrganisations) { @@ -2049,8 +1730,7 @@ public class RepositoryManager { if(StringHelper.containsNonWhitespace(type)) { query.setParameter("resourceType", type); } - List<RepositoryEntry> repoEntries = query.getResultList(); - return repoEntries; + return query.getResultList(); } public List<RepositoryEntryLight> getParticipantRepositoryEntry(IdentityRef identity, int maxResults, RepositoryEntryOrder... orderby) { @@ -2146,8 +1826,7 @@ public class RepositoryManager { if(maxResults > 0) { query.setMaxResults(maxResults); } - List<RepositoryEntry> entries = query.getResultList(); - return entries; + return query.getResultList(); } /** @@ -2252,8 +1931,7 @@ public class RepositoryManager { query.setParameter("identityKeys", ids); } - List<RepositoryEntryMembership> entries = query.getResultList(); - return entries; + return query.getResultList(); } public List<RepositoryEntryMembership> getRepositoryEntryMembership(RepositoryEntryRef re) { @@ -2298,7 +1976,7 @@ public class RepositoryManager { } } - return new ArrayList<RepositoryEntryMembership>(memberships.values()); + return new ArrayList<>(memberships.values()); } public List<RepositoryEntryMembership> getOwnersMembership(List<RepositoryEntry> res) { @@ -2313,8 +1991,7 @@ public class RepositoryManager { .createQuery(sb.toString(), RepositoryEntryMembership.class) .setParameter("repoKey", repoKeys); - List<RepositoryEntryMembership> entries = query.getResultList(); - return entries; + return query.getResultList(); } public void updateRepositoryEntryMemberships(Identity ureqIdentity, Roles ureqRoles, RepositoryEntry re, diff --git a/src/main/java/org/olat/repository/RepositoryService.java b/src/main/java/org/olat/repository/RepositoryService.java index 48f3df6e195..4aabf9709d5 100644 --- a/src/main/java/org/olat/repository/RepositoryService.java +++ b/src/main/java/org/olat/repository/RepositoryService.java @@ -183,7 +183,9 @@ public interface RepositoryService { public int countMembers(RepositoryEntryRef re, String... roles); /** - * Count all members (following up to business groups wainting list) + * Count all members (following up to business groups waiting list) with the following + * roles: owner, coach, participant, waiting + * * @param res * @param excludeMe Exclude to user which call the method (optional) * @return @@ -250,7 +252,7 @@ public interface RepositoryService { /** * Get the role in the specified resource, business group are included in - * the query. + * the query but not organizations. * * @return The list of roles */ diff --git a/src/main/java/org/olat/repository/controllers/RepositorySearchController.java b/src/main/java/org/olat/repository/controllers/RepositorySearchController.java index e17cad77190..32485762183 100644 --- a/src/main/java/org/olat/repository/controllers/RepositorySearchController.java +++ b/src/main/java/org/olat/repository/controllers/RepositorySearchController.java @@ -101,6 +101,9 @@ public class RepositorySearchController extends BasicController implements Activ private Link loginLink; private SearchType searchType; private RepositoryEntryFilter filter; + + @Autowired + private RepositoryManager repositoryManager; @Autowired private RepositoryService repositoryService; @@ -163,7 +166,7 @@ public class RepositorySearchController extends BasicController implements Activ if(RepositoryEntry.class.getSimpleName().equals(subType)) { //activate details Long resId = entries.get(0).getOLATResourceable().getResourceableId(); - selectedEntry = RepositoryManager.getInstance().lookupRepositoryEntry(resId); + selectedEntry = repositoryManager.lookupRepositoryEntry(resId); fireEvent(ureq, new Event(RepositoryTableModel.TABLE_ACTION_SELECT_LINK)); } } @@ -209,18 +212,13 @@ public class RepositorySearchController extends BasicController implements Activ * @param ureq */ private void doSearch(UserRequest ureq, String limitType, boolean updateFilters) { - doSearch(ureq, limitType, false, updateFilters); - } - - private void doSearch(UserRequest ureq, String limitType, boolean onlyOwner, boolean updateFilters) { searchType = SearchType.searchForm; - RepositoryManager rm = RepositoryManager.getInstance(); Collection<String> s = searchForm.getRestrictedTypes(); List<String> restrictedTypes; if(limitType != null) { restrictedTypes = Collections.singletonList(limitType); } else { - restrictedTypes = (s == null) ? null : new ArrayList<String>(s); + restrictedTypes = (s == null) ? null : new ArrayList<>(s); } String author = searchForm.getAuthor(); @@ -231,9 +229,8 @@ public class RepositorySearchController extends BasicController implements Activ new SearchRepositoryEntryParameters(displayName, author, description, restrictedTypes, getIdentity(), ureq.getUserSession().getRoles(), getIdentity().getUser().getProperty(UserConstants.INSTITUTIONALNAME, null)); - params.setOnlyOwnedResources(onlyOwner); - List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true); + List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); if(updateFilters) { @@ -250,7 +247,6 @@ public class RepositorySearchController extends BasicController implements Activ */ private void doSearchAllReferencables(UserRequest ureq, String limitType, boolean updateFilters) { searchType = SearchType.searchForm; - RepositoryManager rm = RepositoryManager.getInstance(); List<String> restrictedTypes; if(limitType != null) { restrictedTypes = Collections.singletonList(limitType); @@ -264,16 +260,8 @@ public class RepositorySearchController extends BasicController implements Activ String author = searchForm.getAuthor(); String desc = searchForm.getDescription(); - List<RepositoryEntry> entries; - if(searchForm.isAdminSearch()) { - entries = rm.queryResourcesLimitType(null, restrictedTypes, name, author, desc, true, false); - } else if(enableSearchforAllInSearchForm == Can.referenceable){ - entries = rm.queryReferencableResourcesLimitType(ident, roles, restrictedTypes, name, author, desc); - } else if(enableSearchforAllInSearchForm == Can.copyable){ - entries = rm.queryCopyableResourcesLimitType(ident, roles, restrictedTypes, name, author, desc); - } else { - entries = new ArrayList<>(); - } + List<RepositoryEntry> entries = repositoryManager.queryResourcesLimitType(ident, roles, restrictedTypes, name, author, desc, + enableSearchforAllInSearchForm == Can.referenceable, enableSearchforAllInSearchForm == Can.copyable); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); if(updateFilters) { @@ -307,15 +295,13 @@ public class RepositorySearchController extends BasicController implements Activ * @param roles The users roles */ public void doSearchForReferencableResourcesLimitType(Identity owner, String[] limitTypes, Roles roles) { - RepositoryManager rm = RepositoryManager.getInstance(); List<String> restrictedTypes = new ArrayList<>(); if(limitTypes == null) { restrictedTypes = null; - } - else { + } else { restrictedTypes.addAll(Arrays.asList(limitTypes)); } - List<RepositoryEntry> entries = rm.queryReferencableResourcesLimitType(owner, roles, restrictedTypes, null, null, null); + List<RepositoryEntry> entries = repositoryManager.queryResourcesLimitType(owner, roles, restrictedTypes, null, null, null, true, false); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); tableCtr.setFilters(null, null); @@ -333,15 +319,13 @@ public class RepositorySearchController extends BasicController implements Activ * @param roles The users roles */ public void doSearchForCopyableResourcesLimitType(Identity owner, String[] limitTypes, Roles roles) { - RepositoryManager rm = RepositoryManager.getInstance(); - List<String> restrictedTypes = new ArrayList<String>(); + List<String> restrictedTypes = new ArrayList<>(); if(limitTypes == null) { restrictedTypes = null; - } - else { + } else { restrictedTypes.addAll(Arrays.asList(limitTypes)); } - List<RepositoryEntry> entries = rm.queryCopyableResourcesLimitType(owner, roles, restrictedTypes, null, null, null); + List<RepositoryEntry> entries = repositoryManager.queryResourcesLimitType(owner, roles, restrictedTypes, null, null, null, false, true); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); tableCtr.setFilters(null, null); @@ -369,8 +353,7 @@ public class RepositorySearchController extends BasicController implements Activ private void doSearchByOwnerLimitTypeInternal(Identity owner, String[] limitTypes, boolean updateFilters) { searchType = SearchType.byOwner; - RepositoryManager rm = RepositoryManager.getInstance(); - List<RepositoryEntry> entries = rm.queryByOwner(owner, limitTypes); + List<RepositoryEntry> entries = repositoryManager.queryByOwner(owner, limitTypes); filterRepositoryEntries(entries); if(updateFilters) { updateFilters(entries, owner); @@ -386,8 +369,7 @@ public class RepositorySearchController extends BasicController implements Activ * @param access */ public void doSearchByOwnerLimitAccess(Identity owner) { - RepositoryManager rm = RepositoryManager.getInstance(); - List<RepositoryEntry> entries = rm.queryByOwnerLimitAccess(owner, RepositoryEntry.ACC_USERS, Boolean.TRUE); + List<RepositoryEntry> entries = repositoryManager.queryByOwnerLimitAccess(owner, RepositoryEntry.ACC_USERS, Boolean.TRUE); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); tableCtr.setFilters(null, null); @@ -403,10 +385,9 @@ public class RepositorySearchController extends BasicController implements Activ */ public void doSearchByTypeLimitAccess(String[] restrictedTypes, UserRequest ureq) { searchType = null; - RepositoryManager rm = RepositoryManager.getInstance(); - List<String> types = Arrays.asList(restrictedTypes); - List<RepositoryEntry> entries = rm.queryByTypeLimitAccess(ureq.getIdentity(), ureq.getUserSession().getRoles(), types); + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles(), restrictedTypes); + List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false); filterRepositoryEntries(entries); repoTableModel.setObjects(entries); tableCtr.setFilters(null, null); @@ -436,8 +417,7 @@ public class RepositorySearchController extends BasicController implements Activ private void doSearchMyCoursesStudent(UserRequest ureq, String limitType, boolean updateFilters) { searchType = SearchType.myAsStudent; - RepositoryManager rm = RepositoryManager.getInstance(); - List<RepositoryEntry> entries = rm.getLearningResourcesAsStudent(ureq.getIdentity(), null, 0, -1); + List<RepositoryEntry> entries = repositoryManager.getLearningResourcesAsStudent(ureq.getIdentity(), null, 0, -1); filterRepositoryEntries(entries); doSearchMyRepositoryEntries(ureq, entries, limitType, updateFilters); } @@ -448,8 +428,7 @@ public class RepositorySearchController extends BasicController implements Activ private void doSearchMyCoursesTeacher(UserRequest ureq, String limitType, boolean updateFilters) { searchType = SearchType.myAsTeacher; - RepositoryManager rm = RepositoryManager.getInstance(); - List<RepositoryEntry> entries = rm.getLearningResourcesAsTeacher(ureq.getIdentity(), 0, -1); + List<RepositoryEntry> entries = repositoryManager.getLearningResourcesAsTeacher(ureq.getIdentity(), 0, -1); filterRepositoryEntries(entries); doSearchMyRepositoryEntries(ureq, entries, limitType, updateFilters); } diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java index 97f54c08ecd..d4bdb64a865 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java @@ -22,18 +22,17 @@ package org.olat.repository.manager; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import javax.persistence.TypedQuery; import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.IdentityImpl; import org.olat.basesecurity.IdentityRef; +import org.olat.basesecurity.OrganisationRoles; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.PersistenceHelper; import org.olat.core.commons.services.mark.impl.MarkImpl; import org.olat.core.id.Identity; -import org.olat.core.id.OrganisationRef; import org.olat.core.id.Roles; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -120,11 +119,8 @@ public class RepositoryEntryAuthorQueries { Class<T> type) { IdentityRef identity = params.getIdentity(); - Roles roles = params.getRoles(); List<String> resourceTypes = params.getResourceTypes(); boolean oracle = "oracle".equals(dbInstance.getDbVendor()); - boolean admin = (roles != null && (roles.isLearnResourceManager() || roles.isOLATAdmin())); - boolean learnResourceOrgs = false; boolean count = Number.class.equals(type); boolean needIdentity = false; @@ -161,40 +157,8 @@ public class RepositoryEntryAuthorQueries { } sb.append(" where"); - if(params.isOwnedResourcesOnly()) { - needIdentity = true; - sb.append(" v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership") - .append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey") - .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") - .append(" )"); - if(params.isDeleted()) { - sb.append(" and v.access=").append(RepositoryEntry.DELETED); - } else { - sb.append(" and v.access>=").append(RepositoryEntry.ACC_OWNERS); - } - } else if(admin) { - if(params.isDeleted()) { - sb.append(" v.access=").append(RepositoryEntry.DELETED); - } else { - sb.append(" v.access>=").append(RepositoryEntry.ACC_OWNERS); - } - - if(params.getLearnResourceManagerOrganisations() != null && !params.getLearnResourceManagerOrganisations().isEmpty()) { - sb.append(" and v.key in (select relToOrg.entry.key from repoentrytoorganisation as relToOrg") - .append(" where relToOrg.organisation.key in (:learnResourceManagerOrganisationKeys)") - .append(")"); - learnResourceOrgs = true; - } - } else { - needIdentity = true; - sb.append(" (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS) - .append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS) - .append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership") - .append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey") - .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") - .append(" )") - .append(" ))"); - } + + needIdentity |= appendAccessSubSelect(sb, params); if(params.getClosed() != null) { if(params.getClosed().booleanValue()) { @@ -212,7 +176,7 @@ public class RepositoryEntryAuthorQueries { sb.append(" exists (select ref.key from references as ref where ref.target.key=res.key)"); } - if(params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) { + if(params.getRepoEntryKeys() != null && !params.getRepoEntryKeys().isEmpty()) { sb.append(" and v.key in (:repoEntryKeys)"); } @@ -312,7 +276,7 @@ public class RepositoryEntryAuthorQueries { TypedQuery<T> dbQuery = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), type); - if(params.getRepoEntryKeys() != null && params.getRepoEntryKeys().size() > 0) { + if(params.getRepoEntryKeys() != null && !params.getRepoEntryKeys().isEmpty()) { dbQuery.setParameter("repoEntryKeys", params.getRepoEntryKeys()); } if (params.isResourceTypesDefined()) { @@ -346,12 +310,6 @@ public class RepositoryEntryAuthorQueries { if (StringHelper.containsNonWhitespace(desc)) { dbQuery.setParameter("desc", desc); } - if(learnResourceOrgs && params.getLearnResourceManagerOrganisations() != null && !params.getLearnResourceManagerOrganisations().isEmpty()) { - List<Long> learnResourceManagerOrganisationKeys = params.getLearnResourceManagerOrganisations() - .stream().map(OrganisationRef::getKey).collect(Collectors.toList()); - dbQuery.setParameter("learnResourceManagerOrganisationKeys", learnResourceManagerOrganisationKeys); - } - if(needIdentity) { dbQuery.setParameter("identityKey", identity.getKey()); } @@ -361,6 +319,52 @@ public class RepositoryEntryAuthorQueries { return dbQuery; } + private boolean appendAccessSubSelect(StringBuilder sb, SearchAuthorRepositoryEntryViewParams params) { + if(params.isOwnedResourcesOnly()) { + sb.append(" v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership") + .append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey") + .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") + .append(" )"); + if(params.isDeleted()) { + sb.append(" and v.access=").append(RepositoryEntry.DELETED); + } else { + sb.append(" and v.access>=").append(RepositoryEntry.ACC_OWNERS); + } + return true; + } + + Roles roles = params.getRoles(); + if(roles != null && roles.isOLATAdmin()) { + if(params.isDeleted()) { + sb.append(" v.access=").append(RepositoryEntry.DELETED); + } else { + sb.append(" v.access>=").append(RepositoryEntry.ACC_OWNERS); + } + return false; + } + + if(roles != null && (roles.isAuthor() || roles.isLearnResourceManager())) { + //TODO roles (author permissions) + sb.append(" (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS) + .append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS) + .append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership") + .append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey") + .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("','").append(OrganisationRoles.learnresourcemanager).append("')") + .append(" )") + .append(" ))"); + + } else { + sb.append(" (v.access>=").append(RepositoryEntry.ACC_USERS) + .append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS) + .append(" and v.key in (select rel.entry.key from repoentrytogroup as rel, bgroupmember as membership") + .append(" where rel.group.key=membership.group.key and membership.identity.key=:identityKey") + .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("')") + .append(" )") + .append(" ))"); + } + return true; + } + private void appendAuthorViewOrderBy(SearchAuthorRepositoryEntryViewParams params, StringBuilder sb) { OrderBy orderBy = params.getOrderBy(); boolean asc = params.isOrderByAsc(); diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java new file mode 100644 index 00000000000..fbd487d1958 --- /dev/null +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java @@ -0,0 +1,221 @@ +package org.olat.repository.manager; + +import java.util.List; + +import javax.persistence.TypedQuery; + +import org.olat.basesecurity.GroupRoles; +import org.olat.basesecurity.IdentityImpl; +import org.olat.basesecurity.OrganisationRoles; +import org.olat.core.commons.persistence.DB; +import org.olat.core.commons.persistence.PersistenceHelper; +import org.olat.core.id.Roles; +import org.olat.core.util.StringHelper; +import org.olat.repository.CatalogEntry; +import org.olat.repository.RepositoryEntry; +import org.olat.repository.model.SearchRepositoryEntryParameters; +import org.olat.user.UserImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * + * Initial date: 3 mai 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +@Service +public class RepositoryEntryQueries { + + @Autowired + private DB dbInstance; + + public int countEntries(SearchRepositoryEntryParameters params) { + TypedQuery<Number> dbQuery = createQuery(params, false, Number.class); + Number count = dbQuery.getSingleResult(); + return count.intValue(); + } + + public List<RepositoryEntry> searchEntries(SearchRepositoryEntryParameters params, int firstResult, int maxResults, boolean orderBy) { + TypedQuery<RepositoryEntry> dbQuery = createQuery(params, orderBy, RepositoryEntry.class); + dbQuery.setFirstResult(firstResult); + if(maxResults > 0) { + dbQuery.setMaxResults(maxResults); + } + return dbQuery.getResultList(); + } + + private <T> TypedQuery<T> createQuery(SearchRepositoryEntryParameters params, boolean orderBy, Class<T> type) { + String author = params.getAuthor(); + String displayName = params.getDisplayName(); + List<String> resourceTypes = params.getResourceTypes(); + + StringBuilder query = new StringBuilder(2048); + if(Number.class.equals(type)) { + query.append("select count(v.key) from repositoryentry v "); + query.append(" inner join v.olatResource as res"); + } else if(params.getParentEntry() != null) { + query.append("select v from ").append(CatalogEntry.class.getName()).append(" cei ") + .append(" inner join cei.parent parentCei") + .append(" inner join cei.repositoryEntry v") + .append(" inner join fetch v.olatResource as res") + .append(" inner join fetch v.statistics as statistics") + .append(" left join fetch v.lifecycle as lifecycle"); + } else { + query.append("select distinct v from repositoryentry v ") + .append(" inner join fetch v.olatResource as res") + .append(" inner join fetch v.statistics as statistics") + .append(" left join fetch v.lifecycle as lifecycle"); + } + + boolean setIdentity = appendAccessSubSelects(query, params.getRoles(), params.isOnlyExplicitMember()); + + if(params.getParentEntry() != null) { + query.append(" and parentCei.key=:parentCeiKey"); + } + + if (StringHelper.containsNonWhitespace(author)) { + // fuzzy author search + author = PersistenceHelper.makeFuzzyQueryString(author); + query.append(" and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership, ") + .append(IdentityImpl.class.getName()).append(" as identity, ").append(UserImpl.class.getName()).append(" as user") + .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=identity.key and user.identity.key=identity.key") + .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") + .append(" and ("); + PersistenceHelper.appendFuzzyLike(query, "user.firstName", "author", dbInstance.getDbVendor()); + query.append(" or "); + PersistenceHelper.appendFuzzyLike(query, "user.lastName", "author", dbInstance.getDbVendor()); + query.append(" or "); + PersistenceHelper.appendFuzzyLike(query, "identity.name", "author", dbInstance.getDbVendor()); + query.append(" ))"); + } + + if (StringHelper.containsNonWhitespace(displayName)) { + displayName = PersistenceHelper.makeFuzzyQueryString(displayName); + query.append(" and "); + PersistenceHelper.appendFuzzyLike(query, "v.displayname", "displayname", dbInstance.getDbVendor()); + } + + String desc = null; + if (StringHelper.containsNonWhitespace(params.getDesc())) { + desc = PersistenceHelper.makeFuzzyQueryString(params.getDesc()); + query.append(" and "); + PersistenceHelper.appendFuzzyLike(query, "v.description", "desc", dbInstance.getDbVendor()); + } + + if (resourceTypes != null && resourceTypes.size() > 0) { + query.append(" and res.resName in (:resourcetypes)"); + } + + if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { + query.append(" and v.key in (:entryKeys)"); + } + + if(params.getManaged() != null) { + if(params.getManaged().booleanValue()) { + query.append(" and v.managedFlagsString is not null"); + } else { + query.append(" and v.managedFlagsString is null"); + } + } + + if(StringHelper.containsNonWhitespace(params.getExternalId())) { + query.append(" and v.externalId=:externalId"); + } + + if(StringHelper.containsNonWhitespace(params.getExternalRef())) { + query.append(" and v.externalRef=:externalRef"); + } + + if(orderBy) { + query.append(" order by v.displayname, v.key ASC"); + } + + TypedQuery<T> dbQuery = dbInstance.getCurrentEntityManager() + .createQuery(query.toString(), type); + if(params.getParentEntry() != null) { + dbQuery.setParameter("parentCeiKey", params.getParentEntry().getKey()); + } + if (StringHelper.containsNonWhitespace(author)) { + dbQuery.setParameter("author", author); + } + if (StringHelper.containsNonWhitespace(displayName)) { + dbQuery.setParameter("displayname", displayName); + } + if (StringHelper.containsNonWhitespace(desc)) { + dbQuery.setParameter("desc", desc); + } + if (resourceTypes != null && !resourceTypes.isEmpty()) { + dbQuery.setParameter("resourcetypes", resourceTypes); + } + if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { + dbQuery.setParameter("entryKeys", params.getRepositoryEntryKeys()); + } + if(StringHelper.containsNonWhitespace(params.getExternalId())) { + dbQuery.setParameter("externalId", params.getExternalId()); + } + if(StringHelper.containsNonWhitespace(params.getExternalRef())) { + dbQuery.setParameter("externalRef", params.getExternalRef()); + } + if(setIdentity) { + dbQuery.setParameter("identityKey", params.getIdentity().getKey()); + } + return dbQuery; + } + + /** + * This query need the repository entry as v, v.olatResource as res + * and v.baseGroup as baseGroup + * @param sb + * @param identity + * @param roles + * @return + */ + private boolean appendAccessSubSelects(StringBuilder sb, Roles roles, boolean onlyExplicitMember) { + if(roles.isOLATAdmin()) { + sb.append(" where v.access>=").append(RepositoryEntry.ACC_OWNERS); + return false; + } + if(roles.isGuestOnly()) { + sb.append(" where v.access>=").append(RepositoryEntry.ACC_USERS_GUESTS); + return false; + } + + // no by-pass -> join the memberships + sb.append(" inner join v.groups as relGroup") + .append(" inner join relGroup.group as baseGroup") + .append(" inner join baseGroup.members as membership") + .append(" where membership.identity.key=:identityKey and"); + + if(onlyExplicitMember) { + sb.append(" (v.access>=").append(RepositoryEntry.ACC_USERS) + .append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true") + .append(" and membership.role in ('").append(GroupRoles.owner.name()).append("','").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("')") + .append(" ))"); + return true; + } + + //access rules as user + sb.append("(v.access>=").append(RepositoryEntry.ACC_USERS); + if(roles.isLearnResourceManager()) { + // as learn resource manager + sb.append(" or (v.access>=").append(RepositoryEntry.ACC_OWNERS) + .append(" and membership.role='").append(OrganisationRoles.learnresourcemanager.name()).append("')"); + } + + if(roles.isAuthor()) { + // as author + sb.append(" or (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS) + .append(" and membership.role='").append(OrganisationRoles.author.name()).append("')"); + } + // as owner + sb.append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS) + .append(" and membership.role='").append(GroupRoles.owner.name()).append("')"); + // as member + sb.append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS).append(" and v.membersOnly=true") + .append(" and membership.role in ('").append(GroupRoles.coach.name()).append("','").append(GroupRoles.participant.name()).append("'))") + .append(")"); + + return true; + } +} diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryRelationDAO.java b/src/main/java/org/olat/repository/manager/RepositoryEntryRelationDAO.java index 2dbf071425b..aed0e0d03d0 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryRelationDAO.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryRelationDAO.java @@ -61,10 +61,12 @@ public class RepositoryEntryRelationDAO { private GroupDAO groupDao; /** - * Get roles in the repository entry, with business groups too - * @param identity - * @param re - * @return + * Get roles in the repository entry, with business groups too but + * not the organizations. + * + * @param identity The identity + * @param re The repository entry + * @return The list of roles */ public List<String> getRoles(IdentityRef identity, RepositoryEntryRef re) { StringBuilder sb = new StringBuilder(); @@ -72,7 +74,8 @@ public class RepositoryEntryRelationDAO { .append(" inner join v.groups as relGroup") .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as membership") - .append(" where v.key=:repoKey and membership.identity.key=:identityKey"); + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key=:repoKey and membership.identity.key=:identityKey and (relGroup.defaultGroup=true or businessGroup.key is not null)"); return dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), String.class) @@ -113,7 +116,7 @@ public class RepositoryEntryRelationDAO { .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as membership") .append(" where v.key=:repoKey and membership.identity.key=:identityKey"); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { sb.append(" and membership.role in (:roles)"); } @@ -121,7 +124,7 @@ public class RepositoryEntryRelationDAO { .createQuery(sb.toString(), Number.class) .setParameter("identityKey", identity.getKey()) .setParameter("repoKey", re.getKey()); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { query.setParameter("roles", roleList); } @@ -150,7 +153,7 @@ public class RepositoryEntryRelationDAO { sb.append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as membership") .append(" where membership.identity.key=:identityKey"); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { sb.append(" and membership.role in (:roles)"); } @@ -159,7 +162,7 @@ public class RepositoryEntryRelationDAO { .setFirstResult(0) .setMaxResults(1) .setParameter("identityKey", identity.getKey()); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { query.setParameter("roles", roleList); } @@ -263,9 +266,11 @@ public class RepositoryEntryRelationDAO { } /** - * It will count all members, business groups members too - * @param re - * @param roles + * It will count all members, business groups members too but not + * the organizations. + * + * @param re The repository entry + * @param roles The roles (optional) * @return */ public int countMembers(RepositoryEntryRef re, String... roles) { @@ -276,15 +281,16 @@ public class RepositoryEntryRelationDAO { .append(" inner join v.groups as relGroup") .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as members") - .append(" where v.key=:repoKey"); - if(roleList.size() > 0) { + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key=:repoKey and (relGroup.defaultGroup=true or businessGroup.key is not null)"); + if(!roleList.isEmpty()) { sb.append(" and members.role in (:roles)"); } TypedQuery<Number> query = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Number.class) .setParameter("repoKey", re.getKey()); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { query.setParameter("roles", roleList); } @@ -301,11 +307,12 @@ public class RepositoryEntryRelationDAO { } StringBuilder sb = new StringBuilder(); - sb.append("select count(distinct members.identity.key) from ").append(RepositoryEntry.class.getName()).append(" as v") + sb.append("select count(distinct members.identity.key) from repositoryentry as v") .append(" inner join v.groups as relGroup") .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as members") - .append(" where v.key in (:repoKeys)"); + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key in (:repoKeys) and (relGroup.defaultGroup=true or businessGroup.key is not null)"); if(excludeMe != null) { sb.append(" and not(members.identity.key=:identityKey)"); } @@ -353,8 +360,9 @@ public class RepositoryEntryRelationDAO { .append(" inner join v.groups as relGroup") .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as members") - .append(" where v.key=:repoKey and members.identity.key=:identityKey"); - if(roleList != null && roleList.size() > 0) { + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key=:repoKey and (relGroup.defaultGroup=true or businessGroup.key is not null) and members.identity.key=:identityKey"); + if(roleList != null && !roleList.isEmpty()) { sb.append(" and members.role in (:roles)"); } @@ -362,7 +370,7 @@ public class RepositoryEntryRelationDAO { .createQuery(sb.toString(), Date.class) .setParameter("repoKey", re.getKey()) .setParameter("identityKey", identity.getKey()); - if(roleList != null && roleList.size() > 0) { + if(roleList != null && !roleList.isEmpty()) { datesQuery.setParameter("roles", roleList); } @@ -386,8 +394,9 @@ public class RepositoryEntryRelationDAO { .append(" inner join v.groups as relGroup") .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as members") - .append(" where v.key=:repoKey"); - if(roleList != null && roleList.size() > 0) { + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key=:repoKey and (relGroup.defaultGroup=true or businessGroup.key is not null)"); + if(roleList != null && !roleList.isEmpty()) { sb.append(" and members.role in (:roles)"); } sb.append(" group by members.identity.key"); @@ -395,7 +404,7 @@ public class RepositoryEntryRelationDAO { TypedQuery<Object[]> datesQuery = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Object[].class) .setParameter("repoKey", re.getKey()); - if(roleList != null && roleList.size() > 0) { + if(roleList != null && !roleList.isEmpty()) { datesQuery.setParameter("roles", roleList); } @@ -431,6 +440,15 @@ public class RepositoryEntryRelationDAO { return getMembers(Collections.singletonList(re), type, roles); } + /** + * The query is limited to the default group and the business group (as specified by + * the type parameter). + * + * @param res The list repository entry references + * @param type The type of relation (only default group, only busines groups or both) + * @param roles The roles (optional) + * @return A list of identity + */ public List<Identity> getMembers(List<? extends RepositoryEntryRef> res, RepositoryEntryRelationType type, String... roles) { if(res == null || res.isEmpty()) return Collections.emptyList(); @@ -444,27 +462,37 @@ public class RepositoryEntryRelationDAO { } StringBuilder sb = new StringBuilder(); - sb.append("select ident from ").append(RepositoryEntry.class.getName()).append(" as v") + sb.append("select ident from repositoryentry as v") .append(" inner join v.groups as relGroup").append(def) .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as memberships") .append(" inner join memberships.identity as ident") .append(" inner join fetch ident.user as identUser") - .append(" where v.key in (:repoKeys)"); - if(roleList.size() > 0) { - sb.append(" and memberships.role in (:roles)"); + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key in (:repoKeys) and (relGroup.defaultGroup=true or businessGroup.key is not null)"); + if(!roleList.isEmpty()) { + sb.append(" and memberships.role in (:roles)"); } - List<Long> repoKeys = res.stream().map(re -> re.getKey()).collect(Collectors.toList()); + List<Long> repoKeys = res.stream().map(RepositoryEntryRef::getKey).collect(Collectors.toList()); TypedQuery<Identity> query = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Identity.class) .setParameter("repoKeys", repoKeys); - if(roleList.size() > 0) { - query.setParameter("roles", roleList); + if(!roleList.isEmpty()) { + query.setParameter("roles", roleList); } return query.getResultList(); } + /** + * The query is limited to the default group and the business group (as specified by + * the type parameter). + * + * @param re The repository entry + * @param type The type of relation (only default group, only busines groups or both) + * @param roles The roles (optional) + * @return A list of identity keys + */ public List<Long> getMemberKeys(RepositoryEntryRef re, RepositoryEntryRelationType type, String... roles) { List<String> roleList = GroupRoles.toList(roles); @@ -476,19 +504,20 @@ public class RepositoryEntryRelationDAO { } StringBuilder sb = new StringBuilder(); - sb.append("select members.identity.key from ").append(RepositoryEntry.class.getName()).append(" as v") + sb.append("select members.identity.key from repositoryentry as v") .append(" inner join v.groups as relGroup").append(def) .append(" inner join relGroup.group as baseGroup") .append(" inner join baseGroup.members as members") - .append(" where v.key=:repoKey"); - if(roleList.size() > 0) { + .append(" left join businessgroup as businessGroup on (businessGroup.baseGroup.key=baseGroup.key)") + .append(" where v.key=:repoKey and (relGroup.defaultGroup=true or businessGroup.key is not null)"); + if(!roleList.isEmpty()) { sb.append(" and members.role in (:roles)"); } TypedQuery<Long> query = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Long.class) .setParameter("repoKey", re.getKey()); - if(roleList.size() > 0) { + if(!roleList.isEmpty()) { query.setParameter("roles", roleList); } return query.getResultList(); diff --git a/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java b/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java index 640e0fa9078..b092eb46b63 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java +++ b/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java @@ -211,9 +211,19 @@ public class RepositoryServiceImpl implements RepositoryService { rel.setDefaultGroup(true); rel.setGroup(group); rel.setEntry(re); - + Set<RepositoryEntryToGroupRelation> rels = new HashSet<>(2); rels.add(rel); + + if(organisation != null) { + RepositoryEntryToGroupRelation relOrg = new RepositoryEntryToGroupRelation(); + relOrg.setCreationDate(new Date()); + relOrg.setDefaultGroup(false); + relOrg.setGroup(organisation.getGroup()); + relOrg.setEntry(re); + rels.add(relOrg); + } + re.setGroups(rels); if(initialAuthor != null) { @@ -546,20 +556,11 @@ public class RepositoryServiceImpl implements RepositoryService { return reToGroupDao.getDefaultGroup(ref); } - /** - * Get the role in the specified resource, business group are included in - * the query. - * - */ @Override public List<String> getRoles(Identity identity, RepositoryEntryRef re) { return reToGroupDao.getRoles(identity, re); } - /** - * Has specific role in the specified resource WITHOUT business groups included in - * the query. - */ @Override public boolean hasRole(Identity identity, RepositoryEntryRef re, String... roles) { return reToGroupDao.hasRole(identity, re, roles); diff --git a/src/main/java/org/olat/repository/model/SearchAuthorRepositoryEntryViewParams.java b/src/main/java/org/olat/repository/model/SearchAuthorRepositoryEntryViewParams.java index c5eb3f32968..5bee8a4b682 100644 --- a/src/main/java/org/olat/repository/model/SearchAuthorRepositoryEntryViewParams.java +++ b/src/main/java/org/olat/repository/model/SearchAuthorRepositoryEntryViewParams.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Set; import org.olat.basesecurity.IdentityRef; -import org.olat.core.id.OrganisationRef; import org.olat.core.id.Roles; /** @@ -43,8 +42,6 @@ public class SearchAuthorRepositoryEntryViewParams { private boolean ownedResourcesOnly; private ResourceUsage resourceUsage = ResourceUsage.all; - private List<OrganisationRef> learnResourceManagerOrganisations; - private String idAndRefs; private String idRefsAndTitle; private String author; @@ -209,14 +206,6 @@ public class SearchAuthorRepositoryEntryViewParams { this.licenseTypeKeys = licenseTypeKeys; } - public List<OrganisationRef> getLearnResourceManagerOrganisations() { - return learnResourceManagerOrganisations; - } - - public void setLearnResourceManagerOrganisations(List<OrganisationRef> learnResourceManagerOrganisations) { - this.learnResourceManagerOrganisations = learnResourceManagerOrganisations; - } - public enum OrderBy { key, favorit, diff --git a/src/main/java/org/olat/repository/model/SearchRepositoryEntryParameters.java b/src/main/java/org/olat/repository/model/SearchRepositoryEntryParameters.java index c1799ba33fa..f47034d55ed 100644 --- a/src/main/java/org/olat/repository/model/SearchRepositoryEntryParameters.java +++ b/src/main/java/org/olat/repository/model/SearchRepositoryEntryParameters.java @@ -42,12 +42,10 @@ public class SearchRepositoryEntryParameters { private List<String> resourceTypes; private Identity identity; private Roles roles; - private Boolean marked; private String institution; private Boolean managed; private String externalId; private String externalRef; - private boolean onlyOwnedResources; private boolean onlyExplicitMember; private List<Long> repositoryEntryKeys; private CatalogEntry parentEntry; @@ -148,7 +146,7 @@ public class SearchRepositoryEntryParameters { public void addResourceTypes(String... types) { if(this.resourceTypes == null) { - this.resourceTypes = new ArrayList<String>(); + this.resourceTypes = new ArrayList<>(); } if(types != null) { for(String resourceType:types) { @@ -172,14 +170,7 @@ public class SearchRepositoryEntryParameters { public void setRoles(Roles roles) { this.roles = roles; } - - public Boolean getMarked() { - return marked; - } - public void setMarked(Boolean marked) { - this.marked = marked; - } public String getInstitution() { return institution; @@ -189,19 +180,6 @@ public class SearchRepositoryEntryParameters { this.institution = institution; } - /** - * This has effect for authors. Administrator or instituional mangers - * has more rights. - * @return - */ - public boolean isOnlyOwnedResources() { - return onlyOwnedResources; - } - - public void setOnlyOwnedResources(boolean onlyOwnedResources) { - this.onlyOwnedResources = onlyOwnedResources; - } - public boolean isOnlyExplicitMember() { return onlyExplicitMember; } diff --git a/src/main/java/org/olat/repository/ui/author/AuthorListController.java b/src/main/java/org/olat/repository/ui/author/AuthorListController.java index 5035041cf08..bfb115d81a6 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthorListController.java +++ b/src/main/java/org/olat/repository/ui/author/AuthorListController.java @@ -28,8 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.olat.NewControllerFactory; import org.olat.admin.user.UserSearchController; import org.olat.basesecurity.GroupRoles; -import org.olat.basesecurity.OrganisationRoles; -import org.olat.basesecurity.OrganisationService; import org.olat.basesecurity.events.MultiIdentityChosenEvent; import org.olat.basesecurity.events.SingleIdentityChosenEvent; import org.olat.core.commons.persistence.DB; @@ -83,8 +81,6 @@ import org.olat.core.gui.media.MediaResource; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; -import org.olat.core.id.Organisation; -import org.olat.core.id.OrganisationRef; import org.olat.core.id.Roles; import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.StateEntry; @@ -181,8 +177,6 @@ public class AuthorListController extends FormBasicController implements Activat @Autowired protected RepositoryHandlerFactory repositoryHandlerFactory; @Autowired - private OrganisationService organisationService; - @Autowired private LicenseModule licenseModule; @Autowired private RepositoryEntryLicenseHandler licenseHandler; @@ -204,16 +198,6 @@ public class AuthorListController extends FormBasicController implements Activat boolean learnResourceManager = roles.isLearnResourceManager(); isOlatAdmin = roles.isOLATAdmin() || learnResourceManager; hasAuthorRight = roles.isAuthor() || learnResourceManager || roles.isOLATAdmin(); - if(!roles.isOLATAdmin()) { - if(learnResourceManager) { - List<Organisation> orgs = organisationService - .getManageableOrganisations(getIdentity(), roles, OrganisationRoles.learnresourcemanager); - searchParams.setLearnResourceManagerOrganisations(new ArrayList<OrganisationRef>(orgs)); - } - if(roles.isAuthor()) { - - } - } dataSource = new AuthoringEntryDataSource(searchParams, this, !withSearch); initForm(ureq); @@ -1235,7 +1219,7 @@ public class AuthorListController extends FormBasicController implements Activat && repositoryManager.isInstitutionalRessourceManagerFor(identity, roles, entry); isOwner = isOlatAdmin || repositoryService.hasRole(ureq.getIdentity(), entry, GroupRoles.owner.name()) || isInstitutionalResourceManager; - isAuthor = isOlatAdmin || roles.isAuthor() | isInstitutionalResourceManager; + isAuthor = isOlatAdmin || roles.isAuthor() || isInstitutionalResourceManager; RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(entry); diff --git a/src/main/java/org/olat/repository/ui/author/CreateRepositoryEntryController.java b/src/main/java/org/olat/repository/ui/author/CreateRepositoryEntryController.java index ff9f2f4df32..6f32d49476e 100644 --- a/src/main/java/org/olat/repository/ui/author/CreateRepositoryEntryController.java +++ b/src/main/java/org/olat/repository/ui/author/CreateRepositoryEntryController.java @@ -94,8 +94,9 @@ public class CreateRepositoryEntryController extends FormBasicController impleme super(ureq, wControl); setTranslator(Util.createPackageTranslator(RepositoryManager.class, getLocale(), getTranslator())); this.handler = handler; - manageableOrganisations = organisationService - .getManageableOrganisations(getIdentity(), ureq.getUserSession().getRoles(), OrganisationRoles.learnresourcemanager); + + manageableOrganisations = organisationService.getOrganisations(getIdentity(), ureq.getUserSession().getRoles(), + OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); initForm(ureq); } diff --git a/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java b/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java index 3ff88835145..1dc9f8761bd 100644 --- a/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java +++ b/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java @@ -91,8 +91,8 @@ public class ImportRepositoryEntryController extends FormBasicController { public ImportRepositoryEntryController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl); setTranslator(Util.createPackageTranslator(RepositoryManager.class, getLocale(), getTranslator())); - manageableOrganisations = organisationService - .getManageableOrganisations(getIdentity(), ureq.getUserSession().getRoles(), OrganisationRoles.learnresourcemanager); + manageableOrganisations = organisationService.getOrganisations(getIdentity(), ureq.getUserSession().getRoles(), + OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); initForm(ureq); } @@ -101,8 +101,8 @@ public class ImportRepositoryEntryController extends FormBasicController { super(ureq, wControl); setTranslator(Util.createPackageTranslator(RepositoryManager.class, getLocale(), getTranslator())); this.limitTypes = limitTypes; - manageableOrganisations = organisationService - .getManageableOrganisations(getIdentity(), ureq.getUserSession().getRoles(), OrganisationRoles.learnresourcemanager); + manageableOrganisations = organisationService.getOrganisations(getIdentity(), ureq.getUserSession().getRoles(), + OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); initForm(ureq); } diff --git a/src/main/java/org/olat/repository/ui/author/RepositoryEditDescriptionController.java b/src/main/java/org/olat/repository/ui/author/RepositoryEditDescriptionController.java index f5ba4801676..6df19cd6cfc 100644 --- a/src/main/java/org/olat/repository/ui/author/RepositoryEditDescriptionController.java +++ b/src/main/java/org/olat/repository/ui/author/RepositoryEditDescriptionController.java @@ -420,14 +420,9 @@ public class RepositoryEditDescriptionController extends FormBasicController { } protected void initFormOrganisations(FormItemContainer formLayout, UserRequest ureq) { - List<Organisation> organisations; Roles roles = ureq.getUserSession().getRoles(); - if(roles.isOLATAdmin()) { - organisations = organisationService.getOrganisations(); - } else { - organisations = organisationService - .getManageableOrganisations(getIdentity(), roles, OrganisationRoles.learnresourcemanager); - } + List<Organisation> organisations = organisationService.getOrganisations(getIdentity(), roles, + OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); List<String> keyList = new ArrayList<>(); List<String> valueList = new ArrayList<>(); diff --git a/src/main/java/org/olat/restapi/repository/course/CoursesInfosWebService.java b/src/main/java/org/olat/restapi/repository/course/CoursesInfosWebService.java index 63dac84fddf..d4382e9a928 100644 --- a/src/main/java/org/olat/restapi/repository/course/CoursesInfosWebService.java +++ b/src/main/java/org/olat/restapi/repository/course/CoursesInfosWebService.java @@ -112,10 +112,10 @@ public class CoursesInfosWebService { if(MediaTypeVariants.isPaged(httpRequest, request)) { int totalCount = rm.countGenericANDQueryWithRolesRestriction(params); List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true); - List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>(); + List<CourseInfoVO> infos = new ArrayList<>(); - final Set<Long> forumNotified = new HashSet<Long>(); - final Map<Long,Set<String>> courseNotified = new HashMap<Long,Set<String>>(); + final Set<Long> forumNotified = new HashSet<>(); + final Map<Long,Set<String>> courseNotified = new HashMap<>(); collectSubscriptions(identity, forumNotified, courseNotified); for(RepositoryEntry entry:repoEntries) { diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java index 8535c0de3e0..0778cda3174 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java @@ -21,6 +21,7 @@ package org.olat.upgrade; import java.util.List; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.IdentityImpl; import org.olat.basesecurity.NamedGroupImpl; import org.olat.basesecurity.OrganisationRoles; @@ -124,7 +125,7 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { List<Long> identitiyKeys = getIdentityInSecurityGroup(secGroupName); for(int i=0; i<identitiyKeys.size(); i++) { Identity member = dbInstance.getCurrentEntityManager().getReference(IdentityImpl.class, identitiyKeys.get(i)); - organisationService.addMember(organisation, member, role); + organisationService.addMember(organisation, member, role, GroupMembershipInheritance.none); if(i % 20 == 0) { dbInstance.commitAndCloseSession(); } diff --git a/src/main/java/org/olat/user/ProfileFormController.java b/src/main/java/org/olat/user/ProfileFormController.java index 142f0994ba1..6f7fdd2404a 100644 --- a/src/main/java/org/olat/user/ProfileFormController.java +++ b/src/main/java/org/olat/user/ProfileFormController.java @@ -339,7 +339,7 @@ public class ProfileFormController extends FormBasicController { @Override protected boolean validateFormLogic(UserRequest ureq) { - boolean allOk = true; + boolean allOk = super.validateFormLogic(ureq); formContext.put("username", identityToModify.getName()); User user = identityToModify.getUser(); @@ -363,7 +363,7 @@ public class ProfileFormController extends FormBasicController { textAboutMe.setErrorKey("input.toolong", new String[] {"10000"}); allOk = false; } - return allOk & super.validateFormLogic(ureq); + return allOk; } @Override @@ -620,7 +620,7 @@ public class ProfileFormController extends FormBasicController { boolean isUserManagerAndBypassVerification = false; if(!isOLATAdmin && usess.getRoles().isUserManager() && BaseSecurityModule.USERMANAGER_CAN_BYPASS_EMAILVERIFICATION.booleanValue()) { //check if the user manager is allowed to manage this user - List<Organisation> organisations = organisationService.getManageableOrganisations(getIdentity(), usess.getRoles(), OrganisationRoles.usermanager); + List<Organisation> organisations = organisationService.getOrganisations(getIdentity(), usess.getRoles(), OrganisationRoles.usermanager); organisations.retainAll(identityOrganisations); isUserManagerAndBypassVerification = !organisations.isEmpty(); } diff --git a/src/main/java/org/olat/user/ui/admin/UserAdminMainController.java b/src/main/java/org/olat/user/ui/admin/UserAdminMainController.java index 50f92e6f837..b8f5340fe18 100644 --- a/src/main/java/org/olat/user/ui/admin/UserAdminMainController.java +++ b/src/main/java/org/olat/user/ui/admin/UserAdminMainController.java @@ -133,13 +133,10 @@ public class UserAdminMainController extends MainLayoutBasicController implement UserSession usess = ureq.getUserSession(); isOlatAdmin = usess.getRoles().isOLATAdmin(); - if(isOlatAdmin) { - manageableOrganisations = organisationService.getOrganisations(); - } else { - manageableOrganisations = organisationService - .getManageableOrganisations(getIdentity(), usess.getRoles(), OrganisationRoles.usermanager); - } - + + manageableOrganisations = organisationService.getOrganisations(getIdentity(), usess.getRoles(), + OrganisationRoles.administrator, OrganisationRoles.usermanager); + menuTree = new MenuTree("olatMenuTree"); menuTree.setExpandSelectedNode(false); menuTree.setScrollTopOnClick(true); diff --git a/src/main/java/org/olat/user/ui/organisation/OrganisationUserManagementController.java b/src/main/java/org/olat/user/ui/organisation/OrganisationUserManagementController.java index 3693a98f18b..9efce4dc474 100644 --- a/src/main/java/org/olat/user/ui/organisation/OrganisationUserManagementController.java +++ b/src/main/java/org/olat/user/ui/organisation/OrganisationUserManagementController.java @@ -27,6 +27,7 @@ import java.util.Set; import org.olat.admin.user.UserSearchController; import org.olat.admin.user.UserTableDataModel; import org.olat.basesecurity.BaseSecurityModule; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.OrganisationManagedFlag; import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; @@ -270,8 +271,12 @@ public class OrganisationUserManagementController extends FormBasicController { } private void doAddMember(List<Identity> identitiesToAdd, OrganisationRoles role) { + GroupMembershipInheritance inheritenceMode = GroupMembershipInheritance.none; + if(role == OrganisationRoles.learnresourcemanager || role == OrganisationRoles.usermanager) { + inheritenceMode = GroupMembershipInheritance.root; + } for(Identity identityToAdd:identitiesToAdd) { - organisationService.addMember(organisation, identityToAdd, role); + organisationService.addMember(organisation, identityToAdd, role, inheritenceMode); } loadModel(true); } diff --git a/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql index 9b843c995cf..eb3c86ea959 100644 --- a/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql @@ -185,3 +185,9 @@ create unique index idx_eva_part_executor_idx on o_eva_form_participation (fk_ex alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); + +-- membership +alter table o_bs_group_member add column g_inheritance_mode varchar(16) default 'none' not null; + + + diff --git a/src/main/resources/database/mysql/setupDatabase.sql b/src/main/resources/database/mysql/setupDatabase.sql index 61aede16563..da77336f55f 100644 --- a/src/main/resources/database/mysql/setupDatabase.sql +++ b/src/main/resources/database/mysql/setupDatabase.sql @@ -1,3445 +1,3435 @@ -SET FOREIGN_KEY_CHECKS = 0; - -create table if not exists o_forum ( - forum_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - primary key (forum_id) -); -create table o_forum_pseudonym ( - id bigint not null auto_increment, - creationdate datetime not null, - p_pseudonym varchar(255) not null, - p_credential varchar(255) not null, - p_salt varchar(255) not null, - p_hashalgorithm varchar(16) not null, - primary key (id) -); -create table if not exists o_property ( - id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - identity bigint, - grp bigint, - resourcetypename varchar(50), - resourcetypeid bigint, - category varchar(33), - name varchar(255) not null, - floatvalue FLOAT(65,30), - longvalue bigint, - stringvalue varchar(255), - textvalue longtext, - primary key (id) -); -create table if not exists o_bs_secgroup ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - primary key (id) -); - -create table o_bs_group ( - id bigint not null, - creationdate datetime not null, - g_name varchar(36), - primary key (id) -); - -create table o_bs_group_member ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_role varchar(50) not null, - fk_group_id bigint not null, - fk_identity_id bigint not null, - primary key (id) -); - -create table o_bs_grant ( - id bigint not null, - creationdate datetime not null, - g_role varchar(32) not null, - g_permission varchar(32) not null, - fk_group_id bigint not null, - fk_resource_id bigint not null, - primary key (id) -); - -create table if not exists o_gp_business ( - group_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - lastusage datetime, - groupname varchar(255), - external_id varchar(64), - managed_flags varchar(255), - descr longtext, - minparticipants integer, - maxparticipants integer, - waitinglist_enabled bit, - autocloseranks_enabled bit, - ownersintern bit not null default 0, - participantsintern bit not null default 0, - waitingintern bit not null default 0, - ownerspublic bit not null default 0, - participantspublic bit not null default 0, - waitingpublic bit not null default 0, - downloadmembers bit not null default 0, - allowtoleave bit not null default 1, - fk_resource bigint unique, - fk_group_id bigint unique, - primary key (group_id) -); -create table if not exists o_temporarykey ( - reglist_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - email varchar(255) not null, - regkey varchar(255) not null, - ip varchar(255) not null, - mailsent bit not null, - action varchar(255) not null, - fk_identity_id bigint, - primary key (reglist_id) -); -create table if not exists o_bs_authentication ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - lastmodified datetime not null, - identity_fk bigint not null, - provider varchar(8), - authusername varchar(255), - credential varchar(255), - salt varchar(255) default null, - hashalgorithm varchar(16) default null, - primary key (id), - unique (provider, authusername) -); -create table if not exists o_bs_authentication_history ( - id bigint not null auto_increment, - creationdate datetime, - provider varchar(8), - authusername varchar(255), - credential varchar(255), - salt varchar(255) default null, - hashalgorithm varchar(16) default null, - fk_identity bigint not null, - primary key (id) -); -create table if not exists o_noti_pub ( - publisher_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - publishertype varchar(50) not null, - data longtext, - resname varchar(50), - resid bigint, - subident varchar(128), - businesspath varchar(255), - state integer, - latestnews datetime not null, - primary key (publisher_id) -); -create table if not exists o_qtiresultset ( - resultset_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime not null, - creationdate datetime, - identity_id bigint not null, - olatresource_fk bigint not null, - olatresourcedetail varchar(255) not null, - assessmentid bigint not null, - repositoryref_fk bigint not null, - ispassed bit, - issuspended bit default 0, - fullyassessed bit default 0, - score FLOAT(65,30), - duration bigint, - primary key (resultset_id) -); -create table if not exists o_bs_identity ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - lastlogin datetime, - name varchar(128) not null unique, - external_id varchar(64), - status integer, - primary key (id) -); -create table o_csp_log ( - id bigint not null auto_increment, - creationdate datetime, - l_blocked_uri varchar(1024), - l_disposition varchar(32), - l_document_uri varchar(1024), - l_effective_directive mediumtext, - l_original_policy mediumtext, - l_referrer varchar(1024), - l_script_sample mediumtext, - l_status_code varchar(1024), - l_violated_directive varchar(1024), - l_source_file varchar(1024), - l_line_number bigint, - l_column_number bigint, - fk_identity bigint, - primary key (id) -); -create table if not exists o_olatresource ( - resource_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - resname varchar(50) not null, - resid bigint not null, - primary key (resource_id), - unique (resname, resid) -); -create table if not exists o_bs_namedgroup ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - secgroup_id bigint not null, - groupname varchar(16), - primary key (id), - unique (groupname) -); -create table if not exists o_catentry ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - name varchar(110) not null, - description longtext, - style varchar(16), - externalurl varchar(255), - fk_repoentry bigint, - fk_ownergroup bigint unique, - type integer not null, - parent_id bigint, - primary key (id) -); -create table if not exists o_note ( - note_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - owner_id bigint, - resourcetypename varchar(50) not null, - resourcetypeid bigint not null, - sub_type varchar(50), - notetitle varchar(255), - notetext longtext, - primary key (note_id) -); -create table if not exists o_references ( - reference_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - source_id bigint not null, - target_id bigint not null, - userdata varchar(64), - primary key (reference_id) -); -create table if not exists o_user ( - user_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - language varchar(30), - fontsize varchar(10), - notification_interval varchar(16), - presencemessagespublic bit, - informsessiontimeout bit not null, - receiverealmail varchar(16), - u_firstname varchar(255), - u_lastname varchar(255), - u_email varchar(255), - u_birthday varchar(255), - u_graduation varchar(255), - u_gender varchar(255), - u_telprivate varchar(255), - u_telmobile varchar(255), - u_teloffice varchar(255), - u_smstelmobile varchar(255), - u_skype varchar(255), - u_msn varchar(255), - u_xing varchar(255), - u_icq varchar(255), - u_homepage varchar(255), - u_street varchar(255), - u_extendedaddress varchar(255), - u_pobox varchar(255), - u_zipcode varchar(255), - u_region varchar(255), - u_city varchar(255), - u_country varchar(255), - u_countrycode varchar(255), - u_institutionalname varchar(255), - u_institutionaluseridentifier varchar(255), - u_institutionalemail varchar(255), - u_orgunit varchar(255), - u_studysubject varchar(255), - u_emchangekey varchar(255), - u_emaildisabled varchar(255), - u_typeofuser varchar(255), - u_socialsecuritynumber varchar(255), - - u_rank varchar(255), - u_degree varchar(255), - u_position varchar(255), - u_userinterests varchar(255), - u_usersearchedinterests varchar(255), - u_officestreet varchar(255), - u_extendedofficeaddress varchar(255), - u_officepobox varchar(255), - u_officezipcode varchar(255), - u_officecity varchar(255), - u_officecountry varchar(255), - u_officemobilephone varchar(255), - u_department varchar(255), - u_privateemail varchar(255), - u_employeenumber varchar(255), - u_organizationalunit varchar(255), - - u_edupersonaffiliation varchar(255), - u_swissedupersonstaffcategory varchar(255), - u_swissedupersonhomeorg varchar(255), - u_swissedupersonstudylevel varchar(255), - u_swissedupersonhomeorgtype varchar(255), - u_swissedupersonstudybranch1 varchar(255), - u_swissedupersonstudybranch2 varchar(255), - u_swissedupersonstudybranch3 varchar(255), - - u_genericselectionproperty varchar(255), - u_genericselectionproperty2 varchar(255), - u_genericselectionproperty3 varchar(255), - u_generictextproperty varchar(255), - u_generictextproperty2 varchar(255), - u_generictextproperty3 varchar(255), - u_generictextproperty4 varchar(255), - u_generictextproperty5 varchar(255), - u_genericuniquetextproperty varchar(255), - u_genericuniquetextproperty2 varchar(255), - u_genericuniquetextproperty3 varchar(255), - u_genericemailproperty1 varchar(255), - u_genericcheckboxproperty varchar(255), - u_genericcheckboxproperty2 varchar(255), - u_genericcheckboxproperty3 varchar(255), - - fk_identity bigint, - primary key (user_id) -); -create table if not exists o_userproperty ( - fk_user_id bigint not null, - propname varchar(255) not null, - propvalue varchar(255), - primary key (fk_user_id, propname) -); -create table if not exists o_message ( - message_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - title varchar(100), - body longtext, - pseudonym varchar(255), - guest bit default 0, - parent_id bigint, - topthread_id bigint, - creator_id bigint, - modifier_id bigint, - forum_fk bigint, - statuscode integer, - numofwords integer, - numofcharacters integer, - primary key (message_id) -); - - - -create table if not exists o_gp_bgtoarea_rel ( - bgtoarea_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - group_fk bigint not null, - area_fk bigint not null, - primary key (bgtoarea_id), - unique (group_fk, area_fk) -); -create table if not exists o_noti_sub ( - publisher_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - fk_publisher bigint not null, - fk_identity bigint not null, - latestemailed datetime, - primary key (publisher_id), - unique (fk_publisher, fk_identity) -); -create table if not exists o_qtiresult ( - result_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime not null, - creationdate datetime, - itemident varchar(255) not null, - answer longtext, - duration bigint, - score FLOAT(65,30), - tstamp datetime not null, - ip varchar(255), - resultset_fk bigint, - primary key (result_id) -); -create table if not exists o_bs_policy ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - oresource_id bigint not null, - group_id bigint not null, - permission varchar(16) not null, - apply_from datetime default null, - apply_to datetime default null, - primary key (id), - unique (oresource_id, group_id, permission) -); -create table if not exists o_gp_bgarea ( - area_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - name varchar(255) not null, - descr longtext, - fk_resource bigint default null, - primary key (area_id) -); -create table if not exists o_repositoryentry ( - repositoryentry_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - softkey varchar(36) not null unique, - external_id varchar(64), - external_ref varchar(64), - managed_flags varchar(255), - displayname varchar(110) not null, - resourcename varchar(100) not null, - authors varchar(2048), - mainlanguage varchar(255), - location varchar(255), - objectives varchar(2048), - requirements varchar(2048), - credits varchar(2048), - expenditureofwork varchar(255), - fk_stats bigint not null unique, - fk_lifecycle bigint, - fk_olatresource bigint unique, - description longtext, - initialauthor varchar(128) not null, - accesscode integer not null default 0, - membersonly bit default 0, - statuscode integer, - allowtoleave varchar(16), - canlaunch bit not null, - candownload bit not null, - cancopy bit not null, - canreference bit not null, - deletiondate datetime default null, - fk_deleted_by bigint default null, - primary key (repositoryentry_id) -); -create table o_re_to_group ( - id bigint not null, - creationdate datetime not null, - r_defgroup boolean not null, - fk_group_id bigint not null, - fk_entry_id bigint not null, - primary key (id) -); -create table o_repositoryentry_cycle ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - r_softkey varchar(64), - r_label varchar(255), - r_privatecycle bit default 0, - r_validfrom datetime, - r_validto datetime, - primary key (id) -); -create table o_repositoryentry_stats ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - r_rating decimal(65,30), - r_num_of_ratings bigint not null default 0, - r_num_of_comments bigint not null default 0, - r_launchcounter bigint not null default 0, - r_downloadcounter bigint not null default 0, - r_lastusage datetime not null, - primary key (id) -); -create table if not exists o_bs_membership ( - id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - secgroup_id bigint not null, - identity_id bigint not null, - primary key (id), - unique (secgroup_id, identity_id) -); - -create table if not exists o_plock ( - plock_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - asset varchar(255) not null unique, - primary key (plock_id) -); - -create table if not exists hibernate_unique_key ( - next_hi integer -); - -create table if not exists o_lifecycle ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - persistenttypename varchar(50) not null, - persistentref bigint not null, - action varchar(50) not null, - lctimestamp datetime, - uservalue longtext, - primary key (id) -); - -create table if not exists oc_lock ( - lock_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - identity_fk bigint not null, - asset varchar(120) not null unique, - primary key (lock_id) -); - -create table if not exists o_readmessage ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - identity_id bigint not null, - forum_id bigint not null, - message_id bigint not null, - primary key (id) -); - -create table if not exists o_loggingtable ( - log_id bigint not null, - creationdate datetime, - sourceclass varchar(255), - sessionid varchar(255) not null, - user_id bigint, - username varchar(255), - userproperty1 varchar(255), - userproperty2 varchar(255), - userproperty3 varchar(255), - userproperty4 varchar(255), - userproperty5 varchar(255), - userproperty6 varchar(255), - userproperty7 varchar(255), - userproperty8 varchar(255), - userproperty9 varchar(255), - userproperty10 varchar(255), - userproperty11 varchar(255), - userproperty12 varchar(255), - actioncrudtype varchar(1) not null, - actionverb varchar(16) not null, - actionobject varchar(32) not null, - simpleduration bigint not null, - resourceadminaction boolean not null, - businesspath varchar(2048), - greatgrandparentrestype varchar(32), - greatgrandparentresid varchar(64), - greatgrandparentresname varchar(255), - grandparentrestype varchar(32), - grandparentresid varchar(64), - grandparentresname varchar(255), - parentrestype varchar(32), - parentresid varchar(64), - parentresname varchar(255), - targetrestype varchar(32), - targetresid varchar(64), - targetresname varchar(255), - primary key (log_id) -); - -create table if not exists o_checklist ( - checklist_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime not null, - title varchar(255), - description longtext, - primary key (checklist_id) -); - -create table if not exists o_checkpoint ( - checkpoint_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime not null, - title varchar(255), - description longtext, - modestring varchar(64) not null, - checklist_fk bigint, - primary key (checkpoint_id) -); - -create table if not exists o_checkpoint_results ( - checkpoint_result_id bigint not null, - version mediumint unsigned not null, - lastmodified datetime not null, - result bool not null, - checkpoint_fk bigint, - identity_fk bigint, - primary key (checkpoint_result_id) -); - -create table if not exists o_projectbroker ( - projectbroker_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - primary key (projectbroker_id) -); - -create table if not exists o_projectbroker_project ( - project_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - title varchar(150), - description longtext, - state varchar(20), - maxMembers integer, - attachmentFileName varchar(100), - mailNotificationEnabled boolean not null, - projectgroup_fk bigint not null, - projectbroker_fk bigint not null, - candidategroup_fk bigint not null, - primary key (project_id) -); - -create table if not exists o_projectbroker_customfields ( - fk_project_id bigint not null, - propname varchar(255) not null, - propvalue varchar(255), - primary key (fk_project_id, propname) -); - -create table if not exists o_usercomment ( - comment_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - resname varchar(50) not null, - resid bigint not null, - ressubpath varchar(2048), - creator_id bigint not null, - commenttext longtext, - parent_key bigint, - primary key (comment_id) -); -create table if not exists o_userrating ( - rating_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - lastmodified datetime, - resname varchar(50) not null, - resid bigint not null, - ressubpath varchar(2048), - creator_id bigint not null, - rating integer not null, - primary key (rating_id) -); - -create table o_co_db_entry ( - id bigint not null, - version bigint not null, - lastmodified datetime, - creationdate datetime, - courseid bigint, - identity bigint, - category varchar(32), - name varchar(255) not null, - floatvalue decimal(65,30), - longvalue bigint, - stringvalue varchar(255), - textvalue mediumtext, - primary key (id) -); - -create table if not exists o_stat_lastupdated ( - - lastupdated datetime not null - -); --- important: initialize with old date! -insert into o_stat_lastupdated values(date('1999-01-01')); - - --- insert into o_stat_dayofweek (businesspath,resid,day,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,dayofweek(creationdate) day,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,day; -create table if not exists o_stat_dayofweek ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - day int not null, - value int not null, - primary key (id) - -); -create index statdow_resid_idx on o_stat_dayofweek (resid); - - --- insert into o_stat_hourofday (businesspath,resid,hour,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,hour(creationdate) hour,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,hour; -create table if not exists o_stat_hourofday ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - hour int not null, - value int not null, - primary key (id) - -); -create index stathod_resid_idx on o_stat_hourofday (resid); - - --- insert into o_stat_weekly (businesspath,resid,week,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,concat(year(creationdate),'-',week(creationdate)) week,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,week; -create table if not exists o_stat_weekly ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - week varchar(7) not null, - value int not null, - primary key (id) - -); -create index statwee_resid_idx on o_stat_weekly (resid); - - --- insert into o_stat_daily (businesspath,resid,day,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,date(creationdate) day,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,day; -create table if not exists o_stat_daily ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - day datetime not null, - value int not null, - primary key (id) - -); -create index statday_resid_idx on o_stat_daily (resid); - - --- insert into o_stat_homeorg (businesspath,resid,homeorg,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty2 homeorg,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,homeorg; -create table if not exists o_stat_homeorg ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - homeorg varchar(255) not null, - value int not null, - primary key (id) - -); -create index stathor_resid_idx on o_stat_homeorg (resid); - - --- insert into o_stat_orgtype (businesspath,resid,orgtype,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty4 orgtype,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,orgtype; -create table if not exists o_stat_orgtype ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - orgtype varchar(255), - value int not null, - primary key (id) - -); -create index statorg_resid_idx on o_stat_orgtype (resid); - - --- insert into o_stat_studylevel (businesspath,resid,studylevel,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty3 studylevel,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,studylevel; -create table if not exists o_stat_studylevel ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - studylevel varchar(255) not null, - value int not null, - primary key (id) - -); -create index statstl_resid_idx on o_stat_studylevel (resid); - - --- insert into o_stat_studybranch3 (businesspath,resid,studybranch3,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty10 studybranch3,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,studybranch3; -create table if not exists o_stat_studybranch3 ( - - id bigint unsigned not null auto_increment, - businesspath varchar(2048) not null, - resid bigint not null, - studybranch3 varchar(255), - value int not null, - primary key (id) - -); -create index statstb_resid_idx on o_stat_studybranch3 (resid); - - -create table if not exists o_mark ( - mark_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - resname varchar(50) not null, - resid bigint not null, - ressubpath varchar(2048), - businesspath varchar(2048), - creator_id bigint not null, - primary key (mark_id) -); - -create table if not exists o_info_message ( - info_id bigint NOT NULL, - version mediumint NOT NULL, - creationdate datetime, - modificationdate datetime, - title varchar(2048), - message longtext, - attachmentpath varchar(1024), - resname varchar(50) NOT NULL, - resid bigint NOT NULL, - ressubpath varchar(2048), - businesspath varchar(2048), - fk_author_id bigint, - fk_modifier_id bigint, - primary key (info_id) -); - - -create table if not exists o_tag ( - tag_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - tag varchar(128) not null, - resname varchar(50) not null, - resid bigint not null, - ressubpath varchar(2048), - businesspath varchar(2048), - fk_author_id bigint not null, - primary key (tag_id) -); - -create table if not exists o_bs_invitation ( - id bigint not null, - creationdate datetime, - token varchar(64) not null, - first_name varchar(64), - last_name varchar(64), - mail varchar(128), - fk_group_id bigint, - primary key (id) -); - -create table if not exists o_ep_artefact ( - artefact_id bigint not null, - artefact_type varchar(32) not null, - version mediumint unsigned not null, - creationdate datetime, - collection_date datetime, - title varchar(512), - description varchar(4000), - signature mediumint default 0, - businesspath varchar(2048), - fulltextcontent longtext, - reflexion longtext, - source varchar(2048), - add_prop1 varchar(2048), - add_prop2 varchar(2048), - add_prop3 varchar(2048), - fk_struct_el_id bigint, - fk_artefact_auth_id bigint not null, - primary key (artefact_id) -); -create table if not exists o_ep_collect_restriction ( - collect_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - artefact_type varchar(256), - amount mediumint not null default -1, - restriction varchar(32), - pos mediumint unsigned not null default 0, - fk_struct_el_id bigint, - primary key (collect_id) -); -create table if not exists o_ep_struct_el ( - structure_id bigint not null, - structure_type varchar(32) not null, - version mediumint unsigned not null, - creationdate datetime, - returndate datetime default null, - copydate datetime default null, - lastsyncheddate datetime default null, - deadline datetime default null, - title varchar(512), - description varchar(2048), - struct_el_source bigint, - target_resname varchar(50), - target_resid bigint, - target_ressubpath varchar(2048), - target_businesspath varchar(2048), - style varchar(128), - status varchar(32), - viewmode varchar(32), - fk_struct_root_id bigint, - fk_struct_root_map_id bigint, - fk_map_source_id bigint, - fk_group_id bigint, - fk_olatresource bigint not null, - primary key (structure_id) -); -create table if not exists o_ep_struct_struct_link ( - link_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - pos mediumint unsigned not null default 0, - fk_struct_parent_id bigint not null, - fk_struct_child_id bigint not null, - primary key (link_id) -); -create table if not exists o_ep_struct_artefact_link ( - link_id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - pos mediumint unsigned not null default 0, - reflexion longtext, - fk_auth_id bigint, - fk_struct_id bigint not null, - fk_artefact_id bigint not null, - primary key (link_id) -); -create table o_ep_struct_to_group ( - id bigint not null, - creationdate datetime not null, - r_defgroup boolean not null, - r_role varchar(64), - r_valid_from datetime, - r_valid_to datetime, - fk_group_id bigint, - fk_struct_id bigint, - primary key (id) -); - --- mail system - -create table if not exists o_mail ( - mail_id bigint NOT NULL, - meta_mail_id varchar(64), - creationdate datetime, - lastmodified datetime, - resname varchar(50), - resid bigint, - ressubpath varchar(2048), - businesspath varchar(2048), - subject varchar(512), - body longtext, - fk_from_id bigint, - primary key (mail_id) -); - --- mail recipient -create table if not exists o_mail_to_recipient ( - pos mediumint NOT NULL default 0, - fk_mail_id bigint, - fk_recipient_id bigint -); - -create table if not exists o_mail_recipient ( - recipient_id bigint NOT NULL, - recipientvisible bit, - deleted bit, - mailread bit, - mailmarked bit, - email varchar(255), - recipientgroup varchar(255), - creationdate datetime, - fk_recipient_id bigint, - primary key (recipient_id) -); - --- mail attachments -create table o_mail_attachment ( - attachment_id bigint NOT NULL, - creationdate datetime, - datas mediumblob, - datas_size bigint, - datas_name varchar(255), - datas_checksum bigint, - datas_path varchar(1024), - datas_lastmodified datetime, - mimetype varchar(255), - fk_att_mail_id bigint, - primary key (attachment_id) -); - --- access control -create table if not exists o_ac_offer ( - offer_id bigint NOT NULL, - creationdate datetime, - lastmodified datetime, - is_valid bit default 1, - validfrom datetime, - validto datetime, - version mediumint unsigned not null, - resourceid bigint, - resourcetypename varchar(255), - resourcedisplayname varchar(255), - autobooking boolean default 0, - confirmation_email bit default 0, - token varchar(255), - price_amount DECIMAL(12,4), - price_currency_code VARCHAR(3), - offer_desc VARCHAR(2000), - fk_resource_id bigint, - primary key (offer_id) -); - -create table if not exists o_ac_method ( - method_id bigint NOT NULL, - access_method varchar(32), - version mediumint unsigned not null, - creationdate datetime, - lastmodified datetime, - is_valid bit default 1, - is_enabled bit default 1, - validfrom datetime, - validto datetime, - primary key (method_id) -); - -create table if not exists o_ac_offer_access ( - offer_method_id bigint NOT NULL, - version mediumint unsigned not null, - creationdate datetime, - is_valid bit default 1, - validfrom datetime, - validto datetime, - fk_offer_id bigint, - fk_method_id bigint, - primary key (offer_method_id) -); - -create table o_ac_auto_advance_order ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - a_identifier_key varchar(64) not null, - a_identifier_value varchar(64) not null, - a_status varchar(32) not null, - a_status_modified datetime not null, - fk_identity int8 not null, - fk_method int8 not null, - primary key (id) -); - --- access cart -create table if not exists o_ac_order ( - order_id bigint NOT NULL, - version mediumint unsigned not null, - creationdate datetime, - lastmodified datetime, - is_valid bit default 1, - total_lines_amount DECIMAL(12,4), - total_lines_currency_code VARCHAR(3), - total_amount DECIMAL(12,4), - total_currency_code VARCHAR(3), - discount_amount DECIMAL(12,4), - discount_currency_code VARCHAR(3), - order_status VARCHAR(32) default 'NEW', - fk_delivery_id bigint, - primary key (order_id) -); - -create table if not exists o_ac_order_part ( - order_part_id bigint NOT NULL, - version mediumint unsigned not null, - pos mediumint unsigned, - creationdate datetime, - total_lines_amount DECIMAL(12,4), - total_lines_currency_code VARCHAR(3), - total_amount DECIMAL(12,4), - total_currency_code VARCHAR(3), - fk_order_id bigint, - primary key (order_part_id) -); - -create table if not exists o_ac_order_line ( - order_item_id bigint NOT NULL, - version mediumint unsigned not null, - pos mediumint unsigned, - creationdate datetime, - unit_price_amount DECIMAL(12,4), - unit_price_currency_code VARCHAR(3), - total_amount DECIMAL(12,4), - total_currency_code VARCHAR(3), - fk_order_part_id bigint, - fk_offer_id bigint, - primary key (order_item_id) -); - -create table if not exists o_ac_transaction ( - transaction_id bigint NOT NULL, - version mediumint unsigned not null, - creationdate datetime, - trx_status VARCHAR(32) default 'NEW', - amount_amount DECIMAL(12,4), - amount_currency_code VARCHAR(3), - fk_order_part_id bigint, - fk_order_id bigint, - fk_method_id bigint, - primary key (transaction_id) -); - -create table if not exists o_ac_reservation ( - reservation_id bigint NOT NULL, - creationdate datetime, - lastmodified datetime, - version mediumint unsigned not null, - expirationdate datetime, - reservationtype varchar(32), - fk_identity bigint not null, - fk_resource bigint not null, - primary key (reservation_id) -); - -create table if not exists o_ac_paypal_transaction ( - transaction_id bigint not null, - version bigint not null, - creationdate datetime, - ref_no varchar(255), - order_id bigint not null, - order_part_id bigint not null, - method_id bigint not null, - success_uuid varchar(32) not null, - cancel_uuid varchar(32) not null, - amount_amount DECIMAL(12,4), - amount_currency_code VARCHAR(3), - pay_response_date datetime, - pay_key varchar(255), - ack varchar(255), - build varchar(255), - coorelation_id varchar(255), - payment_exec_status varchar(255), - ipn_transaction_id varchar(255), - ipn_transaction_status varchar(255), - ipn_sender_transaction_id varchar(255), - ipn_sender_transaction_status varchar(255), - ipn_sender_email varchar(255), - ipn_verify_sign varchar(255), - ipn_pending_reason varchar(255), - trx_status VARCHAR(32) not null default 'NEW', - trx_amount DECIMAL(12,4), - trx_currency_code VARCHAR(3), - primary key (transaction_id) -); - --- openmeetings -create table if not exists o_om_room_reference ( - id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - creationdate datetime, - businessgroup bigint, - resourcetypename varchar(50), - resourcetypeid bigint, - ressubpath varchar(255), - roomId bigint, - config longtext, - primary key (id) -); - --- assessment tables --- efficiency statments -create table if not exists o_as_eff_statement ( - id bigint not null, - version mediumint unsigned not null, - lastmodified datetime, - lastcoachmodified datetime, - lastusermodified datetime, - creationdate datetime, - passed bit default null, - score float(65,30), - total_nodes mediumint, - attempted_nodes mediumint, - passed_nodes mediumint, - course_title varchar(255), - course_short_title varchar(128), - course_repo_key bigint, - statement_xml longtext, - fk_identity bigint, - fk_resource_id bigint, - primary key (id) -); - --- user to course informations (was property initial and recent launch dates) -create table o_as_user_course_infos ( - id bigint not null, - version mediumint unsigned not null, - creationdate datetime, - lastmodified datetime, - initiallaunchdate datetime, - recentlaunchdate datetime, - visit mediumint, - timespend bigint, - fk_identity bigint, - fk_resource_id bigint, - primary key (id) -); - -create table o_as_entry ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - lastcoachmodified datetime, - lastusermodified datetime, - a_attemtps bigint default null, - a_score float(65,30) default null, - a_passed bit default null, - a_status varchar(16) default null, - a_details varchar(1024) default null, - a_fully_assessed bit default null, - a_user_visibility bit default 1, - a_assessment_id bigint default null, - a_completion float(65,30), - a_current_run_completion float(65,30), - a_current_run_status varchar(16), - a_comment text, - a_coach_comment text, - a_num_assessment_docs bigint not null default 0, - fk_entry bigint not null, - a_subident varchar(64), - fk_reference_entry bigint, - fk_identity bigint default null, - a_anon_identifier varchar(128) default null, - primary key (id), - unique (fk_identity, fk_entry, a_subident) -); - -create table o_as_mode_course ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - a_name varchar(255), - a_description longtext, - a_status varchar(16), - a_manual_beginend bit not null default 0, - a_begin datetime not null, - a_leadtime bigint not null default 0, - a_begin_with_leadtime datetime not null, - a_end datetime not null, - a_followuptime bigint not null default 0, - a_end_with_followuptime datetime not null, - a_targetaudience varchar(16), - a_restrictaccesselements bit not null default 0, - a_elements varchar(2048), - a_start_element varchar(64), - a_restrictaccessips bit not null default 0, - a_ips varchar(2048), - a_safeexambrowser bit not null default 0, - a_safeexambrowserkey varchar(2048), - a_safeexambrowserhint longtext, - a_applysettingscoach bit not null default 0, - fk_entry bigint not null, - primary key (id) -); - -create table o_as_mode_course_to_group ( - id bigint not null, - fk_assessment_mode_id bigint not null, - fk_group_id bigint not null, - primary key (id) -); - -create table o_as_mode_course_to_area ( - id bigint not null, - fk_assessment_mode_id bigint not null, - fk_area_id bigint not null, - primary key (id) -); - -create table o_cer_template ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_name varchar(256) not null, - c_path varchar(1024) not null, - c_public boolean not null, - c_format varchar(16), - c_orientation varchar(16), - primary key (id) -); - -create table o_cer_certificate ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_status varchar(16) not null default 'pending', - c_email_status varchar(16), - c_uuid varchar(36) not null, - c_next_recertification datetime, - c_path varchar(1024), - c_last boolean not null default 1, - c_course_title varchar(255), - c_archived_resource_id bigint not null, - fk_olatresource bigint, - fk_identity bigint not null, - primary key (id) -); - -create table o_goto_organizer ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_name varchar(128) default null, - g_account_key varchar(128) default null, - g_access_token varchar(128) not null, - g_renew_date datetime not null, - g_organizer_key varchar(128) not null, - g_username varchar(128) not null, - g_firstname varchar(128) default null, - g_lastname varchar(128) default null, - g_email varchar(128) default null, - fk_identity bigint default null, - primary key (id) -); - -create table o_goto_meeting ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_external_id varchar(128) default null, - g_type varchar(16) not null, - g_meeting_key varchar(128) not null, - g_name varchar(255) default null, - g_description varchar(2000) default null, - g_start_date datetime default null, - g_end_date datetime default null, - fk_organizer_id bigint not null, - fk_entry_id bigint default null, - g_sub_ident varchar(64) default null, - fk_group_id bigint default null, - primary key (id) -); - -create table o_goto_registrant ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_status varchar(16) default null, - g_join_url varchar(1024) default null, - g_confirm_url varchar(1024) default null, - g_registrant_key varchar(64) default null, - fk_meeting_id bigint not null, - fk_identity_id bigint not null, - primary key (id) -); - -create table o_vid_transcoding ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - vid_resolution bigint default null, - vid_width bigint default null, - vid_height bigint default null, - vid_size bigint default null, - vid_format varchar(128) default null, - vid_status bigint default null, - vid_transcoder varchar(128) default null, - fk_resource_id bigint not null, - primary key (id) -); - -create table o_vid_metadata ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - vid_width bigint default null, - vid_height bigint default null, - vid_size bigint default null, - vid_format varchar(32) default null, - vid_length varchar(32) default null, - fk_resource_id bigint not null, - primary key (id) -); - --- calendar -create table o_cal_use_config ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_calendar_id varchar(128) not null, - c_calendar_type varchar(16) not null, - c_token varchar(36), - c_cssclass varchar(36), - c_visible bit not null default 1, - c_aggregated_feed bit not null default 1, - fk_identity bigint not null, - primary key (id), - unique (c_calendar_id, c_calendar_type, fk_identity) -); - -create table o_cal_import ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_calendar_id varchar(128) not null, - c_calendar_type varchar(16) not null, - c_displayname varchar(256), - c_lastupdate datetime not null, - c_url varchar(1024), - fk_identity bigint, - primary key (id) -); - -create table o_cal_import_to ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_to_calendar_id varchar(128) not null, - c_to_calendar_type varchar(16) not null, - c_lastupdate datetime not null, - c_url varchar(1024), - primary key (id) -); - --- instant messaging -create table if not exists o_im_message ( - id bigint not null, - creationdate datetime, - msg_resname varchar(50) not null, - msg_resid bigint not null, - msg_anonym bit default 0, - msg_from varchar(255) not null, - msg_body longtext, - fk_from_identity_id bigint not null, - primary key (id) -); - -create table if not exists o_im_notification ( - id bigint not null, - creationdate datetime, - chat_resname varchar(50) not null, - chat_resid bigint not null, - fk_to_identity_id bigint not null, - fk_from_identity_id bigint not null, - primary key (id) -); - -create table if not exists o_im_roster_entry ( - id bigint not null, - creationdate datetime, - r_resname varchar(50) not null, - r_resid bigint not null, - r_nickname varchar(255), - r_fullname varchar(255), - r_anonym bit default 0, - r_vip bit default 0, - fk_identity_id bigint not null, - primary key (id) -); - -create table if not exists o_im_preferences ( - id bigint not null, - creationdate datetime, - visible_to_others bit default 0, - roster_def_status varchar(12), - fk_from_identity_id bigint not null, - primary key (id) -); - --- add mapper table -create table o_mapper ( - id bigint not null, - lastmodified datetime, - creationdate datetime, - expirationdate datetime, - mapper_uuid varchar(64), - orig_session_id varchar(64), - xml_config text, - primary key (id) -); - --- qti 2.1 -create table o_qti_assessmenttest_session ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - q_exploded bit not null default 0, - q_author_mode bit not null default 0, - q_finish_time datetime, - q_termination_time datetime, - q_duration bigint, - q_score float(65,30) default null, - q_manual_score float(65,30) default null, - q_passed bit default null, - q_num_questions bigint, - q_num_answered_questions bigint, - q_extra_time bigint, - q_storage varchar(1024), - fk_reference_entry bigint not null, - fk_entry bigint, - q_subident varchar(255), - fk_identity bigint default null, - q_anon_identifier varchar(128) default null, - fk_assessment_entry bigint not null, - primary key (id) -); - -create table o_qti_assessmentitem_session ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - q_itemidentifier varchar(255) not null, - q_sectionidentifier varchar(255) default null, - q_testpartidentifier varchar(255) default null, - q_duration bigint, - q_score float(65,30) default null, - q_manual_score float(65,30) default null, - q_coach_comment mediumtext default null, - q_to_review bit default 0, - q_passed bit default null, - q_storage varchar(1024), - fk_assessmenttest_session bigint not null, - primary key (id) -); - -create table o_qti_assessment_response ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - q_responseidentifier varchar(255) not null, - q_responsedatatype varchar(16) not null, - q_responselegality varchar(16) not null, - q_stringuifiedresponse mediumtext, - fk_assessmentitem_session bigint not null, - fk_assessmenttest_session bigint not null, - primary key (id) -); - -create table o_qti_assessment_marks ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - q_marks mediumtext default null, - q_hidden_rubrics mediumtext default null, - fk_reference_entry bigint not null, - fk_entry bigint, - q_subident varchar(64), - fk_identity bigint not null, - primary key (id) -); - --- question item -create table o_qp_pool ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - q_name varchar(255) not null, - q_public bit default 0, - fk_ownergroup bigint, - primary key (id) -); - -create table o_qp_taxonomy_level ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - q_field varchar(255) not null, - q_mat_path_ids varchar(1024), - q_mat_path_names varchar(2048), - fk_parent_field bigint, - primary key (id) -); - -create table o_qp_item ( - id bigint not null, - q_identifier varchar(36) not null, - q_master_identifier varchar(36), - q_title varchar(1024) not null, - q_topic varchar(1024), - q_description varchar(2048), - q_keywords varchar(1024), - q_coverage varchar(1024), - q_additional_informations varchar(256), - q_language varchar(16), - fk_edu_context bigint, - q_educational_learningtime varchar(32), - fk_type bigint, - q_difficulty decimal(10,9), - q_stdev_difficulty decimal(10,9), - q_differentiation decimal(10,9), - q_num_of_answers_alt bigint not null default 0, - q_usage bigint not null default 0, - q_assessment_type varchar(64), - q_status varchar(32) not null, - q_version varchar(50), - fk_license bigint, - q_editor varchar(256), - q_editor_version varchar(256), - q_format varchar(32) not null, - q_creator varchar(1024), - creationdate datetime not null, - lastmodified datetime not null, - q_status_last_modified datetime not null, - q_dir varchar(32), - q_root_filename varchar(255), - fk_taxonomy_level bigint, - fk_taxonomy_level_v2 bigint, - fk_ownergroup bigint not null, - primary key (id) -); - -create table o_qp_item_audit_log ( - id bigint not null auto_increment, - creationdate datetime not null, - q_action varchar(64), - q_val_before mediumtext, - q_val_after mediumtext, - q_lic_before mediumtext, - q_lic_after mediumtext, - q_message mediumtext, - fk_author_id bigint, - fk_item_id bigint, - primary key (id) -); - -create table o_qp_pool_2_item ( - id bigint not null, - creationdate datetime not null, - q_editable bit default 0, - fk_pool_id bigint not null, - fk_item_id bigint not null, - primary key (id) -); - -create table o_qp_share_item ( - id bigint not null, - creationdate datetime not null, - q_editable bit default 0, - fk_resource_id bigint not null, - fk_item_id bigint not null, - primary key (id) -); - -create table o_qp_item_collection ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - q_name varchar(256), - fk_owner_id bigint not null, - primary key (id) -); - -create table o_qp_collection_2_item ( - id bigint not null, - creationdate datetime not null, - fk_collection_id bigint not null, - fk_item_id bigint not null, - primary key (id) -); - -create table o_qp_edu_context ( - id bigint not null, - creationdate datetime not null, - q_level varchar(256) not null, - q_deletable bit default 0, - primary key (id) -); - -create table if not exists o_qp_item_type ( - id bigint not null, - creationdate datetime not null, - q_type varchar(256) not null, - q_deletable bit default 0, - primary key (id) -); - -create table if not exists o_qp_license ( - id bigint not null, - creationdate datetime not null, - q_license varchar(256) not null, - q_text varchar(2048), - q_deletable bit default 0, - primary key (id) -); - - --- portfolio -create table o_pf_binder ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - p_title varchar(255), - p_status varchar(32), - p_copy_date datetime, - p_return_date datetime, - p_deadline datetime, - p_summary mediumtext, - p_image_path varchar(255), - fk_olatresource_id bigint, - fk_group_id bigint not null, - fk_entry_id bigint, - p_subident varchar(128), - fk_template_id bigint, - primary key (id) -); - -create table o_pf_section ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - pos bigint default null, - p_title varchar(255), - p_description mediumtext, - p_status varchar(32) not null default 'notStarted', - p_begin datetime, - p_end datetime, - p_override_begin_end bit default 0, - fk_group_id bigint not null, - fk_binder_id bigint not null, - fk_template_reference_id bigint, - primary key (id) -); - -create table o_pf_page ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - pos bigint default null, - p_editable bit default 1, - p_title varchar(255), - p_summary mediumtext, - p_status varchar(32), - p_image_path varchar(255), - p_image_align varchar(32), - p_version bigint default 0, - p_initial_publish_date datetime, - p_last_publish_date datetime, - fk_body_id bigint not null, - fk_group_id bigint not null, - fk_section_id bigint, - primary key (id) -); - -create table o_pf_page_body ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - primary key (id) -); - -create table o_pf_media ( - id bigint not null auto_increment, - creationdate datetime not null, - p_collection_date datetime not null, - p_type varchar(64) not null, - p_storage_path varchar(255), - p_root_filename varchar(255), - p_title varchar(255) not null, - p_description mediumtext, - p_content mediumtext, - p_signature bigint not null default 0, - p_reference_id varchar(255) default null, - p_business_path varchar(255) not null, - p_creators varchar(1024) default null, - p_place varchar(255) default null, - p_publisher varchar(255) default null, - p_publication_date datetime default null, - p_date varchar(32) default null, - p_url varchar(1024) default null, - p_source varchar(1024) default null, - p_language varchar(32) default null, - p_metadata_xml mediumtext, - fk_author_id bigint not null, - primary key (id) -); - -create table o_pf_page_part ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - pos bigint default null, - dtype varchar(32), - p_content mediumtext, - p_flow varchar(32), - p_layout_options varchar(2000), - fk_media_id bigint, - fk_page_body_id bigint, - fk_form_entry_id bigint default null, - primary key (id) -); - -create table o_pf_category ( - id bigint not null auto_increment, - creationdate datetime not null, - p_name varchar(32), - primary key (id) -); - -create table o_pf_category_relation ( - id bigint not null auto_increment, - creationdate datetime not null, - p_resname varchar(64) not null, - p_resid bigint not null, - fk_category_id bigint not null, - primary key (id) -); - -create table o_pf_assessment_section ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - p_score float(65,30) default null, - p_passed bit default null, - p_comment mediumtext, - fk_section_id bigint not null, - fk_identity_id bigint not null, - primary key (id) -); - -create table o_pf_assignment ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - pos bigint default null, - p_status varchar(32) default null, - p_type varchar(32) not null, - p_version bigint not null default 0, - p_title varchar(255) default null, - p_summary mediumtext, - p_content mediumtext, - p_storage varchar(255) default null, - fk_section_id bigint not null, - fk_template_reference_id bigint, - fk_page_id bigint, - fk_assignee_id bigint, - p_only_auto_eva bit default 1, - p_reviewer_see_auto_eva bit default 0, - p_anon_extern_eva bit default 1, - fk_form_entry_id bigint default null, - primary key (id) -); - -create table o_pf_binder_user_infos ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - p_initiallaunchdate datetime, - p_recentlaunchdate datetime, - p_visit bigint, - fk_identity bigint, - fk_binder bigint, - unique(fk_identity, fk_binder), - primary key (id) -); - -create table o_pf_page_user_infos ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - p_mark bit default 0, - p_status varchar(16) not null default 'incoming', - p_recentlaunchdate datetime not null, - fk_identity_id bigint not null, - fk_page_id bigint not null, - primary key (id) -); - --- evaluation form -create table o_eva_form_survey ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - e_resname varchar(50) not null, - e_resid bigint not null, - e_sub_ident varchar(2048), - fk_form_entry bigint not null, - primary key (id) -); - -create table o_eva_form_participation ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - e_identifier_type varchar(50) not null, - e_identifier_key varchar(50) not null, - e_status varchar(20) not null, - e_anonymous bit not null, - fk_executor bigint, - fk_survey bigint not null, - primary key (id) -); - -create table o_eva_form_session ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - e_status varchar(16), - e_submission_date datetime, - e_first_submission_date datetime, - fk_survey bigint, - fk_participation bigint unique - fk_identity bigint, - fk_page_body bigint, - fk_form_entry bigint, - primary key (id) -); - -create table o_eva_form_response ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - e_no_response bit default 0, - e_responseidentifier varchar(64) not null, - e_numericalresponse decimal default null, - e_stringuifiedresponse mediumtext, - e_file_response_path varchar(4000), - fk_session bigint not null, - primary key (id) -); - -create table o_eva_form_survey ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - e_resname varchar(50), - e_resid bigint, - e_sub_ident varchar(2048), - fk_form_entry bigint not null, - primary key (id) -); - --- lti -create table o_lti_outcome ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - r_ressubpath varchar(2048), - r_action varchar(255) not null, - r_outcome_key varchar(255) not null, - r_outcome_value varchar(2048), - fk_resource_id bigint not null, - fk_identity_id bigint not null, - primary key (id) -); - -create table o_cl_checkbox ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_checkboxid varchar(50) not null, - c_resname varchar(50) not null, - c_resid bigint not null, - c_ressubpath varchar(255) not null, - primary key (id) -); - -create table o_cl_check ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - c_score float(65,30), - c_checked bit default null, - fk_identity_id bigint not null, - fk_checkbox_id bigint not null, - primary key (id) -); - -create table o_gta_task_list ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_course_node_ident varchar(36), - fk_entry bigint not null, - primary key (id) -); - -create table o_gta_task ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - g_status varchar(36), - g_rev_loop mediumint not null default 0, - g_assignment_date datetime, - g_submission_date datetime, - g_submission_ndocs bigint, - g_submission_revisions_date datetime, - g_submission_revisions_ndocs bigint, - g_collection_date datetime, - g_collection_ndocs bigint, - g_acceptation_date datetime, - g_solution_date datetime, - g_graduation_date datetime, - g_allow_reset_date datetime, - g_assignment_due_date datetime, - g_submission_due_date datetime, - g_revisions_due_date datetime, - g_solution_due_date datetime, - g_taskname varchar(1024), - fk_tasklist bigint not null, - fk_identity bigint, - fk_businessgroup bigint, - fk_allow_reset_identity bigint, - primary key (id) -); - -create table o_gta_task_revision_date ( - id bigint not null auto_increment, - creationdate datetime not null, - g_status varchar(36) not null, - g_rev_loop bigint not null, - g_date datetime not null, - fk_task bigint not null, - primary key (id) -); - -create table o_gta_mark ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - fk_tasklist_id int8 not null, - fk_marker_identity_id int8 not null, - fk_participant_identity_id int8 not null, - primary key (id) -); - -create table o_rem_reminder ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - r_description varchar(255), - r_start datetime, - r_sendtime varchar(16), - r_configuration mediumtext, - r_email_subject varchar(255), - r_email_body mediumtext, - fk_creator bigint not null, - fk_entry bigint not null, - primary key (id) -); - -create table o_rem_sent_reminder ( - id bigint not null, - creationdate datetime not null, - r_status varchar(16), - fk_identity bigint not null, - fk_reminder bigint not null, - primary key (id) -); - -create table o_ex_task ( - id bigint not null, - creationdate datetime not null, - lastmodified datetime not null, - e_name varchar(255) not null, - e_status varchar(16) not null, - e_status_before_edit varchar(16), - e_executor_node varchar(16), - e_executor_boot_id varchar(64), - e_task mediumtext not null, - e_scheduled datetime, - e_ressubpath varchar(2048), - fk_resource_id bigint, - fk_identity_id bigint, - primary key (id) -); - -create table o_ex_task_modifier ( - id bigint not null, - creationdate datetime not null, - fk_task_id bigint not null, - fk_identity_id bigint not null, - primary key (id) -); - --- sms -create table o_sms_message_log ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - s_message_uuid varchar(256) not null, - s_server_response varchar(256), - s_service_id varchar(32) not null, - fk_identity bigint not null, - primary key (id) -); - --- webfeed -create table o_feed ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - f_resourceable_id bigint, - f_resourceable_type varchar(64), - f_title varchar(1024), - f_description mediumtext, - f_author varchar(255), - f_image_name varchar(1024), - f_external boolean, - f_external_feed_url varchar(4000), - f_external_image_url varchar(4000), - primary key (id) -); - -create table o_feed_item ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - f_title varchar(1024), - f_description mediumtext, - f_content mediumtext, - f_author varchar(255), - f_guid varchar(255), - f_external_link varchar(4000), - f_draft boolean, - f_publish_date datetime, - f_width bigint, - f_height bigint, - f_filename varchar(1024), - f_type varchar(255), - f_length bigint, - f_external_url varchar(4000), - fk_feed_id bigint not null, - fk_identity_author_id bigint, - fk_identity_modified_id bigint, - primary key (id) -); - --- lectures -create table o_lecture_reason ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_title varchar(255), - l_descr varchar(2000), - primary key (id) -); - -create table o_lecture_block ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_external_id varchar(255), - l_managed_flags varchar(255), - l_title varchar(255), - l_descr mediumtext, - l_preparation mediumtext, - l_location varchar(255), - l_comment mediumtext, - l_start_date datetime not null, - l_end_date datetime not null, - l_compulsory bit default 1, - l_eff_end_date datetime, - l_planned_lectures_num bigint not null default 0, - l_effective_lectures_num bigint not null default 0, - l_effective_lectures varchar(128), - l_auto_close_date datetime default null, - l_status varchar(16) not null, - l_roll_call_status varchar(16) not null, - fk_reason bigint, - fk_entry bigint not null, - fk_teacher_group bigint not null, - primary key (id) -); - -create table o_lecture_block_to_group ( - id bigint not null auto_increment, - fk_lecture_block bigint not null, - fk_group bigint not null, - primary key (id) -); - -create table o_lecture_block_roll_call ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_comment mediumtext, - l_lectures_attended varchar(128), - l_lectures_absent varchar(128), - l_lectures_attended_num bigint not null default 0, - l_lectures_absent_num bigint not null default 0, - l_absence_reason mediumtext, - l_absence_authorized bit default null, - l_absence_appeal_date datetime, - l_absence_supervisor_noti_date datetime, - fk_lecture_block bigint not null, - fk_identity bigint not null, - primary key (id) -); - -create table o_lecture_reminder ( - id bigint not null auto_increment, - creationdate datetime not null, - l_status varchar(16) not null, - fk_lecture_block bigint not null, - fk_identity bigint not null, - primary key (id) -); - -create table o_lecture_participant_summary ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_first_admission_date datetime default null, - l_required_attendance_rate float(65,30) default null, - l_attended_lectures bigint not null default 0, - l_absent_lectures bigint not null default 0, - l_excused_lectures bigint not null default 0, - l_planneds_lectures bigint not null default 0, - l_attendance_rate float(65,30) default null, - l_cal_sync bit default 0, - l_cal_last_sync_date datetime default null, - fk_entry bigint not null, - fk_identity bigint not null, - primary key (id), - unique (fk_entry, fk_identity) -); - -create table o_lecture_entry_config ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_lecture_enabled bit default null, - l_override_module_def bit default 0, - l_rollcall_enabled bit default null, - l_calculate_attendance_rate bit default null, - l_required_attendance_rate float(65,30) default null, - l_sync_calendar_teacher bit default null, - l_sync_calendar_participant bit default null, - l_sync_calendar_course bit default null, - fk_entry bigint not null, - unique(fk_entry), - primary key (id) -); - -create table o_lecture_block_audit_log ( - id bigint not null auto_increment, - creationdate datetime not null, - l_action varchar(32), - l_val_before mediumtext, - l_val_after mediumtext, - l_message mediumtext, - fk_lecture_block bigint, - fk_roll_call bigint, - fk_entry bigint, - fk_identity bigint, - fk_author bigint, - primary key (id) -); - --- taxonomy -create table o_tax_taxonomy ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - t_identifier varchar(64), - t_displayname varchar(255) not null, - t_description mediumtext, - t_external_id varchar(64), - t_managed_flags varchar(255), - t_directory_path varchar(255), - t_directory_lost_found_path varchar(255), - fk_group bigint not null, - primary key (id) -); - -create table o_tax_taxonomy_level_type ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - t_identifier varchar(64), - t_displayname varchar(255) not null, - t_description mediumtext, - t_external_id varchar(64), - t_managed_flags varchar(255), - t_css_class varchar(64), - t_visible bit default 1, - t_library_docs bit default 1, - t_library_manage bit default 1, - t_library_teach_read bit default 1, - t_library_teach_readlevels bigint not null default 0, - t_library_teach_write bit default 0, - t_library_have_read bit default 1, - t_library_target_read bit default 1, - fk_taxonomy bigint not null, - primary key (id) -); - -create table o_tax_taxonomy_type_to_type ( - id bigint not null auto_increment, - fk_type bigint not null, - fk_allowed_sub_type bigint not null, - primary key (id) -); - -create table o_tax_taxonomy_level ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - t_identifier varchar(64), - t_displayname varchar(255) not null, - t_description mediumtext, - t_external_id varchar(64), - t_sort_order bigint, - t_directory_path varchar(255), - t_m_path_keys varchar(255), - t_m_path_identifiers varchar(1024), - t_enabled bit default 1, - t_managed_flags varchar(255), - fk_taxonomy bigint not null, - fk_parent bigint, - fk_type bigint, - primary key (id) -); - -create table o_tax_taxonomy_competence ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - t_type varchar(16), - t_achievement float(65,30) default null, - t_reliability float(65,30) default null, - t_expiration_date datetime, - t_external_id varchar(64), - t_source_text varchar(255), - t_source_url varchar(255), - fk_level bigint not null, - fk_identity bigint not null, - primary key (id) -); - -create table o_tax_competence_audit_log ( - id bigint not null auto_increment, - creationdate datetime not null, - t_action varchar(32), - t_val_before mediumtext, - t_val_after mediumtext, - t_message mediumtext, - fk_taxonomy bigint, - fk_taxonomy_competence bigint, - fk_identity bigint, - fk_author bigint, - primary key (id) -); - --- dialog elements -create table o_dialog_element ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - d_filename varchar(2048), - d_filesize bigint, - d_subident varchar(64) not null, - fk_author bigint, - fk_entry bigint not null, - fk_forum bigint not null, - primary key (id) -); - --- licenses -create table o_lic_license_type ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - l_name varchar(128) not null unique, - l_text mediumtext, - l_css_class varchar(64), - l_predefined boolean not null default false, - l_sort_order int not null, - primary key (id) -); - -create table o_lic_license_type_activation ( - id bigint not null auto_increment, - creationdate timestamp not null, - l_handler_type varchar(128) not null, - fk_license_type_id bigint not null, - primary key (id) -); - -create table o_lic_license ( - id bigint not null auto_increment, - creationdate timestamp not null, - lastmodified datetime not null, - l_resname varchar(50) not null, - l_resid bigint not null, - l_licensor varchar(4000), - l_freetext mediumtext, - fk_license_type_id bigint not null, - primary key (id) -); - --- organisation -create table o_org_organisation_type ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - o_identifier varchar(64), - o_displayname varchar(255) not null, - o_description mediumtext, - o_external_id varchar(64), - o_managed_flags varchar(255), - o_css_class varchar(64), - primary key (id) -); - -create table o_org_organisation ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - o_identifier varchar(64), - o_displayname varchar(255) not null, - o_description mediumtext, - o_m_path_keys varchar(255), - o_external_id varchar(64), - o_managed_flags varchar(255), - o_status varchar(32), - o_css_class varchar(64), - fk_group bigint not null, - fk_root bigint, - fk_parent bigint, - fk_type bigint, - primary key (id) -); - -create table o_org_type_to_type ( - id bigint not null auto_increment, - fk_type bigint not null, - fk_allowed_sub_type bigint not null, - primary key (id) -); - -create table o_re_to_organisation ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - r_master bit default 0, - fk_entry bigint not null, - fk_organisation bigint not null, - primary key (id) -); - --- curriculum -create table o_cur_element_type ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - c_identifier varchar(64), - c_displayname varchar(255) not null, - c_description mediumtext, - c_external_id varchar(64), - c_managed_flags varchar(255), - c_css_class varchar(64), - primary key (id) -); - -create table o_cur_curriculum ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - c_identifier varchar(64), - c_displayname varchar(255) not null, - c_description mediumtext, - c_external_id varchar(64), - c_managed_flags varchar(255), - c_status varchar(32), - c_degree varchar(255), - fk_group bigint not null, - fk_organisation bigint, - primary key (id) -); - -create table o_cur_curriculum_element ( - id bigint not null auto_increment, - creationdate datetime not null, - lastmodified datetime not null, - pos bigint, - c_identifier varchar(64), - c_displayname varchar(255) not null, - c_description mediumtext, - c_status varchar(32), - c_begin datetime, - c_end datetime, - c_external_id varchar(64), - c_managed_flags varchar(255), - fk_group bigint not null, - fk_parent bigint, - fk_curriculum bigint not null, - primary key (id) -); - -create table o_cur_element_type_to_type ( - id bigint not null auto_increment, - fk_type bigint not null, - fk_allowed_sub_type bigint not null, - primary key (id) -); - --- user view -create view o_bs_identity_short_v as ( - select - ident.id as id_id, - ident.name as id_name, - ident.lastlogin as id_lastlogin, - ident.status as id_status, - us.user_id as us_id, - us.u_firstname as first_name, - us.u_lastname as last_name, - us.u_email as email - from o_bs_identity as ident - inner join o_user as us on (ident.id = us.fk_identity) -); - --- eportfolio views -create or replace view o_ep_notifications_struct_v as ( - select - struct.structure_id as struct_id, - struct.structure_type as struct_type, - struct.title as struct_title, - struct.fk_struct_root_id as struct_root_id, - struct.fk_struct_root_map_id as struct_root_map_id, - (case when struct.structure_type = 'page' then struct.structure_id else parent_struct.structure_id end) as page_key, - struct_link.creationdate as creation_date - from o_ep_struct_el as struct - inner join o_ep_struct_struct_link as struct_link on (struct_link.fk_struct_child_id = struct.structure_id) - inner join o_ep_struct_el as parent_struct on (struct_link.fk_struct_parent_id = parent_struct.structure_id) - where struct.structure_type = 'page' or parent_struct.structure_type = 'page' -); - -create or replace view o_ep_notifications_art_v as ( - select - artefact.artefact_id as artefact_id, - artefact_link.link_id as link_id, - artefact.title as artefact_title, - (case when struct.structure_type = 'page' then struct.title else root_struct.title end ) as struct_title, - struct.structure_type as struct_type, - struct.structure_id as struct_id, - root_struct.structure_id as struct_root_id, - root_struct.structure_type as struct_root_type, - struct.fk_struct_root_map_id as struct_root_map_id, - (case when struct.structure_type = 'page' then struct.structure_id else root_struct.structure_id end ) as page_key, - artefact_link.fk_auth_id as author_id, - artefact_link.creationdate as creation_date - from o_ep_struct_el as struct - inner join o_ep_struct_artefact_link as artefact_link on (artefact_link.fk_struct_id = struct.structure_id) - inner join o_ep_artefact as artefact on (artefact_link.fk_artefact_id = artefact.artefact_id) - left join o_ep_struct_el as root_struct on (struct.fk_struct_root_id = root_struct.structure_id) -); - -create or replace view o_ep_notifications_rating_v as ( - select - urating.rating_id as rating_id, - map.structure_id as map_id, - map.title as map_title, - cast(urating.ressubpath as unsigned) as page_key, - page.title as page_title, - urating.creator_id as author_id, - urating.creationdate as creation_date, - urating.lastmodified as last_modified - from o_userrating as urating - inner join o_olatresource as rating_resource on (rating_resource.resid = urating.resid and rating_resource.resname = urating.resname) - inner join o_ep_struct_el as map on (map.fk_olatresource = rating_resource.resource_id) - left join o_ep_struct_el as page on (page.fk_struct_root_map_id = map.structure_id and page.structure_id = urating.ressubpath) -); - -create or replace view o_ep_notifications_comment_v as ( - select - ucomment.comment_id as comment_id, - map.structure_id as map_id, - map.title as map_title, - cast(ucomment.ressubpath as unsigned) as page_key, - page.title as page_title, - ucomment.creator_id as author_id, - ucomment.creationdate as creation_date - from o_usercomment as ucomment - inner join o_olatresource as comment_resource on (comment_resource.resid = ucomment.resid and comment_resource.resname = ucomment.resname) - inner join o_ep_struct_el as map on (map.fk_olatresource = comment_resource.resource_id) - left join o_ep_struct_el as page on (page.fk_struct_root_map_id = map.structure_id and page.structure_id = ucomment.ressubpath) -); - -create view o_gp_business_to_repository_v as ( - select - grp.group_id as grp_id, - repoentry.repositoryentry_id as re_id, - repoentry.displayname as re_displayname - from o_gp_business as grp - inner join o_re_to_group as relation on (relation.fk_group_id = grp.fk_group_id) - inner join o_repositoryentry as repoentry on (repoentry.repositoryentry_id = relation.fk_entry_id) -); - -create view o_bs_gp_membership_v as ( - select - membership.id as membership_id, - membership.fk_identity_id as fk_identity_id, - membership.lastmodified as lastmodified, - membership.creationdate as creationdate, - membership.g_role as g_role, - gp.group_id as group_id - from o_bs_group_member as membership - inner join o_gp_business as gp on (gp.fk_group_id=membership.fk_group_id) -); - -create or replace view o_re_membership_v as ( - select - bmember.id as membership_id, - bmember.creationdate as creationdate, - bmember.lastmodified as lastmodified, - bmember.fk_identity_id as fk_identity_id, - bmember.g_role as g_role, - re.repositoryentry_id as fk_entry_id - from o_repositoryentry as re - inner join o_re_to_group relgroup on (relgroup.fk_entry_id=re.repositoryentry_id and relgroup.r_defgroup=1) - inner join o_bs_group_member as bmember on (bmember.fk_group_id=relgroup.fk_group_id) -); - --- contacts -create view o_gp_contactkey_v as ( - select - bg_member.id as membership_id, - bg_member.fk_identity_id as member_id, - bg_member.g_role as membership_role, - bg_me.fk_identity_id as me_id, - bgroup.group_id as bg_id - from o_gp_business as bgroup - inner join o_bs_group_member as bg_member on (bg_member.fk_group_id = bgroup.fk_group_id) - inner join o_bs_group_member as bg_me on (bg_me.fk_group_id = bgroup.fk_group_id) - where - (bgroup.ownersintern=1 and bg_member.g_role='coach') - or - (bgroup.participantsintern=1 and bg_member.g_role='participant') -); - -create view o_gp_contactext_v as ( - select - bg_member.id as membership_id, - bg_member.fk_identity_id as member_id, - bg_member.g_role as membership_role, - id_member.name as member_name, - us_member.u_firstname as member_firstname, - us_member.u_lastname as member_lastname, - bg_me.fk_identity_id as me_id, - bgroup.group_id as bg_id, - bgroup.groupname as bg_name - from o_gp_business as bgroup - inner join o_bs_group_member as bg_member on (bg_member.fk_group_id = bgroup.fk_group_id) - inner join o_bs_identity as id_member on (bg_member.fk_identity_id = id_member.id) - inner join o_user as us_member on (id_member.id = us_member.fk_identity) - inner join o_bs_group_member as bg_me on (bg_me.fk_group_id = bgroup.fk_group_id) - where - (bgroup.ownersintern=1 and bg_member.g_role='coach') - or - (bgroup.participantsintern=1 and bg_member.g_role='participant') -); - - --- instant messaging -create or replace view o_im_roster_entry_v as ( - select - entry.id as re_id, - entry.creationdate as re_creationdate, - ident.id as ident_id, - ident.name as ident_name, - entry.r_nickname as re_nickname, - entry.r_fullname as re_fullname, - entry.r_anonym as re_anonym, - entry.r_vip as re_vip, - entry.r_resname as re_resname, - entry.r_resid as re_resid - from o_im_roster_entry as entry - inner join o_bs_identity as ident on (entry.fk_identity_id = ident.id) -); - --- question pool -create or replace view o_qp_pool_2_item_short_v as ( - select - pool2item.id as item_to_pool_id, - pool2item.creationdate as item_to_pool_creationdate, - item.id as item_id, - pool2item.q_editable as item_editable, - pool2item.fk_pool_id as item_pool, - pool.q_name as item_pool_name - from o_qp_item as item - inner join o_qp_pool_2_item as pool2item on (pool2item.fk_item_id = item.id) - inner join o_qp_pool as pool on (pool2item.fk_pool_id = pool.id) -); - -create or replace view o_qp_share_2_item_short_v as ( - select - shareditem.id as item_to_share_id, - shareditem.creationdate as item_to_share_creationdate, - item.id as item_id, - shareditem.q_editable as item_editable, - shareditem.fk_resource_id as resource_id, - bgroup.groupname as resource_name - from o_qp_item as item - inner join o_qp_share_item as shareditem on (shareditem.fk_item_id = item.id) - inner join o_gp_business as bgroup on (shareditem.fk_resource_id = bgroup.fk_resource) -); - -create index ocl_asset_idx on oc_lock (asset); -alter table oc_lock add index FK9E30F4B66115906D (identity_fk), add constraint FK9E30F4B66115906D foreign key (identity_fk) references o_bs_identity (id); - -alter table hibernate_unique_key ENGINE = InnoDB; - -alter table o_forum ENGINE = InnoDB; -alter table o_forum_pseudonym ENGINE = InnoDB; -alter table o_property ENGINE = InnoDB; -alter table o_bs_secgroup ENGINE = InnoDB; -alter table o_bs_group ENGINE = InnoDB; -alter table o_bs_group_member ENGINE = InnoDB; -alter table o_re_to_group ENGINE = InnoDB; -alter table o_bs_grant ENGINE = InnoDB; -alter table o_repositoryentry_cycle ENGINE = InnoDB; -alter table o_lti_outcome ENGINE = InnoDB; -alter table o_user ENGINE = InnoDB; -alter table o_userproperty ENGINE = InnoDB; -alter table o_message ENGINE = InnoDB; -alter table o_temporarykey ENGINE = InnoDB; -alter table o_bs_authentication ENGINE = InnoDB; -alter table o_bs_authentication_history ENGINE = InnoDB; -alter table o_qtiresult ENGINE = InnoDB; -alter table o_qtiresultset ENGINE = InnoDB; -alter table o_bs_identity ENGINE = InnoDB; -alter table o_csp_log ENGINE = InnoDB; -alter table o_olatresource ENGINE = InnoDB; -alter table o_bs_policy ENGINE = InnoDB; -alter table o_bs_namedgroup ENGINE = InnoDB; -alter table o_bs_membership ENGINE = InnoDB; -alter table o_repositoryentry ENGINE = InnoDB; -alter table o_repositoryentry_stats ENGINE = InnoDB; -alter table o_references ENGINE = InnoDB; -alter table o_gp_business ENGINE = InnoDB; -alter table o_gp_bgarea ENGINE = InnoDB; -alter table o_gp_bgtoarea_rel ENGINE = InnoDB; -alter table o_catentry ENGINE = InnoDB; -alter table o_noti_pub ENGINE = InnoDB; -alter table o_noti_sub ENGINE = InnoDB; -alter table o_note ENGINE = InnoDB; -alter table o_lifecycle ENGINE = InnoDB; -alter table o_plock ENGINE = InnoDB; -alter table oc_lock ENGINE = InnoDB; -alter table o_readmessage ENGINE = InnoDB; -alter table o_projectbroker ENGINE = InnoDB; -alter table o_projectbroker_project ENGINE = InnoDB; -alter table o_projectbroker_customfields ENGINE = InnoDB; -alter table o_checkpoint ENGINE = InnoDB; -alter table o_checkpoint_results ENGINE = InnoDB; -alter table o_usercomment ENGINE = InnoDB; -alter table o_userrating ENGINE = InnoDB; -alter table o_mark ENGINE = InnoDB; -alter table o_info_message ENGINE = InnoDB; -alter table o_tag ENGINE = InnoDB; -alter table o_bs_invitation ENGINE = InnoDB; -alter table o_ep_artefact ENGINE = InnoDB; -alter table o_ep_collect_restriction ENGINE = InnoDB; -alter table o_ep_struct_el ENGINE = InnoDB; -alter table o_ep_struct_struct_link ENGINE = InnoDB; -alter table o_ep_struct_artefact_link ENGINE = InnoDB; -alter table o_ep_struct_to_group ENGINE = InnoDB; -alter table o_co_db_entry ENGINE = InnoDB; -alter table o_mail ENGINE = InnoDB; -alter table o_mail_to_recipient ENGINE = InnoDB; -alter table o_mail_recipient ENGINE = InnoDB; -alter table o_mail_attachment ENGINE = InnoDB; -alter table o_ac_offer ENGINE = InnoDB; -alter table o_ac_method ENGINE = InnoDB; -alter table o_ac_offer_access ENGINE = InnoDB; -alter table o_ac_order ENGINE = InnoDB; -alter table o_ac_order_part ENGINE = InnoDB; -alter table o_ac_order_line ENGINE = InnoDB; -alter table o_ac_transaction ENGINE = InnoDB; -alter table o_ac_reservation ENGINE = InnoDB; -alter table o_ac_paypal_transaction ENGINE = InnoDB; -alter table o_ac_auto_advance_order ENGINE = InnoDB; -alter table o_as_eff_statement ENGINE = InnoDB; -alter table o_as_user_course_infos ENGINE = InnoDB; -alter table o_as_mode_course ENGINE = InnoDB; -alter table o_as_entry ENGINE = InnoDB; -alter table o_as_mode_course_to_area ENGINE = InnoDB; -alter table o_cal_use_config ENGINE = InnoDB; -alter table o_cal_import ENGINE = InnoDB; -alter table o_cal_import_to ENGINE = InnoDB; -alter table o_mapper ENGINE = InnoDB; -alter table o_qti_assessmenttest_session ENGINE = InnoDB; -alter table o_qti_assessmentitem_session ENGINE = InnoDB; -alter table o_qti_assessment_response ENGINE = InnoDB; -alter table o_qti_assessment_marks ENGINE = InnoDB; -alter table o_qp_pool ENGINE = InnoDB; -alter table o_qp_taxonomy_level ENGINE = InnoDB; -alter table o_qp_item ENGINE = InnoDB; -alter table o_qp_pool_2_item ENGINE = InnoDB; -alter table o_qp_share_item ENGINE = InnoDB; -alter table o_qp_item_collection ENGINE = InnoDB; -alter table o_qp_collection_2_item ENGINE = InnoDB; -alter table o_qp_edu_context ENGINE = InnoDB; -alter table o_qp_item_type ENGINE = InnoDB; -alter table o_qp_license ENGINE = InnoDB; -alter table o_om_room_reference ENGINE = InnoDB; -alter table o_im_message ENGINE = InnoDB; -alter table o_im_notification ENGINE = InnoDB; -alter table o_im_roster_entry ENGINE = InnoDB; -alter table o_im_preferences ENGINE = InnoDB; -alter table o_ex_task ENGINE = InnoDB; -alter table o_ex_task_modifier ENGINE = InnoDB; -alter table o_checklist ENGINE = InnoDB; -alter table o_cl_checkbox ENGINE = InnoDB; -alter table o_cl_check ENGINE = InnoDB; -alter table o_gta_task_list ENGINE = InnoDB; -alter table o_gta_task ENGINE = InnoDB; -alter table o_gta_task_revision_date ENGINE = InnoDB; -alter table o_gta_mark ENGINE = InnoDB; -alter table o_cer_template ENGINE = InnoDB; -alter table o_cer_certificate ENGINE = InnoDB; -alter table o_rem_reminder ENGINE = InnoDB; -alter table o_rem_sent_reminder ENGINE = InnoDB; -alter table o_goto_organizer ENGINE = InnoDB; -alter table o_goto_meeting ENGINE = InnoDB; -alter table o_goto_registrant ENGINE = InnoDB; -alter table o_vid_transcoding ENGINE = InnoDB; -alter table o_vid_metadata ENGINE = InnoDB; -alter table o_pf_category_relation ENGINE = InnoDB; -alter table o_pf_category ENGINE = InnoDB; -alter table o_pf_media ENGINE = InnoDB; -alter table o_pf_page_part ENGINE = InnoDB; -alter table o_pf_section ENGINE = InnoDB; -alter table o_pf_page_body ENGINE = InnoDB; -alter table o_pf_page ENGINE = InnoDB; -alter table o_pf_binder ENGINE = InnoDB; -alter table o_pf_assessment_section ENGINE = InnoDB; -alter table o_pf_assignment ENGINE = InnoDB; -alter table o_pf_binder_user_infos ENGINE = InnoDB; -alter table o_eva_form_survey ENGINE = InnoDB; -alter table o_eva_form_participation ENGINE = InnoDB; -alter table o_eva_form_session ENGINE = InnoDB; -alter table o_eva_form_response ENGINE = InnoDB; -alter table o_eva_form_survey ENGINE = InnoDB; -alter table o_sms_message_log ENGINE = InnoDB; -alter table o_feed ENGINE = InnoDB; -alter table o_feed_item ENGINE = InnoDB; -alter table o_lecture_reason ENGINE = InnoDB; -alter table o_lecture_block ENGINE = InnoDB; -alter table o_lecture_block_to_group ENGINE = InnoDB; -alter table o_lecture_block_roll_call ENGINE = InnoDB; -alter table o_lecture_reminder ENGINE = InnoDB; -alter table o_lecture_participant_summary ENGINE = InnoDB; -alter table o_lecture_entry_config ENGINE = InnoDB; -alter table o_lecture_block_audit_log ENGINE = InnoDB; -alter table o_tax_taxonomy ENGINE = InnoDB; -alter table o_tax_taxonomy_level_type ENGINE = InnoDB; -alter table o_tax_taxonomy_type_to_type ENGINE = InnoDB; -alter table o_tax_taxonomy_level ENGINE = InnoDB; -alter table o_tax_taxonomy_competence ENGINE = InnoDB; -alter table o_lic_license_type ENGINE = InnoDB; -alter table o_lic_license_type_activation ENGINE = InnoDB; -alter table o_lic_license ENGINE = InnoDB; -alter table o_org_organisation_type ENGINE = InnoDB; -alter table o_org_organisation ENGINE = InnoDB; -alter table o_org_type_to_type ENGINE = InnoDB; -alter table o_re_to_organisation ENGINE = InnoDB; -alter table o_cur_element_type ENGINE = InnoDB; -alter table o_cur_curriculum ENGINE = InnoDB; -alter table o_cur_curriculum_element ENGINE = InnoDB; -alter table o_cur_element_type_to_type ENGINE = InnoDB; - --- rating -alter table o_userrating add constraint FKF26C8375236F20X foreign key (creator_id) references o_bs_identity (id); -create index rtn_id_idx on o_userrating (resid); -create index rtn_name_idx on o_userrating (resname); -create index rtn_subpath_idx on o_userrating (ressubpath(255)); -create index rtn_rating_idx on o_userrating (rating); -create index rtn_rating_res_idx on o_userrating (resid, resname, creator_id, rating); - --- comment -alter table o_usercomment add constraint FK92B6864A18251F0 foreign key (parent_key) references o_usercomment (comment_id); -alter table o_usercomment add constraint FKF26C8375236F20A foreign key (creator_id) references o_bs_identity (id); -create index cmt_id_idx on o_usercomment (resid); -create index cmt_name_idx on o_usercomment (resname); -create index cmt_subpath_idx on o_usercomment (ressubpath(255)); - --- checkpoint -alter table o_checkpoint_results add constraint FK9E30F4B661159ZZY foreign key (checkpoint_fk) references o_checkpoint (checkpoint_id) ; -alter table o_checkpoint_results add constraint FK9E30F4B661159ZZX foreign key (identity_fk) references o_bs_identity (id); - -alter table o_checkpoint add constraint FK9E30F4B661159ZZZ foreign key (checklist_fk) references o_checklist (checklist_id); - --- plock -create index asset_idx on o_plock (asset); - --- property -alter table o_property add constraint FKB60B1BA5190E5 foreign key (grp) references o_gp_business (group_id); -alter table o_property add constraint FKB60B1BA5F7E870BE foreign key (identity) references o_bs_identity (id); - -create index idx_prop_indexresid_idx on o_property (resourcetypeid); -create index idx_prop_category_idx on o_property (category); -create index idx_prop_name_idx on o_property (name); -create index idx_prop_restype_idx on o_property (resourcetypename); - --- group -alter table o_bs_group_member add constraint member_identity_ctx foreign key (fk_identity_id) references o_bs_identity (id); -alter table o_bs_group_member add constraint member_group_ctx foreign key (fk_group_id) references o_bs_group (id); -create index member_to_grp_role_idx on o_bs_group_member (g_role); - -alter table o_re_to_group add constraint re_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); -alter table o_re_to_group add constraint re_to_group_re_ctx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); - -alter table o_gp_business add constraint gp_to_group_business_ctx foreign key (fk_group_id) references o_bs_group (id); - --- business group -alter table o_gp_business add constraint idx_bgp_rsrc foreign key (fk_resource) references o_olatresource (resource_id); - -create index gp_name_idx on o_gp_business (groupname); -create index idx_grp_lifecycle_soft_idx on o_gp_business (external_id); - -alter table o_bs_namedgroup add constraint FKBAFCBBC4B85B522C foreign key (secgroup_id) references o_bs_secgroup (id); -create index groupname_idx on o_bs_namedgroup (groupname); - --- area -alter table o_gp_bgarea add constraint idx_area_to_resource foreign key (fk_resource) references o_olatresource (resource_id); -create index name_idx on o_gp_bgarea (name); - -alter table o_gp_bgtoarea_rel add constraint FK9B663F2D1E2E7685 foreign key (group_fk) references o_gp_business (group_id); -alter table o_gp_bgtoarea_rel add constraint FK9B663F2DD381B9B7 foreign key (area_fk) references o_gp_bgarea (area_id); - --- bs -alter table o_bs_authentication add constraint FKC6A5445652595FE6 foreign key (identity_fk) references o_bs_identity (id); -create index provider_idx on o_bs_authentication (provider); -create index credential_idx on o_bs_authentication (credential); -create index authusername_idx on o_bs_authentication (authusername); - -alter table o_bs_authentication_history add constraint auth_hist_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); - -create index name_idx on o_bs_identity (name); -create index identstatus_idx on o_bs_identity (status); -create index idx_ident_creationdate_idx on o_bs_identity (creationdate); -create index idx_id_lastlogin_idx on o_bs_identity (lastlogin); - - - -alter table o_bs_membership add constraint FK7B6288B45259603C foreign key (identity_id) references o_bs_identity (id); -alter table o_bs_membership add constraint FK7B6288B4B85B522C foreign key (secgroup_id) references o_bs_secgroup (id); - -alter table o_bs_invitation add constraint inv_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); - --- user -create index usr_notification_interval_idx on o_user (notification_interval); -create index idx_user_firstname_idx on o_user (u_firstname); -create index idx_user_lastname_idx on o_user (u_lastname); -create index idx_user_email_idx on o_user (u_email); -create index idx_user_instname_idx on o_user (u_institutionalname); -create index idx_user_instid_idx on o_user (u_institutionaluseridentifier); -create index idx_user_instemail_idx on o_user (u_institutionalemail); -create index idx_user_creationdate_idx on o_user (creationdate); - -alter table o_user add constraint user_to_ident_idx foreign key (fk_identity) references o_bs_identity(id); -alter table o_user add constraint idx_un_user_to_ident_idx UNIQUE (fk_identity); - --- csp -create index idx_csp_log_to_ident_idx on o_csp_log (fk_identity); - --- temporary key -create index idx_tempkey_identity_idx on o_temporarykey (fk_identity_id); - --- pub sub -create index name_idx on o_noti_pub (resname, resid, subident); - -alter table o_noti_sub add constraint FK4FB8F04749E53702 foreign key (fk_publisher) references o_noti_pub (publisher_id); -alter table o_noti_sub add constraint FK4FB8F0476B1F22F8 foreign key (fk_identity) references o_bs_identity (id); - --- qti -alter table o_qtiresultset add constraint FK14805D0F5259603C foreign key (identity_id) references o_bs_identity (id); - -create index oresdetindex on o_qtiresultset (olatresourcedetail); -create index oresindex on o_qtiresultset (olatresource_fk); -create index reprefindex on o_qtiresultset (repositoryref_fk); -create index assindex on o_qtiresultset (assessmentid); - -alter table o_qtiresult add constraint FK3563E67340EF401F foreign key (resultset_fk) references o_qtiresultset (resultset_id); -create index itemindex on o_qtiresult (itemident); - --- catalog entry -alter table o_catentry add constraint FKF4433C2C7B66B0D0 foreign key (parent_id) references o_catentry (id); -alter table o_catentry add constraint FKF4433C2CA1FAC766 foreign key (fk_ownergroup) references o_bs_secgroup (id); -alter table o_catentry add constraint FKF4433C2CDDD69946 foreign key (fk_repoentry) references o_repositoryentry (repositoryentry_id); - --- references -alter table o_references add constraint FKE971B4589AC44FBF foreign key (source_id) references o_olatresource (resource_id); -alter table o_references add constraint FKE971B458CF634A89 foreign key (target_id) references o_olatresource (resource_id); - --- resources -create index name_idx on o_olatresource (resname); -create index id_idx on o_olatresource (resid); - --- repository -alter table o_repositoryentry add constraint FK2F9C439888C31018 foreign key (fk_olatresource) references o_olatresource (resource_id); - -create index access_idx on o_repositoryentry (accesscode); -create index initialAuthor_idx on o_repositoryentry (initialauthor); -create index resource_idx on o_repositoryentry (resourcename); -create index displayname_idx on o_repositoryentry (displayname); -create index softkey_idx on o_repositoryentry (softkey); -create index idx_re_lifecycle_extid_idx on o_repositoryentry (external_id); -create index idx_re_lifecycle_extref_idx on o_repositoryentry (external_ref); - -alter table o_repositoryentry add constraint idx_re_lifecycle_fk foreign key (fk_lifecycle) references o_repositoryentry_cycle(id); -create index idx_re_lifecycle_soft_idx on o_repositoryentry_cycle (r_softkey); - -alter table o_repositoryentry add constraint repoentry_stats_ctx foreign key (fk_stats) references o_repositoryentry_stats (id); - -alter table o_repositoryentry add constraint re_deleted_to_identity_idx foreign key (fk_deleted_by) references o_bs_identity (id); - --- access control -create index ac_offer_to_resource_idx on o_ac_offer (fk_resource_id); - -alter table o_ac_offer_access add constraint off_to_meth_meth_ctx foreign key (fk_method_id) references o_ac_method (method_id); -alter table o_ac_offer_access add constraint off_to_meth_off_ctx foreign key (fk_offer_id) references o_ac_offer (offer_id); - -create index ac_order_to_delivery_idx on o_ac_order (fk_delivery_id); - -alter table o_ac_order_part add constraint ord_part_ord_ctx foreign key (fk_order_id) references o_ac_order (order_id); - -alter table o_ac_order_line add constraint ord_item_ord_part_ctx foreign key (fk_order_part_id) references o_ac_order_part (order_part_id); -alter table o_ac_order_line add constraint ord_item_offer_ctx foreign key (fk_offer_id) references o_ac_offer (offer_id); - -alter table o_ac_transaction add constraint trans_ord_ctx foreign key (fk_order_id) references o_ac_order (order_id); -alter table o_ac_transaction add constraint trans_ord_part_ctx foreign key (fk_order_part_id) references o_ac_order_part (order_part_id); -alter table o_ac_transaction add constraint trans_method_ctx foreign key (fk_method_id) references o_ac_method (method_id); - -create index paypal_pay_key_idx on o_ac_paypal_transaction (pay_key); -create index paypal_pay_trx_id_idx on o_ac_paypal_transaction (ipn_transaction_id); -create index paypal_pay_s_trx_id_idx on o_ac_paypal_transaction (ipn_sender_transaction_id); - -create index idx_ac_aao_id_idx on o_ac_auto_advance_order(id); -create index idx_ac_aao_identifier_idx on o_ac_auto_advance_order(a_identifier_key, a_identifier_value); -create index idx_ac_aao_ident_idx on o_ac_auto_advance_order(fk_identity); -alter table o_ac_auto_advance_order add constraint aao_ident_idx foreign key (fk_identity) references o_bs_identity (id); - --- reservations -alter table o_ac_reservation add constraint idx_rsrv_to_rsrc_rsrc foreign key (fk_resource) references o_olatresource (resource_id); -alter table o_ac_reservation add constraint idx_rsrv_to_rsrc_identity foreign key (fk_identity) references o_bs_identity (id); - --- note -alter table o_note add constraint FKC2D855C263219E27 foreign key (owner_id) references o_bs_identity (id); -create index resid_idx on o_note (resourcetypeid); -create index owner_idx on o_note (owner_id); -create index restype_idx on o_note (resourcetypename); - --- ex_task -alter table o_ex_task add constraint idx_ex_task_ident_id foreign key (fk_identity_id) references o_bs_identity(id); -alter table o_ex_task add constraint idx_ex_task_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); -alter table o_ex_task_modifier add constraint idx_ex_task_mod_ident_id foreign key (fk_identity_id) references o_bs_identity(id); -alter table o_ex_task_modifier add constraint idx_ex_task_mod_task_id foreign key (fk_task_id) references o_ex_task(id); - --- checklist -alter table o_cl_check add constraint check_identity_ctx foreign key (fk_identity_id) references o_bs_identity (id); -alter table o_cl_check add constraint check_box_ctx foreign key (fk_checkbox_id) references o_cl_checkbox (id); -alter table o_cl_check add unique check_identity_unique_ctx (fk_identity_id, fk_checkbox_id); -create index idx_checkbox_uuid_idx on o_cl_checkbox (c_checkboxid); - --- group tasks -alter table o_gta_task add constraint gtask_to_tasklist_idx foreign key (fk_tasklist) references o_gta_task_list (id); -alter table o_gta_task add constraint gtask_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_gta_task add constraint gtask_to_bgroup_idx foreign key (fk_businessgroup) references o_gp_business (group_id); -alter table o_gta_task add constraint gtaskreset_to_allower_idx foreign key (fk_allow_reset_identity) references o_bs_identity (id); - -alter table o_gta_task_list add constraint gta_list_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); - -alter table o_gta_task_revision_date add constraint gtaskrev_to_task_idx foreign key (fk_task) references o_gta_task (id); - -alter table o_gta_mark add constraint gtamark_tasklist_idx foreign key (fk_tasklist_id) references o_gta_task_list (id); - --- reminders -alter table o_rem_reminder add constraint rem_reminder_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_rem_reminder add constraint rem_reminder_to_creator_idx foreign key (fk_creator) references o_bs_identity (id); - -alter table o_rem_sent_reminder add constraint rem_sent_rem_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_rem_sent_reminder add constraint rem_sent_rem_to_reminder_idx foreign key (fk_reminder) references o_rem_reminder (id); - - --- lifecycle -create index lc_pref_idx on o_lifecycle (persistentref); -create index lc_type_idx on o_lifecycle (persistenttypename); -create index lc_action_idx on o_lifecycle (action); - --- mark -alter table o_mark add constraint FKF26C8375236F21X foreign key (creator_id) references o_bs_identity (id); - -create index mark_id_idx on o_mark(resid); -create index mark_name_idx on o_mark(resname); -create index mark_subpath_idx on o_mark(ressubpath(255)); -create index mark_businesspath_idx on o_mark(businesspath(255)); - --- forum -alter table o_message add constraint FKF26C8375236F20E foreign key (creator_id) references o_bs_identity (id); -alter table o_message add constraint FKF26C837A3FBEB83 foreign key (modifier_id) references o_bs_identity (id); -alter table o_message add constraint FKF26C8377B66B0D0 foreign key (parent_id) references o_message (message_id); -alter table o_message add constraint FKF26C8378EAC1DBB foreign key (topthread_id) references o_message (message_id); -alter table o_message add constraint FKF26C8371CB7C4A3 foreign key (forum_fk) references o_forum (forum_id); -create index forum_msg_pseudonym_idx on o_message (pseudonym); - -create index readmessage_forum_idx on o_readmessage (forum_id); -create index readmessage_identity_idx on o_readmessage (identity_id); - -create index forum_pseudonym_idx on o_forum_pseudonym (p_pseudonym); - --- project broker -create index projectbroker_project_broker_idx on o_projectbroker_project (projectbroker_fk); -create index projectbroker_project_id_idx on o_projectbroker_project (project_id); -create index o_projectbroker_customfields_idx on o_projectbroker_customfields (fk_project_id); - --- info messages -alter table o_info_message add constraint FKF85553465A4FA5DC foreign key (fk_author_id) references o_bs_identity (id); -alter table o_info_message add constraint FKF85553465A4FA5EF foreign key (fk_modifier_id) references o_bs_identity (id); - -create index imsg_resid_idx on o_info_message (resid); - --- db course -alter table o_co_db_entry add constraint FK_DB_ENTRY_TO_IDENT foreign key (identity) references o_bs_identity (id); - -create index o_co_db_course_idx on o_co_db_entry (courseid); -create index o_co_db_cat_idx on o_co_db_entry (category); -create index o_co_db_name_idx on o_co_db_entry (name); - --- open meeting -alter table o_om_room_reference add constraint idx_omroom_to_bgroup foreign key (businessgroup) references o_gp_business (group_id); -create index idx_omroom_residname on o_om_room_reference (resourcetypename,resourcetypeid); - --- eportfolio -alter table o_ep_artefact add constraint FKF26C8375236F28X foreign key (fk_artefact_auth_id) references o_bs_identity (id); -alter table o_ep_artefact add constraint FKA0070D12316A97B4 foreign key (fk_struct_el_id) references o_ep_struct_el (structure_id); - -alter table o_ep_struct_el add constraint FKF26C8375236F26X foreign key (fk_olatresource) references o_olatresource (resource_id); -alter table o_ep_struct_el add constraint FK4ECC1C8D636191A1 foreign key (fk_map_source_id) references o_ep_struct_el (structure_id); -alter table o_ep_struct_el add constraint FK4ECC1C8D76990817 foreign key (fk_struct_root_id) references o_ep_struct_el (structure_id); -alter table o_ep_struct_el add constraint FK4ECC1C8D76990818 foreign key (fk_struct_root_map_id) references o_ep_struct_el (structure_id); - -alter table o_ep_collect_restriction add constraint FKA0070D12316A97B5 foreign key (fk_struct_el_id) references o_ep_struct_el (structure_id); - -alter table o_ep_struct_struct_link add constraint FKF26C8375236F22X foreign key (fk_struct_parent_id) references o_ep_struct_el (structure_id); -alter table o_ep_struct_struct_link add constraint FKF26C8375236F23X foreign key (fk_struct_child_id) references o_ep_struct_el (structure_id); - -alter table o_ep_struct_artefact_link add constraint FKF26C8375236F24X foreign key (fk_struct_id) references o_ep_struct_el (structure_id); -alter table o_ep_struct_artefact_link add constraint FKF26C8375236F25X foreign key (fk_artefact_id) references o_ep_artefact (artefact_id); -alter table o_ep_struct_artefact_link add constraint FKF26C8375236F26Y foreign key (fk_auth_id) references o_bs_identity (id); - -alter table o_ep_struct_to_group add constraint struct_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); -alter table o_ep_struct_to_group add constraint struct_to_group_re_ctx foreign key (fk_struct_id) references o_ep_struct_el (structure_id); - --- tag -alter table o_tag add constraint FK6491FCA5A4FA5DC foreign key (fk_author_id) references o_bs_identity (id); - --- mail -alter table o_mail add constraint FKF86663165A4FA5DC foreign key (fk_from_id) references o_mail_recipient (recipient_id); -create index idx_mail_meta_id_idx on o_mail (meta_mail_id); - -alter table o_mail_recipient add constraint FKF86663165A4FA5DG foreign key (fk_recipient_id) references o_bs_identity (id); - -alter table o_mail_to_recipient add constraint FKF86663165A4FA5DE foreign key (fk_mail_id) references o_mail (mail_id); -alter table o_mail_to_recipient add constraint FKF86663165A4FA5DD foreign key (fk_recipient_id) references o_mail_recipient (recipient_id); - -alter table o_mail_attachment add constraint FKF86663165A4FA5DF foreign key (fk_att_mail_id) references o_mail (mail_id); -create index idx_mail_att_checksum_idx on o_mail_attachment (datas_checksum); -create index idx_mail_path_idx on o_mail_attachment (datas_path(255)); -create index idx_mail_att_siblings_idx on o_mail_attachment (datas_checksum, mimetype, datas_size, datas_name); - --- instant messaging -alter table o_im_message add constraint idx_im_msg_to_fromid foreign key (fk_from_identity_id) references o_bs_identity (id); -create index idx_im_msg_res_idx on o_im_message (msg_resid,msg_resname); - -alter table o_im_notification add constraint idx_im_not_to_toid foreign key (fk_to_identity_id) references o_bs_identity (id); -alter table o_im_notification add constraint idx_im_not_to_fromid foreign key (fk_from_identity_id) references o_bs_identity (id); -create index idx_im_chat_res_idx on o_im_notification (chat_resid,chat_resname); - -alter table o_im_roster_entry add constraint idx_im_rost_to_id foreign key (fk_identity_id) references o_bs_identity (id); -create index idx_im_rost_res_idx on o_im_roster_entry (r_resid,r_resname); - -alter table o_im_preferences add constraint idx_im_prfs_to_id foreign key (fk_from_identity_id) references o_bs_identity (id); - --- efficiency statements -alter table o_as_eff_statement add unique eff_statement_id_cstr (fk_identity, fk_resource_id), add constraint eff_statement_id_cstr foreign key (fk_identity) references o_bs_identity (id); -create index eff_statement_repo_key_idx on o_as_eff_statement (course_repo_key); - --- course infos -alter table o_as_user_course_infos add index user_course_infos_id_cstr (fk_identity), add constraint user_course_infos_id_cstr foreign key (fk_identity) references o_bs_identity (id); -alter table o_as_user_course_infos add index user_course_infos_res_cstr (fk_resource_id), add constraint user_course_infos_res_cstr foreign key (fk_resource_id) references o_olatresource (resource_id); -alter table o_as_user_course_infos add unique (fk_identity, fk_resource_id); - -alter table o_as_entry add constraint as_entry_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_as_entry add constraint as_entry_to_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_as_entry add constraint as_entry_to_refentry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); - -create index idx_as_entry_to_id_idx on o_as_entry (a_assessment_id); - --- gotomeeting -alter table o_goto_organizer add constraint goto_organ_owner_idx foreign key (fk_identity) references o_bs_identity (id); -create index idx_goto_organ_okey_idx on o_goto_organizer(g_organizer_key); -create index idx_goto_organ_uname_idx on o_goto_organizer(g_username); - -alter table o_goto_meeting add constraint goto_meet_repoentry_idx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); -alter table o_goto_meeting add constraint goto_meet_busgrp_idx foreign key (fk_group_id) references o_gp_business (group_id); -alter table o_goto_meeting add constraint goto_meet_organizer_idx foreign key (fk_organizer_id) references o_goto_organizer (id); - -alter table o_goto_registrant add constraint goto_regis_meeting_idx foreign key (fk_meeting_id) references o_goto_meeting (id); -alter table o_goto_registrant add constraint goto_regis_ident_idx foreign key (fk_identity_id) references o_bs_identity (id); - --- video -alter table o_vid_transcoding add constraint fk_resource_id_idx foreign key (fk_resource_id) references o_olatresource (resource_id); -create index vid_status_trans_idx on o_vid_transcoding(vid_status); -create index vid_transcoder_trans_idx on o_vid_transcoding(vid_transcoder); -alter table o_vid_metadata add constraint vid_meta_rsrc_idx foreign key (fk_resource_id) references o_olatresource (resource_id); - - --- calendar -alter table o_cal_use_config add constraint cal_u_conf_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); -create index idx_cal_u_conf_cal_id_idx on o_cal_use_config (c_calendar_id); -create index idx_cal_u_conf_cal_type_idx on o_cal_use_config (c_calendar_type); - -alter table o_cal_import add constraint cal_imp_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); -create index idx_cal_imp_cal_id_idx on o_cal_import (c_calendar_id); -create index idx_cal_imp_cal_type_idx on o_cal_import (c_calendar_type); - -create index idx_cal_imp_to_cal_id_idx on o_cal_import_to (c_to_calendar_id); -create index idx_cal_imp_to_cal_type_idx on o_cal_import_to (c_to_calendar_type); - --- mapper -create index o_mapper_uuid_idx on o_mapper (mapper_uuid); - --- qti 2.1 -alter table o_qti_assessmenttest_session add constraint qti_sess_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_qti_assessmenttest_session add constraint qti_sess_to_course_entry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); -alter table o_qti_assessmenttest_session add constraint qti_sess_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_qti_assessmenttest_session add constraint qti_sess_to_as_entry_idx foreign key (fk_assessment_entry) references o_as_entry (id); - -alter table o_qti_assessmentitem_session add constraint qti_itemsess_to_testsess_idx foreign key (fk_assessmenttest_session) references o_qti_assessmenttest_session (id); -create index idx_item_identifier_idx on o_qti_assessmentitem_session (q_itemidentifier); - -alter table o_qti_assessment_response add constraint qti_resp_to_testsession_idx foreign key (fk_assessmenttest_session) references o_qti_assessmenttest_session (id); -alter table o_qti_assessment_response add constraint qti_resp_to_itemsession_idx foreign key (fk_assessmentitem_session) references o_qti_assessmentitem_session (id); -create index idx_response_identifier_idx on o_qti_assessment_response (q_responseidentifier); - -alter table o_qti_assessment_marks add constraint qti_marks_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_qti_assessment_marks add constraint qti_marks_to_course_entry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); -alter table o_qti_assessment_marks add constraint qti_marks_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); - --- portfolio -alter table o_pf_binder add constraint pf_binder_resource_idx foreign key (fk_olatresource_id) references o_olatresource (resource_id); -alter table o_pf_binder add constraint pf_binder_group_idx foreign key (fk_group_id) references o_bs_group (id); -alter table o_pf_binder add constraint pf_binder_course_idx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); -alter table o_pf_binder add constraint pf_binder_template_idx foreign key (fk_template_id) references o_pf_binder (id); - -alter table o_pf_section add constraint pf_section_group_idx foreign key (fk_group_id) references o_bs_group (id); -alter table o_pf_section add constraint pf_section_binder_idx foreign key (fk_binder_id) references o_pf_binder (id); -alter table o_pf_section add constraint pf_section_template_idx foreign key (fk_template_reference_id) references o_pf_section (id); - -alter table o_pf_page add constraint pf_page_group_idx foreign key (fk_group_id) references o_bs_group (id); -alter table o_pf_page add constraint pf_page_section_idx foreign key (fk_section_id) references o_pf_section (id); - -alter table o_pf_page add constraint pf_page_body_idx foreign key (fk_body_id) references o_pf_page_body (id); - -alter table o_pf_media add constraint pf_media_author_idx foreign key (fk_author_id) references o_bs_identity (id); -create index idx_category_rel_resid_idx on o_pf_media (p_business_path); - -alter table o_pf_page_part add constraint pf_page_page_body_idx foreign key (fk_page_body_id) references o_pf_page_body (id); -alter table o_pf_page_part add constraint pf_page_media_idx foreign key (fk_media_id) references o_pf_media (id); -alter table o_pf_page_part add constraint pf_part_form_idx foreign key (fk_form_entry_id) references o_repositoryentry (repositoryentry_id); - -create index idx_category_name_idx on o_pf_category (p_name); - -alter table o_pf_category_relation add constraint pf_category_rel_cat_idx foreign key (fk_category_id) references o_pf_category (id); -create index idx_category_rel_resid_idx on o_pf_category_relation (p_resid); - -alter table o_pf_assessment_section add constraint pf_asection_section_idx foreign key (fk_section_id) references o_pf_section (id); -alter table o_pf_assessment_section add constraint pf_asection_ident_idx foreign key (fk_identity_id) references o_bs_identity (id); - -alter table o_pf_assignment add constraint pf_assign_section_idx foreign key (fk_section_id) references o_pf_section (id); -alter table o_pf_assignment add constraint pf_assign_ref_assign_idx foreign key (fk_template_reference_id) references o_pf_assignment (id); -alter table o_pf_assignment add constraint pf_assign_page_idx foreign key (fk_page_id) references o_pf_page (id); -alter table o_pf_assignment add constraint pf_assign_assignee_idx foreign key (fk_assignee_id) references o_bs_identity (id); -alter table o_pf_assignment add constraint pf_assign_form_idx foreign key (fk_form_entry_id) references o_repositoryentry (repositoryentry_id); - -alter table o_pf_binder_user_infos add constraint binder_user_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_pf_binder_user_infos add constraint binder_user_binder_idx foreign key (fk_binder) references o_pf_binder (id); - -alter table o_pf_page_user_infos add constraint user_pfpage_idx foreign key (fk_identity_id) references o_bs_identity (id); -alter table o_pf_page_user_infos add constraint page_pfpage_idx foreign key (fk_page_id) references o_pf_page (id); - --- evaluation form -create unique index idx_eva_surv_ores_idx on o_eva_form_survey (e_resid, e_resname, e_sub_ident(255)); - -alter table o_eva_form_participation add constraint eva_part_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); -create unique index idx_eva_part_ident_idx on o_eva_form_participation (e_identifier_key, e_identifier_type, fk_survey); -create unique index idx_eva_part_executor_idx on o_eva_form_participation (fk_executor, fk_survey); - -alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); -alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); -alter table o_eva_form_session add constraint eva_sess_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_eva_form_session add constraint eva_sess_to_body_idx foreign key (fk_page_body) references o_pf_page_body (id); -alter table o_eva_form_session add constraint eva_sess_to_form_idx foreign key (fk_form_entry) references o_repositoryentry (repositoryentry_id); -create index idx_eva_surv_ores_idx on o_eva_form_session (e_resid, e_resname, e_sub_ident(255)); - -alter table o_eva_form_response add constraint eva_resp_to_sess_idx foreign key (fk_session) references o_eva_form_session (id); - --- question pool -alter table o_qp_pool add constraint idx_qp_pool_owner_grp_id foreign key (fk_ownergroup) references o_bs_secgroup(id); - -alter table o_qp_pool_2_item add constraint idx_qp_pool_2_item_pool_id foreign key (fk_pool_id) references o_qp_pool(id); -alter table o_qp_pool_2_item add constraint idx_qp_pool_2_item_item_id foreign key (fk_item_id) references o_qp_item(id); -alter table o_qp_pool_2_item add unique (fk_pool_id, fk_item_id); - -alter table o_qp_share_item add constraint idx_qp_share_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); -alter table o_qp_share_item add constraint idx_qp_share_item_id foreign key (fk_item_id) references o_qp_item(id); -alter table o_qp_share_item add unique (fk_resource_id, fk_item_id); - -alter table o_qp_item_collection add constraint idx_qp_coll_owner_id foreign key (fk_owner_id) references o_bs_identity(id); - -alter table o_qp_collection_2_item add constraint idx_qp_coll_coll_id foreign key (fk_collection_id) references o_qp_item_collection(id); -alter table o_qp_collection_2_item add constraint idx_qp_coll_item_id foreign key (fk_item_id) references o_qp_item(id); -alter table o_qp_collection_2_item add unique (fk_collection_id, fk_item_id); - -alter table o_qp_item add constraint idx_qp_pool_2_tax_id foreign key (fk_taxonomy_level_v2) references o_tax_taxonomy_level(id); -alter table o_qp_item add constraint idx_qp_item_owner_id foreign key (fk_ownergroup) references o_bs_secgroup(id); -alter table o_qp_item add constraint idx_qp_item_edu_ctxt_id foreign key (fk_edu_context) references o_qp_edu_context(id); -alter table o_qp_item add constraint idx_qp_item_type_id foreign key (fk_type) references o_qp_item_type(id); -alter table o_qp_item add constraint idx_qp_item_license_id foreign key (fk_license) references o_qp_license(id); - -alter table o_qp_taxonomy_level add constraint idx_qp_field_2_parent_id foreign key (fk_parent_field) references o_qp_taxonomy_level(id); -create index idx_taxon_mat_pathon on o_qp_taxonomy_level (q_mat_path_ids(255)); - -alter table o_qp_item_type add unique (q_type(200)); -create index idx_item_audit_item_idx on o_qp_item_audit_log (fk_item_id); - --- lti outcome -alter table o_lti_outcome add constraint idx_lti_outcome_ident_id foreign key (fk_identity_id) references o_bs_identity(id); -alter table o_lti_outcome add constraint idx_lti_outcome_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); - --- assessment mode -alter table o_as_mode_course add constraint as_mode_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); - -alter table o_as_mode_course_to_group add constraint as_modetogroup_group_idx foreign key (fk_group_id) references o_gp_business (group_id); -alter table o_as_mode_course_to_group add constraint as_modetogroup_mode_idx foreign key (fk_assessment_mode_id) references o_as_mode_course (id); - -alter table o_as_mode_course_to_area add constraint as_modetoarea_area_idx foreign key (fk_area_id) references o_gp_bgarea (area_id); -alter table o_as_mode_course_to_area add constraint as_modetoarea_mode_idx foreign key (fk_assessment_mode_id) references o_as_mode_course (id); - --- certificate -alter table o_cer_certificate add constraint cer_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); -alter table o_cer_certificate add constraint cer_to_resource_idx foreign key (fk_olatresource) references o_olatresource (resource_id); - -create index cer_archived_resource_idx on o_cer_certificate (c_archived_resource_id); -create index cer_uuid_idx on o_cer_certificate (c_uuid); - --- sms -alter table o_sms_message_log add constraint sms_log_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); - --- webfeed -create index idx_feed_resourceable_idx on o_feed (f_resourceable_id, f_resourceable_type); -alter table o_feed_item add constraint item_to_feed_fk foreign key(fk_feed_id) references o_feed(id); -create index idx_item_feed_idx on o_feed_item(fk_feed_id); -alter table o_feed_item add constraint feed_item_to_ident_author_fk foreign key (fk_identity_author_id) references o_bs_identity (id); -create index idx_item_ident_author_idx on o_feed_item(fk_identity_author_id); -alter table o_feed_item add constraint feed_item_to_ident_modified_fk foreign key (fk_identity_modified_id) references o_bs_identity (id); -create index idx_item_ident_modified_idx on o_feed_item(fk_identity_modified_id); - --- lecture -alter table o_lecture_block add constraint lec_block_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_lecture_block add constraint lec_block_gcoach_idx foreign key (fk_teacher_group) references o_bs_group (id); -alter table o_lecture_block add constraint lec_block_reason_idx foreign key (fk_reason) references o_lecture_reason (id); - -alter table o_lecture_block_to_group add constraint lec_block_to_block_idx foreign key (fk_group) references o_bs_group (id); -alter table o_lecture_block_to_group add constraint lec_block_to_group_idx foreign key (fk_lecture_block) references o_lecture_block (id); - -alter table o_lecture_block_roll_call add constraint lec_call_block_idx foreign key (fk_lecture_block) references o_lecture_block (id); -alter table o_lecture_block_roll_call add constraint lec_call_identity_idx foreign key (fk_identity) references o_bs_identity (id); - -alter table o_lecture_reminder add constraint lec_reminder_block_idx foreign key (fk_lecture_block) references o_lecture_block (id); -alter table o_lecture_reminder add constraint lec_reminder_identity_idx foreign key (fk_identity) references o_bs_identity (id); - -alter table o_lecture_participant_summary add constraint lec_part_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_lecture_participant_summary add constraint lec_part_ident_idx foreign key (fk_identity) references o_bs_identity (id); - -alter table o_lecture_entry_config add constraint lec_entry_config_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); - -create index idx_lec_audit_entry_idx on o_lecture_block_audit_log(fk_entry); -create index idx_lec_audit_ident_idx on o_lecture_block_audit_log(fk_identity); - --- taxonomy -alter table o_tax_taxonomy add constraint tax_to_group_idx foreign key (fk_group) references o_bs_group (id); - -alter table o_tax_taxonomy_level_type add constraint tax_type_to_taxonomy_idx foreign key (fk_taxonomy) references o_tax_taxonomy (id); - -alter table o_tax_taxonomy_type_to_type add constraint tax_type_to_type_idx foreign key (fk_type) references o_tax_taxonomy_level_type (id); -create index idx_tax_type_to_type_idx on o_tax_taxonomy_type_to_type (fk_type); -alter table o_tax_taxonomy_type_to_type add constraint tax_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_tax_taxonomy_level_type (id); -create index idx_tax_type_to_sub_type_idx on o_tax_taxonomy_type_to_type (fk_allowed_sub_type); - -alter table o_tax_taxonomy_level add constraint tax_level_to_taxonomy_idx foreign key (fk_taxonomy) references o_tax_taxonomy (id); -alter table o_tax_taxonomy_level add constraint tax_level_to_tax_level_idx foreign key (fk_parent) references o_tax_taxonomy_level (id); -alter table o_tax_taxonomy_level add constraint tax_level_to_type_idx foreign key (fk_type) references o_tax_taxonomy_level_type (id); -create index idx_tax_level_path_key_idx on o_tax_taxonomy_level (t_m_path_keys); - -alter table o_tax_taxonomy_competence add constraint tax_comp_to_tax_level_idx foreign key (fk_level) references o_tax_taxonomy_level (id); -alter table o_tax_taxonomy_competence add constraint tax_level_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); - --- dialog elements -alter table o_dialog_element add constraint dial_el_author_idx foreign key (fk_author) references o_bs_identity (id); -alter table o_dialog_element add constraint dial_el_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_dialog_element add constraint dial_el_forum_idx foreign key (fk_forum) references o_forum (forum_id); -create index idx_dial_el_subident_idx on o_dialog_element (d_subident); - --- licenses -alter table o_lic_license_type_activation add constraint lic_activation_type_fk foreign key (fk_license_type_id) references o_lic_license_type (id); -create index lic_activation_type_idx on o_lic_license_type_activation (fk_license_type_id); -alter table o_lic_license add constraint lic_license_type_fk foreign key (fk_license_type_id) references o_lic_license_type (id); -create index lic_license_type_idx on o_lic_license (fk_license_type_id); -create unique index lic_license_ores_idx on o_lic_license (l_resid, l_resname); - --- organisation -alter table o_org_organisation add constraint org_to_group_idx foreign key (fk_group) references o_bs_group (id); -alter table o_org_organisation add constraint org_to_root_org_idx foreign key (fk_root) references o_org_organisation (id); -alter table o_org_organisation add constraint org_to_parent_org_idx foreign key (fk_parent) references o_org_organisation (id); -alter table o_org_organisation add constraint org_to_org_type_idx foreign key (fk_type) references o_org_organisation_type (id); - -alter table o_org_type_to_type add constraint org_type_to_type_idx foreign key (fk_type) references o_org_organisation_type (id); -alter table o_org_type_to_type add constraint org_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_org_organisation_type (id); - -alter table o_re_to_organisation add constraint rel_org_to_re_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); -alter table o_re_to_organisation add constraint rel_org_to_org_idx foreign key (fk_organisation) references o_org_organisation (id); - --- curriculum -alter table o_cur_curriculum add constraint cur_to_group_idx foreign key (fk_group) references o_bs_group (id); -alter table o_cur_curriculum add constraint cur_to_org_idx foreign key (fk_organisation) references o_org_organisation (id); - -alter table o_cur_curriculum_element add constraint cur_el_to_group_idx foreign key (fk_group) references o_bs_group (id); -alter table o_cur_curriculum_element add constraint cur_el_to_cur_el_idx foreign key (fk_parent) references o_cur_curriculum_element (id); -alter table o_cur_curriculum_element add constraint cur_el_to_cur_idx foreign key (fk_curriculum) references o_cur_curriculum (id); - -alter table o_cur_element_type_to_type add constraint cur_type_to_type_idx foreign key (fk_type) references o_cur_element_type (id); -alter table o_cur_element_type_to_type add constraint cur_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_cur_element_type (id); - --- o_logging_table -create index log_target_resid_idx on o_loggingtable(targetresid); -create index log_ptarget_resid_idx on o_loggingtable(parentresid); -create index log_gptarget_resid_idx on o_loggingtable(grandparentresid); -create index log_ggptarget_resid_idx on o_loggingtable(greatgrandparentresid); -create index log_creationdate_idx on o_loggingtable(creationdate); - - -insert into hibernate_unique_key values ( 0 ); -SET FOREIGN_KEY_CHECKS = 1; + SET FOREIGN_KEY_CHECKS = 0; + + create table if not exists o_forum ( + forum_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + primary key (forum_id) + ); + create table o_forum_pseudonym ( + id bigint not null auto_increment, + creationdate datetime not null, + p_pseudonym varchar(255) not null, + p_credential varchar(255) not null, + p_salt varchar(255) not null, + p_hashalgorithm varchar(16) not null, + primary key (id) + ); + create table if not exists o_property ( + id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + identity bigint, + grp bigint, + resourcetypename varchar(50), + resourcetypeid bigint, + category varchar(33), + name varchar(255) not null, + floatvalue FLOAT(65,30), + longvalue bigint, + stringvalue varchar(255), + textvalue longtext, + primary key (id) + ); + create table if not exists o_bs_secgroup ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + primary key (id) + ); + + create table o_bs_group ( + id bigint not null, + creationdate datetime not null, + g_name varchar(36), + primary key (id) + ); + + create table o_bs_group_member ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_role varchar(50) not null, + g_inheritance_mode varchar(16) default 'none' not null, + fk_group_id bigint not null, + fk_identity_id bigint not null, + primary key (id) + ); + + create table o_bs_grant ( + id bigint not null, + creationdate datetime not null, + g_role varchar(32) not null, + g_permission varchar(32) not null, + fk_group_id bigint not null, + fk_resource_id bigint not null, + primary key (id) + ); + + create table if not exists o_gp_business ( + group_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + lastusage datetime, + groupname varchar(255), + external_id varchar(64), + managed_flags varchar(255), + descr longtext, + minparticipants integer, + maxparticipants integer, + waitinglist_enabled bit, + autocloseranks_enabled bit, + ownersintern bit not null default 0, + participantsintern bit not null default 0, + waitingintern bit not null default 0, + ownerspublic bit not null default 0, + participantspublic bit not null default 0, + waitingpublic bit not null default 0, + downloadmembers bit not null default 0, + allowtoleave bit not null default 1, + fk_resource bigint unique, + fk_group_id bigint unique, + primary key (group_id) + ); + create table if not exists o_temporarykey ( + reglist_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + email varchar(255) not null, + regkey varchar(255) not null, + ip varchar(255) not null, + mailsent bit not null, + action varchar(255) not null, + fk_identity_id bigint, + primary key (reglist_id) + ); + create table if not exists o_bs_authentication ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + lastmodified datetime not null, + identity_fk bigint not null, + provider varchar(8), + authusername varchar(255), + credential varchar(255), + salt varchar(255) default null, + hashalgorithm varchar(16) default null, + primary key (id), + unique (provider, authusername) + ); + create table if not exists o_bs_authentication_history ( + id bigint not null auto_increment, + creationdate datetime, + provider varchar(8), + authusername varchar(255), + credential varchar(255), + salt varchar(255) default null, + hashalgorithm varchar(16) default null, + fk_identity bigint not null, + primary key (id) + ); + create table if not exists o_noti_pub ( + publisher_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + publishertype varchar(50) not null, + data longtext, + resname varchar(50), + resid bigint, + subident varchar(128), + businesspath varchar(255), + state integer, + latestnews datetime not null, + primary key (publisher_id) + ); + create table if not exists o_qtiresultset ( + resultset_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime not null, + creationdate datetime, + identity_id bigint not null, + olatresource_fk bigint not null, + olatresourcedetail varchar(255) not null, + assessmentid bigint not null, + repositoryref_fk bigint not null, + ispassed bit, + issuspended bit default 0, + fullyassessed bit default 0, + score FLOAT(65,30), + duration bigint, + primary key (resultset_id) + ); + create table if not exists o_bs_identity ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + lastlogin datetime, + name varchar(128) not null unique, + external_id varchar(64), + status integer, + primary key (id) + ); + create table o_csp_log ( + id bigint not null auto_increment, + creationdate datetime, + l_blocked_uri varchar(1024), + l_disposition varchar(32), + l_document_uri varchar(1024), + l_effective_directive mediumtext, + l_original_policy mediumtext, + l_referrer varchar(1024), + l_script_sample mediumtext, + l_status_code varchar(1024), + l_violated_directive varchar(1024), + l_source_file varchar(1024), + l_line_number bigint, + l_column_number bigint, + fk_identity bigint, + primary key (id) + ); + create table if not exists o_olatresource ( + resource_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + resname varchar(50) not null, + resid bigint not null, + primary key (resource_id), + unique (resname, resid) + ); + create table if not exists o_bs_namedgroup ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + secgroup_id bigint not null, + groupname varchar(16), + primary key (id), + unique (groupname) + ); + create table if not exists o_catentry ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + name varchar(110) not null, + description longtext, + style varchar(16), + externalurl varchar(255), + fk_repoentry bigint, + fk_ownergroup bigint unique, + type integer not null, + parent_id bigint, + primary key (id) + ); + create table if not exists o_note ( + note_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + owner_id bigint, + resourcetypename varchar(50) not null, + resourcetypeid bigint not null, + sub_type varchar(50), + notetitle varchar(255), + notetext longtext, + primary key (note_id) + ); + create table if not exists o_references ( + reference_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + source_id bigint not null, + target_id bigint not null, + userdata varchar(64), + primary key (reference_id) + ); + create table if not exists o_user ( + user_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + language varchar(30), + fontsize varchar(10), + notification_interval varchar(16), + presencemessagespublic bit, + informsessiontimeout bit not null, + receiverealmail varchar(16), + u_firstname varchar(255), + u_lastname varchar(255), + u_email varchar(255), + u_birthday varchar(255), + u_graduation varchar(255), + u_gender varchar(255), + u_telprivate varchar(255), + u_telmobile varchar(255), + u_teloffice varchar(255), + u_smstelmobile varchar(255), + u_skype varchar(255), + u_msn varchar(255), + u_xing varchar(255), + u_icq varchar(255), + u_homepage varchar(255), + u_street varchar(255), + u_extendedaddress varchar(255), + u_pobox varchar(255), + u_zipcode varchar(255), + u_region varchar(255), + u_city varchar(255), + u_country varchar(255), + u_countrycode varchar(255), + u_institutionalname varchar(255), + u_institutionaluseridentifier varchar(255), + u_institutionalemail varchar(255), + u_orgunit varchar(255), + u_studysubject varchar(255), + u_emchangekey varchar(255), + u_emaildisabled varchar(255), + u_typeofuser varchar(255), + u_socialsecuritynumber varchar(255), + + u_rank varchar(255), + u_degree varchar(255), + u_position varchar(255), + u_userinterests varchar(255), + u_usersearchedinterests varchar(255), + u_officestreet varchar(255), + u_extendedofficeaddress varchar(255), + u_officepobox varchar(255), + u_officezipcode varchar(255), + u_officecity varchar(255), + u_officecountry varchar(255), + u_officemobilephone varchar(255), + u_department varchar(255), + u_privateemail varchar(255), + u_employeenumber varchar(255), + u_organizationalunit varchar(255), + + u_edupersonaffiliation varchar(255), + u_swissedupersonstaffcategory varchar(255), + u_swissedupersonhomeorg varchar(255), + u_swissedupersonstudylevel varchar(255), + u_swissedupersonhomeorgtype varchar(255), + u_swissedupersonstudybranch1 varchar(255), + u_swissedupersonstudybranch2 varchar(255), + u_swissedupersonstudybranch3 varchar(255), + + u_genericselectionproperty varchar(255), + u_genericselectionproperty2 varchar(255), + u_genericselectionproperty3 varchar(255), + u_generictextproperty varchar(255), + u_generictextproperty2 varchar(255), + u_generictextproperty3 varchar(255), + u_generictextproperty4 varchar(255), + u_generictextproperty5 varchar(255), + u_genericuniquetextproperty varchar(255), + u_genericuniquetextproperty2 varchar(255), + u_genericuniquetextproperty3 varchar(255), + u_genericemailproperty1 varchar(255), + u_genericcheckboxproperty varchar(255), + u_genericcheckboxproperty2 varchar(255), + u_genericcheckboxproperty3 varchar(255), + + fk_identity bigint, + primary key (user_id) + ); + create table if not exists o_userproperty ( + fk_user_id bigint not null, + propname varchar(255) not null, + propvalue varchar(255), + primary key (fk_user_id, propname) + ); + create table if not exists o_message ( + message_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + title varchar(100), + body longtext, + pseudonym varchar(255), + guest bit default 0, + parent_id bigint, + topthread_id bigint, + creator_id bigint, + modifier_id bigint, + forum_fk bigint, + statuscode integer, + numofwords integer, + numofcharacters integer, + primary key (message_id) + ); + + + + create table if not exists o_gp_bgtoarea_rel ( + bgtoarea_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + group_fk bigint not null, + area_fk bigint not null, + primary key (bgtoarea_id), + unique (group_fk, area_fk) + ); + create table if not exists o_noti_sub ( + publisher_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + fk_publisher bigint not null, + fk_identity bigint not null, + latestemailed datetime, + primary key (publisher_id), + unique (fk_publisher, fk_identity) + ); + create table if not exists o_qtiresult ( + result_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime not null, + creationdate datetime, + itemident varchar(255) not null, + answer longtext, + duration bigint, + score FLOAT(65,30), + tstamp datetime not null, + ip varchar(255), + resultset_fk bigint, + primary key (result_id) + ); + create table if not exists o_bs_policy ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + oresource_id bigint not null, + group_id bigint not null, + permission varchar(16) not null, + apply_from datetime default null, + apply_to datetime default null, + primary key (id), + unique (oresource_id, group_id, permission) + ); + create table if not exists o_gp_bgarea ( + area_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + name varchar(255) not null, + descr longtext, + fk_resource bigint default null, + primary key (area_id) + ); + create table if not exists o_repositoryentry ( + repositoryentry_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + softkey varchar(36) not null unique, + external_id varchar(64), + external_ref varchar(64), + managed_flags varchar(255), + displayname varchar(110) not null, + resourcename varchar(100) not null, + authors varchar(2048), + mainlanguage varchar(255), + location varchar(255), + objectives varchar(2048), + requirements varchar(2048), + credits varchar(2048), + expenditureofwork varchar(255), + fk_stats bigint not null unique, + fk_lifecycle bigint, + fk_olatresource bigint unique, + description longtext, + initialauthor varchar(128) not null, + accesscode integer not null default 0, + membersonly bit default 0, + statuscode integer, + allowtoleave varchar(16), + canlaunch bit not null, + candownload bit not null, + cancopy bit not null, + canreference bit not null, + deletiondate datetime default null, + fk_deleted_by bigint default null, + primary key (repositoryentry_id) + ); + create table o_re_to_group ( + id bigint not null, + creationdate datetime not null, + r_defgroup boolean not null, + fk_group_id bigint not null, + fk_entry_id bigint not null, + primary key (id) + ); + create table o_repositoryentry_cycle ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + r_softkey varchar(64), + r_label varchar(255), + r_privatecycle bit default 0, + r_validfrom datetime, + r_validto datetime, + primary key (id) + ); + create table o_repositoryentry_stats ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + r_rating decimal(65,30), + r_num_of_ratings bigint not null default 0, + r_num_of_comments bigint not null default 0, + r_launchcounter bigint not null default 0, + r_downloadcounter bigint not null default 0, + r_lastusage datetime not null, + primary key (id) + ); + create table if not exists o_bs_membership ( + id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + secgroup_id bigint not null, + identity_id bigint not null, + primary key (id), + unique (secgroup_id, identity_id) + ); + + create table if not exists o_plock ( + plock_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + asset varchar(255) not null unique, + primary key (plock_id) + ); + + create table if not exists hibernate_unique_key ( + next_hi integer + ); + + create table if not exists o_lifecycle ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + persistenttypename varchar(50) not null, + persistentref bigint not null, + action varchar(50) not null, + lctimestamp datetime, + uservalue longtext, + primary key (id) + ); + + create table if not exists oc_lock ( + lock_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + identity_fk bigint not null, + asset varchar(120) not null unique, + primary key (lock_id) + ); + + create table if not exists o_readmessage ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + identity_id bigint not null, + forum_id bigint not null, + message_id bigint not null, + primary key (id) + ); + + create table if not exists o_loggingtable ( + log_id bigint not null, + creationdate datetime, + sourceclass varchar(255), + sessionid varchar(255) not null, + user_id bigint, + username varchar(255), + userproperty1 varchar(255), + userproperty2 varchar(255), + userproperty3 varchar(255), + userproperty4 varchar(255), + userproperty5 varchar(255), + userproperty6 varchar(255), + userproperty7 varchar(255), + userproperty8 varchar(255), + userproperty9 varchar(255), + userproperty10 varchar(255), + userproperty11 varchar(255), + userproperty12 varchar(255), + actioncrudtype varchar(1) not null, + actionverb varchar(16) not null, + actionobject varchar(32) not null, + simpleduration bigint not null, + resourceadminaction boolean not null, + businesspath varchar(2048), + greatgrandparentrestype varchar(32), + greatgrandparentresid varchar(64), + greatgrandparentresname varchar(255), + grandparentrestype varchar(32), + grandparentresid varchar(64), + grandparentresname varchar(255), + parentrestype varchar(32), + parentresid varchar(64), + parentresname varchar(255), + targetrestype varchar(32), + targetresid varchar(64), + targetresname varchar(255), + primary key (log_id) + ); + + create table if not exists o_checklist ( + checklist_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime not null, + title varchar(255), + description longtext, + primary key (checklist_id) + ); + + create table if not exists o_checkpoint ( + checkpoint_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime not null, + title varchar(255), + description longtext, + modestring varchar(64) not null, + checklist_fk bigint, + primary key (checkpoint_id) + ); + + create table if not exists o_checkpoint_results ( + checkpoint_result_id bigint not null, + version mediumint unsigned not null, + lastmodified datetime not null, + result bool not null, + checkpoint_fk bigint, + identity_fk bigint, + primary key (checkpoint_result_id) + ); + + create table if not exists o_projectbroker ( + projectbroker_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + primary key (projectbroker_id) + ); + + create table if not exists o_projectbroker_project ( + project_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + title varchar(150), + description longtext, + state varchar(20), + maxMembers integer, + attachmentFileName varchar(100), + mailNotificationEnabled boolean not null, + projectgroup_fk bigint not null, + projectbroker_fk bigint not null, + candidategroup_fk bigint not null, + primary key (project_id) + ); + + create table if not exists o_projectbroker_customfields ( + fk_project_id bigint not null, + propname varchar(255) not null, + propvalue varchar(255), + primary key (fk_project_id, propname) + ); + + create table if not exists o_usercomment ( + comment_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + resname varchar(50) not null, + resid bigint not null, + ressubpath varchar(2048), + creator_id bigint not null, + commenttext longtext, + parent_key bigint, + primary key (comment_id) + ); + create table if not exists o_userrating ( + rating_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + lastmodified datetime, + resname varchar(50) not null, + resid bigint not null, + ressubpath varchar(2048), + creator_id bigint not null, + rating integer not null, + primary key (rating_id) + ); + + create table o_co_db_entry ( + id bigint not null, + version bigint not null, + lastmodified datetime, + creationdate datetime, + courseid bigint, + identity bigint, + category varchar(32), + name varchar(255) not null, + floatvalue decimal(65,30), + longvalue bigint, + stringvalue varchar(255), + textvalue mediumtext, + primary key (id) + ); + + create table if not exists o_stat_lastupdated ( + + lastupdated datetime not null + + ); + -- important: initialize with old date! + insert into o_stat_lastupdated values(date('1999-01-01')); + + + -- insert into o_stat_dayofweek (businesspath,resid,day,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,dayofweek(creationdate) day,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,day; + create table if not exists o_stat_dayofweek ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + day int not null, + value int not null, + primary key (id) + + ); + create index statdow_resid_idx on o_stat_dayofweek (resid); + + + -- insert into o_stat_hourofday (businesspath,resid,hour,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,hour(creationdate) hour,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,hour; + create table if not exists o_stat_hourofday ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + hour int not null, + value int not null, + primary key (id) + + ); + create index stathod_resid_idx on o_stat_hourofday (resid); + + + -- insert into o_stat_weekly (businesspath,resid,week,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,concat(year(creationdate),'-',week(creationdate)) week,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,week; + create table if not exists o_stat_weekly ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + week varchar(7) not null, + value int not null, + primary key (id) + + ); + create index statwee_resid_idx on o_stat_weekly (resid); + + + -- insert into o_stat_daily (businesspath,resid,day,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,date(creationdate) day,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,day; + create table if not exists o_stat_daily ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + day datetime not null, + value int not null, + primary key (id) + + ); + create index statday_resid_idx on o_stat_daily (resid); + + + -- insert into o_stat_homeorg (businesspath,resid,homeorg,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty2 homeorg,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,homeorg; + create table if not exists o_stat_homeorg ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + homeorg varchar(255) not null, + value int not null, + primary key (id) + + ); + create index stathor_resid_idx on o_stat_homeorg (resid); + + + -- insert into o_stat_orgtype (businesspath,resid,orgtype,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty4 orgtype,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,orgtype; + create table if not exists o_stat_orgtype ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + orgtype varchar(255), + value int not null, + primary key (id) + + ); + create index statorg_resid_idx on o_stat_orgtype (resid); + + + -- insert into o_stat_studylevel (businesspath,resid,studylevel,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty3 studylevel,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,studylevel; + create table if not exists o_stat_studylevel ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + studylevel varchar(255) not null, + value int not null, + primary key (id) + + ); + create index statstl_resid_idx on o_stat_studylevel (resid); + + + -- insert into o_stat_studybranch3 (businesspath,resid,studybranch3,value) select businesspath,substr(businesspath,locate(':',businesspath)+1,locate(']',businesspath)-locate(':',businesspath)-1) resid,userproperty10 studybranch3,count(*) cnt from o_loggingtable where actionverb='launch' and actionobject='node' group by businesspath,studybranch3; + create table if not exists o_stat_studybranch3 ( + + id bigint unsigned not null auto_increment, + businesspath varchar(2048) not null, + resid bigint not null, + studybranch3 varchar(255), + value int not null, + primary key (id) + + ); + create index statstb_resid_idx on o_stat_studybranch3 (resid); + + + create table if not exists o_mark ( + mark_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + resname varchar(50) not null, + resid bigint not null, + ressubpath varchar(2048), + businesspath varchar(2048), + creator_id bigint not null, + primary key (mark_id) + ); + + create table if not exists o_info_message ( + info_id bigint NOT NULL, + version mediumint NOT NULL, + creationdate datetime, + modificationdate datetime, + title varchar(2048), + message longtext, + attachmentpath varchar(1024), + resname varchar(50) NOT NULL, + resid bigint NOT NULL, + ressubpath varchar(2048), + businesspath varchar(2048), + fk_author_id bigint, + fk_modifier_id bigint, + primary key (info_id) + ); + + + create table if not exists o_tag ( + tag_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + tag varchar(128) not null, + resname varchar(50) not null, + resid bigint not null, + ressubpath varchar(2048), + businesspath varchar(2048), + fk_author_id bigint not null, + primary key (tag_id) + ); + + create table if not exists o_bs_invitation ( + id bigint not null, + creationdate datetime, + token varchar(64) not null, + first_name varchar(64), + last_name varchar(64), + mail varchar(128), + fk_group_id bigint, + primary key (id) + ); + + create table if not exists o_ep_artefact ( + artefact_id bigint not null, + artefact_type varchar(32) not null, + version mediumint unsigned not null, + creationdate datetime, + collection_date datetime, + title varchar(512), + description varchar(4000), + signature mediumint default 0, + businesspath varchar(2048), + fulltextcontent longtext, + reflexion longtext, + source varchar(2048), + add_prop1 varchar(2048), + add_prop2 varchar(2048), + add_prop3 varchar(2048), + fk_struct_el_id bigint, + fk_artefact_auth_id bigint not null, + primary key (artefact_id) + ); + create table if not exists o_ep_collect_restriction ( + collect_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + artefact_type varchar(256), + amount mediumint not null default -1, + restriction varchar(32), + pos mediumint unsigned not null default 0, + fk_struct_el_id bigint, + primary key (collect_id) + ); + create table if not exists o_ep_struct_el ( + structure_id bigint not null, + structure_type varchar(32) not null, + version mediumint unsigned not null, + creationdate datetime, + returndate datetime default null, + copydate datetime default null, + lastsyncheddate datetime default null, + deadline datetime default null, + title varchar(512), + description varchar(2048), + struct_el_source bigint, + target_resname varchar(50), + target_resid bigint, + target_ressubpath varchar(2048), + target_businesspath varchar(2048), + style varchar(128), + status varchar(32), + viewmode varchar(32), + fk_struct_root_id bigint, + fk_struct_root_map_id bigint, + fk_map_source_id bigint, + fk_group_id bigint, + fk_olatresource bigint not null, + primary key (structure_id) + ); + create table if not exists o_ep_struct_struct_link ( + link_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + pos mediumint unsigned not null default 0, + fk_struct_parent_id bigint not null, + fk_struct_child_id bigint not null, + primary key (link_id) + ); + create table if not exists o_ep_struct_artefact_link ( + link_id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + pos mediumint unsigned not null default 0, + reflexion longtext, + fk_auth_id bigint, + fk_struct_id bigint not null, + fk_artefact_id bigint not null, + primary key (link_id) + ); + create table o_ep_struct_to_group ( + id bigint not null, + creationdate datetime not null, + r_defgroup boolean not null, + r_role varchar(64), + r_valid_from datetime, + r_valid_to datetime, + fk_group_id bigint, + fk_struct_id bigint, + primary key (id) + ); + + -- mail system + + create table if not exists o_mail ( + mail_id bigint NOT NULL, + meta_mail_id varchar(64), + creationdate datetime, + lastmodified datetime, + resname varchar(50), + resid bigint, + ressubpath varchar(2048), + businesspath varchar(2048), + subject varchar(512), + body longtext, + fk_from_id bigint, + primary key (mail_id) + ); + + -- mail recipient + create table if not exists o_mail_to_recipient ( + pos mediumint NOT NULL default 0, + fk_mail_id bigint, + fk_recipient_id bigint + ); + + create table if not exists o_mail_recipient ( + recipient_id bigint NOT NULL, + recipientvisible bit, + deleted bit, + mailread bit, + mailmarked bit, + email varchar(255), + recipientgroup varchar(255), + creationdate datetime, + fk_recipient_id bigint, + primary key (recipient_id) + ); + + -- mail attachments + create table o_mail_attachment ( + attachment_id bigint NOT NULL, + creationdate datetime, + datas mediumblob, + datas_size bigint, + datas_name varchar(255), + datas_checksum bigint, + datas_path varchar(1024), + datas_lastmodified datetime, + mimetype varchar(255), + fk_att_mail_id bigint, + primary key (attachment_id) + ); + + -- access control + create table if not exists o_ac_offer ( + offer_id bigint NOT NULL, + creationdate datetime, + lastmodified datetime, + is_valid bit default 1, + validfrom datetime, + validto datetime, + version mediumint unsigned not null, + resourceid bigint, + resourcetypename varchar(255), + resourcedisplayname varchar(255), + autobooking boolean default 0, + confirmation_email bit default 0, + token varchar(255), + price_amount DECIMAL(12,4), + price_currency_code VARCHAR(3), + offer_desc VARCHAR(2000), + fk_resource_id bigint, + primary key (offer_id) + ); + + create table if not exists o_ac_method ( + method_id bigint NOT NULL, + access_method varchar(32), + version mediumint unsigned not null, + creationdate datetime, + lastmodified datetime, + is_valid bit default 1, + is_enabled bit default 1, + validfrom datetime, + validto datetime, + primary key (method_id) + ); + + create table if not exists o_ac_offer_access ( + offer_method_id bigint NOT NULL, + version mediumint unsigned not null, + creationdate datetime, + is_valid bit default 1, + validfrom datetime, + validto datetime, + fk_offer_id bigint, + fk_method_id bigint, + primary key (offer_method_id) + ); + + create table o_ac_auto_advance_order ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + a_identifier_key varchar(64) not null, + a_identifier_value varchar(64) not null, + a_status varchar(32) not null, + a_status_modified datetime not null, + fk_identity int8 not null, + fk_method int8 not null, + primary key (id) + ); + + -- access cart + create table if not exists o_ac_order ( + order_id bigint NOT NULL, + version mediumint unsigned not null, + creationdate datetime, + lastmodified datetime, + is_valid bit default 1, + total_lines_amount DECIMAL(12,4), + total_lines_currency_code VARCHAR(3), + total_amount DECIMAL(12,4), + total_currency_code VARCHAR(3), + discount_amount DECIMAL(12,4), + discount_currency_code VARCHAR(3), + order_status VARCHAR(32) default 'NEW', + fk_delivery_id bigint, + primary key (order_id) + ); + + create table if not exists o_ac_order_part ( + order_part_id bigint NOT NULL, + version mediumint unsigned not null, + pos mediumint unsigned, + creationdate datetime, + total_lines_amount DECIMAL(12,4), + total_lines_currency_code VARCHAR(3), + total_amount DECIMAL(12,4), + total_currency_code VARCHAR(3), + fk_order_id bigint, + primary key (order_part_id) + ); + + create table if not exists o_ac_order_line ( + order_item_id bigint NOT NULL, + version mediumint unsigned not null, + pos mediumint unsigned, + creationdate datetime, + unit_price_amount DECIMAL(12,4), + unit_price_currency_code VARCHAR(3), + total_amount DECIMAL(12,4), + total_currency_code VARCHAR(3), + fk_order_part_id bigint, + fk_offer_id bigint, + primary key (order_item_id) + ); + + create table if not exists o_ac_transaction ( + transaction_id bigint NOT NULL, + version mediumint unsigned not null, + creationdate datetime, + trx_status VARCHAR(32) default 'NEW', + amount_amount DECIMAL(12,4), + amount_currency_code VARCHAR(3), + fk_order_part_id bigint, + fk_order_id bigint, + fk_method_id bigint, + primary key (transaction_id) + ); + + create table if not exists o_ac_reservation ( + reservation_id bigint NOT NULL, + creationdate datetime, + lastmodified datetime, + version mediumint unsigned not null, + expirationdate datetime, + reservationtype varchar(32), + fk_identity bigint not null, + fk_resource bigint not null, + primary key (reservation_id) + ); + + create table if not exists o_ac_paypal_transaction ( + transaction_id bigint not null, + version bigint not null, + creationdate datetime, + ref_no varchar(255), + order_id bigint not null, + order_part_id bigint not null, + method_id bigint not null, + success_uuid varchar(32) not null, + cancel_uuid varchar(32) not null, + amount_amount DECIMAL(12,4), + amount_currency_code VARCHAR(3), + pay_response_date datetime, + pay_key varchar(255), + ack varchar(255), + build varchar(255), + coorelation_id varchar(255), + payment_exec_status varchar(255), + ipn_transaction_id varchar(255), + ipn_transaction_status varchar(255), + ipn_sender_transaction_id varchar(255), + ipn_sender_transaction_status varchar(255), + ipn_sender_email varchar(255), + ipn_verify_sign varchar(255), + ipn_pending_reason varchar(255), + trx_status VARCHAR(32) not null default 'NEW', + trx_amount DECIMAL(12,4), + trx_currency_code VARCHAR(3), + primary key (transaction_id) + ); + + -- openmeetings + create table if not exists o_om_room_reference ( + id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + creationdate datetime, + businessgroup bigint, + resourcetypename varchar(50), + resourcetypeid bigint, + ressubpath varchar(255), + roomId bigint, + config longtext, + primary key (id) + ); + + -- assessment tables + -- efficiency statments + create table if not exists o_as_eff_statement ( + id bigint not null, + version mediumint unsigned not null, + lastmodified datetime, + lastcoachmodified datetime, + lastusermodified datetime, + creationdate datetime, + passed bit default null, + score float(65,30), + total_nodes mediumint, + attempted_nodes mediumint, + passed_nodes mediumint, + course_title varchar(255), + course_short_title varchar(128), + course_repo_key bigint, + statement_xml longtext, + fk_identity bigint, + fk_resource_id bigint, + primary key (id) + ); + + -- user to course informations (was property initial and recent launch dates) + create table o_as_user_course_infos ( + id bigint not null, + version mediumint unsigned not null, + creationdate datetime, + lastmodified datetime, + initiallaunchdate datetime, + recentlaunchdate datetime, + visit mediumint, + timespend bigint, + fk_identity bigint, + fk_resource_id bigint, + primary key (id) + ); + + create table o_as_entry ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + lastcoachmodified datetime, + lastusermodified datetime, + a_attemtps bigint default null, + a_score float(65,30) default null, + a_passed bit default null, + a_status varchar(16) default null, + a_details varchar(1024) default null, + a_fully_assessed bit default null, + a_user_visibility bit default 1, + a_assessment_id bigint default null, + a_completion float(65,30), + a_current_run_completion float(65,30), + a_current_run_status varchar(16), + a_comment text, + a_coach_comment text, + a_num_assessment_docs bigint not null default 0, + fk_entry bigint not null, + a_subident varchar(64), + fk_reference_entry bigint, + fk_identity bigint default null, + a_anon_identifier varchar(128) default null, + primary key (id), + unique (fk_identity, fk_entry, a_subident) + ); + + create table o_as_mode_course ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + a_name varchar(255), + a_description longtext, + a_status varchar(16), + a_manual_beginend bit not null default 0, + a_begin datetime not null, + a_leadtime bigint not null default 0, + a_begin_with_leadtime datetime not null, + a_end datetime not null, + a_followuptime bigint not null default 0, + a_end_with_followuptime datetime not null, + a_targetaudience varchar(16), + a_restrictaccesselements bit not null default 0, + a_elements varchar(2048), + a_start_element varchar(64), + a_restrictaccessips bit not null default 0, + a_ips varchar(2048), + a_safeexambrowser bit not null default 0, + a_safeexambrowserkey varchar(2048), + a_safeexambrowserhint longtext, + a_applysettingscoach bit not null default 0, + fk_entry bigint not null, + primary key (id) + ); + + create table o_as_mode_course_to_group ( + id bigint not null, + fk_assessment_mode_id bigint not null, + fk_group_id bigint not null, + primary key (id) + ); + + create table o_as_mode_course_to_area ( + id bigint not null, + fk_assessment_mode_id bigint not null, + fk_area_id bigint not null, + primary key (id) + ); + + create table o_cer_template ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_name varchar(256) not null, + c_path varchar(1024) not null, + c_public boolean not null, + c_format varchar(16), + c_orientation varchar(16), + primary key (id) + ); + + create table o_cer_certificate ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_status varchar(16) not null default 'pending', + c_email_status varchar(16), + c_uuid varchar(36) not null, + c_next_recertification datetime, + c_path varchar(1024), + c_last boolean not null default 1, + c_course_title varchar(255), + c_archived_resource_id bigint not null, + fk_olatresource bigint, + fk_identity bigint not null, + primary key (id) + ); + + create table o_goto_organizer ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_name varchar(128) default null, + g_account_key varchar(128) default null, + g_access_token varchar(128) not null, + g_renew_date datetime not null, + g_organizer_key varchar(128) not null, + g_username varchar(128) not null, + g_firstname varchar(128) default null, + g_lastname varchar(128) default null, + g_email varchar(128) default null, + fk_identity bigint default null, + primary key (id) + ); + + create table o_goto_meeting ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_external_id varchar(128) default null, + g_type varchar(16) not null, + g_meeting_key varchar(128) not null, + g_name varchar(255) default null, + g_description varchar(2000) default null, + g_start_date datetime default null, + g_end_date datetime default null, + fk_organizer_id bigint not null, + fk_entry_id bigint default null, + g_sub_ident varchar(64) default null, + fk_group_id bigint default null, + primary key (id) + ); + + create table o_goto_registrant ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_status varchar(16) default null, + g_join_url varchar(1024) default null, + g_confirm_url varchar(1024) default null, + g_registrant_key varchar(64) default null, + fk_meeting_id bigint not null, + fk_identity_id bigint not null, + primary key (id) + ); + + create table o_vid_transcoding ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + vid_resolution bigint default null, + vid_width bigint default null, + vid_height bigint default null, + vid_size bigint default null, + vid_format varchar(128) default null, + vid_status bigint default null, + vid_transcoder varchar(128) default null, + fk_resource_id bigint not null, + primary key (id) + ); + + create table o_vid_metadata ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + vid_width bigint default null, + vid_height bigint default null, + vid_size bigint default null, + vid_format varchar(32) default null, + vid_length varchar(32) default null, + fk_resource_id bigint not null, + primary key (id) + ); + + -- calendar + create table o_cal_use_config ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_calendar_id varchar(128) not null, + c_calendar_type varchar(16) not null, + c_token varchar(36), + c_cssclass varchar(36), + c_visible bit not null default 1, + c_aggregated_feed bit not null default 1, + fk_identity bigint not null, + primary key (id), + unique (c_calendar_id, c_calendar_type, fk_identity) + ); + + create table o_cal_import ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_calendar_id varchar(128) not null, + c_calendar_type varchar(16) not null, + c_displayname varchar(256), + c_lastupdate datetime not null, + c_url varchar(1024), + fk_identity bigint, + primary key (id) + ); + + create table o_cal_import_to ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_to_calendar_id varchar(128) not null, + c_to_calendar_type varchar(16) not null, + c_lastupdate datetime not null, + c_url varchar(1024), + primary key (id) + ); + + -- instant messaging + create table if not exists o_im_message ( + id bigint not null, + creationdate datetime, + msg_resname varchar(50) not null, + msg_resid bigint not null, + msg_anonym bit default 0, + msg_from varchar(255) not null, + msg_body longtext, + fk_from_identity_id bigint not null, + primary key (id) + ); + + create table if not exists o_im_notification ( + id bigint not null, + creationdate datetime, + chat_resname varchar(50) not null, + chat_resid bigint not null, + fk_to_identity_id bigint not null, + fk_from_identity_id bigint not null, + primary key (id) + ); + + create table if not exists o_im_roster_entry ( + id bigint not null, + creationdate datetime, + r_resname varchar(50) not null, + r_resid bigint not null, + r_nickname varchar(255), + r_fullname varchar(255), + r_anonym bit default 0, + r_vip bit default 0, + fk_identity_id bigint not null, + primary key (id) + ); + + create table if not exists o_im_preferences ( + id bigint not null, + creationdate datetime, + visible_to_others bit default 0, + roster_def_status varchar(12), + fk_from_identity_id bigint not null, + primary key (id) + ); + + -- add mapper table + create table o_mapper ( + id bigint not null, + lastmodified datetime, + creationdate datetime, + expirationdate datetime, + mapper_uuid varchar(64), + orig_session_id varchar(64), + xml_config text, + primary key (id) + ); + + -- qti 2.1 + create table o_qti_assessmenttest_session ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + q_exploded bit not null default 0, + q_author_mode bit not null default 0, + q_finish_time datetime, + q_termination_time datetime, + q_duration bigint, + q_score float(65,30) default null, + q_manual_score float(65,30) default null, + q_passed bit default null, + q_num_questions bigint, + q_num_answered_questions bigint, + q_extra_time bigint, + q_storage varchar(1024), + fk_reference_entry bigint not null, + fk_entry bigint, + q_subident varchar(255), + fk_identity bigint default null, + q_anon_identifier varchar(128) default null, + fk_assessment_entry bigint not null, + primary key (id) + ); + + create table o_qti_assessmentitem_session ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + q_itemidentifier varchar(255) not null, + q_sectionidentifier varchar(255) default null, + q_testpartidentifier varchar(255) default null, + q_duration bigint, + q_score float(65,30) default null, + q_manual_score float(65,30) default null, + q_coach_comment mediumtext default null, + q_to_review bit default 0, + q_passed bit default null, + q_storage varchar(1024), + fk_assessmenttest_session bigint not null, + primary key (id) + ); + + create table o_qti_assessment_response ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + q_responseidentifier varchar(255) not null, + q_responsedatatype varchar(16) not null, + q_responselegality varchar(16) not null, + q_stringuifiedresponse mediumtext, + fk_assessmentitem_session bigint not null, + fk_assessmenttest_session bigint not null, + primary key (id) + ); + + create table o_qti_assessment_marks ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + q_marks mediumtext default null, + q_hidden_rubrics mediumtext default null, + fk_reference_entry bigint not null, + fk_entry bigint, + q_subident varchar(64), + fk_identity bigint not null, + primary key (id) + ); + + -- question item + create table o_qp_pool ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + q_name varchar(255) not null, + q_public bit default 0, + fk_ownergroup bigint, + primary key (id) + ); + + create table o_qp_taxonomy_level ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + q_field varchar(255) not null, + q_mat_path_ids varchar(1024), + q_mat_path_names varchar(2048), + fk_parent_field bigint, + primary key (id) + ); + + create table o_qp_item ( + id bigint not null, + q_identifier varchar(36) not null, + q_master_identifier varchar(36), + q_title varchar(1024) not null, + q_topic varchar(1024), + q_description varchar(2048), + q_keywords varchar(1024), + q_coverage varchar(1024), + q_additional_informations varchar(256), + q_language varchar(16), + fk_edu_context bigint, + q_educational_learningtime varchar(32), + fk_type bigint, + q_difficulty decimal(10,9), + q_stdev_difficulty decimal(10,9), + q_differentiation decimal(10,9), + q_num_of_answers_alt bigint not null default 0, + q_usage bigint not null default 0, + q_assessment_type varchar(64), + q_status varchar(32) not null, + q_version varchar(50), + fk_license bigint, + q_editor varchar(256), + q_editor_version varchar(256), + q_format varchar(32) not null, + q_creator varchar(1024), + creationdate datetime not null, + lastmodified datetime not null, + q_status_last_modified datetime not null, + q_dir varchar(32), + q_root_filename varchar(255), + fk_taxonomy_level bigint, + fk_taxonomy_level_v2 bigint, + fk_ownergroup bigint not null, + primary key (id) + ); + + create table o_qp_item_audit_log ( + id bigint not null auto_increment, + creationdate datetime not null, + q_action varchar(64), + q_val_before mediumtext, + q_val_after mediumtext, + q_lic_before mediumtext, + q_lic_after mediumtext, + q_message mediumtext, + fk_author_id bigint, + fk_item_id bigint, + primary key (id) + ); + + create table o_qp_pool_2_item ( + id bigint not null, + creationdate datetime not null, + q_editable bit default 0, + fk_pool_id bigint not null, + fk_item_id bigint not null, + primary key (id) + ); + + create table o_qp_share_item ( + id bigint not null, + creationdate datetime not null, + q_editable bit default 0, + fk_resource_id bigint not null, + fk_item_id bigint not null, + primary key (id) + ); + + create table o_qp_item_collection ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + q_name varchar(256), + fk_owner_id bigint not null, + primary key (id) + ); + + create table o_qp_collection_2_item ( + id bigint not null, + creationdate datetime not null, + fk_collection_id bigint not null, + fk_item_id bigint not null, + primary key (id) + ); + + create table o_qp_edu_context ( + id bigint not null, + creationdate datetime not null, + q_level varchar(256) not null, + q_deletable bit default 0, + primary key (id) + ); + + create table if not exists o_qp_item_type ( + id bigint not null, + creationdate datetime not null, + q_type varchar(256) not null, + q_deletable bit default 0, + primary key (id) + ); + + create table if not exists o_qp_license ( + id bigint not null, + creationdate datetime not null, + q_license varchar(256) not null, + q_text varchar(2048), + q_deletable bit default 0, + primary key (id) + ); + + + -- portfolio + create table o_pf_binder ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + p_title varchar(255), + p_status varchar(32), + p_copy_date datetime, + p_return_date datetime, + p_deadline datetime, + p_summary mediumtext, + p_image_path varchar(255), + fk_olatresource_id bigint, + fk_group_id bigint not null, + fk_entry_id bigint, + p_subident varchar(128), + fk_template_id bigint, + primary key (id) + ); + + create table o_pf_section ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + pos bigint default null, + p_title varchar(255), + p_description mediumtext, + p_status varchar(32) not null default 'notStarted', + p_begin datetime, + p_end datetime, + p_override_begin_end bit default 0, + fk_group_id bigint not null, + fk_binder_id bigint not null, + fk_template_reference_id bigint, + primary key (id) + ); + + create table o_pf_page ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + pos bigint default null, + p_editable bit default 1, + p_title varchar(255), + p_summary mediumtext, + p_status varchar(32), + p_image_path varchar(255), + p_image_align varchar(32), + p_version bigint default 0, + p_initial_publish_date datetime, + p_last_publish_date datetime, + fk_body_id bigint not null, + fk_group_id bigint not null, + fk_section_id bigint, + primary key (id) + ); + + create table o_pf_page_body ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + primary key (id) + ); + + create table o_pf_media ( + id bigint not null auto_increment, + creationdate datetime not null, + p_collection_date datetime not null, + p_type varchar(64) not null, + p_storage_path varchar(255), + p_root_filename varchar(255), + p_title varchar(255) not null, + p_description mediumtext, + p_content mediumtext, + p_signature bigint not null default 0, + p_reference_id varchar(255) default null, + p_business_path varchar(255) not null, + p_creators varchar(1024) default null, + p_place varchar(255) default null, + p_publisher varchar(255) default null, + p_publication_date datetime default null, + p_date varchar(32) default null, + p_url varchar(1024) default null, + p_source varchar(1024) default null, + p_language varchar(32) default null, + p_metadata_xml mediumtext, + fk_author_id bigint not null, + primary key (id) + ); + + create table o_pf_page_part ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + pos bigint default null, + dtype varchar(32), + p_content mediumtext, + p_flow varchar(32), + p_layout_options varchar(2000), + fk_media_id bigint, + fk_page_body_id bigint, + fk_form_entry_id bigint default null, + primary key (id) + ); + + create table o_pf_category ( + id bigint not null auto_increment, + creationdate datetime not null, + p_name varchar(32), + primary key (id) + ); + + create table o_pf_category_relation ( + id bigint not null auto_increment, + creationdate datetime not null, + p_resname varchar(64) not null, + p_resid bigint not null, + fk_category_id bigint not null, + primary key (id) + ); + + create table o_pf_assessment_section ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + p_score float(65,30) default null, + p_passed bit default null, + p_comment mediumtext, + fk_section_id bigint not null, + fk_identity_id bigint not null, + primary key (id) + ); + + create table o_pf_assignment ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + pos bigint default null, + p_status varchar(32) default null, + p_type varchar(32) not null, + p_version bigint not null default 0, + p_title varchar(255) default null, + p_summary mediumtext, + p_content mediumtext, + p_storage varchar(255) default null, + fk_section_id bigint not null, + fk_template_reference_id bigint, + fk_page_id bigint, + fk_assignee_id bigint, + p_only_auto_eva bit default 1, + p_reviewer_see_auto_eva bit default 0, + p_anon_extern_eva bit default 1, + fk_form_entry_id bigint default null, + primary key (id) + ); + + create table o_pf_binder_user_infos ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + p_initiallaunchdate datetime, + p_recentlaunchdate datetime, + p_visit bigint, + fk_identity bigint, + fk_binder bigint, + unique(fk_identity, fk_binder), + primary key (id) + ); + + create table o_pf_page_user_infos ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + p_mark bit default 0, + p_status varchar(16) not null default 'incoming', + p_recentlaunchdate datetime not null, + fk_identity_id bigint not null, + fk_page_id bigint not null, + primary key (id) + ); + + -- evaluation form + create table o_eva_form_survey ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + e_resname varchar(50), + e_resid bigint, + e_sub_ident varchar(2048), + fk_form_entry bigint not null, + primary key (id) + ); + + create table o_eva_form_participation ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + e_identifier_type varchar(50) not null, + e_identifier_key varchar(50) not null, + e_status varchar(20) not null, + e_anonymous bit not null, + fk_executor bigint, + fk_survey bigint not null, + primary key (id) + ); + + create table o_eva_form_session ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + e_status varchar(16), + e_submission_date datetime, + e_first_submission_date datetime, + fk_survey bigint, + fk_participation bigint unique, + fk_identity bigint, + fk_page_body bigint, + fk_form_entry bigint, + primary key (id) + ); + + create table o_eva_form_response ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + e_no_response bit default 0, + e_responseidentifier varchar(64) not null, + e_numericalresponse decimal default null, + e_stringuifiedresponse mediumtext, + e_file_response_path varchar(4000), + fk_session bigint not null, + primary key (id) + ); + + + -- lti + create table o_lti_outcome ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + r_ressubpath varchar(2048), + r_action varchar(255) not null, + r_outcome_key varchar(255) not null, + r_outcome_value varchar(2048), + fk_resource_id bigint not null, + fk_identity_id bigint not null, + primary key (id) + ); + + create table o_cl_checkbox ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_checkboxid varchar(50) not null, + c_resname varchar(50) not null, + c_resid bigint not null, + c_ressubpath varchar(255) not null, + primary key (id) + ); + + create table o_cl_check ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + c_score float(65,30), + c_checked bit default null, + fk_identity_id bigint not null, + fk_checkbox_id bigint not null, + primary key (id) + ); + + create table o_gta_task_list ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_course_node_ident varchar(36), + fk_entry bigint not null, + primary key (id) + ); + + create table o_gta_task ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + g_status varchar(36), + g_rev_loop mediumint not null default 0, + g_assignment_date datetime, + g_submission_date datetime, + g_submission_ndocs bigint, + g_submission_revisions_date datetime, + g_submission_revisions_ndocs bigint, + g_collection_date datetime, + g_collection_ndocs bigint, + g_acceptation_date datetime, + g_solution_date datetime, + g_graduation_date datetime, + g_allow_reset_date datetime, + g_assignment_due_date datetime, + g_submission_due_date datetime, + g_revisions_due_date datetime, + g_solution_due_date datetime, + g_taskname varchar(1024), + fk_tasklist bigint not null, + fk_identity bigint, + fk_businessgroup bigint, + fk_allow_reset_identity bigint, + primary key (id) + ); + + create table o_gta_task_revision_date ( + id bigint not null auto_increment, + creationdate datetime not null, + g_status varchar(36) not null, + g_rev_loop bigint not null, + g_date datetime not null, + fk_task bigint not null, + primary key (id) + ); + + create table o_gta_mark ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + fk_tasklist_id int8 not null, + fk_marker_identity_id int8 not null, + fk_participant_identity_id int8 not null, + primary key (id) + ); + + create table o_rem_reminder ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + r_description varchar(255), + r_start datetime, + r_sendtime varchar(16), + r_configuration mediumtext, + r_email_subject varchar(255), + r_email_body mediumtext, + fk_creator bigint not null, + fk_entry bigint not null, + primary key (id) + ); + + create table o_rem_sent_reminder ( + id bigint not null, + creationdate datetime not null, + r_status varchar(16), + fk_identity bigint not null, + fk_reminder bigint not null, + primary key (id) + ); + + create table o_ex_task ( + id bigint not null, + creationdate datetime not null, + lastmodified datetime not null, + e_name varchar(255) not null, + e_status varchar(16) not null, + e_status_before_edit varchar(16), + e_executor_node varchar(16), + e_executor_boot_id varchar(64), + e_task mediumtext not null, + e_scheduled datetime, + e_ressubpath varchar(2048), + fk_resource_id bigint, + fk_identity_id bigint, + primary key (id) + ); + + create table o_ex_task_modifier ( + id bigint not null, + creationdate datetime not null, + fk_task_id bigint not null, + fk_identity_id bigint not null, + primary key (id) + ); + + -- sms + create table o_sms_message_log ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + s_message_uuid varchar(256) not null, + s_server_response varchar(256), + s_service_id varchar(32) not null, + fk_identity bigint not null, + primary key (id) + ); + + -- webfeed + create table o_feed ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + f_resourceable_id bigint, + f_resourceable_type varchar(64), + f_title varchar(1024), + f_description mediumtext, + f_author varchar(255), + f_image_name varchar(1024), + f_external boolean, + f_external_feed_url varchar(4000), + f_external_image_url varchar(4000), + primary key (id) + ); + + create table o_feed_item ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + f_title varchar(1024), + f_description mediumtext, + f_content mediumtext, + f_author varchar(255), + f_guid varchar(255), + f_external_link varchar(4000), + f_draft boolean, + f_publish_date datetime, + f_width bigint, + f_height bigint, + f_filename varchar(1024), + f_type varchar(255), + f_length bigint, + f_external_url varchar(4000), + fk_feed_id bigint not null, + fk_identity_author_id bigint, + fk_identity_modified_id bigint, + primary key (id) + ); + + -- lectures + create table o_lecture_reason ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_title varchar(255), + l_descr varchar(2000), + primary key (id) + ); + + create table o_lecture_block ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_external_id varchar(255), + l_managed_flags varchar(255), + l_title varchar(255), + l_descr mediumtext, + l_preparation mediumtext, + l_location varchar(255), + l_comment mediumtext, + l_start_date datetime not null, + l_end_date datetime not null, + l_compulsory bit default 1, + l_eff_end_date datetime, + l_planned_lectures_num bigint not null default 0, + l_effective_lectures_num bigint not null default 0, + l_effective_lectures varchar(128), + l_auto_close_date datetime default null, + l_status varchar(16) not null, + l_roll_call_status varchar(16) not null, + fk_reason bigint, + fk_entry bigint not null, + fk_teacher_group bigint not null, + primary key (id) + ); + + create table o_lecture_block_to_group ( + id bigint not null auto_increment, + fk_lecture_block bigint not null, + fk_group bigint not null, + primary key (id) + ); + + create table o_lecture_block_roll_call ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_comment mediumtext, + l_lectures_attended varchar(128), + l_lectures_absent varchar(128), + l_lectures_attended_num bigint not null default 0, + l_lectures_absent_num bigint not null default 0, + l_absence_reason mediumtext, + l_absence_authorized bit default null, + l_absence_appeal_date datetime, + l_absence_supervisor_noti_date datetime, + fk_lecture_block bigint not null, + fk_identity bigint not null, + primary key (id) + ); + + create table o_lecture_reminder ( + id bigint not null auto_increment, + creationdate datetime not null, + l_status varchar(16) not null, + fk_lecture_block bigint not null, + fk_identity bigint not null, + primary key (id) + ); + + create table o_lecture_participant_summary ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_first_admission_date datetime default null, + l_required_attendance_rate float(65,30) default null, + l_attended_lectures bigint not null default 0, + l_absent_lectures bigint not null default 0, + l_excused_lectures bigint not null default 0, + l_planneds_lectures bigint not null default 0, + l_attendance_rate float(65,30) default null, + l_cal_sync bit default 0, + l_cal_last_sync_date datetime default null, + fk_entry bigint not null, + fk_identity bigint not null, + primary key (id), + unique (fk_entry, fk_identity) + ); + + create table o_lecture_entry_config ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_lecture_enabled bit default null, + l_override_module_def bit default 0, + l_rollcall_enabled bit default null, + l_calculate_attendance_rate bit default null, + l_required_attendance_rate float(65,30) default null, + l_sync_calendar_teacher bit default null, + l_sync_calendar_participant bit default null, + l_sync_calendar_course bit default null, + fk_entry bigint not null, + unique(fk_entry), + primary key (id) + ); + + create table o_lecture_block_audit_log ( + id bigint not null auto_increment, + creationdate datetime not null, + l_action varchar(32), + l_val_before mediumtext, + l_val_after mediumtext, + l_message mediumtext, + fk_lecture_block bigint, + fk_roll_call bigint, + fk_entry bigint, + fk_identity bigint, + fk_author bigint, + primary key (id) + ); + + -- taxonomy + create table o_tax_taxonomy ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + t_identifier varchar(64), + t_displayname varchar(255) not null, + t_description mediumtext, + t_external_id varchar(64), + t_managed_flags varchar(255), + t_directory_path varchar(255), + t_directory_lost_found_path varchar(255), + fk_group bigint not null, + primary key (id) + ); + + create table o_tax_taxonomy_level_type ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + t_identifier varchar(64), + t_displayname varchar(255) not null, + t_description mediumtext, + t_external_id varchar(64), + t_managed_flags varchar(255), + t_css_class varchar(64), + t_visible bit default 1, + t_library_docs bit default 1, + t_library_manage bit default 1, + t_library_teach_read bit default 1, + t_library_teach_readlevels bigint not null default 0, + t_library_teach_write bit default 0, + t_library_have_read bit default 1, + t_library_target_read bit default 1, + fk_taxonomy bigint not null, + primary key (id) + ); + + create table o_tax_taxonomy_type_to_type ( + id bigint not null auto_increment, + fk_type bigint not null, + fk_allowed_sub_type bigint not null, + primary key (id) + ); + + create table o_tax_taxonomy_level ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + t_identifier varchar(64), + t_displayname varchar(255) not null, + t_description mediumtext, + t_external_id varchar(64), + t_sort_order bigint, + t_directory_path varchar(255), + t_m_path_keys varchar(255), + t_m_path_identifiers varchar(1024), + t_enabled bit default 1, + t_managed_flags varchar(255), + fk_taxonomy bigint not null, + fk_parent bigint, + fk_type bigint, + primary key (id) + ); + + create table o_tax_taxonomy_competence ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + t_type varchar(16), + t_achievement float(65,30) default null, + t_reliability float(65,30) default null, + t_expiration_date datetime, + t_external_id varchar(64), + t_source_text varchar(255), + t_source_url varchar(255), + fk_level bigint not null, + fk_identity bigint not null, + primary key (id) + ); + + create table o_tax_competence_audit_log ( + id bigint not null auto_increment, + creationdate datetime not null, + t_action varchar(32), + t_val_before mediumtext, + t_val_after mediumtext, + t_message mediumtext, + fk_taxonomy bigint, + fk_taxonomy_competence bigint, + fk_identity bigint, + fk_author bigint, + primary key (id) + ); + + -- dialog elements + create table o_dialog_element ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + d_filename varchar(2048), + d_filesize bigint, + d_subident varchar(64) not null, + fk_author bigint, + fk_entry bigint not null, + fk_forum bigint not null, + primary key (id) + ); + + -- licenses + create table o_lic_license_type ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + l_name varchar(128) not null unique, + l_text mediumtext, + l_css_class varchar(64), + l_predefined boolean not null default false, + l_sort_order int not null, + primary key (id) + ); + + create table o_lic_license_type_activation ( + id bigint not null auto_increment, + creationdate timestamp not null, + l_handler_type varchar(128) not null, + fk_license_type_id bigint not null, + primary key (id) + ); + + create table o_lic_license ( + id bigint not null auto_increment, + creationdate timestamp not null, + lastmodified datetime not null, + l_resname varchar(50) not null, + l_resid bigint not null, + l_licensor varchar(4000), + l_freetext mediumtext, + fk_license_type_id bigint not null, + primary key (id) + ); + + -- organisation + create table o_org_organisation_type ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + o_identifier varchar(64), + o_displayname varchar(255) not null, + o_description mediumtext, + o_external_id varchar(64), + o_managed_flags varchar(255), + o_css_class varchar(64), + primary key (id) + ); + + create table o_org_organisation ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + o_identifier varchar(64), + o_displayname varchar(255) not null, + o_description mediumtext, + o_m_path_keys varchar(255), + o_external_id varchar(64), + o_managed_flags varchar(255), + o_status varchar(32), + o_css_class varchar(64), + fk_group bigint not null, + fk_root bigint, + fk_parent bigint, + fk_type bigint, + primary key (id) + ); + + create table o_org_type_to_type ( + id bigint not null auto_increment, + fk_type bigint not null, + fk_allowed_sub_type bigint not null, + primary key (id) + ); + + create table o_re_to_organisation ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + r_master bit default 0, + fk_entry bigint not null, + fk_organisation bigint not null, + primary key (id) + ); + + -- curriculum + create table o_cur_element_type ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + c_identifier varchar(64), + c_displayname varchar(255) not null, + c_description mediumtext, + c_external_id varchar(64), + c_managed_flags varchar(255), + c_css_class varchar(64), + primary key (id) + ); + + create table o_cur_curriculum ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + c_identifier varchar(64), + c_displayname varchar(255) not null, + c_description mediumtext, + c_external_id varchar(64), + c_managed_flags varchar(255), + c_status varchar(32), + c_degree varchar(255), + fk_group bigint not null, + fk_organisation bigint, + primary key (id) + ); + + create table o_cur_curriculum_element ( + id bigint not null auto_increment, + creationdate datetime not null, + lastmodified datetime not null, + pos bigint, + c_identifier varchar(64), + c_displayname varchar(255) not null, + c_description mediumtext, + c_status varchar(32), + c_begin datetime, + c_end datetime, + c_external_id varchar(64), + c_managed_flags varchar(255), + fk_group bigint not null, + fk_parent bigint, + fk_curriculum bigint not null, + primary key (id) + ); + + create table o_cur_element_type_to_type ( + id bigint not null auto_increment, + fk_type bigint not null, + fk_allowed_sub_type bigint not null, + primary key (id) + ); + + -- user view + create view o_bs_identity_short_v as ( + select + ident.id as id_id, + ident.name as id_name, + ident.lastlogin as id_lastlogin, + ident.status as id_status, + us.user_id as us_id, + us.u_firstname as first_name, + us.u_lastname as last_name, + us.u_email as email + from o_bs_identity as ident + inner join o_user as us on (ident.id = us.fk_identity) + ); + + -- eportfolio views + create or replace view o_ep_notifications_struct_v as ( + select + struct.structure_id as struct_id, + struct.structure_type as struct_type, + struct.title as struct_title, + struct.fk_struct_root_id as struct_root_id, + struct.fk_struct_root_map_id as struct_root_map_id, + (case when struct.structure_type = 'page' then struct.structure_id else parent_struct.structure_id end) as page_key, + struct_link.creationdate as creation_date + from o_ep_struct_el as struct + inner join o_ep_struct_struct_link as struct_link on (struct_link.fk_struct_child_id = struct.structure_id) + inner join o_ep_struct_el as parent_struct on (struct_link.fk_struct_parent_id = parent_struct.structure_id) + where struct.structure_type = 'page' or parent_struct.structure_type = 'page' + ); + + create or replace view o_ep_notifications_art_v as ( + select + artefact.artefact_id as artefact_id, + artefact_link.link_id as link_id, + artefact.title as artefact_title, + (case when struct.structure_type = 'page' then struct.title else root_struct.title end ) as struct_title, + struct.structure_type as struct_type, + struct.structure_id as struct_id, + root_struct.structure_id as struct_root_id, + root_struct.structure_type as struct_root_type, + struct.fk_struct_root_map_id as struct_root_map_id, + (case when struct.structure_type = 'page' then struct.structure_id else root_struct.structure_id end ) as page_key, + artefact_link.fk_auth_id as author_id, + artefact_link.creationdate as creation_date + from o_ep_struct_el as struct + inner join o_ep_struct_artefact_link as artefact_link on (artefact_link.fk_struct_id = struct.structure_id) + inner join o_ep_artefact as artefact on (artefact_link.fk_artefact_id = artefact.artefact_id) + left join o_ep_struct_el as root_struct on (struct.fk_struct_root_id = root_struct.structure_id) + ); + + create or replace view o_ep_notifications_rating_v as ( + select + urating.rating_id as rating_id, + map.structure_id as map_id, + map.title as map_title, + cast(urating.ressubpath as unsigned) as page_key, + page.title as page_title, + urating.creator_id as author_id, + urating.creationdate as creation_date, + urating.lastmodified as last_modified + from o_userrating as urating + inner join o_olatresource as rating_resource on (rating_resource.resid = urating.resid and rating_resource.resname = urating.resname) + inner join o_ep_struct_el as map on (map.fk_olatresource = rating_resource.resource_id) + left join o_ep_struct_el as page on (page.fk_struct_root_map_id = map.structure_id and page.structure_id = urating.ressubpath) + ); + + create or replace view o_ep_notifications_comment_v as ( + select + ucomment.comment_id as comment_id, + map.structure_id as map_id, + map.title as map_title, + cast(ucomment.ressubpath as unsigned) as page_key, + page.title as page_title, + ucomment.creator_id as author_id, + ucomment.creationdate as creation_date + from o_usercomment as ucomment + inner join o_olatresource as comment_resource on (comment_resource.resid = ucomment.resid and comment_resource.resname = ucomment.resname) + inner join o_ep_struct_el as map on (map.fk_olatresource = comment_resource.resource_id) + left join o_ep_struct_el as page on (page.fk_struct_root_map_id = map.structure_id and page.structure_id = ucomment.ressubpath) + ); + + create view o_gp_business_to_repository_v as ( + select + grp.group_id as grp_id, + repoentry.repositoryentry_id as re_id, + repoentry.displayname as re_displayname + from o_gp_business as grp + inner join o_re_to_group as relation on (relation.fk_group_id = grp.fk_group_id) + inner join o_repositoryentry as repoentry on (repoentry.repositoryentry_id = relation.fk_entry_id) + ); + + create view o_bs_gp_membership_v as ( + select + membership.id as membership_id, + membership.fk_identity_id as fk_identity_id, + membership.lastmodified as lastmodified, + membership.creationdate as creationdate, + membership.g_role as g_role, + gp.group_id as group_id + from o_bs_group_member as membership + inner join o_gp_business as gp on (gp.fk_group_id=membership.fk_group_id) + ); + + create or replace view o_re_membership_v as ( + select + bmember.id as membership_id, + bmember.creationdate as creationdate, + bmember.lastmodified as lastmodified, + bmember.fk_identity_id as fk_identity_id, + bmember.g_role as g_role, + re.repositoryentry_id as fk_entry_id + from o_repositoryentry as re + inner join o_re_to_group relgroup on (relgroup.fk_entry_id=re.repositoryentry_id and relgroup.r_defgroup=1) + inner join o_bs_group_member as bmember on (bmember.fk_group_id=relgroup.fk_group_id) + ); + + -- contacts + create view o_gp_contactkey_v as ( + select + bg_member.id as membership_id, + bg_member.fk_identity_id as member_id, + bg_member.g_role as membership_role, + bg_me.fk_identity_id as me_id, + bgroup.group_id as bg_id + from o_gp_business as bgroup + inner join o_bs_group_member as bg_member on (bg_member.fk_group_id = bgroup.fk_group_id) + inner join o_bs_group_member as bg_me on (bg_me.fk_group_id = bgroup.fk_group_id) + where + (bgroup.ownersintern=1 and bg_member.g_role='coach') + or + (bgroup.participantsintern=1 and bg_member.g_role='participant') + ); + + create view o_gp_contactext_v as ( + select + bg_member.id as membership_id, + bg_member.fk_identity_id as member_id, + bg_member.g_role as membership_role, + id_member.name as member_name, + us_member.u_firstname as member_firstname, + us_member.u_lastname as member_lastname, + bg_me.fk_identity_id as me_id, + bgroup.group_id as bg_id, + bgroup.groupname as bg_name + from o_gp_business as bgroup + inner join o_bs_group_member as bg_member on (bg_member.fk_group_id = bgroup.fk_group_id) + inner join o_bs_identity as id_member on (bg_member.fk_identity_id = id_member.id) + inner join o_user as us_member on (id_member.id = us_member.fk_identity) + inner join o_bs_group_member as bg_me on (bg_me.fk_group_id = bgroup.fk_group_id) + where + (bgroup.ownersintern=1 and bg_member.g_role='coach') + or + (bgroup.participantsintern=1 and bg_member.g_role='participant') + ); + + + -- instant messaging + create or replace view o_im_roster_entry_v as ( + select + entry.id as re_id, + entry.creationdate as re_creationdate, + ident.id as ident_id, + ident.name as ident_name, + entry.r_nickname as re_nickname, + entry.r_fullname as re_fullname, + entry.r_anonym as re_anonym, + entry.r_vip as re_vip, + entry.r_resname as re_resname, + entry.r_resid as re_resid + from o_im_roster_entry as entry + inner join o_bs_identity as ident on (entry.fk_identity_id = ident.id) + ); + + -- question pool + create or replace view o_qp_pool_2_item_short_v as ( + select + pool2item.id as item_to_pool_id, + pool2item.creationdate as item_to_pool_creationdate, + item.id as item_id, + pool2item.q_editable as item_editable, + pool2item.fk_pool_id as item_pool, + pool.q_name as item_pool_name + from o_qp_item as item + inner join o_qp_pool_2_item as pool2item on (pool2item.fk_item_id = item.id) + inner join o_qp_pool as pool on (pool2item.fk_pool_id = pool.id) + ); + + create or replace view o_qp_share_2_item_short_v as ( + select + shareditem.id as item_to_share_id, + shareditem.creationdate as item_to_share_creationdate, + item.id as item_id, + shareditem.q_editable as item_editable, + shareditem.fk_resource_id as resource_id, + bgroup.groupname as resource_name + from o_qp_item as item + inner join o_qp_share_item as shareditem on (shareditem.fk_item_id = item.id) + inner join o_gp_business as bgroup on (shareditem.fk_resource_id = bgroup.fk_resource) + ); + + create index ocl_asset_idx on oc_lock (asset); + alter table oc_lock add index FK9E30F4B66115906D (identity_fk), add constraint FK9E30F4B66115906D foreign key (identity_fk) references o_bs_identity (id); + + alter table hibernate_unique_key ENGINE = InnoDB; + + alter table o_forum ENGINE = InnoDB; + alter table o_forum_pseudonym ENGINE = InnoDB; + alter table o_property ENGINE = InnoDB; + alter table o_bs_secgroup ENGINE = InnoDB; + alter table o_bs_group ENGINE = InnoDB; + alter table o_bs_group_member ENGINE = InnoDB; + alter table o_re_to_group ENGINE = InnoDB; + alter table o_bs_grant ENGINE = InnoDB; + alter table o_repositoryentry_cycle ENGINE = InnoDB; + alter table o_lti_outcome ENGINE = InnoDB; + alter table o_user ENGINE = InnoDB; + alter table o_userproperty ENGINE = InnoDB; + alter table o_message ENGINE = InnoDB; + alter table o_temporarykey ENGINE = InnoDB; + alter table o_bs_authentication ENGINE = InnoDB; + alter table o_bs_authentication_history ENGINE = InnoDB; + alter table o_qtiresult ENGINE = InnoDB; + alter table o_qtiresultset ENGINE = InnoDB; + alter table o_bs_identity ENGINE = InnoDB; + alter table o_csp_log ENGINE = InnoDB; + alter table o_olatresource ENGINE = InnoDB; + alter table o_bs_policy ENGINE = InnoDB; + alter table o_bs_namedgroup ENGINE = InnoDB; + alter table o_bs_membership ENGINE = InnoDB; + alter table o_repositoryentry ENGINE = InnoDB; + alter table o_repositoryentry_stats ENGINE = InnoDB; + alter table o_references ENGINE = InnoDB; + alter table o_gp_business ENGINE = InnoDB; + alter table o_gp_bgarea ENGINE = InnoDB; + alter table o_gp_bgtoarea_rel ENGINE = InnoDB; + alter table o_catentry ENGINE = InnoDB; + alter table o_noti_pub ENGINE = InnoDB; + alter table o_noti_sub ENGINE = InnoDB; + alter table o_note ENGINE = InnoDB; + alter table o_lifecycle ENGINE = InnoDB; + alter table o_plock ENGINE = InnoDB; + alter table oc_lock ENGINE = InnoDB; + alter table o_readmessage ENGINE = InnoDB; + alter table o_projectbroker ENGINE = InnoDB; + alter table o_projectbroker_project ENGINE = InnoDB; + alter table o_projectbroker_customfields ENGINE = InnoDB; + alter table o_checkpoint ENGINE = InnoDB; + alter table o_checkpoint_results ENGINE = InnoDB; + alter table o_usercomment ENGINE = InnoDB; + alter table o_userrating ENGINE = InnoDB; + alter table o_mark ENGINE = InnoDB; + alter table o_info_message ENGINE = InnoDB; + alter table o_tag ENGINE = InnoDB; + alter table o_bs_invitation ENGINE = InnoDB; + alter table o_ep_artefact ENGINE = InnoDB; + alter table o_ep_collect_restriction ENGINE = InnoDB; + alter table o_ep_struct_el ENGINE = InnoDB; + alter table o_ep_struct_struct_link ENGINE = InnoDB; + alter table o_ep_struct_artefact_link ENGINE = InnoDB; + alter table o_ep_struct_to_group ENGINE = InnoDB; + alter table o_co_db_entry ENGINE = InnoDB; + alter table o_mail ENGINE = InnoDB; + alter table o_mail_to_recipient ENGINE = InnoDB; + alter table o_mail_recipient ENGINE = InnoDB; + alter table o_mail_attachment ENGINE = InnoDB; + alter table o_ac_offer ENGINE = InnoDB; + alter table o_ac_method ENGINE = InnoDB; + alter table o_ac_offer_access ENGINE = InnoDB; + alter table o_ac_order ENGINE = InnoDB; + alter table o_ac_order_part ENGINE = InnoDB; + alter table o_ac_order_line ENGINE = InnoDB; + alter table o_ac_transaction ENGINE = InnoDB; + alter table o_ac_reservation ENGINE = InnoDB; + alter table o_ac_paypal_transaction ENGINE = InnoDB; + alter table o_ac_auto_advance_order ENGINE = InnoDB; + alter table o_as_eff_statement ENGINE = InnoDB; + alter table o_as_user_course_infos ENGINE = InnoDB; + alter table o_as_mode_course ENGINE = InnoDB; + alter table o_as_entry ENGINE = InnoDB; + alter table o_as_mode_course_to_area ENGINE = InnoDB; + alter table o_cal_use_config ENGINE = InnoDB; + alter table o_cal_import ENGINE = InnoDB; + alter table o_cal_import_to ENGINE = InnoDB; + alter table o_mapper ENGINE = InnoDB; + alter table o_qti_assessmenttest_session ENGINE = InnoDB; + alter table o_qti_assessmentitem_session ENGINE = InnoDB; + alter table o_qti_assessment_response ENGINE = InnoDB; + alter table o_qti_assessment_marks ENGINE = InnoDB; + alter table o_qp_pool ENGINE = InnoDB; + alter table o_qp_taxonomy_level ENGINE = InnoDB; + alter table o_qp_item ENGINE = InnoDB; + alter table o_qp_pool_2_item ENGINE = InnoDB; + alter table o_qp_share_item ENGINE = InnoDB; + alter table o_qp_item_collection ENGINE = InnoDB; + alter table o_qp_collection_2_item ENGINE = InnoDB; + alter table o_qp_edu_context ENGINE = InnoDB; + alter table o_qp_item_type ENGINE = InnoDB; + alter table o_qp_license ENGINE = InnoDB; + alter table o_om_room_reference ENGINE = InnoDB; + alter table o_im_message ENGINE = InnoDB; + alter table o_im_notification ENGINE = InnoDB; + alter table o_im_roster_entry ENGINE = InnoDB; + alter table o_im_preferences ENGINE = InnoDB; + alter table o_ex_task ENGINE = InnoDB; + alter table o_ex_task_modifier ENGINE = InnoDB; + alter table o_checklist ENGINE = InnoDB; + alter table o_cl_checkbox ENGINE = InnoDB; + alter table o_cl_check ENGINE = InnoDB; + alter table o_gta_task_list ENGINE = InnoDB; + alter table o_gta_task ENGINE = InnoDB; + alter table o_gta_task_revision_date ENGINE = InnoDB; + alter table o_gta_mark ENGINE = InnoDB; + alter table o_cer_template ENGINE = InnoDB; + alter table o_cer_certificate ENGINE = InnoDB; + alter table o_rem_reminder ENGINE = InnoDB; + alter table o_rem_sent_reminder ENGINE = InnoDB; + alter table o_goto_organizer ENGINE = InnoDB; + alter table o_goto_meeting ENGINE = InnoDB; + alter table o_goto_registrant ENGINE = InnoDB; + alter table o_vid_transcoding ENGINE = InnoDB; + alter table o_vid_metadata ENGINE = InnoDB; + alter table o_pf_category_relation ENGINE = InnoDB; + alter table o_pf_category ENGINE = InnoDB; + alter table o_pf_media ENGINE = InnoDB; + alter table o_pf_page_part ENGINE = InnoDB; + alter table o_pf_section ENGINE = InnoDB; + alter table o_pf_page_body ENGINE = InnoDB; + alter table o_pf_page ENGINE = InnoDB; + alter table o_pf_binder ENGINE = InnoDB; + alter table o_pf_assessment_section ENGINE = InnoDB; + alter table o_pf_assignment ENGINE = InnoDB; + alter table o_pf_binder_user_infos ENGINE = InnoDB; + alter table o_eva_form_survey ENGINE = InnoDB; + alter table o_eva_form_participation ENGINE = InnoDB; + alter table o_eva_form_session ENGINE = InnoDB; + alter table o_eva_form_response ENGINE = InnoDB; + alter table o_eva_form_survey ENGINE = InnoDB; + alter table o_sms_message_log ENGINE = InnoDB; + alter table o_feed ENGINE = InnoDB; + alter table o_feed_item ENGINE = InnoDB; + alter table o_lecture_reason ENGINE = InnoDB; + alter table o_lecture_block ENGINE = InnoDB; + alter table o_lecture_block_to_group ENGINE = InnoDB; + alter table o_lecture_block_roll_call ENGINE = InnoDB; + alter table o_lecture_reminder ENGINE = InnoDB; + alter table o_lecture_participant_summary ENGINE = InnoDB; + alter table o_lecture_entry_config ENGINE = InnoDB; + alter table o_lecture_block_audit_log ENGINE = InnoDB; + alter table o_tax_taxonomy ENGINE = InnoDB; + alter table o_tax_taxonomy_level_type ENGINE = InnoDB; + alter table o_tax_taxonomy_type_to_type ENGINE = InnoDB; + alter table o_tax_taxonomy_level ENGINE = InnoDB; + alter table o_tax_taxonomy_competence ENGINE = InnoDB; + alter table o_lic_license_type ENGINE = InnoDB; + alter table o_lic_license_type_activation ENGINE = InnoDB; + alter table o_lic_license ENGINE = InnoDB; + alter table o_org_organisation_type ENGINE = InnoDB; + alter table o_org_organisation ENGINE = InnoDB; + alter table o_org_type_to_type ENGINE = InnoDB; + alter table o_re_to_organisation ENGINE = InnoDB; + alter table o_cur_element_type ENGINE = InnoDB; + alter table o_cur_curriculum ENGINE = InnoDB; + alter table o_cur_curriculum_element ENGINE = InnoDB; + alter table o_cur_element_type_to_type ENGINE = InnoDB; + + -- rating + alter table o_userrating add constraint FKF26C8375236F20X foreign key (creator_id) references o_bs_identity (id); + create index rtn_id_idx on o_userrating (resid); + create index rtn_name_idx on o_userrating (resname); + create index rtn_subpath_idx on o_userrating (ressubpath(255)); + create index rtn_rating_idx on o_userrating (rating); + create index rtn_rating_res_idx on o_userrating (resid, resname, creator_id, rating); + + -- comment + alter table o_usercomment add constraint FK92B6864A18251F0 foreign key (parent_key) references o_usercomment (comment_id); + alter table o_usercomment add constraint FKF26C8375236F20A foreign key (creator_id) references o_bs_identity (id); + create index cmt_id_idx on o_usercomment (resid); + create index cmt_name_idx on o_usercomment (resname); + create index cmt_subpath_idx on o_usercomment (ressubpath(255)); + + -- checkpoint + alter table o_checkpoint_results add constraint FK9E30F4B661159ZZY foreign key (checkpoint_fk) references o_checkpoint (checkpoint_id) ; + alter table o_checkpoint_results add constraint FK9E30F4B661159ZZX foreign key (identity_fk) references o_bs_identity (id); + + alter table o_checkpoint add constraint FK9E30F4B661159ZZZ foreign key (checklist_fk) references o_checklist (checklist_id); + + -- plock + create index asset_idx on o_plock (asset); + + -- property + alter table o_property add constraint FKB60B1BA5190E5 foreign key (grp) references o_gp_business (group_id); + alter table o_property add constraint FKB60B1BA5F7E870BE foreign key (identity) references o_bs_identity (id); + + create index idx_prop_indexresid_idx on o_property (resourcetypeid); + create index idx_prop_category_idx on o_property (category); + create index idx_prop_name_idx on o_property (name); + create index idx_prop_restype_idx on o_property (resourcetypename); + + -- group + alter table o_bs_group_member add constraint member_identity_ctx foreign key (fk_identity_id) references o_bs_identity (id); + alter table o_bs_group_member add constraint member_group_ctx foreign key (fk_group_id) references o_bs_group (id); + create index member_to_grp_role_idx on o_bs_group_member (g_role); + + alter table o_re_to_group add constraint re_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); + alter table o_re_to_group add constraint re_to_group_re_ctx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); + + alter table o_gp_business add constraint gp_to_group_business_ctx foreign key (fk_group_id) references o_bs_group (id); + + -- business group + alter table o_gp_business add constraint idx_bgp_rsrc foreign key (fk_resource) references o_olatresource (resource_id); + + create index gp_name_idx on o_gp_business (groupname); + create index idx_grp_lifecycle_soft_idx on o_gp_business (external_id); + + alter table o_bs_namedgroup add constraint FKBAFCBBC4B85B522C foreign key (secgroup_id) references o_bs_secgroup (id); + create index groupname_idx on o_bs_namedgroup (groupname); + + -- area + alter table o_gp_bgarea add constraint idx_area_to_resource foreign key (fk_resource) references o_olatresource (resource_id); + create index name_idx on o_gp_bgarea (name); + + alter table o_gp_bgtoarea_rel add constraint FK9B663F2D1E2E7685 foreign key (group_fk) references o_gp_business (group_id); + alter table o_gp_bgtoarea_rel add constraint FK9B663F2DD381B9B7 foreign key (area_fk) references o_gp_bgarea (area_id); + + -- bs + alter table o_bs_authentication add constraint FKC6A5445652595FE6 foreign key (identity_fk) references o_bs_identity (id); + create index provider_idx on o_bs_authentication (provider); + create index credential_idx on o_bs_authentication (credential); + create index authusername_idx on o_bs_authentication (authusername); + + alter table o_bs_authentication_history add constraint auth_hist_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + + create index name_idx on o_bs_identity (name); + create index identstatus_idx on o_bs_identity (status); + create index idx_ident_creationdate_idx on o_bs_identity (creationdate); + create index idx_id_lastlogin_idx on o_bs_identity (lastlogin); + + + + alter table o_bs_membership add constraint FK7B6288B45259603C foreign key (identity_id) references o_bs_identity (id); + alter table o_bs_membership add constraint FK7B6288B4B85B522C foreign key (secgroup_id) references o_bs_secgroup (id); + + alter table o_bs_invitation add constraint inv_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); + + -- user + create index usr_notification_interval_idx on o_user (notification_interval); + create index idx_user_firstname_idx on o_user (u_firstname); + create index idx_user_lastname_idx on o_user (u_lastname); + create index idx_user_email_idx on o_user (u_email); + create index idx_user_instname_idx on o_user (u_institutionalname); + create index idx_user_instid_idx on o_user (u_institutionaluseridentifier); + create index idx_user_instemail_idx on o_user (u_institutionalemail); + create index idx_user_creationdate_idx on o_user (creationdate); + + alter table o_user add constraint user_to_ident_idx foreign key (fk_identity) references o_bs_identity(id); + alter table o_user add constraint idx_un_user_to_ident_idx UNIQUE (fk_identity); + + -- csp + create index idx_csp_log_to_ident_idx on o_csp_log (fk_identity); + + -- temporary key + create index idx_tempkey_identity_idx on o_temporarykey (fk_identity_id); + + -- pub sub + create index name_idx on o_noti_pub (resname, resid, subident); + + alter table o_noti_sub add constraint FK4FB8F04749E53702 foreign key (fk_publisher) references o_noti_pub (publisher_id); + alter table o_noti_sub add constraint FK4FB8F0476B1F22F8 foreign key (fk_identity) references o_bs_identity (id); + + -- qti + alter table o_qtiresultset add constraint FK14805D0F5259603C foreign key (identity_id) references o_bs_identity (id); + + create index oresdetindex on o_qtiresultset (olatresourcedetail); + create index oresindex on o_qtiresultset (olatresource_fk); + create index reprefindex on o_qtiresultset (repositoryref_fk); + create index assindex on o_qtiresultset (assessmentid); + + alter table o_qtiresult add constraint FK3563E67340EF401F foreign key (resultset_fk) references o_qtiresultset (resultset_id); + create index itemindex on o_qtiresult (itemident); + + -- catalog entry + alter table o_catentry add constraint FKF4433C2C7B66B0D0 foreign key (parent_id) references o_catentry (id); + alter table o_catentry add constraint FKF4433C2CA1FAC766 foreign key (fk_ownergroup) references o_bs_secgroup (id); + alter table o_catentry add constraint FKF4433C2CDDD69946 foreign key (fk_repoentry) references o_repositoryentry (repositoryentry_id); + + -- references + alter table o_references add constraint FKE971B4589AC44FBF foreign key (source_id) references o_olatresource (resource_id); + alter table o_references add constraint FKE971B458CF634A89 foreign key (target_id) references o_olatresource (resource_id); + + -- resources + create index name_idx on o_olatresource (resname); + create index id_idx on o_olatresource (resid); + + -- repository + alter table o_repositoryentry add constraint FK2F9C439888C31018 foreign key (fk_olatresource) references o_olatresource (resource_id); + + create index access_idx on o_repositoryentry (accesscode); + create index initialAuthor_idx on o_repositoryentry (initialauthor); + create index resource_idx on o_repositoryentry (resourcename); + create index displayname_idx on o_repositoryentry (displayname); + create index softkey_idx on o_repositoryentry (softkey); + create index idx_re_lifecycle_extid_idx on o_repositoryentry (external_id); + create index idx_re_lifecycle_extref_idx on o_repositoryentry (external_ref); + + alter table o_repositoryentry add constraint idx_re_lifecycle_fk foreign key (fk_lifecycle) references o_repositoryentry_cycle(id); + create index idx_re_lifecycle_soft_idx on o_repositoryentry_cycle (r_softkey); + + alter table o_repositoryentry add constraint repoentry_stats_ctx foreign key (fk_stats) references o_repositoryentry_stats (id); + + alter table o_repositoryentry add constraint re_deleted_to_identity_idx foreign key (fk_deleted_by) references o_bs_identity (id); + + -- access control + create index ac_offer_to_resource_idx on o_ac_offer (fk_resource_id); + + alter table o_ac_offer_access add constraint off_to_meth_meth_ctx foreign key (fk_method_id) references o_ac_method (method_id); + alter table o_ac_offer_access add constraint off_to_meth_off_ctx foreign key (fk_offer_id) references o_ac_offer (offer_id); + + create index ac_order_to_delivery_idx on o_ac_order (fk_delivery_id); + + alter table o_ac_order_part add constraint ord_part_ord_ctx foreign key (fk_order_id) references o_ac_order (order_id); + + alter table o_ac_order_line add constraint ord_item_ord_part_ctx foreign key (fk_order_part_id) references o_ac_order_part (order_part_id); + alter table o_ac_order_line add constraint ord_item_offer_ctx foreign key (fk_offer_id) references o_ac_offer (offer_id); + + alter table o_ac_transaction add constraint trans_ord_ctx foreign key (fk_order_id) references o_ac_order (order_id); + alter table o_ac_transaction add constraint trans_ord_part_ctx foreign key (fk_order_part_id) references o_ac_order_part (order_part_id); + alter table o_ac_transaction add constraint trans_method_ctx foreign key (fk_method_id) references o_ac_method (method_id); + + create index paypal_pay_key_idx on o_ac_paypal_transaction (pay_key); + create index paypal_pay_trx_id_idx on o_ac_paypal_transaction (ipn_transaction_id); + create index paypal_pay_s_trx_id_idx on o_ac_paypal_transaction (ipn_sender_transaction_id); + + create index idx_ac_aao_id_idx on o_ac_auto_advance_order(id); + create index idx_ac_aao_identifier_idx on o_ac_auto_advance_order(a_identifier_key, a_identifier_value); + create index idx_ac_aao_ident_idx on o_ac_auto_advance_order(fk_identity); + alter table o_ac_auto_advance_order add constraint aao_ident_idx foreign key (fk_identity) references o_bs_identity (id); + + -- reservations + alter table o_ac_reservation add constraint idx_rsrv_to_rsrc_rsrc foreign key (fk_resource) references o_olatresource (resource_id); + alter table o_ac_reservation add constraint idx_rsrv_to_rsrc_identity foreign key (fk_identity) references o_bs_identity (id); + + -- note + alter table o_note add constraint FKC2D855C263219E27 foreign key (owner_id) references o_bs_identity (id); + create index resid_idx on o_note (resourcetypeid); + create index owner_idx on o_note (owner_id); + create index restype_idx on o_note (resourcetypename); + + -- ex_task + alter table o_ex_task add constraint idx_ex_task_ident_id foreign key (fk_identity_id) references o_bs_identity(id); + alter table o_ex_task add constraint idx_ex_task_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); + alter table o_ex_task_modifier add constraint idx_ex_task_mod_ident_id foreign key (fk_identity_id) references o_bs_identity(id); + alter table o_ex_task_modifier add constraint idx_ex_task_mod_task_id foreign key (fk_task_id) references o_ex_task(id); + + -- checklist + alter table o_cl_check add constraint check_identity_ctx foreign key (fk_identity_id) references o_bs_identity (id); + alter table o_cl_check add constraint check_box_ctx foreign key (fk_checkbox_id) references o_cl_checkbox (id); + alter table o_cl_check add unique check_identity_unique_ctx (fk_identity_id, fk_checkbox_id); + create index idx_checkbox_uuid_idx on o_cl_checkbox (c_checkboxid); + + -- group tasks + alter table o_gta_task add constraint gtask_to_tasklist_idx foreign key (fk_tasklist) references o_gta_task_list (id); + alter table o_gta_task add constraint gtask_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_gta_task add constraint gtask_to_bgroup_idx foreign key (fk_businessgroup) references o_gp_business (group_id); + alter table o_gta_task add constraint gtaskreset_to_allower_idx foreign key (fk_allow_reset_identity) references o_bs_identity (id); + + alter table o_gta_task_list add constraint gta_list_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + + alter table o_gta_task_revision_date add constraint gtaskrev_to_task_idx foreign key (fk_task) references o_gta_task (id); + + alter table o_gta_mark add constraint gtamark_tasklist_idx foreign key (fk_tasklist_id) references o_gta_task_list (id); + + -- reminders + alter table o_rem_reminder add constraint rem_reminder_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_rem_reminder add constraint rem_reminder_to_creator_idx foreign key (fk_creator) references o_bs_identity (id); + + alter table o_rem_sent_reminder add constraint rem_sent_rem_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_rem_sent_reminder add constraint rem_sent_rem_to_reminder_idx foreign key (fk_reminder) references o_rem_reminder (id); + + + -- lifecycle + create index lc_pref_idx on o_lifecycle (persistentref); + create index lc_type_idx on o_lifecycle (persistenttypename); + create index lc_action_idx on o_lifecycle (action); + + -- mark + alter table o_mark add constraint FKF26C8375236F21X foreign key (creator_id) references o_bs_identity (id); + + create index mark_id_idx on o_mark(resid); + create index mark_name_idx on o_mark(resname); + create index mark_subpath_idx on o_mark(ressubpath(255)); + create index mark_businesspath_idx on o_mark(businesspath(255)); + + -- forum + alter table o_message add constraint FKF26C8375236F20E foreign key (creator_id) references o_bs_identity (id); + alter table o_message add constraint FKF26C837A3FBEB83 foreign key (modifier_id) references o_bs_identity (id); + alter table o_message add constraint FKF26C8377B66B0D0 foreign key (parent_id) references o_message (message_id); + alter table o_message add constraint FKF26C8378EAC1DBB foreign key (topthread_id) references o_message (message_id); + alter table o_message add constraint FKF26C8371CB7C4A3 foreign key (forum_fk) references o_forum (forum_id); + create index forum_msg_pseudonym_idx on o_message (pseudonym); + + create index readmessage_forum_idx on o_readmessage (forum_id); + create index readmessage_identity_idx on o_readmessage (identity_id); + + create index forum_pseudonym_idx on o_forum_pseudonym (p_pseudonym); + + -- project broker + create index projectbroker_project_broker_idx on o_projectbroker_project (projectbroker_fk); + create index projectbroker_project_id_idx on o_projectbroker_project (project_id); + create index o_projectbroker_customfields_idx on o_projectbroker_customfields (fk_project_id); + + -- info messages + alter table o_info_message add constraint FKF85553465A4FA5DC foreign key (fk_author_id) references o_bs_identity (id); + alter table o_info_message add constraint FKF85553465A4FA5EF foreign key (fk_modifier_id) references o_bs_identity (id); + + create index imsg_resid_idx on o_info_message (resid); + + -- db course + alter table o_co_db_entry add constraint FK_DB_ENTRY_TO_IDENT foreign key (identity) references o_bs_identity (id); + + create index o_co_db_course_idx on o_co_db_entry (courseid); + create index o_co_db_cat_idx on o_co_db_entry (category); + create index o_co_db_name_idx on o_co_db_entry (name); + + -- open meeting + alter table o_om_room_reference add constraint idx_omroom_to_bgroup foreign key (businessgroup) references o_gp_business (group_id); + create index idx_omroom_residname on o_om_room_reference (resourcetypename,resourcetypeid); + + -- eportfolio + alter table o_ep_artefact add constraint FKF26C8375236F28X foreign key (fk_artefact_auth_id) references o_bs_identity (id); + alter table o_ep_artefact add constraint FKA0070D12316A97B4 foreign key (fk_struct_el_id) references o_ep_struct_el (structure_id); + + alter table o_ep_struct_el add constraint FKF26C8375236F26X foreign key (fk_olatresource) references o_olatresource (resource_id); + alter table o_ep_struct_el add constraint FK4ECC1C8D636191A1 foreign key (fk_map_source_id) references o_ep_struct_el (structure_id); + alter table o_ep_struct_el add constraint FK4ECC1C8D76990817 foreign key (fk_struct_root_id) references o_ep_struct_el (structure_id); + alter table o_ep_struct_el add constraint FK4ECC1C8D76990818 foreign key (fk_struct_root_map_id) references o_ep_struct_el (structure_id); + + alter table o_ep_collect_restriction add constraint FKA0070D12316A97B5 foreign key (fk_struct_el_id) references o_ep_struct_el (structure_id); + + alter table o_ep_struct_struct_link add constraint FKF26C8375236F22X foreign key (fk_struct_parent_id) references o_ep_struct_el (structure_id); + alter table o_ep_struct_struct_link add constraint FKF26C8375236F23X foreign key (fk_struct_child_id) references o_ep_struct_el (structure_id); + + alter table o_ep_struct_artefact_link add constraint FKF26C8375236F24X foreign key (fk_struct_id) references o_ep_struct_el (structure_id); + alter table o_ep_struct_artefact_link add constraint FKF26C8375236F25X foreign key (fk_artefact_id) references o_ep_artefact (artefact_id); + alter table o_ep_struct_artefact_link add constraint FKF26C8375236F26Y foreign key (fk_auth_id) references o_bs_identity (id); + + alter table o_ep_struct_to_group add constraint struct_to_group_group_ctx foreign key (fk_group_id) references o_bs_group (id); + alter table o_ep_struct_to_group add constraint struct_to_group_re_ctx foreign key (fk_struct_id) references o_ep_struct_el (structure_id); + + -- tag + alter table o_tag add constraint FK6491FCA5A4FA5DC foreign key (fk_author_id) references o_bs_identity (id); + + -- mail + alter table o_mail add constraint FKF86663165A4FA5DC foreign key (fk_from_id) references o_mail_recipient (recipient_id); + create index idx_mail_meta_id_idx on o_mail (meta_mail_id); + + alter table o_mail_recipient add constraint FKF86663165A4FA5DG foreign key (fk_recipient_id) references o_bs_identity (id); + + alter table o_mail_to_recipient add constraint FKF86663165A4FA5DE foreign key (fk_mail_id) references o_mail (mail_id); + alter table o_mail_to_recipient add constraint FKF86663165A4FA5DD foreign key (fk_recipient_id) references o_mail_recipient (recipient_id); + + alter table o_mail_attachment add constraint FKF86663165A4FA5DF foreign key (fk_att_mail_id) references o_mail (mail_id); + create index idx_mail_att_checksum_idx on o_mail_attachment (datas_checksum); + create index idx_mail_path_idx on o_mail_attachment (datas_path(255)); + create index idx_mail_att_siblings_idx on o_mail_attachment (datas_checksum, mimetype, datas_size, datas_name); + + -- instant messaging + alter table o_im_message add constraint idx_im_msg_to_fromid foreign key (fk_from_identity_id) references o_bs_identity (id); + create index idx_im_msg_res_idx on o_im_message (msg_resid,msg_resname); + + alter table o_im_notification add constraint idx_im_not_to_toid foreign key (fk_to_identity_id) references o_bs_identity (id); + alter table o_im_notification add constraint idx_im_not_to_fromid foreign key (fk_from_identity_id) references o_bs_identity (id); + create index idx_im_chat_res_idx on o_im_notification (chat_resid,chat_resname); + + alter table o_im_roster_entry add constraint idx_im_rost_to_id foreign key (fk_identity_id) references o_bs_identity (id); + create index idx_im_rost_res_idx on o_im_roster_entry (r_resid,r_resname); + + alter table o_im_preferences add constraint idx_im_prfs_to_id foreign key (fk_from_identity_id) references o_bs_identity (id); + + -- efficiency statements + alter table o_as_eff_statement add unique eff_statement_id_cstr (fk_identity, fk_resource_id), add constraint eff_statement_id_cstr foreign key (fk_identity) references o_bs_identity (id); + create index eff_statement_repo_key_idx on o_as_eff_statement (course_repo_key); + + -- course infos + alter table o_as_user_course_infos add index user_course_infos_id_cstr (fk_identity), add constraint user_course_infos_id_cstr foreign key (fk_identity) references o_bs_identity (id); + alter table o_as_user_course_infos add index user_course_infos_res_cstr (fk_resource_id), add constraint user_course_infos_res_cstr foreign key (fk_resource_id) references o_olatresource (resource_id); + alter table o_as_user_course_infos add unique (fk_identity, fk_resource_id); + + alter table o_as_entry add constraint as_entry_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_as_entry add constraint as_entry_to_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_as_entry add constraint as_entry_to_refentry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); + + create index idx_as_entry_to_id_idx on o_as_entry (a_assessment_id); + + -- gotomeeting + alter table o_goto_organizer add constraint goto_organ_owner_idx foreign key (fk_identity) references o_bs_identity (id); + create index idx_goto_organ_okey_idx on o_goto_organizer(g_organizer_key); + create index idx_goto_organ_uname_idx on o_goto_organizer(g_username); + + alter table o_goto_meeting add constraint goto_meet_repoentry_idx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); + alter table o_goto_meeting add constraint goto_meet_busgrp_idx foreign key (fk_group_id) references o_gp_business (group_id); + alter table o_goto_meeting add constraint goto_meet_organizer_idx foreign key (fk_organizer_id) references o_goto_organizer (id); + + alter table o_goto_registrant add constraint goto_regis_meeting_idx foreign key (fk_meeting_id) references o_goto_meeting (id); + alter table o_goto_registrant add constraint goto_regis_ident_idx foreign key (fk_identity_id) references o_bs_identity (id); + + -- video + alter table o_vid_transcoding add constraint fk_resource_id_idx foreign key (fk_resource_id) references o_olatresource (resource_id); + create index vid_status_trans_idx on o_vid_transcoding(vid_status); + create index vid_transcoder_trans_idx on o_vid_transcoding(vid_transcoder); + alter table o_vid_metadata add constraint vid_meta_rsrc_idx foreign key (fk_resource_id) references o_olatresource (resource_id); + + + -- calendar + alter table o_cal_use_config add constraint cal_u_conf_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + create index idx_cal_u_conf_cal_id_idx on o_cal_use_config (c_calendar_id); + create index idx_cal_u_conf_cal_type_idx on o_cal_use_config (c_calendar_type); + + alter table o_cal_import add constraint cal_imp_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + create index idx_cal_imp_cal_id_idx on o_cal_import (c_calendar_id); + create index idx_cal_imp_cal_type_idx on o_cal_import (c_calendar_type); + + create index idx_cal_imp_to_cal_id_idx on o_cal_import_to (c_to_calendar_id); + create index idx_cal_imp_to_cal_type_idx on o_cal_import_to (c_to_calendar_type); + + -- mapper + create index o_mapper_uuid_idx on o_mapper (mapper_uuid); + + -- qti 2.1 + alter table o_qti_assessmenttest_session add constraint qti_sess_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_qti_assessmenttest_session add constraint qti_sess_to_course_entry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); + alter table o_qti_assessmenttest_session add constraint qti_sess_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_qti_assessmenttest_session add constraint qti_sess_to_as_entry_idx foreign key (fk_assessment_entry) references o_as_entry (id); + + alter table o_qti_assessmentitem_session add constraint qti_itemsess_to_testsess_idx foreign key (fk_assessmenttest_session) references o_qti_assessmenttest_session (id); + create index idx_item_identifier_idx on o_qti_assessmentitem_session (q_itemidentifier); + + alter table o_qti_assessment_response add constraint qti_resp_to_testsession_idx foreign key (fk_assessmenttest_session) references o_qti_assessmenttest_session (id); + alter table o_qti_assessment_response add constraint qti_resp_to_itemsession_idx foreign key (fk_assessmentitem_session) references o_qti_assessmentitem_session (id); + create index idx_response_identifier_idx on o_qti_assessment_response (q_responseidentifier); + + alter table o_qti_assessment_marks add constraint qti_marks_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_qti_assessment_marks add constraint qti_marks_to_course_entry_idx foreign key (fk_reference_entry) references o_repositoryentry (repositoryentry_id); + alter table o_qti_assessment_marks add constraint qti_marks_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + + -- portfolio + alter table o_pf_binder add constraint pf_binder_resource_idx foreign key (fk_olatresource_id) references o_olatresource (resource_id); + alter table o_pf_binder add constraint pf_binder_group_idx foreign key (fk_group_id) references o_bs_group (id); + alter table o_pf_binder add constraint pf_binder_course_idx foreign key (fk_entry_id) references o_repositoryentry (repositoryentry_id); + alter table o_pf_binder add constraint pf_binder_template_idx foreign key (fk_template_id) references o_pf_binder (id); + + alter table o_pf_section add constraint pf_section_group_idx foreign key (fk_group_id) references o_bs_group (id); + alter table o_pf_section add constraint pf_section_binder_idx foreign key (fk_binder_id) references o_pf_binder (id); + alter table o_pf_section add constraint pf_section_template_idx foreign key (fk_template_reference_id) references o_pf_section (id); + + alter table o_pf_page add constraint pf_page_group_idx foreign key (fk_group_id) references o_bs_group (id); + alter table o_pf_page add constraint pf_page_section_idx foreign key (fk_section_id) references o_pf_section (id); + + alter table o_pf_page add constraint pf_page_body_idx foreign key (fk_body_id) references o_pf_page_body (id); + + alter table o_pf_media add constraint pf_media_author_idx foreign key (fk_author_id) references o_bs_identity (id); + create index idx_category_rel_resid_idx on o_pf_media (p_business_path); + + alter table o_pf_page_part add constraint pf_page_page_body_idx foreign key (fk_page_body_id) references o_pf_page_body (id); + alter table o_pf_page_part add constraint pf_page_media_idx foreign key (fk_media_id) references o_pf_media (id); + alter table o_pf_page_part add constraint pf_part_form_idx foreign key (fk_form_entry_id) references o_repositoryentry (repositoryentry_id); + + create index idx_category_name_idx on o_pf_category (p_name); + + alter table o_pf_category_relation add constraint pf_category_rel_cat_idx foreign key (fk_category_id) references o_pf_category (id); + create index idx_category_rel_resid_idx on o_pf_category_relation (p_resid); + + alter table o_pf_assessment_section add constraint pf_asection_section_idx foreign key (fk_section_id) references o_pf_section (id); + alter table o_pf_assessment_section add constraint pf_asection_ident_idx foreign key (fk_identity_id) references o_bs_identity (id); + + alter table o_pf_assignment add constraint pf_assign_section_idx foreign key (fk_section_id) references o_pf_section (id); + alter table o_pf_assignment add constraint pf_assign_ref_assign_idx foreign key (fk_template_reference_id) references o_pf_assignment (id); + alter table o_pf_assignment add constraint pf_assign_page_idx foreign key (fk_page_id) references o_pf_page (id); + alter table o_pf_assignment add constraint pf_assign_assignee_idx foreign key (fk_assignee_id) references o_bs_identity (id); + alter table o_pf_assignment add constraint pf_assign_form_idx foreign key (fk_form_entry_id) references o_repositoryentry (repositoryentry_id); + + alter table o_pf_binder_user_infos add constraint binder_user_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_pf_binder_user_infos add constraint binder_user_binder_idx foreign key (fk_binder) references o_pf_binder (id); + + alter table o_pf_page_user_infos add constraint user_pfpage_idx foreign key (fk_identity_id) references o_bs_identity (id); + alter table o_pf_page_user_infos add constraint page_pfpage_idx foreign key (fk_page_id) references o_pf_page (id); + + -- evaluation form + create unique index idx_eva_surv_ores_idx on o_eva_form_survey (e_resid, e_resname, e_sub_ident(255)); + + alter table o_eva_form_participation add constraint eva_part_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); + create unique index idx_eva_part_ident_idx on o_eva_form_participation (e_identifier_key, e_identifier_type, fk_survey); + create unique index idx_eva_part_executor_idx on o_eva_form_participation (fk_executor, fk_survey); + + alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); + alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); + alter table o_eva_form_session add constraint eva_sess_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_eva_form_session add constraint eva_sess_to_body_idx foreign key (fk_page_body) references o_pf_page_body (id); + alter table o_eva_form_session add constraint eva_sess_to_form_idx foreign key (fk_form_entry) references o_repositoryentry (repositoryentry_id); + + alter table o_eva_form_response add constraint eva_resp_to_sess_idx foreign key (fk_session) references o_eva_form_session (id); + + -- question pool + alter table o_qp_pool add constraint idx_qp_pool_owner_grp_id foreign key (fk_ownergroup) references o_bs_secgroup(id); + + alter table o_qp_pool_2_item add constraint idx_qp_pool_2_item_pool_id foreign key (fk_pool_id) references o_qp_pool(id); + alter table o_qp_pool_2_item add constraint idx_qp_pool_2_item_item_id foreign key (fk_item_id) references o_qp_item(id); + alter table o_qp_pool_2_item add unique (fk_pool_id, fk_item_id); + + alter table o_qp_share_item add constraint idx_qp_share_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); + alter table o_qp_share_item add constraint idx_qp_share_item_id foreign key (fk_item_id) references o_qp_item(id); + alter table o_qp_share_item add unique (fk_resource_id, fk_item_id); + + alter table o_qp_item_collection add constraint idx_qp_coll_owner_id foreign key (fk_owner_id) references o_bs_identity(id); + + alter table o_qp_collection_2_item add constraint idx_qp_coll_coll_id foreign key (fk_collection_id) references o_qp_item_collection(id); + alter table o_qp_collection_2_item add constraint idx_qp_coll_item_id foreign key (fk_item_id) references o_qp_item(id); + alter table o_qp_collection_2_item add unique (fk_collection_id, fk_item_id); + + alter table o_qp_item add constraint idx_qp_pool_2_tax_id foreign key (fk_taxonomy_level_v2) references o_tax_taxonomy_level(id); + alter table o_qp_item add constraint idx_qp_item_owner_id foreign key (fk_ownergroup) references o_bs_secgroup(id); + alter table o_qp_item add constraint idx_qp_item_edu_ctxt_id foreign key (fk_edu_context) references o_qp_edu_context(id); + alter table o_qp_item add constraint idx_qp_item_type_id foreign key (fk_type) references o_qp_item_type(id); + alter table o_qp_item add constraint idx_qp_item_license_id foreign key (fk_license) references o_qp_license(id); + + alter table o_qp_taxonomy_level add constraint idx_qp_field_2_parent_id foreign key (fk_parent_field) references o_qp_taxonomy_level(id); + create index idx_taxon_mat_pathon on o_qp_taxonomy_level (q_mat_path_ids(255)); + + alter table o_qp_item_type add unique (q_type(200)); + create index idx_item_audit_item_idx on o_qp_item_audit_log (fk_item_id); + + -- lti outcome + alter table o_lti_outcome add constraint idx_lti_outcome_ident_id foreign key (fk_identity_id) references o_bs_identity(id); + alter table o_lti_outcome add constraint idx_lti_outcome_rsrc_id foreign key (fk_resource_id) references o_olatresource(resource_id); + + -- assessment mode + alter table o_as_mode_course add constraint as_mode_to_repo_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + + alter table o_as_mode_course_to_group add constraint as_modetogroup_group_idx foreign key (fk_group_id) references o_gp_business (group_id); + alter table o_as_mode_course_to_group add constraint as_modetogroup_mode_idx foreign key (fk_assessment_mode_id) references o_as_mode_course (id); + + alter table o_as_mode_course_to_area add constraint as_modetoarea_area_idx foreign key (fk_area_id) references o_gp_bgarea (area_id); + alter table o_as_mode_course_to_area add constraint as_modetoarea_mode_idx foreign key (fk_assessment_mode_id) references o_as_mode_course (id); + + -- certificate + alter table o_cer_certificate add constraint cer_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + alter table o_cer_certificate add constraint cer_to_resource_idx foreign key (fk_olatresource) references o_olatresource (resource_id); + + create index cer_archived_resource_idx on o_cer_certificate (c_archived_resource_id); + create index cer_uuid_idx on o_cer_certificate (c_uuid); + + -- sms + alter table o_sms_message_log add constraint sms_log_to_identity_idx foreign key (fk_identity) references o_bs_identity (id); + + -- webfeed + create index idx_feed_resourceable_idx on o_feed (f_resourceable_id, f_resourceable_type); + alter table o_feed_item add constraint item_to_feed_fk foreign key(fk_feed_id) references o_feed(id); + create index idx_item_feed_idx on o_feed_item(fk_feed_id); + alter table o_feed_item add constraint feed_item_to_ident_author_fk foreign key (fk_identity_author_id) references o_bs_identity (id); + create index idx_item_ident_author_idx on o_feed_item(fk_identity_author_id); + alter table o_feed_item add constraint feed_item_to_ident_modified_fk foreign key (fk_identity_modified_id) references o_bs_identity (id); + create index idx_item_ident_modified_idx on o_feed_item(fk_identity_modified_id); + + -- lecture + alter table o_lecture_block add constraint lec_block_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_lecture_block add constraint lec_block_gcoach_idx foreign key (fk_teacher_group) references o_bs_group (id); + alter table o_lecture_block add constraint lec_block_reason_idx foreign key (fk_reason) references o_lecture_reason (id); + + alter table o_lecture_block_to_group add constraint lec_block_to_block_idx foreign key (fk_group) references o_bs_group (id); + alter table o_lecture_block_to_group add constraint lec_block_to_group_idx foreign key (fk_lecture_block) references o_lecture_block (id); + + alter table o_lecture_block_roll_call add constraint lec_call_block_idx foreign key (fk_lecture_block) references o_lecture_block (id); + alter table o_lecture_block_roll_call add constraint lec_call_identity_idx foreign key (fk_identity) references o_bs_identity (id); + + alter table o_lecture_reminder add constraint lec_reminder_block_idx foreign key (fk_lecture_block) references o_lecture_block (id); + alter table o_lecture_reminder add constraint lec_reminder_identity_idx foreign key (fk_identity) references o_bs_identity (id); + + alter table o_lecture_participant_summary add constraint lec_part_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_lecture_participant_summary add constraint lec_part_ident_idx foreign key (fk_identity) references o_bs_identity (id); + + alter table o_lecture_entry_config add constraint lec_entry_config_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + + create index idx_lec_audit_entry_idx on o_lecture_block_audit_log(fk_entry); + create index idx_lec_audit_ident_idx on o_lecture_block_audit_log(fk_identity); + + -- taxonomy + alter table o_tax_taxonomy add constraint tax_to_group_idx foreign key (fk_group) references o_bs_group (id); + + alter table o_tax_taxonomy_level_type add constraint tax_type_to_taxonomy_idx foreign key (fk_taxonomy) references o_tax_taxonomy (id); + + alter table o_tax_taxonomy_type_to_type add constraint tax_type_to_type_idx foreign key (fk_type) references o_tax_taxonomy_level_type (id); + create index idx_tax_type_to_type_idx on o_tax_taxonomy_type_to_type (fk_type); + alter table o_tax_taxonomy_type_to_type add constraint tax_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_tax_taxonomy_level_type (id); + create index idx_tax_type_to_sub_type_idx on o_tax_taxonomy_type_to_type (fk_allowed_sub_type); + + alter table o_tax_taxonomy_level add constraint tax_level_to_taxonomy_idx foreign key (fk_taxonomy) references o_tax_taxonomy (id); + alter table o_tax_taxonomy_level add constraint tax_level_to_tax_level_idx foreign key (fk_parent) references o_tax_taxonomy_level (id); + alter table o_tax_taxonomy_level add constraint tax_level_to_type_idx foreign key (fk_type) references o_tax_taxonomy_level_type (id); + create index idx_tax_level_path_key_idx on o_tax_taxonomy_level (t_m_path_keys); + + alter table o_tax_taxonomy_competence add constraint tax_comp_to_tax_level_idx foreign key (fk_level) references o_tax_taxonomy_level (id); + alter table o_tax_taxonomy_competence add constraint tax_level_to_ident_idx foreign key (fk_identity) references o_bs_identity (id); + + -- dialog elements + alter table o_dialog_element add constraint dial_el_author_idx foreign key (fk_author) references o_bs_identity (id); + alter table o_dialog_element add constraint dial_el_entry_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_dialog_element add constraint dial_el_forum_idx foreign key (fk_forum) references o_forum (forum_id); + create index idx_dial_el_subident_idx on o_dialog_element (d_subident); + + -- licenses + alter table o_lic_license_type_activation add constraint lic_activation_type_fk foreign key (fk_license_type_id) references o_lic_license_type (id); + create index lic_activation_type_idx on o_lic_license_type_activation (fk_license_type_id); + alter table o_lic_license add constraint lic_license_type_fk foreign key (fk_license_type_id) references o_lic_license_type (id); + create index lic_license_type_idx on o_lic_license (fk_license_type_id); + create unique index lic_license_ores_idx on o_lic_license (l_resid, l_resname); + + -- organisation + alter table o_org_organisation add constraint org_to_group_idx foreign key (fk_group) references o_bs_group (id); + alter table o_org_organisation add constraint org_to_root_org_idx foreign key (fk_root) references o_org_organisation (id); + alter table o_org_organisation add constraint org_to_parent_org_idx foreign key (fk_parent) references o_org_organisation (id); + alter table o_org_organisation add constraint org_to_org_type_idx foreign key (fk_type) references o_org_organisation_type (id); + + alter table o_org_type_to_type add constraint org_type_to_type_idx foreign key (fk_type) references o_org_organisation_type (id); + alter table o_org_type_to_type add constraint org_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_org_organisation_type (id); + + alter table o_re_to_organisation add constraint rel_org_to_re_idx foreign key (fk_entry) references o_repositoryentry (repositoryentry_id); + alter table o_re_to_organisation add constraint rel_org_to_org_idx foreign key (fk_organisation) references o_org_organisation (id); + + -- curriculum + alter table o_cur_curriculum add constraint cur_to_group_idx foreign key (fk_group) references o_bs_group (id); + alter table o_cur_curriculum add constraint cur_to_org_idx foreign key (fk_organisation) references o_org_organisation (id); + + alter table o_cur_curriculum_element add constraint cur_el_to_group_idx foreign key (fk_group) references o_bs_group (id); + alter table o_cur_curriculum_element add constraint cur_el_to_cur_el_idx foreign key (fk_parent) references o_cur_curriculum_element (id); + alter table o_cur_curriculum_element add constraint cur_el_to_cur_idx foreign key (fk_curriculum) references o_cur_curriculum (id); + + alter table o_cur_element_type_to_type add constraint cur_type_to_type_idx foreign key (fk_type) references o_cur_element_type (id); + alter table o_cur_element_type_to_type add constraint cur_type_to_sub_type_idx foreign key (fk_allowed_sub_type) references o_cur_element_type (id); + + -- o_logging_table + create index log_target_resid_idx on o_loggingtable(targetresid); + create index log_ptarget_resid_idx on o_loggingtable(parentresid); + create index log_gptarget_resid_idx on o_loggingtable(grandparentresid); + create index log_ggptarget_resid_idx on o_loggingtable(greatgrandparentresid); + create index log_creationdate_idx on o_loggingtable(creationdate); + + + insert into hibernate_unique_key values ( 0 ); + SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql index 9adea335db6..4d2ddc81dbf 100644 --- a/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql @@ -184,3 +184,6 @@ alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key ( create index idx_eva_sess_to_surv_idx on o_eva_form_session (fk_survey); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); + +-- membership +alter table o_bs_group_member add g_inheritance_mode varchar(16) default 'none' not null; diff --git a/src/main/resources/database/oracle/setupDatabase.sql b/src/main/resources/database/oracle/setupDatabase.sql index 77ab5a68214..940aaa4ffaa 100644 --- a/src/main/resources/database/oracle/setupDatabase.sql +++ b/src/main/resources/database/oracle/setupDatabase.sql @@ -55,6 +55,7 @@ CREATE TABLE o_bs_group_member ( creationdate date not null, lastmodified date not null, g_role varchar2(50 char) not null, + g_inheritance_mode varchar2(16 char) default 'none' not null, fk_group_id number(20) not null, fk_identity_id number(20) not null, PRIMARY KEY (id) diff --git a/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql index 0904cd04b05..9f2610789d5 100644 --- a/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql @@ -189,3 +189,7 @@ create index idx_eva_sess_to_surv_idx on o_eva_form_session (fk_survey); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); create unique index idx_eva_sess_to_part_idx on o_eva_form_session (fk_participation); + +-- membership +alter table o_bs_group_member add column g_inheritance_mode varchar(16) default 'none' not null; + diff --git a/src/main/resources/database/postgresql/setupDatabase.sql b/src/main/resources/database/postgresql/setupDatabase.sql index 753003e6c4b..832b465f8cf 100644 --- a/src/main/resources/database/postgresql/setupDatabase.sql +++ b/src/main/resources/database/postgresql/setupDatabase.sql @@ -49,6 +49,7 @@ create table o_bs_group_member ( creationdate timestamp not null, lastmodified timestamp not null, g_role varchar(50) not null, + g_inheritance_mode varchar(16) default 'none' not null, fk_group_id int8 not null, fk_identity_id int8 not null, primary key (id) diff --git a/src/test/java/org/olat/basesecurity/manager/OrganisationDAOTest.java b/src/test/java/org/olat/basesecurity/manager/OrganisationDAOTest.java index 0d54a49d937..ff8bf79c73e 100644 --- a/src/test/java/org/olat/basesecurity/manager/OrganisationDAOTest.java +++ b/src/test/java/org/olat/basesecurity/manager/OrganisationDAOTest.java @@ -24,6 +24,7 @@ import java.util.UUID; import org.junit.Assert; import org.junit.Test; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; import org.olat.basesecurity.OrganisationType; @@ -134,7 +135,7 @@ public class OrganisationDAOTest extends OlatTestCase { String identifier = UUID.randomUUID().toString(); Organisation organisation = organisationDao.createAndPersistOrganisation("OpenOLAT EE", identifier, null, null, null); dbInstance.commit(); - organisationService.addMember(organisation, member, OrganisationRoles.user); + organisationService.addMember(organisation, member, OrganisationRoles.user, GroupMembershipInheritance.none); dbInstance.commitAndCloseSession(); List<OrganisationMember> members = organisationDao.getMembers(organisation); @@ -152,8 +153,8 @@ public class OrganisationDAOTest extends OlatTestCase { String identifier = UUID.randomUUID().toString(); Organisation organisation = organisationDao.createAndPersistOrganisation("Org 6", identifier, null, null, null); dbInstance.commit(); - organisationService.addMember(organisation, member1, OrganisationRoles.groupmanager); - organisationService.addMember(organisation, member2, OrganisationRoles.usermanager); + organisationService.addMember(organisation, member1, OrganisationRoles.groupmanager, GroupMembershipInheritance.none); + organisationService.addMember(organisation, member2, OrganisationRoles.usermanager, GroupMembershipInheritance.none); dbInstance.commitAndCloseSession(); List<Identity> userManagers = organisationDao.getIdentities(identifier, OrganisationRoles.usermanager.name()); @@ -169,7 +170,7 @@ public class OrganisationDAOTest extends OlatTestCase { String identifier = UUID.randomUUID().toString(); Organisation organisation = organisationDao.createAndPersistOrganisation("OpenOLAT E2E", identifier, null, null, null); dbInstance.commit(); - organisationService.addMember(organisation, member, OrganisationRoles.poolmanager); + organisationService.addMember(organisation, member, OrganisationRoles.poolmanager, GroupMembershipInheritance.none); dbInstance.commitAndCloseSession(); boolean isPoolManager = organisationDao.hasRole(member, identifier, OrganisationRoles.poolmanager.name()); diff --git a/src/test/java/org/olat/basesecurity/manager/OrganisationServiceTest.java b/src/test/java/org/olat/basesecurity/manager/OrganisationServiceTest.java index 370a020f40f..04da07c20ea 100644 --- a/src/test/java/org/olat/basesecurity/manager/OrganisationServiceTest.java +++ b/src/test/java/org/olat/basesecurity/manager/OrganisationServiceTest.java @@ -20,12 +20,23 @@ package org.olat.basesecurity.manager; import java.util.List; +import java.util.UUID; import org.junit.Assert; import org.junit.Test; +import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.BaseSecurityModule; +import org.olat.basesecurity.GroupMembership; +import org.olat.basesecurity.GroupMembershipInheritance; +import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; +import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; +import org.olat.core.id.Organisation; +import org.olat.core.id.User; +import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; +import org.olat.user.UserManager; import org.springframework.beans.factory.annotation.Autowired; /** @@ -36,14 +47,127 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class OrganisationServiceTest extends OlatTestCase { + @Autowired + private DB dbInstance; + @Autowired + private GroupDAO groupDao; + @Autowired + private UserManager userManager; + @Autowired + private BaseSecurity securityManager; @Autowired private OrganisationService organisationService; + @Test + public void getDefaultOrganisation() { + Organisation organisation = organisationService.getDefaultOrganisation(); + Assert.assertNotNull(organisation); + Assert.assertEquals(OrganisationService.DEFAULT_ORGANISATION_IDENTIFIER, organisation.getIdentifier()); + } + @Test public void getDefaultsSystemAdministator() { List<Identity> administrators = organisationService.getDefaultsSystemAdministator(); Assert.assertNotNull(administrators); Assert.assertFalse(administrators.isEmpty()); } + + @Test + public void addMembershipWithInheritance() { + Identity user = createRandomUser("Org. user"); + + Organisation organisation = organisationService.getDefaultOrganisation(); + String identifierLevel1 = UUID.randomUUID().toString(); + Organisation organisationLevel1 = organisationService.createOrganisation("Sub-organisation", identifierLevel1, "", organisation, null); + String identifierLevel2 = UUID.randomUUID().toString(); + Organisation organisationLevel2 = organisationService.createOrganisation("Sub-sub-organisation", identifierLevel2, "", organisationLevel1, null); + dbInstance.commitAndCloseSession(); + + //add membership + organisationService.addMember(organisationLevel1, user, OrganisationRoles.user, GroupMembershipInheritance.root); + dbInstance.commitAndCloseSession(); + + //check level 1 + GroupMembership membershipLevel1 = groupDao.getMembership(organisationLevel1.getGroup(), user, OrganisationRoles.user.name()); + Assert.assertNotNull(membershipLevel1); + Assert.assertEquals(OrganisationRoles.user.name(), membershipLevel1.getRole()); + Assert.assertEquals(GroupMembershipInheritance.root, membershipLevel1.getInheritanceMode()); + + //check level 2 + GroupMembership membershipLevel2 = groupDao.getMembership(organisationLevel2.getGroup(), user, OrganisationRoles.user.name()); + Assert.assertEquals(OrganisationRoles.user.name(), membershipLevel2.getRole()); + Assert.assertEquals(GroupMembershipInheritance.inherited, membershipLevel2.getInheritanceMode()); + } + + @Test + public void removeAllMembershipWithInheritance() { + Identity user = createRandomUser("Org. user"); + + Organisation organisation = organisationService.getDefaultOrganisation(); + String identifierLevel1 = UUID.randomUUID().toString(); + Organisation organisationLevel1 = organisationService.createOrganisation("1. Org.", identifierLevel1, "", organisation, null); + String identifierLevel1_1 = UUID.randomUUID().toString(); + Organisation organisationLevel1_1 = organisationService.createOrganisation("1.1.", identifierLevel1_1, "", organisationLevel1, null); + dbInstance.commitAndCloseSession(); + + //add membership + organisationService.addMember(organisationLevel1, user, OrganisationRoles.user, GroupMembershipInheritance.root); + organisationService.addMember(organisationLevel1_1, user, OrganisationRoles.author, GroupMembershipInheritance.none); + dbInstance.commitAndCloseSession(); + + //check level 1 + GroupMembership membershipLevel1 = groupDao.getMembership(organisationLevel1.getGroup(), user, OrganisationRoles.user.name()); + Assert.assertNotNull(membershipLevel1); + Assert.assertEquals(OrganisationRoles.user.name(), membershipLevel1.getRole()); + Assert.assertEquals(GroupMembershipInheritance.root, membershipLevel1.getInheritanceMode()); + + //check level 1-1 + GroupMembership membershipLevel2 = groupDao.getMembership(organisationLevel1_1.getGroup(), user, OrganisationRoles.user.name()); + Assert.assertEquals(OrganisationRoles.user.name(), membershipLevel2.getRole()); + Assert.assertEquals(GroupMembershipInheritance.inherited, membershipLevel2.getInheritanceMode()); + + // remove all the memberships + organisationService.removeMember(organisationLevel1, user); + dbInstance.commitAndCloseSession(); + + // check there is no membership left + List<GroupMembership> membershipsLevel1 = groupDao.getMemberships(organisationLevel1.getGroup(), user); + Assert.assertTrue(membershipsLevel1.isEmpty()); + List<GroupMembership> membershipsLevel1_1 = groupDao.getMemberships(organisationLevel1_1.getGroup(), user); + Assert.assertEquals(1, membershipsLevel1_1.size()); + + GroupMembership lastMembersip = membershipsLevel1_1.get(0); + Assert.assertEquals(OrganisationRoles.author.name(), lastMembersip.getRole()); + } + + @Test + public void createSubOrgnisationWithInheritedsMemberships() { + Identity user = createRandomUser("Org. user"); + + Organisation defOrganisation = organisationService.getDefaultOrganisation(); + Organisation organisation = organisationService.createOrganisation("Inherit-organisation", "Top", "", defOrganisation, null); + organisationService.addMember(organisation, user, OrganisationRoles.usermanager, GroupMembershipInheritance.root); + organisationService.addMember(organisation, user, OrganisationRoles.user, GroupMembershipInheritance.none); + dbInstance.commitAndCloseSession(); + + + Organisation subOrganisation = organisationService.createOrganisation("Sub-organisation", "Sub", "", organisation, null); + + //check level user role (not inherited) + GroupMembership userMembership = groupDao.getMembership(subOrganisation.getGroup(), user, OrganisationRoles.user.name()); + Assert.assertNull(userMembership); + + //check level user manager role (inherited) + GroupMembership userManagerMembership = groupDao.getMembership(subOrganisation.getGroup(), user, OrganisationRoles.usermanager.name()); + Assert.assertEquals(OrganisationRoles.usermanager.name(), userManagerMembership.getRole()); + Assert.assertEquals(GroupMembershipInheritance.inherited, userManagerMembership.getInheritanceMode()); + } + + private Identity createRandomUser(String login) { + login += UUID.randomUUID().toString(); + User user = userManager.createUser("first" + login, "last" + login, login + "@openolat.com"); + return securityManager.createAndPersistIdentityAndUser(login, null, user, + BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, JunitTestHelper.PWD); + } } diff --git a/src/test/java/org/olat/core/id/context/HistoryManagerTest.java b/src/test/java/org/olat/core/id/context/HistoryManagerTest.java index 6549480469b..55669df7a13 100644 --- a/src/test/java/org/olat/core/id/context/HistoryManagerTest.java +++ b/src/test/java/org/olat/core/id/context/HistoryManagerTest.java @@ -41,6 +41,7 @@ public class HistoryManagerTest extends OlatTestCase { @Autowired private HistoryManager historyManager; + /** * Test the compatibility for old resume files with business group * @throws IOException @@ -96,4 +97,32 @@ public class HistoryManagerTest extends OlatTestCase { HistoryPoint history = historyManager.readHistory(resumeXml); Assert.assertNotNull(history); } + + /** + * Test the compatibility with version 13 (varian a) + * @throws IOException + * @throws URISyntaxException + */ + @Test + public void testRead_v13a() throws IOException, URISyntaxException { + URL xmlUrl = HistoryManagerTest.class.getResource("resume_ver13a.xml"); + assertNotNull(xmlUrl); + File resumeXml = new File(xmlUrl.toURI()); + HistoryPoint history = historyManager.readHistory(resumeXml); + Assert.assertNotNull(history); + } + + /** + * Test the compatibility with version 13 (varian b) + * @throws IOException + * @throws URISyntaxException + */ + @Test + public void testRead_v13b() throws IOException, URISyntaxException { + URL xmlUrl = HistoryManagerTest.class.getResource("resume_ver13b.xml"); + assertNotNull(xmlUrl); + File resumeXml = new File(xmlUrl.toURI()); + HistoryPoint history = historyManager.readHistory(resumeXml); + Assert.assertNotNull(history); + } } diff --git a/src/test/java/org/olat/core/id/context/resume_ver13a.xml b/src/test/java/org/olat/core/id/context/resume_ver13a.xml new file mode 100644 index 00000000000..467a6dde812 --- /dev/null +++ b/src/test/java/org/olat/core/id/context/resume_ver13a.xml @@ -0,0 +1,260 @@ +<org.olat.core.id.context.HistoryPointImpl> + <uuid>16</uuid> + <businessPath>[RepositoryEntry:5242880][CourseNode:91389880396330]</businessPath> + <entries> + <org.olat.core.id.context.MyContextEntry> + <olatResourceable class="org.olat.repository.RepositoryEntry"> + <key>5242880</key> + <version>2</version> + <creationDate class="sql-timestamp">2018-05-04 09:58:45</creationDate> + <lastModified>2018-05-04 09:58:45.321 UTC</lastModified> + <softkey>2_1_97627386084952</softkey> + <olatResource class="org.olat.resource.OLATResourceImpl"> + <key>5144576</key> + <version>0</version> + <creationDate>2018-05-04 09:58:45.139 UTC</creationDate> + <resName>CourseModule</resName> + <resId>97627386084951</resId> + </olatResource> + <groups class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>false</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.groups</role> + <key class="long">5242880</key> + <dirty>false</dirty> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + </groups> + <organisations class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>true</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.organisations</role> + <key class="long">5242880</key> + <dirty>false</dirty> + <storedSnapshot class="map"> + <entry> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl> + <key>617</key> + <creationDate>2018-05-04 09:58:45.158 UTC</creationDate> + <lastModified reference="../creationDate"/> + <master>false</master> + <entry> + <key>5242880</key> + <version>1</version> + <creationDate>2018-05-04 09:58:45.128 UTC</creationDate> + <lastModified reference="../creationDate"/> + <softkey>2_1_97627386084952</softkey> + <olatResource class="org.olat.resource.OLATResourceImpl" reference="../../../../../../olatResource"/> + <groups class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>true</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.groups</role> + <key class="long">5242880</key> + <dirty>false</dirty> + <storedSnapshot class="map"> + <entry> + <org.olat.repository.model.RepositoryEntryToGroupRelation> + <key>5275648</key> + <creationDate>2018-05-04 09:58:45.152 UTC</creationDate> + <defaultGroup>true</defaultGroup> + <group class="org.olat.basesecurity.model.GroupImpl"> + <key>5210112</key> + <creationDate>2018-05-04 09:58:45.146 UTC</creationDate> + <members class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>true</initialized> + <owner class="org.olat.basesecurity.model.GroupImpl" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.basesecurity.model.GroupImpl.members</role> + <key class="long">5210112</key> + <dirty>false</dirty> + <storedSnapshot class="map"> + <entry> + <org.olat.basesecurity.model.GroupMembershipImpl> + <key>4980738</key> + <creationDate>2018-05-04 09:58:45.152 UTC</creationDate> + <lastModified>2018-05-04 09:58:45.152 UTC</lastModified> + <role>owner</role> + <inheritanceModeString>none</inheritanceModeString> + <group class="org.olat.basesecurity.model.GroupImpl" reference="../../../../.."/> + <identity class="org.olat.basesecurity.IdentityImpl"> + <key>4882432</key> + <version>0</version> + <creationDate class="sql-timestamp">2018-05-04 09:58:42</creationDate> + <lastLogin class="sql-timestamp">2018-05-04 09:58:42</lastLogin> + <name>selena-1ecd96e68-11a9-4f</name> + <user class="org.olat.user.UserImpl"> + <key>4915200</key> + <version>1</version> + <creationDate class="sql-timestamp">2018-05-04 09:58:42</creationDate> + <identity class="org.olat.basesecurity.IdentityImpl" reference="../.."/> + <webdav>false</webdav> + <firstName>Selena-Auth-1ecd96e68-11a9-4f45-9a20-4e0e7d019bfa</firstName> + <lastName>Smith</lastName> + <email>selena-1ecd96e68-11a9-4f@frentix.com</email> + <gender>female</gender> + <birthDay>20091212</birthDay> + <telPrivate>39847592</telPrivate> + <telMobile>39847592</telMobile> + <telOffice>39847592</telOffice> + <preferences> + <language>de</language> + <fontsize>100</fontsize> + <notificationInterval>daily</notificationInterval> + <informSessionTimeout>false</informSessionTimeout> + <presenceMessagesPublic>false</presenceMessagesPublic> + </preferences> + <identEnvAttribs> + <entry> + <string>authprovider</string> + <string>OLAT</string> + </entry> + <entry> + <string>isrest</string> + <string>false</string> + </entry> + <entry> + <string>iswebdav</string> + <string>false</string> + </entry> + <entry> + <string>language</string> + <string>de</string> + </entry> + </identEnvAttribs> + </user> + <status>2</status> + </identity> + </org.olat.basesecurity.model.GroupMembershipImpl> + <org.olat.basesecurity.model.GroupMembershipImpl reference="../org.olat.basesecurity.model.GroupMembershipImpl"/> + </entry> + </storedSnapshot> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + <set> + <org.olat.basesecurity.model.GroupMembershipImpl reference="../../storedSnapshot/entry/org.olat.basesecurity.model.GroupMembershipImpl"/> + </set> + </members> + </group> + <entry reference="../../../../.."/> + </org.olat.repository.model.RepositoryEntryToGroupRelation> + <org.olat.repository.model.RepositoryEntryToGroupRelation reference="../org.olat.repository.model.RepositoryEntryToGroupRelation"/> + </entry> + <entry> + <org.olat.repository.model.RepositoryEntryToGroupRelation> + <key>5275649</key> + <creationDate>2018-05-04 09:58:45.152 UTC</creationDate> + <defaultGroup>false</defaultGroup> + <group class="org.olat.basesecurity.model.GroupImpl"> + <key>65536</key> + <creationDate class="sql-timestamp">2018-05-04 08:50:29</creationDate> + <members class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>false</initialized> + <owner class="org.olat.basesecurity.model.GroupImpl" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.basesecurity.model.GroupImpl.members</role> + <key class="long">65536</key> + <dirty>false</dirty> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + </members> + </group> + <entry reference="../../../../.."/> + </org.olat.repository.model.RepositoryEntryToGroupRelation> + <org.olat.repository.model.RepositoryEntryToGroupRelation reference="../org.olat.repository.model.RepositoryEntryToGroupRelation"/> + </entry> + </storedSnapshot> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + <set> + <org.olat.repository.model.RepositoryEntryToGroupRelation reference="../../storedSnapshot/entry/org.olat.repository.model.RepositoryEntryToGroupRelation"/> + <org.olat.repository.model.RepositoryEntryToGroupRelation reference="../../storedSnapshot/entry[2]/org.olat.repository.model.RepositoryEntryToGroupRelation"/> + </set> + </groups> + <organisations class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>true</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.organisations</role> + <key class="long">5242880</key> + <dirty>false</dirty> + <storedSnapshot class="map"> + <entry> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl reference="../../../../.."/> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl reference="../../../../.."/> + </entry> + </storedSnapshot> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + <set> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl reference="../../../.."/> + </set> + </organisations> + <resourcename>-</resourcename> + <displayname>SCORM courseSCORM - 7eceeb94-ad58-4a55-a913-3a883c55038e</displayname> + <description></description> + <initialAuthor>selena-1ecd96e68-11a9-4f</initialAuthor> + <statistics> + <key>5177344</key> + <creationDate reference="../../creationDate"/> + <lastModified reference="../../creationDate"/> + <numOfRatings>0</numOfRatings> + <numOfComments>0</numOfComments> + <launchCounter>0</launchCounter> + <downloadCounter>0</downloadCounter> + <lastUsage reference="../../creationDate"/> + </statistics> + <access>1</access> + <canCopy>false</canCopy> + <canReference>false</canReference> + <canLaunch>true</canLaunch> + <canDownload>false</canDownload> + <membersOnly>false</membersOnly> + <statusCode>0</statusCode> + <allowToLeave>atAnyTime</allowToLeave> + </entry> + <organisation class="org.olat.basesecurity.model.OrganisationImpl"> + <key>1</key> + <creationDate class="sql-timestamp">2018-05-04 08:50:29</creationDate> + <lastModified class="sql-timestamp">2018-05-04 08:50:29</lastModified> + <identifier>default-org</identifier> + <displayName>OpenOLAT</displayName> + <materializedPathKeys>/1/</materializedPathKeys> + <managedFlagsString>identifier,externalId,move,delete</managedFlagsString> + <group class="org.olat.basesecurity.model.GroupImpl" reference="../../entry/groups/storedSnapshot/entry[2]/org.olat.repository.model.RepositoryEntryToGroupRelation/group"/> + </organisation> + </org.olat.repository.model.RepositoryEntryToOrganisationImpl> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl reference="../org.olat.repository.model.RepositoryEntryToOrganisationImpl"/> + </entry> + </storedSnapshot> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + <set> + <org.olat.repository.model.RepositoryEntryToOrganisationImpl reference="../../storedSnapshot/entry/org.olat.repository.model.RepositoryEntryToOrganisationImpl"/> + </set> + </organisations> + <resourcename>-</resourcename> + <displayname>SCORM courseSCORM - 7eceeb94-ad58-4a55-a913-3a883c55038e</displayname> + <description></description> + <initialAuthor>selena-1ecd96e68-11a9-4f</initialAuthor> + <statistics reference="../organisations/storedSnapshot/entry/org.olat.repository.model.RepositoryEntryToOrganisationImpl/entry/statistics"/> + <access>1</access> + <canCopy>false</canCopy> + <canReference>false</canReference> + <canLaunch>true</canLaunch> + <canDownload>false</canDownload> + <membersOnly>false</membersOnly> + <statusCode>0</statusCode> + <allowToLeave>atAnyTime</allowToLeave> + </olatResourceable> + </org.olat.core.id.context.MyContextEntry> + <org.olat.core.id.context.MyContextEntry> + <olatResourceable class="org.olat.core.util.resource.Resourceable"> + <resourceableTypeName>CourseNode</resourceableTypeName> + <resourceableId>91389880396330</resourceableId> + </olatResourceable> + </org.olat.core.id.context.MyContextEntry> + </entries> +</org.olat.core.id.context.HistoryPointImpl> \ No newline at end of file diff --git a/src/test/java/org/olat/core/id/context/resume_ver13b.xml b/src/test/java/org/olat/core/id/context/resume_ver13b.xml new file mode 100644 index 00000000000..fd30bec8c68 --- /dev/null +++ b/src/test/java/org/olat/core/id/context/resume_ver13b.xml @@ -0,0 +1,64 @@ +<org.olat.core.id.context.HistoryPointImpl> + <uuid>4</uuid> + <businessPath>[RepositoryEntry:1319927808]</businessPath> + <entries> + <org.olat.core.id.context.MyContextEntry> + <olatResourceable class="org.olat.repository.RepositoryEntry"> + <key>1319927808</key> + <version>1</version> + <creationDate class="sql-timestamp">2018-04-27 12:57:49.727</creationDate> + <lastModified class="sql-timestamp">2018-04-27 12:57:49.727</lastModified> + <softkey>sropenpg_1_97589364187858</softkey> + <olatResource class="org.olat.resource.OLATResourceImpl"> + <key>1319796736</key> + <version>0</version> + <creationDate class="sql-timestamp">2018-04-27 12:57:49.728</creationDate> + <resName>CourseModule</resName> + <resId>97589364187857</resId> + </olatResource> + <groups class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>false</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.groups</role> + <key class="long">1319927808</key> + <dirty>false</dirty> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + </groups> + <organisations class="org.hibernate.collection.internal.PersistentSet"> + <isTempSession>false</isTempSession> + <initialized>false</initialized> + <owner class="org.olat.repository.RepositoryEntry" reference="../.."/> + <cachedSize>-1</cachedSize> + <role>org.olat.repository.RepositoryEntry.organisations</role> + <key class="long">1319927808</key> + <dirty>false</dirty> + <allowLoadOutsideTransaction>false</allowLoadOutsideTransaction> + </organisations> + <resourcename>-</resourcename> + <displayname>Artificial life course</displayname> + <description></description> + <initialAuthor>kanu</initialAuthor> + <statistics> + <key>1319829504</key> + <creationDate class="sql-timestamp">2018-04-27 12:57:49.727</creationDate> + <lastModified class="sql-timestamp">2018-04-27 12:57:49.727</lastModified> + <numOfRatings>0</numOfRatings> + <numOfComments>0</numOfComments> + <launchCounter>6</launchCounter> + <downloadCounter>0</downloadCounter> + <lastUsage class="sql-timestamp">2018-05-04 09:51:13.265</lastUsage> + </statistics> + <access>1</access> + <canCopy>false</canCopy> + <canReference>false</canReference> + <canLaunch>true</canLaunch> + <canDownload>false</canDownload> + <membersOnly>false</membersOnly> + <statusCode>0</statusCode> + <allowToLeave>atAnyTime</allowToLeave> + </olatResourceable> + </org.olat.core.id.context.MyContextEntry> + </entries> +</org.olat.core.id.context.HistoryPointImpl> \ No newline at end of file diff --git a/src/test/java/org/olat/course/nodes/gta/rule/GTAReminderRuleTest.java b/src/test/java/org/olat/course/nodes/gta/rule/GTAReminderRuleTest.java index 6ec20e0c5ec..00acf8a90ca 100644 --- a/src/test/java/org/olat/course/nodes/gta/rule/GTAReminderRuleTest.java +++ b/src/test/java/org/olat/course/nodes/gta/rule/GTAReminderRuleTest.java @@ -30,6 +30,8 @@ import java.util.UUID; import org.junit.Assert; import org.junit.Test; +import org.olat.basesecurity.Group; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.model.GroupMembershipImpl; import org.olat.core.commons.persistence.DB; @@ -58,7 +60,6 @@ import org.olat.repository.RepositoryEntry; import org.olat.repository.manager.RepositoryEntryLifecycleDAO; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.model.RepositoryEntryLifecycle; -import org.olat.repository.model.RepositoryEntryToGroupRelation; import org.olat.resource.OLATResource; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; @@ -193,11 +194,11 @@ public class GTAReminderRuleTest extends OlatTestCase { @Test public void assignTask_businessGroup() { //prepare - Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2"); - Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3"); - Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4"); - Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-5"); - Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6"); + Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3"); + Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4"); + Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-5"); + Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-6"); + Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-7"); BusinessGroup businessGroup1 = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false); BusinessGroup businessGroup2 = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false); @@ -238,8 +239,8 @@ public class GTAReminderRuleTest extends OlatTestCase { @Test public void assignTask_relativeToDateEnrollment() { //prepare a course with a volatile task - Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1"); - Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2"); + Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-8"); + Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-9"); RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false); addEnrollmentDate(re, participant1, GroupRoles.participant, -12, Calendar.DATE); addEnrollmentDate(re, participant2, GroupRoles.participant, -5, Calendar.DATE); @@ -294,9 +295,8 @@ public class GTAReminderRuleTest extends OlatTestCase { } private void addEnrollmentDate(RepositoryEntry entry, Identity id, GroupRoles role, int amount, int field) { - RepositoryEntryToGroupRelation rel = entry.getGroups().iterator().next(); - rel.getGroup(); - + Group group = repositoryEntryRelationDao.getDefaultGroup(entry); + Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(field, amount); @@ -304,9 +304,10 @@ public class GTAReminderRuleTest extends OlatTestCase { GroupMembershipImpl membership = new GroupMembershipImpl(); membership.setCreationDate(cal.getTime()); membership.setLastModified(cal.getTime()); - membership.setGroup(rel.getGroup()); + membership.setGroup(group); membership.setIdentity(id); membership.setRole(role.name()); + membership.setInheritanceMode(GroupMembershipInheritance.none); dbInstance.getCurrentEntityManager().persist(membership); dbInstance.commit(); } @@ -411,8 +412,8 @@ public class GTAReminderRuleTest extends OlatTestCase { @Test public void submitTask_individual() { //prepare a course with a volatile task - Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1"); - Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2"); + Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-10"); + Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-11"); RepositoryEntry re = deployGTACourse(); repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name()); repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name()); @@ -497,8 +498,8 @@ public class GTAReminderRuleTest extends OlatTestCase { @Test public void submitTask_relativeLifecycle() { //prepare a course with a volatile task - Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-1"); - Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-2"); + Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-12"); + Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-13"); RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false); repositoryEntryRelationDao.addRole(participant1, re, GroupRoles.participant.name()); repositoryEntryRelationDao.addRole(participant2, re, GroupRoles.participant.name()); diff --git a/src/test/java/org/olat/modules/reminder/manager/ReminderRuleEngineTest.java b/src/test/java/org/olat/modules/reminder/manager/ReminderRuleEngineTest.java index 937294f2a49..376f04dc8e1 100644 --- a/src/test/java/org/olat/modules/reminder/manager/ReminderRuleEngineTest.java +++ b/src/test/java/org/olat/modules/reminder/manager/ReminderRuleEngineTest.java @@ -29,6 +29,8 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; +import org.olat.basesecurity.Group; +import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.model.GroupMembershipImpl; import org.olat.core.commons.persistence.DB; @@ -70,7 +72,6 @@ import org.olat.repository.RepositoryManager; import org.olat.repository.manager.RepositoryEntryLifecycleDAO; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.model.RepositoryEntryLifecycle; -import org.olat.repository.model.RepositoryEntryToGroupRelation; import org.olat.resource.OLATResource; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; @@ -635,8 +636,7 @@ public class ReminderRuleEngineTest extends OlatTestCase { } private void addEnrollmentDate(RepositoryEntry entry, Identity id, GroupRoles role, int amount, int field) { - RepositoryEntryToGroupRelation rel = entry.getGroups().iterator().next(); - rel.getGroup(); + Group group = repositoryEntryRelationDao.getDefaultGroup(entry); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); @@ -645,9 +645,10 @@ public class ReminderRuleEngineTest extends OlatTestCase { GroupMembershipImpl membership = new GroupMembershipImpl(); membership.setCreationDate(cal.getTime()); membership.setLastModified(cal.getTime()); - membership.setGroup(rel.getGroup()); + membership.setGroup(group); membership.setIdentity(id); membership.setRole(role.name()); + membership.setInheritanceMode(GroupMembershipInheritance.none); dbInstance.getCurrentEntityManager().persist(membership); dbInstance.commit(); } diff --git a/src/test/java/org/olat/portfolio/manager/EPStructureManagerTest.java b/src/test/java/org/olat/portfolio/manager/EPStructureManagerTest.java index 28343c8b103..4ca4e4a2ad6 100644 --- a/src/test/java/org/olat/portfolio/manager/EPStructureManagerTest.java +++ b/src/test/java/org/olat/portfolio/manager/EPStructureManagerTest.java @@ -697,7 +697,7 @@ public class EPStructureManagerTest extends OlatTestCase { assertFalse(singleAuthor.contains(ident2));//owner securityGroupDao.getSecurityGroupsForIdentity(ident1); - repositoryManager.queryReferencableResourcesLimitType(ident1, new Roles(false, false, false, false, false, false, false), null, null, null, null); + repositoryManager.queryResourcesLimitType(ident1, new Roles(false, false, false, false, false, false, false), null, null, null, null, true, false); } diff --git a/src/test/java/org/olat/repository/RepositoryManagerQueryTest.java b/src/test/java/org/olat/repository/RepositoryManagerQueryTest.java deleted file mode 100644 index 82f122f9c07..00000000000 --- a/src/test/java/org/olat/repository/RepositoryManagerQueryTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/** - * <a href="http://www.openolat.org"> - * OpenOLAT - Online Learning and Training</a><br> - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); <br> - * you may not use this file except in compliance with the License.<br> - * You may obtain a copy of the License at the - * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> - * <p> - * Unless required by applicable law or agreed to in writing,<br> - * software distributed under the License is distributed on an "AS IS" BASIS, <br> - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> - * See the License for the specific language governing permissions and <br> - * limitations under the License. - * <p> - * Initial code contributed and copyrighted by<br> - * frentix GmbH, http://www.frentix.com - * <p> - */ -package org.olat.repository; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import java.util.Collections; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.OrganisationRoles; -import org.olat.basesecurity.OrganisationService; -import org.olat.core.commons.persistence.DB; -import org.olat.core.id.Identity; -import org.olat.core.id.Organisation; -import org.olat.core.id.Roles; -import org.olat.core.id.UserConstants; -import org.olat.repository.model.SearchRepositoryEntryParameters; -import org.olat.resource.OLATResource; -import org.olat.resource.OLATResourceManager; -import org.olat.test.JunitTestHelper; -import org.olat.test.OlatTestCase; -import org.olat.user.UserManager; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * - * Description:<br> - * - * <P> - * Initial Date: 18 oct. 2011 <br> - * - * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com - */ -public class RepositoryManagerQueryTest extends OlatTestCase { - - private static final String TEST_RES_NAME = "TestManagerQuery"; - - @Autowired - private DB dbInstance; - @Autowired - private RepositoryManager rm; - @Autowired - private UserManager userManager; - @Autowired - private BaseSecurity securityManager; - @Autowired - private RepositoryService repositoryService; - @Autowired - private OLATResourceManager resourceManager; - @Autowired - private OrganisationService organisationService; - - private static Identity admin; - private static Identity learnResourceManager1; - private static Identity learnResourceManager2; - - private static final String author = "RepositoryManagerQueryAuthor"; - private static boolean initialized = false; - - public void testManagers() { - assertNotNull(rm); - } - - @Before - public void setup() { - if(initialized) return; - - Organisation defOrganisation = organisationService.getDefaultOrganisation(); - Organisation organisation = organisationService.createOrganisation("Test repo query", "test-repo-query", null, defOrganisation, null); - dbInstance.commit(); - - admin = JunitTestHelper.createAndPersistIdentityAsAdmin("administrator"); - - Identity id1 = JunitTestHelper.createAndPersistIdentityAsAuthor(author + "1"); - id1.getUser().setProperty(UserConstants.FIRSTNAME, author + "1"); - id1.getUser().setProperty(UserConstants.LASTNAME, author + "1"); - userManager.updateUserFromIdentity(id1); - - Identity id2 = JunitTestHelper.createAndPersistIdentityAsAuthor(author + "2"); - id2.getUser().setProperty(UserConstants.FIRSTNAME, author + "2"); - id2.getUser().setProperty(UserConstants.LASTNAME, author + "2"); - userManager.updateUserFromIdentity(id2); - - learnResourceManager1 = JunitTestHelper.createAndPersistIdentityAsAuthor("kanu"); - learnResourceManager1.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "Volks"); - learnResourceManager1.getUser().setProperty(UserConstants.FIRSTNAME, "Kanu"); - learnResourceManager1.getUser().setProperty(UserConstants.LASTNAME, "Unchou"); - userManager.updateUserFromIdentity(learnResourceManager1); - - learnResourceManager2 = JunitTestHelper.createAndPersistIdentityAsAuthor("rei"); - learnResourceManager2.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "Nerv"); - learnResourceManager2.getUser().setProperty(UserConstants.FIRSTNAME, "Rei"); - learnResourceManager2.getUser().setProperty(UserConstants.LASTNAME, "Ayanami"); - userManager.updateUserFromIdentity(learnResourceManager2); - - dbInstance.commit(); - - organisationService.addMember(organisation, learnResourceManager1, OrganisationRoles.learnresourcemanager); - organisationService.addMember(organisation, learnResourceManager2, OrganisationRoles.learnresourcemanager); - organisationService.addMember(organisation, id1, OrganisationRoles.user); - organisationService.addMember(organisation, id2, OrganisationRoles.user); - dbInstance.commitAndCloseSession(); - - // generate some repo entries - int numbRes = 500; - for (int i = 0; i < numbRes; i++) { - - - int rest = i%4; - int access = 0; - Identity owner = null; - switch(rest) { - case 0: { - access = RepositoryEntry.ACC_USERS_GUESTS; - owner = id1; - break; - } - case 1: { - access = RepositoryEntry.ACC_USERS; - owner = id2; - break; - } - case 2: { - access = RepositoryEntry.ACC_OWNERS; - owner = learnResourceManager1; - break; - } - case 3: { - access = RepositoryEntry.ACC_OWNERS; - owner = learnResourceManager2; - break; - } - } - - // create course and persist as OLATResourceImpl - RepositoryEntry re = createCourseRepositoryEntry(owner, i, organisation); - re.setAccess(access); - - repositoryService.update(re); - if (i % 20 == 0) { - dbInstance.commitAndCloseSession(); - } - } - - dbInstance.commitAndCloseSession(); - - initialized = true; - } - - @Test - public void testOneShootQueryWithRoles() { - List<String> types = Collections.singletonList(TEST_RES_NAME); - - //roles: author + institution manager - Roles adminRoles = securityManager.getRoles(admin); - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, null, null, types, admin, adminRoles, "Volks"); - List<RepositoryEntry> resultOneShootInstitut = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true); - assertNotNull(resultOneShootInstitut); - assertFalse(resultOneShootInstitut.isEmpty()); - } - - @Test - public void testOneShootQueryWithAuthorRole() { - List<String> types = Collections.singletonList(TEST_RES_NAME); - - //roles: author + institution manager - Roles role2 = new Roles(false, false, false, true, false, false, false); - - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, null, null, types, null, role2, null); - List<RepositoryEntry> resultOneShoot = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true); - assertNotNull(resultOneShoot); - assertFalse(resultOneShoot.isEmpty()); - } - - @Test - public void testOneShootWithInstitution() { - List<String> types = Collections.singletonList(TEST_RES_NAME); - - //roles: institution manager - Roles learnResourceManager1Roles = securityManager.getRoles(learnResourceManager1); - - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, null, null, types, - learnResourceManager1, learnResourceManager1Roles, "Volks"); - List<RepositoryEntry> resultOneShootInstitut3 = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true); - assertNotNull(resultOneShootInstitut3); - assertFalse(resultOneShootInstitut3.isEmpty()); - } - - @Test - public void testOneShootWithInstitutionAndSearchByAuthorName() { - List<String> types = Collections.singletonList(TEST_RES_NAME); - - //roles: institution manager search: authorname - Roles learnResourceManager2Roles = securityManager.getRoles(learnResourceManager2); - - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, "kan", null, types, - learnResourceManager2, learnResourceManager2Roles, "Volks"); - List<RepositoryEntry> resultOneShootInstitut4 = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true); - assertNotNull(resultOneShootInstitut4); - assertFalse(resultOneShootInstitut4.isEmpty()); - } - - @Test - public void testOneShootQueryPaging() { - List<String> types = Collections.singletonList(TEST_RES_NAME); - - //roles: institution manager search: authorname - Roles learnResourceManager1Role = securityManager.getRoles(learnResourceManager1); - - //test paging - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, "kan", null, types, - learnResourceManager1, learnResourceManager1Role, "Volks"); - List<RepositoryEntry> resultOneShootInstitut6 = rm.genericANDQueryWithRolesRestriction(params, 0, 50, true); - rm.countGenericANDQueryWithRolesRestriction(params); - assertNotNull(resultOneShootInstitut6); - assertEquals(50, resultOneShootInstitut6.size()); - } - - private RepositoryEntry createCourseRepositoryEntry(Identity owner, final int i, Organisation organisation) { - OLATResource r = resourceManager.createOLATResourceInstance(TEST_RES_NAME); - resourceManager.saveOLATResource(r); - // now make a repository entry for this course - RepositoryEntry re = repositoryService.create(owner, null, - "Lernen mit OLAT " + i, "JunitTest_RepositoryEntry_" + i, "Description of learning by OLAT " + i, r, RepositoryEntry.ACC_OWNERS, organisation); - return re; - } -} \ No newline at end of file diff --git a/src/test/java/org/olat/repository/RepositoryManagerTest.java b/src/test/java/org/olat/repository/RepositoryManagerTest.java index 703a037d31b..c12c5b023a3 100644 --- a/src/test/java/org/olat/repository/RepositoryManagerTest.java +++ b/src/test/java/org/olat/repository/RepositoryManagerTest.java @@ -27,7 +27,6 @@ package org.olat.repository; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; @@ -64,7 +63,6 @@ import org.olat.repository.manager.RepositoryEntryLifecycleDAO; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.model.RepositoryEntryLifecycle; import org.olat.repository.model.RepositoryEntryMembership; -import org.olat.repository.model.SearchRepositoryEntryParameters; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceManager; import org.olat.test.JunitTestHelper; @@ -652,81 +650,6 @@ public class RepositoryManagerTest extends OlatTestCase { Assert.assertEquals(0, countEntries); } - @Test - public void queryByTypeLimitAccess() { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-1-" + UUID.randomUUID().toString()); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); - BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-1", "tg", null, null, false, false, re); - businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); - dbInstance.commitAndCloseSession(); - - //check - List<String> types = Collections.singletonList(re.getOlatResource().getResourceableTypeName()); - List<RepositoryEntry> entries = repositoryManager.queryByTypeLimitAccess(id, - types, new Roles(false, false, false, false, false, false, false)); - - Assert.assertNotNull(entries); - Assert.assertFalse(entries.isEmpty()); - Assert.assertTrue(entries.contains(re)); - for(RepositoryEntry entry:entries) { - if(!entry.equals(re)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - } - - @Test - public void queryByTypeLimitAccess_withoutInstitution() { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-2-" + UUID.randomUUID().toString()); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); - BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-2", "tg", null, null, false, false, re); - businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); - dbInstance.commitAndCloseSession(); - - //check - List<String> types = Collections.singletonList(re.getOlatResource().getResourceableTypeName()); - List<RepositoryEntry> entries = repositoryManager.queryByTypeLimitAccess(id, - new Roles(false, false, false, false, false, false, false), types); - - Assert.assertNotNull(entries); - Assert.assertFalse(entries.isEmpty()); - Assert.assertTrue(entries.contains(re)); - for(RepositoryEntry entry:entries) { - if(!entry.equals(re)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - } - - @Test - public void queryByTypeLimitAccess_withInstitution() { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-3-" + UUID.randomUUID().toString()); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); - BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-3", "tg", null, null, false, false, re); - businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); - dbInstance.commitAndCloseSession(); - - //promote id to institution resource manager - id.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "openolat.org"); - userManager.updateUserFromIdentity(id); - organisationService.addMember(id, OrganisationRoles.learnresourcemanager); - dbInstance.commitAndCloseSession(); - - //check - List<String> types = Collections.singletonList(re.getOlatResource().getResourceableTypeName()); - List<RepositoryEntry> entries = repositoryManager.queryByTypeLimitAccess(id, - new Roles(false, false, false, false, false, true, false), types); - - Assert.assertNotNull(entries); - Assert.assertFalse(entries.isEmpty()); - Assert.assertTrue(entries.contains(re)); - for(RepositoryEntry entry:entries) { - if(!entry.equals(re)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - } - @Test public void queryResourcesLimitType() { Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString()); @@ -735,15 +658,16 @@ public class RepositoryManagerTest extends OlatTestCase { List<String> resourceTypes = Collections.singletonList(re.getOlatResource().getResourceableTypeName()); List<RepositoryEntry> entries = repositoryManager - .queryResourcesLimitType(id, resourceTypes, "re-member", "me", "no", true, true); + .queryResourcesLimitType(id, Roles.authorRoles(), resourceTypes, "re-member", "me", "no", true, true); Assert.assertNotNull(entries); } @Test public void queryReferencableResourcesLimitType() { - final String FG_TYPE = UUID.randomUUID().toString().replace("_", ""); + String resourceType = UUID.randomUUID().toString().replace("_", ""); Identity id1 = JunitTestHelper.createAndPersistIdentityAsAuthor("id1"); Identity id2 = JunitTestHelper.createAndPersistIdentityAsAuthor("id2"); + Roles id1Roles = securityManager.getRoles(id1); // generate 5000 repo entries int numbRes = 500; @@ -752,7 +676,7 @@ public class RepositoryManagerTest extends OlatTestCase { // create course and persist as OLATResourceImpl Identity owner = (i % 2 > 0) ? id1 : id2; - OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(FG_TYPE, new Long(i)); + OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(resourceType, new Long(i)); OLATResource r = OLATResourceManager.getInstance().createOLATResourceInstance(resourceable); dbInstance.getCurrentEntityManager().persist(r); @@ -778,18 +702,18 @@ public class RepositoryManagerTest extends OlatTestCase { long endCreate = System.currentTimeMillis(); log.info("created " + numbRes + " repo entries in " + (endCreate - startCreate) + "ms"); - List<String> typelist = Collections.singletonList(FG_TYPE); + List<String> typelist = Collections.singletonList(resourceType); // finally the search query long startSearchReferencable = System.currentTimeMillis(); - List<RepositoryEntry> results = repositoryManager.queryReferencableResourcesLimitType(id1, new Roles(false, false, false, true, false, false, false), typelist, null, null, null); + List<RepositoryEntry> results = repositoryManager.queryResourcesLimitType(id1, id1Roles, typelist, null, null, null, true, false); long endSearchReferencable = System.currentTimeMillis(); log.info("found " + results.size() + " repo entries " + (endSearchReferencable - startSearchReferencable) + "ms"); // only half of the items should be found - assertEquals(numbRes / 2, results.size()); + Assert.assertEquals(numbRes / 2, results.size()); // inserting must take longer than searching, otherwhise most certainly we have a problem somewhere in the query - assertTrue((endCreate - startCreate) > (endSearchReferencable - startSearchReferencable)); + Assert.assertTrue((endCreate - startCreate) > (endSearchReferencable - startSearchReferencable)); } @Test @@ -1001,177 +925,6 @@ public class RepositoryManagerTest extends OlatTestCase { assertEquals("Add one course repository-entry, but countByTypeLimitAccess does NOT return one more element", countValueBefore + 1,count); } - @Test - public void genericANDQueryWithRolesRestrictionMembersOnly() { - //create 2 identities (repo owner and tutor) - Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-1-" + UUID.randomUUID().toString()); - Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-2-" + UUID.randomUUID().toString()); - Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-3-" + UUID.randomUUID().toString()); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); - repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name()); - BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re); - businessGroupRelationDao.addRole(id2, group, GroupRoles.coach.name()); - dbInstance.commitAndCloseSession(); - - - //check for id 1 (owner of the repository entry) - SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters(); - params1.setIdentity(id1); - params1.setRoles(new Roles(false, false, false, false, false, false, false)); - params1.setOnlyExplicitMember(true); - List<RepositoryEntry> entries1 = repositoryManager.genericANDQueryWithRolesRestriction(params1, 0, -1, true); - Assert.assertNotNull(entries1); - Assert.assertFalse(entries1.isEmpty()); - Assert.assertTrue(entries1.contains(re)); - for(RepositoryEntry entry:entries1) { - if(!entry.equals(re)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - - //check for id2 (tutor) - SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters(); - params2.setIdentity(id2); - params2.setRoles(new Roles(false, false, false, false, false, false, false)); - params2.setOnlyExplicitMember(true); - List<RepositoryEntry> entries2 = repositoryManager.genericANDQueryWithRolesRestriction(params2, 0, -1, true); - Assert.assertNotNull(entries2); - Assert.assertFalse(entries2.isEmpty()); - Assert.assertTrue(entries2.contains(re)); - for(RepositoryEntry entry:entries2) { - if(!entry.equals(re)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - - //check for id3 (negative test) - SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters(); - params3.setIdentity(id3); - params3.setRoles(new Roles(false, false, false, false, false, false, false)); - params3.setOnlyExplicitMember(true); - List<RepositoryEntry> entries3 = repositoryManager.genericANDQueryWithRolesRestriction(params3, 0, -1, true); - Assert.assertNotNull(entries3); - Assert.assertFalse(entries3.contains(re)); - for(RepositoryEntry entry:entries3) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - - @Test - public void genericANDQueryWithRolesWithStandardUser() { - //create 2 identities (repo owner and tutor) - Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-1-" + UUID.randomUUID().toString()); - Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-2-" + UUID.randomUUID().toString()); - RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry(); - RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry(true); - repositoryEntryRelationDao.addRole(id1, re2, GroupRoles.participant.name()); - BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re1); - businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name()); - dbInstance.commitAndCloseSession(); - - - //check for guest (negative test) - SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters(); - params1.setRoles(new Roles(false, false, false, false, true, false, false)); - List<RepositoryEntry> entries1 = repositoryManager.genericANDQueryWithRolesRestriction(params1, 0, -1, true); - Assert.assertNotNull(entries1); - Assert.assertFalse(entries1.contains(re1)); - Assert.assertFalse(entries1.contains(re2)); - for(RepositoryEntry entry:entries1) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS_GUESTS); - } - - //check for identity 1 (participant re2 + re1 accessible to all users) - SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters(); - params2.setIdentity(id1); - params2.setRoles(new Roles(false, false, false, false, false, false, false)); - List<RepositoryEntry> entries2 = repositoryManager.genericANDQueryWithRolesRestriction(params2, 0, -1, true); - Assert.assertNotNull(entries2); - Assert.assertFalse(entries2.isEmpty()); - Assert.assertTrue(entries2.contains(re1)); - Assert.assertTrue(entries2.contains(re2)); - for(RepositoryEntry entry:entries2) { - if(!entry.equals(re2)) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - - //check for identity 1 (re1 accessible to all users) - SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters(); - params3.setIdentity(id2); - params3.setRoles(new Roles(false, false, false, false, false, false, false)); - List<RepositoryEntry> entries3 = repositoryManager.genericANDQueryWithRolesRestriction(params3, 0, -1, true); - Assert.assertNotNull(entries3); - Assert.assertFalse(entries3.isEmpty()); - Assert.assertTrue(entries3.contains(re1)); - Assert.assertFalse(entries3.contains(re2)); - for(RepositoryEntry entry:entries3) { - Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); - } - } - - @Test - public void genericANDQueryWithRoles_managed() { - RepositoryEntry managedRe = JunitTestHelper.createAndPersistRepositoryEntry(); - managedRe.setManagedFlagsString("all"); - managedRe = dbInstance.getCurrentEntityManager().merge(managedRe); - RepositoryEntry freeRe = JunitTestHelper.createAndPersistRepositoryEntry(); - dbInstance.commitAndCloseSession(); - - //search managed - SearchRepositoryEntryParameters paramsManaged = new SearchRepositoryEntryParameters(); - paramsManaged.setRoles(new Roles(true, false, false, false, false, false, false)); - paramsManaged.setManaged(Boolean.TRUE); - List<RepositoryEntry> managedEntries = repositoryManager.genericANDQueryWithRolesRestriction(paramsManaged, 0, -1, true); - Assert.assertNotNull(managedEntries); - Assert.assertTrue(managedEntries.size() > 0); - Assert.assertTrue(managedEntries.contains(managedRe)); - Assert.assertFalse(managedEntries.contains(freeRe)); - - //search unmanaged - SearchRepositoryEntryParameters paramsFree = new SearchRepositoryEntryParameters(); - paramsFree.setRoles(new Roles(true, false, false, false, false, false, false)); - paramsFree.setManaged(Boolean.FALSE); - List<RepositoryEntry> freeEntries = repositoryManager.genericANDQueryWithRolesRestriction(paramsFree, 0, -1, true); - Assert.assertNotNull(freeEntries); - Assert.assertTrue(freeEntries.size() > 0); - Assert.assertFalse(freeEntries.contains(managedRe)); - Assert.assertTrue(freeEntries.contains(freeRe)); - } - - @Test - public void genericANDQueryWithRoles_owned() { - Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("owned-re-"); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(); - repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name()); - dbInstance.commitAndCloseSession(); - - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(); - params.setRoles(new Roles(false, false, false, true, false, false, false)); - params.setOnlyOwnedResources(true); - params.setIdentity(owner); - List<RepositoryEntry> myEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true); - Assert.assertNotNull(myEntries); - Assert.assertEquals(1, myEntries.size()); - Assert.assertTrue(myEntries.contains(re)); - } - - @Test - public void genericANDQueryWithRoles_byauthor() { - Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("author-re-"); - RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(); - repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name()); - dbInstance.commitAndCloseSession(); - - SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(); - params.setRoles(new Roles(true, false, false, false, false, false, false)); - params.setAuthor(owner.getName()); - List<RepositoryEntry> myEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true); - Assert.assertNotNull(myEntries); - Assert.assertEquals(1, myEntries.size()); - Assert.assertTrue(myEntries.contains(re)); - } - @Test public void setDescriptionAndName() { RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(); @@ -1229,6 +982,35 @@ public class RepositoryManagerTest extends OlatTestCase { Assert.assertEquals("Brand new description", reloaded.getDescription()); Assert.assertEquals(publicCycle, reloaded.getLifecycle()); } + + @Test + public void setDescriptionAndName_organisations() { + RepositoryEntryLifecycle publicCycle + = lifecycleDao.create("Public 2", "Soft public 2", false, new Date(), new Date()); + Organisation organisation = organisationService.getDefaultOrganisation(); + + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(); + dbInstance.commitAndCloseSession(); + Assert.assertNotNull(re); + + String newName = "Organized name"; + String newDesc = "Organized description"; + re = repositoryManager.setDescriptionAndName(re, newName, null, null, newDesc, null, null, null, null, null, null, + publicCycle, Collections.singletonList(organisation)); + Assert.assertNotNull(re); + Assert.assertEquals(2, re.getGroups().size());// check repository entry to group relations + + dbInstance.commitAndCloseSession(); + + // reload and check twice + RepositoryEntry reloaded = repositoryManager.lookupRepositoryEntry(re.getKey()); + Assert.assertNotNull(reloaded); + Assert.assertEquals("Organized name", reloaded.getDisplayname()); + Assert.assertEquals("Organized description", reloaded.getDescription()); + Assert.assertEquals(publicCycle, reloaded.getLifecycle()); + Assert.assertEquals(1, reloaded.getOrganisations().size());// check repository entry to organization relations + Assert.assertEquals(2, reloaded.getGroups().size());// check repository entry to group relations + } @Test public void setAllowToLeaveOption() { diff --git a/src/test/java/org/olat/repository/manager/RepositoryEntryQueriesTest.java b/src/test/java/org/olat/repository/manager/RepositoryEntryQueriesTest.java new file mode 100644 index 00000000000..feb63206b67 --- /dev/null +++ b/src/test/java/org/olat/repository/manager/RepositoryEntryQueriesTest.java @@ -0,0 +1,469 @@ +package org.olat.repository.manager; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.GroupMembershipInheritance; +import org.olat.basesecurity.GroupRoles; +import org.olat.basesecurity.OrganisationRoles; +import org.olat.basesecurity.OrganisationService; +import org.olat.core.commons.persistence.DB; +import org.olat.core.id.Identity; +import org.olat.core.id.Organisation; +import org.olat.core.id.Roles; +import org.olat.core.id.UserConstants; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupService; +import org.olat.group.manager.BusinessGroupRelationDAO; +import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryManager; +import org.olat.repository.RepositoryService; +import org.olat.repository.model.SearchRepositoryEntryParameters; +import org.olat.resource.OLATResource; +import org.olat.resource.OLATResourceManager; +import org.olat.test.JunitTestHelper; +import org.olat.test.OlatTestCase; +import org.olat.user.UserManager; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * Initial date: 3 mai 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class RepositoryEntryQueriesTest extends OlatTestCase { + + private static final String TEST_RES_NAME = "TestManagerQuery"; + + @Autowired + private DB dbInstance; + @Autowired + private RepositoryManager rm; + @Autowired + private RepositoryEntryQueries repositoryEntryQueries; + @Autowired + private UserManager userManager; + @Autowired + private BaseSecurity securityManager; + @Autowired + private RepositoryService repositoryService; + @Autowired + private OLATResourceManager resourceManager; + @Autowired + private OrganisationService organisationService; + @Autowired + private BusinessGroupService businessGroupService; + @Autowired + private BusinessGroupRelationDAO businessGroupRelationDao; + @Autowired + private RepositoryEntryRelationDAO repositoryEntryRelationDao; + + private static Identity admin; + private static Identity user1; + private static Identity learnResourceManager1; + private static Identity learnResourceManager2; + + private static final String author = "RepositoryManagerQueryAuthor"; + private static boolean initialized = false; + + public void testManagers() { + assertNotNull(rm); + } + + @Before + public void setup() { + if(initialized) return; + + Organisation defOrganisation = organisationService.getDefaultOrganisation(); + Organisation organisation = organisationService.createOrganisation("Test repo query", "test-repo-query", null, defOrganisation, null); + dbInstance.commit(); + + admin = JunitTestHelper.createAndPersistIdentityAsAdmin("queryAdministrator"); + + user1 = JunitTestHelper.createAndPersistIdentityAsAuthor(author + "1"); + user1.getUser().setProperty(UserConstants.FIRSTNAME, author + "1"); + user1.getUser().setProperty(UserConstants.LASTNAME, author + "1"); + userManager.updateUserFromIdentity(user1); + + Identity id2 = JunitTestHelper.createAndPersistIdentityAsAuthor(author + "2"); + id2.getUser().setProperty(UserConstants.FIRSTNAME, author + "2"); + id2.getUser().setProperty(UserConstants.LASTNAME, author + "2"); + userManager.updateUserFromIdentity(id2); + + learnResourceManager1 = JunitTestHelper.createAndPersistIdentityAsAuthor("kanu"); + learnResourceManager1.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "Volks"); + learnResourceManager1.getUser().setProperty(UserConstants.FIRSTNAME, "Kanu"); + learnResourceManager1.getUser().setProperty(UserConstants.LASTNAME, "Unchou"); + userManager.updateUserFromIdentity(learnResourceManager1); + + learnResourceManager2 = JunitTestHelper.createAndPersistIdentityAsAuthor("rei"); + learnResourceManager2.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "Nerv"); + learnResourceManager2.getUser().setProperty(UserConstants.FIRSTNAME, "Rei"); + learnResourceManager2.getUser().setProperty(UserConstants.LASTNAME, "Ayanami"); + userManager.updateUserFromIdentity(learnResourceManager2); + + dbInstance.commit(); + + organisationService.addMember(organisation, learnResourceManager1, OrganisationRoles.learnresourcemanager, GroupMembershipInheritance.none); + organisationService.addMember(organisation, learnResourceManager2, OrganisationRoles.learnresourcemanager, GroupMembershipInheritance.none); + organisationService.addMember(organisation, user1, OrganisationRoles.user, GroupMembershipInheritance.none); + organisationService.addMember(organisation, user1, OrganisationRoles.user, GroupMembershipInheritance.none); + dbInstance.commitAndCloseSession(); + + // generate some repo entries + int numbRes = 500; + for (int i = 0; i < numbRes; i++) { + + + int rest = i%4; + int access = 0; + Identity owner = null; + switch(rest) { + case 0: { + access = RepositoryEntry.ACC_USERS_GUESTS; + owner = user1; + break; + } + case 1: { + access = RepositoryEntry.ACC_USERS; + owner = id2; + break; + } + case 2: { + access = RepositoryEntry.ACC_OWNERS; + owner = learnResourceManager1; + break; + } + case 3: { + access = RepositoryEntry.ACC_OWNERS; + owner = learnResourceManager2; + break; + } + } + + // create course and persist as OLATResourceImpl + RepositoryEntry re = createCourseRepositoryEntry(owner, i, organisation); + re.setAccess(access); + + repositoryService.update(re); + if (i % 20 == 0) { + dbInstance.commitAndCloseSession(); + } + } + + dbInstance.commitAndCloseSession(); + + initialized = true; + } + + @Test + public void testOneShootQueryWithRoles() { + //roles: admin + Roles adminRoles = securityManager.getRoles(admin); + Assert.assertTrue(adminRoles.isOLATAdmin()); + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(admin, adminRoles, TEST_RES_NAME); + List<RepositoryEntry> resultOneShootInstitut = repositoryEntryQueries.searchEntries(params, 0, -1, true); + Assert.assertNotNull(resultOneShootInstitut); + Assert.assertFalse(resultOneShootInstitut.isEmpty()); + } + + @Test + public void testOneShootQueryWithAuthorRole() { + //roles: author + Roles authorRoles = Roles.authorRoles(); + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(user1, authorRoles, TEST_RES_NAME); + List<RepositoryEntry> resultOneShoot = repositoryEntryQueries.searchEntries(params, 0, -1, true); + Assert.assertNotNull(resultOneShoot); + Assert.assertFalse(resultOneShoot.isEmpty()); + } + + @Test + public void testOneShootWithInstitution() { + List<String> types = Collections.singletonList(TEST_RES_NAME); + + //roles: institution manager + Roles learnResourceManager1Roles = securityManager.getRoles(learnResourceManager1); + + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, null, null, types, + learnResourceManager1, learnResourceManager1Roles, "Volks"); + List<RepositoryEntry> resultOneShootInstitut3 = repositoryEntryQueries.searchEntries(params, 0, -1, true); + assertNotNull(resultOneShootInstitut3); + assertFalse(resultOneShootInstitut3.isEmpty()); + } + + @Test + public void testOneShootWithInstitutionAndSearchByAuthorName() { + List<String> types = Collections.singletonList(TEST_RES_NAME); + + //roles: institution manager search: authorname + Roles learnResourceManager2Roles = securityManager.getRoles(learnResourceManager2); + + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, "kan", null, types, + learnResourceManager2, learnResourceManager2Roles, "Volks"); + List<RepositoryEntry> resultOneShootInstitut4 = repositoryEntryQueries.searchEntries(params, 0, -1, true); + assertNotNull(resultOneShootInstitut4); + assertFalse(resultOneShootInstitut4.isEmpty()); + } + + @Test + public void testOneShootQueryPaging() { + List<String> types = Collections.singletonList(TEST_RES_NAME); + + //roles: institution manager search: authorname + Roles learnResourceManager1Role = securityManager.getRoles(learnResourceManager1); + + //test paging + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, "kan", null, types, + learnResourceManager1, learnResourceManager1Role, "Volks"); + List<RepositoryEntry> resultOneShootInstitut6 = repositoryEntryQueries.searchEntries(params, 0, 50, true); + rm.countGenericANDQueryWithRolesRestriction(params); + assertNotNull(resultOneShootInstitut6); + assertEquals(50, resultOneShootInstitut6.size()); + } + + @Test + public void search_byAuthor() { + Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("author-re-"); + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(); + repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name()); + dbInstance.commitAndCloseSession(); + + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(); + params.setRoles(new Roles(true, false, false, false, false, false, false)); + params.setAuthor(owner.getName()); + List<RepositoryEntry> myEntries = repositoryEntryQueries.searchEntries(params, 0, -1, true); + Assert.assertNotNull(myEntries); + Assert.assertEquals(1, myEntries.size()); + Assert.assertTrue(myEntries.contains(re)); + } + + @Test + public void genericANDQueryWithRoles_managed() { + RepositoryEntry managedRe = JunitTestHelper.createAndPersistRepositoryEntry(); + managedRe.setManagedFlagsString("all"); + managedRe = dbInstance.getCurrentEntityManager().merge(managedRe); + RepositoryEntry freeRe = JunitTestHelper.createAndPersistRepositoryEntry(); + dbInstance.commitAndCloseSession(); + + //search managed + SearchRepositoryEntryParameters paramsManaged = new SearchRepositoryEntryParameters(); + paramsManaged.setRoles(new Roles(true, false, false, false, false, false, false)); + paramsManaged.setManaged(Boolean.TRUE); + List<RepositoryEntry> managedEntries = repositoryEntryQueries.searchEntries(paramsManaged, 0, -1, true); + Assert.assertNotNull(managedEntries); + Assert.assertTrue(managedEntries.size() > 0); + Assert.assertTrue(managedEntries.contains(managedRe)); + Assert.assertFalse(managedEntries.contains(freeRe)); + + //search unmanaged + SearchRepositoryEntryParameters paramsFree = new SearchRepositoryEntryParameters(); + paramsFree.setRoles(new Roles(true, false, false, false, false, false, false)); + paramsFree.setManaged(Boolean.FALSE); + List<RepositoryEntry> freeEntries = repositoryEntryQueries.searchEntries(paramsFree, 0, -1, true); + Assert.assertNotNull(freeEntries); + Assert.assertTrue(freeEntries.size() > 0); + Assert.assertFalse(freeEntries.contains(managedRe)); + Assert.assertTrue(freeEntries.contains(freeRe)); + } + + @Test + public void genericANDQueryWithRolesWithStandardUser() { + //create 2 identities (repo owner and tutor) + Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-1-" + UUID.randomUUID().toString()); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-2-" + UUID.randomUUID().toString()); + RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry(); + RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry(true); + repositoryEntryRelationDao.addRole(id1, re2, GroupRoles.participant.name()); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re1); + businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name()); + dbInstance.commitAndCloseSession(); + + + //check for guest (negative test) + SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters(); + params1.setRoles(new Roles(false, false, false, false, true, false, false)); + List<RepositoryEntry> entries1 = repositoryEntryQueries.searchEntries(params1, 0, -1, true); + Assert.assertNotNull(entries1); + Assert.assertFalse(entries1.contains(re1)); + Assert.assertFalse(entries1.contains(re2)); + for(RepositoryEntry entry:entries1) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS_GUESTS); + } + + //check for identity 1 (participant re2 + re1 accessible to all users) + SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters(); + params2.setIdentity(id1); + params2.setRoles(new Roles(false, false, false, false, false, false, false)); + List<RepositoryEntry> entries2 = repositoryEntryQueries.searchEntries(params2, 0, -1, true); + Assert.assertNotNull(entries2); + Assert.assertFalse(entries2.isEmpty()); + Assert.assertTrue(entries2.contains(re1)); + Assert.assertTrue(entries2.contains(re2)); + for(RepositoryEntry entry:entries2) { + if(!entry.equals(re2)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + + //check for identity 1 (re1 accessible to all users) + SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters(); + params3.setIdentity(id2); + params3.setRoles(new Roles(false, false, false, false, false, false, false)); + List<RepositoryEntry> entries3 = repositoryEntryQueries.searchEntries(params3, 0, -1, true); + Assert.assertNotNull(entries3); + Assert.assertFalse(entries3.isEmpty()); + Assert.assertTrue(entries3.contains(re1)); + Assert.assertFalse(entries3.contains(re2)); + for(RepositoryEntry entry:entries3) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + + @Test + public void genericANDQueryWithRolesRestrictionMembersOnly() { + //create 2 identities (repo owner and tutor) + Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("re-gen-1-"); + Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("re-gen-2-"); + Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("re-gen-3-"); + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); + repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name()); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re); + businessGroupRelationDao.addRole(id2, group, GroupRoles.coach.name()); + dbInstance.commitAndCloseSession(); + + + //check for id 1 (owner of the repository entry) + SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters(); + params1.setIdentity(id1); + params1.setRoles(new Roles(false, false, false, false, false, false, false)); + params1.setOnlyExplicitMember(true); + List<RepositoryEntry> entries1 = repositoryEntryQueries.searchEntries(params1, 0, -1, true); + Assert.assertNotNull(entries1); + Assert.assertFalse(entries1.isEmpty()); + Assert.assertTrue(entries1.contains(re)); + for(RepositoryEntry entry:entries1) { + if(!entry.equals(re)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + + //check for id2 (tutor) + SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters(); + params2.setIdentity(id2); + params2.setRoles(new Roles(false, false, false, false, false, false, false)); + params2.setOnlyExplicitMember(true); + List<RepositoryEntry> entries2 = repositoryEntryQueries.searchEntries(params2, 0, -1, true); + Assert.assertNotNull(entries2); + Assert.assertFalse(entries2.isEmpty()); + Assert.assertTrue(entries2.contains(re)); + for(RepositoryEntry entry:entries2) { + if(!entry.equals(re)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + + //check for id3 (negative test) + SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters(); + params3.setIdentity(id3); + params3.setRoles(new Roles(false, false, false, false, false, false, false)); + params3.setOnlyExplicitMember(true); + List<RepositoryEntry> entries3 = repositoryEntryQueries.searchEntries(params3, 0, -1, true); + Assert.assertNotNull(entries3); + Assert.assertFalse(entries3.contains(re)); + for(RepositoryEntry entry:entries3) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + + @Test + public void queryByTypeLimitAccess() { + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-1-" + UUID.randomUUID().toString()); + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-1", "tg", null, null, false, false, re); + businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); + dbInstance.commitAndCloseSession(); + + //check + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(id, Roles.userRoles(), re.getOlatResource().getResourceableTypeName()); + List<RepositoryEntry> entries = repositoryEntryQueries.searchEntries(params, 0, -1, false); + + Assert.assertNotNull(entries); + Assert.assertFalse(entries.isEmpty()); + Assert.assertTrue(entries.contains(re)); + for(RepositoryEntry entry:entries) { + if(!entry.equals(re)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + } + + @Test + public void queryByTypeLimitAccess_withoutInstitution() { + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-2-" + UUID.randomUUID().toString()); + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-2", "tg", null, null, false, false, re); + businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); + dbInstance.commitAndCloseSession(); + + //check + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(id, Roles.userRoles(), re.getOlatResource().getResourceableTypeName()); + List<RepositoryEntry> entries = repositoryEntryQueries.searchEntries(params, 0, -1, false); + + Assert.assertNotNull(entries); + Assert.assertFalse(entries.isEmpty()); + Assert.assertTrue(entries.contains(re)); + for(RepositoryEntry entry:entries) { + if(!entry.equals(re)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + } + + @Test + public void queryByTypeLimitAccess_withInstitution() { + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-3-" + UUID.randomUUID().toString()); + RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-3", "tg", null, null, false, false, re); + businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name()); + dbInstance.commitAndCloseSession(); + + //promote id to institution resource manager + id.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "openolat.org"); + userManager.updateUserFromIdentity(id); + organisationService.addMember(id, OrganisationRoles.learnresourcemanager); + dbInstance.commitAndCloseSession(); + + //check + Roles learnResourceManagerRoles = new Roles(false, false, false, false, false, true, false); + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(id, learnResourceManagerRoles, re.getOlatResource().getResourceableTypeName()); + List<RepositoryEntry> entries = repositoryEntryQueries.searchEntries(params, 0, -1, false); + + Assert.assertNotNull(entries); + Assert.assertFalse(entries.isEmpty()); + Assert.assertTrue(entries.contains(re)); + for(RepositoryEntry entry:entries) { + if(!entry.equals(re)) { + Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS); + } + } + } + + private RepositoryEntry createCourseRepositoryEntry(Identity owner, final int i, Organisation organisation) { + OLATResource r = resourceManager.createOLATResourceInstance(TEST_RES_NAME); + resourceManager.saveOLATResource(r); + // now make a repository entry for this course + RepositoryEntry re = repositoryService.create(owner, null, + "Lernen mit OLAT " + i, "JunitTest_RepositoryEntry_" + i, "Description of learning by OLAT " + i, r, RepositoryEntry.ACC_OWNERS, organisation); + return re; + } +} diff --git a/src/test/java/org/olat/repository/manager/RepositoryEntryRelationDAOTest.java b/src/test/java/org/olat/repository/manager/RepositoryEntryRelationDAOTest.java index e3a7e8ba51a..cbd6f981e20 100644 --- a/src/test/java/org/olat/repository/manager/RepositoryEntryRelationDAOTest.java +++ b/src/test/java/org/olat/repository/manager/RepositoryEntryRelationDAOTest.java @@ -528,7 +528,7 @@ public class RepositoryEntryRelationDAOTest extends OlatTestCase { dbInstance.commitAndCloseSession(); int numOfRelations = repositoryEntryRelationDao.removeRelations(re2); - Assert.assertEquals(2, numOfRelations);//default relation + relation to group + Assert.assertEquals(3, numOfRelations);//default relation + relation to group + default organization dbInstance.commitAndCloseSession(); List<Group> groups = Collections.singletonList(group.getBaseGroup()); diff --git a/src/test/java/org/olat/repository/manager/RepositoryServiceImplTest.java b/src/test/java/org/olat/repository/manager/RepositoryServiceImplTest.java index b9e3a7636fe..0646ba586be 100644 --- a/src/test/java/org/olat/repository/manager/RepositoryServiceImplTest.java +++ b/src/test/java/org/olat/repository/manager/RepositoryServiceImplTest.java @@ -97,7 +97,7 @@ public class RepositoryServiceImplTest extends OlatTestCase { Assert.assertNotNull(re.getLastModified()); Assert.assertNotNull(re.getOlatResource()); Assert.assertNotNull(loadedEntry.getGroups()); - Assert.assertEquals(1, loadedEntry.getGroups().size()); + Assert.assertEquals(2, loadedEntry.getGroups().size());// default group + default organization group //saved? Assert.assertEquals(displayName, re.getDisplayname()); Assert.assertEquals(resourceName, re.getResourcename()); diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index 3a9ff3fb21d..01e9bdeaa2a 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -140,8 +140,8 @@ import org.junit.runners.Suite; org.olat.repository.manager.RepositoryEntryMyCourseQueriesTest.class, org.olat.repository.manager.RepositoryEntryMembershipProcessorTest.class, org.olat.repository.manager.RepositoryEntryToOrganisationDAOTest.class, + org.olat.repository.manager.RepositoryEntryQueriesTest.class, org.olat.repository.RepositoryManagerTest.class, - org.olat.repository.RepositoryManagerQueryTest.class, org.olat.instantMessaging.InstantMessageDAOTest.class, org.olat.instantMessaging.InstantMessagePreferencesDAOTest.class, org.olat.instantMessaging.RosterDAOTest.class, -- GitLab