Skip to content

Commit

Permalink
editor presentation model for crnk-ui #517
Browse files Browse the repository at this point in the history
  • Loading branch information
remmeier committed Jun 21, 2019
1 parent 472c278 commit edc91b1
Show file tree
Hide file tree
Showing 21 changed files with 866 additions and 415 deletions.
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.int";

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

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

public static final String ID_LONG = "base.long";
}
4 changes: 2 additions & 2 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,8 +10,6 @@
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 {

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 edc91b1

Please sign in to comment.