use of org.olat.portfolio.model.structel.EPStructuredMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method testSyncMapTemplateToUserMap.
@Test
public void testSyncMapTemplateToUserMap() {
// create a template
OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
// create a repository entry
RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "Template in user", "Template in use", resource, RepositoryEntry.ACC_OWNERS);
// create the template owned by ident1
PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
// create five pages
List<PortfolioStructure> pageRefs = new ArrayList<PortfolioStructure>();
List<PortfolioStructure> elementRefs = new ArrayList<PortfolioStructure>();
for (int i = 0; i < 5; i++) {
PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(templateEl, "sync-template-page-" + i, "sync-template-page-" + i);
pageRefs.add(page);
for (int j = 0; j < 5; j++) {
PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(page, "template-structure-" + i + "." + j, "template-structure-" + i + "." + j);
epStructureManager.addCollectRestriction(struct, "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(struct);
elementRefs.add(struct);
}
}
// save the template
dbInstance.commitAndCloseSession();
// end create template
// ////////////////////
// make the copy
PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(map);
// ////////////////////////////////
// shuffle the pages and delete one
PortfolioStructure retrievedTemplateEl = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedTemplateEl);
epStructureManager.moveUp(retrievedTemplateEl, pages.get(1));
epStructureManager.moveDown(retrievedTemplateEl, pages.get(2));
epStructureManager.removeStructure(retrievedTemplateEl, pages.get(3));
epStructureManager.savePortfolioStructure(retrievedTemplateEl);
// shuffle a page
List<PortfolioStructure> page1Children = epFrontendManager.loadStructureChildren(pages.get(1));
epStructureManager.moveUp(pages.get(1), page1Children.get(3));
epStructureManager.moveUp(pages.get(1), page1Children.get(2));
epStructureManager.moveUp(pages.get(1), page1Children.get(4));
// and add an element and sub-elements
PortfolioStructure newStruct = epFrontendManager.createAndPersistPortfolioStructureElement(pages.get(1), "new-template-structure-1.6", "template-structure-1.6");
epStructureManager.addCollectRestriction(pages.get(1), "Forum", "minimum", 2);
epStructureManager.savePortfolioStructure(newStruct);
epStructureManager.savePortfolioStructure(pages.get(1));
for (int k = 0; k < 5; k++) {
PortfolioStructure struct = epFrontendManager.createAndPersistPortfolioStructureElement(newStruct, "new-template-structure-2." + k, "template-structure-2." + k);
epStructureManager.addCollectRestriction(struct, "bc", "minimum", 2);
epStructureManager.savePortfolioStructure(struct);
elementRefs.add(struct);
}
dbInstance.commitAndCloseSession();
// end shuffle the pages
// ////////////////////////////////
// //////////////////
// check the template
PortfolioStructure retrievedTemplate2El = epFrontendManager.loadPortfolioStructureByKey(templateEl.getKey());
assertNotNull(retrievedTemplate2El);
assertTrue(retrievedTemplate2El instanceof EPStructuredMapTemplate);
List<PortfolioStructure> retrievedPages2 = epFrontendManager.loadStructureChildren(retrievedTemplate2El);
assertEquals(4, retrievedPages2.size());
assertEquals(4, ((EPStructuredMapTemplate) retrievedTemplate2El).getInternalChildren().size());
// check the shuffled pages
assertEquals(pageRefs.get(1).getKey(), retrievedPages2.get(0).getKey());
assertEquals(pageRefs.get(0).getKey(), retrievedPages2.get(1).getKey());
assertEquals(pageRefs.get(2).getKey(), retrievedPages2.get(2).getKey());
assertEquals(pageRefs.get(4).getKey(), retrievedPages2.get(3).getKey());
// check added element
List<PortfolioStructure> retrievedChildren2 = epFrontendManager.loadStructureChildren(retrievedPages2.get(0));
assertEquals(6, retrievedChildren2.size());
dbInstance.commitAndCloseSession();
// check the template
// //////////////////
// sync the map
epFrontendManager.synchronizeStructuredMapToUserCopy(map);
dbInstance.commitAndCloseSession();
// ///////////////
// check the sync
PortfolioStructure synchedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
assertNotNull(synchedMap);
assertTrue(synchedMap instanceof EPStructuredMap);
List<PortfolioStructure> synchedPages = epFrontendManager.loadStructureChildren(synchedMap);
assertNotNull(synchedPages);
assertEquals(4, synchedPages.size());
assertEquals(((EPStructureElement) pageRefs.get(1)).getTitle(), ((EPStructureElement) synchedPages.get(0)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(0)).getTitle(), ((EPStructureElement) synchedPages.get(1)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(2)).getTitle(), ((EPStructureElement) synchedPages.get(2)).getTitle());
assertEquals(((EPStructureElement) pageRefs.get(4)).getTitle(), ((EPStructureElement) synchedPages.get(3)).getTitle());
// check synched key
assertEquals(((EPStructureElement) pageRefs.get(1)).getKey(), ((EPStructureElement) synchedPages.get(0)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(0)).getKey(), ((EPStructureElement) synchedPages.get(1)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(2)).getKey(), ((EPStructureElement) synchedPages.get(2)).getStructureElSource());
assertEquals(((EPStructureElement) pageRefs.get(4)).getKey(), ((EPStructureElement) synchedPages.get(3)).getStructureElSource());
// check the new elements
List<PortfolioStructure> retrievedPage1Children = epFrontendManager.loadStructureChildren(synchedPages.get(0));
assertEquals(6, retrievedPage1Children.size());
PortfolioStructure retrievedNewStruct = retrievedPage1Children.get(5);
assertEquals("new-template-structure-1.6", ((EPStructureElement) retrievedNewStruct).getTitle());
List<PortfolioStructure> retrievedNewStructChildren = epFrontendManager.loadStructureChildren(retrievedNewStruct);
assertNotNull(retrievedNewStructChildren);
assertEquals(5, retrievedNewStructChildren.size());
for (int k = 0; k < 5; k++) {
assertEquals("new-template-structure-2." + k, ((EPStructureElement) retrievedNewStructChildren.get(k)).getTitle());
}
// end check the sync
// //////////////////
}
use of org.olat.portfolio.model.structel.EPStructuredMap in project OpenOLAT by OpenOLAT.
the class EPStructureManagerTest method testUseStructureMapTemplate.
@Test
public void testUseStructureMapTemplate() {
// save parent and 20 children
PortfolioStructureMap template = epStructureManager.createPortfolioMapTemplate(ident1, "paged-parent-structure-el", "parent-structure-element");
epStructureManager.savePortfolioStructure(template);
dbInstance.commitAndCloseSession();
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioStructuredMap(template, ident1, "cloned-map", "cloned-map-from-template", null, null, null);
((EPStructuredMap) map).setReturnDate(new Date());
EPTargetResource targetResource = ((EPStructuredMap) map).getTargetResource();
targetResource.setResourceableTypeName("CourseModule");
targetResource.setResourceableId(234l);
targetResource.setSubPath("3894580");
targetResource.setBusinessPath("[RepositoryEntry:23647598][CourseNode:934598]");
epStructureManager.savePortfolioStructure(map);
dbInstance.commitAndCloseSession();
// test
PortfolioStructureMap retrievedMap = (PortfolioStructureMap) epFrontendManager.loadPortfolioStructureByKey(map.getKey());
assertNotNull(retrievedMap);
assertNotNull(((EPStructuredMap) retrievedMap).getReturnDate());
assertNotNull(((EPStructuredMap) retrievedMap).getStructuredMapSource());
assertNotNull(((EPStructuredMap) retrievedMap).getTargetResource());
EPTargetResource retriviedTargetResource = ((EPStructuredMap) retrievedMap).getTargetResource();
assertEquals("CourseModule", retriviedTargetResource.getResourceableTypeName());
assertEquals(new Long(234l), retriviedTargetResource.getResourceableId());
assertEquals("3894580", retriviedTargetResource.getSubPath());
assertEquals("[RepositoryEntry:23647598][CourseNode:934598]", retriviedTargetResource.getBusinessPath());
}
use of org.olat.portfolio.model.structel.EPStructuredMap in project OpenOLAT by OpenOLAT.
the class EPStructureManager method createPortfolioStructuredMap.
protected PortfolioStructureMap createPortfolioStructuredMap(PortfolioStructureMap template, Identity identity, String title, String description, OLATResourceable targetOres, String targetSubPath, String targetBusinessPath) {
EPStructuredMap el = new EPStructuredMap();
el.setStructuredMapSource((EPStructuredMapTemplate) template);
el.setStructureElSource(template.getKey());
if (template != null) {
copyOrUpdateCollectRestriction(template, el, false);
}
EPTargetResource targetResource = el.getTargetResource();
if (targetOres != null) {
targetResource.setResourceableId(targetOres.getResourceableId());
targetResource.setResourceableTypeName(targetOres.getResourceableTypeName());
}
if (StringHelper.containsNonWhitespace(targetSubPath)) {
targetResource.setSubPath(targetSubPath);
}
if (StringHelper.containsNonWhitespace(targetBusinessPath)) {
targetResource.setBusinessPath(targetBusinessPath);
}
fillStructureElement(el, title, description);
// create security group
EPStructureElementToGroupRelation ownerGroup = createBaseGroup(el, identity);
Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
relations.add(ownerGroup);
el.setGroups(relations);
return el;
}
use of org.olat.portfolio.model.structel.EPStructuredMap in project OpenOLAT by OpenOLAT.
the class EPFrontendManager method submitMap.
private void submitMap(PortfolioStructureMap map, boolean logActivity, Role by) {
// add an exception
if (!(map instanceof EPStructuredMap))
return;
EPStructuredMap submittedMap = (EPStructuredMap) map;
structureManager.submitMap(submittedMap);
EPTargetResource resource = submittedMap.getTargetResource();
OLATResourceable courseOres = resource.getOLATResourceable();
ICourse course = CourseFactory.loadCourse(courseOres);
AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
CourseNode courseNode = course.getRunStructure().getNode(resource.getSubPath());
List<Identity> owners = policyManager.getOwners(submittedMap);
for (Identity owner : owners) {
if (courseNode != null) {
// courseNode might have been deleted meanwhile
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(owner);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
if (logActivity) {
am.incrementNodeAttempts(courseNode, owner, uce, by);
} else {
am.incrementNodeAttemptsInBackground(courseNode, owner, uce);
}
RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
assessmentService.updateAssessmentEntry(owner, courseEntry, courseNode.getIdent(), referenceEntry, AssessmentEntryStatus.inReview);
}
assessmentNotificationsHandler.markPublisherNews(owner, course.getResourceableId());
log.audit("Map " + map + " from " + owner.getName() + " has been submitted.");
}
}
use of org.olat.portfolio.model.structel.EPStructuredMap in project OpenOLAT by OpenOLAT.
the class EPMultipleMapController method initOrUpdateMaps.
/**
*/
private void initOrUpdateMaps(UserRequest ureq) {
if (isLogDebugEnabled()) {
start = System.currentTimeMillis();
logDebug("start loading map overview at : ", String.valueOf(start));
}
List<PortfolioStructure> allUsersStruct = getUsersStructsToDisplay();
userMaps = new ArrayList<PortfolioStructureMap>();
if (allUsersStruct.isEmpty()) {
vC.contextPut("noMaps", true);
return;
} else
vC.contextRemove("noMaps");
// remove forward link (maybe it's not needed (last page) )
if (forwardLink != null)
vC.remove(forwardLink);
// now add paging-components if necessary and wanted
int elementCount = ePFMgr.countStructureElementsFromOthers(getIdentity(), mapOwner, ElementType.DEFAULT_MAP);
if (pagingAvailable && elementCount > ITEMS_PER_PAGE) {
vC.contextPut("showPaging", true);
int additionalPage = ((elementCount % ITEMS_PER_PAGE) > 0) ? 1 : 0;
int pageCount = (elementCount / ITEMS_PER_PAGE) + additionalPage;
List<Component> pagingLinks = new ArrayList<Component>();
for (int i = 1; i < pageCount + 1; i++) {
Link pageLink = LinkFactory.createCustomLink(PAGING_LINK_PREFIX + i, "switchPage", String.valueOf(i), Link.NONTRANSLATED, vC, this);
pageLink.setUserObject(new Integer(i));
pagingLinks.add(pageLink);
if (i == currentPageNum) {
pageLink.setEnabled(false);
}
}
vC.contextPut("pageLinks", pagingLinks);
if (currentPageNum < pageCount) {
forwardLink = LinkFactory.createCustomLink("forwardLink", "pagingFWD", "table.forward", Link.LINK, vC, this);
forwardLink.setIconRightCSS("o_icon o_icon_next_page");
}
}
// now display the maps
List<String> artAmount = new ArrayList<String>(userMaps.size());
List<Integer> childAmount = new ArrayList<Integer>(userMaps.size());
List<String> mapStyles = new ArrayList<String>(userMaps.size());
List<Date> deadLines = new ArrayList<Date>(userMaps.size());
List<String> restriStats = new ArrayList<String>(userMaps.size());
List<String> owners = new ArrayList<String>(userMaps.size());
List<String> amounts = new ArrayList<String>(userMaps.size());
int i = 1;
for (PortfolioStructure portfolioStructure : allUsersStruct) {
if (portfolioStructure.getRoot() == null) {
// only show maps
PortfolioStructureMap map = (PortfolioStructureMap) portfolioStructure;
EPSecurityCallback secCallback = EPSecurityCallbackFactory.getSecurityCallback(ureq, map, ePFMgr);
userMaps.add(map);
Link vLink = LinkFactory.createCustomLink(VIEW_LINK_PREFIX + i, "viewMap" + map.getResourceableId(), "view.map", Link.LINK, vC, this);
vLink.setUserObject(map);
vLink.setElementCssClass("o_sel_ep_open_map");
vLink.setIconRightCSS("o_icon o_icon-fw o_icon_start");
// can always try to delete your own map, but exercise only if the course was deleted
// remove as update could require hiding it
vC.remove(vC.getComponent(DELETE_LINK_PREFIX + i));
// can always try to delete your own map, but exercise only if the course was deleted
final boolean myMaps = (option.equals(EPMapRunViewOption.MY_DEFAULTS_MAPS) || option.equals(EPMapRunViewOption.MY_EXERCISES_MAPS));
boolean addDeleteLink = myMaps;
if ((map instanceof EPStructuredMap) && (((EPStructuredMap) map).getReturnDate() != null)) {
// it's a portfolio-task that was already handed in, so do not display delete-link
addDeleteLink = false;
}
if (addDeleteLink) {
final Link dLink = LinkFactory.createCustomLink(DELETE_LINK_PREFIX + i, "delMap" + map.getResourceableId(), "delete.map", Link.LINK, vC, this);
dLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
dLink.setUserObject(map);
}
Link cLink = LinkFactory.createCustomLink(COPY_LINK_PREFIX + i, "copyMap" + map.getResourceableId(), "copy.map", Link.LINK, vC, this);
cLink.setIconLeftCSS("o_icon o_icon_copy");
cLink.setUserObject(map);
// its not allowed to copy maps from a portfolio-task
if (map instanceof EPStructuredMap) {
cLink.setVisible(false);
}
// remove as update could require hiding it
vC.remove(vC.getComponent(SHARE_LINK_PREFIX + i));
if (myMaps && secCallback.canShareMap()) {
Link shareLink = LinkFactory.createCustomLink(SHARE_LINK_PREFIX + i, "shareMap" + map.getResourceableId(), "map.share", Link.LINK, vC, this);
shareLink.setIconLeftCSS("o_icon o_icon-fw o_icon_share");
shareLink.setUserObject(map);
boolean shared = ePFMgr.isMapShared(map);
if (shared || (map instanceof EPStructuredMap && ((EPStructuredMap) map).getTargetResource() != null)) {
shareLink.setCustomDisplayText(translate("map.share.shared"));
}
}
if (isLogDebugEnabled()) {
logDebug(" in loop : got share state at: ", String.valueOf(System.currentTimeMillis()));
}
// get deadline + link to course
if (map instanceof EPStructuredMap) {
EPStructuredMap structMap = (EPStructuredMap) map;
Date deadLine = structMap.getDeadLine();
deadLines.add(deadLine);
EPTargetResource resource = structMap.getTargetResource();
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(resource.getOLATResourceable(), false);
if (repoEntry != null) {
vC.contextPut("courseName" + i, StringHelper.escapeHtml(repoEntry.getDisplayname()));
String url = Settings.getServerContextPathURI();
url += "/url/RepositoryEntry/" + repoEntry.getKey() + "/CourseNode/" + resource.getSubPath();
vC.contextPut("courseLink" + i, url);
}
if (isLogDebugEnabled()) {
logDebug(" in loop : looked up course at : ", String.valueOf(System.currentTimeMillis()));
}
// get some stats about the restrictions if available
String[] stats = ePFMgr.getRestrictionStatisticsOfMap(structMap);
int toCollect = 0;
if (stats != null) {
try {
toCollect = Integer.parseInt(stats[1]) - Integer.parseInt(stats[0]);
} catch (Exception e) {
// do nothing
toCollect = 0;
}
}
if (toCollect != 0) {
restriStats.add(String.valueOf(toCollect));
} else {
restriStats.add(null);
}
if (isLogDebugEnabled()) {
logDebug(" in loop : calculated restriction statistics at : ", String.valueOf(System.currentTimeMillis()));
}
} else {
deadLines.add(null);
restriStats.add(null);
}
// show owner on shared maps
if (!secCallback.isOwner()) {
owners.add(ePFMgr.getAllOwnersAsString(map));
} else
owners.add(null);
String artCount = String.valueOf(ePFMgr.countArtefactsInMap(map));
artAmount.add(artCount);
Integer childs = ePFMgr.countStructureChildren(map);
childAmount.add(childs);
amounts.add(translate("map.contains", new String[] { childs.toString(), artCount }));
mapStyles.add(ePFMgr.getValidStyleName(map));
if (isLogDebugEnabled()) {
logDebug(" in loop : got map details (artefact-amount, child-struct-amount, style) at : ", String.valueOf(System.currentTimeMillis()));
}
i++;
}
}
vC.contextPut("owners", owners);
vC.contextPut("deadLines", deadLines);
vC.contextPut("restriStats", restriStats);
vC.contextPut("mapStyles", mapStyles);
vC.contextPut("childAmount", childAmount);
vC.contextPut("artefactAmount", artAmount);
vC.contextPut("amounts", amounts);
vC.contextPut("userMaps", userMaps);
if (isLogDebugEnabled()) {
long now = System.currentTimeMillis();
logDebug("finished processing all maps at : ", String.valueOf(now));
logDebug("Total processing time for " + (i - 1) + " maps was : ", String.valueOf(now - start));
}
}
Aggregations