Skip to content

Commit

Permalink
presentation model refinement for crnk-ui #517
Browse files Browse the repository at this point in the history
- editors
- full-text search
- labels how to present complex objects
  • Loading branch information
remmeier committed Jun 27, 2019
1 parent 5f1faf4 commit a5d0a86
Show file tree
Hide file tree
Showing 29 changed files with 1,462 additions and 719 deletions.
510 changes: 254 additions & 256 deletions crnk-meta/src/main/java/io/crnk/meta/model/MetaAttribute.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
@JsonApiResource(type = "meta/primitiveType")
public class MetaPrimitiveType extends MetaType {

public static final String ID_STRING = "base.string";

public static final String ID_INT = "base.integer";

public static final String ID_BYTE = "base.byte";

public static final String ID_SHORT = "base.short";

public static final String ID_LONG = "base.long";
}
26 changes: 23 additions & 3 deletions crnk-meta/src/main/java/io/crnk/meta/model/MetaType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.crnk.meta.model;

import java.lang.reflect.Type;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.crnk.core.engine.internal.utils.ClassUtils;
import io.crnk.core.engine.internal.utils.PreconditionUtil;
Expand All @@ -8,20 +10,27 @@
import io.crnk.core.resource.annotations.LookupIncludeBehavior;
import io.crnk.core.resource.annotations.SerializeType;

import java.lang.reflect.Type;

@JsonApiResource(type = "meta/type")
public class MetaType extends MetaElement {

@JsonIgnore
private Type implementationType;

private String implementationClassName;

@JsonApiRelation(serialize = SerializeType.LAZY, lookUp = LookupIncludeBehavior.AUTOMATICALLY_ALWAYS)
private MetaType elementType;

@JsonIgnore
public Class<?> getImplementationClass() {
return ClassUtils.getRawType(implementationType);
if (implementationType == null && implementationClassName != null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
implementationType = ClassUtils.loadClass(cl, implementationClassName);
}
if (implementationType != null) {
return ClassUtils.getRawType(implementationType);
}
return null;
}

public Type getImplementationType() {
Expand All @@ -30,6 +39,17 @@ public Type getImplementationType() {

public void setImplementationType(Type implementationType) {
this.implementationType = implementationType;
if (implementationType != null) {
this.implementationClassName = ClassUtils.getRawType(implementationType).getName();
}
}

public String getImplementationClassName() {
return implementationClassName;
}

public void setImplementationClassName(String implementationClassName) {
this.implementationClassName = implementationClassName;
}

@JsonIgnore
Expand Down
4 changes: 3 additions & 1 deletion crnk-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ task npmRunBuild(type: NpmTask) {

npmCommand = ['run', 'build']
args = ['--', '--base-href', './'] + NG_BUILD_ARGS
inputs.dir 'src'
inputs.dir 'src/app'
inputs.dir 'src/assets'
inputs.dir 'src/environments'
inputs.files 'angular-cli.json', 'package.json'
outputs.dir 'build/npm/io/crnk/ui'
}
Expand Down
188 changes: 100 additions & 88 deletions crnk-ui/src/main/java/io/crnk/ui/UIModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package io.crnk.ui;


import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import io.crnk.core.engine.internal.utils.ClassUtils;
import io.crnk.core.module.Module;
import io.crnk.core.module.ModuleExtension;
Expand All @@ -12,97 +18,103 @@
import io.crnk.ui.internal.UIHttpRequestProcessor;
import io.crnk.ui.presentation.PresentationManager;
import io.crnk.ui.presentation.PresentationService;
import io.crnk.ui.presentation.repository.EditorRepository;
import io.crnk.ui.presentation.repository.ExplorerRepository;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

public class UIModule implements Module {


private final UIModuleConfig config;

private ExplorerRepository explorerRepository;

private ModuleContext context;

// protected for CDI
protected UIModule() {
config = null;
}

protected UIModule(UIModuleConfig config) {
this.config = config;
}

public static UIModule create(UIModuleConfig config) {
return new UIModule(config);
}

public String getModuleName() {
return "ui";
}

private MetaLookup metaLookup;

private MetaLookup initMetaModule() {
if (metaLookup == null) {
Optional<MetaModule> optMetaModule = context.getModuleRegistry().getModule(MetaModule.class);
if (optMetaModule.isPresent()) {
metaLookup = optMetaModule.get().getLookup();
} else {
MetaModuleConfig config = new MetaModuleConfig();
config.addMetaProvider(new ResourceMetaProvider());

MetaLookupImpl impl = new MetaLookupImpl();
impl.setModuleContext(context);
config.apply(impl);
impl.initialize();
metaLookup = impl;
}
}
return metaLookup;
}

@Override
public void setupModule(ModuleContext context) {
this.context = context;
context.addHttpRequestProcessor(new UIHttpRequestProcessor(config));
setupHomeExtension(context);

if (config != null) {
Supplier<List<PresentationService>> servicesSupplier = config.getServices();
if (servicesSupplier == null) {
servicesSupplier = () -> Arrays.asList(new PresentationService("local", null, initMetaModule()));
}

PresentationManager manager = new PresentationManager(servicesSupplier);
explorerRepository = new ExplorerRepository(manager);
context.addRepository(explorerRepository);
}
}

public ExplorerRepository getExplorerRepository() {
return explorerRepository;
}

public UIModuleConfig getConfig() {
return config;
}

private void setupHomeExtension(ModuleContext context) {
if (ClassUtils.existsClass("io.crnk.home.HomeModuleExtension")) {
try {
Class clazz = Class.forName("io.crnk.ui.internal.UiHomeModuleExtensionFactory");
Method method = clazz.getMethod("create", UIModuleConfig.class);
ModuleExtension homeExtension = (ModuleExtension) method.invoke(clazz, config);
context.addExtension(homeExtension);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
private final UIModuleConfig config;

private ExplorerRepository explorerRepository;

private EditorRepository editorRepository;

private ModuleContext context;

// protected for CDI
protected UIModule() {
config = null;
}

protected UIModule(UIModuleConfig config) {
this.config = config;
}

public static UIModule create(UIModuleConfig config) {
return new UIModule(config);
}

public String getModuleName() {
return "ui";
}

private MetaLookup metaLookup;

private MetaLookup initMetaModule() {
if (metaLookup == null) {
Optional<MetaModule> optMetaModule = context.getModuleRegistry().getModule(MetaModule.class);
if (optMetaModule.isPresent()) {
metaLookup = optMetaModule.get().getLookup();
}
else {
MetaModuleConfig config = new MetaModuleConfig();
config.addMetaProvider(new ResourceMetaProvider());

MetaLookupImpl impl = new MetaLookupImpl();
impl.setModuleContext(context);
config.apply(impl);
impl.initialize();
metaLookup = impl;
}
}
return metaLookup;
}

@Override
public void setupModule(ModuleContext context) {
this.context = context;
context.addHttpRequestProcessor(new UIHttpRequestProcessor(config));
setupHomeExtension(context);

if (config != null) {
Supplier<List<PresentationService>> servicesSupplier = config.getServices();
if (servicesSupplier == null) {
servicesSupplier = () -> Arrays.asList(new PresentationService("local", null, initMetaModule()));
}

PresentationManager manager = new PresentationManager(servicesSupplier);
explorerRepository = new ExplorerRepository(manager);
context.addRepository(explorerRepository);
editorRepository = new EditorRepository(manager);
context.addRepository(editorRepository);
}
}

public ExplorerRepository getExplorerRepository() {
return explorerRepository;
}


public EditorRepository getEditorRepository() {
return editorRepository;
}

public UIModuleConfig getConfig() {
return config;
}

private void setupHomeExtension(ModuleContext context) {
if (ClassUtils.existsClass("io.crnk.home.HomeModuleExtension")) {
try {
Class clazz = Class.forName("io.crnk.ui.internal.UiHomeModuleExtensionFactory");
Method method = clazz.getMethod("create", UIModuleConfig.class);
ModuleExtension homeExtension = (ModuleExtension) method.invoke(clazz, config);
context.addExtension(homeExtension);
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
}
Loading

0 comments on commit a5d0a86

Please sign in to comment.