From 170ddebcd6db4a4fe8666ca0fb15af18015d8d0e Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Tue, 10 Mar 2015 16:39:05 +0100 Subject: [PATCH 1/7] config demo mode --- .../src/main/java/org/lightadmin/api/config/LightAdmin.java | 4 ++-- .../lightadmin/core/util/LightAdminConfigurationUtils.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java b/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java index 61c2e721..00318e7f 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java +++ b/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java @@ -72,8 +72,8 @@ public LightAdmin fileStreaming(boolean fileStreaming) { return this; } - public LightAdmin demoMode() { - servletContext.setInitParameter(LIGHT_ADMINISTRATION_DEMO_MODE, Boolean.toString(true)); + public LightAdmin demoMode(boolean demoMode) { + servletContext.setInitParameter(LIGHT_ADMINISTRATION_DEMO_MODE, Boolean.toString(demoMode)); return this; } } \ No newline at end of file diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/util/LightAdminConfigurationUtils.java b/lightadmin-core/src/main/java/org/lightadmin/core/util/LightAdminConfigurationUtils.java index 814ed927..00a139fa 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/util/LightAdminConfigurationUtils.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/util/LightAdminConfigurationUtils.java @@ -35,7 +35,7 @@ public class LightAdminConfigurationUtils { public static final String LIGHT_ADMIN_REST_URL_DEFAULT = "/rest"; - public static final String LIGHT_ADMIN_CUSTOM_LOGO_LOCATION = "/WEB-INF/admin/images/logo.png"; + public static final String LIGHT_ADMIN_CUSTOM_LOGO_LOCATION = "/images/customLogo.png"; public static final String LIGHT_ADMIN_DEFAULT_LOGO_LOCATION = "/images/loginLogo_2-1.png"; public static final String LIGHT_ADMIN_CUSTOM_FRAGMENT_SERVLET_URL = "/dynamic/custom"; From cc6e579b80457ee56d01f89db157b0e2a8bb11d7 Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Tue, 10 Mar 2015 16:39:22 +0100 Subject: [PATCH 2/7] fetch custom logo in classpath --- .../LightAdminWebApplicationInitializer.java | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/config/LightAdminWebApplicationInitializer.java b/lightadmin-core/src/main/java/org/lightadmin/core/config/LightAdminWebApplicationInitializer.java index 9251c21d..abd820b5 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/config/LightAdminWebApplicationInitializer.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/config/LightAdminWebApplicationInitializer.java @@ -15,7 +15,33 @@ */ package org.lightadmin.core.config; +import static org.apache.commons.io.FileUtils.getFile; +import static org.apache.commons.lang3.BooleanUtils.toBoolean; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMINISTRATION_BASE_PACKAGE; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMINISTRATION_BASE_URL; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMINISTRATION_FILE_STORAGE_PATH; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMINISTRATION_SECURITY; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_CUSTOM_FRAGMENT_SERVLET_URL; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_CUSTOM_LOGO_LOCATION; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_CUSTOM_RESOURCE_SERVLET_NAME; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_DEFAULT_LOGO_LOCATION; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_DISPATCHER_NAME; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_DISPATCHER_REDIRECTOR_NAME; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_LOGO_RESOURCE_SERVLET_NAME; +import static org.lightadmin.core.util.LightAdminConfigurationUtils.LIGHT_ADMIN_LOGO_SERVLET_URL; +import static org.springframework.core.Ordered.LOWEST_PRECEDENCE; + +import java.io.File; +import java.util.regex.Pattern; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.servlet.http.HttpServletRequest; + import net.sf.ehcache.constructs.web.filter.GzipFilter; + import org.lightadmin.core.config.bootstrap.LightAdminBeanDefinitionRegistryPostProcessor; import org.lightadmin.core.config.context.LightAdminContextConfiguration; import org.lightadmin.core.config.context.LightAdminSecurityConfiguration; @@ -23,6 +49,7 @@ import org.lightadmin.core.view.TilesContainerEnrichmentFilter; import org.lightadmin.core.web.DispatcherRedirectorServlet; import org.springframework.core.annotation.Order; +import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -34,19 +61,6 @@ import org.springframework.web.servlet.FrameworkServlet; import org.springframework.web.servlet.ResourceServlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; -import javax.servlet.http.HttpServletRequest; -import java.io.File; -import java.util.regex.Pattern; - -import static org.apache.commons.io.FileUtils.getFile; -import static org.apache.commons.lang3.BooleanUtils.toBoolean; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.lightadmin.core.util.LightAdminConfigurationUtils.*; -import static org.springframework.core.Ordered.LOWEST_PRECEDENCE; - @SuppressWarnings("unused") @Order(LOWEST_PRECEDENCE) public class LightAdminWebApplicationInitializer implements WebApplicationInitializer { @@ -130,13 +144,13 @@ private void registerLogoResourceServlet(final ServletContext servletContext) { customResourceServletRegistration.addMapping(resourceServletMapping(servletContext, LIGHT_ADMIN_LOGO_SERVLET_URL)); } - private ResourceServlet logoResourceServlet(ServletContext servletContext) { - Resource resource = servletContextResourceLoader(servletContext).getResource(LIGHT_ADMIN_CUSTOM_LOGO_LOCATION); - if (resource.exists()) { - return concreteResourceServlet(LIGHT_ADMIN_CUSTOM_LOGO_LOCATION); - } - return concreteResourceServlet(resourceServletMapping(servletContext, LIGHT_ADMIN_DEFAULT_LOGO_LOCATION)); - } + private ResourceServlet logoResourceServlet(ServletContext servletContext) { + Resource resource = new ClassPathResource("/META-INF/resources" + LIGHT_ADMIN_CUSTOM_LOGO_LOCATION); + if (resource.exists()) { + return concreteResourceServlet(resourceServletMapping(servletContext, LIGHT_ADMIN_CUSTOM_LOGO_LOCATION)); + } + return concreteResourceServlet(resourceServletMapping(servletContext, LIGHT_ADMIN_DEFAULT_LOGO_LOCATION)); + } private void registerTilesDecorationFilter(final ServletContext servletContext) { final String urlMapping = urlMapping(lightAdminBaseUrl(servletContext)); @@ -271,7 +285,8 @@ private ServletContextResourceLoader servletContextResourceLoader(ServletContext private ResourceServlet concreteResourceServlet(final String location) { return new ResourceServlet() { - { + private static final long serialVersionUID = 4602656496188884537L; + { setApplyLastModified(true); setContentType("image/png"); } From 99f0ebe2b794264e7b37d10d823f75c82ddbe58f Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Wed, 11 Mar 2015 19:48:33 +0100 Subject: [PATCH 3/7] default demo config builder --- .../src/main/java/org/lightadmin/api/config/LightAdmin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java b/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java index 00318e7f..81f7192a 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java +++ b/lightadmin-core/src/main/java/org/lightadmin/api/config/LightAdmin.java @@ -72,6 +72,10 @@ public LightAdmin fileStreaming(boolean fileStreaming) { return this; } + public LightAdmin demoMode() { + return demoMode(true); + } + public LightAdmin demoMode(boolean demoMode) { servletContext.setInitParameter(LIGHT_ADMINISTRATION_DEMO_MODE, Boolean.toString(demoMode)); return this; From 47231ba588610a18ed4465304492dde4eccb5061 Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Mon, 23 Mar 2015 10:25:04 +0100 Subject: [PATCH 4/7] EmptyConfig support for enums --- .../org/lightadmin/api/config/utils/EnumElement.java | 11 +++++++++++ .../EmptyConfigurationUnitPostProcessor.java | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/EnumElement.java b/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/EnumElement.java index 935f2560..d1b18b95 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/EnumElement.java +++ b/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/EnumElement.java @@ -16,6 +16,8 @@ package org.lightadmin.api.config.utils; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; public class EnumElement implements Serializable { @@ -48,5 +50,14 @@ public static EnumElement element(long value, String label) { public static EnumElement element(String value, String label) { return new EnumElement(value, label); } + + public static EnumElement[] enumElements(Class> clazz){ + List els = new ArrayList(); + for(Enum el : clazz.getEnumConstants()){ + els.add(EnumElement.element(el.name(), el.name())); + } + return els.toArray(new EnumElement[]{}); + } + } diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/config/domain/unit/processor/EmptyConfigurationUnitPostProcessor.java b/lightadmin-core/src/main/java/org/lightadmin/core/config/domain/unit/processor/EmptyConfigurationUnitPostProcessor.java index fe86d45f..47b01905 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/config/domain/unit/processor/EmptyConfigurationUnitPostProcessor.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/config/domain/unit/processor/EmptyConfigurationUnitPostProcessor.java @@ -17,6 +17,7 @@ import org.lightadmin.api.config.builder.FieldSetConfigurationUnitBuilder; import org.lightadmin.api.config.unit.FieldSetConfigurationUnit; +import org.lightadmin.api.config.utils.EnumElement; import org.lightadmin.core.config.domain.common.GenericFieldSetConfigurationUnitBuilder; import org.lightadmin.core.config.domain.unit.ConfigurationUnit; import org.lightadmin.core.config.domain.unit.ConfigurationUnits; @@ -66,10 +67,14 @@ public void doWithAssociation(Association> assoc return fieldSetConfigurationUnitBuilder.build(); } - - private void addField(PersistentProperty property, FieldSetConfigurationUnitBuilder fieldSetConfigurationUnitBuilder) { + + @SuppressWarnings("unchecked") + private void addField(PersistentProperty property, FieldSetConfigurationUnitBuilder fieldSetConfigurationUnitBuilder) { if (isSupportedAttributeType(PersistentPropertyType.forPersistentProperty(property))) { fieldSetConfigurationUnitBuilder.field(property.getName()).caption(capitalize(property.getName())); + if(PersistentPropertyType.ENUM.equals(PersistentPropertyType.forPersistentProperty(property))){ + fieldSetConfigurationUnitBuilder.enumeration(EnumElement.enumElements((Class>) property.getActualType())); + } } } From f83637a21f1df63207596cb7f4241e2802f04b99 Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Mon, 23 Mar 2015 12:30:41 +0100 Subject: [PATCH 5/7] disable anaylitics when not in demo mode --- .../views/sections/footer-section.jsp | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/lightadmin-core/src/main/resources/META-INF/resources/views/sections/footer-section.jsp b/lightadmin-core/src/main/resources/META-INF/resources/views/sections/footer-section.jsp index 4ea417cb..02ca7697 100644 --- a/lightadmin-core/src/main/resources/META-INF/resources/views/sections/footer-section.jsp +++ b/lightadmin-core/src/main/resources/META-INF/resources/views/sections/footer-section.jsp @@ -1,5 +1,5 @@ <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %> - +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> @@ -9,42 +9,45 @@ - + - - - - \ No newline at end of file + + + + + + + \ No newline at end of file From b4f4aeca3f880c1ac7953245abded6017172dbb9 Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Mon, 23 Mar 2015 17:31:41 +0100 Subject: [PATCH 6/7] fieldCollection support --- .../lightadmin/api/config/utils/Editors.java | 14 +++++---- .../metamodel/PersistentPropertyType.java | 5 ++++ .../tags/form/EditControlDispatcherTag.java | 10 ++++++- .../lightadmin-formview-controller.js | 28 +++++++++++++---- .../scripts/lightadmin-serializer.js | 30 +++++++++++-------- .../editors/collection-field-edit-control.jsp | 21 +++++++++++++ 6 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 lightadmin-core/src/main/resources/META-INF/resources/views/editors/collection-field-edit-control.jsp diff --git a/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/Editors.java b/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/Editors.java index a0238d90..2bea35b6 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/Editors.java +++ b/lightadmin-core/src/main/java/org/lightadmin/api/config/utils/Editors.java @@ -15,18 +15,22 @@ */ package org.lightadmin.api.config.utils; -import org.lightadmin.core.view.editor.EnumFieldEditControl; -import org.lightadmin.core.view.editor.JspFragmentFieldControl; - -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; import static java.util.Arrays.asList; import static org.lightadmin.api.config.utils.EnumElement.element; +import java.util.List; + +import org.lightadmin.core.view.editor.EnumFieldEditControl; +import org.lightadmin.core.view.editor.JspFragmentFieldControl; + @SuppressWarnings("unused") public abstract class Editors { + public static JspFragmentFieldControl collection() { + return new JspFragmentFieldControl("/views/editors/collection-field-edit-control.jsp"); + } + public static JspFragmentFieldControl textArea() { return new JspFragmentFieldControl("/views/editors/textarea-field-edit-control.jsp"); } diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/persistence/metamodel/PersistentPropertyType.java b/lightadmin-core/src/main/java/org/lightadmin/core/persistence/metamodel/PersistentPropertyType.java index 779b90fc..6fd813b8 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/persistence/metamodel/PersistentPropertyType.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/persistence/metamodel/PersistentPropertyType.java @@ -50,6 +50,7 @@ public enum PersistentPropertyType { ENUM, EMBEDDED, MAP, + COLLECTION, UNKNOWN; public static PersistentPropertyType forPersistentProperty(PersistentProperty persistentProperty) { @@ -74,6 +75,10 @@ public static PersistentPropertyType forPersistentProperty(PersistentProperty pe return ENUM; } + if (persistentProperty.isCollectionLike()) { + return PersistentPropertyType.COLLECTION; + } + if (forType(attrType) == STRING && persistentProperty.isAnnotationPresent(FileReference.class)) { return PersistentPropertyType.FILE; } diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/view/tags/form/EditControlDispatcherTag.java b/lightadmin-core/src/main/java/org/lightadmin/core/view/tags/form/EditControlDispatcherTag.java index 557699e7..1e48c8a1 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/view/tags/form/EditControlDispatcherTag.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/view/tags/form/EditControlDispatcherTag.java @@ -42,6 +42,7 @@ public class EditControlDispatcherTag extends SimpleTagSupport { private JspFragment n2oneEditControl; private JspFragment n2manyEditControl; private JspFragment mapEditControl; + private JspFragment collectionEditControl; @Override public void doTag() throws JspException, IOException { @@ -71,6 +72,9 @@ private void doWithStandardControl() throws JspException, IOException { case MAP: worker = mapEditControl; break; + case COLLECTION: + worker = collectionEditControl; + break; case BOOL: worker = booleanEditControl; break; @@ -142,7 +146,11 @@ public void setMapEditControl(JspFragment control) { this.mapEditControl = control; } - public void setFileEditControl(final JspFragment fileEditControl) { + public void setCollectionEditControl(JspFragment collectionEditControl) { + this.collectionEditControl = collectionEditControl; + } + + public void setFileEditControl(final JspFragment fileEditControl) { this.fileEditControl = fileEditControl; } diff --git a/lightadmin-core/src/main/resources/META-INF/resources/scripts/controllers/lightadmin-formview-controller.js b/lightadmin-core/src/main/resources/META-INF/resources/scripts/controllers/lightadmin-formview-controller.js index 4ac04087..19a3acdf 100644 --- a/lightadmin-core/src/main/resources/META-INF/resources/scripts/controllers/lightadmin-formview-controller.js +++ b/lightadmin-core/src/main/resources/META-INF/resources/scripts/controllers/lightadmin-formview-controller.js @@ -161,16 +161,32 @@ function LoadDomainEntityAction(resourceName) { var property = fields[fieldIdx]; var propertyName = property['name']; var propertyType = property['type']; - - var editor = form.find('[name="' + propertyName + '"]'); - if (editor.length == 0) { - continue; - } - + var propertyValue = domainEntity.getPropertyValue(property, 'formView'); if (propertyValue == null) { continue; } + + var editors = form.find('[name="' + propertyName + '[]"]'); + if (editors.length > 0) { + var lastEditor = $(editors[0]); + for (var propertyValueIdx in propertyValue) { + var ePropertyValue = propertyValue[propertyValueIdx]; + if(ePropertyValue != null){ + lastEditor.val(ePropertyValue); + nextEditor = $(""); + lastEditor.after(nextEditor); + lastEditor.after("
"); + lastEditor = nextEditor; + } + } + continue; + } + + var editor = form.find('[name="' + propertyName + '"]'); + if (editor.length == 0) { + continue; + } switch (propertyType) { case 'ASSOC': diff --git a/lightadmin-core/src/main/resources/META-INF/resources/scripts/lightadmin-serializer.js b/lightadmin-core/src/main/resources/META-INF/resources/scripts/lightadmin-serializer.js index 191b9f70..1fb5761d 100644 --- a/lightadmin-core/src/main/resources/META-INF/resources/scripts/lightadmin-serializer.js +++ b/lightadmin-core/src/main/resources/META-INF/resources/scripts/lightadmin-serializer.js @@ -35,33 +35,37 @@ var json = {}; $.each(this.serializeArray(), function () { var attrVal = this.value || ''; - - var property = ConfigurationMetadataService.getProperty(resourceName, this.name, 'formView'); - + var propertyName = this.name.replace("[]", ""); + var property = ConfigurationMetadataService.getProperty(resourceName, propertyName, 'formView'); if (property == null) { - if ( isPartialPropertyField(this.name) && attrVal.length != 0) { - var main_property_name = this.name.substr(0, this.name.indexOf("_time")); + if ( isPartialPropertyField(propertyName) && attrVal.length != 0) { + var main_property_name = propertyName.substr(0, propertyName.indexOf("_time")); if (json[main_property_name] != null && json[main_property_name].length != 0) { json[main_property_name] = json[main_property_name] + 'T' + attrVal; } } return; } - var propertyType = property['type']; - - if (propertyType.indexOf('ASSOC') == 0) { + if (propertyType.indexOf('COLLECTION') == 0) { + if (!json[propertyName]) { + json[propertyName] = []; + } + if(attrVal != ''){ + json[propertyName].push(attrVal); + } + }else if (propertyType.indexOf('ASSOC') == 0) { var href = resolveObjectHref(attrVal, property); if (propertyType == 'ASSOC_MULTI') { - if (!json[this.name]) { - json[this.name] = []; + if (!json[propertyName]) { + json[propertyName] = []; } - json[this.name].push(href); + json[propertyName].push(href); } else { - json[this.name] = href; + json[propertyName] = href; } } else { - json[this.name] = attrVal; + json[propertyName] = attrVal; } }); diff --git a/lightadmin-core/src/main/resources/META-INF/resources/views/editors/collection-field-edit-control.jsp b/lightadmin-core/src/main/resources/META-INF/resources/views/editors/collection-field-edit-control.jsp new file mode 100644 index 00000000..e41f530d --- /dev/null +++ b/lightadmin-core/src/main/resources/META-INF/resources/views/editors/collection-field-edit-control.jsp @@ -0,0 +1,21 @@ +<%@ page import="org.lightadmin.core.persistence.metamodel.PersistentPropertyType" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="light" uri="http://www.lightadmin.org/tags" %> + + + + +
+Add Element + + \ No newline at end of file From bf03d59eba2ce30eb6a8b4b8661b85badd4bafbb Mon Sep 17 00:00:00 2001 From: Max Tuni Date: Wed, 24 Jun 2015 18:18:19 +0200 Subject: [PATCH 7/7] don't create new repositories if they already exist on the ApplicationContext --- ...inBeanDefinitionRegistryPostProcessor.java | 12 +++++-- ...htAdminRepositoryRestMvcConfiguration.java | 31 +++++++------------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/config/bootstrap/LightAdminBeanDefinitionRegistryPostProcessor.java b/lightadmin-core/src/main/java/org/lightadmin/core/config/bootstrap/LightAdminBeanDefinitionRegistryPostProcessor.java index 904e84ca..6ecacf89 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/config/bootstrap/LightAdminBeanDefinitionRegistryPostProcessor.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/config/bootstrap/LightAdminBeanDefinitionRegistryPostProcessor.java @@ -15,6 +15,7 @@ */ package org.lightadmin.core.config.bootstrap; +import org.apache.tika.metadata.Geographic; import org.lightadmin.core.config.bootstrap.parsing.validation.CompositeConfigurationUnitsValidator; import org.lightadmin.core.config.bootstrap.scanning.AdministrationClassScanner; import org.lightadmin.core.config.bootstrap.scanning.ClassScanner; @@ -33,6 +34,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.core.io.ResourceLoader; import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; +import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.core.event.AbstractRepositoryEventListener; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.orm.jpa.SharedEntityManagerCreator; @@ -44,6 +46,7 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.metamodel.EntityType; import javax.servlet.ServletContext; + import java.util.Set; import static com.google.common.collect.Sets.newHashSet; @@ -89,10 +92,13 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t registry.registerBeanDefinition(JPA_MAPPPING_CONTEXT_BEAN, mappingContext(entityManager)); registry.registerBeanDefinition(CONFIGURATION_UNITS_VALIDATOR_BEAN, configurationUnitsValidator(resourceLoader)); - + + Repositories repositories = new Repositories(rootContext); for (Class managedEntityType : managedEntities(entityManager)) { - Class repoInterface = createDynamicRepositoryClass(managedEntityType, entityManager); - registry.registerBeanDefinition(beanName(repoInterface), repositoryFactory(repoInterface, entityManager)); + if(!repositories.hasRepositoryFor(managedEntityType)){ + Class repoInterface = createDynamicRepositoryClass(managedEntityType, entityManager); + registry.registerBeanDefinition(beanName(repoInterface), repositoryFactory(repoInterface, entityManager)); + } } registerRepositoryEventListeners(configurationUnits, registry); diff --git a/lightadmin-core/src/main/java/org/lightadmin/core/config/context/LightAdminRepositoryRestMvcConfiguration.java b/lightadmin-core/src/main/java/org/lightadmin/core/config/context/LightAdminRepositoryRestMvcConfiguration.java index e643bb56..05a38543 100644 --- a/lightadmin-core/src/main/java/org/lightadmin/core/config/context/LightAdminRepositoryRestMvcConfiguration.java +++ b/lightadmin-core/src/main/java/org/lightadmin/core/config/context/LightAdminRepositoryRestMvcConfiguration.java @@ -15,9 +15,13 @@ */ package org.lightadmin.core.config.context; -import com.fasterxml.jackson.databind.ObjectMapper; +import static com.google.common.collect.Lists.newLinkedList; +import static org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess; +import static org.springframework.util.ClassUtils.isAssignableValue; + +import java.util.List; + import org.lightadmin.core.config.LightAdminConfiguration; -import org.lightadmin.core.config.bootstrap.RepositoriesFactoryBean; import org.lightadmin.core.config.domain.GlobalAdministrationConfiguration; import org.lightadmin.core.persistence.repository.event.FileManipulationRepositoryEventListener; import org.lightadmin.core.persistence.repository.invoker.DynamicRepositoryInvokerFactory; @@ -25,14 +29,16 @@ import org.lightadmin.core.storage.FileResourceStorage; import org.lightadmin.core.web.json.DomainTypeToJsonMetadataConverter; import org.lightadmin.core.web.json.LightAdminJacksonModule; -import org.lightadmin.core.web.support.*; -import org.springframework.beans.BeanInstantiationException; +import org.lightadmin.core.web.support.ConfigurationHandlerMethodArgumentResolver; +import org.lightadmin.core.web.support.DomainEntityLinks; +import org.lightadmin.core.web.support.DynamicPersistentEntityResourceAssemblerArgumentResolver; +import org.lightadmin.core.web.support.DynamicPersistentEntityResourceProcessor; +import org.lightadmin.core.web.support.DynamicRepositoryEntityLinks; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener; import org.springframework.data.rest.core.invoke.RepositoryInvokerFactory; @@ -44,11 +50,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; -import java.util.List; - -import static com.google.common.collect.Lists.newLinkedList; -import static org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess; -import static org.springframework.util.ClassUtils.isAssignableValue; +import com.fasterxml.jackson.databind.ObjectMapper; @Configuration @ComponentScan(basePackages = {"org.lightadmin.core.web"}, @@ -78,15 +80,6 @@ public DomainTypeToJsonMetadataConverter domainTypeToJsonMetadataConverter() { return new DomainTypeToJsonMetadataConverter(globalAdministrationConfiguration(), entityLinks()); } - @Bean - public Repositories repositories() { - try { - return new RepositoriesFactoryBean(beanFactory).getObject(); - } catch (Exception e) { - throw new BeanInstantiationException(Repositories.class, "Repositories bean instantiation problem!", e); - } - } - @Bean public DomainObjectMerger domainObjectMerger() throws Exception { return new DynamicDomainObjectMerger(repositories(), defaultConversionService(), globalAdministrationConfiguration());