Skip to content

Commit

Permalink
feat: Initialize Spring Integration - Meeds-io/MIPs#57
Browse files Browse the repository at this point in the history
This change will introduce Spring into Kudos Addon with the most minimal configuration for an hybrid IoC based containers: Spring and Meeds Kernel. This will allow to constinuously test and continuously migrate applications from deprecated Meeds Kernel Module to Spring.
  • Loading branch information
boubaker committed Dec 29, 2023
1 parent fa34f40 commit eae9f75
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 18 deletions.
2 changes: 0 additions & 2 deletions kudos-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
<dependency>
<groupId>org.exoplatform.social</groupId>
<artifactId>social-component-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.exoplatform.social</groupId>
<artifactId>social-component-notification</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<type>org.exoplatform.kudos.dao.KudosDAO</type>
</component>

<component>
<type>org.exoplatform.kudos.service.KudosStorage</type>
</component>

<component>
<type>org.exoplatform.kudos.service.KudosService</type>
<init-params>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd" xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">

<component>
<type>org.exoplatform.kudos.storage.KudosStorage</type>
</component>

<component>
<key>org.exoplatform.social.core.space.spi.SpaceService</key>
<type>org.exoplatform.kudos.test.mock.SpaceServiceMock</type>
Expand Down
5 changes: 5 additions & 0 deletions kudos-webapps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<packaging>war</packaging>
<name>eXo Add-on:: eXo Kudos - Application</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>kudos-services</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.exoplatform.platform-ui</groupId>
<artifactId>platform-ui-skin</artifactId>
Expand Down
39 changes: 39 additions & 0 deletions kudos-webapps/src/main/java/io/meeds/kudos/KudosApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2022 Meeds Association [email protected]
* 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";

}

0 comments on commit eae9f75

Please sign in to comment.