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);
}
}
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);
}
}
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());
}
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());
}
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();
}
Aggregations