Commit 13280cfb authored by Martín's avatar Martín
Browse files

Archivo de configuración para ENDPOINT de Moodle y nombre del grupo asociado.

parent 46f097c5
//export const SERVER = 'https://matefun.mybluemix.net';
//export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint';
export const SERVER = 'https://matefun.mybluemix.net';
export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint';
export const SERVER = 'http://localhost:9090';
export const GHCI_URL = 'ws://localhost:9090/endpoint';
//export const SERVER = 'http://localhost:9090';
//export const GHCI_URL = 'ws://localhost:9090/endpoint';
//Configuracion dinamica pensando en servidor con ip dinamica
//export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090';
......
{
"endpoint":"https://tics.moodlecloud.com",
"group":"Piloto"
}
\ No newline at end of file
......@@ -48,7 +48,25 @@ import edu.proygrado.modelo.Usuario;
*/
@Stateless
public class LoginEJB {
public static String moodleApiEndpoint = null;
public static String moodleGroup = null;
public LoginEJB() {
super();
//leo archivo de configuración.
JSONParser parser = new JSONParser();
try {
String currentPath = System.getProperty("user.dir");
String configFilePath = currentPath.substring(0,currentPath.length()-4);
configFilePath = configFilePath + "/standalone/deployments/matefun.war/WEB-INF/config.json";
Object obj = parser.parse(new FileReader(configFilePath));
JSONObject jsonObject = (JSONObject) obj;
LoginEJB.moodleApiEndpoint = (String) jsonObject.get("endpoint");
LoginEJB.moodleGroup = (String) jsonObject.get("group");
} catch (Exception e) {
e.printStackTrace();
System.out.print("No se ha podido cargar el archivo: /standalone/deployments/matefun.war/WEB-INF/config.json");
}
}
@PersistenceContext(unitName = "matefunDS")
private EntityManager em;
......@@ -98,7 +116,8 @@ public class LoginEJB {
Long courseId = null;
for (MoodleCourseDTO course : coursesInfo.getEnrolledcourses()) {
System.out.println(course.getShortname());
if (course.getShortname().toLowerCase().equals("piloto")) {
String groupName = LoginEJB.moodleGroup.toLowerCase();
if (course.getShortname().toLowerCase().equals(groupName)) {
courseId = course.getId();
System.out.println(courseId);
}
......@@ -106,7 +125,7 @@ public class LoginEJB {
if (courseId != null) {
coursesInfo = getCursesInfo(token, userInfo.getUserid(), courseId);
} else {
throw new MatefunForbiddenException("Usuario no asignado al curso \"Piloto\" en Moodle");
throw new MatefunForbiddenException("Usuario no asignado al curso \"" +LoginEJB.moodleGroup +"\" en Moodle");
}
String rol = null;
......@@ -121,7 +140,7 @@ public class LoginEJB {
}
if (rol == null) {
throw new MatefunForbiddenException("Rol incorrecto en curso \"Piloto\"");
throw new MatefunForbiddenException("Rol incorrecto en curso \"" +LoginEJB.moodleGroup +"\"");
}
Usuario nuevoDesdeMoodle;
......@@ -180,7 +199,7 @@ public class LoginEJB {
javax.ws.rs.client.Client c = cb.build();
String url = "https://tics.moodlecloud.com/login/token.php";
String url = LoginEJB.moodleApiEndpoint + "/login/token.php";
MoodleTokensDTO tokens = null;
try {
// https://tics.moodlecloud.com/login/token.php
......@@ -206,8 +225,7 @@ public class LoginEJB {
javax.ws.rs.client.ClientBuilder cb = ClientBuilder.newBuilder();
javax.ws.rs.client.Client c = cb.build();
String url = "https://tics.moodlecloud.com/webservice/rest/server.php";
String url = LoginEJB.moodleApiEndpoint + "/webservice/rest/server.php";
MoodleUserInfoDTO userInfo = null;
try {
......@@ -234,7 +252,7 @@ public class LoginEJB {
private MoodleCoursesInfoDTO getCursesInfo(String token, Long userId, Long courseId) throws MatefunException {
javax.ws.rs.client.ClientBuilder cb = ClientBuilder.newBuilder();
javax.ws.rs.client.Client c = cb.build();
String url = "https://tics.moodlecloud.com/webservice/rest/server.php";
String url = LoginEJB.moodleApiEndpoint+ "/webservice/rest/server.php";
List<MoodleCoursesInfoDTO> coursesInfo = null;
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment