Search in sources :

Example 11 with LicenseType

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

the class QTIMetadataConverter method addLicenseMetadataField.

private void addLicenseMetadataField(String label, QuestionItemFull fullItem, Element metadata) {
    LicenseService lService = CoreSpringFactory.getImpl(LicenseService.class);
    ResourceLicense license = lService.loadLicense(fullItem);
    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)) {
            addMetadataField(label, licenseText, metadata);
        }
    }
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 12 with LicenseType

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

the class QTIMetadataConverter method createLicense.

public void createLicense(QuestionItemImpl poolItem, String licenseText, String licensor) {
    ResourceLicense license = licenseService.loadOrCreateLicense(poolItem);
    if (StringHelper.containsNonWhitespace(licenseText)) {
        String mappedLicenseText = mapLicenseTypeName(licenseText);
        LicenseType licenseType = licenseService.loadLicenseTypeByName(mappedLicenseText);
        if (licenseType == null) {
            licenseType = licenseService.loadFreetextLicenseType();
            license.setFreetext(mappedLicenseText);
        } else {
            license.setFreetext(null);
        }
        license.setLicenseType(licenseType);
    }
    if (StringHelper.containsNonWhitespace(licensor)) {
        license.setLicensor(licensor);
    }
    licenseService.update(license);
}
Also used : ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 13 with LicenseType

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

the class AdvancedSearchInputController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    searchInput = uifactory.addTextElement("search_input", "search.title", 255, "", formLayout);
    authorQuery = uifactory.addTextElement("search_author", "form.search.label.author", 255, "", formLayout);
    titleQuery = uifactory.addTextElement("search_title", "form.search.label.title", 255, "", formLayout);
    descriptionQuery = uifactory.addTextElement("search_description", "form.search.label.description", 255, "", formLayout);
    createdDate = uifactory.addDateChooser("search_creation", "form.search.label.created.date", null, formLayout);
    modifiedDate = uifactory.addDateChooser("search_modification", "form.search.label.modified.date", null, formLayout);
    // document types
    initDocumentTypesKeysAndValues();
    String[] documentTypeKeys = new String[documentInfos.size()];
    String[] documentTypeValues = new String[documentInfos.size()];
    int j = 0;
    for (DocumentInfo documentType : documentInfos) {
        documentTypeKeys[j] = documentType.getKey();
        documentTypeValues[j++] = documentType.getValue();
    }
    documentTypeQuery = uifactory.addCheckboxesDropdown("doc_type", "form.search.label.documenttype", formLayout, documentTypeKeys, documentTypeValues);
    documentTypeQuery.setNonSelectedText(translate("drop.down.no.selection"));
    // licenses
    List<LicenseType> activeLicenseTypes = licenseService.loadLicenseTypes();
    activeLicenseTypes.removeIf(licenseService::isNoLicense);
    Collections.sort(activeLicenseTypes);
    String[] licenseTypeKeys = new String[activeLicenseTypes.size()];
    String[] licenseTypeValues = new String[activeLicenseTypes.size()];
    int counter = 0;
    for (LicenseType licenseType : activeLicenseTypes) {
        licenseTypeKeys[counter] = String.valueOf(licenseType.getKey());
        licenseTypeValues[counter] = LicenseUIFactory.translate(licenseType, getLocale());
        counter++;
    }
    licenseQuery = uifactory.addCheckboxesDropdown("search_license", "form.search.label.license", formLayout, licenseTypeKeys, licenseTypeValues);
    licenseQuery.setNonSelectedText(translate("drop.down.no.selection"));
    if (!licenseModule.isAnyHandlerEnabled()) {
        licenseQuery.setVisible(false);
    }
    // metadatas
    SearchMetadataFieldsProvider metadataProvider = (SearchMetadataFieldsProvider) CoreSpringFactory.getBean("SearchMetadataFieldsProvider");
    // The metadata key selection, e.g DC.language for doublin core language metadata
    List<String> metaDataList = metadataProvider.getAdvancedSearchableFields();
    if (metaDataList.size() > 0) {
        String[] metaDataFields = ArrayHelper.toArray(metaDataList);
        String[] metaDataFieldsTranslated = new String[metaDataFields.length];
        Translator metaTranslator = metadataProvider.createFieldsTranslator(getLocale());
        for (int i = 0; i < metaDataFields.length; i++) {
            String key = metaDataFields[i];
            metaDataFieldsTranslated[i] = key + " (" + metaTranslator.translate(key) + ")";
        }
        metadataType = uifactory.addDropdownSingleselect("metadata_type", "form.search.label.metadatatype", formLayout, metaDataFields, metaDataFieldsTranslated, null);
        metadataQuery = uifactory.addTextElement("metadata_query", null, 255, "", formLayout);
    }
    contextSelection = uifactory.addRadiosHorizontal("context", "form.search.label.context", formLayout, new String[0], new String[0]);
    searchButton = uifactory.addFormLink("search", formLayout, Link.BUTTON_SMALL);
    searchButton.setEnabled(true);
}
Also used : Translator(org.olat.core.gui.translator.Translator) SearchMetadataFieldsProvider(org.olat.search.service.SearchMetadataFieldsProvider) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 14 with LicenseType

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

the class MetadataBulkChangeController method updateLicenseVisibility.

void updateLicenseVisibility() {
    boolean freetextSelected = false;
    if (licenseEl != null && licenseEl.isOneSelected()) {
        String selectedKey = licenseEl.getSelectedKey();
        LicenseType licenseType = licenseService.loadLicenseTypeByKey(selectedKey);
        freetextSelected = licenseService.isFreetext(licenseType);
    }
    licenseFreetextEl.setVisible(freetextSelected);
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 15 with LicenseType

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

the class AuthorSearchController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer leftContainer = FormLayoutContainer.createDefaultFormLayout("left_1", getTranslator());
    leftContainer.setRootForm(mainForm);
    formLayout.add(leftContainer);
    // LEFT part of form
    displayName = uifactory.addTextElement("cif_displayname", "cif.displayname", 255, "", leftContainer);
    displayName.setElementCssClass("o_sel_repo_search_displayname");
    displayName.setFocus(true);
    id = uifactory.addTextElement("cif_id", "cif.id", 128, "", leftContainer);
    id.setElementCssClass("o_sel_repo_search_id");
    author = uifactory.addTextElement("cif_author", "cif.author", 255, "", leftContainer);
    author.setElementCssClass("o_sel_repo_search_author");
    description = uifactory.addTextElement("cif_description", "cif.description", 255, "", leftContainer);
    description.setElementCssClass("o_sel_repo_search_description");
    // RIGHT part of form
    FormLayoutContainer rightContainer = FormLayoutContainer.createDefaultFormLayout("right_1", getTranslator());
    rightContainer.setRootForm(mainForm);
    formLayout.add(rightContainer);
    List<String> typeList = getResources();
    typeKeys = typeList.toArray(new String[typeList.size()]);
    String[] typeValues = getTranslatedResources(typeList);
    String[] typeCSS = getResourcesCSS(typeList);
    types = uifactory.addCheckboxesDropdown("cif.type", "cif.type", rightContainer, typeKeys, typeValues, null, typeCSS);
    types.setNonSelectedText(translate("table.showall"));
    if (licenseModule.isEnabled(licenseHandler)) {
        List<LicenseType> activeLicenseTypes = licenseService.loadActiveLicenseTypes(licenseHandler);
        Collections.sort(activeLicenseTypes);
        String[] licenseTypeKeys = new String[activeLicenseTypes.size()];
        String[] licenseTypeValues = new String[activeLicenseTypes.size()];
        int counter = 0;
        for (LicenseType licenseType : activeLicenseTypes) {
            licenseTypeKeys[counter] = String.valueOf(licenseType.getKey());
            licenseTypeValues[counter] = LicenseUIFactory.translate(licenseType, getLocale());
            counter++;
        }
        licenseEl = uifactory.addCheckboxesDropdown("cif.license", "cif.license", rightContainer, licenseTypeKeys, licenseTypeValues, null, null);
        licenseEl.setNonSelectedText(translate("table.showall"));
    }
    String[] statusValues = new String[] { translate("cif.resources.status.all"), translate("cif.resources.status.active"), translate("cif.resources.status.closed") };
    closedEl = uifactory.addRadiosHorizontal("cif_status", "cif.resources.status", rightContainer, statusKeys, statusValues);
    closedEl.select(statusKeys[1], true);
    String[] usageValues = new String[] { translate("cif.owned.resources.usage.all"), translate("cif.owned.resources.usage.used"), translate("cif.owned.resources.usage.notUsed") };
    resourceUsageEl = uifactory.addRadiosHorizontal("cif_used", "cif.owned.resources.usage", rightContainer, usageKeys, usageValues);
    resourceUsageEl.select(usageKeys[0], true);
    ownedResourcesOnlyEl = uifactory.addCheckboxesHorizontal("cif_my", "cif.owned.resources.only", rightContainer, keys, new String[] { "" });
    ownedResourcesOnlyEl.select(keys[0], true);
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    searchButton = uifactory.addFormLink("search", buttonLayout, Link.BUTTON);
    searchButton.setCustomEnabledLinkCSS("btn btn-primary");
    if (cancelAllowed) {
        uifactory.addFormCancelButton("quick.search", buttonLayout, ureq, getWindowControl());
    }
}
Also used : FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) 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