Search in sources :

Example 6 with ResourceLicense

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

the class AuthoringEntryDataSource method processViewModel.

private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) {
    Set<String> newNames = new HashSet<>();
    List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
    for (RepositoryEntryAuthorView entry : repoEntries) {
        if (entry.isOfferAvailable()) {
            resourcesWithAC.add(entry.getOlatResource());
        }
        final String author = entry.getAuthor();
        if (StringHelper.containsNonWhitespace(author)) {
            newNames.add(author);
        }
    }
    Map<String, String> fullNames = userManager.getUserDisplayNamesByUserName(newNames);
    List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
    Collection<OLATResourceable> resources = repoEntries.stream().map(RepositoryEntryAuthorView::getOlatResource).collect(Collectors.toList());
    List<ResourceLicense> licenses = licenseService.loadLicenses(resources);
    List<AuthoringEntryRow> items = new ArrayList<>();
    for (RepositoryEntryAuthorView entry : repoEntries) {
        String fullname = fullNames.get(entry.getAuthor());
        if (fullname == null) {
            fullname = entry.getAuthor();
        }
        AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname);
        // bookmark
        row.setMarked(entry.isMarked());
        // access control
        List<PriceMethod> types = new ArrayList<>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
        } else {
            // collect access control method icons
            OLATResource resource = entry.getOlatResource();
            for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
                if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
                    for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
                        String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
                        String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
                        AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
                        String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        // license
        for (ResourceLicense license : licenses) {
            OLATResource resource = entry.getOlatResource();
            if (license.getResId().equals(resource.getResourceableId()) && license.getResName().equals(resource.getResourceableTypeName())) {
                row.setLicense(license);
            }
        }
        uifactory.forgeLinks(row);
        items.add(row);
    }
    return items;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) PriceMethod(org.olat.repository.ui.PriceMethod) RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle) HashSet(java.util.HashSet)

Example 7 with ResourceLicense

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

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

use of org.olat.core.commons.services.license.ResourceLicense 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 9 with ResourceLicense

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

the class OLATUpgrade_12_4_0 method saveFreetextLicense.

private void saveFreetextLicense(QuestionItemImpl item) {
    QLicense qlicense = item.getLicense();
    ResourceLicense license = licenseService.loadOrCreateLicense(item);
    license.setLicenseType(getFreetextLicenseType());
    license.setFreetext(qlicense.getLicenseText());
    license.setLicensor(item.getCreator());
    licenseService.update(license);
}
Also used : QLicense(org.olat.modules.qpool.model.QLicense) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 10 with ResourceLicense

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

the class RepositoryEntryImportExport method addLicenseInformations.

private void addLicenseInformations(RepositoryEntryImport imp, RepositoryEntry re) {
    LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
    ResourceLicense license = licenseService.loadLicense(re.getOlatResource());
    if (license != null) {
        imp.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
        imp.setLicenseTypeName(license.getLicenseType().getName());
        imp.setLicensor(license.getLicensor());
        imp.setLicenseText(LicenseUIFactory.getLicenseText(license));
    }
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) 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