Search in sources :

Example 81 with OLATResource

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);
}
Also used : OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 82 with OLATResource

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());
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 83 with OLATResource

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());
}
Also used : OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 84 with OLATResource

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);
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) OLATResource(org.olat.resource.OLATResource) SortKey(org.olat.core.commons.persistence.SortKey) PublisherData(org.olat.core.commons.services.notifications.PublisherData) ContextualSubscriptionController(org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 85 with OLATResource

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);
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26