protected void changeTutorial(Parameters params, Map sitemapParams) throws ProcessingException {
    final String METHOD_NAME = "changeTutorial";
    this.getLogger().debug(METHOD_NAME + " 1/2: Started");

    DbHelper dbHelper = null;
    try {
      // Init services:
      dbHelper = (DbHelper) this.manager.lookup(DbHelper.ROLE);

      // Get data from parameters:
      int userId = ParamUtil.getAsInt(params, "user");
      int classId = ParamUtil.getAsId(params, "class");
      int oldTutorialId = ParamUtil.getAsInt(params, "old-tutorial");
      int newTutorialId = ParamUtil.getAsInt(params, "new-tutorial");

      // Both tutorials must belong to the specified class:
      int oldTutorialClassId =
          dbHelper.getPseudoDocDatumAsInt(PseudoDocType.TUTORIAL, oldTutorialId, DbColumn.CLASS);
      int newTutorialClassId =
          dbHelper.getPseudoDocDatumAsInt(PseudoDocType.TUTORIAL, newTutorialId, DbColumn.CLASS);
      if (oldTutorialClassId != classId)
        throw new IllegalArgumentException("Old tutorial does not belong to the specified class");
      if (newTutorialClassId != classId)
        throw new IllegalArgumentException("New tutorial does not belong to the specified class");

      dbHelper.beginTransaction(this, true);

      // Remove user from old tutorial:
      dbHelper.removeTutorialMember(oldTutorialId, userId);

      // Add user to new tutorial:
      dbHelper.addTutorialMember(newTutorialId, userId);

      dbHelper.endTransaction(this);

      this.getLogger().debug(METHOD_NAME + " 2/2: Done");
    } catch (Exception exception) {
      throw new ProcessingException(exception);
    } finally {
      if (dbHelper != null)
        try {
          if (dbHelper.hasTransactionLocked(this)) dbHelper.abortTransaction(this);
        } catch (Exception exception) {
          throw new ProcessingException(exception);
        } finally {
          this.manager.release(dbHelper);
        }
    }
  }
Example #2
0
 /**
  * Returns the default section path. It is obtained as follows: First, the section path of the
  * specified class is determined. This path should have the form <code>
  *  <var>some_path</var>/classes</code>. The default section path of the tutorial is then
  * <var>some_path</var>/tutorials</code>, which is returned. If the path of the section has not
  * the above form, an {@link IllegalArgumentException IllegalArgumentException} is thrown.
  */
 public static String getDefaultSectionPath(
     int classId, DbHelper dbHelper, PathTokenizer pathTokenizer) throws SQLException {
   String classSectionPath =
       dbHelper.getPseudoDocDatumAsString(PseudoDocType.CLASS, classId, DbColumn.SECTION_PATH);
   pathTokenizer.tokenize(classSectionPath);
   String pureName = pathTokenizer.getPureName();
   if (!pureName.equals("classes"))
     throw new IllegalArgumentException(
         "Class section pure name does not meet the standard: \""
             + pureName
             + "\""
             + " (should be \"classes\")");
   String sectionPath = pathTokenizer.getSectionPath();
   return sectionPath + "/tutorials";
 }
Example #3
0
 /**
  * Returns the default section path. It is obtained as follows: First, the section path of the
  * specified class is determined. This path should have the form <code>
  *  <var>some_path</var>/classes</code>. The default section path of the tutorial is then
  * <var>some_path</var>/tutorials</code>, which is returned. If the path of the section has not
  * the above form, an {@link IllegalArgumentException IllegalArgumentException} is thrown.
  */
 public static String getDefaultSectionPath(
     String classSyncId, DbHelper dbHelper, PathTokenizer pathTokenizer) throws SQLException {
   ResultSet resultSet =
       dbHelper.queryPseudoDocDatumBySyncId(
           PseudoDocType.CLASS, classSyncId, DbColumn.SECTION_PATH);
   if (!resultSet.next())
     throw new SQLException("Cannot find class with sync id \"" + classSyncId + "\"");
   String classSectionPath = resultSet.getString(DbColumn.SECTION_PATH);
   pathTokenizer.tokenize(classSectionPath);
   String pureName = pathTokenizer.getPureName();
   if (!pureName.equals("classes"))
     throw new IllegalArgumentException(
         "Class section pure name does not meet the standard: \""
             + pureName
             + "\""
             + " (should be \"classes\")");
   String sectionPath = pathTokenizer.getSectionPath();
   return sectionPath + "/tutorials";
 }