Skip to content

Commit

Permalink
chore: update to use Hibernate 5 and Spring JPA; fix topic w/ announc…
Browse files Browse the repository at this point in the history
…ements export issue
  • Loading branch information
groybal committed Sep 23, 2023
1 parent c69d181 commit f20060f
Show file tree
Hide file tree
Showing 40 changed files with 793 additions and 745 deletions.
166 changes: 104 additions & 62 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@
<properties>
<junit.version>4.13.2</junit.version>
<logback.version>1.3.5</logback.version>
<hibernate.version>5.6.15.Final</hibernate.version>
<hsqldb.version>2.7.0</hsqldb.version>
<persistence-api.version>2.2</persistence-api.version>
<resource-server.version>1.3.1</resource-server.version>
<servlet-api.version>3.1.0</servlet-api.version>
<slf4j.version>2.0.6</slf4j.version>
<spring.version>4.3.30.RELEASE</spring.version>
<spring-data.version>2.7.15</spring-data.version>

<!-- The JDBC Driver used by the portlet -->
<jdbc.groupId>org.hsqldb</jdbc.groupId>
<jdbc.artifactId>hsqldb</jdbc.artifactId>
<jdbc.version>2.5.0</jdbc.version>
<jdbc.version>${hsqldb.version}</jdbc.version>

<!-- Utility libraries -->
<jackson.version>2.14.1</jackson.version>
Expand Down Expand Up @@ -104,6 +108,12 @@
<version>2.1.9</version>
</dependency>

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>${persistence-api.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
Expand Down Expand Up @@ -135,13 +145,11 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -150,53 +158,57 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<artifactId>spring-tx</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
<version>${hibernate.version}</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- Needed for schema reset; version compatible with org.hibernate:hibernate-core:3.6.10.FINAL -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.6.0.Final</version>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -211,19 +223,13 @@
<version>3.12.1.GA</version>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.6</version>
</dependency>

<dependency>
<groupId>backport-util-concurrent</groupId>
<artifactId>backport-util-concurrent</artifactId>
<version>3.1</version>
</dependency>

<dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
Expand Down Expand Up @@ -314,8 +320,46 @@
<dependency>
<groupId>org.jasig.portal</groupId>
<artifactId>uPortal-spring</artifactId>
<version>5.12.0</version>
<version>5.15.1</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>org.jasig.portal</groupId>
<artifactId>uPortal-api-internal</artifactId>
</exclusion>
<exclusion>
<groupId>org.jasig.portal</groupId>
<artifactId>uPortal-security-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jasig.portal</groupId>
<artifactId>uPortal-security-mvc</artifactId>
</exclusion>
<exclusion>
<groupId>org.jasig.portal</groupId>
<artifactId>uPortal-tools</artifactId>
</exclusion>
<exclusion>
<groupId>net.oauth.core</groupId>
<artifactId>oauth</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.spi</artifactId>
</exclusion>
</exclusions>
</dependency>


Expand Down Expand Up @@ -357,6 +401,14 @@
<artifactId>resource-server-utils</artifactId>
<version>${resource-server.version}</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand All @@ -377,26 +429,27 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<type>pom</type>
<version>${spring.version}</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Hopper-SR3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>${project.artifactId}</finalName>
<!-- textResources makes context files available to Spring integration tests -->
<testResources>
<testResource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
Expand Down Expand Up @@ -445,7 +498,6 @@

<plugin>
<artifactId>maven-compiler-plugin</artifactId>

<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -455,7 +507,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>

<configuration>
<warName>Announcements</warName>
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
Expand Down Expand Up @@ -490,9 +541,8 @@
<extensions>true</extensions>
</plugin>
<!--
| Invoke this plugin as follows to drop and recreate the Announcements database tables...
|
| >mvn db-init
| To drop and recreate the Announcements database tables, use: mvn db-init
| To import the announcement db tables, use: mvn [-Ddir=dir] data-import
+-->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
Expand All @@ -518,24 +568,6 @@
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</plugin>
<!-- To import the announcement db tables, use mvn [-Ddir=dir] data-import -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>data-import</id>
<phase>data-import</phase>
Expand Down Expand Up @@ -613,6 +645,16 @@
<artifactId>js</artifactId>
<version>1.7R2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</plugin>

Expand Down
40 changes: 18 additions & 22 deletions src/main/java/org/jasig/portlet/announcements/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,17 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import org.jasig.portlet.announcements.model.Topic;
import org.jasig.portlet.announcements.service.IAnnouncementService;
import org.jasig.portlet.announcements.service.IAnnouncementsService;
import org.jasig.portlet.announcements.spring.PortletApplicationContextLocator;
import org.springframework.context.ApplicationContext;

/**
* <p>Exporter class.</p>
*
* @author Unknown
* @version $Id: $Id
*/
public class Exporter {
private static final String SESSION_FACTORY_BEAN_NAME = "sessionFactory";
private static final String ANNOUNCEMENT_SVC_BEAN_NAME = "announcementService";
private static final String ANNOUNCEMENTS_SVC_BEAN_NAME = "announcementsService";

/**
* <p>main.</p>
Expand All @@ -52,31 +45,26 @@ public class Exporter {
* @throws java.lang.Exception if any.
*/
public static void main(String[] args) throws Exception {

String dir = args[0];
ApplicationContext context =
PortletApplicationContextLocator.getApplicationContext(
PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION);
SessionFactory sessionFactory =
context.getBean(SESSION_FACTORY_BEAN_NAME, SessionFactory.class);
IAnnouncementService announcementService =
context.getBean(ANNOUNCEMENT_SVC_BEAN_NAME, IAnnouncementService.class);

Session session = sessionFactory.getCurrentSession();
Transaction transaction = session.beginTransaction();
IAnnouncementsService announcementsService =
context.getBean(ANNOUNCEMENTS_SVC_BEAN_NAME, IAnnouncementsService.class);

JAXBContext jc = JAXBContext.newInstance(Topic.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

List<Topic> topics = announcementService.getAllTopics();
List<Topic> topics = announcementsService.getAllTopics();
for (Topic topic : topics) {
if (topic.getSubscriptionMethod() == 4) {
continue;
}

session.lock(topic, LockMode.NONE);
JAXBElement<Topic> je2 = new JAXBElement<Topic>(new QName("topic"), Topic.class, topic);
updateTopicAnnouncementsToAvoidInfiniteCycleIssueWithJaxb(topic);

JAXBElement<Topic> je2 = new JAXBElement<>(new QName("topic"), Topic.class, topic);
String output = dir + File.separator + UUID.randomUUID().toString() + ".xml";
System.out.println("Exporting Topic " + topic.getId() + " to file " + output);
try {
Expand All @@ -85,6 +73,14 @@ public static void main(String[] args) throws Exception {
exception.printStackTrace();
}
}
transaction.commit();
}

private static void updateTopicAnnouncementsToAvoidInfiniteCycleIssueWithJaxb(Topic topic) {
topic.getAnnouncements().forEach(announcement -> {
Topic topicWithNameOnly = new Topic();
topicWithNameOnly.setTitle(announcement.getParent().getTitle());
announcement.setParent(topicWithNameOnly);
});
}

}
Loading

0 comments on commit f20060f

Please sign in to comment.