Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Integration - Meeds-io/MIPs#57 #454

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kudos-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<rest.api.doc.version>1.0</rest.api.doc.version>
<rest.api.doc.description>Kudos addon rest endpoints</rest.api.doc.description>

<exo.test.coverage.ratio>0.64</exo.test.coverage.ratio>
<exo.test.coverage.ratio>0.60</exo.test.coverage.ratio>
</properties>
<dependencies>
<dependency>
Expand All @@ -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 @@ -5,9 +5,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import javax.persistence.NoResultException;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import jakarta.persistence.NoResultException;
import jakarta.persistence.Tuple;
import jakarta.persistence.TypedQuery;

import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
import org.exoplatform.kudos.entity.KudosEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.Serializable;

import javax.persistence.*;
import jakarta.persistence.*;

import org.hibernate.annotations.DynamicUpdate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.exoplatform.kudos.service.utils.Utils.KUDOS_ACTIVITY_COMMENT_TYPE;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.kudos.model.Kudos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.exoplatform.analytics.utils.AnalyticsUtils.addSpaceStatistics;
import static org.exoplatform.analytics.utils.AnalyticsUtils.getIdentity;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.analytics.model.StatisticData;
import org.exoplatform.analytics.utils.AnalyticsUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.kudos.model.AccountSettings;
import org.exoplatform.kudos.service.KudosService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.kudos.exception.KudosAlreadyLinkedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.time.LocalDateTime;
import java.util.*;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.kudos.exception.KudosAlreadyLinkedException;
import org.picocontainer.Startable;
Expand All @@ -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
Expand Up @@ -3,7 +3,7 @@
import java.time.*;
import java.util.*;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.commons.api.notification.model.ArgumentLiteral;
Expand Down Expand Up @@ -165,7 +165,7 @@ public static Kudos fromEntity(KudosEntity kudosEntity, String defaultPortal) {
kudos.setReceiverId(receiverIdentity.getRemoteId());
kudos.setReceiverIdentityId(getIdentityIdByType(receiverIdentity));
kudos.setReceiverType(USER_ACCOUNT_TYPE);
kudos.setReceiverPosition(StringEscapeUtils.unescapeHtml(receiverIdentity.getProfile().getPosition()));
kudos.setReceiverPosition(StringEscapeUtils.unescapeHtml4(receiverIdentity.getProfile().getPosition()));
kudos.setExternalReceiver(receiverIdentity.getProfile() != null
&& receiverIdentity.getProfile().getProperty("external") != null
&& receiverIdentity.getProfile().getProperty("external").equals("true"));
Expand Down Expand Up @@ -250,9 +250,9 @@ public static KudosPeriodType getPeriodType(GlobalSettings globalSettings) {

public static void computeKudosActivityProperties(ExoSocialActivity activity, Kudos kudos) {
String senderLink = "<a href='" + kudos.getSenderURL() + "'>" + kudos.getSenderFullName() + "</a>";
senderLink = StringEscapeUtils.unescapeHtml(senderLink);
senderLink = StringEscapeUtils.unescapeHtml4(senderLink);
String receiverLink = "<a href='" + kudos.getReceiverURL() + "'>" + kudos.getReceiverFullName() + "</a>";
receiverLink = StringEscapeUtils.unescapeHtml(receiverLink);
receiverLink = StringEscapeUtils.unescapeHtml4(receiverLink);

String kudosMessage = kudos.getMessage();
String message = StringUtils.isBlank(kudosMessage) ? "." : ": " + kudosMessage;
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 @@ -4,7 +4,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;

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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
} else {
message = _ctx.appRes("Notification.kudos.received", profileUrl);
}
if(org.apache.commons.lang.StringUtils.isNotBlank(ACTIVITY)) {
if(org.apache.commons.lang3.StringUtils.isNotBlank(ACTIVITY)) {
message += " " + _ctx.appRes("Notification.kudos.onActivity");
}
%>
<%=message%>
</p>
<% if(org.apache.commons.lang.StringUtils.isNotBlank(ACTIVITY)) { %>
<% if(org.apache.commons.lang3.StringUtils.isNotBlank(ACTIVITY)) { %>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff" align="center" style="background-color: #ffffff; font-size: 12px;color:#333333;line-height: 18px;">
<tbody>
<tr>
Expand All @@ -40,7 +40,7 @@
</table>
<br/>
<% } %>
<% if(org.apache.commons.lang.StringUtils.isNotBlank(KUDOS_MESSAGE)) { %>
<% if(org.apache.commons.lang3.StringUtils.isNotBlank(KUDOS_MESSAGE)) { %>
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff" align="center" style="background-color: #ffffff; font-size: 12px;color:#333333;line-height: 18px; margin-bottom: 15px;">
<tbody>
<tr>
Expand All @@ -52,7 +52,7 @@
</table>
<br/>
<% } %>
<% if(org.apache.commons.lang.StringUtils.isNotBlank(ACTIVITY)) { %>
<% if(org.apache.commons.lang3.StringUtils.isNotBlank(ACTIVITY)) { %>
<p style="margin: 0 0 20px;">
<a target="_blank" style="
display: inline-block;
Expand Down