Search in sources :

Example 81 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project openolat by klemens.

the class RepositoryEditDescriptionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        String licensor = null;
        String freetext = null;
        if (licensorEl != null && licensorEl.isVisible()) {
            licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
            freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
        }
        license.setLicensor(licensor);
        license.setFreetext(freetext);
        license = licenseService.update(license);
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    File uploadedImage = fileUpload.getUploadFile();
    if (uploadedImage != null && uploadedImage.exists()) {
        VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
        VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
        // give it it's real name and extension
        VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
        boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
        if (!ok) {
            showWarning("cif.error.image");
        } else {
            VFSLeaf image = repositoryManager.getImage(repositoryEntry);
            if (image instanceof LocalFileImpl) {
                fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
            }
        }
        container.delete();
    }
    File uploadedMovie = movieUpload.getUploadFile();
    if (uploadedMovie != null && uploadedMovie.exists()) {
        VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
        VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
        if (newFile == null) {
            showWarning("cif.error.movie");
        } else {
            String filename = movieUpload.getUploadFileName();
            String extension = FileUtils.getFileSuffix(filename);
            newFile.rename(repositoryEntry.getKey() + "." + extension);
        }
    }
    String displayname = displayName.getValue().trim();
    repositoryEntry.setDisplayname(displayname);
    String mainLanguage = language.getValue();
    if (StringHelper.containsNonWhitespace(mainLanguage)) {
        repositoryEntry.setMainLanguage(mainLanguage);
    } else {
        repositoryEntry.setMainLanguage(null);
    }
    if (dateTypesEl != null) {
        String type = "none";
        if (dateTypesEl.isOneSelected()) {
            type = dateTypesEl.getSelectedKey();
        }
        if ("none".equals(type)) {
            repositoryEntry.setLifecycle(null);
        } else if ("public".equals(type)) {
            String key = publicDatesEl.getSelectedKey();
            if (StringHelper.isLong(key)) {
                Long cycleKey = Long.parseLong(key);
                RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
                repositoryEntry.setLifecycle(cycle);
            }
        } else if ("private".equals(type)) {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
            if (cycle == null || !cycle.isPrivateCycle()) {
                String softKey = "lf_" + repositoryEntry.getSoftkey();
                cycle = lifecycleDao.create(displayname, softKey, true, start, end);
            } else {
                cycle.setValidFrom(start);
                cycle.setValidTo(end);
                cycle = lifecycleDao.updateLifecycle(cycle);
            }
            repositoryEntry.setLifecycle(cycle);
        }
    }
    if (externalRef != null && externalRef.isEnabled()) {
        String ref = externalRef.getValue().trim();
        repositoryEntry.setExternalRef(ref);
    }
    String desc = description.getValue().trim();
    repositoryEntry.setDescription(desc);
    if (authors != null) {
        String auth = authors.getValue().trim();
        repositoryEntry.setAuthors(auth);
    }
    if (objectives != null) {
        String obj = objectives.getValue().trim();
        repositoryEntry.setObjectives(obj);
    }
    if (requirements != null) {
        String req = requirements.getValue().trim();
        repositoryEntry.setRequirements(req);
    }
    if (credits != null) {
        String cred = credits.getValue().trim();
        repositoryEntry.setCredits(cred);
    }
    if (expenditureOfWork != null) {
        String exp = expenditureOfWork.getValue().trim();
        repositoryEntry.setExpenditureOfWork(exp);
    }
    if (location != null) {
        String loc = location.getValue().trim();
        repositoryEntry.setLocation(loc);
    }
    repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
    if (repositoryEntry == null) {
        showWarning("repositoryentry.not.existing");
        fireEvent(ureq, Event.CLOSE_EVENT);
    } else {
        fireEvent(ureq, Event.CHANGED_EVENT);
        MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date) LicenseType(org.olat.core.commons.services.license.LicenseType) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 82 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project openolat by klemens.

the class OLATUpgrade_12_4_0 method saveLicense.

private void saveLicense(QuestionItemImpl item) {
    QLicense qlicense = item.getLicense();
    String name = mapLicenseTypeName(qlicense.getLicenseKey());
    LicenseType licenseType = licenseService.loadLicenseTypeByName(name);
    ResourceLicense license = licenseService.loadOrCreateLicense(item);
    license.setLicenseType(licenseType);
    license.setFreetext(qlicense.getLicenseText());
    license.setLicensor(item.getCreator());
    licenseService.update(license);
}
Also used : QLicense(org.olat.modules.qpool.model.QLicense) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 83 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project openolat by klemens.

the class OLATUpgrade_12_4_0 method migrateQPoolLicenseTypes.

private void migrateQPoolLicenseTypes() {
    List<QLicense> qpoolLicenseTypes = getQpoolLicenseTypes();
    for (QLicense qlicense : qpoolLicenseTypes) {
        String licenseKey = qlicense.getLicenseKey();
        if (StringHelper.containsNonWhitespace(licenseKey) && isNotFreetextLicense(licenseKey)) {
            String licenseTypeName = mapLicenseTypeName(licenseKey);
            if (isLicenseTypeMissing(licenseTypeName)) {
                LicenseType licenseType = licenseService.createLicenseType(licenseTypeName);
                licenseService.saveLicenseType(licenseType);
                log.info("LicenseType created: " + licenseTypeName);
            } else {
                log.info("LicenseType not created (exists): " + licenseTypeName);
            }
            LicenseType licenseType = licenseService.loadLicenseTypeByName(licenseTypeName);
            licenseService.activate(licenseHandler, licenseType);
        }
    }
}
Also used : QLicense(org.olat.modules.qpool.model.QLicense) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 84 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project openolat by klemens.

the class StandardResultController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer formLayoutCont = (FormLayoutContainer) formLayout;
        formLayoutCont.contextPut("result", document);
        formLayoutCont.contextPut("id", hashCode());
        formLayoutCont.contextPut("formatter", Formatter.getInstance(getLocale()));
        String author = document.getAuthor();
        if (StringHelper.containsNonWhitespace(author)) {
            List<IdentityShort> identities = BaseSecurityManager.getInstance().findShortIdentitiesByName(Collections.singleton(author));
            if (identities.size() > 0) {
                author = UserManager.getInstance().getUserDisplayName(identities.get(0));
            }
        }
        formLayoutCont.contextPut("author", author);
        if (StringHelper.containsNonWhitespace(document.getLicenseTypeKey())) {
            LicenseType licenseType = licenseService.loadLicenseTypeByKey(document.getLicenseTypeKey());
            if (!licenseService.isNoLicense(licenseType)) {
                formLayoutCont.contextPut("licenseIcon", LicenseUIFactory.getCssOrDefault(licenseType));
                formLayoutCont.contextPut("license", LicenseUIFactory.translate(licenseType, getLocale()));
            }
        }
    }
    String icon = document.getCssIcon();
    if (!StringHelper.containsNonWhitespace(icon)) {
        icon = "o_sp_icon";
    }
    String label = document.getTitle();
    if (label != null) {
        label = label.trim();
    }
    if (label.length() > 128) {
        label = FilterFactory.getHtmlTagsFilter().filter(label);
        label = Formatter.truncate(label, 128);
    }
    label = StringHelper.escapeHtml(label);
    docLink = uifactory.addFormLink("open_doc", label, label, formLayout, Link.NONTRANSLATED);
    docLink.setIconLeftCSS("o_icon o_icon-fw " + icon);
    String highlightLabel = document.getHighlightTitle();
    if (!StringHelper.containsNonWhitespace(highlightLabel)) {
        highlightLabel = label;
    }
    docHighlightLink = uifactory.addFormLink("open_doc_highlight", highlightLabel, highlightLabel, formLayout, Link.NONTRANSLATED);
    docHighlightLink.setIconLeftCSS("o_icon o_icon-fw " + icon);
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 85 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project openolat by klemens.

the class RightsMetadataEditController method updateLicenseText.

private void updateLicenseText() {
    if (licenseTextEl != null && licenseEl != null && licenseEl.isOneSelected()) {
        String selectedKey = licenseEl.getSelectedKey();
        LicenseType licenseType = licenseService.loadLicenseTypeByKey(selectedKey);
        licenseTextEl.setValue(getLicenseText(licenseType));
        boolean noLicenseSelected = licenseService.isNoLicense(licenseType);
        boolean freetextSelected = licenseService.isFreetext(licenseType);
        boolean licenseTextVisible = !noLicenseSelected && !freetextSelected;
        licenseTextEl.setVisible(licenseTextVisible);
        ;
    }
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType)

Aggregations

LicenseType (org.olat.core.commons.services.license.LicenseType)106 Test (org.junit.Test)40 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)28 LicenseService (org.olat.core.commons.services.license.LicenseService)14 License (org.olat.core.commons.services.license.License)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 File (java.io.File)6 ArrayList (java.util.ArrayList)4 LicenseHandler (org.olat.core.commons.services.license.LicenseHandler)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 QLicense (org.olat.modules.qpool.model.QLicense)4 Date (java.util.Date)2 Random (java.util.Random)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 LicenseImpl (org.olat.core.commons.services.license.model.LicenseImpl)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 Translator (org.olat.core.gui.translator.Translator)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2