Search in sources :

Example 16 with LicenseType

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

the class RightsMetadataEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.UPDATE_QUESTION_ITEM_METADATA);
        builder.withBefore(itemImpl);
        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());
        }
        item = qpoolService.updateItem(item);
        builder.withAfter(itemImpl);
        qpoolService.persist(builder.create());
        fireEvent(ureq, new QItemEdited(item));
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QItemEdited(org.olat.modules.qpool.ui.events.QItemEdited) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 17 with LicenseType

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

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)

Example 18 with LicenseType

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

the class ManifestMetadataBuilder method appendMetadataFrom.

/**
 * This method will add new metadata to the current ones.
 *
 * @param item
 * @param locale
 */
public void appendMetadataFrom(QuestionItem item, AssessmentItem assessmentItem, Locale locale) {
    String lang = item.getLanguage();
    if (!StringHelper.containsNonWhitespace(lang)) {
        lang = locale.getLanguage();
    }
    // LOM : General
    if (StringHelper.containsNonWhitespace(item.getTitle())) {
        setTitle(item.getTitle(), lang);
    }
    if (StringHelper.containsNonWhitespace(item.getCoverage())) {
        setCoverage(item.getCoverage(), lang);
    }
    if (StringHelper.containsNonWhitespace(item.getKeywords())) {
        setGeneralKeywords(item.getKeywords(), lang);
    }
    if (StringHelper.containsNonWhitespace(item.getDescription())) {
        setDescription(item.getDescription(), lang);
    }
    // LOM : Technical
    setTechnicalFormat(ManifestBuilder.ASSESSMENTITEM_MIMETYPE);
    // LOM : Educational
    if (StringHelper.containsNonWhitespace(item.getEducationalContextLevel())) {
        setEducationalContext(item.getEducationalContextLevel(), lang);
    }
    if (StringHelper.containsNonWhitespace(item.getEducationalLearningTime())) {
        setEducationalLearningTime(item.getEducationalLearningTime());
    }
    if (item.getLanguage() != null) {
        setLanguage(item.getLanguage(), lang);
    }
    // LOM : Lifecycle
    if (StringHelper.containsNonWhitespace(item.getItemVersion())) {
        setLifecycleVersion(item.getItemVersion());
    }
    // LOM : Rights
    LicenseService lService = CoreSpringFactory.getImpl(LicenseService.class);
    ResourceLicense license = lService.loadLicense(item);
    if (license != null) {
        String licenseText = null;
        LicenseType licenseType = license.getLicenseType();
        if (lService.isFreetext(licenseType)) {
            licenseText = license.getFreetext();
        } else if (!lService.isNoLicense(licenseType)) {
            licenseText = license.getLicenseType().getName();
        }
        if (StringHelper.containsNonWhitespace(licenseText)) {
            setLicense(licenseText);
        }
        setOpenOLATMetadataCreator(license.getLicensor());
    }
    // LOM : classification
    if (StringHelper.containsNonWhitespace(item.getTaxonomicPath())) {
        setClassificationTaxonomy(item.getTaxonomicPath(), lang);
    }
    // QTI 2.1
    setQtiMetadataTool(item.getEditor(), null, item.getEditorVersion());
    if (assessmentItem != null) {
        List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
        List<String> interactionNames = new ArrayList<>(interactions.size());
        for (Interaction interaction : interactions) {
            interactionNames.add(interaction.getQtiClassName());
        }
        setQtiMetadataInteractionTypes(interactionNames);
    }
    // OpenOLAT
    if (item.getType() != null) {
        setOpenOLATMetadataQuestionType(item.getType().getType());
    } else {
        setOpenOLATMetadataQuestionType(null);
    }
    setOpenOLATMetadataIdentifier(item.getIdentifier());
    setOpenOLATMetadataDifficulty(item.getDifficulty());
    setOpenOLATMetadataDiscriminationIndex(item.getDifferentiation());
    setOpenOLATMetadataDistractors(item.getNumOfAnswerAlternatives());
    setOpenOLATMetadataStandardDeviation(item.getStdevDifficulty());
    setOpenOLATMetadataUsage(item.getUsage());
    setOpenOLATMetadataAssessmentType(item.getAssessmentType());
    setOpenOLATMetadataTopic(item.getTopic());
    setOpenOLATMetadataAdditionalInformations(item.getAdditionalInformations());
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ArrayList(java.util.ArrayList) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 19 with LicenseType

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

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 20 with LicenseType

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

the class MetaInfoFactoryTest method shouldCreateNonExistingLicenseType.

@Test
public void shouldCreateNonExistingLicenseType() {
    String typeName = "name";
    LicenseType licenseType = licenseService.createLicenseType(typeName);
    licenseType = licenseService.saveLicenseType(licenseType);
    dbInstance.commitAndCloseSession();
    String licensor = "licensor";
    String name = "new";
    String text = "text";
    File file = new File("");
    MetaInfo meta = new MetaInfoFileImpl(file);
    meta.setLicenseTypeName(name);
    meta.setLicensor(licensor);
    meta.setLicenseText(text);
    License license = metaInfoFactory.getLicense(meta);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    LicenseType loadedLicenseType = license.getLicenseType();
    assertThat(loadedLicenseType.getName()).isEqualTo(name);
    assertThat(loadedLicenseType.getText()).isEqualTo(text);
    LicenseType createdLicenseType = licenseService.loadLicenseTypeByName(name);
    assertThat(createdLicenseType).isNotNull();
}
Also used : License(org.olat.core.commons.services.license.License) File(java.io.File) LicenseType(org.olat.core.commons.services.license.LicenseType) Test(org.junit.Test)

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