use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class SPCourseNodeIndexer method indexSubPages.
private void indexSubPages(SearchResourceContext courseNodeResourceContext, VFSContainer rootContainer, OlatFullIndexer indexWriter, VFSLeaf leaf, Set<String> alreadyIndexFileNames, int subPageLevel, String rootFilePath) throws IOException, InterruptedException {
int mySubPageLevel = subPageLevel;
// check deepness of recursion
if (mySubPageLevel++ <= 5) {
List<String> links = getLinkListFrom(leaf);
for (String link : links) {
if (log.isDebug())
log.debug("link=" + link);
if ((rootFilePath != null) && !rootFilePath.equals("")) {
if (rootFilePath.endsWith("/")) {
link = rootFilePath + link;
} else {
link = rootFilePath + "/" + link;
}
}
if (!alreadyIndexFileNames.contains(link)) {
VFSItem item = rootContainer.resolve(link);
if ((item != null) && (item instanceof VFSLeaf)) {
VFSLeaf subPageLeaf = (VFSLeaf) item;
if (log.isDebug())
log.debug("subPageLeaf=" + subPageLeaf);
String filePath = getPathFor(subPageLeaf);
String newRootFilePath = filePath;
doIndexVFSLeafByMySelf(courseNodeResourceContext, subPageLeaf, indexWriter, filePath);
alreadyIndexFileNames.add(link);
indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, subPageLeaf, alreadyIndexFileNames, mySubPageLevel, newRootFilePath);
} else {
if (log.isDebug())
log.debug("Could not found sub-page for link=" + link);
}
} else {
if (log.isDebug())
log.debug("sub-page already indexed, link=" + link);
}
}
} else {
if (log.isDebug())
log.debug("Reach to many sub-page levels. Go not further with indexing sub-pages last leaf=" + leaf.getName());
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class STCourseNodeIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
if (log.isDebug())
log.debug("Index StructureNode...");
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, TYPE);
Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
indexWriter.addDocument(document);
ModuleConfiguration config = courseNode.getModuleConfiguration();
String displayType = config.getStringValue(STCourseNodeEditController.CONFIG_KEY_DISPLAY_TYPE);
String relPath = STCourseNodeEditController.getFileName(config);
if (relPath != null && displayType != null && displayType.equals(STCourseNodeEditController.CONFIG_VALUE_DISPLAY_FILE)) {
VFSItem displayPage = course.getCourseFolderContainer().resolve(relPath);
if (displayPage instanceof VFSLeaf) {
doIndexVFSLeafByMySelf(courseNodeResourceContext, (VFSLeaf) displayPage, indexWriter, relPath);
}
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class CheckListRunController method forgeCheckboxWrapper.
private CheckboxWrapper forgeCheckboxWrapper(Checkbox checkbox, DBCheck check, boolean readOnly, FormItemContainer formLayout) {
String[] values = new String[] { translate(checkbox.getLabel().i18nKey()) };
boolean canCheck = CheckboxReleaseEnum.userAndCoach.equals(checkbox.getRelease());
String boxId = "box_" + checkbox.getCheckboxId();
MultipleSelectionElement el = uifactory.addCheckboxesHorizontal(boxId, null, formLayout, onKeys, values);
el.setEnabled(canCheck && !readOnly && !userCourseEnv.isCourseReadOnly());
el.addActionListener(FormEvent.ONCHANGE);
DownloadLink downloadLink = null;
if (StringHelper.containsNonWhitespace(checkbox.getFilename())) {
VFSContainer container = checkboxManager.getFileContainer(userCourseEnv.getCourseEnvironment(), courseNode);
VFSItem item = container.resolve(checkbox.getFilename());
if (item instanceof VFSLeaf) {
String name = "file_" + checkbox.getCheckboxId();
downloadLink = uifactory.addDownloadLink(name, checkbox.getFilename(), null, (VFSLeaf) item, formLayout);
}
}
CheckboxWrapper wrapper = new CheckboxWrapper(checkbox, downloadLink, el);
el.setUserObject(wrapper);
if (check != null && check.getChecked() != null && check.getChecked().booleanValue()) {
el.select(onKeys[0], true);
wrapper.setDbCheckbox(check.getCheckbox());
wrapper.setScore(check.getScore());
}
if (downloadLink != null) {
downloadLink.setUserObject(wrapper);
}
return wrapper;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class CheckboxEditController method doDownloadFile.
private void doDownloadFile(UserRequest ureq) {
VFSContainer container = getFileContainer();
VFSItem item = container.resolve(checkbox.getFilename());
if (item instanceof VFSLeaf) {
VFSMediaResource rsrc = new VFSMediaResource((VFSLeaf) item);
rsrc.setDownloadable(true);
ureq.getDispatchResult().setResultingMediaResource(rsrc);
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class CheckboxEditController method formOK.
@Override
protected void formOK(UserRequest ureq) {
checkbox.setTitle(titleEl.getValue());
String releaseKey = releaseEl.getSelectedKey();
checkbox.setRelease(CheckboxReleaseEnum.valueOf(releaseKey));
String labelKey = labelEl.getSelectedKey();
checkbox.setLabel(CheckboxLabelEnum.valueOf(labelKey));
if (awardPointEl.isAtLeastSelected(1)) {
Float points = null;
try {
points = new Float(Float.parseFloat(pointsEl.getValue()));
} catch (NumberFormatException e) {
// check in validation
}
checkbox.setPoints(points);
} else {
checkbox.setPoints(null);
}
checkbox.setDescription(descriptionEl.getValue());
if (Boolean.TRUE.equals(deleteFile)) {
checkbox.setFilename(null);
VFSContainer container = getFileContainer();
for (VFSItem chd : container.getItems()) {
chd.delete();
}
}
File uploadedFile = fileEl.getUploadFile();
if (uploadedFile != null) {
String filename = fileEl.getUploadFileName();
checkbox.setFilename(filename);
VFSContainer container = getFileContainer();
VFSLeaf leaf = container.createChildLeaf(filename);
try (InputStream inStream = new FileInputStream(uploadedFile)) {
VFSManager.copyContent(inStream, leaf);
} catch (IOException e) {
logError("", e);
}
}
if (courseNode != null) {
ILoggingAction action = newCheckbox ? CourseLoggingAction.CHECKLIST_CHECKBOX_CREATED : CourseLoggingAction.CHECKLIST_CHECKBOX_UPDATED;
ThreadLocalUserActivityLogger.log(action, getClass(), LoggingResourceable.wrap(courseNode), LoggingResourceable.wrapNonOlatResource(StringResourceableType.checkbox, checkbox.getCheckboxId(), checkbox.getTitle()));
}
fireEvent(ureq, Event.CHANGED_EVENT);
}
Aggregations