Exemplo n.º 1
0
  /** testGetAllResourceTypeNames */
  @Test
  public void testGetAllResourceTypeNames() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-3-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    // create a property
    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catall",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    Assert.assertNotNull(p.getResourceTypeName());
    List<String> resTypeNames = pm.getAllResourceTypeNames();
    assertTrue(resTypeNames.contains(ores.getResourceableTypeName()));
  }
Exemplo n.º 2
0
  @Test
  public void testFindProperties() {
    // create identities, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-8-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-9-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            id1, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    String category = "cat3";
    String propertyName = "TestProperty3";
    String textValue = "textValue3";
    Property p =
        pm.createPropertyInstance(
            id1,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id2,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    List<Property> propertyList =
        pm.findProperties(
            id1,
            group,
            res.getResourceableTypeName(),
            res.getResourceableId(),
            category,
            propertyName);
    assertEquals(1, propertyList.size());
    assertEquals(propertyName, propertyList.get(0).getName());
    assertEquals(textValue, propertyList.get(0).getTextValue());
    int deletedCount1 = pm.deleteProperties(id1, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount1);
    int deletedCount2 = pm.deleteProperties(id2, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount2);
  }
Exemplo n.º 3
0
  @Test
  public void testFindWithResourceIdList() {
    // create resource, identity
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-2-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // create the property
    Property p =
        pm.createPropertyInstance(
            identity,
            null,
            ores,
            "catidlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    // check with empty list
    List<Property> emptyProps =
        pm.findProperties(
            ores.getResourceableTypeName(),
            Collections.<Long>emptyList(),
            "catidlist",
            "TestProperty");
    assertNotNull(emptyProps);
    Assert.assertTrue(emptyProps.isEmpty());

    // check with a real value and a dummy
    List<Long> resIds = new ArrayList<Long>();
    resIds.add(ores.getResourceableId());
    resIds.add(2456l); // dummy
    List<Property> props =
        pm.findProperties(ores.getResourceableTypeName(), resIds, "catidlist", "TestProperty");
    assertNotNull(props);
    Assert.assertEquals(1, props.size());
    Assert.assertEquals(p, props.get(0));
  }
Exemplo n.º 4
0
  /** testListProperties */
  @Test
  public void testListProperties() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-4-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "cat",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);

    List<Property> entries =
        PropertyManager.getInstance()
            .listProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty");
    Assert.assertNotNull(entries);
    Assert.assertEquals(1, entries.size());

    Property prop = entries.get(0);
    assertEquals(ores.getResourceableTypeName(), prop.getResourceTypeName());
    assertEquals(ores.getResourceableId(), prop.getResourceTypeId());

    int numOfEntries =
        PropertyManager.getInstance()
            .countProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty",
                null,
                null);
    Assert.assertEquals(entries.size(), numOfEntries);
  }
Exemplo n.º 5
0
  private void appendCourseCalendars(
      UserRequest ureq,
      WindowControl wControl,
      List<KalendarRenderWrapper> calendars,
      Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar()
        || calendarModule.isEnableCourseToolCalendar()) {

      // add course calendars
      List<Object[]> resources = getCourses(ureq.getIdentity());
      Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());

      Set<Long> duplicates = new HashSet<>();

      for (Object[] resource : resources) {
        RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
        if (duplicates.contains(courseEntry.getKey())) {
          continue;
        }
        duplicates.add(courseEntry.getKey());

        String role = (String) resource[1];
        Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
        try {
          ICourse course = CourseFactory.loadCourse(courseEntry);
          if (isCourseCalendarEnabled(course)) {
            // calendar course aren't enabled per default but course node of type calendar are
            // always possible
            // REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled())
            // continue;
            // add course calendar
            KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
            boolean isPrivileged =
                GroupRoles.owner.name().equals(role)
                    || editoredResources.contains(courseEntry.getOlatResource());
            if (isPrivileged) {
              courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
            } else {
              courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
            }

            if (role != null
                && (GroupRoles.owner.name().equals(role)
                    || GroupRoles.coach.name().equals(role)
                    || GroupRoles.participant.name().equals(role))) {
              courseCalendarWrapper.setPrivateEventsVisible(true);
            }

            CalendarUserConfiguration config =
                configMap.get(courseCalendarWrapper.getCalendarKey());
            if (config != null) {
              courseCalendarWrapper.setConfiguration(config);
            }
            courseCalendarWrapper.setLinkProvider(
                new CourseLinkProviderController(
                    course, Collections.singletonList(course), ureq, wControl));
            calendars.add(courseCalendarWrapper);
          }
        } catch (CorruptedCourseException e) {
          OLATResource olatResource = courseEntry.getOlatResource();
          log.error(
              "Corrupted course: "
                  + olatResource.getResourceableTypeName()
                  + " :: "
                  + courseResourceableID,
              null);
        }
      }
    }
  }