Esempio n. 1
0
  /** @deprecated since 2.2.3 use {@link com.xpn.xwiki.doc.XWikiDocument#newXObject} */
  @Deprecated
  public BaseCollection newObject(XWikiContext context) throws XWikiException {
    BaseObject bobj = newCustomClassInstance(context);
    DocumentReference classReference = getDocumentReference();
    bobj.setXClassReference(classReference.removeParent(classReference.getWikiReference()));

    return bobj;
  }
 @Override
 public Object doInHibernate(Session session) throws HibernateException, XWikiException {
   XWikiContext context = getXWikiContext();
   XWiki xwiki = context.getWiki();
   DocumentReference oldClassReference =
       new DocumentReference(context.getWikiId(), "ClinicalInformationCode", this.className);
   DocumentReference newClassReference =
       new DocumentReference(context.getWikiId(), Constants.CODE_SPACE, this.className);
   Query q =
       session.createQuery(
           "select distinct o.name from BaseObject o where o.className = '"
               + R45391PhenoTips434DataMigration.this.serializer.serialize(oldClassReference)
               + "'");
   @SuppressWarnings("unchecked")
   List<String> documents = q.list();
   for (String docName : documents) {
     XWikiDocument doc =
         xwiki.getDocument(
             R45391PhenoTips434DataMigration.this.resolver.resolve(docName), context);
     for (BaseObject oldObject : doc.getXObjects(oldClassReference)) {
       BaseObject newObject = oldObject.duplicate();
       newObject.setXClassReference(newClassReference);
       doc.addXObject(newObject);
     }
     doc.removeXObjects(oldClassReference);
     doc.setComment("Migrated patient data in class " + this.className);
     doc.setMinorEdit(true);
     try {
       // There's a bug in XWiki which prevents saving an object in the same session that it was
       // loaded,
       // so we must clear the session cache first.
       session.clear();
       ((XWikiHibernateStore) getStore()).saveXWikiDoc(doc, context, false);
       session.flush();
     } catch (DataMigrationException e) {
       // We're in the middle of a migration, we're not expecting another migration
     }
   }
   return null;
 }
  @Before
  public void before() throws Exception {
    Locale.setDefault(Locale.ROOT);

    // checking

    this.preferencesDocumentReference =
        new DocumentReference(
            this.oldcore.getXWikiContext().getWikiId(), "XWiki", "XWikiPreferences");

    XWikiDocument preferencesDocument = new XWikiDocument(this.preferencesDocumentReference);
    BaseObject preferencesObject = new BaseObject();
    preferencesObject.setXClassReference(
        new DocumentReference(
            this.oldcore.getXWikiContext().getWikiId(), "XWiki", "XWikiPreferences"));
    preferencesDocument.addXObject(preferencesObject);
    preferencesDocument.setSyntax(Syntax.PLAIN_1_0);
    this.oldcore
        .getMockXWiki()
        .saveDocument(preferencesDocument, "", this.oldcore.getXWikiContext());

    this.defaultWikiTranslationReference =
        new DocumentReference(this.oldcore.getXWikiContext().getWikiId(), "XWiki", "Translations");

    XWikiDocument defaultWikiTranslation = new XWikiDocument(this.defaultWikiTranslationReference);
    defaultWikiTranslation.setSyntax(Syntax.PLAIN_1_0);
    this.oldcore
        .getMockXWiki()
        .saveDocument(defaultWikiTranslation, "", this.oldcore.getXWikiContext());

    // MessageTool

    this.tool =
        new XWikiMessageTool(
            this.oldcore
                .getMocker()
                .<ContextualLocalizationManager>getInstance(ContextualLocalizationManager.class));
  }