Search in sources :

Example 41 with ResourceLicense

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

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

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

the class ResourceLicenseDAOTest method shouldCreateAndPersistLicense.

@Test
public void shouldCreateAndPersistLicense() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    String licensor = "licensor";
    ResourceLicense license = licenseDao.createAndPersist(ores, licenseType, licensor);
    dbInstance.commitAndCloseSession();
    assertThat(license.getResName()).isEqualTo(ores.getResourceableTypeName());
    assertThat(license.getResId()).isEqualTo(ores.getResourceableId());
    assertThat(license.getLicenseType()).isEqualTo(licenseType);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    assertThat(license.getCreationDate()).isNotNull();
    assertThat(license.getLastModified()).isNotNull();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 43 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldUpdateLicense.

@Test
public void shouldUpdateLicense() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    ResourceLicense license = licenseDao.createAndPersist(ores, licenseType);
    dbInstance.commitAndCloseSession();
    String freetext = "freetext";
    license.setFreetext(freetext);
    String licensor = "licensor";
    license.setLicensor(licensor);
    license = licenseDao.save(license);
    assertThat(license.getFreetext()).isEqualTo(freetext);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    assertThat(license.getLicenseType()).isEqualTo(licenseType);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 44 with ResourceLicense

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

the class LicenseServiceImpl method copy.

@Override
public ResourceLicense copy(OLATResourceable source, OLATResourceable target) {
    if (source == null || target == null)
        return null;
    ResourceLicense targetLicense = null;
    ResourceLicense sourceLicense = licenseDao.loadByResource(source);
    if (sourceLicense != null) {
        licenseDao.delete(target);
        targetLicense = licenseDao.createAndPersist(target, sourceLicense);
    }
    return targetLicense;
}
Also used : ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 45 with ResourceLicense

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

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)

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