use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.
the class IndexedObjectReferenceTest method testConstructors.
/**
* Ensures the equivalence of constructors.
*/
@Test
public void testConstructors() {
IndexedObjectReference reference1 = new IndexedObjectReference(new EntityReference("XWiki.Class[2]", EntityType.OBJECT, new EntityReference("Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI)))));
IndexedObjectReference reference2 = new IndexedObjectReference("XWiki.Class", 2, new EntityReference("Page", EntityType.DOCUMENT, new EntityReference("Space", EntityType.SPACE, new EntityReference("wiki", EntityType.WIKI))));
assertEquals(reference1, reference2);
assertEquals(reference1.getClassName(), reference2.getClassName());
assertEquals(reference1.getObjectNumber(), reference2.getObjectNumber());
}
use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method testAuthorReference.
@Test
public void testAuthorReference() throws Exception {
XWikiContext context = mock(XWikiContext.class);
XWiki xwiki = mock(XWiki.class);
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference authorReference = mock(DocumentReference.class);
EntityReference entityReference = mock(EntityReference.class);
when(this.contextProvider.get()).thenReturn(context);
when(context.getWiki()).thenReturn(xwiki);
when(xwiki.getDocument(entityReference, context)).thenReturn(document);
when(document.getAuthorReference()).thenReturn(authorReference);
DocumentReference result = this.mocker.getComponentUnderTest().getAuthorReference(entityReference);
assertEquals(authorReference, result);
}
use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.
the class AbstractExtensionValidator method checkAccess.
protected void checkAccess(Right entityRight, String namespaceString, Request request) throws AccessDeniedException {
Namespace namespace = NamespaceUtils.toNamespace(namespaceString);
// Root namespace
if (namespace == null) {
checkRootRight(entityRight, request);
return;
}
if (namespace.getType() != null) {
// User
if (namespace.getType().equals("user")) {
EntityReference reference = this.resolver.resolve(namespace.getValue(), EntityType.DOCUMENT);
checkUserRight(reference, request);
return;
}
// Entity
EntityType entityType = EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase());
if (entityType != null) {
EntityReference reference = this.resolver.resolve(namespace.getValue(), entityType);
checkAccess(reference, entityRight, request);
return;
}
}
// Unknown namespace
checkNamespaceRight(namespace, Right.PROGRAM, request);
}
use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.
the class XClassMigratorListener method migrate.
private void migrate(PropertyClass newPropertyClass) throws QueryException {
ClassPropertyReference propertyReference = newPropertyClass.getReference();
EntityReference classReference = propertyReference.extractReference(EntityType.DOCUMENT);
EntityReference wikiReference = propertyReference.extractReference(EntityType.WIKI);
// Get all document containing object of modified class
Query query = this.queryManager.createQuery("from doc.object(" + this.localSerializer.serialize(classReference) + ") as obj", Query.XWQL);
query.setWiki(wikiReference.getName());
List<String> documents = query.execute();
if (!documents.isEmpty()) {
XWikiContext xcontext = this.xcontextProvider.get();
String currentWikiId = xcontext.getWikiId();
try {
// Switch to class wiki to be safer
xcontext.setWikiId(wikiReference.getName());
for (String documentName : documents) {
try {
migrate(newPropertyClass, documentName, xcontext);
} catch (XWikiException e) {
this.logger.error("Failed to migrate property [{}] in document [{}]", propertyReference, documentName, xcontext);
}
}
} finally {
// Restore context wiki
xcontext.setWikiId(currentWikiId);
}
}
}
use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.
the class AbstractSheetBinder method bind.
private boolean bind(DocumentModelBridge document, String sheetReferenceString) {
EntityReference sheetBindingClassReference = this.relativeReferenceResolver.resolve(getSheetBindingClass(), EntityType.DOCUMENT);
List<BaseObject> sheetBindingObjects = ((XWikiDocument) document).getXObjects(sheetBindingClassReference);
if (sheetBindingObjects != null) {
for (BaseObject sheetBindingObject : sheetBindingObjects) {
// The list of XWiki objects can contain null values due to a design flaw in the old XWiki core.
if (sheetBindingObject != null) {
String boundSheetStringRef = sheetBindingObject.getStringValue(SHEET_PROPERTY);
if (StringUtils.equals(boundSheetStringRef, sheetReferenceString)) {
return false;
}
}
}
}
try {
BaseObject sheetBindingObject = ((XWikiDocument) document).newXObject(sheetBindingClassReference, getXWikiContext());
sheetBindingObject.setStringValue(SHEET_PROPERTY, sheetReferenceString);
} catch (XWikiException e) {
String docStringReference = this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference());
this.logger.warn("Failed to bind sheet [{}] to document [{}].", sheetReferenceString, docStringReference);
return false;
}
return true;
}
Aggregations