use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.
the class EfficiencyStatementManagerTest method testBigDatas.
@Test
public void testBigDatas() {
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
params.setRoles(new Roles(true, false, false, false, false, false, false));
params.setResourceTypes(Collections.singletonList("CourseModule"));
List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 10000);
int count = 0;
for (RepositoryEntry entry : entries) {
Long resourceableId = entry.getOlatResource().getResourceableId();
try {
ICourse course = CourseFactory.loadCourse(resourceableId);
boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
if (!enabled) {
course = CourseFactory.openCourseEditSession(entry.getOlatResource().getResourceableId());
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
courseConfig.setEfficencyStatementIsEnabled(true);
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
}
DBFactory.getInstance().commitAndCloseSession();
try {
int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
if (fromIndex < 100) {
fromIndex = 100;
}
List<Identity> assessedIdentities = loadIdentities.subList(fromIndex - 100, fromIndex);
// force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
efficiencyStatementManager.updateEfficiencyStatements(courseEntry, assessedIdentities);
} catch (Exception e) {
e.printStackTrace();
}
DBFactory.getInstance().commitAndCloseSession();
DBFactory.getInstance().closeSession();
} catch (CorruptedCourseException e) {
System.out.println("Error");
}
if (count++ % 100 == 0) {
dbInstance.commitAndCloseSession();
}
}
}
use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.
the class CourseTest method testDeleteCourses.
@Test
public void testDeleteCourses() throws IOException, URISyntaxException {
ICourse course = CoursesWebService.createEmptyCourse(admin, "courseToDel", "course to delete", null);
dbInstance.intermediateCommit();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course.getResourceableId()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<String> courseType = new ArrayList<String>();
courseType.add(CourseModule.getCourseTypeName());
Roles roles = new Roles(true, true, true, true, false, true, false);
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters("*", "*", "*", courseType, null, roles, "");
List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
assertNotNull(repoEntries);
for (RepositoryEntry entry : repoEntries) {
assertNotSame(entry.getOlatResource().getResourceableId(), course.getResourceableId());
}
}
use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.
the class CatalogNodeManagerController method loadResources.
private void loadResources(UserRequest ureq) {
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
params.setParentEntry(catalogEntry);
List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
List<Long> resourceKeys = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
resourceKeys.add(entry.getOlatResource().getKey());
}
List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
List<CatalogEntryRow> items = new ArrayList<>();
List<CatalogEntryRow> closedItems = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
CatalogEntryRow row = new CatalogEntryRow(entry);
List<PriceMethod> types = new ArrayList<PriceMethod>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", translate("cif.access.membersonly.short")));
} else {
// collect access control method icons
OLATResource resource = entry.getOlatResource();
for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
String displayName = amh.getMethodName(getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
if (entry.getRepositoryEntryStatus().isClosed()) {
closedItems.add(row);
} else {
items.add(row);
}
}
entriesModel.setObjects(items);
entriesEl.reset();
entriesEl.setVisible(entriesModel.getRowCount() > 0);
closedEntriesModel.setObjects(closedItems);
closedEntriesEl.reset();
closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.
the class RepositoryIndexer method doIndex.
/**
* Loops over all repository-entries. Index repository meta data.
* Go further with repository-indexer for certain type if available.
* @see org.olat.search.service.indexer.Indexer#doIndex(org.olat.search.service.SearchResourceContext, java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer)
*/
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
final Roles roles = new Roles(true, true, true, true, false, true, false);
final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
params.setRoles(roles);
boolean debug = isLogDebugEnabled();
// loop over all repository-entries
// committing here to make sure the loadBusinessGroup below does actually
// reload from the database and not only use the session cache
// (see org.hibernate.Session.get():
// If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.)
dbInstance.commitAndCloseSession();
int counter = 0;
List<RepositoryEntry> repositoryList;
do {
repositoryList = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, BATCH_SIZE, true);
for (RepositoryEntry repositoryEntry : repositoryList) {
try {
// reload the repositoryEntry here before indexing it to make sure it has not been deleted in the meantime
RepositoryEntry reloadedRepositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryEntry.getKey());
if (reloadedRepositoryEntry == null) {
logInfo("doIndex: repositoryEntry was deleted while we were indexing. The deleted repositoryEntry was: " + repositoryEntry);
continue;
}
if (repositoryEntry.getAccess() == RepositoryEntry.DELETED) {
continue;
}
repositoryEntry = reloadedRepositoryEntry;
if (debug) {
logDebug("Index repositoryEntry=" + repositoryEntry + " counter=" + counter++ + " with ResourceableId=" + repositoryEntry.getOlatResource().getResourceableId());
}
if (!isOnBlacklist(repositoryEntry.getOlatResource().getResourceableId())) {
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(repositoryEntry);
searchResourceContext.setTitle(repositoryEntry.getDisplayname());
searchResourceContext.setDescription(repositoryEntry.getDescription());
Document document = documentFactory.createDocument(searchResourceContext, repositoryEntry);
indexWriter.addDocument(document);
// Pass created-date & modified-date in context to child indexer because the child have no dates
searchResourceContext.setLastModified(repositoryEntry.getLastModified());
searchResourceContext.setCreatedDate(repositoryEntry.getCreationDate());
// go further with resource
Indexer repositoryEntryIndexer = getRepositoryEntryIndexer(repositoryEntry);
if (repositoryEntryIndexer != null) {
repositoryEntryIndexer.doIndex(searchResourceContext, repositoryEntry, indexWriter);
} else if (debug) {
// e.g. RepositoryEntry
logDebug("No RepositoryEntryIndexer for " + repositoryEntry.getOlatResource());
}
} else {
logWarn("RepositoryEntry is on black-list and excluded from search-index, repositoryEntry=" + repositoryEntry, null);
}
} catch (Throwable ex) {
// create meaninfull debugging output to find repo entry that is somehow broken
String entryDebug = "NULL";
if (repositoryEntry != null) {
entryDebug = "resId::" + repositoryEntry.getResourceableId() + " resTypeName::" + repositoryEntry.getResourceableTypeName() + " resName::" + repositoryEntry.getResourcename();
}
logWarn("Exception=" + ex.getMessage() + " for repo entry " + entryDebug, ex);
dbInstance.rollbackAndCloseSession();
}
dbInstance.commitAndCloseSession();
}
counter += repositoryList.size();
} while (repositoryList.size() == BATCH_SIZE);
if (debug) {
logDebug("RepositoryIndexer finished. counter=" + counter);
}
}
use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_8_2_0 method upgradeCourseConditions.
private boolean upgradeCourseConditions(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_CONDITIONS)) {
int counter = 0;
List<RepositoryEntry> entries;
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
params.setRoles(new Roles(true, false, false, false, false, false, false));
params.addResourceTypes("CourseModule");
do {
entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, REPO_ENTRIES_BATCH_SIZE, true);
for (RepositoryEntry entry : entries) {
try {
ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
CourseEnvironmentMapper envMapper = getCourseEnvironmentMapper(entry);
course.postImport(null, envMapper);
} catch (CorruptedCourseException e) {
log.error("Course seems corrupt: " + entry.getOlatResource().getResourceableId());
} catch (Exception e) {
log.error("Course seems highly corrupt: " + entry.getOlatResource().getResourceableId());
}
}
dbInstance.intermediateCommit();
counter += entries.size();
log.audit("Processed repository entries: " + entries.size());
} while (entries.size() == REPO_ENTRIES_BATCH_SIZE);
uhd.setBooleanDataValue(TASK_CONDITIONS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return true;
}
Aggregations