Search in sources :

Example 21 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldLoadLicenseForResource.

@Test
public void shouldLoadLicenseForResource() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    License license = licenseDao.createAndPersist(ores, licenseType);
    dbInstance.commitAndCloseSession();
    ResourceLicense loadedLicense = licenseDao.loadByResource(ores);
    assertThat(loadedLicense).isEqualTo(license);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) License(org.olat.core.commons.services.license.License) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 22 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldLoadLicenseForResources.

@Test
public void shouldLoadLicenseForResources() {
    String resName = "res";
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    OLATResourceable ores1 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license1 = licenseDao.createAndPersist(ores1, licenseType);
    OLATResourceable ores2 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license2 = licenseDao.createAndPersist(ores2, licenseType);
    OLATResourceable ores3 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license3 = licenseDao.createAndPersist(ores3, licenseType);
    OLATResourceable oresSameName = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    licenseDao.createAndPersist(oresSameName, licenseType);
    OLATResourceable oresSameId = OresHelper.createOLATResourceableInstance("other", ores1.getResourceableId());
    licenseDao.createAndPersist(oresSameId, licenseType);
    dbInstance.commitAndCloseSession();
    List<ResourceLicense> loadedLicenses = licenseDao.loadLicenses(Arrays.asList(ores1, ores2, ores3));
    assertThat(loadedLicenses).containsExactly(license1, license2, license3);
}
Also used : Random(java.util.Random) 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 23 with ResourceLicense

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

the class ResourceLicenseDAOTest method shoulDeleteLicenseOfResource.

@Test
public void shoulDeleteLicenseOfResource() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    licenseDao.createAndPersist(ores, licenseType);
    dbInstance.commitAndCloseSession();
    ResourceLicense loadedLicense = licenseDao.loadByResource(ores);
    assertThat(loadedLicense).isNotNull();
    licenseDao.delete(ores);
    dbInstance.commitAndCloseSession();
    loadedLicense = licenseDao.loadByResource(ores);
    assertThat(loadedLicense).isNull();
}
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 24 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldCreateAndPersistRawLicense.

@Test
public void shouldCreateAndPersistRawLicense() {
    OLATResourceable oresTarget = JunitTestHelper.createRandomResource();
    OLATResourceable oresSource = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    String licensor = "licensor";
    String freetext = "freetext";
    ResourceLicense sourceLicense = licenseDao.createAndPersist(oresSource, licenseType, licensor);
    sourceLicense.setFreetext(freetext);
    sourceLicense = licenseDao.save(sourceLicense);
    dbInstance.commitAndCloseSession();
    ResourceLicense targetLicense = licenseDao.createAndPersist(oresTarget, sourceLicense);
    assertThat(targetLicense.getResName()).isEqualTo(oresTarget.getResourceableTypeName());
    assertThat(targetLicense.getResId()).isEqualTo(oresTarget.getResourceableId());
    assertThat(targetLicense.getLicenseType()).isEqualTo(sourceLicense.getLicenseType());
    assertThat(targetLicense.getLicensor()).isEqualTo(sourceLicense.getLicensor());
    assertThat(targetLicense.getFreetext()).isEqualTo(sourceLicense.getFreetext());
    assertThat(targetLicense.getCreationDate()).isNotNull();
    assertThat(targetLicense.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 25 with ResourceLicense

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

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