Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import org.xwiki.model.reference.WikiReference;

import com.celements.model.classes.fields.ClassField;
import com.google.common.collect.ImmutableList;

@ComponentRole
public interface ClassDefinition extends ClassIdentity {

ImmutableList<String> LANG_FIELD_NAMES = ImmutableList.of("lang", "language");
List<String> LANG_FIELD_NAMES = List.of("lang", "language");

String CFG_SRC_KEY = "celements.classdefinition.blacklist";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.celements.model.classes.ClassDefinition;
import com.google.common.base.Strings;
import com.xpn.xwiki.objects.PropertyInterface;
import com.xpn.xwiki.objects.classes.PropertyClass;

/**
Expand Down Expand Up @@ -124,7 +123,7 @@ public String getValidationMessage() {
}

@Override
public PropertyInterface getXField() {
public PropertyClass getXField() {
PropertyClass element = getPropertyClass();
element.setName(name);
if (prettyName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.xwiki.model.reference.ClassReference;

import com.celements.model.classes.ClassDefinition;
import com.xpn.xwiki.objects.PropertyInterface;
import com.xpn.xwiki.objects.classes.PropertyClass;

public interface ClassField<T> {

Expand All @@ -26,7 +26,7 @@ public interface ClassField<T> {
Class<T> getType();

@NotNull
PropertyInterface getXField();
PropertyClass getXField();

@NotNull
String serialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.celements.model.classes.ClassDefinition;
import com.celements.model.object.ObjectFetcher;
import com.xpn.xwiki.objects.PropertyInterface;
import com.xpn.xwiki.objects.classes.PropertyClass;

/**
* A plain {@link ClassField} without the necessity of a backing {@link ClassDefinition}.
Expand Down Expand Up @@ -49,7 +49,7 @@ public Class<T> getType() {
}

@Override
public PropertyInterface getXField() {
public PropertyClass getXField() {
throw new UnsupportedOperationException("PlainClassField not generateable");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import static com.celements.common.test.CelementsTestUtils.*;
import static com.celements.model.classes.TestClassDefinition.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -44,10 +44,8 @@ public void prepareTest() throws Exception {
private BaseClass expectClass(ClassDefinition classDef, WikiReference wikiRef)
throws XWikiException {
BaseClass bClass = expectNewBaseObject(classDef.getDocRef(wikiRef));
for (ClassField<?> field : classDef.getFields()) {
expect(bClass.get(field.getName())).andReturn(field.getXField()).anyTimes();
}
return bClass;
return expectPropertyClasses(bClass, classDef.getFields().stream()
.collect(Collectors.toMap(ClassField::getName, ClassField::getXField)));
}

@Test
Expand Down Expand Up @@ -95,7 +93,7 @@ public void test_noFields() throws Exception {
@Test
public void test_noObj() throws Exception {
replayDefault();
new ExceptionAsserter<BeanLoadException>(BeanLoadException.class) {
new ExceptionAsserter<>(BeanLoadException.class) {

@Override
protected void execute() throws BeanLoadException {
Expand All @@ -110,7 +108,7 @@ protected void execute() throws BeanLoadException {
public void test_notInitialized() throws Exception {
loader = Utils.getComponent(XDocBeanLoader.class);
replayDefault();
new ExceptionAsserter<IllegalStateException>(IllegalStateException.class) {
new ExceptionAsserter<>(IllegalStateException.class) {

@Override
protected void execute() throws IllegalStateException, BeanLoadException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
import org.xwiki.model.EntityType;
Expand Down Expand Up @@ -40,10 +42,8 @@ public void prepareTest() throws Exception {
private BaseClass expectClass(ClassDefinition classDef, WikiReference wikiRef)
throws XWikiException {
BaseClass bClass = expectNewBaseObject(classDef.getDocRef(wikiRef));
for (ClassField<?> field : classDef.getFields()) {
expect(bClass.get(field.getName())).andReturn(field.getXField()).anyTimes();
}
return bClass;
return expectPropertyClasses(bClass, classDef.getFields().stream()
.collect(Collectors.toMap(ClassField::getName, ClassField::getXField)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.celements.model.field;

import static com.celements.common.test.CelementsTestUtils.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
import org.xwiki.model.reference.ClassReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.WikiReference;

import com.celements.common.test.AbstractComponentTest;
import com.celements.common.test.ExceptionAsserter;
Expand All @@ -32,15 +34,14 @@ public void prepareTest() throws Exception {
accessor = (XObjectFieldAccessor) Utils.getComponent(FieldAccessor.class,
XObjectFieldAccessor.NAME);
testClassDef = Utils.getComponent(ClassDefinition.class, TestClassDefinition.NAME);
expectClass(testClassDef);
expectClass(testClassDef, getXContext().getWikiRef());
}

private static BaseClass expectClass(ClassDefinition classDef) throws XWikiException {
BaseClass bClass = expectNewBaseObject(classDef.getDocRef());
for (ClassField<?> field : classDef.getFields()) {
expect(bClass.get(field.getName())).andReturn(field.getXField()).anyTimes();
}
return bClass;
private BaseClass expectClass(ClassDefinition classDef, WikiReference wikiRef)
throws XWikiException {
BaseClass bClass = expectNewBaseObject(classDef.getDocRef(wikiRef));
return expectPropertyClasses(bClass, classDef.getFields().stream()
.collect(Collectors.toMap(ClassField::getName, ClassField::getXField)));
}

@Test
Expand Down Expand Up @@ -90,14 +91,14 @@ public void test_FieldAccessException_invalidXClass() {
final ClassField<String> field = TestClassDefinition.FIELD_MY_STRING;
final BaseObject obj = new BaseObject();
obj.setXClassReference(new ClassReference("space", "class"));
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
accessor.get(obj, field);
}
}.evaluate();
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
Expand All @@ -111,14 +112,14 @@ public void test_FieldAccessException_pseudoClass() {
final ClassField<String> field = XWikiDocumentClass.FIELD_CONTENT;
final BaseObject obj = new BaseObject();
obj.setXClassReference(new ClassReference("space", "class"));
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
accessor.get(obj, field);
}
}.evaluate();
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
Expand All @@ -132,23 +133,23 @@ public void test_FieldAccessException_setValue_xObjFields() {
final BaseObject obj = new BaseObject();
final ClassReference classRef = testClassDef.getClassReference();
obj.setXClassReference(classRef);
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
accessor.set(obj, XWikiObjectClass.FIELD_CLASS_REF, classRef);
}
}.evaluate();
final DocumentReference docRef = new DocumentReference("wiki", "space", "doc");
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
accessor.set(obj, XWikiObjectClass.FIELD_DOC_REF, docRef);
}
}.evaluate();
final Integer number = 5;
new ExceptionAsserter<FieldAccessException>(FieldAccessException.class) {
new ExceptionAsserter<>(FieldAccessException.class) {

@Override
protected void execute() throws FieldAccessException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.celements.wiki;

import java.net.URI;

import org.xwiki.model.reference.WikiReference;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

public record WikiDescriptor(
WikiReference wiki,
String prettyName,
String server,
Visibility visibility,
State state,
String language,
Boolean secure,
Boolean oicd,
URI uri) {

@JsonIgnore
public WikiReference wiki() {
return wiki;
}

@JsonProperty("wiki")
public String wikiName() {
return (wiki != null) ? wiki.getName() : null;
}

public enum Visibility {
PUBLIC, PRIVATE
}

public enum State {
ACTIVE, INACTIVE, LOCKED
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package com.celements.wiki;

import java.util.List;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.WikiReference;

import com.celements.wiki.exception.WikiDescriptorException;
import com.celements.wiki.exception.WikiMissingException;

public interface WikiDescriptorService {

@NotNull
DocumentReference getDescriptorDocRef(@NotNull WikiReference wikiRef);

@NotNull
List<WikiDescriptor> getDescriptors(@NotNull WikiReference wikiRef) throws WikiMissingException;

void createDescriptor(@NotNull WikiReference wikiRef, @NotEmpty String host)
throws WikiDescriptorException;

void deleteDescriptors(@NotNull WikiReference wikiRef) throws WikiDescriptorException;

boolean isOicdEnabled(@NotNull WikiReference wikiRef);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.celements.wiki.exception;

import org.xwiki.model.reference.WikiReference;

public class WikiDescriptorException extends WikiException {

private static final long serialVersionUID = 1L;

public WikiDescriptorException(WikiReference wikiRef, Throwable cause) {
super(wikiRef, cause);
}

}
5 changes: 5 additions & 0 deletions celements-wiki-manager/component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<artifactId>celements-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-spring-security</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-wiki-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static java.util.Objects.*;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -128,7 +127,7 @@ void notifyWikiCreatingEvent(WikiReference wikiRef) {
XWikiUser userPrev = ectx.set(XWIKI_USER, new XWikiUser(SUPERADMIN_FQN, true));
try {
eventPublisher.publishEvent(new WikiCreatingEvent(wikiRef));
wikiUpdater.getFuture(wikiRef).ifPresent(CompletableFuture::join);
wikiUpdater.awaitCompletion(wikiRef);
} finally {
ectx.set(XWIKI_USER, userPrev);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private WikiReference convertMainWiki(WikiReference wikiRef) {
return wikiRef;
}

private Optional<URI> toUri(Integer secure, String host) {
public Optional<URI> toUri(Integer secure, String host) {
try {
return Optional.of(UriComponentsBuilder.newInstance()
.scheme(Optional.ofNullable(secure)
Expand Down
Loading