public static java.util.List<Long> getRequiredActivities(Course course)
     throws DocumentException, PortalException, SystemException {
   java.util.List<Long> result = new java.util.ArrayList<Long>();
   String extraData = course.getCourseExtraData();
   if (extraData != null && extraData.startsWith("<?xml")) {
     Document document = SAXReaderUtil.read(extraData);
     Element rootElement = document.getRootElement();
     java.util.List<Element> reqElements = rootElement.elements("required");
     for (Element reqElement : reqElements) {
       long actId = Long.parseLong(reqElement.attributeValue("actId"));
       LearningActivity larn = LearningActivityLocalServiceUtil.fetchLearningActivity(actId);
       if (larn != null
           && larn.getGroupId() == course.getGroupCreatedId()
           && larn.getWeightinmodule() > 0) {
         result.add(actId);
       }
     }
   }
   return result;
 }
  @Override
  public boolean updateCourse(Course course, long userId) throws SystemException {

    CourseResult courseResult =
        CourseResultLocalServiceUtil.getByUserAndCourse(course.getCourseId(), userId);
    // .fetchByuc(mresult.getUserId(), course.getCourseId());
    if (courseResult == null) {
      courseResult = CourseResultLocalServiceUtil.create(course.getCourseId(), userId);
    }

    if (courseResult.getStartDate() == null) {
      courseResult.setStartDate(new Date());
    }

    try {
      java.util.Map<Long, Long> weights = PonderatedCourseEval.getActivitiesWeight(course);
      long score = PonderatedCourseEval.getScore(course);

      boolean passed = true;
      long result = 0;
      long weight = 0;
      List<LearningActivity> learningActivities =
          LearningActivityLocalServiceUtil.getMandatoryLearningActivitiesOfGroup(
              course.getGroupCreatedId());

      // Guardo los resultados de las actividades del usuario en el curso en un hashmap para no
      // tener que acceder a bbdd por cada uno de ellos
      List<LearningActivityResult> lresult =
          LearningActivityResultLocalServiceUtil.getMandatoryByGroupIdUserId(
              course.getGroupCreatedId(), userId);
      HashMap<Long, LearningActivityResult> results = new HashMap<Long, LearningActivityResult>();
      for (LearningActivityResult ar : lresult) {
        results.put(ar.getActId(), ar);
      }

      boolean isFailed = false;
      LearningActivityResult learningActivityResult = null;

      for (LearningActivity act : learningActivities) {

        if (!weights.containsKey(
            act
                .getActId())) { // Solo se tienen en cuenta las actividades obligatorias que tienen
                                // peso definido
          continue;
        }

        if (results.containsKey(act.getActId())) {
          learningActivityResult = results.get(act.getActId());
        } else {
          learningActivityResult = null;
        }

        if (learningActivityResult != null) {
          if (learningActivityResult.getEndDate() != null) {
            if (!learningActivityResult.isPassed()) {
              passed = false;
              if (act.getTries() > 0) {
                long userTries =
                    LearningActivityTryLocalServiceUtil.getLearningActivityTryByActUserCount(
                        act.getActId(), userId);
                if (userTries >= act.getTries()) {
                  isFailed = true;
                }
              }
            }
            result = result + (learningActivityResult.getResult() * weights.get(act.getActId()));

          } else {
            passed = false;
          }
        } else {
          passed = false;
        }
        weight += weights.get(act.getActId());
      }

      if (result > 0 && weight > 0) {
        result = result / weight;
      }

      if (result < score) {
        passed = false;
      }

      // Si el usuario se ha marcado como isFailed es porque lo tiene suspenso. Se le asigna un
      // passed a false y se marca la fecha de finalizaciĆ³n del curso (passedDate).
      courseResult.setPassed(passed && !isFailed);
      // Se almacena el result del resultado del usuario en el curso.
      courseResult.setResult(result);
      if ((passed || isFailed) && courseResult.getPassedDate() == null) {
        courseResult.setPassedDate(new Date());
      }
      CourseResultLocalServiceUtil.update(courseResult);
      return true;

    } catch (PortalException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DocumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return true;
  }