Search in sources :

Example 6 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project openolat by klemens.

the class ConfirmDeletePermanentlyController method doCompleteDelete.

private void doCompleteDelete(UserRequest ureq) {
    List<ErrorList> errorList = new ArrayList<>();
    boolean allOk = deleteEntries(ureq, rows, errorList);
    if (allOk && deleteReferencesEl.isVisible() && deleteReferencesEl.isEnabled() && deleteReferencesEl.isOneSelected() && deleteReferencesEl.isSelected(0)) {
        Map<Long, ReferenceInfos> referencesMap = new HashMap<>();
        for (ReferenceInfos reference : references) {
            referencesMap.put(reference.getEntry().getKey(), reference);
        }
        Collection<String> selectedKeys = referencesEl.getSelectedKeys();
        List<RepositoryEntry> referencesToDelete = new ArrayList<>(selectedKeys.size());
        for (String selectedRefKey : selectedKeys) {
            Long key = new Long(selectedRefKey);
            ReferenceInfos refInfos = referencesMap.get(key);
            if (refInfos != null && refInfos.isOrphan() && refInfos.isOwner() && !refInfos.isManaged()) {
                referencesToDelete.add(referencesMap.get(key).getEntry());
            }
        }
        allOk &= deleteEntries(ureq, referencesToDelete, errorList);
    }
    if (allOk) {
        showInfo("info.entry.deleted");
    } else {
        List<String> msgs = new ArrayList<>();
        for (ErrorList error : errorList) {
            if (StringHelper.containsNonWhitespace(error.getFirstError())) {
                msgs.add(error.getFirstError());
            }
        }
        if (msgs.size() == 1) {
            getWindowControl().setWarning(msgs.get(0));
        } else if (msgs.size() > 1) {
            StringBuilder sb = new StringBuilder();
            sb.append("<ul>");
            for (String msg : msgs) {
                sb.append("<li>").append(msg).append("</li>");
            }
            sb.append("</ul>");
            getWindowControl().setWarning(sb.toString());
        } else {
            showWarning("info.could.not.delete.entry");
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) ErrorList(org.olat.repository.ErrorList) ReferenceInfos(org.olat.resource.references.ReferenceInfos)

Aggregations

ReferenceInfos (org.olat.resource.references.ReferenceInfos)6 RepositoryEntry (org.olat.repository.RepositoryEntry)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 ErrorList (org.olat.repository.ErrorList)2