View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.userdirectory.moodle;
23  
24  import org.json.simple.parser.ParseException;
25  
26  import java.io.IOException;
27  import java.net.URISyntaxException;
28  import java.util.List;
29  
30  /**
31   * Client class for the Moodle web service.
32   */
33  public interface MoodleWebService {
34    String MOODLE_FUNCTION_CORE_USER_GET_USERS_BY_FIELD = "core_user_get_users_by_field";
35    String MOODLE_FUNCTION_TOOL_OPENCAST_GET_COURSES_FOR_INSTRUCTOR = "tool_opencast_get_courses_for_instructor";
36    String MOODLE_FUNCTION_TOOL_OPENCAST_GET_COURSES_FOR_LEARNER = "tool_opencast_get_courses_for_learner";
37    String MOODLE_FUNCTION_TOOL_OPENCAST_GET_GROUPS_FOR_LEARNER = "tool_opencast_get_groups_for_learner";
38  
39    /**
40     * Searches for a user in Moodle.
41     *
42     * @param filter Filter type to apply
43     * @param values Value for the filter.
44     * @return A {@link MoodleUser} list.
45     * @throws URISyntaxException        In case the URL cannot be constructed.
46     * @throws IOException               In case of an IO error.
47     * @throws MoodleWebServiceException In case Moodle returns an error.
48     * @throws ParseException            In case the Moodle response cannot be parsed.
49     */
50    List<MoodleUser> coreUserGetUsersByField(CoreUserGetUserByFieldFilters filter, List<String> values)
51            throws URISyntaxException, IOException, MoodleWebServiceException, ParseException;
52  
53    /**
54     * Returns the list of Moodle course IDs the given user has the instructor capability.
55     *
56     * @param username The username to search for.
57     * @return A list of Moodle course IDs.
58     * @throws URISyntaxException        In case the URL cannot be constructed.
59     * @throws IOException               In case of an IO error.
60     * @throws MoodleWebServiceException In case Moodle returns an error.
61     * @throws ParseException            In case the Moodle response cannot be parsed.
62     */
63    List<String> toolOpencastGetCoursesForInstructor(String username)
64            throws URISyntaxException, IOException, MoodleWebServiceException, ParseException;
65  
66    /**
67     * Returns the list of Moodle course IDs the given user has the learner capability.
68     *
69     * @param username The username to search for.
70     * @return A list of Moodle course IDs.
71     * @throws URISyntaxException        In case the URL cannot be constructed.
72     * @throws IOException               In case of an IO error.
73     * @throws MoodleWebServiceException In case Moodle returns an error.
74     * @throws ParseException            In case the Moodle response cannot be parsed.
75     */
76    List<String> toolOpencastGetCoursesForLearner(String username)
77            throws URISyntaxException, IOException, MoodleWebServiceException, ParseException;
78  
79    /**
80     * Returns the list of Moodle group IDs where the given user has the learner capability.
81     *
82     * @param username The username to search for.
83     * @return A list of Moodle group IDs.
84     * @throws URISyntaxException        In case the URL cannot be constructed.
85     * @throws IOException               In case of an IO error.
86     * @throws MoodleWebServiceException In case Moodle returns an error.
87     * @throws ParseException            In case the Moodle response cannot be parsed.
88     */
89    List<String> toolOpencastGetGroupsForLearner(String username)
90            throws URISyntaxException, IOException, MoodleWebServiceException, ParseException;
91  
92    /**
93     * Returns the URL to the Moodle web service.
94     *
95     * @return URL to the Moodle web service.
96     */
97    String getURL();
98  
99    enum CoreUserGetUserByFieldFilters {
100     id, lastname, firstname, idnumber, username, email, auth
101   }
102 }