use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPStructureToArtefactTest method moveUpArtefact.
@Test
public void moveUpArtefact() {
// save parent and 5 children
PortfolioStructure structureEl = epFrontendManager.createAndPersistPortfolioStructureElement(null, "move-up-structure-el-1", "move-up-structure-element");
List<AbstractArtefact> children = new ArrayList<AbstractArtefact>();
for (int i = 0; i < 5; i++) {
AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
artefact.setTitle("move-up-artefact-1-" + i);
artefact = epFrontendManager.updateArtefact(artefact);
epFrontendManager.addArtefactToStructure(ident1, artefact, structureEl);
children.add(artefact);
}
dbInstance.commitAndCloseSession();
// move up the first place
epStructureManager.moveUp(structureEl, children.get(0));
dbInstance.commitAndCloseSession();
// check that all is the same
List<AbstractArtefact> persistedChildren1 = epFrontendManager.getArtefacts(structureEl);
assertNotNull(persistedChildren1);
assertEquals(5, persistedChildren1.size());
assertEquals(children.get(0).getKey(), persistedChildren1.get(0).getKey());
assertEquals(children.get(1).getKey(), persistedChildren1.get(1).getKey());
assertEquals(children.get(2).getKey(), persistedChildren1.get(2).getKey());
assertEquals(children.get(3).getKey(), persistedChildren1.get(3).getKey());
assertEquals(children.get(4).getKey(), persistedChildren1.get(4).getKey());
dbInstance.commitAndCloseSession();
// move the second to the first place
epStructureManager.moveUp(structureEl, children.get(1));
dbInstance.commitAndCloseSession();
// check that all is the same
List<AbstractArtefact> persistedChildren2 = epFrontendManager.getArtefacts(structureEl);
assertNotNull(persistedChildren2);
assertEquals(5, persistedChildren2.size());
assertEquals(children.get(1).getKey(), persistedChildren2.get(0).getKey());
assertEquals(children.get(0).getKey(), persistedChildren2.get(1).getKey());
assertEquals(children.get(2).getKey(), persistedChildren2.get(2).getKey());
assertEquals(children.get(3).getKey(), persistedChildren2.get(3).getKey());
assertEquals(children.get(4).getKey(), persistedChildren2.get(4).getKey());
dbInstance.commitAndCloseSession();
// move up the last
epStructureManager.moveUp(structureEl, children.get(4));
dbInstance.commitAndCloseSession();
// check that all is the same
List<AbstractArtefact> persistedChildren3 = epFrontendManager.getArtefacts(structureEl);
assertNotNull(persistedChildren3);
assertEquals(5, persistedChildren3.size());
assertEquals(children.get(1).getKey(), persistedChildren3.get(0).getKey());
assertEquals(children.get(0).getKey(), persistedChildren3.get(1).getKey());
assertEquals(children.get(2).getKey(), persistedChildren3.get(2).getKey());
assertEquals(children.get(4).getKey(), persistedChildren3.get(3).getKey());
assertEquals(children.get(3).getKey(), persistedChildren3.get(4).getKey());
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPStructureManagerTest method testGetReferencedMapsForArtefact.
@Test
public void testGetReferencedMapsForArtefact() {
PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el", "structure-element");
dbInstance.commitAndCloseSession();
AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "Forum");
epFrontendManager.addArtefactToStructure(ident1, artefact, el);
dbInstance.commitAndCloseSession();
// get the referenced maps
List<PortfolioStructure> mapList = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList.get(0)));
dbInstance.commitAndCloseSession();
// make the test more complex
// reload the structure element
el = epFrontendManager.loadPortfolioStructureByKey(el.getKey());
// add artefact to substructure (page) and check for the same map
PortfolioStructure childEl = epFrontendManager.createAndPersistPortfolioStructureElement(el, "child-structure-el", "child-structure-element");
el = epFrontendManager.removeArtefactFromStructure(artefact, el);
epFrontendManager.addArtefactToStructure(ident1, artefact, childEl);
dbInstance.commitAndCloseSession();
// get the referenced maps
List<PortfolioStructure> mapList2 = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertTrue(((Persistable) el).equalsByPersistableKey((Persistable) mapList2.get(0)));
dbInstance.commitAndCloseSession();
// add artefact to 3 maps and check to get all of them
PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-2", "structure-element-2");
epFrontendManager.addArtefactToStructure(ident1, artefact, el2);
PortfolioStructure el3 = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-3", "structure-element-3");
epFrontendManager.addArtefactToStructure(ident1, artefact, el3);
List<PortfolioStructure> mapList3 = epFrontendManager.getReferencedMapsForArtefact(artefact);
assertEquals(3, mapList3.size());
boolean found = false;
for (PortfolioStructure mapValue : mapList3) {
if (((Persistable) mapValue).equalsByPersistableKey((Persistable) el)) {
found = true;
}
}
assertTrue(found);
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPStructureManager method getRestrictionStatistics.
protected Integer[] getRestrictionStatistics(PortfolioStructure structure) {
if (structure instanceof EPStructureElement) {
EPStructureElement structEl = (EPStructureElement) structure;
structEl = (EPStructureElement) reloadPortfolioStructure(structEl);
final List<CollectRestriction> restrictions = structEl.getCollectRestrictions();
if (restrictions != null && !restrictions.isEmpty()) {
int todo = 0;
int done = 0;
List<AbstractArtefact> artefacts = getArtefacts(structEl);
for (CollectRestriction cR : restrictions) {
if (RestrictionsConstants.MIN.equals(cR.getRestriction()) || RestrictionsConstants.EQUAL.equals(cR.getRestriction())) {
todo += cR.getAmount();
int actualCRCount = countRestrictionType(artefacts, cR);
done += actualCRCount;
}
}
return new Integer[] { done, todo };
}
}
return null;
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPArtefactManager method filterArtefactsByTags.
/**
* @param allArtefacts
* @param filterSettings (containing tags to filter for or boolean if filter should keep only artefacts without a tag)
* @param collect the tags found in the filtered artefacts
* @return filtered artefact list
*/
private void filterArtefactsByTags(List<AbstractArtefact> artefacts, EPFilterSettings filterSettings, Set<String> cloud) {
List<String> tags = filterSettings.getTagFilter();
// either search for artefacts with given tags, or such with no one!
List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
if (tags != null && tags.size() != 0) {
// allowed!
for (AbstractArtefact artefact : artefacts) {
List<String> artefactTags = getArtefactTags(artefact);
if (!artefactTags.containsAll(tags)) {
toRemove.add(artefact);
} else if (cloud != null) {
cloud.addAll(artefactTags);
}
}
artefacts.removeAll(toRemove);
} else if (filterSettings.isNoTagFilterSet()) {
for (AbstractArtefact artefact : artefacts) {
if (!getArtefactTags(artefact).isEmpty()) {
toRemove.add(artefact);
}
}
artefacts.removeAll(toRemove);
}
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project openolat by klemens.
the class EPArtefactManager method createAndPersistArtefact.
/**
* Create and persist an artefact of the given type
*
* @param type
* @return The persisted artefact
*/
protected AbstractArtefact createAndPersistArtefact(Identity identity, String type) {
EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(type);
if (handler != null && handler.isEnabled()) {
AbstractArtefact artefact = handler.createArtefact();
artefact.setAuthor(identity);
dbInstance.saveObject(artefact);
saveArtefactFulltextContent(artefact);
return artefact;
} else {
return null;
}
}
Aggregations