Search in sources :

Example 46 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class RepositoryEditDescriptionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        String licensor = null;
        String freetext = null;
        if (licensorEl != null && licensorEl.isVisible()) {
            licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
            freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
        }
        license.setLicensor(licensor);
        license.setFreetext(freetext);
        license = licenseService.update(license);
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    File uploadedImage = fileUpload.getUploadFile();
    if (uploadedImage != null && uploadedImage.exists()) {
        VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
        VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
        // give it it's real name and extension
        VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
        boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
        if (!ok) {
            showWarning("cif.error.image");
        } else {
            VFSLeaf image = repositoryManager.getImage(repositoryEntry);
            if (image instanceof LocalFileImpl) {
                fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
            }
        }
        container.delete();
    }
    File uploadedMovie = movieUpload.getUploadFile();
    if (uploadedMovie != null && uploadedMovie.exists()) {
        VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
        VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
        if (newFile == null) {
            showWarning("cif.error.movie");
        } else {
            String filename = movieUpload.getUploadFileName();
            String extension = FileUtils.getFileSuffix(filename);
            newFile.rename(repositoryEntry.getKey() + "." + extension);
        }
    }
    String displayname = displayName.getValue().trim();
    repositoryEntry.setDisplayname(displayname);
    String mainLanguage = language.getValue();
    if (StringHelper.containsNonWhitespace(mainLanguage)) {
        repositoryEntry.setMainLanguage(mainLanguage);
    } else {
        repositoryEntry.setMainLanguage(null);
    }
    if (dateTypesEl != null) {
        String type = "none";
        if (dateTypesEl.isOneSelected()) {
            type = dateTypesEl.getSelectedKey();
        }
        if ("none".equals(type)) {
            repositoryEntry.setLifecycle(null);
        } else if ("public".equals(type)) {
            String key = publicDatesEl.getSelectedKey();
            if (StringHelper.isLong(key)) {
                Long cycleKey = Long.parseLong(key);
                RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
                repositoryEntry.setLifecycle(cycle);
            }
        } else if ("private".equals(type)) {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
            if (cycle == null || !cycle.isPrivateCycle()) {
                String softKey = "lf_" + repositoryEntry.getSoftkey();
                cycle = lifecycleDao.create(displayname, softKey, true, start, end);
            } else {
                cycle.setValidFrom(start);
                cycle.setValidTo(end);
                cycle = lifecycleDao.updateLifecycle(cycle);
            }
            repositoryEntry.setLifecycle(cycle);
        }
    }
    if (externalRef != null && externalRef.isEnabled()) {
        String ref = externalRef.getValue().trim();
        repositoryEntry.setExternalRef(ref);
    }
    String desc = description.getValue().trim();
    repositoryEntry.setDescription(desc);
    if (authors != null) {
        String auth = authors.getValue().trim();
        repositoryEntry.setAuthors(auth);
    }
    if (objectives != null) {
        String obj = objectives.getValue().trim();
        repositoryEntry.setObjectives(obj);
    }
    if (requirements != null) {
        String req = requirements.getValue().trim();
        repositoryEntry.setRequirements(req);
    }
    if (credits != null) {
        String cred = credits.getValue().trim();
        repositoryEntry.setCredits(cred);
    }
    if (expenditureOfWork != null) {
        String exp = expenditureOfWork.getValue().trim();
        repositoryEntry.setExpenditureOfWork(exp);
    }
    if (location != null) {
        String loc = location.getValue().trim();
        repositoryEntry.setLocation(loc);
    }
    repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
    if (repositoryEntry == null) {
        showWarning("repositoryentry.not.existing");
        fireEvent(ureq, Event.CLOSE_EVENT);
    } else {
        fireEvent(ureq, Event.CHANGED_EVENT);
        MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date) LicenseType(org.olat.core.commons.services.license.LicenseType) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 47 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class CoursesTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    conn = new RestConnection();
    try {
        // create course and persist as OLATResourceImpl
        admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
        course1 = CoursesWebService.createEmptyCourse(admin, "courses1", "courses1 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, null, null, null, null);
        externalId = UUID.randomUUID().toString();
        externalRef = UUID.randomUUID().toString();
        course2 = CoursesWebService.createEmptyCourse(admin, "courses2", "courses2 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, externalId, externalRef, "all", null);
        dbInstance.commitAndCloseSession();
        re1 = repositoryManager.lookupRepositoryEntry(course1, false);
        re2 = repositoryManager.lookupRepositoryEntry(course2, false);
        externalId3 = UUID.randomUUID().toString();
        course3 = CoursesWebService.createEmptyCourse(admin, "courses3", "courses3 long name", null, null, null, RepositoryEntry.ACC_OWNERS, false, null, null, externalId3, null, "all", null);
        re3 = repositoryManager.lookupRepositoryEntry(course3, false);
        RepositoryEntryLifecycle lifecycle3 = reLifecycleDao.create("course3 lifecycle", UUID.randomUUID().toString(), true, new Date(), new Date());
        dbInstance.commit();
        re3.setLifecycle(lifecycle3);
        re3 = dbInstance.getCurrentEntityManager().merge(re3);
        dbInstance.commitAndCloseSession();
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 48 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class RepositoryManagerTest method setDescriptionAndName.

@Test
public void setDescriptionAndName() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(re);
    String newName = "Brand new name";
    String newDesc = "Brand new description";
    String newAuthors = "Me and only me";
    String newLocation = "Far away";
    String newExternalId = "Brand - ext";
    String newExternalRef = "Brand - ref";
    String newManagedFlags = RepositoryEntryManagedFlag.access.name();
    RepositoryEntryLifecycle newCycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
    re = repositoryManager.setDescriptionAndName(re, newName, newDesc, newLocation, newAuthors, newExternalId, newExternalRef, newManagedFlags, newCycle);
    Assert.assertNotNull(re);
    dbInstance.commitAndCloseSession();
    RepositoryEntry reloaded = repositoryManager.lookupRepositoryEntry(re.getKey());
    Assert.assertNotNull(reloaded);
    Assert.assertEquals("Me and only me", reloaded.getAuthors());
    Assert.assertEquals("Far away", reloaded.getLocation());
    Assert.assertEquals("Brand new name", reloaded.getDisplayname());
    Assert.assertEquals("Brand new description", reloaded.getDescription());
    Assert.assertEquals("Brand - ext", reloaded.getExternalId());
    Assert.assertEquals("Brand - ref", reloaded.getExternalRef());
    Assert.assertEquals(RepositoryEntryManagedFlag.access.name(), reloaded.getManagedFlagsString());
    Assert.assertNotNull(reloaded.getLifecycle());
    Assert.assertEquals(newCycle, reloaded.getLifecycle());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) Test(org.junit.Test)

Example 49 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class RepositoryManagerTest method setDescriptionAndName_lifecycle.

@Test
public void setDescriptionAndName_lifecycle() {
    RepositoryEntryLifecycle publicCycle = lifecycleDao.create("Public 1", "Soft public 1", false, new Date(), new Date());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(re);
    String newName = "Brand new name";
    String newDesc = "Brand new description";
    re = repositoryManager.setDescriptionAndName(re, newName, null, null, newDesc, null, null, null, null, null, null, publicCycle);
    Assert.assertNotNull(re);
    dbInstance.commitAndCloseSession();
    RepositoryEntry reloaded = repositoryManager.lookupRepositoryEntry(re.getKey());
    Assert.assertNotNull(reloaded);
    Assert.assertEquals("Brand new name", reloaded.getDisplayname());
    Assert.assertEquals("Brand new description", reloaded.getDescription());
    Assert.assertEquals(publicCycle, reloaded.getLifecycle());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) Test(org.junit.Test)

Example 50 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class RepositoryManagerTest method lazyLoadingCheck.

/**
 * This is a simulation of OO-2667 to make sure that the LazyInitializationException don't
 * set the transaction on rollback.
 */
@Test
public void lazyLoadingCheck() {
    RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
    dbInstance.commitAndCloseSession();
    RepositoryEntryLifecycle cycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
    re = repositoryManager.setDescriptionAndName(re, "Updated repo entry", null, null, "", null, null, null, null, null, null, cycle);
    dbInstance.commitAndCloseSession();
    RepositoryEntry lazyRe = repositoryManager.setAccess(re, 2, false);
    dbInstance.commitAndCloseSession();
    try {
        // produce the exception
        lazyRe.getLifecycle().getValidFrom();
        Assert.fail();
    } catch (LazyInitializationException e) {
    // 
    }
    // load a fresh entry
    RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(lazyRe.getKey());
    Date validFrom = entry.getLifecycle().getValidFrom();
    Assert.assertNotNull(validFrom);
    dbInstance.commitAndCloseSession();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) LazyInitializationException(org.hibernate.LazyInitializationException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)54 Date (java.util.Date)34 Test (org.junit.Test)22 Calendar (java.util.Calendar)18 ArrayList (java.util.ArrayList)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 List (java.util.List)6 Identity (org.olat.core.id.Identity)6 RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)6 Produces (javax.ws.rs.Produces)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ICourse (org.olat.course.ICourse)4 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 RepositoryEntryLifecycleDAO (org.olat.repository.manager.RepositoryEntryLifecycleDAO)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)3 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)3 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2