コード例 #1
0
  private void deleteOldWorkspaceObject(BaseObject oldObject, XWikiDocument oldWikiDescriptor)
      throws DataMigrationException {
    // Context, XWiki
    XWikiContext context = getXWikiContext();
    XWiki xwiki = context.getWiki();

    // Delete the old object
    oldWikiDescriptor.removeXObject(oldObject);

    // Save the document
    try {
      xwiki.saveDocument(
          oldWikiDescriptor, "Remove the old WorkspaceManager.WorkspaceClass object.", context);
    } catch (XWikiException e) {
      throw new DataMigrationException(
          String.format(
              "Failed to save the document [%s] to remove the WorkspaceManager.WorkspaceClass object.",
              oldWikiDescriptor.getDocumentReference().toString()),
          e);
    }
  }
コード例 #2
0
  /**
   * Convert the old WorkspaceManager.WorkspaceCandidateMemberClass objects to the new candidacies
   * format.
   *
   * @param wikiId id of the wiki to upgrade
   * @throws XWikiException if problems occur
   */
  private void upgradeWorkspaceCandidacies(String wikiId) throws XWikiException {
    XWikiContext xcontext = getXWikiContext();
    XWiki xwiki = xcontext.getWiki();

    // We need to get the document that holds the candidacies
    DocumentReference candidaciesDocumentReference =
        new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup");
    XWikiDocument candidaciesDocument = xwiki.getDocument(candidaciesDocumentReference, xcontext);

    // We need to get all the old candidacies
    DocumentReference oldCandidateClassReference =
        new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "WorkspaceCandidateMemberClass");
    List<BaseObject> candidacyObjects = candidaciesDocument.getXObjects(oldCandidateClassReference);
    if (candidacyObjects != null) {
      DocumentReference newCandidateClassReference =
          new DocumentReference(
              wikiId,
              WikiCandidateMemberClassInitializer.DOCUMENT_SPACE,
              WikiCandidateMemberClassInitializer.DOCUMENT_NAME);

      for (BaseObject oldObject : candidacyObjects) {
        if (oldObject == null) {
          continue;
        }
        // Transform the candidacy to the new class
        BaseObject newObject = candidaciesDocument.newXObject(newCandidateClassReference, xcontext);
        newObject.setStringValue(
            WikiCandidateMemberClassInitializer.FIELD_TYPE, oldObject.getStringValue("type"));
        newObject.setStringValue(
            WikiCandidateMemberClassInitializer.FIELD_STATUS, oldObject.getStringValue("status"));
        newObject.setStringValue(
            WikiCandidateMemberClassInitializer.FIELD_USER, oldObject.getStringValue("userName"));
        newObject.setLargeStringValue(
            WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT,
            oldObject.getLargeStringValue("userComment"));
        newObject.setStringValue(
            WikiCandidateMemberClassInitializer.FIELD_ADMIN, oldObject.getStringValue("reviewer"));
        newObject.setLargeStringValue(
            WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT,
            oldObject.getLargeStringValue("reviewerComment"));
        newObject.setLargeStringValue(
            WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT,
            oldObject.getLargeStringValue("reviewerPrivateComment"));
        newObject.setDateValue(
            WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION,
            oldObject.getDateValue("date"));
        newObject.setDateValue(
            WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE,
            oldObject.getDateValue("resolutionDate"));

        // Remove the old object
        candidaciesDocument.removeXObject(oldObject);
      }

      // Save
      xwiki.saveDocument(
          candidaciesDocument,
          "Upgrade candidacies from the old Workspace Application to the "
              + "new Wiki Application.",
          xcontext);
    }
  }