Search in sources :

Example 1 with SearchMetadataFieldsProvider

use of org.olat.search.service.SearchMetadataFieldsProvider 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 2 with SearchMetadataFieldsProvider

use of org.olat.search.service.SearchMetadataFieldsProvider in project openolat by klemens.

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)

Aggregations

LicenseType (org.olat.core.commons.services.license.LicenseType)2 Translator (org.olat.core.gui.translator.Translator)2 SearchMetadataFieldsProvider (org.olat.search.service.SearchMetadataFieldsProvider)2