use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiStats method fromXML.
/**
* Initialize statistics object from XML schema.
*
* @param oel the XML root node containing statistics datas.
* @throws XWikiException error when parsing XML schema.
*/
public void fromXML(Element oel) throws XWikiException {
Element cel = oel.element("class");
BaseClass bclass = new BaseClass();
if (cel != null) {
bclass.fromXML(cel);
setClassName(bclass.getName());
}
setName(oel.element(XMLNODE_NAME).getText());
List<?> list = oel.elements(XMLNODE_PROPERTY);
for (int i = 0; i < list.size(); i++) {
Element pcel = (Element) ((Element) list.get(i)).elements().get(0);
String name = pcel.getName();
PropertyClass pclass = (PropertyClass) bclass.get(name);
if (pclass != null) {
BaseProperty property = pclass.newPropertyfromXML(pcel);
property.setName(name);
property.setObject(this);
safeput(name, property);
}
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class RightsManager method removeUserOrGroupFromAllRights.
/**
* Remove all references to provided user or group from all rights documents.
*
* @param userOrGroupWiki the name of the wiki of the use or group.
* @param userOrGroupSpace the name of the space of the use or group.
* @param userOrGroupName the name of the use or group.
* @param user indicate if it is a user or a group.
* @param context the XWiki context.
* @throws XWikiException error when browsing rights.
*/
public void removeUserOrGroupFromAllRights(String userOrGroupWiki, String userOrGroupSpace, String userOrGroupName, boolean user, XWikiContext context) throws XWikiException {
List<String> parameterValues = new ArrayList<String>();
String fieldName;
if (user) {
fieldName = RIGHTSFIELD_USERS;
} else {
fieldName = RIGHTSFIELD_GROUPS;
}
BaseClass rightClass = context.getWiki().getRightsClass(context);
BaseClass globalRightClass = context.getWiki().getGlobalRightsClass(context);
String fieldTypeName = ((PropertyClass) rightClass.get(fieldName)).newProperty().getClass().getSimpleName();
StringBuilder where = new StringBuilder(", BaseObject as obj" + ", " + fieldTypeName + " as prop where doc.fullName=obj.name" + " and (obj.className=? or obj.className=?)");
parameterValues.add(rightClass.getName());
parameterValues.add(globalRightClass.getName());
where.append(" and obj.id=prop.id.id");
where.append(" and prop.name=?");
parameterValues.add(fieldName);
where.append(" and prop.value like ?");
if (context.getWikiId() == null || context.getWikiId().equalsIgnoreCase(userOrGroupWiki)) {
if (userOrGroupSpace == null || userOrGroupSpace.equals(DEFAULT_USERORGROUP_SPACE)) {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupName + HQLLIKE_ALL_SYMBOL);
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupSpace + SPACEPAGENAME_SEP + userOrGroupName + HQLLIKE_ALL_SYMBOL);
}
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupWiki + WIKIFULLNAME_SEP + userOrGroupName + HQLLIKE_ALL_SYMBOL);
}
List<XWikiDocument> documentList = context.getWiki().getStore().searchDocuments(where.toString(), parameterValues, context);
for (XWikiDocument groupDocument : documentList) {
if (removeUserOrGroupFromAllRights(groupDocument, userOrGroupWiki, userOrGroupSpace, userOrGroupName, user, context)) {
context.getWiki().saveDocument(groupDocument, context);
}
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class ObjectsResourceImpl method addObject.
@Override
public Response addObject(String wikiName, String spaceName, String pageName, Boolean minorRevision, Object object) throws XWikiRestException {
if (object.getClassName() == null) {
throw new WebApplicationException(Status.BAD_REQUEST);
}
try {
List<String> spaces = parseSpaceSegments(spaceName);
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaces, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
BaseObject xwikiObject = xwikiDocument.newObject(object.getClassName(), Utils.getXWikiContext(componentManager));
if (xwikiObject == null) {
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
// We must initialize all the fields to an empty value in order to correctly create the object
BaseClass xwikiClass = Utils.getXWiki(componentManager).getClass(xwikiObject.getClassName(), Utils.getXWikiContext(componentManager));
for (java.lang.Object propertyNameObject : xwikiClass.getPropertyNames()) {
String propertyName = (String) propertyNameObject;
xwikiObject.set(propertyName, "", Utils.getXWikiContext(componentManager));
}
for (Property property : object.getProperties()) {
xwikiObject.set(property.getName(), property.getValue(), Utils.getXWikiContext(componentManager));
}
doc.save("", Boolean.TRUE.equals(minorRevision));
return Response.created(Utils.createURI(uriInfo.getBaseUri(), ObjectResource.class, wikiName, spaces, pageName, object.getClassName(), xwikiObject.getNumber())).entity(DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, xwikiObject, false, Utils.getXWikiApi(componentManager), false)).build();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class PageTagsResourceImpl method setTags.
@Override
public Response setTags(String wikiName, String spaceName, String pageName, Boolean minorRevision, Tags tags) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
List<String> tagNames = new ArrayList<String>();
for (Tag tag : tags.getTags()) {
tagNames.add(tag.getName());
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
BaseObject xwikiObject = xwikiDocument.getObject("XWiki.TagClass", 0);
if (xwikiObject == null) {
int objectNumber = xwikiDocument.createNewObject("XWiki.TagClass", Utils.getXWikiContext(componentManager));
xwikiObject = xwikiDocument.getObject("XWiki.TagClass", objectNumber);
if (xwikiObject == null) {
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
// We must initialize all the fields to an empty value in order to correctly create the object
BaseClass xwikiClass = Utils.getXWiki(componentManager).getClass(xwikiObject.getClassName(), Utils.getXWikiContext(componentManager));
for (Object propertyNameObject : xwikiClass.getPropertyNames()) {
String propertyName = (String) propertyNameObject;
xwikiObject.set(propertyName, "", Utils.getXWikiContext(componentManager));
}
}
xwikiObject.set("tags", tagNames, Utils.getXWikiContext(componentManager));
doc.save("", Boolean.TRUE.equals(minorRevision));
return Response.status(Status.ACCEPTED).entity(tags).build();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class DefaultClassPropertyValuesProvider method getPropertyType.
private String getPropertyType(ClassPropertyReference propertyReference) throws XWikiRestException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(propertyReference.getParent(), xcontext);
BaseClass xclass = document.getXClass();
PropertyInterface xproperty = xclass.get(propertyReference.getName());
if (xproperty instanceof PropertyClass) {
return ((PropertyClass) xproperty).getClassType();
} else {
throw new XWikiRestException(String.format("No such property [%s].", this.entityReferenceSerializer.serialize(propertyReference)));
}
} catch (XWikiException e) {
throw new XWikiRestException(String.format("Failed to determine the property type for [{}].", this.entityReferenceSerializer.serialize(propertyReference)));
}
}
Aggregations