diff --git a/kudos-services/pom.xml b/kudos-services/pom.xml index 25179db1b..4fa2baff5 100644 --- a/kudos-services/pom.xml +++ b/kudos-services/pom.xml @@ -23,12 +23,10 @@ org.exoplatform.social social-component-service - provided org.exoplatform.social social-component-notification - provided diff --git a/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosService.java b/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosService.java index 7e25ebab3..fd77875f6 100644 --- a/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosService.java +++ b/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosService.java @@ -32,6 +32,7 @@ import org.exoplatform.container.PortalContainer; import org.exoplatform.container.xml.InitParams; import org.exoplatform.kudos.model.*; +import org.exoplatform.kudos.storage.KudosStorage; import org.exoplatform.services.listener.ListenerService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; diff --git a/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosStorage.java b/kudos-services/src/main/java/org/exoplatform/kudos/storage/KudosStorage.java similarity index 81% rename from kudos-services/src/main/java/org/exoplatform/kudos/service/KudosStorage.java rename to kudos-services/src/main/java/org/exoplatform/kudos/storage/KudosStorage.java index aa6556327..95febc47a 100644 --- a/kudos-services/src/main/java/org/exoplatform/kudos/service/KudosStorage.java +++ b/kudos-services/src/main/java/org/exoplatform/kudos/storage/KudosStorage.java @@ -1,16 +1,28 @@ -package org.exoplatform.kudos.service; +package org.exoplatform.kudos.storage; -import static org.exoplatform.kudos.service.utils.Utils.*; +import static org.exoplatform.kudos.service.utils.Utils.USER_ACCOUNT_TYPE; +import static org.exoplatform.kudos.service.utils.Utils.fromEntity; +import static org.exoplatform.kudos.service.utils.Utils.getSpace; +import static org.exoplatform.kudos.service.utils.Utils.toEntity; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; +import org.picocontainer.Startable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import org.exoplatform.commons.utils.CommonsUtils; +import org.exoplatform.container.PortalContainer; import org.exoplatform.kudos.dao.KudosDAO; import org.exoplatform.kudos.entity.KudosEntity; -import org.exoplatform.kudos.model.*; +import org.exoplatform.kudos.model.Kudos; +import org.exoplatform.kudos.model.KudosEntityType; +import org.exoplatform.kudos.model.KudosPeriod; import org.exoplatform.kudos.service.utils.Utils; import org.exoplatform.portal.config.UserPortalConfigService; import org.exoplatform.services.log.ExoLogger; @@ -21,18 +33,43 @@ import org.exoplatform.social.core.manager.IdentityManager; import org.exoplatform.social.core.space.model.Space; -public class KudosStorage { +import jakarta.annotation.PostConstruct; + +@Service // FIXME Should be @Repository instead, but Kept with @Service to expose it + // into Kernel Container +public class KudosStorage implements Startable { + private static final Log LOG = ExoLogger.getLogger(KudosStorage.class); + @Autowired private KudosDAO kudosDAO; + @Autowired private IdentityManager identityManager; - private String defaultPortal; - - public KudosStorage(KudosDAO kudosDAO, UserPortalConfigService userPortalConfigService) { - this.kudosDAO = kudosDAO; - this.defaultPortal = userPortalConfigService.getDefaultPortal(); + @Autowired + private UserPortalConfigService userPortalConfigService; + + private String defaultPortal; + + @PostConstruct + public void init() { + this.defaultPortal = userPortalConfigService.getMetaPortal(); + } + + /** + * @deprecated kept to be able to use this service as Kernel Service in Unit + * Tests To delete once the Unit Tests migrated + * with Spring and JUnit 5 + */ + @Override + @Deprecated(forRemoval = true, since = "1.6.0") + public void start() { + PortalContainer container = PortalContainer.getInstance(); + this.kudosDAO = container.getComponentInstanceOfType(KudosDAO.class); + this.identityManager = container.getComponentInstanceOfType(IdentityManager.class); + this.defaultPortal = container.getComponentInstanceOfType(UserPortalConfigService.class) + .getDefaultPortal(); } public Kudos getKudoById(long id) { diff --git a/kudos-services/src/main/resources/conf/portal/configuration.xml b/kudos-services/src/main/resources/conf/portal/configuration.xml index 28445e13e..ec44ef043 100644 --- a/kudos-services/src/main/resources/conf/portal/configuration.xml +++ b/kudos-services/src/main/resources/conf/portal/configuration.xml @@ -7,10 +7,6 @@ org.exoplatform.kudos.dao.KudosDAO - - org.exoplatform.kudos.service.KudosStorage - - org.exoplatform.kudos.service.KudosService diff --git a/kudos-services/src/test/java/org/exoplatform/kudos/test/service/KudosServiceTest.java b/kudos-services/src/test/java/org/exoplatform/kudos/test/service/KudosServiceTest.java index 680531e53..939a79749 100644 --- a/kudos-services/src/test/java/org/exoplatform/kudos/test/service/KudosServiceTest.java +++ b/kudos-services/src/test/java/org/exoplatform/kudos/test/service/KudosServiceTest.java @@ -9,9 +9,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.lang3.StringUtils; -import org.exoplatform.commons.exception.ObjectNotFoundException; import org.junit.Test; +import org.exoplatform.commons.exception.ObjectNotFoundException; import org.exoplatform.kudos.entity.KudosEntity; import org.exoplatform.kudos.model.AccountSettings; import org.exoplatform.kudos.model.GlobalSettings; @@ -20,8 +20,8 @@ import org.exoplatform.kudos.model.KudosPeriod; import org.exoplatform.kudos.model.KudosPeriodType; import org.exoplatform.kudos.service.KudosService; -import org.exoplatform.kudos.service.KudosStorage; import org.exoplatform.kudos.service.utils.Utils; +import org.exoplatform.kudos.storage.KudosStorage; import org.exoplatform.kudos.test.BaseKudosTest; import org.exoplatform.services.listener.Event; import org.exoplatform.services.listener.Listener; diff --git a/kudos-services/src/test/resources/conf/kudos-test-configuration.xml b/kudos-services/src/test/resources/conf/kudos-test-configuration.xml index 88601d144..59dc7c527 100644 --- a/kudos-services/src/test/resources/conf/kudos-test-configuration.xml +++ b/kudos-services/src/test/resources/conf/kudos-test-configuration.xml @@ -3,6 +3,10 @@ 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. --> + + org.exoplatform.kudos.storage.KudosStorage + + org.exoplatform.social.core.space.spi.SpaceService org.exoplatform.kudos.test.mock.SpaceServiceMock diff --git a/kudos-webapps/pom.xml b/kudos-webapps/pom.xml index e4bda1096..712bc6f34 100644 --- a/kudos-webapps/pom.xml +++ b/kudos-webapps/pom.xml @@ -9,6 +9,11 @@ war eXo Add-on:: eXo Kudos - Application + + ${project.groupId} + kudos-services + provided + org.exoplatform.platform-ui platform-ui-skin diff --git a/kudos-webapps/src/main/java/io/meeds/kudos/KudosApplication.java b/kudos-webapps/src/main/java/io/meeds/kudos/KudosApplication.java new file mode 100644 index 000000000..a74df1398 --- /dev/null +++ b/kudos-webapps/src/main/java/io/meeds/kudos/KudosApplication.java @@ -0,0 +1,39 @@ +/* + * This file is part of the Meeds project (https://meeds.io/). + * Copyright (C) 2020 - 2022 Meeds Association contact@meeds.io + * This program 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 3 of the License, or (at your option) any later version. + * This program 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 program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package io.meeds.kudos; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; +import org.springframework.context.annotation.PropertySource; + +import io.meeds.spring.AvailableIntegration; +import io.meeds.spring.kernel.PortalApplicationContextInitializer; + +@SpringBootApplication(scanBasePackages = { + KudosApplication.MODULE_NAME, + AvailableIntegration.KERNEL_MODULE, + AvailableIntegration.JPA_MODULE, + AvailableIntegration.WEB_SECURITY_MODULE, +}, +exclude = { + LiquibaseAutoConfiguration.class, +}) +@PropertySource("classpath:application.properties") +public class KudosApplication extends PortalApplicationContextInitializer { + + public static final String MODULE_NAME = "org.exoplatform.kudos"; + +}