use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ACReservationDAOTest method testCountReservation.
@Test
public void testCountReservation() {
// create 3 identities and 3 reservations
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("reserv-1-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("reserv-2-" + UUID.randomUUID().toString());
Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("reserv-3-" + UUID.randomUUID().toString());
OLATResource resource = JunitTestHelper.createRandomResource();
dbInstance.commitAndCloseSession();
ResourceReservation reservation1 = acReservationDao.createReservation(id1, "test", null, resource);
Assert.assertNotNull(reservation1);
ResourceReservation reservation2 = acReservationDao.createReservation(id2, "test", null, resource);
Assert.assertNotNull(reservation2);
ResourceReservation reservation3 = acReservationDao.createReservation(id3, "test", null, resource);
Assert.assertNotNull(reservation3);
dbInstance.commitAndCloseSession();
// count reservations
int count = acReservationDao.countReservations(resource);
Assert.assertEquals(3, count);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ReferenceManagerTest method testAddReference.
@Test
public void testAddReference() {
OLATResource oressource = JunitTestHelper.createRandomResource();
OLATResource orestarget = JunitTestHelper.createRandomResource();
String udata = "üserdätä";
// add a reference
referenceManager.addReference(oressource, orestarget, udata);
dbInstance.commitAndCloseSession();
OLATResourceable targetOres = OresHelper.createOLATResourceableInstance(orestarget.getResourceableTypeName(), orestarget.getResourceableId());
OLATResource orestarget2 = resourceManager.findOrPersistResourceable(targetOres);
List<Reference> refs = referenceManager.getReferencesTo(orestarget2);
Assert.assertNotNull(refs);
Assert.assertEquals("only one reference may exist", 1, refs.size());
Assert.assertEquals(oressource, refs.get(0).getSource());
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ReferenceManagerTest method testAddAndDeleteAllReferences_parano.
@Test
public void testAddAndDeleteAllReferences_parano() {
OLATResource oressource = JunitTestHelper.createRandomResource();
OLATResource orestarget1 = JunitTestHelper.createRandomResource();
OLATResource orestarget2 = JunitTestHelper.createRandomResource();
OLATResource orestarget3 = JunitTestHelper.createRandomResource();
// add the references
referenceManager.addReference(oressource, orestarget1, "üserdätä");
referenceManager.addReference(orestarget2, orestarget1, "üserdätä");
referenceManager.addReference(oressource, orestarget2, "éserdàtà");
referenceManager.addReference(orestarget2, oressource, "éserdàtà");
referenceManager.addReference(orestarget3, oressource, "éserdàtà");
referenceManager.addReference(orestarget3, orestarget1, "éserdàtà");
dbInstance.commitAndCloseSession();
List<Reference> refs = referenceManager.getReferences(oressource);
Assert.assertEquals("2 references exist", 2, refs.size());
List<Reference> reverseRefs = referenceManager.getReferencesTo(oressource);
Assert.assertEquals("2 references exist", 2, reverseRefs.size());
referenceManager.deleteAllReferencesOf(oressource);
dbInstance.commitAndCloseSession();
// now make sure the reference was deleted
List<Reference> norefs = referenceManager.getReferences(oressource);
Assert.assertTrue("reference should now be deleted", norefs.isEmpty());
// check target 3 has 1
List<Reference> refTarget3s = referenceManager.getReferences(orestarget3);
Assert.assertEquals(1, refTarget3s.size());
Assert.assertEquals(orestarget1, refTarget3s.get(0).getTarget());
// check target 2 has 1
List<Reference> refTarget2s = referenceManager.getReferences(orestarget2);
Assert.assertEquals(1, refTarget2s.size());
Assert.assertEquals(orestarget1, refTarget2s.get(0).getTarget());
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class PFCoachController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
OLATResource course = courseEnv.getCourseGroupManager().getCourseResource();
String businessPath = getWindowControl().getBusinessControl().getAsString();
SubscriptionContext subsContext = new SubscriptionContext(course, pfNode.getIdent());
PublisherData publisherData = new PublisherData(OresHelper.calculateTypeName(PFCourseNode.class), String.valueOf(course.getResourceableId()), businessPath);
contextualSubscriptionCtr = new ContextualSubscriptionController(ureq, getWindowControl(), subsContext, publisherData);
listenTo(contextualSubscriptionCtr);
layoutCont.put("contextualSubscription", contextualSubscriptionCtr.getInitialComponent());
backLink = LinkFactory.createLinkBack(layoutCont.getFormItemComponent(), this);
}
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
int i = 0;
FlexiTableSortOptions options = new FlexiTableSortOptions();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
int colIndex = USER_PROPS_OFFSET + i++;
if (userPropertyHandler == null)
continue;
String propName = userPropertyHandler.getName();
boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
FlexiColumnModel col;
if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, userPropertyHandler.getName(), true, propName, new StaticFlexiCellRenderer(userPropertyHandler.getName(), new TextFlexiCellRenderer()));
} else {
col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, true, propName);
}
columnsModel.addFlexiColumnModel(col);
if (!options.hasDefaultOrderBy()) {
options.setDefaultOrderBy(new SortKey(propName, true));
} else if (UserConstants.LASTNAME.equals(propName)) {
options.setDefaultOrderBy(new SortKey(propName, true));
}
}
if (pfNode.hasParticipantBoxConfigured()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(DropBoxCols.numberFiles, "drop.box"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(DropBoxCols.lastUpdate));
}
if (pfNode.hasCoachBoxConfigured()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(DropBoxCols.numberFilesReturn, "return.box"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(DropBoxCols.lastUpdateReturn));
}
StaticFlexiCellRenderer openCellRenderer = new StaticFlexiCellRenderer(translate("open.box"), "open.box");
openCellRenderer.setIconRightCSS("o_icon_start o_icon-fw");
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(DropBoxCols.openbox, "open.box", openCellRenderer));
tableModel = new DropBoxTableModel(columnsModel, getTranslator());
dropboxTable = uifactory.addTableElement(getWindowControl(), "table", tableModel, getTranslator(), formLayout);
dropboxTable.setMultiSelect(true);
dropboxTable.setSelectAllEnable(true);
dropboxTable.setExportEnabled(true);
dropboxTable.setSortSettings(options);
dropboxTable.setAndLoadPersistedPreferences(ureq, "participant-folder_coach_" + pfView.name());
dropboxTable.setEmtpyTableMessageKey("table.empty");
FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonGroupLayout.setElementCssClass("o_button_group");
formLayout.add(buttonGroupLayout);
downloadLink = uifactory.addFormLink("download.link", buttonGroupLayout, Link.BUTTON);
uploadAllLink = uifactory.addFormLink("upload.link", buttonGroupLayout, Link.BUTTON);
}
use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.
the class ProjectEditDetailsFormController method formOK.
@Override
protected void formOK(UserRequest ureq) {
boolean projectChanged = false;
if (!project.getTitle().equals(projectTitle.getValue())) {
// title has been changed => change project-group name too
String newProjectGroupName = translate("project.member.groupname", projectTitle.getValue());
String newProjectGroupDescription = translate("project.member.groupdescription", projectTitle.getValue());
OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
projectGroupManager.changeProjectGroupName(getIdentity(), project.getProjectGroup(), newProjectGroupName, newProjectGroupDescription, courseResource);
projectGroupManager.sendGroupChangeEvent(project, courseEnv.getCourseResourceableId(), ureq.getIdentity());
projectChanged = true;
}
if (!project.getTitle().equals(projectTitle.getValue())) {
project.setTitle(projectTitle.getValue());
projectChanged = true;
}
if (!project.getDescription().equals(projectDescription.getValue())) {
project.setDescription(projectDescription.getValue());
projectChanged = true;
}
if (project.getMaxMembers() != maxMembers.getIntValue()) {
project.setMaxMembers(maxMembers.getIntValue());
projectGroupManager.setProjectGroupMaxMembers(getIdentity(), project.getProjectGroup(), maxMembers.getIntValue());
projectChanged = true;
}
if (StringHelper.containsNonWhitespace(attachmentFileName.getUploadFileName())) {
// First call uploadFiles than setAttachedFileName because uploadFiles needs old attachment name
uploadFiles(attachmentFileName);
project.setAttachedFileName(attachmentFileName.getUploadFileName());
projectChanged = true;
} else if (StringHelper.containsNonWhitespace(project.getAttachmentFileName()) && attachmentFileName.getInitialFile() == null) {
// Attachment file has been removed
project.setAttachedFileName("");
projectChanged = true;
}
// store customfields
int index = 0;
for (Iterator<FormItem> iterator = customfieldElementList.iterator(); iterator.hasNext(); ) {
FormItem element = iterator.next();
String value = "";
if (element instanceof TextElement) {
TextElement textElement = (TextElement) element;
value = textElement.getValue();
} else if (element instanceof SingleSelection) {
SingleSelection selectionElement = (SingleSelection) element;
if (!selectionElement.getSelectedKey().equals(DROPDOWN_NO_SELECETION)) {
value = selectionElement.getValue(selectionElement.getSelected());
} else {
value = "";
}
}
getLogger().debug("customfield index=" + index + " value=" + value + " project.getCustomFieldValue(index)=" + project.getCustomFieldValue(index));
if (!project.getCustomFieldValue(index).equals(value)) {
project.setCustomFieldValue(index, value);
projectChanged = true;
}
index++;
}
// store events
for (Project.EventType eventType : eventStartElementList.keySet()) {
Date startDate = eventStartElementList.get(eventType).getDate();
Date endDate = eventEndElementList.get(eventType).getDate();
// First handle startdate
if (hasBeenChanged(project.getProjectEvent(eventType).getStartDate(), startDate) || hasBeenChanged(project.getProjectEvent(eventType).getEndDate(), endDate)) {
project.setProjectEvent(new ProjectEvent(eventType, startDate, endDate));
projectChanged = true;
}
}
if (mailNotification.isSelected(0) != project.isMailNotificationEnabled()) {
project.setMailNotificationEnabled(mailNotification.isSelected(0));
projectChanged = true;
}
if (projectChanged) {
if (projectBrokerManager.existsProject(project.getKey())) {
projectBrokerManager.updateProject(project);
projectBrokerMailer.sendProjectChangedEmailToParticipants(ureq.getIdentity(), project, this.getTranslator());
} else {
showInfo("info.project.nolonger.exist", project.getTitle());
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations