Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
7f31bb5b
Commit
7f31bb5b
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-291: upgrade the area
parent
6b775847
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/group/area/BGAreaImpl.java
+2
-2
2 additions, 2 deletions
src/main/java/org/olat/group/area/BGAreaImpl.java
src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java
+125
-3
125 additions, 3 deletions
src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java
with
127 additions
and
5 deletions
src/main/java/org/olat/group/area/BGAreaImpl.java
+
2
−
2
View file @
7f31bb5b
...
...
@@ -55,9 +55,9 @@ public class BGAreaImpl extends PersistentObject implements BGArea {
setDescription
(
description
);
}
BGAreaImpl
(
String
name
,
String
description
,
OLATResource
OLATR
esource
)
{
BGAreaImpl
(
String
name
,
String
description
,
OLATResource
r
esource
)
{
setName
(
name
);
setResource
(
OLATR
esource
);
setResource
(
r
esource
);
setDescription
(
description
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java
+
125
−
3
View file @
7f31bb5b
...
...
@@ -20,13 +20,19 @@
package
org.olat.upgrade
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.olat.core.commons.persistence.DB
;
import
org.olat.group.BusinessGroup
;
import
org.olat.group.BusinessGroupImpl
;
import
org.olat.group.BusinessGroupService
;
import
org.olat.group.area.BGArea
;
import
org.olat.group.area.BGAreaImpl
;
import
org.olat.group.area.BGAreaManager
;
import
org.olat.group.area.BGtoAreaRelationImpl
;
import
org.olat.group.context.BGContext2Resource
;
import
org.olat.group.model.BGResourceRelation
;
import
org.olat.resource.OLATResource
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -44,12 +50,15 @@ import org.springframework.beans.factory.annotation.Autowired;
public
class
OLATUpgrade_8_2_0
extends
OLATUpgrade
{
private
static
final
String
TASK_CONTEXTS
=
"Upgrade contexts"
;
private
static
final
String
TASK_AREAS
=
"Upgrade areas"
;
private
static
final
int
REPO_ENTRIES_BATCH_SIZE
=
20
;
private
static
final
String
VERSION
=
"OLAT_8.2.0"
;
@Autowired
private
DB
dbInstance
;
@Autowired
private
BGAreaManager
areaManager
;
@Autowired
private
BusinessGroupService
businessGroupService
;
public
OLATUpgrade_8_2_0
()
{
...
...
@@ -78,7 +87,8 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade {
}
}
boolean
allOk
=
upgradeAreas
(
upgradeManager
,
uhd
);
boolean
allOk
=
upgradeGroups
(
upgradeManager
,
uhd
);
allOk
&=
upgradeAreas
(
upgradeManager
,
uhd
);
uhd
.
setInstallationComplete
(
allOk
);
upgradeManager
.
setUpgradesHistory
(
uhd
,
VERSION
);
...
...
@@ -90,7 +100,7 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade {
return
allOk
;
}
private
boolean
upgrade
Area
s
(
UpgradeManager
upgradeManager
,
UpgradeHistoryData
uhd
)
{
private
boolean
upgrade
Group
s
(
UpgradeManager
upgradeManager
,
UpgradeHistoryData
uhd
)
{
if
(!
uhd
.
getBooleanDataValue
(
TASK_CONTEXTS
))
{
int
counter
=
0
;
...
...
@@ -111,6 +121,27 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade {
return
false
;
}
private
boolean
upgradeAreas
(
UpgradeManager
upgradeManager
,
UpgradeHistoryData
uhd
)
{
if
(!
uhd
.
getBooleanDataValue
(
TASK_AREAS
))
{
int
counter
=
0
;
List
<
BGAreaImpl
>
areas
;
do
{
areas
=
findAreas
(
counter
,
REPO_ENTRIES_BATCH_SIZE
);
for
(
BGAreaImpl
area:
areas
)
{
processArea
(
area
);
}
counter
+=
areas
.
size
();
log
.
audit
(
"Processed areas: "
+
areas
.
size
());
}
while
(
areas
.
size
()
==
REPO_ENTRIES_BATCH_SIZE
);
uhd
.
setBooleanDataValue
(
TASK_AREAS
,
true
);
upgradeManager
.
setUpgradesHistory
(
uhd
,
VERSION
);
return
false
;
}
return
false
;
}
private
void
processBusinessGroup
(
BusinessGroup
group
)
{
List
<
OLATResource
>
resources
=
findOLATResourcesForBusinessGroup
(
group
);
List
<
OLATResource
>
currentList
=
businessGroupService
.
findResources
(
Collections
.
singletonList
(
group
),
0
,
-
1
);
...
...
@@ -123,7 +154,98 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade {
}
}
dbInstance
.
commitAndCloseSession
();
System
.
out
.
println
(
"Processed: "
+
group
.
getName
()
+
" add "
+
count
+
" resources"
);
log
.
audit
(
"Processed: "
+
group
.
getName
()
+
" add "
+
count
+
" resources"
);
}
private
void
processArea
(
BGAreaImpl
area
)
{
if
(
area
.
getResource
()
!=
null
)
{
//already migrated
return
;
}
Long
groupContextKey
=
area
.
getGroupContextKey
();
List
<
OLATResource
>
resources
=
findOLATResourcesForBGContext
(
groupContextKey
);
if
(
resources
.
isEmpty
())
{
//nothing to do
}
else
{
//reuse the area for the first resource
Iterator
<
OLATResource
>
resourcesIt
=
resources
.
iterator
();
OLATResource
firstResource
=
resourcesIt
.
next
();
area
.
setResource
(
firstResource
);
dbInstance
.
getCurrentEntityManager
().
merge
(
area
);
List
<
Long
>
firstResourcesGroupKeys
=
findBusinessGroupsOfResource
(
firstResource
);
List
<
BusinessGroup
>
originalGroupList
=
findBusinessGroupsOfArea
(
area
);
//remove the groups which aren't part of the first resource
for
(
BusinessGroup
group:
originalGroupList
)
{
if
(!
firstResourcesGroupKeys
.
contains
(
group
.
getKey
()))
{
areaManager
.
removeBGFromArea
(
group
,
area
);
}
}
//duplicate the areas for the next resources
if
(
resourcesIt
.
hasNext
())
{
for
(
;
resourcesIt
.
hasNext
();
)
{
OLATResource
resource
=
resourcesIt
.
next
();
List
<
Long
>
resourcesGroupKeys
=
findBusinessGroupsOfResource
(
resource
);
BGArea
existingArea
=
areaManager
.
findBGArea
(
area
.
getName
(),
resource
);
if
(
existingArea
==
null
)
{
BGArea
copyArea
=
areaManager
.
createAndPersistBGAreaIfNotExists
(
area
.
getName
(),
area
.
getDescription
(),
resource
);
for
(
BusinessGroup
group:
originalGroupList
)
{
if
(
resourcesGroupKeys
.
contains
(
group
.
getKey
()))
{
areaManager
.
addBGToBGArea
(
group
,
copyArea
);
}
}
}
}
}
}
dbInstance
.
commitAndCloseSession
();
}
private
List
<
OLATResource
>
findOLATResourcesForBGContext
(
Long
contextKey
)
{
StringBuilder
q
=
new
StringBuilder
();
q
.
append
(
"select bgcr.resource from "
).
append
(
BGContext2Resource
.
class
.
getName
()).
append
(
" as bgcr where bgcr.groupContext.key=:contextKey"
);
List
<
OLATResource
>
resources
=
dbInstance
.
getCurrentEntityManager
()
.
createQuery
(
q
.
toString
(),
OLATResource
.
class
)
.
setParameter
(
"contextKey"
,
contextKey
)
.
getResultList
();
return
resources
;
}
private
List
<
Long
>
findBusinessGroupsOfResource
(
OLATResource
resource
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"select distinct relation.group.key from "
).
append
(
BGResourceRelation
.
class
.
getName
()).
append
(
" relation where relation.resource.key=:resourceKey"
);
List
<
Long
>
groups
=
dbInstance
.
getCurrentEntityManager
()
.
createQuery
(
sb
.
toString
(),
Long
.
class
)
.
setParameter
(
"resourceKey"
,
resource
.
getKey
())
.
getResultList
();
return
groups
;
}
private
List
<
BusinessGroup
>
findBusinessGroupsOfArea
(
BGArea
area
)
{
StringBuilder
q
=
new
StringBuilder
();
q
.
append
(
"select bgarel.businessGroup from "
).
append
(
BGtoAreaRelationImpl
.
class
.
getName
()).
append
(
" as bgarel "
)
.
append
(
" where bgarel.groupArea.key=:areaKey"
);
List
<
BusinessGroup
>
groups
=
dbInstance
.
getCurrentEntityManager
()
.
createQuery
(
q
.
toString
(),
BusinessGroup
.
class
)
.
setParameter
(
"areaKey"
,
area
.
getKey
())
.
getResultList
();
return
groups
;
}
private
List
<
BGAreaImpl
>
findAreas
(
int
firstResult
,
int
maxResults
)
{
StringBuilder
q
=
new
StringBuilder
();
q
.
append
(
"select area from "
).
append
(
BGAreaImpl
.
class
.
getName
()).
append
(
" area "
)
.
append
(
" left join fetch area.resource resource"
)
.
append
(
" order by area.key"
);
List
<
BGAreaImpl
>
resources
=
dbInstance
.
getCurrentEntityManager
().
createQuery
(
q
.
toString
(),
BGAreaImpl
.
class
)
.
setFirstResult
(
firstResult
)
.
setMaxResults
(
maxResults
)
.
getResultList
();
return
resources
;
}
private
List
<
BusinessGroup
>
findBusinessGroups
(
int
firstResult
,
int
maxResults
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment