Skip to content

Commit e1980a4

Browse files
committed
Remove circular dependency ListProvidersService
Break the circular dependency by removing the direct dependency from ElasticsearchIndex to ListProvidersService. Some list providers depend on index service, which created a problematic cycle. This change decouples the index implementation from the list-provider lookup, reducing coupling and avoiding initialization/order problems.
1 parent 158b358 commit e1980a4

File tree

25 files changed

+190
-167
lines changed

25 files changed

+190
-167
lines changed

modules/admin-ui/src/main/java/org/opencastproject/adminui/endpoint/SeriesEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public Response getSeriesAccessInformation(@PathParam("seriesId") String seriesI
362362
@RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
363363
public Response getSeriesMetadata(@PathParam("seriesId") String series) throws UnauthorizedException,
364364
NotFoundException, SearchIndexException {
365-
Optional<Series> optSeries = searchIndex.getSeries(series, securityService.getOrganization().getId(), securityService.getUser());
365+
Optional<Series> optSeries = searchIndex.getSeries(series, securityService.getOrganization(), securityService.getUser());
366366
if (optSeries.isEmpty())
367367
return notFound("Cannot find a series with id '%s'.", series);
368368

@@ -1035,7 +1035,7 @@ private Response getSimpleThemeJsonResponse(Theme theme) {
10351035
public Response getSeriesTheme(@PathParam("seriesId") String seriesId) {
10361036
Long themeId;
10371037
try {
1038-
Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization().getId(), securityService.getUser());
1038+
Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization(), securityService.getUser());
10391039
if (series.isEmpty())
10401040
return notFound("Cannot find a series with id {}", seriesId);
10411041

@@ -1298,7 +1298,7 @@ public Response applyAclToSeries(@PathParam("seriesId") String seriesId, @FormPa
12981298
return badRequest();
12991299
}
13001300

1301-
Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization().getId(), securityService.getUser());
1301+
Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization(), securityService.getUser());
13021302
if (series.isEmpty())
13031303
return notFound("Cannot find a series with id {}", seriesId);
13041304

modules/admin-ui/src/main/java/org/opencastproject/adminui/endpoint/StatisticsEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private void checkMediapackageAccess(final String mpId) throws UnauthorizedExcep
318318
}
319319

320320
private void checkSeriesAccess(final String seriesId) throws UnauthorizedException, SearchIndexException {
321-
final Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization().getId(), securityService.getUser());
321+
final Optional<Series> series = searchIndex.getSeries(seriesId, securityService.getOrganization(), securityService.getUser());
322322
if (series.isEmpty()) {
323323
// IndexService checks permissions and returns None if user is unauthorized
324324
throw new UnauthorizedException(securityService.getUser(), "read");

modules/admin-ui/src/test/java/org/opencastproject/adminui/endpoint/TestSeriesEndpoint.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ private void setupIndex(Organization defaultOrganization, User user) throws Sear
361361

362362
elasticsearchIndex = EasyMock.createMock(ElasticsearchIndex.class);
363363

364-
EasyMock.expect(elasticsearchIndex.getSeries("1", defaultOrganization.getId(), user)).andReturn(Optional.of(series1));
365-
EasyMock.expect(elasticsearchIndex.getSeries("2", defaultOrganization.getId(), user)).andReturn(Optional.of(series2));
366-
EasyMock.expect(elasticsearchIndex.getSeries("3", defaultOrganization.getId(), user)).andReturn(Optional.of(series3));
367-
EasyMock.expect(elasticsearchIndex.getSeries(anyString(), anyString(), anyObject())).andReturn(Optional.empty());
364+
EasyMock.expect(elasticsearchIndex.getSeries("1", defaultOrganization, user)).andReturn(Optional.of(series1));
365+
EasyMock.expect(elasticsearchIndex.getSeries("2", defaultOrganization, user)).andReturn(Optional.of(series2));
366+
EasyMock.expect(elasticsearchIndex.getSeries("3", defaultOrganization, user)).andReturn(Optional.of(series3));
367+
EasyMock.expect(elasticsearchIndex.getSeries(anyString(), anyObject(Organization.class), anyObject())).andReturn(Optional.empty());
368368

369369
final Capture<SeriesSearchQuery> captureSeriesSearchQuery = EasyMock.newCapture();
370370
final Capture<EventSearchQuery> captureEventSearchQuery = EasyMock.newCapture();

modules/admin-ui/src/test/java/org/opencastproject/adminui/endpoint/TestTasksEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.opencastproject.security.api.JaxbOrganization;
5353
import org.opencastproject.security.api.JaxbRole;
5454
import org.opencastproject.security.api.JaxbUser;
55+
import org.opencastproject.security.api.Organization;
5556
import org.opencastproject.security.api.SecurityService;
5657
import org.opencastproject.security.api.User;
5758
import org.opencastproject.util.IoSupport;
@@ -179,8 +180,8 @@ public Snapshot prepareForDelivery(Snapshot snapshot) {
179180
EasyMock.replay(authorizationService);
180181

181182
ElasticsearchIndex esIndex = EasyMock.createNiceMock(ElasticsearchIndex.class);
182-
EasyMock.expect(esIndex.addOrUpdateEvent(EasyMock.anyString(), EasyMock.anyObject(Function.class),
183-
EasyMock.anyString(), EasyMock.anyObject(User.class))).andReturn(Optional.empty()).atLeastOnce();
183+
expect(esIndex.addOrUpdateEvent(EasyMock.anyString(), anyObject(Function.class),
184+
anyObject(Organization.class), anyObject(User.class))).andReturn(Optional.empty()).atLeastOnce();
184185
EasyMock.replay(esIndex);
185186

186187
AssetManagerImpl am = new AssetManagerImpl();

modules/asset-manager-impl/src/main/java/org/opencastproject/assetmanager/impl/AssetManagerImpl.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,18 @@ public void triggerIndexUpdate(String mediaPackageId) throws NotFoundException,
524524
*/
525525
private void updateEventInIndex(Snapshot snapshot) {
526526
final String eventId = snapshot.getMediaPackage().getIdentifier().toString();
527-
final String orgId = securityService.getOrganization().getId();
527+
final Organization organization = securityService.getOrganization();
528528
final User user = securityService.getUser();
529529

530530
logger.debug("Updating event {} in the {} index.", eventId, index.getIndexName());
531-
Function<Optional<Event>, Optional<Event>> updateFunction = getEventUpdateFunction(snapshot, orgId, user);
531+
Function<Optional<Event>, Optional<Event>> updateFunction = getEventUpdateFunction(
532+
snapshot,
533+
organization.getId(),
534+
user
535+
);
532536

533537
try {
534-
index.addOrUpdateEvent(eventId, updateFunction, orgId, user);
538+
index.addOrUpdateEvent(eventId, updateFunction, organization, user);
535539
logger.debug("Event {} updated in the {} index.", eventId, index.getIndexName());
536540
} catch (SearchIndexException e) {
537541
logger.error("Error updating the event {} in the {} index.", eventId, index.getIndexName(), e);
@@ -545,7 +549,7 @@ private void updateEventInIndex(Snapshot snapshot) {
545549
* The id of the event to remove
546550
*/
547551
private void removeArchivedVersionFromIndex(String eventId) {
548-
final String orgId = securityService.getOrganization().getId();
552+
final Organization organization = securityService.getOrganization();
549553
final User user = securityService.getUser();
550554
logger.debug("Received AssetManager delete episode message {}", eventId);
551555

@@ -560,7 +564,7 @@ private void removeArchivedVersionFromIndex(String eventId) {
560564
};
561565

562566
try {
563-
index.addOrUpdateEvent(eventId, updateFunction, orgId, user);
567+
index.addOrUpdateEvent(eventId, updateFunction, organization, user);
564568
logger.debug("Event {} removed from the {} index", eventId, index.getIndexName());
565569
} catch (SearchIndexException e) {
566570
logger.error("Error deleting the event {} from the {} index.", eventId, index.getIndexName(), e);
@@ -1072,8 +1076,11 @@ public void repopulate(DataType dataType) throws IndexRebuildException {
10721076
try {
10731077
current++;
10741078

1075-
var updatedEventData = index.getEvent(snapshot.getMediaPackage().getIdentifier().toString(), orgId,
1076-
snapshotSystemUser);
1079+
var updatedEventData = index.getEvent(
1080+
snapshot.getMediaPackage().getIdentifier().toString(),
1081+
securityService.getOrganization(),
1082+
snapshotSystemUser
1083+
);
10771084
if (dataType == DataType.ALL) {
10781085
// Reindex everything (default)
10791086
updatedEventData = getEventUpdateFunction(snapshot, orgId, snapshotSystemUser)
@@ -1089,7 +1096,7 @@ public void repopulate(DataType dataType) throws IndexRebuildException {
10891096
updatedEventRange.add(updatedEventData.get());
10901097

10911098
if (updatedEventRange.size() >= n || current >= total) {
1092-
index.bulkEventUpdate(updatedEventRange);
1099+
index.bulkEventUpdate(updatedEventRange, securityService.getOrganization());
10931100
logIndexRebuildProgress(logger, total, current, n);
10941101
updatedEventRange.clear();
10951102
}

modules/asset-manager-impl/src/test/java/org/opencastproject/assetmanager/impl/AssetManagerTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ protected AssetManagerImpl makeAssetManagerWithoutHandlers() throws Exception {
157157

158158
ElasticsearchIndex esIndex = EasyMock.createNiceMock(ElasticsearchIndex.class);
159159
EasyMock.expect(esIndex.addOrUpdateEvent(EasyMock.anyString(), EasyMock.anyObject(Function.class),
160-
EasyMock.anyString(), EasyMock.anyObject(User.class))).andReturn(Optional.empty()).atLeastOnce();
160+
EasyMock.anyObject(Organization.class), EasyMock.anyObject(User.class)))
161+
.andReturn(Optional.empty()).atLeastOnce();
161162
EasyMock.replay(esIndex);
162163

163164
AssetManagerImpl am = new AssetManagerImpl();

modules/authorization-manager/src/main/java/org/opencastproject/authorization/xacml/manager/impl/AclServiceImpl.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public boolean updateAcl(ManagedAcl acl) {
8585
if (updateAcl) {
8686
if (oldName.isPresent() && !(oldName.get().getName().equals(acl.getName()))) {
8787
User user = securityService.getUser();
88-
updateAclInIndex(oldName.get().getName(), acl.getName(), index, organization.getId(), user);
88+
updateAclInIndex(oldName.get().getName(), acl.getName(), index, organization, user);
8989
}
9090
}
9191
return updateAcl;
@@ -103,7 +103,7 @@ public boolean deleteAcl(long id) throws AclServiceException, NotFoundException
103103
if (aclDb.deleteAcl(organization, id)) {
104104
if (deletedAcl.isPresent()) {
105105
User user = securityService.getUser();
106-
removeAclFromIndex(deletedAcl.get().getName(), index, organization.getId(), user);
106+
removeAclFromIndex(deletedAcl.get().getName(), index, organization, user);
107107
}
108108
return true;
109109
}
@@ -119,18 +119,18 @@ public boolean deleteAcl(long id) throws AclServiceException, NotFoundException
119119
* the new name of the managed acl
120120
* @param index
121121
* the index to update
122-
* @param orgId
122+
* @param organization
123123
* the organization the managed acl belongs to
124124
* @param user
125125
* the current user
126126
*/
127-
private void updateAclInIndex(String currentAclName, String newAclName, ElasticsearchIndex index, String orgId,
128-
User user) {
127+
private void updateAclInIndex(String currentAclName, String newAclName, ElasticsearchIndex index,
128+
Organization organization, User user) {
129129
logger.debug("Update the events to change the managed acl name from '{}' to '{}'.", currentAclName, newAclName);
130-
updateManagedAclForEvents(currentAclName, Optional.of(newAclName), index, orgId, user);
130+
updateManagedAclForEvents(currentAclName, Optional.of(newAclName), index, organization, user);
131131

132132
logger.debug("Update the series to change the managed acl name from '{}' to '{}'.", currentAclName, newAclName);
133-
updateManagedAclForSeries(currentAclName, Optional.of(newAclName), index, orgId, user);
133+
updateManagedAclForSeries(currentAclName, Optional.of(newAclName), index, organization, user);
134134
}
135135

136136
/**
@@ -140,18 +140,18 @@ private void updateAclInIndex(String currentAclName, String newAclName, Elastics
140140
* the current name of the managed acl
141141
* @param index
142142
* the index to update
143-
* @param orgId
143+
* @param organization
144144
* the organization the managed acl belongs to
145145
* @param user
146146
* the current user
147147
*/
148-
private void removeAclFromIndex(String currentAclName, ElasticsearchIndex index, String orgId,
148+
private void removeAclFromIndex(String currentAclName, ElasticsearchIndex index, Organization organization,
149149
User user) {
150150
logger.debug("Update the events to remove the managed acl name '{}'.", currentAclName);
151-
updateManagedAclForEvents(currentAclName, Optional.empty(), index, orgId, user);
151+
updateManagedAclForEvents(currentAclName, Optional.empty(), index, organization, user);
152152

153153
logger.debug("Update the series to remove the managed acl name '{}'.", currentAclName);
154-
updateManagedAclForSeries(currentAclName, Optional.empty(), index, orgId, user);
154+
updateManagedAclForSeries(currentAclName, Optional.empty(), index, organization, user);
155155
}
156156

157157
/**
@@ -162,19 +162,20 @@ private void removeAclFromIndex(String currentAclName, ElasticsearchIndex index,
162162
* @param newAclNameOpt
163163
* @param index
164164
* the index to update
165-
* @param orgId
165+
* @param organization
166166
* the organization the managed acl belongs to
167167
* @param user
168168
* the current user
169169
*/
170170
private void updateManagedAclForSeries(String currentAclName, Optional<String> newAclNameOpt,
171-
ElasticsearchIndex index, String orgId, User user) {
171+
ElasticsearchIndex index, Organization organization, User user) {
172172
SearchResult<Series> result;
173173
try {
174-
result = index.getByQuery(new SeriesSearchQuery(orgId, user).withoutActions()
174+
result = index.getByQuery(new SeriesSearchQuery(organization.getId(), user).withoutActions()
175175
.withManagedAcl(currentAclName));
176176
} catch (SearchIndexException e) {
177-
logger.error("Unable to find the series in org '{}' with current managed acl name '{}'", orgId, currentAclName,
177+
logger.error("Unable to find the series in org '{}' with current managed acl name '{}'", organization.getId(),
178+
currentAclName,
178179
e);
179180
return;
180181
}
@@ -192,7 +193,7 @@ private void updateManagedAclForSeries(String currentAclName, Optional<String> n
192193
};
193194

194195
try {
195-
index.addOrUpdateSeries(seriesId, updateFunction, orgId, user);
196+
index.addOrUpdateSeries(seriesId, updateFunction, organization, user);
196197
} catch (SearchIndexException e) {
197198
if (newAclNameOpt.isPresent()) {
198199
logger.warn("Unable to update series'{}' from current managed acl '{}' to new managed acl name '{}'",
@@ -212,20 +213,20 @@ private void updateManagedAclForSeries(String currentAclName, Optional<String> n
212213
* @param newAclNameOpt
213214
* @param index
214215
* the index to update
215-
* @param orgId
216+
* @param organization
216217
* the organization the managed acl belongs to
217218
* @param user
218219
* the current user
219220
*/
220221
private void updateManagedAclForEvents(String currentAclName, Optional<String> newAclNameOpt,
221-
ElasticsearchIndex index, String orgId, User user) {
222+
ElasticsearchIndex index, Organization organization, User user) {
222223
SearchResult<Event> result;
223224
try {
224-
result = index.getByQuery(new EventSearchQuery(orgId, user).withoutActions()
225+
result = index.getByQuery(new EventSearchQuery(organization.getId(), user).withoutActions()
225226
.withManagedAcl(currentAclName));
226227
} catch (SearchIndexException e) {
227228
logger.error("Unable to find the events in org '{}' with current managed acl name '{}' for event",
228-
orgId, currentAclName, e);
229+
organization.getId(), currentAclName, e);
229230
return;
230231
}
231232

@@ -242,7 +243,7 @@ private void updateManagedAclForEvents(String currentAclName, Optional<String> n
242243
};
243244

244245
try {
245-
index.addOrUpdateEvent(eventId, updateFunction, orgId, user);
246+
index.addOrUpdateEvent(eventId, updateFunction, organization, user);
246247
} catch (SearchIndexException e) {
247248
if (newAclNameOpt.isPresent()) {
248249
logger.warn(

0 commit comments

Comments
 (0)