Search in sources :

Example 16 with ResourceLicense

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

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 17 with ResourceLicense

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

the class MetadataBulkChangeController method formOKRights.

private void formOKRights(QuestionItemImpl itemImpl) {
    if (isEnabled(licenseWrapperCont) || isEnabled(licensorEl)) {
        ResourceLicense license = licenseService.loadOrCreateLicense(itemImpl);
        if (isEnabled(licenseWrapperCont)) {
            if (licenseEl != null && licenseEl.isOneSelected()) {
                String licenseTypeKey = licenseEl.getSelectedKey();
                LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
                license.setLicenseType(licneseType);
                String freetext = null;
                if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
                    freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
                }
                license.setFreetext(freetext);
                license = licenseService.update(license);
            }
        }
        if (isEnabled(licensorEl)) {
            license.setLicensor(licensorEl.getValue());
        }
        licenseService.update(license);
    }
}
Also used : ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 18 with ResourceLicense

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

the class RepositoryEntryImportExport method importLicense.

private void importLicense(RepositoryEntry newEntry) {
    if (!propertiesLoaded) {
        loadConfiguration();
    }
    LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
    boolean hasLicense = StringHelper.containsNonWhitespace(repositoryProperties.getLicenseTypeName());
    if (hasLicense) {
        String licenseTypeName = repositoryProperties.getLicenseTypeName();
        LicenseType licenseType = licenseService.loadLicenseTypeByName(licenseTypeName);
        if (licenseType == null) {
            licenseType = licenseService.createLicenseType(licenseTypeName);
            licenseType.setText(repositoryProperties.getLicenseText());
            licenseService.saveLicenseType(licenseType);
        }
        ResourceLicense license = licenseService.loadOrCreateLicense(newEntry.getOlatResource());
        license.setLicenseType(licenseType);
        license.setLicensor(repositoryProperties.getLicensor());
        if (licenseService.isFreetext(licenseType)) {
            license.setFreetext(repositoryProperties.getLicenseText());
        }
        licenseService.update(license);
    }
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 19 with ResourceLicense

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

the class QuestionItemDocumentFactory method createDocument.

public Document createDocument(SearchResourceContext searchResourceContext, QuestionItemFull item) {
    OlatDocument oDocument = new OlatDocument();
    oDocument.setId(item.getKey());
    oDocument.setCreatedDate(item.getCreationDate());
    oDocument.setLastChange(item.getLastModified());
    oDocument.setTitle(item.getTitle());
    oDocument.setDescription(item.getDescription());
    oDocument.setResourceUrl(getResourceUrl(item.getKey()));
    oDocument.setDocumentType(QItemDocument.TYPE);
    oDocument.setCssIcon("o_qitem_icon");
    oDocument.setParentContextType(searchResourceContext.getParentContextType());
    oDocument.setParentContextName(searchResourceContext.getParentContextName());
    // author
    StringBuilder authorSb = new StringBuilder();
    List<Identity> owners = qpoolService.getAuthors(item);
    for (Identity owner : owners) {
        User user = owner.getUser();
        authorSb.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(user.getProperty(UserConstants.LASTNAME, null)).append(" ");
    }
    oDocument.setAuthor(authorSb.toString());
    // add specific fields
    Document document = oDocument.getLuceneDocument();
    // content
    QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
    if (provider != null) {
        String content = provider.extractTextContent(item);
        if (content != null) {
            addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f);
        }
    }
    if (item.getDescription() != null) {
        addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f);
    }
    // general fields
    addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier(), 1.0f);
    addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier(), 1.0f);
    addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords(), 2.0f);
    addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage(), 2.0f);
    addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations(), 2.0f);
    addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage(), 1.0f);
    addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic(), 2.0f);
    // educational
    if (qpoolModule.isEducationalContextEnabled()) {
        if (item.getEducationalContext() != null) {
            String context = item.getEducationalContext().getLevel();
            addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f);
        }
    }
    // question
    if (item.getType() != null) {
        String itemType = item.getType().getType();
        addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f);
    }
    addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f);
    // lifecycle
    addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f);
    if (item.getQuestionStatus() != null) {
        addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f);
    }
    // rights
    ResourceLicense license = licenseService.loadLicense(item);
    if (license != null && license.getLicenseType() != null) {
        String licenseKey = String.valueOf(license.getLicenseType().getKey());
        addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey, 2.0f);
    }
    // technical
    addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor(), 2.0f);
    addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion(), 1.0f);
    addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat(), 1.0f);
    // save owners key
    for (Identity owner : owners) {
        document.add(new StringField(QItemDocument.OWNER_FIELD, owner.getKey().toString(), Field.Store.NO));
    }
    // link resources
    List<OLATResource> resources = questionItemDao.getSharedResources(item);
    for (OLATResource resource : resources) {
        document.add(new StringField(QItemDocument.SHARE_FIELD, resource.getKey().toString(), Field.Store.NO));
    }
    // need pools
    List<Pool> pools = poolDao.getPools(item);
    for (Pool pool : pools) {
        document.add(new StringField(QItemDocument.POOL_FIELD, pool.getKey().toString(), Field.Store.NO));
    }
    // need path
    if (qpoolModule.isTaxonomyEnabled()) {
        String path = item.getTaxonomicPath();
        if (StringHelper.containsNonWhitespace(path)) {
            for (StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
                String nextToken = tokenizer.nextToken();
                document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
            }
            if (item instanceof QuestionItemImpl) {
                Long key = ((QuestionItemImpl) item).getTaxonomyLevel().getKey();
                TextField field = new TextField(QItemDocument.TAXONOMIC_FIELD, key.toString(), Field.Store.YES);
                field.setBoost(3.0f);
                document.add(field);
            }
        }
    }
    return document;
}
Also used : User(org.olat.core.id.User) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) OLATResource(org.olat.resource.OLATResource) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) QItemDocument(org.olat.modules.qpool.model.QItemDocument) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) StringTokenizer(java.util.StringTokenizer) QPoolSPI(org.olat.modules.qpool.QPoolSPI) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity)

Example 20 with ResourceLicense

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

the class RepositoryEntryDocumentFactory method createDocument.

public Document createDocument(SearchResourceContext searchResourceContext, RepositoryEntry re) {
    OlatDocument oDocument = new OlatDocument();
    oDocument.setId(re.getKey());
    oDocument.setCreatedDate(re.getCreationDate());
    oDocument.setLastChange(re.getLastModified());
    oDocument.setTitle(re.getDisplayname());
    StringBuilder sb = new StringBuilder();
    String desc = re.getDescription();
    if (desc != null) {
        sb.append(desc).append(" ");
    }
    String objectives = re.getObjectives();
    if (objectives != null) {
        sb.append(objectives).append(" ");
    }
    String requirements = re.getRequirements();
    if (requirements != null) {
        sb.append(requirements);
    }
    oDocument.setDescription(sb.toString());
    oDocument.setResourceUrl(getResourceUrl(re.getKey()));
    String docType = RepositoryEntryDocument.TYPE + re.getOlatResource().getResourceableTypeName();
    oDocument.setDocumentType(docType);
    oDocument.setCssIcon(getIconCss(docType));
    oDocument.setParentContextType(searchResourceContext.getParentContextType());
    oDocument.setParentContextName(searchResourceContext.getParentContextName());
    oDocument.setAuthor(re.getAuthors());
    oDocument.setLocation(re.getLocation());
    if (licenseModule.isEnabled(licenseHandler)) {
        ResourceLicense license = licenseService.loadLicense(re.getOlatResource());
        if (license != null && license.getLicenseType() != null) {
            oDocument.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
        }
    }
    // add specific fields
    Document document = oDocument.getLuceneDocument();
    return document;
}
Also used : OlatDocument(org.olat.search.model.OlatDocument) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) RepositoryEntryDocument(org.olat.search.service.document.RepositoryEntryDocument) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Aggregations

ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)46 LicenseType (org.olat.core.commons.services.license.LicenseType)26 OLATResourceable (org.olat.core.id.OLATResourceable)16 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 LicenseService (org.olat.core.commons.services.license.LicenseService)8 HashSet (java.util.HashSet)4 Document (org.apache.lucene.document.Document)4 QuestionItemView (org.olat.modules.qpool.QuestionItemView)4 QLicense (org.olat.modules.qpool.model.QLicense)4 OLATResource (org.olat.resource.OLATResource)4 OlatDocument (org.olat.search.model.OlatDocument)4 Random (java.util.Random)2 StringTokenizer (java.util.StringTokenizer)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 DefaultResultInfos (org.olat.core.commons.persistence.DefaultResultInfos)2 License (org.olat.core.commons.services.license.License)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Identity (org.olat.core.id.Identity)2