From 37b832b0b89fd6ee345b34e7717eaac354b954d4 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 01:17:07 +0545 Subject: [PATCH 01/14] Get IP-Address of local machine --- .../operp/server/data/service/items/impl/ItemServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index f6b02e45..5c13ce09 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -87,4 +87,8 @@ protected Item findByEntityName(String entityName) { return itemRepository.findByItemName(entityName); } + @Override + public void registerClient(String clientAddress) { + System.out.println("Client from " + clientAddress); + } } From 2f11bcecda1c0f50b1f5dd3007e9a15e608fb9f1 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 16:34:29 +0545 Subject: [PATCH 02/14] Able to make bean programmatically for TestClass --- .../service/items/impl/ItemServiceImpl.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index 5c13ce09..7cfa2ebe 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -2,6 +2,11 @@ import javax.inject.Inject; +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import devopsdistilled.operp.server.data.entity.items.Brand; @@ -21,6 +26,9 @@ public class ItemServiceImpl extends @Inject private ItemRepository itemRepository; + @Inject + private ApplicationContext context; + @Override protected ItemRepository getRepo() { return itemRepository; @@ -90,5 +98,29 @@ protected Item findByEntityName(String entityName) { @Override public void registerClient(String clientAddress) { System.out.println("Client from " + clientAddress); + // + // RmiProxyFactoryBean rmiProxy = new RmiProxyFactoryBean(); + // rmiProxy.setServiceInterface(ItemModel.class); + // String serviceName = + // rmiProxy.getServiceInterface().getCanonicalName(); + // rmiProxy.setServiceUrl("rmi://" + clientAddress + ":1099/" + // + serviceName); + + // TestClass testing = new TestClass(); + + AutowireCapableBeanFactory factory = context + .getAutowireCapableBeanFactory(); + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; + GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClass(TestClass.class); + beanDefinition.setAutowireCandidate(true); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + propertyValues.addPropertyValue("property", "Just a sample"); + beanDefinition.setPropertyValues(propertyValues); + + registry.registerBeanDefinition("testClass", beanDefinition); + + System.out.println(context.getBean(TestClass.class)); } } From c7e46125325bf5f2d813af1d25804c7b0cbf79b5 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 17:20:29 +0545 Subject: [PATCH 03/14] Remove RmiExporterBean for EntityModel --- .../client/context/items/EntityModelContext.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/context/items/EntityModelContext.java b/OpERP/src/main/java/devopsdistilled/operp/client/context/items/EntityModelContext.java index 5cf7e9a8..0240eb55 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/context/items/EntityModelContext.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/context/items/EntityModelContext.java @@ -41,4 +41,16 @@ public ManufacturerModel manufacturerModel() { return new ManufacturerModelImpl(); } +// @Bean +// public RmiServiceExporter rmiEmployeeServiceExporter() { +// RmiServiceExporter rmiServiceExportor = new RmiServiceExporter(); +// rmiServiceExportor.setServiceInterface(ItemModel.class); +// // String serviceName = rmiServiceExportor.getServiceInterface() +// // .getCanonicalName(); +// rmiServiceExportor.setServiceName("ItemModel"); +// rmiServiceExportor.setService(itemModel()); +// rmiServiceExportor.setRegistryPort(1099); +// System.out.println(rmiServiceExportor); +// return rmiServiceExportor; +// } } From 92e06b944a0c20075accfc2bdb6f553ef7c3be21 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 17:21:05 +0545 Subject: [PATCH 04/14] Make working bidirectional RMI connection --- .../items/models/impl/ItemModelImpl.java | 64 +++++++++++++++++++ .../data/service/items/ItemService.java | 2 + .../service/items/impl/ItemServiceImpl.java | 14 ++-- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java index 4e24b224..f635381e 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java @@ -1,7 +1,21 @@ package devopsdistilled.operp.client.items.models.impl; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.context.ApplicationContext; +import org.springframework.remoting.rmi.RmiServiceExporter; + import devopsdistilled.operp.client.abstracts.AbstractEntityModel; import devopsdistilled.operp.client.items.models.ItemModel; import devopsdistilled.operp.client.items.models.observers.ItemModelObserver; @@ -12,6 +26,9 @@ public class ItemModelImpl extends AbstractEntityModel implements ItemModel { + @Inject + private ApplicationContext context; + @Inject private ItemService service; @@ -20,4 +37,51 @@ public ItemService getService() { return service; } + @PostConstruct + public void registerWithServer() { + + AutowireCapableBeanFactory factory = context + .getAutowireCapableBeanFactory(); + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; + GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClass(RmiServiceExporter.class); + beanDefinition.setAutowireCandidate(true); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + propertyValues.addPropertyValue("serviceInterface", ItemModel.class); + propertyValues.addPropertyValue("serviceName", "ItemModel"); + propertyValues.addPropertyValue("service", this); + propertyValues.addPropertyValue("registryPort", "1099"); + beanDefinition.setPropertyValues(propertyValues); + + registry.registerBeanDefinition("itemModelServiceExporter", + beanDefinition); + System.out.println(context.getBean("itemModelServiceExporter")); + + try { + Enumeration networkInterfaces = NetworkInterface + .getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface network = networkInterfaces.nextElement(); + + if (!network.isUp() || network.isLoopback() + || network.isVirtual()) + continue; + + Enumeration addresses = network.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress netAddr = addresses.nextElement(); + + if (!netAddr.isLoopbackAddress() + && (netAddr instanceof Inet4Address)) { + service.registerClient(netAddr.getHostAddress()); + break; + } + + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + } } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java index aabd48f9..b4453096 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java @@ -16,4 +16,6 @@ boolean isProductBrandPairValidForItem(Long itemId, Product product, boolean isItemNameValidForItem(Long itemId, String itemName); + void registerClient(String clientAddress); + } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index 7cfa2ebe..67e33982 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -7,8 +7,10 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.ApplicationContext; +import org.springframework.remoting.rmi.RmiProxyFactoryBean; import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.items.models.ItemModel; import devopsdistilled.operp.server.data.entity.items.Brand; import devopsdistilled.operp.server.data.entity.items.Item; import devopsdistilled.operp.server.data.entity.items.Product; @@ -112,15 +114,17 @@ public void registerClient(String clientAddress) { .getAutowireCapableBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClass(TestClass.class); + beanDefinition.setBeanClass(RmiProxyFactoryBean.class); beanDefinition.setAutowireCandidate(true); MutablePropertyValues propertyValues = new MutablePropertyValues(); - propertyValues.addPropertyValue("property", "Just a sample"); + propertyValues.addPropertyValue("serviceInterface", ItemModel.class); + propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress + + ":1099/" + "ItemModel"); beanDefinition.setPropertyValues(propertyValues); - registry.registerBeanDefinition("testClass", beanDefinition); - - System.out.println(context.getBean(TestClass.class)); + registry.registerBeanDefinition("itemModelRmiProxyFactoryBean", + beanDefinition); + System.out.println(context.getBean("itemModelRmiProxyFactoryBean")); } } From 7c6c18e3256dc84c7cb68c7755445fed64eee239 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 17:23:22 +0545 Subject: [PATCH 05/14] Change serviceName for RMI Bean --- .../operp/client/items/models/impl/ItemModelImpl.java | 3 ++- .../operp/server/data/service/items/impl/ItemServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java index f635381e..f40463f5 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java @@ -49,7 +49,8 @@ public void registerWithServer() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("serviceInterface", ItemModel.class); - propertyValues.addPropertyValue("serviceName", "ItemModel"); + propertyValues.addPropertyValue("serviceName", + ItemModel.class.getCanonicalName()); propertyValues.addPropertyValue("service", this); propertyValues.addPropertyValue("registryPort", "1099"); beanDefinition.setPropertyValues(propertyValues); diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index 67e33982..8ec2b179 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -120,11 +120,11 @@ public void registerClient(String clientAddress) { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("serviceInterface", ItemModel.class); propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress - + ":1099/" + "ItemModel"); + + ":1099/" + ItemModel.class.getCanonicalName()); beanDefinition.setPropertyValues(propertyValues); registry.registerBeanDefinition("itemModelRmiProxyFactoryBean", beanDefinition); - System.out.println(context.getBean("itemModelRmiProxyFactoryBean")); + System.out.println(context.getBean("itemModelRmiProxyFactoryBean")); } } From f3fc5b4ffdf2ddef5bbffdc748b110e2f1df2c20 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 17:30:21 +0545 Subject: [PATCH 06/14] Get Bean with Class name --- .../operp/client/items/models/impl/ItemModelImpl.java | 3 ++- .../operp/server/data/service/items/impl/ItemServiceImpl.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java index f40463f5..7f393a36 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java @@ -57,7 +57,8 @@ public void registerWithServer() { registry.registerBeanDefinition("itemModelServiceExporter", beanDefinition); - System.out.println(context.getBean("itemModelServiceExporter")); + context.getBean("itemModelServiceExporter"); // Need this else + // NotBoundException try { Enumeration networkInterfaces = NetworkInterface diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index 8ec2b179..c99b2b29 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -125,6 +125,7 @@ public void registerClient(String clientAddress) { registry.registerBeanDefinition("itemModelRmiProxyFactoryBean", beanDefinition); - System.out.println(context.getBean("itemModelRmiProxyFactoryBean")); + System.out.println(context.getBean(ItemModel.class)); + } } From 82f49f919235dc49a37aef2f5da0e9b2310a83ff Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 17:36:40 +0545 Subject: [PATCH 07/14] Delegate registerWithServer() to super class --- .../client/abstracts/AbstractEntityModel.java | 68 +++++++++++++++++++ .../items/models/impl/ItemModelImpl.java | 58 +--------------- 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java index d4c21154..2012d21d 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java @@ -4,15 +4,34 @@ import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; import java.util.LinkedList; import java.util.List; +import javax.inject.Inject; + +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.context.ApplicationContext; +import org.springframework.remoting.rmi.RmiServiceExporter; + +import devopsdistilled.operp.client.items.models.ItemModel; import devopsdistilled.operp.server.data.entity.Entiti; import devopsdistilled.operp.server.data.service.EntityService; +import devopsdistilled.operp.server.data.service.items.ItemService; public abstract class AbstractEntityModel, ES extends EntityService, EO extends EntityModelObserver> extends AbstractModel implements EntityModel { + @Inject + private ApplicationContext context; + protected List entities; public AbstractEntityModel() { @@ -80,4 +99,53 @@ public void deleteAndUpdateModel(E entity) { getService().delete(entity); update(); } + + public void registerWithServer() { + AutowireCapableBeanFactory factory = context + .getAutowireCapableBeanFactory(); + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; + GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClass(RmiServiceExporter.class); + beanDefinition.setAutowireCandidate(true); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + propertyValues.addPropertyValue("serviceInterface", ItemModel.class); + propertyValues.addPropertyValue("serviceName", + ItemModel.class.getCanonicalName()); + propertyValues.addPropertyValue("service", this); + propertyValues.addPropertyValue("registryPort", "1099"); + beanDefinition.setPropertyValues(propertyValues); + + registry.registerBeanDefinition("itemModelServiceExporter", + beanDefinition); + context.getBean("itemModelServiceExporter"); // Need this else + // NotBoundException + + try { + Enumeration networkInterfaces = NetworkInterface + .getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface network = networkInterfaces.nextElement(); + + if (!network.isUp() || network.isLoopback() + || network.isVirtual()) + continue; + + Enumeration addresses = network.getInetAddresses(); + while (addresses.hasMoreElements()) { + InetAddress netAddr = addresses.nextElement(); + + if (!netAddr.isLoopbackAddress() + && (netAddr instanceof Inet4Address)) { + ((ItemService) getService()).registerClient(netAddr + .getHostAddress()); + break; + } + + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + } } diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java index 7f393a36..98d3ccf2 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java @@ -1,20 +1,9 @@ package devopsdistilled.operp.client.items.models.impl; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Enumeration; - import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.springframework.beans.MutablePropertyValues; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.ApplicationContext; -import org.springframework.remoting.rmi.RmiServiceExporter; import devopsdistilled.operp.client.abstracts.AbstractEntityModel; import devopsdistilled.operp.client.items.models.ItemModel; @@ -37,53 +26,10 @@ public ItemService getService() { return service; } + @Override @PostConstruct public void registerWithServer() { - AutowireCapableBeanFactory factory = context - .getAutowireCapableBeanFactory(); - BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; - GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClass(RmiServiceExporter.class); - beanDefinition.setAutowireCandidate(true); - - MutablePropertyValues propertyValues = new MutablePropertyValues(); - propertyValues.addPropertyValue("serviceInterface", ItemModel.class); - propertyValues.addPropertyValue("serviceName", - ItemModel.class.getCanonicalName()); - propertyValues.addPropertyValue("service", this); - propertyValues.addPropertyValue("registryPort", "1099"); - beanDefinition.setPropertyValues(propertyValues); - - registry.registerBeanDefinition("itemModelServiceExporter", - beanDefinition); - context.getBean("itemModelServiceExporter"); // Need this else - // NotBoundException - - try { - Enumeration networkInterfaces = NetworkInterface - .getNetworkInterfaces(); - while (networkInterfaces.hasMoreElements()) { - NetworkInterface network = networkInterfaces.nextElement(); - - if (!network.isUp() || network.isLoopback() - || network.isVirtual()) - continue; - - Enumeration addresses = network.getInetAddresses(); - while (addresses.hasMoreElements()) { - InetAddress netAddr = addresses.nextElement(); - - if (!netAddr.isLoopbackAddress() - && (netAddr instanceof Inet4Address)) { - service.registerClient(netAddr.getHostAddress()); - break; - } - - } - } - } catch (SocketException e) { - e.printStackTrace(); - } + super.registerWithServer(); } } From fd615dbdb8641244d226a0bfb8b8c6403e002f0c Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 18:09:29 +0545 Subject: [PATCH 08/14] Make registerWithServer() generic to all EntityModel --- .../client/abstracts/AbstractEntityModel.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java index 2012d21d..689e9288 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java @@ -21,7 +21,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.remoting.rmi.RmiServiceExporter; -import devopsdistilled.operp.client.items.models.ItemModel; import devopsdistilled.operp.server.data.entity.Entiti; import devopsdistilled.operp.server.data.service.EntityService; import devopsdistilled.operp.server.data.service.items.ItemService; @@ -109,17 +108,19 @@ public void registerWithServer() { beanDefinition.setAutowireCandidate(true); MutablePropertyValues propertyValues = new MutablePropertyValues(); - propertyValues.addPropertyValue("serviceInterface", ItemModel.class); - propertyValues.addPropertyValue("serviceName", - ItemModel.class.getCanonicalName()); + + Class serviceInterface = this.getClass().getInterfaces()[0]; + + propertyValues.addPropertyValue("serviceInterface", serviceInterface); + String serviceName = serviceInterface.getCanonicalName(); + propertyValues.addPropertyValue("serviceName", serviceName); propertyValues.addPropertyValue("service", this); propertyValues.addPropertyValue("registryPort", "1099"); beanDefinition.setPropertyValues(propertyValues); - registry.registerBeanDefinition("itemModelServiceExporter", - beanDefinition); - context.getBean("itemModelServiceExporter"); // Need this else - // NotBoundException + registry.registerBeanDefinition(serviceName, beanDefinition); + context.getBean(serviceName); // Need this else + // NotBoundException try { Enumeration networkInterfaces = NetworkInterface From c0fc92663978c1fa85af310e155a958a2d277bd0 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 19:03:56 +0545 Subject: [PATCH 09/14] Remove DescRow services --- .../service/business/SaleDescRowService.java | 7 ----- .../impl/BusinessDescRowServiceImpl.java | 20 -------------- .../business/impl/SaleDescRowServiceImpl.java | 26 ------------------- 3 files changed, 53 deletions(-) delete mode 100644 OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/SaleDescRowService.java delete mode 100644 OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescRowServiceImpl.java delete mode 100644 OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescRowServiceImpl.java diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/SaleDescRowService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/SaleDescRowService.java deleted file mode 100644 index 59cba75f..00000000 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/SaleDescRowService.java +++ /dev/null @@ -1,7 +0,0 @@ -package devopsdistilled.operp.server.data.service.business; - -import devopsdistilled.operp.server.data.entity.business.SaleDescRow; - -public interface SaleDescRowService extends BusinessDescRowService { - -} diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescRowServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescRowServiceImpl.java deleted file mode 100644 index 1dea4fc8..00000000 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescRowServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package devopsdistilled.operp.server.data.service.business.impl; - -import org.springframework.data.jpa.repository.JpaRepository; - -import devopsdistilled.operp.server.data.entity.business.BusinessDescRow; -import devopsdistilled.operp.server.data.service.business.BusinessDescRowService; -import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; - -public abstract class BusinessDescRowServiceImpl, R extends JpaRepository> - extends AbstractEntityService implements - BusinessDescRowService { - - private static final long serialVersionUID = 2019639925021618876L; - - @Override - protected D findByEntityName(String entityName) { - return null; - } - -} diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescRowServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescRowServiceImpl.java deleted file mode 100644 index c4fc7c9d..00000000 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescRowServiceImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package devopsdistilled.operp.server.data.service.business.impl; - -import javax.inject.Inject; - -import org.springframework.stereotype.Service; - -import devopsdistilled.operp.server.data.entity.business.SaleDescRow; -import devopsdistilled.operp.server.data.repo.business.SaleDescRowRepository; -import devopsdistilled.operp.server.data.service.business.SaleDescRowService; - -@Service -public class SaleDescRowServiceImpl extends - BusinessDescRowServiceImpl - implements SaleDescRowService { - - private static final long serialVersionUID = 3851649621319722826L; - - @Inject - private SaleDescRowRepository repo; - - @Override - protected SaleDescRowRepository getRepo() { - return repo; - } - -} From 8766b0690c3841048f4e4c8c9883bda307355dff Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 19:15:39 +0545 Subject: [PATCH 10/14] Modify to make registerClient generic to all Services --- .../client/abstracts/AbstractEntityModel.java | 6 +- .../purchases/models/PurchaseDescModel.java | 12 ++++ .../purchases/models/SaleDescModel.java | 11 +++ .../observers/PurchaseDescModelObserver.java | 7 ++ .../observers/SaleDescModelObserver.java | 7 ++ .../client/commons/models/AddressModel.java | 11 +++ .../commons/models/ContactInfoModel.java | 11 +++ .../observers/AddressModelObserver.java | 7 ++ .../observers/ContactInfoModelObserver.java | 7 ++ .../items/models/impl/ItemModelImpl.java | 12 ---- .../server/data/service/EntityService.java | 2 + .../account/impl/AccountServiceImpl.java | 5 +- .../impl/PaidTransactionServiceImpl.java | 6 +- .../impl/PayableAccountServiceImpl.java | 8 ++- .../impl/ReceivableAccountServiceImpl.java | 6 +- .../impl/ReceivedTransactionServiceImpl.java | 3 +- .../account/impl/TransactionServiceImpl.java | 5 +- .../impl/BusinessDescServiceImpl.java | 5 +- .../business/impl/BusinessServiceImpl.java | 6 +- .../impl/PurchaseDescServiceImpl.java | 8 ++- .../business/impl/PurchaseServiceImpl.java | 5 +- .../business/impl/SaleDescServiceImpl.java | 5 +- .../business/impl/SaleServiceImpl.java | 6 +- .../commons/impl/AddressServiceImpl.java | 5 +- .../commons/impl/ContactInfoServiceImpl.java | 6 +- .../employee/impl/EmployeeServiceImpl.java | 8 ++- .../service/impl/AbstractEntityService.java | 70 ++++++++++++++++++- .../data/service/items/ItemService.java | 2 - .../service/items/impl/BrandServiceImpl.java | 5 +- .../items/impl/CategoryServiceImpl.java | 8 ++- .../service/items/impl/ItemServiceImpl.java | 42 +---------- .../items/impl/ManufacturerServiceImpl.java | 6 +- .../items/impl/ProductServiceImpl.java | 5 +- .../party/impl/CustomerServiceImpl.java | 8 ++- .../service/party/impl/VendorServiceImpl.java | 5 +- .../stock/impl/StockKeeperServiceImpl.java | 6 +- .../service/stock/impl/StockServiceImpl.java | 5 +- .../stock/impl/WarehouseServiceImpl.java | 8 ++- 38 files changed, 238 insertions(+), 112 deletions(-) create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/PurchaseDescModel.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/SaleDescModel.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/PurchaseDescModelObserver.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/SaleDescModelObserver.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/commons/models/AddressModel.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/commons/models/ContactInfoModel.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/AddressModelObserver.java create mode 100644 OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/ContactInfoModelObserver.java diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java index 689e9288..6605d7f3 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java @@ -12,6 +12,7 @@ import java.util.LinkedList; import java.util.List; +import javax.annotation.PostConstruct; import javax.inject.Inject; import org.springframework.beans.MutablePropertyValues; @@ -23,7 +24,6 @@ import devopsdistilled.operp.server.data.entity.Entiti; import devopsdistilled.operp.server.data.service.EntityService; -import devopsdistilled.operp.server.data.service.items.ItemService; public abstract class AbstractEntityModel, ES extends EntityService, EO extends EntityModelObserver> extends AbstractModel implements EntityModel { @@ -99,6 +99,7 @@ public void deleteAndUpdateModel(E entity) { update(); } + @PostConstruct public void registerWithServer() { AutowireCapableBeanFactory factory = context .getAutowireCapableBeanFactory(); @@ -138,8 +139,7 @@ public void registerWithServer() { if (!netAddr.isLoopbackAddress() && (netAddr instanceof Inet4Address)) { - ((ItemService) getService()).registerClient(netAddr - .getHostAddress()); + getService().registerClient(netAddr.getHostAddress()); break; } diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/PurchaseDescModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/PurchaseDescModel.java new file mode 100644 index 00000000..ff343ebc --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/PurchaseDescModel.java @@ -0,0 +1,12 @@ +package devopsdistilled.operp.client.business.purchases.models; + +import devopsdistilled.operp.client.abstracts.EntityModel; +import devopsdistilled.operp.client.business.purchases.models.observers.PurchaseDescModelObserver; +import devopsdistilled.operp.server.data.entity.business.PurchaseDesc; +import devopsdistilled.operp.server.data.service.business.PurchaseDescService; + +public interface PurchaseDescModel + extends + EntityModel { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/SaleDescModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/SaleDescModel.java new file mode 100644 index 00000000..a19664b4 --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/SaleDescModel.java @@ -0,0 +1,11 @@ +package devopsdistilled.operp.client.business.purchases.models; + +import devopsdistilled.operp.client.abstracts.EntityModel; +import devopsdistilled.operp.client.business.purchases.models.observers.SaleDescModelObserver; +import devopsdistilled.operp.server.data.entity.business.SaleDesc; +import devopsdistilled.operp.server.data.service.business.SaleDescService; + +public interface SaleDescModel extends + EntityModel { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/PurchaseDescModelObserver.java b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/PurchaseDescModelObserver.java new file mode 100644 index 00000000..0e4b5064 --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/PurchaseDescModelObserver.java @@ -0,0 +1,7 @@ +package devopsdistilled.operp.client.business.purchases.models.observers; + +import devopsdistilled.operp.client.abstracts.EntityModelObserver; + +public interface PurchaseDescModelObserver extends EntityModelObserver { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/SaleDescModelObserver.java b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/SaleDescModelObserver.java new file mode 100644 index 00000000..85d41d03 --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/business/purchases/models/observers/SaleDescModelObserver.java @@ -0,0 +1,7 @@ +package devopsdistilled.operp.client.business.purchases.models.observers; + +import devopsdistilled.operp.client.abstracts.EntityModelObserver; + +public interface SaleDescModelObserver extends EntityModelObserver { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/AddressModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/AddressModel.java new file mode 100644 index 00000000..4b689579 --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/AddressModel.java @@ -0,0 +1,11 @@ +package devopsdistilled.operp.client.commons.models; + +import devopsdistilled.operp.client.abstracts.EntityModel; +import devopsdistilled.operp.client.commons.models.observers.AddressModelObserver; +import devopsdistilled.operp.server.data.entity.commons.Address; +import devopsdistilled.operp.server.data.service.commons.AddressService; + +public interface AddressModel extends + EntityModel { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/ContactInfoModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/ContactInfoModel.java new file mode 100644 index 00000000..8d14ab4c --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/ContactInfoModel.java @@ -0,0 +1,11 @@ +package devopsdistilled.operp.client.commons.models; + +import devopsdistilled.operp.client.abstracts.EntityModel; +import devopsdistilled.operp.client.commons.models.observers.ContactInfoModelObserver; +import devopsdistilled.operp.server.data.entity.commons.ContactInfo; +import devopsdistilled.operp.server.data.service.commons.ContactInfoService; + +public interface ContactInfoModel extends + EntityModel { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/AddressModelObserver.java b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/AddressModelObserver.java new file mode 100644 index 00000000..ab0ceb5d --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/AddressModelObserver.java @@ -0,0 +1,7 @@ +package devopsdistilled.operp.client.commons.models.observers; + +import devopsdistilled.operp.client.abstracts.EntityModelObserver; + +public interface AddressModelObserver extends EntityModelObserver { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/ContactInfoModelObserver.java b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/ContactInfoModelObserver.java new file mode 100644 index 00000000..abc5bc70 --- /dev/null +++ b/OpERP/src/main/java/devopsdistilled/operp/client/commons/models/observers/ContactInfoModelObserver.java @@ -0,0 +1,7 @@ +package devopsdistilled.operp.client.commons.models.observers; + +import devopsdistilled.operp.client.abstracts.EntityModelObserver; + +public interface ContactInfoModelObserver extends EntityModelObserver { + +} diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java index 98d3ccf2..4e24b224 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/items/models/impl/ItemModelImpl.java @@ -1,10 +1,7 @@ package devopsdistilled.operp.client.items.models.impl; -import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.springframework.context.ApplicationContext; - import devopsdistilled.operp.client.abstracts.AbstractEntityModel; import devopsdistilled.operp.client.items.models.ItemModel; import devopsdistilled.operp.client.items.models.observers.ItemModelObserver; @@ -15,9 +12,6 @@ public class ItemModelImpl extends AbstractEntityModel implements ItemModel { - @Inject - private ApplicationContext context; - @Inject private ItemService service; @@ -26,10 +20,4 @@ public ItemService getService() { return service; } - @Override - @PostConstruct - public void registerWithServer() { - - super.registerWithServer(); - } } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java index 8c07b0aa..38b051b8 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java @@ -13,4 +13,6 @@ public interface EntityService, ID extends Serializable> public boolean isEntityNameValidForTheEntity(ID id, String entityName); + void registerClient(String clientAddress); + } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/AccountServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/AccountServiceImpl.java index ab526581..94042a07 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/AccountServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/AccountServiceImpl.java @@ -2,11 +2,12 @@ import org.springframework.data.jpa.repository.JpaRepository; +import devopsdistilled.operp.client.abstracts.EntityModel; import devopsdistilled.operp.server.data.entity.account.Account; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; -public abstract class AccountServiceImpl, AR extends JpaRepository> - extends AbstractEntityService { +public abstract class AccountServiceImpl, AR extends JpaRepository, AM extends EntityModel> + extends AbstractEntityService { private static final long serialVersionUID = 8694809412525181588L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PaidTransactionServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PaidTransactionServiceImpl.java index 847602cb..6b24ece1 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PaidTransactionServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PaidTransactionServiceImpl.java @@ -7,14 +7,16 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import devopsdistilled.operp.client.account.models.PaidTransactionModel; import devopsdistilled.operp.server.data.entity.account.PaidTransaction; import devopsdistilled.operp.server.data.repo.account.PaidTransactionRepository; import devopsdistilled.operp.server.data.service.account.PaidTransactionService; import devopsdistilled.operp.server.data.service.account.PayableAccountService; @Service -public class PaidTransactionServiceImpl extends - TransactionServiceImpl +public class PaidTransactionServiceImpl + extends + TransactionServiceImpl implements PaidTransactionService { private static final long serialVersionUID = 8946536638729817665L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PayableAccountServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PayableAccountServiceImpl.java index 135a048e..d35156d6 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PayableAccountServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/PayableAccountServiceImpl.java @@ -4,14 +4,16 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.account.models.PayableAccountModel; import devopsdistilled.operp.server.data.entity.account.PayableAccount; import devopsdistilled.operp.server.data.repo.account.PayableAccountRepository; import devopsdistilled.operp.server.data.service.account.PayableAccountService; @Service -public class PayableAccountServiceImpl extends - AccountServiceImpl implements - PayableAccountService { +public class PayableAccountServiceImpl + extends + AccountServiceImpl + implements PayableAccountService { private static final long serialVersionUID = -2228578598359971560L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivableAccountServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivableAccountServiceImpl.java index c6f24d34..f8a21b08 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivableAccountServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivableAccountServiceImpl.java @@ -4,13 +4,15 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.account.models.ReceivableAccountModel; import devopsdistilled.operp.server.data.entity.account.ReceivableAccount; import devopsdistilled.operp.server.data.repo.account.ReceivableAccountRepository; import devopsdistilled.operp.server.data.service.account.ReceivableAccountService; @Service -public class ReceivableAccountServiceImpl extends - AccountServiceImpl +public class ReceivableAccountServiceImpl + extends + AccountServiceImpl implements ReceivableAccountService { private static final long serialVersionUID = -2228578598359971560L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivedTransactionServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivedTransactionServiceImpl.java index 1260e93c..ea5d140c 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivedTransactionServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/ReceivedTransactionServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import devopsdistilled.operp.client.account.models.ReceivedTransactionModel; import devopsdistilled.operp.server.data.entity.account.ReceivedTransaction; import devopsdistilled.operp.server.data.repo.account.ReceivedTransactionRepository; import devopsdistilled.operp.server.data.service.account.ReceivableAccountService; @@ -15,7 +16,7 @@ @Service public class ReceivedTransactionServiceImpl extends - TransactionServiceImpl + TransactionServiceImpl implements ReceivedTransactionService { private static final long serialVersionUID = -8134555856017276841L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/TransactionServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/TransactionServiceImpl.java index ea9c9c1f..90318847 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/TransactionServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/account/impl/TransactionServiceImpl.java @@ -2,11 +2,12 @@ import org.springframework.data.jpa.repository.JpaRepository; +import devopsdistilled.operp.client.abstracts.EntityModel; import devopsdistilled.operp.server.data.entity.account.Transaction; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; -public abstract class TransactionServiceImpl, TR extends JpaRepository> - extends AbstractEntityService { +public abstract class TransactionServiceImpl, TR extends JpaRepository, TM extends EntityModel> + extends AbstractEntityService { private static final long serialVersionUID = -4898201898165854461L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescServiceImpl.java index 83edb018..e8db52a7 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessDescServiceImpl.java @@ -2,12 +2,13 @@ import org.springframework.data.jpa.repository.JpaRepository; +import devopsdistilled.operp.client.abstracts.EntityModel; import devopsdistilled.operp.server.data.entity.business.BusinessDesc; import devopsdistilled.operp.server.data.service.business.BusinessDescService; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; -public abstract class BusinessDescServiceImpl, R extends JpaRepository> - extends AbstractEntityService implements +public abstract class BusinessDescServiceImpl, R extends JpaRepository, BDM extends EntityModel> + extends AbstractEntityService implements BusinessDescService { private static final long serialVersionUID = 2019639925021618876L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessServiceImpl.java index 076f84a8..d560e686 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/BusinessServiceImpl.java @@ -2,12 +2,14 @@ import org.springframework.data.jpa.repository.JpaRepository; +import devopsdistilled.operp.client.abstracts.EntityModel; import devopsdistilled.operp.server.data.entity.business.Business; import devopsdistilled.operp.server.data.service.business.BusinessService; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; -public abstract class BusinessServiceImpl, R extends JpaRepository> - extends AbstractEntityService implements BusinessService { +public abstract class BusinessServiceImpl, R extends JpaRepository, BM extends EntityModel> + extends AbstractEntityService implements + BusinessService { private static final long serialVersionUID = 2019639925021618876L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseDescServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseDescServiceImpl.java index 518ccf3a..0ef0beca 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseDescServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseDescServiceImpl.java @@ -4,14 +4,16 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.business.purchases.models.PurchaseDescModel; import devopsdistilled.operp.server.data.entity.business.PurchaseDesc; import devopsdistilled.operp.server.data.repo.business.PurchaseDescRepository; import devopsdistilled.operp.server.data.service.business.PurchaseDescService; @Service -public class PurchaseDescServiceImpl extends - BusinessDescServiceImpl implements - PurchaseDescService { +public class PurchaseDescServiceImpl + extends + BusinessDescServiceImpl + implements PurchaseDescService { private static final long serialVersionUID = 2688393943868408691L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseServiceImpl.java index 0ec47de1..988c49c6 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/PurchaseServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import devopsdistilled.operp.client.business.purchases.models.PurchaseModel; import devopsdistilled.operp.server.data.entity.account.PaidTransaction; import devopsdistilled.operp.server.data.entity.business.Purchase; import devopsdistilled.operp.server.data.entity.business.PurchaseDescRow; @@ -19,8 +20,8 @@ @Service public class PurchaseServiceImpl extends - BusinessServiceImpl implements - PurchaseService { + BusinessServiceImpl + implements PurchaseService { private static final long serialVersionUID = 2688393943868408691L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescServiceImpl.java index 66791853..f118a336 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleDescServiceImpl.java @@ -4,14 +4,15 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.business.purchases.models.SaleDescModel; import devopsdistilled.operp.server.data.entity.business.SaleDesc; import devopsdistilled.operp.server.data.repo.business.SaleDescRepository; import devopsdistilled.operp.server.data.service.business.SaleDescService; @Service public class SaleDescServiceImpl extends - BusinessDescServiceImpl implements - SaleDescService { + BusinessDescServiceImpl + implements SaleDescService { private static final long serialVersionUID = 2688393943868408691L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleServiceImpl.java index 082e1ade..99fdb91d 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/business/impl/SaleServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import devopsdistilled.operp.client.business.sales.models.SaleModel; import devopsdistilled.operp.server.data.entity.account.ReceivedTransaction; import devopsdistilled.operp.server.data.entity.business.Sale; import devopsdistilled.operp.server.data.entity.business.SaleDescRow; @@ -18,8 +19,9 @@ import devopsdistilled.operp.server.data.service.stock.StockKeeperService; @Service -public class SaleServiceImpl extends BusinessServiceImpl - implements SaleService { +public class SaleServiceImpl extends + BusinessServiceImpl implements + SaleService { private static final long serialVersionUID = 2688393943868408691L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/AddressServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/AddressServiceImpl.java index 9a8da80b..5070d5d8 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/AddressServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/AddressServiceImpl.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.commons.models.AddressModel; import devopsdistilled.operp.server.data.entity.commons.Address; import devopsdistilled.operp.server.data.repo.commons.AddressRepository; import devopsdistilled.operp.server.data.service.commons.AddressService; @@ -11,8 +12,8 @@ @Service public class AddressServiceImpl extends - AbstractEntityService implements - AddressService { + AbstractEntityService + implements AddressService { private static final long serialVersionUID = -8957185104379351117L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/ContactInfoServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/ContactInfoServiceImpl.java index 3cced516..6782ef0d 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/ContactInfoServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/commons/impl/ContactInfoServiceImpl.java @@ -4,14 +4,16 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.commons.models.ContactInfoModel; import devopsdistilled.operp.server.data.entity.commons.ContactInfo; import devopsdistilled.operp.server.data.repo.commons.ContactInfoRepository; import devopsdistilled.operp.server.data.service.commons.ContactInfoService; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; @Service -public class ContactInfoServiceImpl extends - AbstractEntityService +public class ContactInfoServiceImpl + extends + AbstractEntityService implements ContactInfoService { private static final long serialVersionUID = 3910975586559308476L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/employee/impl/EmployeeServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/employee/impl/EmployeeServiceImpl.java index ea314149..c487ba5b 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/employee/impl/EmployeeServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/employee/impl/EmployeeServiceImpl.java @@ -6,15 +6,17 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.employee.models.EmployeeModel; import devopsdistilled.operp.server.data.entity.employee.Employee; import devopsdistilled.operp.server.data.repo.employee.EmployeeRepository; import devopsdistilled.operp.server.data.service.employee.EmployeeService; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; @Service -public class EmployeeServiceImpl extends - AbstractEntityService implements - EmployeeService { +public class EmployeeServiceImpl + extends + AbstractEntityService + implements EmployeeService { private static final long serialVersionUID = 2648525777561781085L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java index 585e2625..81488ab7 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java @@ -1,23 +1,51 @@ package devopsdistilled.operp.server.data.service.impl; import java.io.Serializable; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.LinkedList; import java.util.List; +import javax.inject.Inject; + +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.remoting.rmi.RmiProxyFactoryBean; +import devopsdistilled.operp.client.abstracts.EntityModel; import devopsdistilled.operp.server.data.entity.Entiti; import devopsdistilled.operp.server.data.service.EntityService; -public abstract class AbstractEntityService, ID extends Serializable, ER extends JpaRepository> +public abstract class AbstractEntityService, ID extends Serializable, ER extends JpaRepository, EM extends EntityModel> implements EntityService { private static final long serialVersionUID = 4892118695516828793L; + @Inject + private ApplicationContext context; + protected abstract ER getRepo(); + protected List entityModels = new LinkedList<>(); + + public void registerEntityModel(EM entityModel) { + entityModels.add(entityModel); + } + + public void removeEntityModel(EM entityModel) { + int i = entityModels.indexOf(entityModel); + if (i >= 0) { + entityModels.remove(i); + } + } + @Override public boolean isEntityNameExists(String entityName) { E entity = findByEntityName(entityName); @@ -126,4 +154,44 @@ public void deleteAll() { public Iterable findAll(Iterable ids) { return getRepo().findAll(ids); } + + @Override + public void registerClient(String clientAddress) { + System.out.println("Client from " + clientAddress); + + AutowireCapableBeanFactory factory = context + .getAutowireCapableBeanFactory(); + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; + GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClass(RmiProxyFactoryBean.class); + beanDefinition.setAutowireCandidate(true); + + Class entityModelInterfaceClass = getEntityModelInterfaceClass(); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + propertyValues.addPropertyValue("serviceInterface", + entityModelInterfaceClass); + propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress + + ":1099/" + entityModelInterfaceClass.getCanonicalName()); + beanDefinition.setPropertyValues(propertyValues); + + registry.registerBeanDefinition( + entityModelInterfaceClass.getCanonicalName(), beanDefinition); + EM entityModel = context.getBean(entityModelInterfaceClass); + registerEntityModel(entityModel); + System.out.println(entityModel); + + } + + @SuppressWarnings("unchecked") + protected Class getEntityModelInterfaceClass() { + Type superclass = getClass().getGenericSuperclass(); + + Type[] typeArguments = ((ParameterizedType) superclass) + .getActualTypeArguments(); + Class observerClass = (Class) (typeArguments[typeArguments.length - 1]); + return observerClass; + + } + } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java index b4453096..aabd48f9 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/ItemService.java @@ -16,6 +16,4 @@ boolean isProductBrandPairValidForItem(Long itemId, Product product, boolean isItemNameValidForItem(Long itemId, String itemName); - void registerClient(String clientAddress); - } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/BrandServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/BrandServiceImpl.java index 4efc65fd..0217851b 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/BrandServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/BrandServiceImpl.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.items.models.BrandModel; import devopsdistilled.operp.server.data.entity.items.Brand; import devopsdistilled.operp.server.data.repo.items.BrandRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; @@ -11,8 +12,8 @@ @Service public class BrandServiceImpl extends - AbstractEntityService implements - BrandService { + AbstractEntityService + implements BrandService { private static final long serialVersionUID = -9026551460330247355L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/CategoryServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/CategoryServiceImpl.java index e8ed69ec..6315abef 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/CategoryServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/CategoryServiceImpl.java @@ -4,15 +4,17 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.items.models.CategoryModel; import devopsdistilled.operp.server.data.entity.items.Category; import devopsdistilled.operp.server.data.repo.items.CategoryRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; import devopsdistilled.operp.server.data.service.items.CategoryService; @Service -public class CategoryServiceImpl extends - AbstractEntityService implements - CategoryService { +public class CategoryServiceImpl + extends + AbstractEntityService + implements CategoryService { private static final long serialVersionUID = 7024824459392415034L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java index c99b2b29..a75b5a42 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ItemServiceImpl.java @@ -2,12 +2,6 @@ import javax.inject.Inject; -import org.springframework.beans.MutablePropertyValues; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.GenericBeanDefinition; -import org.springframework.context.ApplicationContext; -import org.springframework.remoting.rmi.RmiProxyFactoryBean; import org.springframework.stereotype.Service; import devopsdistilled.operp.client.items.models.ItemModel; @@ -20,7 +14,7 @@ @Service public class ItemServiceImpl extends - AbstractEntityService implements + AbstractEntityService implements ItemService { private static final long serialVersionUID = 7578267584162733059L; @@ -28,9 +22,6 @@ public class ItemServiceImpl extends @Inject private ItemRepository itemRepository; - @Inject - private ApplicationContext context; - @Override protected ItemRepository getRepo() { return itemRepository; @@ -97,35 +88,4 @@ protected Item findByEntityName(String entityName) { return itemRepository.findByItemName(entityName); } - @Override - public void registerClient(String clientAddress) { - System.out.println("Client from " + clientAddress); - // - // RmiProxyFactoryBean rmiProxy = new RmiProxyFactoryBean(); - // rmiProxy.setServiceInterface(ItemModel.class); - // String serviceName = - // rmiProxy.getServiceInterface().getCanonicalName(); - // rmiProxy.setServiceUrl("rmi://" + clientAddress + ":1099/" - // + serviceName); - - // TestClass testing = new TestClass(); - - AutowireCapableBeanFactory factory = context - .getAutowireCapableBeanFactory(); - BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; - GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClass(RmiProxyFactoryBean.class); - beanDefinition.setAutowireCandidate(true); - - MutablePropertyValues propertyValues = new MutablePropertyValues(); - propertyValues.addPropertyValue("serviceInterface", ItemModel.class); - propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress - + ":1099/" + ItemModel.class.getCanonicalName()); - beanDefinition.setPropertyValues(propertyValues); - - registry.registerBeanDefinition("itemModelRmiProxyFactoryBean", - beanDefinition); - System.out.println(context.getBean(ItemModel.class)); - - } } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ManufacturerServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ManufacturerServiceImpl.java index 091cfeae..8991bd34 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ManufacturerServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ManufacturerServiceImpl.java @@ -4,14 +4,16 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.items.models.ManufacturerModel; import devopsdistilled.operp.server.data.entity.items.Manufacturer; import devopsdistilled.operp.server.data.repo.items.ManufacturerRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; import devopsdistilled.operp.server.data.service.items.ManufacturerService; @Service -public class ManufacturerServiceImpl extends - AbstractEntityService +public class ManufacturerServiceImpl + extends + AbstractEntityService implements ManufacturerService { private static final long serialVersionUID = -6005274349296129598L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ProductServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ProductServiceImpl.java index bc067a9e..c036f499 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ProductServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/items/impl/ProductServiceImpl.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.items.models.ProductModel; import devopsdistilled.operp.server.data.entity.items.Product; import devopsdistilled.operp.server.data.repo.items.ProductRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; @@ -11,8 +12,8 @@ @Service public class ProductServiceImpl extends - AbstractEntityService implements - ProductService { + AbstractEntityService + implements ProductService { private static final long serialVersionUID = 8517308443607933958L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/CustomerServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/CustomerServiceImpl.java index 7d8cebed..8c763885 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/CustomerServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/CustomerServiceImpl.java @@ -6,15 +6,17 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.party.models.CustomerModel; import devopsdistilled.operp.server.data.entity.party.Customer; import devopsdistilled.operp.server.data.repo.party.CustomerRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; import devopsdistilled.operp.server.data.service.party.CustomerService; @Service -public class CustomerServiceImpl extends - AbstractEntityService implements - CustomerService { +public class CustomerServiceImpl + extends + AbstractEntityService + implements CustomerService { private static final long serialVersionUID = 7983273640225740161L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/VendorServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/VendorServiceImpl.java index 6b8006b8..17b80b3a 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/VendorServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/party/impl/VendorServiceImpl.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.party.models.VendorModel; import devopsdistilled.operp.server.data.entity.party.Vendor; import devopsdistilled.operp.server.data.repo.party.VendorRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; @@ -13,8 +14,8 @@ @Service public class VendorServiceImpl extends - AbstractEntityService implements - VendorService { + AbstractEntityService + implements VendorService { private static final long serialVersionUID = 7983273640225740161L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockKeeperServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockKeeperServiceImpl.java index 4f1a3cb7..e08375e1 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockKeeperServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockKeeperServiceImpl.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import devopsdistilled.operp.client.stock.models.StockKeeperModel; import devopsdistilled.operp.server.data.entity.stock.Stock; import devopsdistilled.operp.server.data.entity.stock.StockKeeper; import devopsdistilled.operp.server.data.repo.stock.StockKeeperRepository; @@ -17,8 +18,9 @@ import devopsdistilled.operp.server.data.service.stock.StockKeeperService; @Service -public class StockKeeperServiceImpl extends - AbstractEntityService +public class StockKeeperServiceImpl + extends + AbstractEntityService implements StockKeeperService { private static final long serialVersionUID = -1311042040845285500L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockServiceImpl.java index fc2dc5c1..bcceccc3 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/StockServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.stock.models.StockModel; import devopsdistilled.operp.server.data.entity.items.Item; import devopsdistilled.operp.server.data.entity.stock.Stock; import devopsdistilled.operp.server.data.entity.stock.Warehouse; @@ -18,8 +19,8 @@ @Service public class StockServiceImpl extends - AbstractEntityService implements - StockService { + AbstractEntityService + implements StockService { private static final long serialVersionUID = -7737068540744137395L; diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/WarehouseServiceImpl.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/WarehouseServiceImpl.java index 6b57ee72..7dcab6a6 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/WarehouseServiceImpl.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/stock/impl/WarehouseServiceImpl.java @@ -4,15 +4,17 @@ import org.springframework.stereotype.Service; +import devopsdistilled.operp.client.stock.models.WarehouseModel; import devopsdistilled.operp.server.data.entity.stock.Warehouse; import devopsdistilled.operp.server.data.repo.stock.WarehouseRepository; import devopsdistilled.operp.server.data.service.impl.AbstractEntityService; import devopsdistilled.operp.server.data.service.stock.WarehouseService; @Service -public class WarehouseServiceImpl extends - AbstractEntityService implements - WarehouseService { +public class WarehouseServiceImpl + extends + AbstractEntityService + implements WarehouseService { private static final long serialVersionUID = -460466203849182372L; From bedc75ee86b7b07c4983844bff750d3801019b39 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 19:19:26 +0545 Subject: [PATCH 11/14] Assemble to notify all clients registered with notifyClientsForUpdate() --- .../operp/server/data/service/EntityService.java | 2 ++ .../server/data/service/impl/AbstractEntityService.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java index 38b051b8..b3b79529 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/EntityService.java @@ -15,4 +15,6 @@ public interface EntityService, ID extends Serializable> void registerClient(String clientAddress); + void notifyClientsForUpdate(); + } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java index 81488ab7..8be771b5 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java @@ -46,6 +46,13 @@ public void removeEntityModel(EM entityModel) { } } + @Override + public void notifyClientsForUpdate() { + for (EM entityModel : entityModels) { + entityModel.update(); + } + } + @Override public boolean isEntityNameExists(String entityName) { E entity = findByEntityName(entityName); From 1c186c79c1fe9f79906e0eea4126b798d6e52dbc Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 19:20:03 +0545 Subject: [PATCH 12/14] Delegate server to update clients --- .../operp/client/abstracts/AbstractEntityModel.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java index 6605d7f3..de03b785 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java +++ b/OpERP/src/main/java/devopsdistilled/operp/client/abstracts/AbstractEntityModel.java @@ -86,17 +86,16 @@ private Method getUpdateMethod() { } @Override - // @Transactional public E saveAndUpdateModel(E entity) { E savedEntity = getService().save(entity); - update(); + getService().notifyClientsForUpdate(); return savedEntity; } @Override public void deleteAndUpdateModel(E entity) { getService().delete(entity); - update(); + getService().notifyClientsForUpdate(); } @PostConstruct From a505be82dee013a3e812526b81b640c2d89963a3 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 21:31:27 +0545 Subject: [PATCH 13/14] Remove Client EntityModel if not available --- .../server/data/service/impl/AbstractEntityService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java index 8be771b5..02af7398 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java @@ -17,6 +17,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.remoting.RemoteConnectFailureException; import org.springframework.remoting.rmi.RmiProxyFactoryBean; import devopsdistilled.operp.client.abstracts.EntityModel; @@ -49,7 +50,11 @@ public void removeEntityModel(EM entityModel) { @Override public void notifyClientsForUpdate() { for (EM entityModel : entityModels) { - entityModel.update(); + try { + entityModel.update(); + } catch (RemoteConnectFailureException e) { + entityModels.remove(entityModel); + } } } From 4a1dec59f55c8fecdc8c0f5fa3fe3685bb8a6ea5 Mon Sep 17 00:00:00 2001 From: Kapil Koju Date: Sat, 31 Aug 2013 21:40:35 +0545 Subject: [PATCH 14/14] Reference to ServerApp.context instead of injecting in services --- .../java/devopsdistilled/operp/server/ServerApp.java | 10 ++++++++-- .../data/service/impl/AbstractEntityService.java | 7 ++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/ServerApp.java b/OpERP/src/main/java/devopsdistilled/operp/server/ServerApp.java index f8f0843b..f307eb49 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/ServerApp.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/ServerApp.java @@ -7,6 +7,12 @@ public class ServerApp { + private static ApplicationContext context; + + public static ApplicationContext getApplicationContext() { + return context; + } + public static void main(String[] args) { if (args.length > 0 && args[0].equalsIgnoreCase("init")) @@ -14,9 +20,9 @@ public static void main(String[] args) { else System.setProperty("hibernate.hbm2ddl.auto", "update"); - ApplicationContext context = new AnnotationConfigApplicationContext( - AppContext.class); + context = new AnnotationConfigApplicationContext(AppContext.class); System.out.println(context); } + } diff --git a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java index 02af7398..f2c329ec 100644 --- a/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java +++ b/OpERP/src/main/java/devopsdistilled/operp/server/data/service/impl/AbstractEntityService.java @@ -6,8 +6,6 @@ import java.util.LinkedList; import java.util.List; -import javax.inject.Inject; - import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -21,6 +19,7 @@ import org.springframework.remoting.rmi.RmiProxyFactoryBean; import devopsdistilled.operp.client.abstracts.EntityModel; +import devopsdistilled.operp.server.ServerApp; import devopsdistilled.operp.server.data.entity.Entiti; import devopsdistilled.operp.server.data.service.EntityService; @@ -29,9 +28,6 @@ public abstract class AbstractEntityService, ID extends Seri private static final long serialVersionUID = 4892118695516828793L; - @Inject - private ApplicationContext context; - protected abstract ER getRepo(); protected List entityModels = new LinkedList<>(); @@ -171,6 +167,7 @@ public Iterable findAll(Iterable ids) { public void registerClient(String clientAddress) { System.out.println("Client from " + clientAddress); + ApplicationContext context = ServerApp.getApplicationContext(); AutowireCapableBeanFactory factory = context .getAutowireCapableBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory;