use of org.olat.portfolio.model.restriction.CollectRestriction 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.restriction.CollectRestriction in project openolat by klemens.
the class EPStructureManager method addCollectRestriction.
/**
* Add or update a restriction to the collection of artefacts for a given structure element
* @param structure
* @param artefactType
* @param restriction
* @param amount
*/
public void addCollectRestriction(PortfolioStructure structure, String artefactType, String restriction, int amount) {
if (structure == null)
throw new NullPointerException("Structure cannot be null");
EPStructureElement structEl = (EPStructureElement) structure;
List<CollectRestriction> restrictions = structEl.getCollectRestrictions();
CollectRestriction cr = new CollectRestriction();
cr.setArtefactType(artefactType);
cr.setRestriction(restriction);
cr.setAmount(amount);
restrictions.add(cr);
}
use of org.olat.portfolio.model.restriction.CollectRestriction in project openolat by klemens.
the class EPStructureElementsController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(UserRequest ureq) {
flc.contextPut("structElements", structElements);
tableCtrls = new ArrayList<Controller>();
addBtnCtrls = new ArrayList<Controller>();
int i = 1;
removeComponents();
for (PortfolioStructure portStruct : structElements) {
if (secCallback.isRestrictionsEnabled()) {
List<CollectRestriction> restrictions = portStruct.getCollectRestrictions();
if (!restrictions.isEmpty()) {
boolean check = ePFMgr.checkCollectRestriction(portStruct);
EPCollectRestrictionResultController resultCtrl = new EPCollectRestrictionResultController(ureq, getWindowControl());
resultCtrl.setMessage(portStruct.getCollectRestrictions(), check);
flc.put("checkResults" + i, resultCtrl.getInitialComponent());
listenTo(resultCtrl);
}
}
// get artefacts for this structure
List<AbstractArtefact> artefacts = ePFMgr.getArtefacts(portStruct);
if (artefacts.size() != 0) {
EPMultiArtefactsController artefactCtrl = EPUIFactory.getConfigDependentArtefactsControllerForStructure(ureq, getWindowControl(), artefacts, portStruct, secCallback);
flc.put("artefacts" + i, artefactCtrl.getInitialComponent());
listenTo(artefactCtrl);
tableCtrls.add(artefactCtrl);
}
if (!parentMapClosed && secCallback.canAddArtefact()) {
// get an addElement-button for each structure
EPAddElementsController addButton = new EPAddElementsController(ureq, getWindowControl(), portStruct);
listenTo(addButton);
addButton.setShowLink(EPAddElementsController.ADD_ARTEFACT);
flc.put("addButton" + i, addButton.getInitialComponent());
addBtnCtrls.add(addButton);
}
i++;
}
if (i != maxStructAmount)
maxStructAmount = i;
}
use of org.olat.portfolio.model.restriction.CollectRestriction in project openolat by klemens.
the class EPStructureDetailsController method formOK.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
*/
@Override
protected void formOK(final UserRequest ureq) {
editStructure = ePFMgr.reloadPortfolioStructure(editStructure);
editStructure.setTitle(titleEl.getValue());
editStructure.setDescription(descriptionEl.getValue());
editStructure.setArtefactRepresentationMode(viewRadio.getSelectedKey());
if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
clearErrors();
editStructure.getCollectRestrictions().clear();
setCollectRestrictions();
for (final SingleSelection restrictionElement : restrictionElements) {
final CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
if (restriction.isValid()) {
final CollectRestriction cr = new CollectRestriction(restriction);
editStructure.getCollectRestrictions().add(cr);
}
}
}
ePFMgr.savePortfolioStructure(editStructure);
fireEvent(ureq, new EPStructureEvent(EPStructureEvent.CHANGE, editStructure));
}
use of org.olat.portfolio.model.restriction.CollectRestriction in project openolat by klemens.
the class EPStructureDetailsController method validateFormLogic.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest)
*/
@Override
protected boolean validateFormLogic(UserRequest ureq) {
if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
setCollectRestrictions();
clearErrors();
ArrayList<String> usedTypes = new ArrayList<String>();
int i = 0;
boolean hasError = false;
for (SingleSelection restrictionElement : restrictionElements) {
CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
if (usedTypes.contains(restriction.getArtefactType())) {
StaticTextElement thisErrorEl = errorElements.get(i);
thisErrorEl.setVisible(true);
thisErrorEl.setValue(translate("collect.restriction.duplicate.type"));
hasError = true;
}
usedTypes.add(restriction.getArtefactType());
boolean hasRestriction = StringHelper.containsNonWhitespace(restriction.getRestriction());
boolean hasArtType = StringHelper.containsNonWhitespace(restriction.getArtefactType());
boolean hasAmount = restriction.getAmount() > 0;
boolean isValid = restriction.isValid();
if (!isValid && (hasRestriction || hasArtType || hasAmount)) {
StaticTextElement thisErrorEl = errorElements.get(i);
thisErrorEl.setVisible(true);
thisErrorEl.setValue(translate("collect.restriction.incomplete"));
hasError = true;
}
i++;
}
return !hasError;
}
return true;
}
Aggregations