use of org.olat.portfolio.model.structel.EPPage in project openolat by klemens.
the class EPTOCReadOnlyController method buildTOCModel.
/**
* builds the tocList recursively containing artefacts, pages and
* struct-Elements
*
* @param pStruct
* @param tocList
* list with TOCElement's to use in velocity
* @param level
* @param withArtefacts
* set false, to skip artefacts
*/
private void buildTOCModel(PortfolioStructure pStruct, List<TOCElement> tocList, int level) {
level++;
if (displayArtefactsInTOC) {
List<AbstractArtefact> artList = ePFMgr.getArtefacts(pStruct);
if (artList != null && artList.size() != 0) {
for (AbstractArtefact artefact : artList) {
String key = String.valueOf(artefact.getKey());
String title = StringHelper.escapeHtml(artefact.getTitle());
Link iconLink = LinkFactory.createCustomLink("arte_" + key, LINK_CMD_OPEN_ARTEFACT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(pStruct);
Link titleLink = LinkFactory.createCustomLink("arte_t_" + key, LINK_CMD_OPEN_ARTEFACT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(pStruct);
TOCElement actualTOCEl = new TOCElement(level, "artefact", titleLink, iconLink, null, null);
tocList.add(actualTOCEl);
}
}
}
List<PortfolioStructure> childs = ePFMgr.loadStructureChildren(pStruct);
if (childs != null && childs.size() != 0) {
for (PortfolioStructure portfolioStructure : childs) {
String type = "";
if (portfolioStructure instanceof EPPage) {
type = CONST_FOR_VC_STYLE_PAGE;
} else {
// a structure element
type = CONST_FOR_VC_STYLE_STRUCT;
}
String key = String.valueOf(portfolioStructure.getKey());
String title = StringHelper.escapeHtml(portfolioStructure.getTitle());
Link iconLink = LinkFactory.createCustomLink("portstruct" + key, LINK_CMD_OPEN_STRUCT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(portfolioStructure);
Link titleLink = LinkFactory.createCustomLink("portstruct_t_" + key, LINK_CMD_OPEN_STRUCT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(portfolioStructure);
Link commentLink = null;
if (portfolioStructure instanceof EPPage && secCallback.canCommentAndRate()) {
UserCommentsCount comments = getUserCommentsCount(portfolioStructure);
String count = comments == null ? "0" : comments.getCount().toString();
String label = translate("commentLink", new String[] { count });
commentLink = LinkFactory.createCustomLink("commentLink" + key, LINK_CMD_OPEN_COMMENTS, label, Link.NONTRANSLATED, vC, this);
commentLink.setIconLeftCSS("o_icon o_icon_comments");
commentLink.setUserObject(portfolioStructure);
}
// prefetch children to keep reference on them
List<TOCElement> tocChildList = new ArrayList<TOCElement>();
buildTOCModel(portfolioStructure, tocChildList, level);
TOCElement actualTOCEl = new TOCElement(level, type, titleLink, iconLink, commentLink, tocChildList);
tocList.add(actualTOCEl);
if (tocChildList.size() != 0) {
tocList.addAll(tocChildList);
}
}
}
}
use of org.olat.portfolio.model.structel.EPPage in project openolat by klemens.
the class OLATUpgrade_7_1_1 method mergeCommentsToFinalStruct.
private void mergeCommentsToFinalStruct(PortfolioStructure finalStruct, List<PortfolioStructure> wrongStructs) {
if (wrongStructs == null || wrongStructs.isEmpty())
return;
List<UserComment> collectedComments = new ArrayList<UserComment>();
// collect all comments out there
for (PortfolioStructure portfolioStructure : wrongStructs) {
// no comments on StructureElements!
if (!(portfolioStructure instanceof EPPage))
return;
List<UserComment> oldComments = commentAndRatingService.getComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
collectedComments.addAll(oldComments);
commentAndRatingService.deleteAllComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
}
log.audit(" found " + collectedComments.size() + " comments for this structure, will be merged to new destination.");
if (collectedComments.size() == 0)
return;
Identity ident = collectedComments.get(0).getCreator();
UserComment topComment = commentAndRatingService.createComment(ident, finalStruct.getRootMap(), finalStruct.getKey().toString(), "The following comments were restored from a migration task to rescue lost data.");
// attach all to this info-comment
for (UserComment userComment : collectedComments) {
UserComment attachedComment = commentAndRatingService.replyTo(topComment, userComment.getCreator(), userComment.getComment());
// set original date
attachedComment.setCreationDate(userComment.getCreationDate());
commentAndRatingService.updateComment(attachedComment, attachedComment.getComment());
}
}
use of org.olat.portfolio.model.structel.EPPage in project OpenOLAT by OpenOLAT.
the class EPFrontendManager method createAndPersistPortfolioPage.
/**
* create a page
* @param root
* @param title
* @param description
* @return
*/
public PortfolioStructure createAndPersistPortfolioPage(PortfolioStructure root, String title, String description) {
EPPage newPage = (EPPage) structureManager.createPortfolioPage(root, title, description);
if (root != null)
structureManager.addStructureToStructure(root, newPage, -1);
structureManager.savePortfolioStructure(newPage);
return newPage;
}
use of org.olat.portfolio.model.structel.EPPage in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method testAssignMapTemplateToUser.
@Test
public void testAssignMapTemplateToUser() {
// create a template
OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
// create a repository entry
RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "template-1", "map-template-1", resource, RepositoryEntry.ACC_OWNERS);
dbInstance.commitAndCloseSession();
// create the template owned by ident1
PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
// first page
PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-1", "template-page-1");
// structure element 1 from page 1
PortfolioStructure struct11 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.1", "template-structure-1.1");
epStructureManager.addCollectRestriction(struct11, "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(struct11);
// structure element 2 from page 1
PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.2", "template-structure-1.2");
assertNotNull(struct12);
// first page
PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-2", "template-page-2");
// structure element 1 from page 2
PortfolioStructure struct21 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "template-structure-2.1", "template-structure-2.1");
epStructureManager.addCollectRestriction(struct21, "bc", "maximum", 4);
epStructureManager.savePortfolioStructure(struct21);
// save the template
dbInstance.commitAndCloseSession();
// make the copy
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(map);
// check the copy
PortfolioStructure retrievedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
assertNotNull(retrievedMap);
assertTrue(retrievedMap instanceof EPStructuredMap);
assertNotNull(((EPStructuredMap) retrievedMap).getStructuredMapSource());
assertEquals(templateEl.getKey(), ((EPStructuredMap) retrievedMap).getStructuredMapSource().getKey());
// check pages of the copied map
List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedMap);
assertNotNull(pages);
assertEquals(2, pages.size());
assertTrue(pages.get(0) instanceof EPPage);
assertTrue(pages.get(1) instanceof EPPage);
assertEquals("template-page-1", ((EPStructureElement) pages.get(0)).getTitle());
assertEquals("template-page-2", ((EPStructureElement) pages.get(1)).getTitle());
// check root
assertNotNull(((EPStructureElement) pages.get(0)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) pages.get(0)).getRoot().getKey());
// check children of the pages
List<PortfolioStructure> structs1 = epFrontendManager.loadStructureChildren(pages.get(0));
assertNotNull(structs1);
assertEquals(2, structs1.size());
assertTrue(structs1.get(0) instanceof EPStructureElement);
assertTrue(structs1.get(1) instanceof EPStructureElement);
EPStructureElement struct11El = (EPStructureElement) structs1.get(0);
assertEquals("template-structure-1.1", struct11El.getTitle());
assertEquals("template-structure-1.2", ((EPStructureElement) structs1.get(1)).getTitle());
// check root
assertNotNull(((EPStructureElement) structs1.get(0)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(0)).getRoot().getKey());
assertNotNull(((EPStructureElement) structs1.get(1)).getRoot());
assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(1)).getRoot().getKey());
// check collect restriction
assertNotNull(struct11El.getCollectRestrictions());
assertEquals("Forum", struct11El.getCollectRestrictions().get(0).getArtefactType());
assertEquals("minimum", struct11El.getCollectRestrictions().get(0).getRestriction());
assertEquals(2, struct11El.getCollectRestrictions().get(0).getAmount());
List<PortfolioStructure> structs2 = epFrontendManager.loadStructureChildren(pages.get(1));
assertNotNull(structs2);
assertEquals(1, structs2.size());
assertTrue(structs2.get(0) instanceof EPStructureElement);
EPStructureElement struct21El = (EPStructureElement) structs2.get(0);
assertEquals("template-structure-2.1", struct21El.getTitle());
// check root
assertNotNull(struct21El.getRoot());
assertEquals(retrievedMap.getKey(), struct21El.getRoot().getKey());
// check collect restriction
assertNotNull(struct21El.getCollectRestrictions());
assertEquals("bc", struct21El.getCollectRestrictions().get(0).getArtefactType());
assertEquals("maximum", struct21El.getCollectRestrictions().get(0).getRestriction());
assertEquals(4, struct21El.getCollectRestrictions().get(0).getAmount());
}
use of org.olat.portfolio.model.structel.EPPage in project OpenOLAT by OpenOLAT.
the class EPTOCController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source instanceof Link) {
Link link = (Link) source;
if (link.getCommand().equals(DELETE_LINK_CMD)) {
if (artefactClicked != null) {
AbstractArtefact artefact = artefactClicked;
PortfolioStructure parentStruct = getArtefactParentStruct(artefactClicked);
ePFMgr.removeArtefactFromStructure(artefact, parentStruct);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (structureClicked != null) {
if ((structureClicked instanceof EPPage) && !(structureClicked instanceof EPAbstractMap)) {
PortfolioStructure ps = structureClicked;
while (ePFMgr.loadStructureParent(ps) != null) {
ps = ePFMgr.loadStructureParent(ps);
}
int childPages = ePFMgr.countStructureChildren(ps);
if (childPages > 1) {
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showError("last.page.not.deletable");
}
} else if (structureClicked instanceof EPStructureElement && !(structureClicked instanceof EPAbstractMap)) {
// structures should always be deletable
eSTMgr.removeStructureRecursively(structureClicked);
// refresh the view
fireEvent(ureq, Event.CHANGED_EVENT);
} else {
showInfo("element.not.deletable");
}
}
}
} else if (source == treeCtr) {
if (event instanceof TreeEvent) {
TreeEvent te = (TreeEvent) event;
if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
doSelectTreeElement(ureq, te);
}
} else if (event instanceof TreeDropEvent) {
TreeDropEvent te = (TreeDropEvent) event;
doDrop(ureq, te.getDroppedNodeId(), te.getTargetNodeId(), te.isAsChild());
}
}
}
Aggregations