diff --git a/pom.xml b/pom.xml index 2b77d1cf..0c2c9127 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,9 @@ 4.13.2 1.3.5 + 5.6.15.Final + 2.7.0 + 2.2 1.3.1 3.1.0 2.0.6 @@ -104,6 +107,12 @@ 2.1.9 + + javax.persistence + javax.persistence-api + ${persistence-api.version} + + javax.servlet jstl @@ -135,13 +144,11 @@ org.springframework spring-beans - ${spring.version} org.springframework spring-core - ${spring.version} commons-logging @@ -150,53 +157,57 @@ + + org.springframework.data + spring-data-jpa + + org.springframework - spring-orm - ${spring.version} + spring-tx org.springframework spring-web - ${spring.version} org.springframework spring-webmvc - ${spring.version} org.springframework spring-webmvc-portlet - ${spring.version} org.springframework spring-test - ${spring.version} org.springframework spring-context-support - ${spring.version} org.hibernate hibernate-core - 3.6.10.Final + ${hibernate.version} + + + + org.hibernate + hibernate-ehcache + ${hibernate.version} - org.hibernate hibernate-tools - 3.6.0.Final + ${hibernate.version} commons-logging @@ -211,19 +222,13 @@ 3.12.1.GA - - net.sf.ehcache - ehcache - 2.10.6 - - backport-util-concurrent backport-util-concurrent 3.1 - + org.slf4j slf4j-api ${slf4j.version} @@ -314,8 +319,46 @@ org.jasig.portal uPortal-spring - 5.12.0 + 5.15.1 jar + + + org.jasig.portal + uPortal-api-internal + + + org.jasig.portal + uPortal-security-core + + + org.jasig.portal + uPortal-security-mvc + + + org.jasig.portal + uPortal-tools + + + net.oauth.core + oauth + + + org.springframework + spring-webmvc + + + net.sf.ehcache + ehcache-core + + + org.jadira.usertype + usertype.core + + + org.jadira.usertype + usertype.spi + + @@ -357,6 +400,14 @@ resource-server-utils ${resource-server.version} + + net.sf.ehcache + ehcache-core + + + net.sf.ehcache + ehcache-web + org.springframework spring-web @@ -377,26 +428,27 @@ + + + + org.springframework + spring-framework-bom + pom + ${spring.version} + import + + + org.springframework.data + spring-data-releasetrain + Hopper-SR3 + import + pom + + + + ${project.artifactId} - - - - src/main/webapp/WEB-INF - true - - **/*.xml - **/*.properties - - - - src/test/resources - true - - **/*.properties - - - com.mycila @@ -445,7 +497,6 @@ maven-compiler-plugin - 1.8 1.8 @@ -455,7 +506,6 @@ org.apache.maven.plugins maven-war-plugin - Announcements ${basedir}/src/main/webapp/WEB-INF/web.xml @@ -490,9 +540,8 @@ true maven-antrun-plugin @@ -518,24 +567,6 @@ - - - - javax.servlet - javax.servlet-api - ${servlet-api.version} - - - javax.portlet - portlet-api - 2.0 - - - - - - maven-antrun-plugin - data-import data-import @@ -613,6 +644,16 @@ js 1.7R2 + + javax.servlet + javax.servlet-api + ${servlet-api.version} + + + javax.portlet + portlet-api + 2.0 + diff --git a/src/main/java/org/jasig/portlet/announcements/Exporter.java b/src/main/java/org/jasig/portlet/announcements/Exporter.java index aef1b074..9945e8fe 100644 --- a/src/main/java/org/jasig/portlet/announcements/Exporter.java +++ b/src/main/java/org/jasig/portlet/announcements/Exporter.java @@ -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; /** *

Exporter class.

- * - * @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"; /** *

main.

@@ -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 topics = announcementService.getAllTopics(); + List topics = announcementsService.getAllTopics(); for (Topic topic : topics) { if (topic.getSubscriptionMethod() == 4) { continue; } - session.lock(topic, LockMode.NONE); - JAXBElement je2 = new JAXBElement(new QName("topic"), Topic.class, topic); + updateTopicAnnouncementsToAvoidInfiniteCycleIssueWithJaxb(topic); + + JAXBElement 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 { @@ -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); + }); + } + } diff --git a/src/main/java/org/jasig/portlet/announcements/Importer.java b/src/main/java/org/jasig/portlet/announcements/Importer.java index e33304dd..3a9595c9 100644 --- a/src/main/java/org/jasig/portlet/announcements/Importer.java +++ b/src/main/java/org/jasig/portlet/announcements/Importer.java @@ -36,7 +36,7 @@ import org.hibernate.HibernateException; import org.jasig.portlet.announcements.model.Announcement; 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; @@ -48,25 +48,25 @@ */ public class Importer { - private static final String ANNOUNCEMENT_SVC_BEAN_NAME = "announcementService"; + private static final String ANNOUNCEMENTS_SVC_BEAN_NAME = "announcementsService"; private static final Log log = LogFactory.getLog(Importer.class); private File dataDirectory; - private IAnnouncementService announcementService; + private IAnnouncementsService announcementsService; private List errors = new ArrayList(); /** *

Constructor for Importer.

* * @param dataDirectory a {@link java.io.File} object. - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. + * @param announcementsService a {@link org.jasig.portlet.announcements.service.IAnnouncementsService} object. */ public Importer( File dataDirectory, /*SessionFactory sessionFactory, */ - IAnnouncementService announcementService) { + IAnnouncementsService announcementsService) { this.dataDirectory = dataDirectory; - this.announcementService = announcementService; + this.announcementsService = announcementsService; } /** @@ -100,10 +100,10 @@ public static void main(String[] args) { ApplicationContext context = PortletApplicationContextLocator.getApplicationContext( PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION); - IAnnouncementService announcementService = - context.getBean(ANNOUNCEMENT_SVC_BEAN_NAME, IAnnouncementService.class); + IAnnouncementsService announcementsService = + context.getBean(ANNOUNCEMENTS_SVC_BEAN_NAME, IAnnouncementsService.class); - Importer importer = new Importer(dataDirectory, announcementService); + Importer importer = new Importer(dataDirectory, announcementsService); importer.importData(); if (importer.errors.size() > 0) { @@ -147,7 +147,7 @@ private void importTopics() { log.error(msg); errors.add(msg); } else { - announcementService.addOrSaveTopic(topic); + announcementsService.addOrSaveTopic(topic); log.info("Successfully imported topic '" + topic.getTitle() + "'"); } } catch (JAXBException e) { @@ -209,7 +209,7 @@ private void importAnnouncements() { } else { Topic topic = findTopicForAnnouncement(announcement); announcement.setParent(topic); - announcementService.addOrSaveAnnouncement(announcement); + announcementsService.addOrSaveAnnouncement(announcement); log.info("Successfully imported announcement '" + announcement.getTitle() + "'"); } } catch (ImportException e) { @@ -240,7 +240,7 @@ private void importAnnouncements() { private Topic findTopicForAnnouncement(Announcement announcement) { Topic topic = null; - List topics = announcementService.getAllTopics(); + List topics = announcementsService.getAllTopics(); for (Topic t : topics) { if (t.getTitle().equals(announcement.getParent().getTitle())) { if (topic != null) { diff --git a/src/main/java/org/jasig/portlet/announcements/SchemaCreator.java b/src/main/java/org/jasig/portlet/announcements/SchemaCreator.java index dab7ec2a..bef317f7 100644 --- a/src/main/java/org/jasig/portlet/announcements/SchemaCreator.java +++ b/src/main/java/org/jasig/portlet/announcements/SchemaCreator.java @@ -18,21 +18,22 @@ */ package org.jasig.portlet.announcements; -import java.sql.Connection; -import java.sql.SQLException; +import java.io.File; +import java.util.EnumSet; import java.util.List; -import javax.sql.DataSource; +import javax.persistence.EntityManagerFactory; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.cfg.Configuration; +import org.hibernate.boot.MetadataSources; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; import org.jasig.portlet.announcements.spring.PortletApplicationContextLocator; -import org.springframework.beans.BeansException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.orm.hibernate3.LocalSessionFactoryBean; /** * This tool is responsible for creating the Announcements portlet database schema (and dropping @@ -40,31 +41,15 @@ * with Announcements' Spring-managed ORM strategy and Announcements' configuration features (esp. * encrypted properties). It is invokable from the command line with '$ java', but designed to be * integrated with build tools like Gradle. - * - * @author Unknown - * @version $Id: $Id */ -public class SchemaCreator implements ApplicationContextAware { - - /* - * Prefixing a Spring factory bean with '&' gives you the factory itself, rather than the product. - * (https://stackoverflow.com/questions/2736100/how-can-i-get-the-hibernate-configuration-object-from-spring) - */ - private static final String SESSION_FACTORY_BEAN_NAME = "&sessionFactory"; +public class SchemaCreator { - private static final String DATA_SOURCE_BEAN_NAME = "dataSource"; + private final Logger logger = LoggerFactory.getLogger(getClass()); - private ApplicationContext applicationContext; + @Autowired + private EntityManagerFactory entityManagerFactory; - private final Log logger = LogFactory.getLog(getClass()); - - /** - *

main.

- * - * @param args an array of {@link java.lang.String} objects. - */ public static void main(String[] args) { - // There will be an instance of this class in the ApplicationContent ApplicationContext context = PortletApplicationContextLocator.getApplicationContext( @@ -73,43 +58,32 @@ public static void main(String[] args) { System.exit(schemaCreator.create()); } - /** {@inheritDoc} */ - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - private int create() { + try { + SessionFactoryImplementor sessionFactory = entityManagerFactory.unwrap(SessionFactoryImplementor.class); + ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry(); - /* - * We will need to provide a Configuration and a Connection; both should be properly - * managed by the Spring ApplicationContext. - */ + MetadataSources metadata = new MetadataSources(serviceRegistry.getParentServiceRegistry()); + metadata.addDirectory(new File("src/main/resources/hibernate-mappings")); - final LocalSessionFactoryBean sessionFactoryBean = applicationContext - .getBean(SESSION_FACTORY_BEAN_NAME, LocalSessionFactoryBean.class); - final DataSource dataSource = applicationContext.getBean(DATA_SOURCE_BEAN_NAME, DataSource.class); - - try (final Connection conn = dataSource.getConnection()) { - final Configuration cfg = sessionFactoryBean.getConfiguration(); - final SchemaExport schemaExport = new SchemaExport(cfg, conn); - schemaExport.execute(true, true, false, false); + EnumSet enumSet = EnumSet.of(TargetType.DATABASE); + SchemaExport schemaExport = new SchemaExport(); + schemaExport.execute(enumSet, SchemaExport.Action.BOTH, metadata.buildMetadata()); final List exceptions = schemaExport.getExceptions(); - if (exceptions.size() != 0) { + if (!exceptions.isEmpty()) { logger.error("Schema Create Failed; see below for details"); for (Exception e : exceptions) { logger.error("Exception from Hibernate Tools SchemaExport", e); } return 1; } - } catch (SQLException sqle) { - logger.error("Failed to initialize & invoke the SchemaExport tool", sqle); + } catch (Exception e) { + logger.error("Failed to initialize & invoke the SchemaExport tool", e); return 1; } return 0; - } } diff --git a/src/main/java/org/jasig/portlet/announcements/dao/jpa/AnnouncementsRepository.java b/src/main/java/org/jasig/portlet/announcements/dao/jpa/AnnouncementsRepository.java new file mode 100644 index 00000000..0919cfaf --- /dev/null +++ b/src/main/java/org/jasig/portlet/announcements/dao/jpa/AnnouncementsRepository.java @@ -0,0 +1,21 @@ +package org.jasig.portlet.announcements.dao.jpa; + +import org.jasig.portlet.announcements.model.Announcement; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +import java.util.Calendar; + +public interface AnnouncementsRepository extends CrudRepository { + + @Query( + value = "delete from Announcement where END_DISPLAY < current_timestamp()", + nativeQuery = true) + long deleteWhereEndDisplayPastCurrentTime(); + + @Query( + value = "delete from Announcement where END_DISPLAY < :date", + nativeQuery = true) + long deleteWhereEndDisplayPastDate(Calendar date); + +} diff --git a/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicSubscriptionsRepository.java b/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicSubscriptionsRepository.java new file mode 100644 index 00000000..8dab6337 --- /dev/null +++ b/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicSubscriptionsRepository.java @@ -0,0 +1,12 @@ +package org.jasig.portlet.announcements.dao.jpa; + +import org.jasig.portlet.announcements.model.TopicSubscription; +import org.springframework.data.repository.CrudRepository; + +public interface TopicSubscriptionsRepository extends CrudRepository { + + Iterable findByTopicId(Long topicId); + + Iterable findByOwner(String ownerId); + +} diff --git a/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicsRepository.java b/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicsRepository.java new file mode 100644 index 00000000..9507981c --- /dev/null +++ b/src/main/java/org/jasig/portlet/announcements/dao/jpa/TopicsRepository.java @@ -0,0 +1,10 @@ +package org.jasig.portlet.announcements.dao.jpa; + +import org.jasig.portlet.announcements.model.Topic; +import org.springframework.data.repository.CrudRepository; + +public interface TopicsRepository extends CrudRepository { + + Iterable findBySubscriptionMethod(Integer subMethod); + +} diff --git a/src/main/java/org/jasig/portlet/announcements/hibernate/ApplicationContextConnectionProvider.java b/src/main/java/org/jasig/portlet/announcements/hibernate/ApplicationContextConnectionProvider.java index 9bf41228..78aa3cc9 100644 --- a/src/main/java/org/jasig/portlet/announcements/hibernate/ApplicationContextConnectionProvider.java +++ b/src/main/java/org/jasig/portlet/announcements/hibernate/ApplicationContextConnectionProvider.java @@ -22,93 +22,87 @@ import java.sql.SQLException; import java.util.Properties; import javax.sql.DataSource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.hibernate.HibernateException; -import org.hibernate.connection.ConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.jasig.portlet.announcements.spring.PortletApplicationContextLocator; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; /** - * When the hibernate3-maven-plugin:hbm2ddl goal is executed, this class provides connections from - * the Spring ApplicationContext, which is capable of using encrypted database connection settings - * (in datasource.properties). + * When the hibernate3-maven-plugin:hbm2ddl goal is executed, this class + * provides connections from the Spring ApplicationContext, which is capable of + * using encrypted database connection settings (in datasource.properties). * - * @author drewwills - * @version $Id: $Id + * @deprecated Because this class is not necessary for Import/Export based on Gradle */ +@Deprecated public class ApplicationContextConnectionProvider implements ConnectionProvider { - private static final String DATA_SOURCE_BEAN_NAME = "dataSource"; + private static final long serialVersionUID = 1L; - private ApplicationContext context; + private static final String DATA_SOURCE_BEAN_NAME = "dataSource"; - private final Log logger = LogFactory.getLog(getClass()); + private ApplicationContext context; - /** {@inheritDoc} */ - @Override - public void close() throws HibernateException { - if (context != null) { - ((ConfigurableApplicationContext) context).close(); + Logger log = LoggerFactory.getLogger(this.getClass()); + + @Override + public void closeConnection(Connection conn) throws SQLException { + conn.close(); } - } - /** {@inheritDoc} */ - @Override - public void closeConnection(Connection conn) throws SQLException { - conn.close(); - } + @Override + public Connection getConnection() throws SQLException { - /** {@inheritDoc} */ - @Override - public void configure(Properties props) throws HibernateException { - /* - * Configuration is handled by the ApplicationContext itself; there is - * nothing to do here. - */ - } + if (context == null) { + init(); + } - /** {@inheritDoc} */ - @Override - public Connection getConnection() throws SQLException { + final DataSource dataSource = context.getBean(DATA_SOURCE_BEAN_NAME, DataSource.class); + final Connection rslt = dataSource.getConnection(); + log.info("Providing the following connection to hbm2ddl: " + rslt); + return rslt; - if (context == null) { - init(); } - final DataSource dataSource = context.getBean(DATA_SOURCE_BEAN_NAME, DataSource.class); - final Connection rslt = dataSource.getConnection(); - logger.info("Providing the following connection to hbm2ddl: " + rslt); - return rslt; - } + @Override + public boolean supportsAggressiveRelease() { + return false; // WTF? + } - /** {@inheritDoc} */ - @Override - public boolean supportsAggressiveRelease() { - return false; // WTF? - } + @Override + public boolean isUnwrappableAs(@SuppressWarnings("rawtypes") Class arg0) { + return false; // WTF? + } - /* - * Implementation - */ + @Override + public T unwrap(Class arg0) { + throw new UnsupportedOperationException(); + } - private synchronized void init() { + /* + * Implementation + */ - if (context != null) { - // Already done... - return; + private synchronized void init() { + + if (context != null) { + // Already done... + return; + } + + try { + context = + PortletApplicationContextLocator.getApplicationContext( + PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION); + } catch (Exception e) { + log.error( + "Unable to load the application context from " + + PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION, + e); + } } - try { - context = - PortletApplicationContextLocator.getApplicationContext( - PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION); - } catch (Exception e) { - logger.error( - "Unable to load the application context from " - + PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION, - e); - } - } } diff --git a/src/main/java/org/jasig/portlet/announcements/model/Topic.java b/src/main/java/org/jasig/portlet/announcements/model/Topic.java index 2f00c154..a8533be1 100644 --- a/src/main/java/org/jasig/portlet/announcements/model/Topic.java +++ b/src/main/java/org/jasig/portlet/announcements/model/Topic.java @@ -57,7 +57,7 @@ public class Topic { private static final Log logger = LogFactory.getLog(Topic.class); - private Set announcements; + private Set announcements = new HashSet<>(); private Set subscriptions; @@ -439,6 +439,7 @@ public Long getId() { */ public void setAnnouncements(Set announcements) { this.announcements = announcements; + this.announcements.forEach(ann -> ann.setParent(this)); } /** @param id the id to set */ diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/TopicEditor.java b/src/main/java/org/jasig/portlet/announcements/mvc/TopicEditor.java index cf6c8815..cf488271 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/TopicEditor.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/TopicEditor.java @@ -21,7 +21,7 @@ import java.beans.PropertyEditorSupport; import javax.portlet.PortletException; import org.jasig.portlet.announcements.model.Topic; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; /** *

TopicEditor class.

@@ -31,15 +31,15 @@ */ public class TopicEditor extends PropertyEditorSupport { - private IAnnouncementService announcementService; + private IAnnouncementsService announcementsService; /** *

Constructor for TopicEditor.

* - * @param service a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. + * @param service a {@link org.jasig.portlet.announcements.service.IAnnouncementsService} object. */ - public TopicEditor(IAnnouncementService service) { - this.announcementService = service; + public TopicEditor(IAnnouncementsService service) { + this.announcementsService = service; } /* (non-Javadoc) @@ -63,7 +63,7 @@ public String getAsText() { public void setAsText(String text) throws IllegalArgumentException { if (text != null && !"".equals(text)) { try { - super.setValue(announcementService.getTopic(Long.parseLong(text))); + super.setValue(announcementsService.getTopic(Long.parseLong(text))); } catch (PortletException e) { throw new IllegalArgumentException("Invalid Topic ID. Cannot convert to object."); } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminAnnouncementController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminAnnouncementController.java index d0725703..8883d2a1 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminAnnouncementController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminAnnouncementController.java @@ -30,7 +30,7 @@ import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.model.validators.AnnouncementValidator; import org.jasig.portlet.announcements.mvc.TopicEditor; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.UserPermissionChecker; import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory; import org.springframework.beans.factory.InitializingBean; @@ -93,7 +93,7 @@ public class AdminAnnouncementController implements InitializingBean { + " extended_valid_elements:\"a[name|href|target|title|onclick],span[class|align|style]\", " + " theme_advanced_path:false"; - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; private static final Log log = LogFactory.getLog(AdminController.class); private PropertyEditor topicEditor; @@ -161,7 +161,7 @@ public String showAddAnnouncementForm( try { log.debug( "editId found. This is an edit request for announcement Id " + editId.toString()); - ann = announcementService.getAnnouncement(editId); + ann = announcementsService.getAnnouncement(editId); // return immediately when we have our announcement } catch (NumberFormatException e) { @@ -171,7 +171,7 @@ public String showAddAnnouncementForm( if (ann != null && ann.getParent() == null) { try { - topic = announcementService.getTopic(topicId); + topic = announcementsService.getTopic(topicId); ann.setParent(topic); } catch (NumberFormatException e) { log.error("Unable to get topicId from request"); @@ -243,11 +243,8 @@ public void actionAddAnnouncementForm( // add the automatic data announcement.setAuthor(req.getRemoteUser()); announcement.setCreated(new Date()); - announcementService.addOrSaveAnnouncement(announcement); - } else { - announcementService.mergeAnnouncement(announcement); } - + announcementsService.addOrSaveAnnouncement(announcement); status.setComplete(); res.setRenderParameter("topicId", announcement.getParent().getId().toString()); res.setRenderParameter("action", "showTopic"); @@ -271,8 +268,8 @@ public void actionDeleteAnnouncement( ActionResponse response) throws PortletException { - Topic topic = announcementService.getTopic(topicId); - Announcement ann = announcementService.getAnnouncement(annId); + Topic topic = announcementsService.getTopic(topicId); + Announcement ann = announcementsService.getAnnouncement(annId); UserPermissionChecker upChecker = userPermissionCheckerFactory.createUserPermissionChecker(request, topic); @@ -282,7 +279,7 @@ public void actionDeleteAnnouncement( && ann.getAuthor() != null && ann.getAuthor().equals(request.getRemoteUser()))) { // the person deleting the announcement must be the author, a moderator or an admin - announcementService.deleteAnnouncement(ann); + announcementsService.deleteAnnouncement(ann); } else { throw new UnauthorizedException("You do not have permission to delete this announcement"); } @@ -395,20 +392,20 @@ public void setCustomDateFormat(String customDateFormat) { } } - /** @param announcementService the announcementService to set */ + /** @param announcementsService the announcementsService to set */ /** *

Setter for the field announcementService.

* - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. + * @param announcementsService a {@link org.jasig.portlet.announcements.service.IAnnouncementsService} object. */ - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } /** *

afterPropertiesSet.

*/ public void afterPropertiesSet() throws Exception { - topicEditor = new TopicEditor(announcementService); + topicEditor = new TopicEditor(announcementsService); } } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminController.java index 42ad516c..ca8e092b 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminController.java @@ -23,7 +23,7 @@ import javax.portlet.RenderRequest; import org.jasig.portlet.announcements.model.Announcement; 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.service.UserPermissionChecker; import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -41,7 +41,7 @@ @RequestMapping("VIEW") public class AdminController { - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; @Autowired private UserPermissionCheckerFactory userPermissionCheckerFactory = null; @@ -56,7 +56,7 @@ public class AdminController { @RequestMapping public String showBaseView(RenderRequest request, Model model) { - List allTopics = announcementService.getAllTopics(); + List allTopics = announcementsService.getAllTopics(); List pendingAnnouncements = new ArrayList(); // add all topics for the portal admin @@ -95,13 +95,13 @@ public String showBaseView(RenderRequest request, Model model) { return "baseAdmin"; } - /** @param announcementService the announcementService to set */ + /** @param announcementsService the announcementService to set */ /** *

Setter for the field announcementService.

* - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. + * @param announcementsService a {@link org.jasig.portlet.announcements.service.IAnnouncementsService} object. */ - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminRoleSetController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminRoleSetController.java index 45941a88..f0709490 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminRoleSetController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminRoleSetController.java @@ -24,7 +24,7 @@ import javax.portlet.PortletException; import org.jasig.portlet.announcements.model.RoleSelection; 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.service.IGroupService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -44,7 +44,7 @@ @RequestMapping("VIEW") public class AdminRoleSetController { - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; @Autowired private IGroupService groupService; /** @@ -67,7 +67,7 @@ public void processSubmit( throws PortletException { if (!errors.hasErrors()) { - Topic topic = announcementService.getTopic(topicId); + Topic topic = announcementsService.getTopic(topicId); // Extract and save the USER members Set oldGroupList = topic.getGroup(groupKey); @@ -89,7 +89,7 @@ public void processSubmit( topic.setGroup(groupKey, newList); // save the topic to the database - announcementService.addOrSaveTopic(topic); + announcementsService.addOrSaveTopic(topic); response.setRenderParameter("topicId", topicId.toString()); response.setRenderParameter("action", "showTopic"); @@ -111,7 +111,7 @@ public String showForm( throws PortletException { if (!model.containsAttribute("selection")) { - Topic topic = announcementService.getTopic(topicId); + Topic topic = announcementsService.getTopic(topicId); Set group = topic.getGroup(groupKey); model.addAttribute("selection", new RoleSelection(group)); @@ -141,12 +141,12 @@ public void processAddUser( @RequestParam("userAdd") String userAdd) throws PortletException { - Topic topic = announcementService.getTopic(topicId); + Topic topic = announcementsService.getTopic(topicId); Set updateGroup = topic.getGroup(groupKey); updateGroup.add("USER." + userAdd); - announcementService.addOrSaveTopic(topic); + announcementsService.addOrSaveTopic(topic); response.setRenderParameter("topicId", topicId.toString()); response.setRenderParameter("groupKey", groupKey); @@ -170,34 +170,22 @@ public void processDeleteUser( @RequestParam("userKey") String userKey) throws PortletException { - Topic topic = announcementService.getTopic(topicId); + Topic topic = announcementsService.getTopic(topicId); Set updateGroup = topic.getGroup(groupKey); updateGroup.remove(userKey); - announcementService.addOrSaveTopic(topic); + announcementsService.addOrSaveTopic(topic); response.setRenderParameter("topicId", topicId.toString()); response.setRenderParameter("groupKey", groupKey); response.setRenderParameter("action", "addMembers"); } - /** @param announcementService the announcementService to set */ - /** - *

Setter for the field announcementService.

- * - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. - */ - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } - /** @param groupService the groupService to set */ - /** - *

Setter for the field groupService.

- * - * @param groupService a {@link org.jasig.portlet.announcements.service.IGroupService} object. - */ public void setGroupService(IGroupService groupService) { this.groupService = groupService; } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminTopicController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminTopicController.java index 9845a731..d1930d0c 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminTopicController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/AdminTopicController.java @@ -36,7 +36,7 @@ import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.model.UserRoles; import org.jasig.portlet.announcements.model.validators.TopicValidator; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.UserPermissionChecker; import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +66,7 @@ public class AdminTopicController { private static final Log log = LogFactory.getLog(AdminTopicController.class); - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; @Autowired private UserPermissionCheckerFactory userPermissionCheckerFactory = null; @@ -86,7 +86,7 @@ public String showAddTopicForm( if (!model.containsAttribute("topic")) { if (topicIdStr != null && !"".equals(topicIdStr)) { Long topicId = Long.parseLong(topicIdStr); - Topic t = announcementService.getTopic(topicId); + Topic t = announcementsService.getTopic(topicId); model.addAttribute("topic", t); if (log.isDebugEnabled()) log.debug("Adding existing topic to model: " + t.toString()); } else { @@ -133,16 +133,16 @@ public void actionAddTopicForm( // no id has been assigned by hibernate, so this must be a new topic if (!topic.hasId()) { topic.setCreator(request.getRemoteUser()); - announcementService.addOrSaveTopic(topic); + announcementsService.addOrSaveTopic(topic); } else { Long id = topic.getId(); - Topic oldTopic = announcementService.getTopic(id); + Topic oldTopic = announcementsService.getTopic(id); oldTopic.setTitle(topic.getTitle()); oldTopic.setDescription(topic.getDescription()); oldTopic.setAllowRss(topic.isAllowRss()); oldTopic.setSubscriptionMethod(topic.getSubscriptionMethod()); - announcementService.addOrSaveTopic(oldTopic); + announcementsService.addOrSaveTopic(oldTopic); } status.setComplete(); @@ -163,13 +163,13 @@ public void actionAddTopicForm( public void actionDeleteTopic( @RequestParam("topicId") String topicId, ActionRequest request, ActionResponse response) throws NumberFormatException, PortletException { - Topic topic = announcementService.getTopic(Long.parseLong(topicId)); + Topic topic = announcementsService.getTopic(Long.parseLong(topicId)); if (!UserPermissionChecker.inRoleForTopic(request, UserRoles.ADMIN_ROLE_NAME, topic)) { throw new UnauthorizedException("You do not have access to delete this topic!"); } - announcementService.deleteTopic(topic); + announcementsService.deleteTopic(topic); response.setRenderParameter("action", "baseAdmin"); } @@ -190,7 +190,7 @@ public String showTopic( throws NumberFormatException, PortletException { PortletPreferences prefs = request.getPreferences(); - Topic topic = announcementService.getTopic(Long.parseLong(topicId)); + Topic topic = announcementsService.getTopic(Long.parseLong(topicId)); UserPermissionChecker upChecker = userPermissionCheckerFactory.createUserPermissionChecker(request, topic); @@ -216,13 +216,7 @@ public String showTopic( return "showTopic"; } - /** @param announcementService the announcementService to set */ - /** - *

Setter for the field announcementService.

- * - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. - */ - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/PreviewAnnouncementController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/PreviewAnnouncementController.java index 00347514..c463b530 100755 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/PreviewAnnouncementController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/PreviewAnnouncementController.java @@ -22,7 +22,7 @@ import org.jasig.portlet.announcements.model.Announcement; import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.mvc.IViewNameSelector; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.UserPermissionChecker; import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +40,7 @@ @Controller public class PreviewAnnouncementController { - @Autowired private IAnnouncementService announcementService = null; + @Autowired private IAnnouncementsService announcementsService = null; @Autowired(required = true) private final IViewNameSelector viewNameSelector = null; @@ -60,7 +60,7 @@ public class PreviewAnnouncementController { protected String previewAnnouncement( Model model, RenderRequest request, @RequestParam("annId") String annId) throws Exception { - Announcement ann = announcementService.getAnnouncement(Long.parseLong(annId)); + Announcement ann = announcementsService.getAnnouncement(Long.parseLong(annId)); Topic topic = ann.getParent(); UserPermissionChecker upChecker = userPermissionCheckerFactory.createUserPermissionChecker(request, topic); diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/ShowHistoryController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/ShowHistoryController.java index a119c6c2..83767bce 100755 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/ShowHistoryController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/admin/ShowHistoryController.java @@ -31,7 +31,7 @@ import org.jasig.portlet.announcements.model.Announcement; import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.mvc.IViewNameSelector; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.UserPermissionChecker; import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -51,7 +51,7 @@ public class ShowHistoryController { private static final Log logger = LogFactory.getLog(ShowHistoryController.class); - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; @Autowired private UserPermissionCheckerFactory userPermissionCheckerFactory = null; @@ -72,7 +72,7 @@ protected String showHistory( Model model, RenderRequest request, @RequestParam("topicId") String topicId) throws Exception { - Topic topic = announcementService.getTopic(Long.parseLong(topicId)); + Topic topic = announcementsService.getTopic(Long.parseLong(topicId)); UserPermissionChecker upChecker = userPermissionCheckerFactory.createUserPermissionChecker(request, topic); upChecker.validateCanEditTopic(); diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsPreferencesController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsPreferencesController.java index bb1ec034..746ce382 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsPreferencesController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsPreferencesController.java @@ -34,7 +34,7 @@ import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.model.TopicSubscription; import org.jasig.portlet.announcements.mvc.IViewNameSelector; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.ITopicSubscriptionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -55,7 +55,7 @@ public class AnnouncementsPreferencesController { @Autowired private ITopicSubscriptionService tss = null; - @Autowired private final IAnnouncementService announcementService = null; + @Autowired private final IAnnouncementsService announcementsService = null; @Autowired(required = true) private final IViewNameSelector viewNameSelector = null; @@ -127,7 +127,7 @@ public void savePreferences( String topicSubId = request.getParameter("topicSubId_" + i).trim(); Boolean subscribed = Boolean.valueOf(request.getParameter("subscribed_" + i)); - Topic topic = announcementService.getTopic(topicId); + Topic topic = announcementsService.getTopic(topicId); // Make sure that any pushed_forced topics weren't sneakingly removed (by tweaking the URL, for example) if (topic.getSubscriptionMethod() == Topic.PUSHED_FORCED) { @@ -149,7 +149,7 @@ public void savePreferences( if (newSubscription.size() > 0) { try { - announcementService.addOrSaveTopicSubscription(newSubscription); + announcementsService.addOrSaveTopicSubscription(newSubscription); } catch (Exception e) { logger.error( "ERROR saving TopicSubscriptions for user " diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsViewController.java b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsViewController.java index 8235b365..36dd1afd 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsViewController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/portlet/display/AnnouncementsViewController.java @@ -47,7 +47,7 @@ import org.jasig.portlet.announcements.model.TopicSubscription; import org.jasig.portlet.announcements.model.UserRoles; import org.jasig.portlet.announcements.mvc.IViewNameSelector; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.jasig.portlet.announcements.service.ITopicSubscriptionService; import org.jasig.portlet.announcements.service.UserIdService; import org.jasig.portlet.announcements.service.UserPermissionChecker; @@ -136,7 +136,7 @@ public class AnnouncementsViewController { public static final String TOPICS_CACHE = "topicLists"; @Autowired - private final IAnnouncementService announcementService = null; + private final IAnnouncementsService announcementsService = null; private final ObjectMapper mapper = new ObjectMapper(); private final Log logger = LogFactory.getLog(getClass()); @Autowired @@ -613,7 +613,7 @@ private List paginateAnnouncements( private Announcement getAnnouncementById(PortletRequest request, String announcementId) throws Exception { Long annId = Long.valueOf(announcementId); - Announcement announcement = announcementService.getAnnouncement(annId); + Announcement announcement = announcementsService.getAnnouncement(annId); if (!UserPermissionChecker.inRoleForTopic( request, UserRoles.AUDIENCE_ROLE_NAME, announcement.getParent())) { diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/servlet/AjaxApproveController.java b/src/main/java/org/jasig/portlet/announcements/mvc/servlet/AjaxApproveController.java index be5c81d3..2db4b068 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/servlet/AjaxApproveController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/servlet/AjaxApproveController.java @@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest; import org.jasig.portlet.announcements.model.Announcement; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.stereotype.Controller; @@ -46,18 +46,13 @@ public class AjaxApproveController { private static final int STATUS_SHOWING = 2; private static final int STATUS_PENDING = 3; - private IAnnouncementService announcementService; + private IAnnouncementsService announcementsService; private EhCacheCacheManager cacheManager = null; - /** - *

Setter for the field announcementService.

- * - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. - */ @Autowired - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } /** @@ -82,7 +77,7 @@ public ModelAndView toggleApprove(HttpServletRequest request) throws PortletExce final Long annId = Long.valueOf(request.getParameter("annId")); final Boolean approval = Boolean.valueOf(request.getParameter("approval")); - final Announcement ann = announcementService.getAnnouncement(annId); + final Announcement ann = announcementsService.getAnnouncement(annId); final Date startDisplay = ann.getStartDisplay(); Date endDisplay = ann.getEndDisplay(); @@ -107,7 +102,7 @@ public ModelAndView toggleApprove(HttpServletRequest request) throws PortletExce ann.setPublished(approval); - announcementService.addOrSaveAnnouncement(ann); + announcementsService.addOrSaveAnnouncement(ann); return new ModelAndView("ajaxApprove", "status", status); } diff --git a/src/main/java/org/jasig/portlet/announcements/mvc/servlet/RssFeedController.java b/src/main/java/org/jasig/portlet/announcements/mvc/servlet/RssFeedController.java index 4d48975e..014c6656 100644 --- a/src/main/java/org/jasig/portlet/announcements/mvc/servlet/RssFeedController.java +++ b/src/main/java/org/jasig/portlet/announcements/mvc/servlet/RssFeedController.java @@ -45,7 +45,7 @@ import org.jasig.portlet.announcements.model.Announcement; import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.mvc.portlet.display.AnnouncementsViewController; -import org.jasig.portlet.announcements.service.IAnnouncementService; +import org.jasig.portlet.announcements.service.IAnnouncementsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.javamail.ConfigurableMimeFileTypeMap; @@ -77,7 +77,7 @@ public class RssFeedController { private static final String PATH_ATTRIBUTE = "path"; private static final String FILENAME_ATTRIBUTE = "filename"; - private IAnnouncementService announcementService; + private IAnnouncementsService announcementsService; @Value("${RssFeedController.portalContextName:uPortal}") private String portalContextName; @@ -99,14 +99,9 @@ public void init() { this.fileTypeMap.setMappings("image/png png"); } - /** - *

Setter for the field announcementService.

- * - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. - */ @Autowired - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } /** @@ -172,7 +167,7 @@ private Topic selectTopic(HttpServletRequest req) throws ServletRequestBindingEx final Long topicId = ServletRequestUtils.getLongParameter(req, "topic"); if (topicId != null) { try { - rslt = announcementService.getTopic(topicId); + rslt = announcementsService.getTopic(topicId); } catch (PortletException pe) { logger.warn(String.format("Failed to obtain a Topic for the specified id of '%s'", topicId)); } @@ -180,7 +175,7 @@ private Topic selectTopic(HttpServletRequest req) throws ServletRequestBindingEx final String titleParameter = ServletRequestUtils.getStringParameter(req, "topicTitle"); if (titleParameter != null) { // We need to find it... - final List allTopics = announcementService.getAllTopics(); + final List allTopics = announcementsService.getAllTopics(); for (Topic t : allTopics) { final String convertedTopicTitle = t.getTitle().trim().replaceAll("\\s", "-"); logger.debug(String.format("Calculated convertedTopicTitle='%s' for topic with title='%s'", diff --git a/src/main/java/org/jasig/portlet/announcements/service/AnnouncementCleanupThread.java b/src/main/java/org/jasig/portlet/announcements/service/AnnouncementCleanupThread.java index bcb30a96..40f4afb8 100644 --- a/src/main/java/org/jasig/portlet/announcements/service/AnnouncementCleanupThread.java +++ b/src/main/java/org/jasig/portlet/announcements/service/AnnouncementCleanupThread.java @@ -35,7 +35,7 @@ */ public class AnnouncementCleanupThread extends Thread { - @Autowired private IAnnouncementService announcementService; + @Autowired private IAnnouncementsService announcementsService; private int hourToCheck = 3; // military time private int minuteToCheck = 0; @@ -96,10 +96,10 @@ public void run() { if (expireThreshold > 0) { log.info("Going to delete old announcements at " + now.toString()); - announcementService.deleteAnnouncementsPastExpirationThreshold(expireThreshold); + announcementsService.deleteAnnouncementsPastExpirationThreshold(expireThreshold); } else { log.info("Going to delete expired announcements at " + now.toString()); - announcementService.deleteAnnouncementsPastCurrentTime(); + announcementsService.deleteAnnouncementsPastCurrentTime(); } lastCheckTime = System.currentTimeMillis(); diff --git a/src/main/java/org/jasig/portlet/announcements/service/AnnouncementsService.java b/src/main/java/org/jasig/portlet/announcements/service/AnnouncementsService.java new file mode 100644 index 00000000..5a8a0a50 --- /dev/null +++ b/src/main/java/org/jasig/portlet/announcements/service/AnnouncementsService.java @@ -0,0 +1,181 @@ +/** + * Licensed to Apereo under one or more contributor license + * agreements. See the NOTICE file distributed with this work + * for additional information regarding copyright ownership. + * Apereo licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a + * copy of the License at the following location: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jasig.portlet.announcements.service; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.portlet.PortletException; +import javax.portlet.PortletRequest; + +import org.apache.commons.collections4.IterableUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jasig.portlet.announcements.dao.jpa.AnnouncementsRepository; +import org.jasig.portlet.announcements.dao.jpa.TopicSubscriptionsRepository; +import org.jasig.portlet.announcements.dao.jpa.TopicsRepository; +import org.jasig.portlet.announcements.model.Announcement; +import org.jasig.portlet.announcements.model.Topic; +import org.jasig.portlet.announcements.model.TopicSubscription; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

AnnouncementsService class.

+ */ +@Service +@Transactional +public class AnnouncementsService implements IAnnouncementsService { + + private static final Log log = LogFactory.getLog(AnnouncementsService.class); + + @Autowired + private AnnouncementsRepository announcementsRepository; + @Autowired + private TopicsRepository topicsRepository; + @Autowired + private TopicSubscriptionsRepository topicSubscriptionsRepository; + + /** {@inheritDoc} */ + public List getAllTopics() { + return IterableUtils.toList(this.topicsRepository.findAll()); + } + + /** {@inheritDoc} */ + public Topic getEmergencyTopic() { + Iterable iterable = this.topicsRepository.findBySubscriptionMethod(4); + return iterable.iterator().next(); + } + + /** {@inheritDoc} */ + public void addOrSaveTopic(Topic topic) { + log.debug( + "Insert or save topic: [topicId: " + + (topic.getId() != null ? topic.getId().toString() : "NEW") + + "]"); + this.topicsRepository.save(topic); + } + + /** {@inheritDoc} */ + public void persistTopic(Topic topic) { + log.debug("Persisting topic: [topicId: " + topic.getId().toString() + "]"); + this.topicsRepository.save(topic); + } + + /** {@inheritDoc} */ + public void addOrSaveAnnouncement(Announcement ann) { + log.debug( + "Save announcement: [annId: " + + (ann.getId() != null ? ann.getId().toString() : "NEW") + + "]"); + if (ann.getCreated() == null) { + ann.setCreated(new Date()); + } + this.announcementsRepository.save(ann); + } + + /** {@inheritDoc} */ + public Topic getTopic(Long id) throws PortletException { + if (id == null) { + throw new PortletException("Programming error: getTopic called with null parameter"); + } + final Topic result = this.topicsRepository.findOne(id); + if (result == null) { + throw new PortletException("The requested topic [" + id.toString() + "] does not exist."); + } + return result; + // TODO: use the following instead of the above when we upgrade to Spring 5.x and use a newer version of + // Spring Data JPA ('findOne' has been deprecated in favor of 'findById') + //return this.topicsRepository.findById(id) + // .orElseThrow(() -> new PortletException("The requested topic [" + id.toString() + "] does not exist.")); + } + + /** {@inheritDoc} */ + public Announcement getAnnouncement(Long id) throws PortletException { + if (id == null) { + throw new PortletException("Programming error: getAnnouncement called with null parameter"); + } + final Announcement result = this.announcementsRepository.findOne(id); + if (result == null) { + throw new PortletException("The requested announcement [" + id.toString() + "] does not exist."); + } + return result; + // TODO: use the following instead of the above when we upgrade to Spring 5.x and use a newer version of + // Spring Data JPA ('findOne' has been deprecated in favor of 'findById') + //return this.announcementsRepository.findById(id) + // .orElseThrow(() -> new PortletException("The requested announcement [" + id.toString() + "] does not exist.")); + } + + /** {@inheritDoc} */ + public void deleteAnnouncementsPastCurrentTime() { + long count = this.announcementsRepository.deleteWhereEndDisplayPastCurrentTime(); + log.info("Deleted " + count + " expired announcements that stopped displaying prior to now."); + } + + /** {@inheritDoc} */ + public void deleteAnnouncementsPastExpirationThreshold(int numDays) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, (numDays * -1)); + long count = this.announcementsRepository.deleteWhereEndDisplayPastDate(cal); + log.info( + "Deleted " + + count + + " expired announcements that stopped displaying prior to " + + cal.getTime()); + } + + /** {@inheritDoc} */ + public List getTopicSubscriptionFor(PortletRequest request) throws PortletException { + return IterableUtils.toList(this.topicSubscriptionsRepository.findByOwner(request.getRemoteUser())); + } + + /** {@inheritDoc} */ + public void addOrSaveTopicSubscription(List subs) { + //this.topicSubscriptionsRepository.saveAll(subs); + for (TopicSubscription sub : subs) { + this.topicSubscriptionsRepository.save(sub); + } + } + + /** {@inheritDoc} */ + public void deleteTopic(Topic topic) { + // any topic subscriptions with this id should be trashed first (since the topic is not aware of + // what topic subscriptions exist for it) + Long topicId = topic.getId(); + List result = IterableUtils.toList(this.topicSubscriptionsRepository.findByTopicId(topicId)); + for (TopicSubscription ts : result) { + this.topicSubscriptionsRepository.delete(ts); + } + // then delete the topic itself (announcements get deleted by hibernate) + this.topicsRepository.delete(topic); + } + + /** {@inheritDoc} */ + public void deleteAnnouncement(Announcement ann) { + this.announcementsRepository.delete(ann); + } + + /** {@inheritDoc} */ + public void deleteTopicSubscription(TopicSubscription sub) { + this.topicSubscriptionsRepository.delete(sub); + } + +} diff --git a/src/main/java/org/jasig/portlet/announcements/service/HibernateAnnouncementService.java b/src/main/java/org/jasig/portlet/announcements/service/HibernateAnnouncementService.java deleted file mode 100644 index 622cf9d2..00000000 --- a/src/main/java/org/jasig/portlet/announcements/service/HibernateAnnouncementService.java +++ /dev/null @@ -1,332 +0,0 @@ -/** - * Licensed to Apereo under one or more contributor license - * agreements. See the NOTICE file distributed with this work - * for additional information regarding copyright ownership. - * Apereo licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a - * copy of the License at the following location: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jasig.portlet.announcements.service; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import javax.portlet.PortletException; -import javax.portlet.PortletRequest; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.HibernateException; -import org.hibernate.Query; -import org.hibernate.Session; -import org.jasig.portlet.announcements.model.Announcement; -import org.jasig.portlet.announcements.model.Topic; -import org.jasig.portlet.announcements.model.TopicSubscription; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - *

HibernateAnnouncementService class.

- * - * @author Erik A. Olsson (eolsson@uci.edu) - * @version $Id: $Id - */ -public class HibernateAnnouncementService extends HibernateDaoSupport - implements IAnnouncementService { - - private static Log log = LogFactory.getLog(HibernateAnnouncementService.class); - - /** - * Fetch all the Topics from the database and return them as a list - * - * @return a {@link java.util.List} object. - */ - @SuppressWarnings("unchecked") - public List getAllTopics() { - - List result; - - try { - result = (List) getHibernateTemplate().find("from Topic"); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - - return result; - } - - /** - *

getEmergencyTopic.

- * - * @return a {@link org.jasig.portlet.announcements.model.Topic} object. - */ - @SuppressWarnings("unchecked") - public Topic getEmergencyTopic() { - Topic t = null; - List result; - - try { - result = (List) getHibernateTemplate().find("from Topic where SUB_METHOD = 4"); - t = result.get(0); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - - return t; - } - - /** {@inheritDoc} */ - public void addOrSaveTopic(Topic topic) { - try { - log.debug( - "Insert or save topic: [topicId: " - + (topic.getId() != null ? topic.getId().toString() : "NEW") - + "]"); - getHibernateTemplate().saveOrUpdate(topic); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void persistTopic(Topic topic) { - try { - log.debug("Persisting topic: [topicId: " + topic.getId().toString() + "]"); - getHibernateTemplate().persist(topic); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void mergeTopic(Topic topic) { - try { - log.debug("Merging topic: [topicId: " + topic.getId().toString() + "]"); - getHibernateTemplate().merge(topic); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void addOrSaveAnnouncement(Announcement ann) { - try { - if (ann.getCreated() == null) { - ann.setCreated(new Date()); - } - log.debug( - "Insert or save announcement: [annId: " - + (ann.getId() != null ? ann.getId().toString() : "NEW") - + "]"); - getHibernateTemplate().saveOrUpdate(ann); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void mergeAnnouncement(Announcement ann) { - try { - log.debug( - "Merge announcement: [annId: " - + (ann.getId() != null ? ann.getId().toString() : "NEW") - + "]"); - getHibernateTemplate().merge(ann); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** - * {@inheritDoc} - * - * Lookup the specified topic id and return it from the database - */ - @SuppressWarnings("unchecked") - public Topic getTopic(Long id) throws PortletException { - List result; - - if (id == null) { - throw new PortletException("Programming error: getTopic called with null parameter"); - } - - try { - result = - (List) - getHibernateTemplate().find("from Topic where id = '" + id.toString() + "'"); - if (result.size() != 1) { - throw new PortletException("The requested topic [" + id.toString() + "] does not exist."); - } - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - - return result.get(0); - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - public Announcement getAnnouncement(Long id) throws PortletException { - List result = null; - - if (id == null) { - throw new PortletException("Programming error: getAnnouncement called with null parameter"); - } - - try { - result = - (List) - getHibernateTemplate().find("from Announcement where id = '" + id.toString() + "'"); - if (result.size() != 1) { - throw new PortletException( - "The requested announcement [" + id.toString() + "] does not exist."); - } - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - - return result.get(0); - } - - /** - *

deleteAnnouncementsPastCurrentTime.

- */ - @SuppressWarnings("unchecked") - public void deleteAnnouncementsPastCurrentTime() { - try { - Session session = this.getSession(); - Query q = session.createQuery("delete from Announcement where END_DISPLAY < current_timestamp()"); - int count = q.executeUpdate(); - getHibernateTemplate().flush(); - this.releaseSession(session); - log.info("Deleted " + count + " expired announcements that stopped displaying prior to now."); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - public void deleteAnnouncementsPastExpirationThreshold(int numDays) { - try { - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DATE, (numDays * -1)); - - Session session = this.getSession(); - Query q = session.createQuery("delete from Announcement where END_DISPLAY < :date"); - q.setCalendarDate("date", cal); - int count = q.executeUpdate(); - getHibernateTemplate().flush(); - this.releaseSession(session); - log.info( - "Deleted " - + count - + " expired announcements that stopped displaying prior to " - + cal.getTime()); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - public List getTopicSubscriptionFor(PortletRequest request) - throws PortletException { - List result = null; - - try { - result = - (List) - getHibernateTemplate() - .find( - "from TopicSubscription where OWNER_ID = '" + request.getRemoteUser() + "'"); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - - return result; - } - - /** {@inheritDoc} */ - public void addOrSaveTopicSubscription(List subs) { - - try { - for (TopicSubscription ts : subs) { - getHibernateTemplate().saveOrUpdate(ts); - } - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void persistTopicSubscription(List subs) { - - try { - for (TopicSubscription ts : subs) { - getHibernateTemplate().persist(ts); - } - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - public void deleteTopic(Topic topic) { - try { - // any topic subscriptions with this id should be trashed first (since the topic is not aware of - // what topic subscriptions exist for it) - Long topicId = topic.getId(); - List result = - (List) - getHibernateTemplate() - .find("from TopicSubscription where TOPIC_ID = " + topicId.toString()); - for (TopicSubscription ts : result) { - getHibernateTemplate().delete(ts); - } - // then delete the topic itself (announcements get deleted by hibernate) - getHibernateTemplate().delete(topic); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void deleteAnnouncement(Announcement ann) { - try { - getHibernateTemplate().delete(ann); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } - - /** {@inheritDoc} */ - public void deleteTopicSubscription(TopicSubscription sub) { - try { - getHibernateTemplate().delete(sub); - getHibernateTemplate().flush(); - } catch (HibernateException ex) { - throw convertHibernateAccessException(ex); - } - } -} diff --git a/src/main/java/org/jasig/portlet/announcements/service/IAnnouncementService.java b/src/main/java/org/jasig/portlet/announcements/service/IAnnouncementsService.java similarity index 86% rename from src/main/java/org/jasig/portlet/announcements/service/IAnnouncementService.java rename to src/main/java/org/jasig/portlet/announcements/service/IAnnouncementsService.java index dd4b92f0..1a4bc973 100644 --- a/src/main/java/org/jasig/portlet/announcements/service/IAnnouncementService.java +++ b/src/main/java/org/jasig/portlet/announcements/service/IAnnouncementsService.java @@ -26,13 +26,13 @@ import org.jasig.portlet.announcements.model.TopicSubscription; /** - *

IAnnouncementService interface.

+ *

IAnnouncementsService interface.

* * @author Erik A. Olsson (eolsson@uci.edu) *

$LastChangedBy$ $LastChangedDate$ * @version $Id: $Id */ -public interface IAnnouncementService { +public interface IAnnouncementsService { /** *

getAllTopics.

@@ -62,13 +62,6 @@ public interface IAnnouncementService { */ public void persistTopic(Topic topic); - /** - *

mergeTopic.

- * - * @param topic a {@link org.jasig.portlet.announcements.model.Topic} object. - */ - public void mergeTopic(Topic topic); - /** *

addOrSaveAnnouncement.

* @@ -76,13 +69,6 @@ public interface IAnnouncementService { */ public void addOrSaveAnnouncement(Announcement ann); - /** - *

mergeAnnouncement.

- * - * @param ann a {@link org.jasig.portlet.announcements.model.Announcement} object. - */ - public void mergeAnnouncement(Announcement ann); - /** *

getTopic.

* @@ -130,13 +116,6 @@ public List getTopicSubscriptionFor(PortletRequest request) */ public void addOrSaveTopicSubscription(List subs); - /** - *

persistTopicSubscription.

- * - * @param subs a {@link java.util.List} object. - */ - public void persistTopicSubscription(List subs); - /** *

deleteTopic.

* diff --git a/src/main/java/org/jasig/portlet/announcements/service/UserConfiguredTopicSubscriptionService.java b/src/main/java/org/jasig/portlet/announcements/service/UserConfiguredTopicSubscriptionService.java index cd38a1fb..cf410494 100644 --- a/src/main/java/org/jasig/portlet/announcements/service/UserConfiguredTopicSubscriptionService.java +++ b/src/main/java/org/jasig/portlet/announcements/service/UserConfiguredTopicSubscriptionService.java @@ -33,6 +33,7 @@ import org.jasig.portlet.announcements.model.Topic; import org.jasig.portlet.announcements.model.TopicSubscription; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; /** @@ -52,18 +53,13 @@ public class UserConfiguredTopicSubscriptionService implements ITopicSubscriptio private Log log = LogFactory.getLog(getClass()); - private IAnnouncementService announcementService; + private IAnnouncementsService announcementsService; private Topic emergencyTopic; private UserIdService userIdService; - /** - *

Setter for the field announcementService.

- * - * @param announcementService a {@link org.jasig.portlet.announcements.service.IAnnouncementService} object. - */ @Autowired - public void setAnnouncementService(IAnnouncementService announcementService) { - this.announcementService = announcementService; + public void setAnnouncementsService(IAnnouncementsService announcementsService) { + this.announcementsService = announcementsService; } /** @@ -71,7 +67,8 @@ public void setAnnouncementService(IAnnouncementService announcementService) { * * @param emergencyTopic a {@link org.jasig.portlet.announcements.model.Topic} object. */ - @Resource(name = "emergencyTopic") + @Autowired(required = false) + @Qualifier("emergencyTopic") public void setEmergencyTopic(Topic emergencyTopic) { this.emergencyTopic = emergencyTopic; log.debug("Emergency Topic assigned successfully."); @@ -96,7 +93,7 @@ public void init() { // if the emergencyTopic exists, update it to reflect changes in the spring config Topic t = null; try { - t = announcementService.getEmergencyTopic(); + t = announcementsService.getEmergencyTopic(); } catch (Exception ex) { log.warn( "Could not load emergencyTopic from database (OK during unit tests or after dbinit): " @@ -104,7 +101,7 @@ public void init() { } if (t == null && emergencyTopic != null) { - announcementService.addOrSaveTopic(emergencyTopic); + announcementsService.addOrSaveTopic(emergencyTopic); } else { emergencyTopic = t; } @@ -117,13 +114,13 @@ public List getTopicSubscription( List subscriptions = new ArrayList<>(); List subSaved = null; // must reload all topics each time, in case new ones were added by admins since last visit - List allTopics = announcementService.getAllTopics(); + List allTopics = announcementsService.getAllTopics(); if (request.getRemoteUser() == null) { subSaved = new ArrayList<>(); } else { try { - subSaved = announcementService.getTopicSubscriptionFor(request); + subSaved = announcementsService.getTopicSubscriptionFor(request); } catch (Exception e) { log.error( "ERROR getting topic subscriptions for " @@ -183,7 +180,7 @@ public List getTopicSubscription( log.debug( "Removing invalid TopicSubscription topic [" + topic.getId() + "] for " + userId); subSaved.remove(invalid); - announcementService.deleteTopicSubscription(invalid); + announcementsService.deleteTopicSubscription(invalid); } if (!topicSubscriptionExists(topic, subSaved)) { if (log.isDebugEnabled()) @@ -218,7 +215,7 @@ public List getTopicSubscription( subSaved.remove(toRemove); // We're here because a DB record is no longer // allowable... remove from persistence as well! - announcementService.deleteTopicSubscription(toRemove); + announcementsService.deleteTopicSubscription(toRemove); } } } @@ -227,7 +224,7 @@ public List getTopicSubscription( if (includeEmergency) { // add the emergency topic for everyone, but don't save the topicsubscription to the database since it's implied - emergencyTopic = announcementService.getEmergencyTopic(); + emergencyTopic = announcementsService.getEmergencyTopic(); subscriptions.add(new TopicSubscription(userId, emergencyTopic, Boolean.TRUE)); } diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..81dcbadc --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/src/main/resources/command-line.logback.xml b/src/main/resources/command-line.logback.xml new file mode 100644 index 00000000..648bdc82 --- /dev/null +++ b/src/main/resources/command-line.logback.xml @@ -0,0 +1,94 @@ + + + + announcements-command-line + + + true + + + + + %-5level %logger{36} [%date{mm:ss.SSS}] %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/context/applicationContext.xml b/src/main/resources/context/applicationContext.xml index 29f6a71d..5fb24f11 100644 --- a/src/main/resources/context/applicationContext.xml +++ b/src/main/resources/context/applicationContext.xml @@ -31,6 +31,8 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> + + @@ -48,13 +50,6 @@ - - - - FLUSH_AUTO - - - diff --git a/src/main/resources/context/databaseContext.xml b/src/main/resources/context/databaseContext.xml index 9c1ef2b3..fc7f2d25 100644 --- a/src/main/resources/context/databaseContext.xml +++ b/src/main/resources/context/databaseContext.xml @@ -17,11 +17,25 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:jpa="http://www.springframework.org/schema/data/jpa" + xmlns:p="http://www.springframework.org/schema/p" + xmlns:tx="http://www.springframework.org/schema/tx" + xsi:schemaLocation="http://www.springframework.org/schema/beans + https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd + http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd"> + + + + + + + @@ -58,6 +72,8 @@ + + @@ -92,28 +108,30 @@ - - - - - - ${hibernate.dialect} - - + + + + - - - - - + + + - - + + + + + + + + + + diff --git a/src/main/resources/context/portlet/announcementsAdmin.xml b/src/main/resources/context/portlet/announcementsAdmin.xml index 44fd56e5..d8ed0d9e 100644 --- a/src/main/resources/context/portlet/announcementsAdmin.xml +++ b/src/main/resources/context/portlet/announcementsAdmin.xml @@ -47,7 +47,6 @@ - diff --git a/src/main/resources/context/portlet/announcementsDisplay.xml b/src/main/resources/context/portlet/announcementsDisplay.xml index b895dd35..41967619 100644 --- a/src/main/resources/context/portlet/announcementsDisplay.xml +++ b/src/main/resources/context/portlet/announcementsDisplay.xml @@ -44,7 +44,6 @@ - diff --git a/src/main/resources/context/servlet/spring-servlet.xml b/src/main/resources/context/servlet/spring-servlet.xml index a697a733..11e54de8 100644 --- a/src/main/resources/context/servlet/spring-servlet.xml +++ b/src/main/resources/context/servlet/spring-servlet.xml @@ -36,11 +36,6 @@ - - - - - rssFeedController diff --git a/src/main/resources/hibernate-mappings/Announcement.hbm.xml b/src/main/resources/hibernate-mappings/Announcement.hbm.xml index b14612df..acea30c8 100644 --- a/src/main/resources/hibernate-mappings/Announcement.hbm.xml +++ b/src/main/resources/hibernate-mappings/Announcement.hbm.xml @@ -48,7 +48,7 @@ - + diff --git a/src/main/resources/hibernate-mappings/Topic.hbm.xml b/src/main/resources/hibernate-mappings/Topic.hbm.xml index cb8acec3..4d1d129f 100644 --- a/src/main/resources/hibernate-mappings/Topic.hbm.xml +++ b/src/main/resources/hibernate-mappings/Topic.hbm.xml @@ -34,9 +34,9 @@ - - - + + + @@ -65,7 +65,7 @@ - + diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index b268e1b3..7123a86e 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -35,9 +35,12 @@ true true - net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory + org.hibernate.cache.ehcache.EhCacheRegionFactory true + thread + true + update diff --git a/src/main/resources/hibernate.properties b/src/main/resources/hibernate.properties index a5d5f0c5..080cbbfc 100644 --- a/src/main/resources/hibernate.properties +++ b/src/main/resources/hibernate.properties @@ -19,5 +19,4 @@ ## Properties in this file are used ONLY by the hibernate3-maven-plugin:hbm2ddl goal; ## everyone else uses the Spring context effectively without them. -hibernate.connection.provider_class=org.jasig.portlet.announcements.hibernate.ApplicationContextConnectionProvider hibernate.dialect=org.hibernate.dialect.HSQLDialect diff --git a/src/test/java/org/jasig/portlet/announcements/TestImporter.java b/src/test/java/org/jasig/portlet/announcements/TestImporter.java index d2819405..db483d63 100644 --- a/src/test/java/org/jasig/portlet/announcements/TestImporter.java +++ b/src/test/java/org/jasig/portlet/announcements/TestImporter.java @@ -21,46 +21,47 @@ import java.io.File; import java.util.List; import java.util.Set; -import javax.annotation.Resource; import junit.framework.TestCase; -import org.hibernate.SessionFactory; import org.jasig.portlet.announcements.model.Announcement; 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.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; +import javax.persistence.EntityManager; + /** @author eolsson */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION}) -@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional public class TestImporter extends TestCase { - @Resource SessionFactory sessionFactory; + @Autowired + private EntityManager entityManager; - @Resource IAnnouncementService announcementService; + @Autowired + IAnnouncementsService announcementsService; @Test public void testImporter() { - String basedir = System.getProperty("basedir", "."); - File dataDirectory = new File(basedir + "/src/main/data"); + File dataDirectory = new File(this.getClass().getResource("/data").getFile()); - Importer importer = new Importer(dataDirectory, announcementService); + Importer importer = new Importer(dataDirectory, announcementsService); importer.importData(); // Clear the first level cache to remove the topics that are cached - sessionFactory.getCurrentSession().clear(); + entityManager.clear(); - List updatedTopics = announcementService.getAllTopics(); - assertTrue( + List updatedTopics = announcementsService.getAllTopics(); + assertEquals( "topic list should have 1 item; instead had " + updatedTopics.size(), - updatedTopics.size() == 1); + 1, + updatedTopics.size()); // verify data after import. Topic addedTopic = updatedTopics.get(0); @@ -70,9 +71,10 @@ public void testImporter() { assert "Campus Services".equals(addedTopic.getTitle()); Set announcements = addedTopic.getAnnouncements(); - assertTrue( + assertEquals( "Campus Services topic has " + announcements.size() + " announcement instead of 2", - announcements.size() == 2); + 2, + announcements.size()); boolean firstAnnFound = false; boolean secondAnnFound = false; for (Announcement announcement : announcements) { @@ -85,4 +87,5 @@ public void testImporter() { assertTrue("Did not find first announcement", firstAnnFound); assertTrue("Did not find second announcement", secondAnnFound); } + } diff --git a/src/main/data/example-announcement.xml b/src/test/resources/data/example-announcement.xml similarity index 100% rename from src/main/data/example-announcement.xml rename to src/test/resources/data/example-announcement.xml diff --git a/src/main/data/example-topic.xml b/src/test/resources/data/example-topic.xml similarity index 100% rename from src/main/data/example-topic.xml rename to src/test/resources/data/example-topic.xml diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 00000000..164c57fe --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + true + + + + + + %-5level [%thread] %logger{36} %d{ISO8601} - %msg%n + + + + + + + + + + + + + +