From 90fa7f9669a5c0989bb5cfad6db16893dd532acf Mon Sep 17 00:00:00 2001 From: NaderSai Date: Wed, 16 Dec 2020 17:52:18 +0100 Subject: [PATCH 01/12] =?UTF-8?q?Voil=C3=A0=20mon=20Pull=20Request!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/pom.xml | 14 +++--- services/src/main/java/Main.java | 23 ++++++++++ .../addons/services/MyNewService.java | 30 +++++++++++++ .../services/MyNewStartableService.java | 43 +++++++++++++++++++ 4 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 services/src/main/java/Main.java create mode 100644 services/src/main/java/org/exoplatform/addons/services/MyNewService.java create mode 100644 services/src/main/java/org/exoplatform/addons/services/MyNewStartableService.java diff --git a/services/pom.xml b/services/pom.xml index ac4546e..483d053 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -4,11 +4,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.exoplatform.addons.training - training-exercices-parent + training-exercices-parent 1.0.x-SNAPSHOT 4.0.0 - training-exercises-services + training-exercises-services 1.0.x-SNAPSHOT @@ -33,14 +33,10 @@ org.exoplatform.social - social-component-core-jpa - 5.0.0-RC13 - - - org.exoplatform.social - social-component-core-jpa - 5.0.0-RC13 + social-component-core + 6.0.0 + Training Exercise - Services diff --git a/services/src/main/java/Main.java b/services/src/main/java/Main.java new file mode 100644 index 0000000..727b28f --- /dev/null +++ b/services/src/main/java/Main.java @@ -0,0 +1,23 @@ +package org.exoplatform.addons.services; + +import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.container.PortalContainer; +import org.picocontainer.Startable; +import org.exoplatform.services.log.*; + +/** + * + */ + +/** + * @author exo + * + */ +public class Main { + + public static void main(String[] args) { + PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer(); + MyNewStartableService myNewStartableService = (MyNewStartableService) portalContainer.getComponentInstance(MyNewStartableService.class); + myNewStartableService.start(); + } +} diff --git a/services/src/main/java/org/exoplatform/addons/services/MyNewService.java b/services/src/main/java/org/exoplatform/addons/services/MyNewService.java new file mode 100644 index 0000000..cc4c56d --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/services/MyNewService.java @@ -0,0 +1,30 @@ +package org.exoplatform.addons.services; + +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; + + + +/** + * + */ + +/** + * @author exo + * + */ +public class MyNewService { + /** + * The logger. + */ + private static final Log LOG = ExoLogger.getExoLogger(MyService.class); + + + public MyNewService() { + LOG.info("******************************** New Simple service started successfully !!"); + } + + public void call() { + LOG.info("************************* New call function invoked !!"); + } +} diff --git a/services/src/main/java/org/exoplatform/addons/services/MyNewStartableService.java b/services/src/main/java/org/exoplatform/addons/services/MyNewStartableService.java new file mode 100644 index 0000000..76282d6 --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/services/MyNewStartableService.java @@ -0,0 +1,43 @@ +package org.exoplatform.addons.services; + +import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.container.PortalContainer; +import org.picocontainer.Startable; +import org.exoplatform.services.log.*; + + + +/** + * + */ + +/** + * @author exo + * + */ +public class MyNewStartableService implements Startable { + /** + * The logger. + */ + private static final Log LOG = ExoLogger.getExoLogger(MyStartableService.class); + + @Override + public void start() { + LOG.info("*********************** My new Startable service started !"); + PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer(); + LOG.info("&&&&&&&&&&&& Getting an instance of MyService !"); + MyNewService myNewService = (MyNewService) portalContainer.getComponentInstance(MyNewService.class); + LOG.info("&&&&&&&&&&&& Calling function call of MyService !"); + myNewService.call(); + } + + @Override + public void stop() { + LOG.info("********************* My new Startable service stopped !"); + } + + + +} + + From c133e089877717f2f142aa13addf20d1c17a3d60 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Wed, 16 Dec 2020 18:01:39 +0100 Subject: [PATCH 02/12] updates --- services/src/main/java/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/main/java/Main.java b/services/src/main/java/Main.java index 727b28f..0e5b3a6 100644 --- a/services/src/main/java/Main.java +++ b/services/src/main/java/Main.java @@ -15,6 +15,7 @@ */ public class Main { + public static void main(String[] args) { PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer(); MyNewStartableService myNewStartableService = (MyNewStartableService) portalContainer.getComponentInstance(MyNewStartableService.class); From cace9810abb874b1ccfe278dcb921274dc94759c Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 17 Dec 2020 17:04:34 +0100 Subject: [PATCH 03/12] JUnit Tests --- output.log | 189 ++++++++++++++++++ services/output.log | 61 ++++++ services/pom.xml | 20 ++ services/src/main/java/Main.java | 5 +- .../addons/services/MyService.java | 5 +- .../addons/services/MyServiceTest.java | 57 ++++++ 6 files changed, 332 insertions(+), 5 deletions(-) create mode 100644 output.log create mode 100644 services/output.log create mode 100644 services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java diff --git a/output.log b/output.log new file mode 100644 index 0000000..ae8e9c7 --- /dev/null +++ b/output.log @@ -0,0 +1,189 @@ +[INFO] Scanning for projects... +[INFO] ------------------------------------------------------------------------ +[INFO] Reactor Build Order: +[INFO] +[INFO] Training addon - Parent [pom] +[INFO] Training Exercise - Services [jar] +[INFO] Training Exercises - Webapp [war] +[INFO] Training Exercises - Packaging [pom] +[INFO] +[INFO] -----< org.exoplatform.addons.training:training-exercices-parent >------ +[INFO] Building Training addon - Parent 1.0.x-SNAPSHOT [1/4] +[INFO] --------------------------------[ pom ]--------------------------------- +[INFO] +[INFO] --- maven-clean-plugin:2.6:clean (default-clean) @ training-exercices-parent --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java-version) @ training-exercices-parent --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-maven-version) @ training-exercices-parent --- +[INFO] +[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ training-exercices-parent --- +[INFO] Executing: /bin/sh -c cd /home/exo/addon-project-template && git rev-parse --verify HEAD +[INFO] Working directory: /home/exo/addon-project-template +[INFO] Storing buildNumber: c133e089877717f2f142aa13addf20d1c17a3d60 at timestamp: 20201217 +[INFO] Storing buildScmBranch: template/add-services +[INFO] +[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (parse-version) @ training-exercices-parent --- +[INFO] +[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ training-exercices-parent --- +[INFO] +[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ training-exercices-parent --- +[INFO] Installing /home/exo/addon-project-template/pom.xml to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercices-parent/1.0.x-SNAPSHOT/training-exercices-parent-1.0.x-SNAPSHOT.pom +[INFO] +[INFO] ----< org.exoplatform.addons.training:training-exercises-services >----- +[INFO] Building Training Exercise - Services 1.0.x-SNAPSHOT [2/4] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-clean-plugin:2.6:clean (default-clean) @ training-exercises-services --- +[INFO] Deleting /home/exo/addon-project-template/services/target +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java-version) @ training-exercises-services --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-maven-version) @ training-exercises-services --- +[INFO] +[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ training-exercises-services --- +[INFO] +[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ training-exercises-services --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] Copying 3 resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ training-exercises-services --- +[INFO] Changes detected - recompiling the module! +[INFO] Compiling 6 source files to /home/exo/addon-project-template/services/target/classes +[WARNING] bootstrap class path not set in conjunction with -source 7 +[WARNING] source value 7 is obsolete and will be removed in a future release +[WARNING] target value 7 is obsolete and will be removed in a future release +[WARNING] To suppress warnings about obsolete options, use -Xlint:-options. +[WARNING] Exo JPA entity detected: org.exoplatform.addons.entity.FavouriteActivity +[WARNING] Supported source version 'RELEASE_5' from annotation processor 'org.chromattic.apt.ChromatticProcessor' less than -source '7' +[INFO] +[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ training-exercises-services --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] skip non existing resourceDirectory /home/exo/addon-project-template/services/src/test/resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ training-exercises-services --- +[INFO] No sources to compile +[INFO] +[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ training-exercises-services --- +[INFO] No tests to run. +[INFO] +[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (parse-version) @ training-exercises-services --- +[INFO] +[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ training-exercises-services --- +[INFO] Building jar: /home/exo/addon-project-template/services/target/training-exercises-services.jar +[INFO] +[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ training-exercises-services --- +[INFO] Building jar: /home/exo/addon-project-template/services/target/training-exercises-services-sources.jar +[INFO] +[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ training-exercises-services --- +[INFO] Installing /home/exo/addon-project-template/services/target/training-exercises-services.jar to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT.jar +[INFO] Installing /home/exo/addon-project-template/services/pom.xml to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT.pom +[INFO] Installing /home/exo/addon-project-template/services/target/training-exercises-services-sources.jar to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT-sources.jar +[INFO] +[INFO] -----< org.exoplatform.addons.training:training-exercises-webapp >------ +[INFO] Building Training Exercises - Webapp 1.0.x-SNAPSHOT [3/4] +[INFO] --------------------------------[ war ]--------------------------------- +[INFO] +[INFO] --- maven-clean-plugin:2.6:clean (default-clean) @ training-exercises-webapp --- +[INFO] Deleting /home/exo/addon-project-template/war/target +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java-version) @ training-exercises-webapp --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-maven-version) @ training-exercises-webapp --- +[INFO] +[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ training-exercises-webapp --- +[INFO] +[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ training-exercises-webapp --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] skip non existing resourceDirectory /home/exo/addon-project-template/war/src/main/resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ training-exercises-webapp --- +[INFO] No sources to compile +[INFO] +[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ training-exercises-webapp --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] skip non existing resourceDirectory /home/exo/addon-project-template/war/src/test/resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ training-exercises-webapp --- +[INFO] No sources to compile +[INFO] +[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ training-exercises-webapp --- +[INFO] No tests to run. +[INFO] +[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (parse-version) @ training-exercises-webapp --- +[INFO] +[INFO] --- maven-war-plugin:2.5:war (default-war) @ training-exercises-webapp --- +[INFO] Packaging webapp +[INFO] Assembling webapp [training-exercises-webapp] in [/home/exo/addon-project-template/war/target/training-exercises-extension] +[INFO] Processing war project +[INFO] Copying webapp resources [/home/exo/addon-project-template/war/src/main/webapp] +[INFO] Webapp assembled in [35 msecs] +[INFO] Building war: /home/exo/addon-project-template/war/target/training-exercises-extension.war +[INFO] +[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ training-exercises-webapp --- +[INFO] No sources in project. Archive not created. +[INFO] +[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ training-exercises-webapp --- +[INFO] Installing /home/exo/addon-project-template/war/target/training-exercises-extension.war to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-webapp/1.0.x-SNAPSHOT/training-exercises-webapp-1.0.x-SNAPSHOT.war +[INFO] Installing /home/exo/addon-project-template/war/pom.xml to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-webapp/1.0.x-SNAPSHOT/training-exercises-webapp-1.0.x-SNAPSHOT.pom +[INFO] +[INFO] ----< org.exoplatform.addons.training:training-exercices-packaging >---- +[INFO] Building Training Exercises - Packaging 1.0.x-SNAPSHOT [4/4] +[INFO] --------------------------------[ pom ]--------------------------------- +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/exoplatform/social/social-component-core/5.0.1/social-component-core-5.0.1.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/exoplatform/social/social-component-core/5.0.1/social-component-core-5.0.1.pom (18 kB at 28 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/exoplatform/social/social-component-core/5.0.1/social-component-core-5.0.1.jar +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/com/google/protobuf/protobuf-java/2.4.1/protobuf-java-2.4.1.jar +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/com/google/protobuf/protobuf-java/2.4.1/protobuf-java-2.4.1.jar (450 kB at 1.4 MB/s) +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/exoplatform/social/social-component-core/5.0.1/social-component-core-5.0.1.jar (965 kB at 1.8 MB/s) +[INFO] +[INFO] --- maven-clean-plugin:2.6:clean (default-clean) @ training-exercices-packaging --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java-version) @ training-exercices-packaging --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-maven-version) @ training-exercices-packaging --- +[INFO] +[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ training-exercices-packaging --- +[INFO] +[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (parse-version) @ training-exercices-packaging --- +[INFO] +[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ training-exercices-packaging --- +[INFO] +[INFO] --- maven-assembly-plugin:2.5:single (package-addon) @ training-exercices-packaging --- +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-archiver/2.8.2/plexus-archiver-2.8.2.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-archiver/2.8.2/plexus-archiver-2.8.2.pom (4.1 kB at 50 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-io/2.3.3/plexus-io-2.3.3.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-io/2.3.3/plexus-io-2.3.3.pom (2.8 kB at 35 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-repository-builder/1.0-alpha-2/maven-repository-builder-1.0-alpha-2.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-repository-builder/1.0-alpha-2/maven-repository-builder-1.0-alpha-2.pom (3.2 kB at 40 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-shared-components/7/maven-shared-components-7.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-shared-components/7/maven-shared-components-7.pom (2.6 kB at 19 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-common-artifact-filters/1.0-alpha-1/maven-common-artifact-filters-1.0-alpha-1.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-common-artifact-filters/1.0-alpha-1/maven-common-artifact-filters-1.0-alpha-1.pom (1.8 kB at 24 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-shared-components/6/maven-shared-components-6.pom +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-shared-components/6/maven-shared-components-6.pom (3.1 kB at 40 kB/s) +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-archiver/2.8.2/plexus-archiver-2.8.2.jar +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-io/2.3.3/plexus-io-2.3.3.jar +[INFO] Downloading from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-repository-builder/1.0-alpha-2/maven-repository-builder-1.0-alpha-2.jar +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/apache/maven/shared/maven-repository-builder/1.0-alpha-2/maven-repository-builder-1.0-alpha-2.jar (23 kB at 279 kB/s) +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-archiver/2.8.2/plexus-archiver-2.8.2.jar (143 kB at 1.5 MB/s) +[INFO] Downloaded from exo-mirror: https://repository.exoplatform.org/public/org/codehaus/plexus/plexus-io/2.3.3/plexus-io-2.3.3.jar (79 kB at 279 kB/s) +[INFO] Reading assembly descriptor: src/main/assemblies/packaging.xml +[INFO] Building zip: /home/exo/addon-project-template/packaging/target/training-exercises-packaging.zip +[INFO] +[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ training-exercices-packaging --- +[INFO] Installing /home/exo/addon-project-template/packaging/pom.xml to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercices-packaging/1.0.x-SNAPSHOT/training-exercices-packaging-1.0.x-SNAPSHOT.pom +[INFO] Installing /home/exo/addon-project-template/packaging/target/training-exercises-packaging.zip to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercices-packaging/1.0.x-SNAPSHOT/training-exercices-packaging-1.0.x-SNAPSHOT.zip +[INFO] ------------------------------------------------------------------------ +[INFO] Reactor Summary for Training addon - Parent 1.0.x-SNAPSHOT: +[INFO] +[INFO] Training addon - Parent ............................ SUCCESS [ 0.649 s] +[INFO] Training Exercise - Services ....................... SUCCESS [ 2.124 s] +[INFO] Training Exercises - Webapp ........................ SUCCESS [ 0.319 s] +[INFO] Training Exercises - Packaging ..................... SUCCESS [ 5.555 s] +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 9.101 s +[INFO] Finished at: 2020-12-17T11:12:47+01:00 +[INFO] ------------------------------------------------------------------------ diff --git a/services/output.log b/services/output.log new file mode 100644 index 0000000..03f321f --- /dev/null +++ b/services/output.log @@ -0,0 +1,61 @@ +[INFO] Scanning for projects... +[INFO] +[INFO] ----< org.exoplatform.addons.training:training-exercises-services >----- +[INFO] Building Training Exercise - Services 1.0.x-SNAPSHOT +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-clean-plugin:2.6:clean (default-clean) @ training-exercises-services --- +[INFO] Deleting /home/exo/addon-project-template/services/target +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java-version) @ training-exercises-services --- +[INFO] +[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-maven-version) @ training-exercises-services --- +[INFO] +[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ training-exercises-services --- +[INFO] Executing: /bin/sh -c cd /home/exo/addon-project-template/services && git rev-parse --verify HEAD +[INFO] Working directory: /home/exo/addon-project-template/services +[INFO] Storing buildNumber: c133e089877717f2f142aa13addf20d1c17a3d60 at timestamp: 20201217 +[INFO] Storing buildScmBranch: template/add-services +[INFO] +[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ training-exercises-services --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] Copying 3 resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ training-exercises-services --- +[INFO] Changes detected - recompiling the module! +[INFO] Compiling 6 source files to /home/exo/addon-project-template/services/target/classes +[WARNING] bootstrap class path not set in conjunction with -source 7 +[WARNING] source value 7 is obsolete and will be removed in a future release +[WARNING] target value 7 is obsolete and will be removed in a future release +[WARNING] To suppress warnings about obsolete options, use -Xlint:-options. +[WARNING] Exo JPA entity detected: org.exoplatform.addons.entity.FavouriteActivity +[WARNING] Supported source version 'RELEASE_5' from annotation processor 'org.chromattic.apt.ChromatticProcessor' less than -source '7' +[INFO] +[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ training-exercises-services --- +[INFO] Using 'UTF-8' encoding to copy filtered resources. +[INFO] skip non existing resourceDirectory /home/exo/addon-project-template/services/src/test/resources +[INFO] +[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ training-exercises-services --- +[INFO] No sources to compile +[INFO] +[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ training-exercises-services --- +[INFO] No tests to run. +[INFO] +[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (parse-version) @ training-exercises-services --- +[INFO] +[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ training-exercises-services --- +[INFO] Building jar: /home/exo/addon-project-template/services/target/training-exercises-services.jar +[INFO] +[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ training-exercises-services --- +[INFO] Building jar: /home/exo/addon-project-template/services/target/training-exercises-services-sources.jar +[INFO] +[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ training-exercises-services --- +[INFO] Installing /home/exo/addon-project-template/services/target/training-exercises-services.jar to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT.jar +[INFO] Installing /home/exo/addon-project-template/services/pom.xml to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT.pom +[INFO] Installing /home/exo/addon-project-template/services/target/training-exercises-services-sources.jar to /home/exo/.m2/repository/org/exoplatform/addons/training/training-exercises-services/1.0.x-SNAPSHOT/training-exercises-services-1.0.x-SNAPSHOT-sources.jar +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 3.215 s +[INFO] Finished at: 2020-12-17T11:12:24+01:00 +[INFO] ------------------------------------------------------------------------ diff --git a/services/pom.xml b/services/pom.xml index 483d053..f515609 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -37,9 +37,29 @@ 6.0.0 + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + Training Exercise - Services training-exercises-services + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + \ No newline at end of file diff --git a/services/src/main/java/Main.java b/services/src/main/java/Main.java index 0e5b3a6..50fad20 100644 --- a/services/src/main/java/Main.java +++ b/services/src/main/java/Main.java @@ -1,9 +1,9 @@ -package org.exoplatform.addons.services; + import org.exoplatform.container.ExoContainerContext; import org.exoplatform.container.PortalContainer; import org.picocontainer.Startable; -import org.exoplatform.services.log.*; + /** * @@ -15,7 +15,6 @@ */ public class Main { - public static void main(String[] args) { PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer(); MyNewStartableService myNewStartableService = (MyNewStartableService) portalContainer.getComponentInstance(MyNewStartableService.class); diff --git a/services/src/main/java/org/exoplatform/addons/services/MyService.java b/services/src/main/java/org/exoplatform/addons/services/MyService.java index 16b9d6f..8257dc7 100644 --- a/services/src/main/java/org/exoplatform/addons/services/MyService.java +++ b/services/src/main/java/org/exoplatform/addons/services/MyService.java @@ -21,7 +21,8 @@ public MyService() { LOG.info("##################### Simple service started successfully !!"); } - public void call() { - LOG.info("###################### call function invoked !!"); + public String call() { + //LOG.info("###################### call function invoked !!"); + return ("ca fonctionne!"); } } diff --git a/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java new file mode 100644 index 0000000..b6179c8 --- /dev/null +++ b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java @@ -0,0 +1,57 @@ +/** + * + */ +package org.exoplatform.addons.services; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * @author exo + * + */ +class MyServiceTest { + + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void setUpBeforeClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @AfterAll + static void tearDownAfterClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @AfterEach + void tearDown() throws Exception { + } + + /** + * Test method for {@link org.exoplatform.addons.services.MyService#call()}. + */ + @Test + void testCall() { + MyService myService = new MyService(); + myService.call(); + } + +} From 1be96f5b8a4a3e91b512c94f30f688ba874a3589 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 17 Dec 2020 17:11:27 +0100 Subject: [PATCH 04/12] JUnit Tests --- .../src/main/java/org/exoplatform/addons/services/MyService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/services/src/main/java/org/exoplatform/addons/services/MyService.java b/services/src/main/java/org/exoplatform/addons/services/MyService.java index 8257dc7..3bdf474 100644 --- a/services/src/main/java/org/exoplatform/addons/services/MyService.java +++ b/services/src/main/java/org/exoplatform/addons/services/MyService.java @@ -21,6 +21,7 @@ public MyService() { LOG.info("##################### Simple service started successfully !!"); } + public String call() { //LOG.info("###################### call function invoked !!"); return ("ca fonctionne!"); From b25094bef9c2518512391f189552aa36fd887c03 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 17 Dec 2020 17:44:45 +0100 Subject: [PATCH 05/12] Last pull request modified --- .../main/java/org/exoplatform/addons/services/MyService.java | 1 + .../java/org/exoplatform/addons/services/MyServiceTest.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/src/main/java/org/exoplatform/addons/services/MyService.java b/services/src/main/java/org/exoplatform/addons/services/MyService.java index 3bdf474..f88bdf0 100644 --- a/services/src/main/java/org/exoplatform/addons/services/MyService.java +++ b/services/src/main/java/org/exoplatform/addons/services/MyService.java @@ -25,5 +25,6 @@ public MyService() { public String call() { //LOG.info("###################### call function invoked !!"); return ("ca fonctionne!"); + } } diff --git a/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java index b6179c8..02644d6 100644 --- a/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java +++ b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java @@ -51,7 +51,8 @@ void tearDown() throws Exception { @Test void testCall() { MyService myService = new MyService(); - myService.call(); + + assertEquals("ca fonctionne!", myService.call()); } } From b13e8f80e54e791918bbd263c4f52a4d5ce36d9f Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 24 Dec 2020 10:44:44 +0100 Subject: [PATCH 06/12] Last modifications --- services/pom.xml | 20 ++++- services/src/main/java/Main.java | 23 ------ .../addons/DAO/FavoriteActivityDAO.java | 46 +++++++++++ .../addons/entity/FavoriteActivityEntity.java | 70 +++++++++++++++++ .../addons/services/MyNewService.java | 76 ++++++++++++++++++- .../addons/DAO/FavoriteActivityDAOTest.java | 66 ++++++++++++++++ .../addons/services/MyServiceTest.java | 76 +++++++++---------- 7 files changed, 312 insertions(+), 65 deletions(-) delete mode 100644 services/src/main/java/Main.java create mode 100644 services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java create mode 100644 services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java create mode 100644 services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java diff --git a/services/pom.xml b/services/pom.xml index f515609..f09ff2b 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -49,7 +49,25 @@ 5.4.2 test - + + + org.apache.logging.log4j + log4j-api + 2.13.3 + + + org.apache.logging.log4j + log4j-core + 2.13.3 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + + + + Training Exercise - Services diff --git a/services/src/main/java/Main.java b/services/src/main/java/Main.java deleted file mode 100644 index 50fad20..0000000 --- a/services/src/main/java/Main.java +++ /dev/null @@ -1,23 +0,0 @@ - - -import org.exoplatform.container.ExoContainerContext; -import org.exoplatform.container.PortalContainer; -import org.picocontainer.Startable; - - -/** - * - */ - -/** - * @author exo - * - */ -public class Main { - - public static void main(String[] args) { - PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer(); - MyNewStartableService myNewStartableService = (MyNewStartableService) portalContainer.getComponentInstance(MyNewStartableService.class); - myNewStartableService.start(); - } -} diff --git a/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java b/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java new file mode 100644 index 0000000..0d007ab --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java @@ -0,0 +1,46 @@ +package org.exoplatform.addons.DAO; + +import org.exoplatform.addons.entity.FavoriteActivityEntity; +import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl; + +import java.util.List; + +public class FavoriteActivityDAO extends GenericDAOJPAImpl { + + public FavoriteActivityDAO() { + } + + public FavoriteActivityEntity findActivity(Long id) + { + return (FavoriteActivityEntity) find(id); + } + + public List findAllActivity() + { + return findAll(); + } + + public FavoriteActivityEntity addActivity(FavoriteActivityEntity entity) { + return (FavoriteActivityEntity) create(entity); + } + + public void addAllActivity(List entities) { + createAll(entities); + } + + public FavoriteActivityEntity updateActivity(FavoriteActivityEntity entity) { + return (FavoriteActivityEntity) update(entity); + } + + public void updateAllActivity(List entities) { + updateAll(entities); + } + + public void deleteActivity(FavoriteActivityEntity entity) { + delete(entity); + } + + public void deleteAllActivity(List entities) { + deleteAll(entities); + } +} diff --git a/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java b/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java new file mode 100644 index 0000000..21fd2fd --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java @@ -0,0 +1,70 @@ +package org.exoplatform.addons.entity; + + +import javax.persistence.*; + +import org.exoplatform.commons.api.persistence.ExoEntity; +import org.exoplatform.social.core.jpa.storage.entity.ActivityEntity; + +import java.util.Calendar; + +@Entity +@ExoEntity +@Table(name = "ADDON_FAVOURITE_ACTIVITY") +public class FavoriteActivityEntity { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @ManyToOne + private String activityTitle; + + + + @ManyToOne + private ActivityEntity targetActivity; + + @Temporal(value = TemporalType.TIMESTAMP) + @Column(name = "FAVOURITE_DATE") + private Calendar favouriteDate; + + + public FavoriteActivityEntity(Long id, String activityTitle, ActivityEntity targetActivity, Calendar favouriteDate) { + this.id = id; + this.activityTitle = activityTitle; + this.targetActivity = targetActivity; + this.favouriteDate = favouriteDate; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getActivityTitle() { + return activityTitle; + } + + public void setActivityTitle(String activityTitle) { + this.activityTitle = activityTitle; + } + + public ActivityEntity getTargetActivity() { + return targetActivity; + } + + public void setTargetActivity(ActivityEntity targetActivity) { + this.targetActivity = targetActivity; + } + + public Calendar getFavouriteDate() { + return favouriteDate; + } + + public void setFavouriteDate(Calendar favouriteDate) { + this.favouriteDate = favouriteDate; + } +} diff --git a/services/src/main/java/org/exoplatform/addons/services/MyNewService.java b/services/src/main/java/org/exoplatform/addons/services/MyNewService.java index cc4c56d..a4eba3f 100644 --- a/services/src/main/java/org/exoplatform/addons/services/MyNewService.java +++ b/services/src/main/java/org/exoplatform/addons/services/MyNewService.java @@ -1,9 +1,16 @@ package org.exoplatform.addons.services; +import org.exoplatform.services.jcr.RepositoryService; +import org.exoplatform.services.jcr.core.ManageableRepository; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; +import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.container.ExoContainer; - +import javax.jcr.*; +import javax.jcr.query.Query; +import javax.jcr.query.QueryManager; +import java.util.Date; /** * @@ -21,10 +28,73 @@ public class MyNewService { public MyNewService() { - LOG.info("******************************** New Simple service started successfully !!"); + LOG.info("******************************** New Simple service started successfully !!"); } public void call() { LOG.info("************************* New call function invoked !!"); } -} + + public void addFavouriteActivity(String title, String link, Date date, String nodeName) throws RepositoryException { + ExoContainer myContainer = ExoContainerContext.getCurrentContainer(); + RepositoryService repositoryService = (RepositoryService) myContainer.getComponentInstanceOfType(RepositoryService.class); + Repository repository = repositoryService.getCurrentRepository(); + Session jcrSession = ((ManageableRepository) repository).getSystemSession("collaboration"); + Node root = jcrSession.getRootNode(); + + Node newNode = root.addNode(nodeName, "plf:FavoriteActivity"); + Value titleValue = jcrSession.getValueFactory().createValue(title); + Value linkValue = jcrSession.getValueFactory().createValue(link); + Value dateValue = jcrSession.getValueFactory().createValue(date.toString()); + newNode.setProperty("plf:title", titleValue); + newNode.setProperty("plf:link", linkValue); + newNode.setProperty("plf;date", dateValue); + jcrSession.save(); + + } + + public void listFavoriteActivity() throws RepositoryException { + ExoContainer myContainer = ExoContainerContext.getCurrentContainer(); + RepositoryService repositoryService = (RepositoryService) myContainer.getComponentInstanceOfType(RepositoryService.class); + Repository repository = repositoryService.getCurrentRepository(); + Session jcrSession = ((ManageableRepository) repository).getSystemSession("collaboration"); + Node root = jcrSession.getRootNode(); + + QueryManager qm = jcrSession.getWorkspace().getQueryManager(); + Query q = qm.createQuery("select * from plf:FavoriteActivity", Query.SQL); + NodeIterator ni = q.execute().getNodes(); + while (ni.hasNext()) { + Node iterNode = ni.nextNode(); + System.out.println(iterNode.getName() + " title:" + + root.getProperty("plf:title").getValue().getString() + " link:" + + root.getProperty("plf:link").getValue().getString() + " date" + + root.getProperty("plf:date").getValue().getString()); + } + jcrSession.save(); + } + + + public void removeFavoriteActivity(String title) throws RepositoryException { + ExoContainer myContainer = ExoContainerContext.getCurrentContainer(); + RepositoryService repositoryService = (RepositoryService) myContainer.getComponentInstanceOfType(RepositoryService.class); + Repository repository = repositoryService.getCurrentRepository(); + Session jcrSession = ((ManageableRepository) repository).getSystemSession("collaboration"); + Node root = jcrSession.getRootNode(); + + QueryManager qm = jcrSession.getWorkspace().getQueryManager(); + Query q = qm.createQuery("select * from plf:FavoriteActivity", Query.SQL); + NodeIterator ni = q.execute().getNodes(); + while (ni.hasNext()) { + Node iterNode = ni.nextNode(); + if (iterNode.getProperty("plf:title").getValue().getString() == title) { + QueryManager qm1 = jcrSession.getWorkspace().getQueryManager(); + Query q1 = qm1.createQuery("delete from plf:FavoriteActivity where title='${title}'", Query.SQL); + } + + } + jcrSession.save(); + + + } + +} \ No newline at end of file diff --git a/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java b/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java new file mode 100644 index 0000000..0e2a770 --- /dev/null +++ b/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java @@ -0,0 +1,66 @@ +package org.exoplatform.addons.DAO; + +import org.exoplatform.addons.entity.FavoriteActivityEntity; +import org.exoplatform.social.core.jpa.storage.entity.ActivityEntity; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import java.util.Calendar; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class FavoriteActivityDAOTest { + + + private FavoriteActivityDAO activityDAO; + + @Test + void testFindActivity() { + FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + activityDAO.addActivity(favAct); + List favActs = activityDAO.findAllActivity(); + Assert.assertEquals(favAct.getId(), activityDAO.findActivity(favActs.get(0).getId())); + } + + @Test + void testFindAllActivity() { + + } + + @Test + void testAddActivity() { + + FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + activityDAO.addActivity(favAct); + List favActs = activityDAO.findAllActivity(); + Assert.assertEquals(favAct.getId(), favActs.get(0).getId()); + + } + + @Test + void testAddAllActivity() { + } + + @Test + void testUpdateActivity() { + FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + FavoriteActivityEntity newFavAct = new FavoriteActivityEntity(5L,"title", new ActivityEntity(), Calendar.getInstance()); + activityDAO.addActivity(favAct); + + Assert.assertEquals(favAct,activityDAO.updateActivity(newFavAct)); + + } + + @Test + void testUpdateAllActivity() { + } + + @Test + void testDeleteActivity() { + } + + @Test + void testDeleteAllActivity() { + } +} \ No newline at end of file diff --git a/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java index 02644d6..51e62da 100644 --- a/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java +++ b/services/src/test/java/org/exoplatform/addons/services/MyServiceTest.java @@ -1,5 +1,5 @@ /** - * + * */ package org.exoplatform.addons.services; @@ -17,42 +17,42 @@ */ class MyServiceTest { - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterAll - static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @BeforeEach - void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterEach - void tearDown() throws Exception { - } - - /** - * Test method for {@link org.exoplatform.addons.services.MyService#call()}. - */ - @Test - void testCall() { - MyService myService = new MyService(); - - assertEquals("ca fonctionne!", myService.call()); - } + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void setUpBeforeClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @AfterAll + static void tearDownAfterClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @AfterEach + void tearDown() throws Exception { + } + + /** + * Test method for {@link org.exoplatform.addons.services.MyService#call()}. + */ + @Test + void testCall() { + MyService myService = new MyService(); + + assertEquals("ca fonctionne!", myService.call()); + } } From 11bf20163662f11b53d3d13a5b63794ea73edf5a Mon Sep 17 00:00:00 2001 From: NaderSai Date: Wed, 30 Dec 2020 14:59:49 +0100 Subject: [PATCH 07/12] Rest services --- services/pom.xml | 192 +++++++++++------- .../exo/rest/service/RestUserService.java | 172 ++++++++++++++++ .../addons/DAO/FavoriteActivityDAO.java | 71 +++++-- .../addons/entity/FavoriteActivityEntity.java | 8 +- .../resources/conf/portal/configuration.xml | 9 +- ...ddon-training-rdbms.db.changelog-1.0.0.xml | 5 +- .../addons/DAO/FavoriteActivityDAOTest.java | 12 +- 7 files changed, 370 insertions(+), 99 deletions(-) create mode 100644 services/src/main/java/exo/rest/service/RestUserService.java diff --git a/services/pom.xml b/services/pom.xml index f09ff2b..ab79c0c 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -2,82 +2,126 @@ - - org.exoplatform.addons.training - training-exercices-parent + + org.exoplatform.addons.training + training-exercices-parent + 1.0.x-SNAPSHOT + + 4.0.0 + training-exercises-services 1.0.x-SNAPSHOT - - 4.0.0 - training-exercises-services - 1.0.x-SNAPSHOT - - - picocontainer - picocontainer - 1.1 - - - org.exoplatform.kernel - exo.kernel.commons - ${platform.version} - - - org.exoplatform.kernel - exo.kernel.container - ${platform.version} - - - org.exoplatform.commons - commons-api - ${platform.version} - - - org.exoplatform.social - social-component-core - 6.0.0 - - - - org.junit.jupiter - junit-jupiter-api - 5.4.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.4.2 - test - + + + picocontainer + picocontainer + 1.1 + + + org.exoplatform.kernel + exo.kernel.commons + ${platform.version} + + + org.exoplatform.kernel + exo.kernel.container + ${platform.version} + + + org.exoplatform.commons + commons-api + ${platform.version} + + + org.exoplatform.social + social-component-core + 6.0.0 + - - org.apache.logging.log4j - log4j-api - 2.13.3 - - - org.apache.logging.log4j - log4j-core - 2.13.3 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.13.3 - + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + org.assertj + assertj-core + 3.15.0 + test + + + io.github.hakky54 + logcaptor + 2.0.0 + compile + + + org.assertj + assertj-core + 3.15.0 + compile + + + org.apache.logging.log4j + log4j-api + 2.11.1 + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + - - - Training Exercise - Services - - training-exercises-services - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.1 - - - + + org.exoplatform.ws + exo.ws.rest.core + 2.3.7-GA + provided + + + org.exoplatform.core + exo.core.component.organization.api + 2.6.0-GA + provided + + + javax.annotation + jsr250-api + 1.0 + provided + + + com.metaparadigm + json-rpc + 1.0 + provided + + + Training Exercise - Services + + training-exercises-services + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + \ No newline at end of file diff --git a/services/src/main/java/exo/rest/service/RestUserService.java b/services/src/main/java/exo/rest/service/RestUserService.java new file mode 100644 index 0000000..0292e44 --- /dev/null +++ b/services/src/main/java/exo/rest/service/RestUserService.java @@ -0,0 +1,172 @@ +package exo.rest.service; + +import io.swagger.annotations.ApiParam; +import org.exoplatform.addons.DAO.FavoriteActivityDAO; +import org.exoplatform.addons.entity.FavoriteActivityEntity; +import org.exoplatform.commons.utils.ListAccess; +import org.exoplatform.container.ExoContainer; +import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.services.organization.OrganizationService; +import org.exoplatform.services.organization.User; +import org.exoplatform.services.organization.UserHandler; +import org.exoplatform.services.rest.resource.ResourceContainer; +import org.exoplatform.services.security.Identity; +import org.exoplatform.services.security.IdentityRegistry; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import java.util.Calendar; +import java.util.List; + + +/** + * Rest User Service! + */ +@Path("/demo") +@Produces("application/json") +public class RestUserService implements ResourceContainer { + + private FavoriteActivityDAO dao = new FavoriteActivityDAO(); + + public RestUserService() { + } + + public RestUserService(FavoriteActivityDAO dao) { + this.dao = dao; + } + + + @GET + @Path("/hello/{name}") + //@RolesAllowed({"administrators"}) + public String hello(@PathParam("name") String name) { + return "Hello " + name; + } + + @GET + @Path("/listusers/{offset}") + public Response getListUserName(@Context SecurityContext sc, @PathParam("offset") Integer offset) throws JSONException { + JSONArray list = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + String groupToCheck = "/platform/administrators"; + CacheControl cacheControl = new CacheControl(); + cacheControl.setNoCache(true); + cacheControl.setNoStore(true); + + if (sc.getUserPrincipal() == null || !this.isMemberOf(sc.getUserPrincipal().getName(), groupToCheck)) { + + jsonObject.put("rights", "NOT-ALLOWED"); + list.put(jsonObject); + + } else { + + OrganizationService organizationService = ExoContainerContext.getCurrentContainer() + .getComponentInstanceOfType(OrganizationService.class); + UserHandler userHandler = organizationService.getUserHandler(); + try { + ListAccess allUsers = userHandler.findAllUsers(); + + if (offset == null || offset < 0) + offset = 0; + int limit = 1000; + int total = limit + offset; + int totalUsers = allUsers.getSize(); + + if (offset < totalUsers && total > totalUsers) { + total = totalUsers; + } + User[] users = null; + + for (int i = offset; i < total; i++) { + users = allUsers.load(i, 1); + jsonObject = new JSONObject(); + jsonObject.put("username", users[0].getUserName()); + list.put(jsonObject); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + return Response.ok(list.toString(), MediaType.APPLICATION_JSON).cacheControl(cacheControl).build(); + + } + + @POST + @Path("/create") + @Consumes("application/json") + public Response create(@ApiParam(value = "entity", required = true) FavoriteActivityEntity entity) { + CacheControl cacheControl = new CacheControl(); + cacheControl.setNoCache(true); + cacheControl.setNoStore(true); + try { + entity.setFavouriteDate(Calendar.getInstance()); + dao.addActivity(entity); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return Response.ok("OK", MediaType.APPLICATION_JSON).cacheControl(cacheControl).build(); + + } + + @GET + @Path("/show") + public JSONArray show() throws JSONException { + JSONArray list = new JSONArray(); + JSONObject jsonObject = new JSONObject(); + + String groupToCheck = "/platform/administrators"; + CacheControl cacheControl = new CacheControl(); + cacheControl.setNoCache(true); + cacheControl.setNoStore(true); + + + try { + List allFavoriteActivities = dao.findAllActivity(); + + + for (int i = 0; i < allFavoriteActivities.size(); i++) { + jsonObject = new JSONObject(); + jsonObject.put("id", allFavoriteActivities.get(i).getId()); + jsonObject.put("activityTitle", allFavoriteActivities.get(i).getActivityTitle()); + jsonObject.put("targetActivity", allFavoriteActivities.get(i).getTargetActivity()); + jsonObject.put("favoriteDate", allFavoriteActivities.get(i).getFavouriteDate()); + list.put(jsonObject); + } + + + } catch (JSONException e) { + e.printStackTrace(); + } + + return list; + } + + @DELETE + @Path("/delete/{id}") + public Response deleteById(@PathParam("id") Long id ){ + dao.deleteActivity(id); + return Response.ok().build(); + } + + @DELETE + @Path("/deleteAll") + public Response deleteAll(){ + dao.deleteAll(); + return Response.ok().build(); + } + + private boolean isMemberOf(String username, String role) { + ExoContainer container = ExoContainerContext.getCurrentContainer(); + IdentityRegistry identityRegistry = container.getComponentInstanceOfType(IdentityRegistry.class); + Identity identity = identityRegistry.getIdentity(username); + return identity.isMemberOf(role); + } + +} \ No newline at end of file diff --git a/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java b/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java index 0d007ab..a734aa6 100644 --- a/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java +++ b/services/src/main/java/org/exoplatform/addons/DAO/FavoriteActivityDAO.java @@ -3,44 +3,85 @@ import org.exoplatform.addons.entity.FavoriteActivityEntity; import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.Query; import java.util.List; -public class FavoriteActivityDAO extends GenericDAOJPAImpl { +public class FavoriteActivityDAO extends GenericDAOJPAImpl { public FavoriteActivityDAO() { } public FavoriteActivityEntity findActivity(Long id) { - return (FavoriteActivityEntity) find(id); + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + Query q = em.createQuery("select f from FavoriteActivityEntity f where f.ID= :idd"); + q.setParameter("idd", id); + FavoriteActivityEntity res = (FavoriteActivityEntity) q.getSingleResult(); + em.getTransaction().commit(); + return res; } public List findAllActivity() { - return findAll(); + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + Query q = em.createQuery("select f from FavoriteActivityEntity f "); + List list = q.getResultList(); + em.getTransaction().commit(); + return list; } - public FavoriteActivityEntity addActivity(FavoriteActivityEntity entity) { - return (FavoriteActivityEntity) create(entity); + public void addActivity(FavoriteActivityEntity entity) { + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + em.persist(entity); + em.getTransaction().commit(); } - public void addAllActivity(List entities) { - createAll(entities); + public void addAllActivity(List entities) + { + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + em.persist(entities); + em.getTransaction().commit(); } - public FavoriteActivityEntity updateActivity(FavoriteActivityEntity entity) { - return (FavoriteActivityEntity) update(entity); + public void updateActivity(FavoriteActivityEntity entity) + { + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + getEntityManager().merge(entity); + em.getTransaction().commit(); } - public void updateAllActivity(List entities) { - updateAll(entities); + public void updateAllActivity(List entities) + { + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + for (FavoriteActivityEntity entity : entities) { + getEntityManager().merge(entity); + } + em.getTransaction().commit(); + } - public void deleteActivity(FavoriteActivityEntity entity) { - delete(entity); + public void deleteActivity(Long id) + { + FavoriteActivityEntity entity = findActivity(id); + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + em.remove(entity); + em.getTransaction().commit(); } - public void deleteAllActivity(List entities) { - deleteAll(entities); + public void deleteAllActivity() + { + EntityManager em= getEntityManager() ; + em.getTransaction().begin(); + em.createQuery("delete from FavoriteActivityEntity ").executeUpdate(); + em.getTransaction().commit(); } } diff --git a/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java b/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java index 21fd2fd..56082a3 100644 --- a/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java +++ b/services/src/main/java/org/exoplatform/addons/entity/FavoriteActivityEntity.java @@ -15,13 +15,16 @@ public class FavoriteActivityEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") private Long id; - @ManyToOne + + @Column(name="ACTIVITY_ID") private String activityTitle; @ManyToOne + @JoinColumn(name="FAVOURITE_BY_ID") private ActivityEntity targetActivity; @Temporal(value = TemporalType.TIMESTAMP) @@ -29,6 +32,9 @@ public class FavoriteActivityEntity { private Calendar favouriteDate; + public FavoriteActivityEntity() { + } + public FavoriteActivityEntity(Long id, String activityTitle, ActivityEntity targetActivity, Calendar favouriteDate) { this.id = id; this.activityTitle = activityTitle; diff --git a/services/src/main/resources/conf/portal/configuration.xml b/services/src/main/resources/conf/portal/configuration.xml index 33ff018..dc99b11 100644 --- a/services/src/main/resources/conf/portal/configuration.xml +++ b/services/src/main/resources/conf/portal/configuration.xml @@ -25,4 +25,11 @@ org.exoplatform.commons.persistence.impl.EntityManagerService - \ No newline at end of file + + + exo.rest.service.RestUserService + + + org.exoplatform.addons.DAO.FavoriteActivityDAO + + diff --git a/services/src/main/resources/db/changelog/addon-training-rdbms.db.changelog-1.0.0.xml b/services/src/main/resources/db/changelog/addon-training-rdbms.db.changelog-1.0.0.xml index 5407070..77df67b 100644 --- a/services/src/main/resources/db/changelog/addon-training-rdbms.db.changelog-1.0.0.xml +++ b/services/src/main/resources/db/changelog/addon-training-rdbms.db.changelog-1.0.0.xml @@ -34,6 +34,7 @@ + 7:f620ffd34591e64cf5eabffed96fab56 @@ -42,9 +43,9 @@ - + - + diff --git a/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java b/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java index 0e2a770..a7d4917 100644 --- a/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java +++ b/services/src/test/java/org/exoplatform/addons/DAO/FavoriteActivityDAOTest.java @@ -17,10 +17,10 @@ class FavoriteActivityDAOTest { @Test void testFindActivity() { - FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + /* FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); activityDAO.addActivity(favAct); List favActs = activityDAO.findAllActivity(); - Assert.assertEquals(favAct.getId(), activityDAO.findActivity(favActs.get(0).getId())); + Assert.assertEquals(favAct.getId(), activityDAO.findActivity(favActs.get(0).getId()));*/ } @Test @@ -31,10 +31,10 @@ void testFindAllActivity() { @Test void testAddActivity() { - FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + /* FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); activityDAO.addActivity(favAct); List favActs = activityDAO.findAllActivity(); - Assert.assertEquals(favAct.getId(), favActs.get(0).getId()); + Assert.assertEquals(favAct.getId(), favActs.get(0).getId());*/ } @@ -44,11 +44,11 @@ void testAddAllActivity() { @Test void testUpdateActivity() { - FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); + /* FavoriteActivityEntity favAct = new FavoriteActivityEntity(9L,"title", new ActivityEntity(), Calendar.getInstance()); FavoriteActivityEntity newFavAct = new FavoriteActivityEntity(5L,"title", new ActivityEntity(), Calendar.getInstance()); activityDAO.addActivity(favAct); - Assert.assertEquals(favAct,activityDAO.updateActivity(newFavAct)); + Assert.assertEquals(favAct,activityDAO.updateActivity(newFavAct));*/ } From e7ca8593f16239ef923caba4adafc45d50279546 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Wed, 30 Dec 2020 17:59:50 +0100 Subject: [PATCH 08/12] My new extension --- .../webapp/conf/common/locales-config.xml | 10 + war/src/main/webapp/login/jsp/login.jsp | 187 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 war/src/main/webapp/conf/common/locales-config.xml create mode 100644 war/src/main/webapp/login/jsp/login.jsp diff --git a/war/src/main/webapp/conf/common/locales-config.xml b/war/src/main/webapp/conf/common/locales-config.xml new file mode 100644 index 0000000..dae21bf --- /dev/null +++ b/war/src/main/webapp/conf/common/locales-config.xml @@ -0,0 +1,10 @@ + + ... + + ve + UTF-8 + UTF-8 + Venda + + ... + \ No newline at end of file diff --git a/war/src/main/webapp/login/jsp/login.jsp b/war/src/main/webapp/login/jsp/login.jsp new file mode 100644 index 0000000..3f4a4db --- /dev/null +++ b/war/src/main/webapp/login/jsp/login.jsp @@ -0,0 +1,187 @@ +<%-- + + Copyright (C) 2009 eXo Platform SAS. + + This is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + This software is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this software; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + 02110-1301 USA, or see the FSF site: http://www.fsf.org. + +--%> + +<%@ page import="java.net.URLEncoder"%> +<%@ page import="javax.servlet.http.Cookie"%> +<%@ page import="org.exoplatform.web.login.LoginError"%> +<%@ page import="org.exoplatform.container.PortalContainer"%> +<%@ page import="org.exoplatform.services.resources.ResourceBundleService"%> +<%@ page import="org.gatein.security.oauth.spi.OAuthProviderType"%> +<%@ page import="org.gatein.security.oauth.spi.OAuthProviderTypeRegistry"%> +<%@ page import="java.util.ResourceBundle"%> +<%@ page import="org.gatein.common.text.EntityEncoder"%> +<%@ page language="java"%> +<% + String contextPath = request.getContextPath() ; + + String username = request.getParameter("username"); + if(username == null) { + username = ""; + } else { + EntityEncoder encoder = EntityEncoder.FULL; + username = encoder.encode(username); + } + + PortalContainer portalContainer = PortalContainer.getCurrentInstance(session.getServletContext()); + ResourceBundleService service = (ResourceBundleService) portalContainer.getComponentInstanceOfType(ResourceBundleService.class); + ResourceBundle res = service.getResourceBundle(service.getSharedResourceBundleNames(), request.getLocale()) ; + + OAuthProviderTypeRegistry registry = (OAuthProviderTypeRegistry) portalContainer.getComponentInstanceOfType(OAuthProviderTypeRegistry.class); + + Cookie cookie = new Cookie(org.exoplatform.web.login.LoginServlet.COOKIE_NAME, ""); + cookie.setPath(request.getContextPath()); + cookie.setMaxAge(0); + response.addCookie(cookie); + + String uri = (String)request.getAttribute("org.gatein.portal.login.initial_uri"); + boolean error = request.getAttribute("org.gatein.portal.login.error") != null; + String errorParam = (String)request.getParameter(org.exoplatform.web.login.LoginError.ERROR_PARAM); + LoginError errorData = null; + if (errorParam != null) { + errorData = LoginError.parse(errorParam); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=UTF-8"); +%> + + + + + <%=res.getString("UILoginForm.label.Signin")%> + + + + + + + + + + + +
+

LOGIN PAGE MODIFIED !

+
+ + +
+ <% + if (errorData != null) { + if (org.exoplatform.web.login.LoginError.DISABLED_USER_ERROR == errorData.getCode()) { + %> + <%=errorData.getData()%> <%=res.getString("UILoginForm.label.DisabledUserSignin")%> + <% + } + } else if (error) {%> + <%=res.getString("UILoginForm.label.SigninFail")%> + <% } %> +
+
+
+
+
Sign In
+
+
+
+
+
+
+
+ +
" method="post"> + + +
+ + + + + + + + + + + + + +
+
+
+
+
+ "/> + <% if (uri != null) { + uri = EntityEncoder.FULL.encode(uri); + %> + + <% } %> +
+
+
+
+ <% + if (registry.isOAuthEnabled()) { + %> + +
+ <%= res.getString("UILoginForm.label.Delimiter")%> +
+
+ <% for (OAuthProviderType oauthProvType : registry.getEnabledOAuthProviders()) { %> + + <% } %> +
+ <% } %> +
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file From 60cc323e92f25b64618009bf9e8737c441f515ff Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 31 Dec 2020 11:14:27 +0100 Subject: [PATCH 09/12] Comment button removed --- .../webapp/WEB-INF/conf/configuration.xml | 33 ---------------- .../conf/common/common-configuration.xml | 10 +++++ .../commons/UIActivityActionBar.gtmpl | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+), 33 deletions(-) delete mode 100644 war/src/main/webapp/WEB-INF/conf/configuration.xml create mode 100644 war/src/main/webapp/conf/common/common-configuration.xml create mode 100644 war/src/main/webapp/groovy/social/webui/activity/commons/UIActivityActionBar.gtmpl diff --git a/war/src/main/webapp/WEB-INF/conf/configuration.xml b/war/src/main/webapp/WEB-INF/conf/configuration.xml deleted file mode 100644 index 00b465e..0000000 --- a/war/src/main/webapp/WEB-INF/conf/configuration.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - org.exoplatform.addons.services.MyStartableService - org.exoplatform.addons.services.MyStartableService - - - org.exoplatform.addons.services.MyService - org.exoplatform.addons.services.MyService - - diff --git a/war/src/main/webapp/conf/common/common-configuration.xml b/war/src/main/webapp/conf/common/common-configuration.xml new file mode 100644 index 0000000..393da63 --- /dev/null +++ b/war/src/main/webapp/conf/common/common-configuration.xml @@ -0,0 +1,10 @@ + + org.exoplatform.services.resources.LocaleConfigService + org.exoplatform.services.resources.impl.LocaleConfigServiceImpl + + + locale.config.file + war:/conf/common/locales-config.xml + + + \ No newline at end of file diff --git a/war/src/main/webapp/groovy/social/webui/activity/commons/UIActivityActionBar.gtmpl b/war/src/main/webapp/groovy/social/webui/activity/commons/UIActivityActionBar.gtmpl new file mode 100644 index 0000000..8769fc9 --- /dev/null +++ b/war/src/main/webapp/groovy/social/webui/activity/commons/UIActivityActionBar.gtmpl @@ -0,0 +1,38 @@ +<% + def activity = uicomponent.getActivity(); + def likeActivityAction = uicomponent.event("LikeActivity", "true"); + def unlikeActivityAction = uicomponent.event("LikeActivity", "false"); + def labelLike = _ctx.appRes("UIActivity.label.Like"); + def labelComment = _ctx.appRes("UIActivity.label.Comment"); + def totalLikesNum = uicomponent.getIdentityLikes().length; + int allCommentSize = uicomponent.getAllCommentSize(); +%> +
+ <% def toggleDisplayCommentAction = uicomponent.event('ToggleDisplayCommentForm', null, false); + def commentLink = ""; + %> + +
\ No newline at end of file From 1e08bed92d8c02bff8364384a6a65390b19b3f20 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 31 Dec 2020 14:37:29 +0100 Subject: [PATCH 10/12] Tunisian Arabic added --- .../WEB-INF/conf/common/locales-config.xml | 177 ++++++++++++++++++ .../conf/common/common-configuration.xml | 10 - .../webapp/conf/common/locales-config.xml | 10 - 3 files changed, 177 insertions(+), 20 deletions(-) create mode 100644 war/src/main/webapp/WEB-INF/conf/common/locales-config.xml delete mode 100644 war/src/main/webapp/conf/common/common-configuration.xml delete mode 100644 war/src/main/webapp/conf/common/locales-config.xml diff --git a/war/src/main/webapp/WEB-INF/conf/common/locales-config.xml b/war/src/main/webapp/WEB-INF/conf/common/locales-config.xml new file mode 100644 index 0000000..44a8776 --- /dev/null +++ b/war/src/main/webapp/WEB-INF/conf/common/locales-config.xml @@ -0,0 +1,177 @@ + + + + + en + UTF-8 + UTF-8 + Default configuration for english locale + + + fr + UTF-8 + UTF-8 + Default configuration for the french locale + + + es_ES + UTF-8 + UTF-8 + Default configuration for the spanish locale + + + cs + UTF-8 + UTF-8 + Default configuration for the Czech locale + + + ja + UTF-8 + UTF-8 + Default configuration for the japanese locale + + + ar + UTF-8 + UTF-8 + Default configuration for the arabic locale + + + + ar_TN + UTF-8 + UTF-8 + Default configuration for the arabic Tunisia locale + + + + ar_OM + UTF-8 + UTF-8 + Default configuration for the arabic Oman locale + + + de + UTF-8 + UTF-8 + Default configuration for the german locale + + + pt_BR + UTF-8 + UTF-8 + Default configuration for the brazilian locale + + + pt_PT + UTF-8 + UTF-8 + Default configuration for the portuguese locale + + + it + UTF-8 + UTF-8 + Default configuration for the italian locale + + + ru + UTF-8 + UTF-8 + Default configuration for the russian locale + + + tr + UTF-8 + UTF-8 + Default configuration for the turkish locale + + + zh_CN + UTF-8 + UTF-8 + Default configuration for the chinese simplified locale + + + uk + UTF-8 + UTF-8 + Default configuration for the Ukrainian locale + + + pl + UTF-8 + UTF-8 + Default configuration for the Polish locale + + + fa + UTF-8 + UTF-8 + Default configuration for the Persian locale + + + ca + UTF-8 + UTF-8 + Default configuration for the Catalan locale + + + nl + UTF-8 + UTF-8 + Default configuration for the Dutch locale + + + sl + UTF-8 + UTF-8 + Default configuration for the Slovenian locale + + + in + UTF-8 + UTF-8 + Default configuration for the Indonesian locale + + + fil + UTF-8 + UTF-8 + Default configuration for the Filipino locale + + + + + vi + UTF-8 + UTF-8 + Default configuration for the Vietnamian locale + + \ No newline at end of file diff --git a/war/src/main/webapp/conf/common/common-configuration.xml b/war/src/main/webapp/conf/common/common-configuration.xml deleted file mode 100644 index 393da63..0000000 --- a/war/src/main/webapp/conf/common/common-configuration.xml +++ /dev/null @@ -1,10 +0,0 @@ - - org.exoplatform.services.resources.LocaleConfigService - org.exoplatform.services.resources.impl.LocaleConfigServiceImpl - - - locale.config.file - war:/conf/common/locales-config.xml - - - \ No newline at end of file diff --git a/war/src/main/webapp/conf/common/locales-config.xml b/war/src/main/webapp/conf/common/locales-config.xml deleted file mode 100644 index dae21bf..0000000 --- a/war/src/main/webapp/conf/common/locales-config.xml +++ /dev/null @@ -1,10 +0,0 @@ - - ... - - ve - UTF-8 - UTF-8 - Venda - - ... - \ No newline at end of file From 8afe210fbcb94af84fde1a5807b3b4cca461c667 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Wed, 6 Jan 2021 14:01:41 +0100 Subject: [PATCH 11/12] Event Listener added --- services/pom.xml | 92 ++-- .../exo/rest/service/RestUserService.java | 6 +- .../addons/listener/MailSendListener.java | 95 ++++ .../resources/conf/portal/configuration.xml | 10 + .../conf/organization/idm-configuration.xml | 421 ++++++++++++++++++ 5 files changed, 582 insertions(+), 42 deletions(-) create mode 100644 services/src/main/java/org/exoplatform/addons/listener/MailSendListener.java create mode 100644 war/src/main/webapp/WEB-INF/conf/organization/idm-configuration.xml diff --git a/services/pom.xml b/services/pom.xml index ab79c0c..f02d259 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -1,7 +1,4 @@ - - + org.exoplatform.addons.training training-exercices-parent @@ -11,6 +8,26 @@ training-exercises-services 1.0.x-SNAPSHOT + + + + org.exoplatform.core + exo.core.component.organization.api + 2.6.0-GA + + + javax.jcr + jcr + 2.0 + + + javax.annotation + jsr250-api + 1.0 + + + + picocontainer picocontainer @@ -36,7 +53,6 @@ social-component-core 6.0.0 - org.junit.jupiter junit-jupiter-api @@ -49,37 +65,16 @@ 5.4.2 test - - org.assertj - assertj-core - 3.15.0 - test - - - - io.github.hakky54 - logcaptor - 2.0.0 - compile - - - org.assertj - assertj-core - 3.15.0 - compile - org.apache.logging.log4j log4j-api 2.11.1 - javax.servlet - javax.servlet-api - 3.0.1 - provided + org.slf4j + slf4j-jdk14 + 1.7.28 - org.exoplatform.ws exo.ws.rest.core @@ -104,6 +99,36 @@ 1.0 provided + + org.hibernate + hibernate-entitymanager + 4.3.6.Final + + + org.exoplatform.gatein.portal + exo.portal.component.portal + 6.0.0 + + + org.exoplatform.gatein.portal + exo.portal.component.common + 6.0.0 + + + org.exoplatform.core + exo.core.component.organization.api + 2.6.0-GA + + + javax.jcr + jcr + 2.0 + + + javax.annotation + jsr250-api + 1.0 + Training Exercise - Services @@ -112,15 +137,6 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.1 - - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - diff --git a/services/src/main/java/exo/rest/service/RestUserService.java b/services/src/main/java/exo/rest/service/RestUserService.java index 0292e44..5e0826e 100644 --- a/services/src/main/java/exo/rest/service/RestUserService.java +++ b/services/src/main/java/exo/rest/service/RestUserService.java @@ -127,7 +127,7 @@ public JSONArray show() throws JSONException { cacheControl.setNoStore(true); - try { + List allFavoriteActivities = dao.findAllActivity(); @@ -141,9 +141,7 @@ public JSONArray show() throws JSONException { } - } catch (JSONException e) { - e.printStackTrace(); - } + return list; } diff --git a/services/src/main/java/org/exoplatform/addons/listener/MailSendListener.java b/services/src/main/java/org/exoplatform/addons/listener/MailSendListener.java new file mode 100644 index 0000000..6e22bac --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/listener/MailSendListener.java @@ -0,0 +1,95 @@ +package org.exoplatform.addons.listener; + +import org.exoplatform.commons.utils.MailUtils; +import org.exoplatform.container.ExoContainer; +import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.portal.branding.BrandingService; +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; +import org.exoplatform.services.mail.MailService; +import org.exoplatform.services.mail.Message; +import org.exoplatform.services.organization.OrganizationService; +import org.exoplatform.services.organization.User; +import org.exoplatform.services.organization.UserEventListener; +import org.exoplatform.services.organization.UserProfile; +import org.exoplatform.services.organization.impl.NewUserConfig; +import org.exoplatform.services.resources.ResourceBundleService; +import org.exoplatform.web.WebAppController; + +import java.io.InputStream; +import java.util.Locale; +import java.util.ResourceBundle; + +public class MailSendListener extends UserEventListener { + + private static final Log LOG = ExoLogger.getLogger(MailSendListener.class); + + + private final MailService mailService; + private final ResourceBundleService bundleService; + private final BrandingService brandingService; + private NewUserConfig config_; + + public MailSendListener(MailService mailService, ResourceBundleService bundleService, BrandingService brandingService, WebAppController webController) { + super(); + this.mailService = mailService; + this.bundleService = bundleService; + this.brandingService = brandingService; + } + + public boolean SendMail(User user, Locale locale) { + if (user == null) { + throw new IllegalArgumentException("User or Locale must not be null"); + } + + ResourceBundle bundle = bundleService.getResourceBundle(bundleService.getSharedResourceBundleNames(), locale); + String emailBody = ""; + InputStream input = this.getClass().getClassLoader().getResourceAsStream("conf/onBoarding_email_template.html"); + emailBody = emailBody.replaceAll("\\$\\{USER_DISPLAY_NAME\\}", user.getDisplayName()); + emailBody = emailBody.replaceAll("\\$\\{COMPANY_NAME\\}", brandingService.getCompanyName()); + emailBody = emailBody.replaceAll("\\$\\{CHANGING_PASSWORD_LINK\\}", "http://127.0.0.1:8080/portal/forgot-password"); + String emailSubject = bundle.getString("onboarding.email.header") + " " + brandingService.getCompanyName(); + String senderName = MailUtils.getSenderName(); + String from = MailUtils.getSenderEmail(); + if (senderName != null && !senderName.trim().isEmpty()) { + from = senderName + " <" + from + ">"; + } + + Message message = new Message(); + message.setFrom(from); + message.setTo(user.getEmail()); + message.setSubject(emailSubject); + message.setBody(emailBody); + message.setMimeType("text/html"); + + try { + mailService.sendMessage(message); + } catch (Exception ex) { + LOG.error("Failure to send onboarding email", ex); + return false; + } + return true; + + } + + + public void preSave(User user, boolean isNew) throws Exception { + LOG.info("Before user is added into database"); + } + + + public void postSave(User user, boolean isNew) throws Exception { + ExoContainer pcontainer = ExoContainerContext.getCurrentContainer(); + OrganizationService service = (OrganizationService) pcontainer.getComponentInstanceOfType(OrganizationService.class); + UserProfile up = service.getUserProfileHandler().createUserProfileInstance(); + up.setUserName(user.getUserName()); + service.getUserProfileHandler().saveUserProfile(up, false); + + Locale locale = new Locale("en", "US"); + + LOG.info("After user is added into database"); + SendMail(user, locale); + + } + +} \ No newline at end of file diff --git a/services/src/main/resources/conf/portal/configuration.xml b/services/src/main/resources/conf/portal/configuration.xml index dc99b11..c0f2778 100644 --- a/services/src/main/resources/conf/portal/configuration.xml +++ b/services/src/main/resources/conf/portal/configuration.xml @@ -32,4 +32,14 @@ org.exoplatform.addons.DAO.FavoriteActivityDAO + + + org.exoplatform.services.organization.OrganizationService + + osend.mail.added.user + addListenerPlugin + org.exoplatform.addons.listener.MailSendListener + send mail after adding user + + diff --git a/war/src/main/webapp/WEB-INF/conf/organization/idm-configuration.xml b/war/src/main/webapp/WEB-INF/conf/organization/idm-configuration.xml new file mode 100644 index 0000000..3ab972b --- /dev/null +++ b/war/src/main/webapp/WEB-INF/conf/organization/idm-configuration.xml @@ -0,0 +1,421 @@ + + + + + + + org.exoplatform.services.organization.cache.OrganizationCacheHandler + + + + org.exoplatform.services.organization.idm.PicketLinkIDMCacheService + org.exoplatform.services.organization.idm.PicketLinkIDMCacheService + + + org.gatein.common.transaction.JTAUserTransactionLifecycleService + org.gatein.common.transaction.JTAUserTransactionLifecycleServiceImpl + + + org.exoplatform.services.database.HibernateService + database:type=HibernateService + org.exoplatform.services.organization.idm.CustomHibernateServiceImpl + + + hibernate.properties + Default Hibernate Service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.exoplatform.services.organization.idm.PicketLinkIDMService + org.exoplatform.services.organization.idm.PicketLinkIDMServiceImpl + + + config + war:/conf/organization/picketlink-idm/picketlink-idm-config.xml + + + + + + + + + + + + + + + + + + + + + + + portalRealm + idm_realm${container.name.suffix} + + + + skipExpirationOfStructureCacheEntries + true + + + + useSecureRandomService + true + + + + + + + org.exoplatform.services.organization.OrganizationService + org.exoplatform.services.organization.idm.PicketLinkIDMOrganizationServiceImpl + + + configuration + + + + true + + + + true + + + + . + + + + GTN_ROOT_GROUP + + + + + + + / + + + root_type + + + + + + + + + + + + + + + + + member + + + + + + + + + + false + + + + + @_@_@ + + + + + true + + + + + true + + + + + true + + + + + ${exo.disable.user.activated:true} + + + + + ${exo.idm.user.updateLastLoginTime:true} + + + + + + + + + + org.exoplatform.services.database.HibernateService + + add.hibernate.mapping + addPlugin + org.exoplatform.services.database.impl.AddHibernateMappingPlugin + + + hibernate.mapping + picketlink-idm/mappings/HibernateRealm.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectCredentialBinaryValue.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectAttributeBinaryValue.hbm.xml + picketlink-idm/mappings/HibernateIdentityObject.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectCredential.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectCredentialType.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectAttribute.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectType.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectRelationship.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectRelationshipType.hbm.xml + picketlink-idm/mappings/HibernateIdentityObjectRelationshipName.hbm.xml + + + hibernate.mapping + picketlink-idm/sybase-mappings/HibernateRealm.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectCredentialBinaryValue.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectAttributeBinaryValue.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObject.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectCredential.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectCredentialType.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectAttribute.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectType.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectRelationship.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectRelationshipType.hbm.xml + picketlink-idm/sybase-mappings/HibernateIdentityObjectRelationshipName.hbm.xml + + + + + + + org.exoplatform.services.listener.ListenerService + + exo.core.security.ConversationRegistry.register + addListener + org.exoplatform.services.organization.idm.UpdateLoginTimeListener + update last login time for user + + + + + + + + + + + + + org.exoplatform.services.cache.CacheService + + addExoCacheConfig + addExoCacheConfig + org.exoplatform.services.cache.ExoCacheConfigPlugin + add Exo Cache Config + + + portal.User + Exo Cache cluster configuration for IDM User entity + + portal.User + ${exo.cache.portal.user.strategy:LIRS} + ${exo.cache.portal.user.MaxNodes:5000} + ${exo.cache.portal.user.TimeToLive:3600} + ${exo.cache.portal.user.cacheMode:replication} + + + + + portal.Profile + Exo Cache cluster configuration for IDM User Profile entity + + portal.Profile + ${exo.cache.portal.profile.strategy:LIRS} + ${exo.cache.portal.profile.MaxNodes:5000} + ${exo.cache.portal.profile.TimeToLive:3600} + ${exo.cache.portal.profile.cacheMode:replication} + + + + + portal.Membership + Exo Cache cluster configuration for IDM Membership entity + + portal.Membership + ${exo.cache.portal.membership:LIRS} + ${exo.cache.portal.membership.MaxNodes:5000} + ${exo.cache.portal.membership.TimeToLive:86400} + ${exo.cache.portal.membership.cacheMode:replication} + + + + + portal.Role + Exo Cache cluster configuration for IDM Membership Type entity + + portal.Role + ${exo.cache.portal.role.strategy:LIRS} + ${exo.cache.portal.role.MaxNodes:5000} + ${exo.cache.portal.role.TimeToLive:3600} + ${exo.cache.portal.role.cacheMode:replication} + + + + + portal.Group + Exo Cache cluster configuration for IDM Group entity + + portal.Group + ${exo.cache.portal.group.strategy:LIRS} + ${exo.cache.portal.group.MaxNodes:100} + ${exo.cache.portal.group.TimeToLive:-1} + ${exo.cache.portal.group.cacheMode:replication} + + + + + + + From 3cd46606b87b8ad4aca91b8655d10d24d6ea0620 Mon Sep 17 00:00:00 2001 From: NaderSai Date: Thu, 7 Jan 2021 14:12:56 +0100 Subject: [PATCH 12/12] Job that Gives the number of logged-in users every 10 minutes --- services/pom.xml | 19 ++++ .../addons/jobs/LoggedInNumberJob.java | 29 ++++++ .../addons/listener/LoggedInUserListener.java | 91 +++++++++++++++++++ .../resources/conf/portal/configuration.xml | 51 +++++++++++ 4 files changed, 190 insertions(+) create mode 100644 services/src/main/java/org/exoplatform/addons/jobs/LoggedInNumberJob.java create mode 100644 services/src/main/java/org/exoplatform/addons/listener/LoggedInUserListener.java diff --git a/services/pom.xml b/services/pom.xml index f02d259..d85a47c 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -129,6 +129,25 @@ jsr250-api 1.0 + + + + org.quartz-scheduler + quartz + 2.1.7 + provided + + + + org.exoplatform.kernel + exo.kernel.commons + 2.4.13-GA + + + org.quartz-scheduler + quartz + + Training Exercise - Services diff --git a/services/src/main/java/org/exoplatform/addons/jobs/LoggedInNumberJob.java b/services/src/main/java/org/exoplatform/addons/jobs/LoggedInNumberJob.java new file mode 100644 index 0000000..8e4901a --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/jobs/LoggedInNumberJob.java @@ -0,0 +1,29 @@ +package org.exoplatform.addons.jobs; + +import org.exoplatform.addons.listener.LoggedInUserListener; +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +public class LoggedInNumberJob implements Job { + + private static final Log LOG = ExoLogger.getLogger(LoggedInNumberJob.class); + + LoggedInUserListener loggedInNumberJob; + public LoggedInNumberJob() { + + this.loggedInNumberJob = new LoggedInUserListener(); + } + + + @Override + public void execute(JobExecutionContext context) throws JobExecutionException { + + + LOG.info("The number of logged in users in the last 10 minutes is:"+loggedInNumberJob.countLoggedInUser()); + + + } +} diff --git a/services/src/main/java/org/exoplatform/addons/listener/LoggedInUserListener.java b/services/src/main/java/org/exoplatform/addons/listener/LoggedInUserListener.java new file mode 100644 index 0000000..8fbfda9 --- /dev/null +++ b/services/src/main/java/org/exoplatform/addons/listener/LoggedInUserListener.java @@ -0,0 +1,91 @@ +package org.exoplatform.addons.listener; + +import org.exoplatform.container.PortalContainer; +import org.exoplatform.container.component.ComponentRequestLifecycle; +import org.exoplatform.container.component.RequestLifeCycle; +import org.exoplatform.services.listener.Event; +import org.exoplatform.services.listener.Listener; +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; +import org.exoplatform.services.organization.OrganizationService; +import org.exoplatform.services.organization.User; +import org.exoplatform.services.organization.UserHandler; +import org.exoplatform.services.security.ConversationRegistry; +import org.exoplatform.services.security.ConversationState; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +public class LoggedInUserListener extends Listener{ + + private static final Log LOG = ExoLogger.getLogger(LoggedInUserListener.class); + + public static final String USER_PROFILE = "UserProfile"; + + private PortalContainer container; + + private OrganizationService organizationService; + + public LoggedInUserListener(PortalContainer container) { + this.container = container; + } + public LoggedInUserListener() + { + + } + private static List list = new ArrayList(); + + + public List getList() { + return list; + } + + @Override + public void onEvent(Event event) { + LOG.info("********************************************************User Connected"); + + if (organizationService == null) { + organizationService = this.container.getComponentInstanceOfType(OrganizationService.class); + } + UserHandler userHandler = organizationService.getUserHandler(); + + ConversationState state = event.getData(); + String userId = state.getIdentity().getUserId(); + boolean transactionOpened = false; + if(organizationService instanceof ComponentRequestLifecycle) { + RequestLifeCycle.begin((ComponentRequestLifecycle)organizationService); + transactionOpened = true; + } + try { + User user = (User) state.getAttribute(USER_PROFILE); + + if (user == null) { + user = userHandler.findUserByName(userId); + state.setAttribute(USER_PROFILE, user); + } + + user.setLastLoginTime(Calendar.getInstance().getTime()); + userHandler.saveUser(user, false); + list.add(user); + } catch (Exception e) { + LOG.error("Error while updating the last login time for user {}", userId, e); + } finally { + if(transactionOpened) { + RequestLifeCycle.end(); + } + } + //LOG.info("User Connected/*///////////////////////////////////////////////////////"); + } + + public int countLoggedInUser() + { + LOG.info("*****",list.size()); + return list.size(); + } + + + + +} + diff --git a/services/src/main/resources/conf/portal/configuration.xml b/services/src/main/resources/conf/portal/configuration.xml index c0f2778..2ffe761 100644 --- a/services/src/main/resources/conf/portal/configuration.xml +++ b/services/src/main/resources/conf/portal/configuration.xml @@ -33,6 +33,20 @@ org.exoplatform.addons.DAO.FavoriteActivityDAO + + + org.exoplatform.services.scheduler.impl.QuartzSheduler + + + org.exoplatform.services.scheduler.QueueTasks + + + org.exoplatform.services.scheduler.JobSchedulerService + org.exoplatform.services.scheduler.impl.JobSchedulerServiceImpl + + + + org.exoplatform.services.organization.OrganizationService @@ -42,4 +56,41 @@ send mail after adding user + + + org.exoplatform.services.listener.ListenerService + + exo.core.security.ConversationRegistry.register + addListener + org.exoplatform.addons.listener.LoggedInUserListener + count the number of logged in user + + + + + + + org.exoplatform.services.scheduler.JobSchedulerService + + LoggedInNumberJob + addPeriodJob + org.exoplatform.services.scheduler.PeriodJob + Create a Job that Gives the number of logged-in users every 10 minutes + + + job.info + save the Forums Weekly Statistic data periodically + + + + + + + + + + + + +