From 19696efec4e63b005ca3a8b0c6763bcd9388b7d1 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Thu, 18 Jul 2024 15:10:12 -0500 Subject: [PATCH 1/9] :sparkles: feat(Project): Add initial configurations for new version of hibernate.aiccra-feature-A2-749-hibernate-new-version --- .../marlo/MarloDatabaseConfiguration.java | 76 ++++++++++++------- .../marlo/MarloLocalSessionFactoryBean.java | 39 ++++++++++ .../ccafs/marlo/config/MyIntegrator.java | 12 +-- marlo-parent/pom.xml | 2 +- marlo-utils/pom.xml | 6 ++ marlo-web/pom.xml | 5 ++ .../cgiar/ccafs/marlo/action/BaseAction.java | 2 +- marlo-web/src/main/resources/ehcache.xml | 4 +- 8 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloLocalSessionFactoryBean.java diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java index c65aabbac5..888c4e356e 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java @@ -15,19 +15,25 @@ package org.cgiar.ccafs.marlo; +import java.util.Properties; + import javax.sql.DataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import org.hibernate.SessionFactory; -import org.hibernate.cfg.Environment; +import org.hibernate.cache.ehcache.internal.EhcacheRegionFactory; +import org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory; +import org.hibernate.cfg.AvailableSettings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; import org.springframework.orm.hibernate4.HibernateTransactionManager; -import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; /** @@ -56,6 +62,11 @@ public class MarloDatabaseConfiguration { private final Logger log = LoggerFactory.getLogger(MarloDatabaseConfiguration.class); + @Bean(name = "ehcacheRegionFactory") + public EhcacheRegionFactory ehcacheRegionFactory() { + return new SingletonEhcacheRegionFactory(); + } + @Bean(name = "dataSource", destroyMethod = "close") public DataSource getDataSource() { @@ -87,6 +98,38 @@ public DataSource getDataSource() { return dataSource; } + private Properties hibernateProperties() { + Properties props = new Properties(); + props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); + if (Boolean.TRUE.equals(showSql)) { + props.setProperty(AvailableSettings.SHOW_SQL, "true"); + } + props.setProperty("hibernate.cache.use_second_level_cache", Boolean.TRUE.toString()); + props.setProperty("hibernate.cache.use_query_cache", Boolean.TRUE.toString()); + return props; + } + + @Bean(name = "transactionManager") + public PlatformTransactionManager hibernateTransactionManager() { + final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); + transactionManager.setSessionFactory(this.sessionFactory()); + return transactionManager; + } + + @Bean(name = "localSessionFactoryBean") + public LocalSessionFactoryBean localSessionFactory() { + log.info("Setting LocalSessionFactory"); + MarloLocalSessionFactoryBean sessionFactory = new MarloLocalSessionFactoryBean(); + sessionFactory.setDataSource(this.getDataSource()); + sessionFactory.setConfigLocation(new ClassPathResource("hibernate.cfg.xml")); + sessionFactory.setHibernateProperties(this.hibernateProperties()); + + // Enable second level cache with ehcache + sessionFactory.setRegionFactory(this.ehcacheRegionFactory()); + + return sessionFactory; + } + /** * Leave commented out for now. * @@ -98,32 +141,9 @@ public DataSource getDataSource() { // } @Bean(name = "sessionFactory") - public SessionFactory getSessionFactory(final DataSource dataSource) { + public SessionFactory sessionFactory() { log.info("Setting SessionFactory"); - LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource); - sessionBuilder.configure("hibernate.cfg.xml"); - sessionBuilder.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); - if (showSql) { - sessionBuilder.setProperty(Environment.SHOW_SQL, "true"); - } - - // Enable second level cache with ehcache - sessionBuilder.setProperty("hibernate.cache.use_second_level_cache", Boolean.TRUE.toString()); - sessionBuilder.setProperty("hibernate.cache.region.factory_class", - "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"); - - // // Enable query cache - sessionBuilder.setProperty("hibernate.cache.use_query_cache", Boolean.TRUE.toString()); - - SessionFactory sessionFactory = sessionBuilder.buildSessionFactory(); - return sessionFactory; - } - - - @Bean(name = "transactionManager") - public HibernateTransactionManager getTransactionManager(final SessionFactory sessionFactory) { - final HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory); - return transactionManager; + return this.localSessionFactory().getObject(); } -} +} \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloLocalSessionFactoryBean.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloLocalSessionFactoryBean.java new file mode 100644 index 0000000000..7773402401 --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloLocalSessionFactoryBean.java @@ -0,0 +1,39 @@ +/** + * + */ +package org.cgiar.ccafs.marlo; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cache.spi.RegionFactory; +import org.springframework.beans.factory.annotation.Required; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder; + +/** + * Custom session factory bean extended from {@link LocalSessionFactoryBean}. This implementation overrides the method + * buildSessionFactory to provide Hibernate with own region factory. + * + * @author Alexander Filigrana - Premize S.A.S + * @since 4.4.0 + * @see {@link RegionFactory} + */ +public class MarloLocalSessionFactoryBean extends LocalSessionFactoryBean { + + private RegionFactory regionFactory; + + @Override + protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) { + + StandardServiceRegistryBuilder serviceRegistryBuilder = sfb.getStandardServiceRegistryBuilder(); + serviceRegistryBuilder.addService(RegionFactory.class, regionFactory); + + return sfb.buildSessionFactory(); + } + + @Required + public void setRegionFactory(RegionFactory regionFactory) { + this.regionFactory = regionFactory; + } + +} \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/MyIntegrator.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/MyIntegrator.java index 030981344d..b0d4fec2c2 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/MyIntegrator.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/config/MyIntegrator.java @@ -18,12 +18,11 @@ import org.cgiar.ccafs.marlo.data.AuditColumnHibernateListener; import org.cgiar.ccafs.marlo.data.HibernateAuditLogListener; -import org.hibernate.cfg.Configuration; +import org.hibernate.boot.Metadata; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.integrator.spi.Integrator; -import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +37,7 @@ public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactor } @Override - public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, + public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class); @@ -59,12 +58,5 @@ public void integrate(Configuration configuration, SessionFactoryImplementor ses } - @Override - public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory, - SessionFactoryServiceRegistry serviceRegistry) { - return; - - } - } diff --git a/marlo-parent/pom.xml b/marlo-parent/pom.xml index f4071efaa9..28ed08b227 100644 --- a/marlo-parent/pom.xml +++ b/marlo-parent/pom.xml @@ -12,7 +12,7 @@ UTF-8 5.5 - 4.3.11.Final + 5.6.14.Final 4.3.24.RELEASE 4.13.2 1.2.13 diff --git a/marlo-utils/pom.xml b/marlo-utils/pom.xml index a7b746e58b..75431c19f7 100644 --- a/marlo-utils/pom.xml +++ b/marlo-utils/pom.xml @@ -50,6 +50,12 @@ org.springframework spring-context-support + + + dom4j + dom4j + 1.6.1 + diff --git a/marlo-web/pom.xml b/marlo-web/pom.xml index 9bfc58161c..9438222dbf 100644 --- a/marlo-web/pom.xml +++ b/marlo-web/pom.xml @@ -414,6 +414,11 @@ + + org.javassist + javassist + 3.27.0-GA + diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java index e236cf7b0f..47ccdd62c9 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java @@ -148,7 +148,7 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import org.jsoup.safety.Safelist;; +import org.jsoup.safety.Safelist; import org.jsoup.select.Elements; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/marlo-web/src/main/resources/ehcache.xml b/marlo-web/src/main/resources/ehcache.xml index 2d6061ae87..807c62d689 100644 --- a/marlo-web/src/main/resources/ehcache.xml +++ b/marlo-web/src/main/resources/ehcache.xml @@ -19,7 +19,7 @@ @@ -27,7 +27,7 @@ From 9198bac0b919810f2222951479ed3b54ab9e4895 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Fri, 19 Jul 2024 16:09:08 -0500 Subject: [PATCH 2/9] :sparkles: feat(Project): Modify classes of the marlo-data component, to adapt it to the new version of hibernate.aiccra-feature-A2-749-hibernate-new-version --- .../data/dao/mysql/AbstractMarloDAO.java | 48 ++++-- .../data/dao/mysql/ActivityTitleMySQLDAO.java | 6 +- .../data/dao/mysql/AuditLogMySQLDao.java | 5 +- .../data/dao/mysql/CrpMilestoneMySQLDAO.java | 4 +- .../dao/mysql/CrpOutcomeSubIdoMySQLDAO.java | 6 +- .../CrpProgramOutcomeIndicatorMySQLDAO.java | 5 +- .../dao/mysql/CrpProgramOutcomeMySQLDAO.java | 4 +- .../mysql/DeliverableAffiliationMySQLDAO.java | 4 +- .../DeliverableAltmetricInfoMySQLDAO.java | 5 +- ...DeliverableClusterParticipantMySQLDAO.java | 8 +- .../dao/mysql/DeliverableCrpMySQLDAO.java | 4 +- .../DeliverableDisseminationMySQLDAO.java | 4 +- .../DeliverableIntellectualAssetMySQLDAO.java | 4 +- .../DeliverableMetadataElementMySQLDAO.java | 4 +- ...erableMetadataExternalSourcesMySQLDAO.java | 5 +- .../data/dao/mysql/DeliverableMySQLDAO.java | 4 +- .../mysql/DeliverableParticipantMySQLDAO.java | 5 +- ...eliverablePublicationMetadataMySQLDAO.java | 4 +- .../DeliverableQualityCheckMySQLDAO.java | 5 +- .../dao/mysql/DeliverableUserMySQLDAO.java | 6 +- .../mysql/ExpectedStudyProjectMySQLDAO.java | 5 +- .../mysql/ExternalSourceAuthorMySQLDAO.java | 4 +- .../data/dao/mysql/GlobalUnitMySQLDAO.java | 162 +++++++++--------- .../data/dao/mysql/InstitutionMySQLDAO.java | 4 +- .../ProjectDeliverableSharedMySQLDAO.java | 8 +- .../ProjectExpectedStudyLinkMySQLDAO.java | 4 +- ...ProjectExpectedStudyReferenceMySQLDAO.java | 4 +- .../ProjectInnovationSharedMySQLDAO.java | 4 +- .../dao/mysql/ProjectPartnerMySQLDAO.java | 4 +- ...isFlagshipProgressDeliverableMySQLDAO.java | 5 +- .../marlo/data/dao/mysql/UserMySQLDAO.java | 6 +- marlo-parent/pom.xml | 2 +- .../web/filter/MARLOCustomPersistFilter.java | 1 + 33 files changed, 189 insertions(+), 164 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 2b8a9190e7..455ac40dd8 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -24,8 +24,10 @@ import java.util.Map; import org.hibernate.FlushMode; -import org.hibernate.Query; +import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.hibernate.query.NativeQuery; +import org.hibernate.query.Query; // import org.hibernate.Transaction; import org.hibernate.transform.AliasToEntityMapResultTransformer; import org.slf4j.Logger; @@ -81,10 +83,11 @@ protected void delete(Object obj) { * @param sqlQuery is a string representing an SQL query. */ public List> excuteStoreProcedure(String storeProcedure, String sqlQuery) { - Query queryProcd = this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); + NativeQuery> queryProcd = + this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); queryProcd.setFlushMode(FlushMode.COMMIT); queryProcd.executeUpdate(); - Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + NativeQuery> query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); query.setFlushMode(FlushMode.COMMIT); @@ -109,7 +112,7 @@ public Object executeFunction(String function) { */ public void executeUpdateQuery(String sqlQuery) { - Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setFlushMode(FlushMode.COMMIT); query.executeUpdate(); } @@ -140,19 +143,20 @@ public void executeUpdateQuery(String sqlQuery) { * @return the object populated. */ public T find(Class clazz, ID id) { - T obj = (T) sessionFactory.getCurrentSession().get(clazz, id); + + T obj = sessionFactory.getCurrentSession().get(clazz, id); return obj; } - - protected List findAll(Query hibernateQuery) { - hibernateQuery.setFlushMode(FlushMode.COMMIT); + protected List findAll(Query hibernateQuery) { + hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") List list = hibernateQuery.list(); return list; } + /** * This method make a query that returns a list of objects from the model. * This method was implemented in a generic way, so, the list of objects to be returned will depend on how the method @@ -166,7 +170,7 @@ protected List findAll(Query hibernateQuery) { * @return a list of objects. */ protected List findAll(String hibernateQuery) { - Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); + Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); return this.findAll(query); } @@ -176,7 +180,7 @@ protected List findAll(String hibernateQuery) { * @param sqlQuery is a string representing an HQL query. */ public List> findCustomQuery(String sqlQuery) { - Query query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + NativeQuery> query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); query.setFlushMode(FlushMode.COMMIT); List> result = query.list(); @@ -186,8 +190,8 @@ public List> findCustomQuery(String sqlQuery) { } protected List findEveryone(Class clazz) { - Query query = sessionFactory.getCurrentSession().createQuery("from " + clazz.getName()); - query.setFlushMode(FlushMode.COMMIT); + Query query = sessionFactory.getCurrentSession().createQuery("from " + clazz.getName()); + query.setHibernateFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") List list = query.list(); @@ -195,7 +199,6 @@ protected List findEveryone(Class clazz) { } - /** * Allows clients to create the HibernateQuery and set parameters on it. * @@ -203,12 +206,13 @@ protected List findEveryone(Class clazz) { * @param hibernateQuery * @return */ - protected T findSingleResult(Class clazz, Query hibernateQuery) { - hibernateQuery.setFlushMode(FlushMode.COMMIT); + protected T findSingleResult(Class clazz, Query hibernateQuery) { + hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); T object = clazz.cast(hibernateQuery.uniqueResult()); return object; } + /** * This method make a query that returns a single object result from the model. * This method was implemented in a generic way, so, the object to be returned will depend on how the method @@ -218,11 +222,21 @@ protected T findSingleResult(Class clazz, Query hibernateQuery) { * @return a Object of */ protected T findSingleResult(Class clazz, String hibernateQuery) { - Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); - query.setFlushMode(FlushMode.COMMIT); + Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); + query.setHibernateFlushMode(FlushMode.COMMIT); return this.findSingleResult(clazz, query); } + public Session getCurrentSession() { + Session session = sessionFactory.getCurrentSession(); + + if (session == null || !session.isOpen()) { + session = sessionFactory.openSession(); + } + + return session; + } + /** * Return the sessionFactory. DAOs are free to get this and use it to perform custom queries. diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java index f4f0165752..f11260a01c 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ActivityTitleMySQLDAO extends AbstractMarloDAO implements ActivityTitleDAO { @@ -58,6 +58,7 @@ public ActivityTitle find(long id) { } + @Override public List findAll() { String query = "from " + ActivityTitle.class.getName(); @@ -72,7 +73,7 @@ public List findAll() { @Override public List findByCurrentYear(int year) { String query = "select pat from ActivityTitle pat where pat.endYear >= :year and pat.startYear < :year"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("year", year); List list = super.findAll(createQuery); if (!list.isEmpty()) { @@ -81,6 +82,7 @@ public List findByCurrentYear(int year) { return null; } + @Override public ActivityTitle save(ActivityTitle activityTitle) { if (activityTitle.getId() == null) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java index e2b31f729e..ca15fd4ed2 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java @@ -43,15 +43,16 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; -import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.metadata.ClassMetadata; +import org.hibernate.query.Query; import org.hibernate.type.OneToOneType; import org.hibernate.type.OrderedSetType; import org.hibernate.type.SetType; import org.hibernate.type.Type; + /** * @author Christian Garcia */ @@ -72,7 +73,7 @@ public List findAllWithClassNameAndIdAndActionName(Class classAudit String queryString = "from " + Auditlog.class.getName() + " where ENTITY_NAME='class " + classAudit.getName() + "' and ENTITY_ID=" + id + " and main=1 and DETAIL like 'Action: " + actionName + "%' order by CREATED_DATE desc"; - Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString); + Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString); query.setMaxResults(11); List auditLogs = super.findAll(query); return auditLogs; diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpMilestoneMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpMilestoneMySQLDAO.java index 223a216d8e..4fc783c9d5 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpMilestoneMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpMilestoneMySQLDAO.java @@ -27,8 +27,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class CrpMilestoneMySQLDAO extends AbstractMarloDAO implements CrpMilestoneDAO { @@ -77,7 +77,7 @@ public List findAll() { public CrpMilestone getCrpMilestone(String composedId, CrpProgramOutcome crpProgramOutcome) { String query = "select distinct pp from CrpMilestone pp " + "where composeID=:composeID and crpProgramOutcome.id=:crpProgramOutcomeID and active=true"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("composeID", composedId); createQuery.setParameter("crpProgramOutcomeID", crpProgramOutcome.getId()); Object findSingleResult = super.findSingleResult(CrpMilestone.class, createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpOutcomeSubIdoMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpOutcomeSubIdoMySQLDAO.java index 924a322b6b..41253d527e 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpOutcomeSubIdoMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpOutcomeSubIdoMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class CrpOutcomeSubIdoMySQLDAO extends AbstractMarloDAO implements CrpOutcomeSubIdoDAO { @@ -74,7 +74,7 @@ public CrpOutcomeSubIdo getCrpOutcomeSubIdoByOutcomeComposedIdAndPhase(String ou + "with cpo.composeID = :composeID and cpo.active=true " + "and cpo.phase.id = :phaseID " + " where cosi.srfSubIdo is null and cosi.active=true and cosi.crpProgramOutcome.active=true"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("composeID", outcomeComposedId); createQuery.setParameter("phaseID", phaseId); @@ -89,7 +89,7 @@ public CrpOutcomeSubIdo getCrpOutcomeSubIdoByOutcomeComposedIdPhaseAndSubIdo(Str + "with cpo.composeID = :composeID and cpo.active=true " + "and cpo.phase.id = :phaseID " + " where cosi.srfSubIdo.id = :subIdoID and cosi.active=true and cosi.crpProgramOutcome.active=true"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("composeID", outcomeComposedId); createQuery.setParameter("phaseID", phaseId); createQuery.setParameter("subIdoID", subIdoId); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeIndicatorMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeIndicatorMySQLDAO.java index 2c34428609..b76a1cfda3 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeIndicatorMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeIndicatorMySQLDAO.java @@ -28,8 +28,9 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; + @Named @@ -81,7 +82,7 @@ public CrpProgramOutcomeIndicator getCrpProgramOutcomeIndicator(String composedI CrpProgramOutcome crpProgramOutcome) { String query = "select distinct pp from CrpProgramOutcomeIndicator pp " + "where composeID=:id and crpProgramOutcome.id=:crpProgramOutcomeID and active=true"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("id", composedId); createQuery.setParameter("crpProgramOutcomeID", crpProgramOutcome.getId()); Object findSingleResult = super.findSingleResult(CrpProgramOutcomeIndicator.class, createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeMySQLDAO.java index 15bb075f62..b571097949 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/CrpProgramOutcomeMySQLDAO.java @@ -25,8 +25,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class CrpProgramOutcomeMySQLDAO extends AbstractMarloDAO @@ -78,7 +78,7 @@ public List findAll() { public List getAllCrpProgramOutcomesByComposedIdFromPhase(String composedId, long phaseId) { String query = "select distinct cpo from CrpProgramOutcome cpo " + "where composeID=:composeID and active=true " + "and phase.id >= :phaseId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("composeID", composedId); createQuery.setParameter("phaseId", phaseId); List resultList = super.findAll(createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAffiliationMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAffiliationMySQLDAO.java index f20ac6e857..112efce5cd 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAffiliationMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAffiliationMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableAffiliationMySQLDAO extends AbstractMarloDAO @@ -77,7 +77,7 @@ public List findAll() { public List findByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct da from DeliverableAffiliation da where phase.id = :phaseId " + "and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAltmetricInfoMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAltmetricInfoMySQLDAO.java index bf889f9a05..43003ea204 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAltmetricInfoMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableAltmetricInfoMySQLDAO.java @@ -25,8 +25,9 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; + /************** * @author German C. Martinez - CIAT/CCAFS @@ -79,7 +80,7 @@ public List findAll() { public DeliverableAltmetricInfo findByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct dai from DeliverableAltmetricInfo dai where phase.id = :phaseId " + "and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableClusterParticipantMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableClusterParticipantMySQLDAO.java index 82982ec7be..19202e68cb 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableClusterParticipantMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableClusterParticipantMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableClusterParticipantMySQLDAO extends AbstractMarloDAO @@ -77,7 +77,7 @@ public List getDeliverableClusterParticipantByDel String query = "select dp from DeliverableClusterParticipant dp " + "where phase.id = :phaseId and deliverable.id= :deliverableId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phaseID); createQuery.setParameter("deliverableId", deliverableID); @@ -92,7 +92,7 @@ public List getDeliverableClusterParticipantByDel String query = "select dp from DeliverableClusterParticipant dp " + "where phase.id = :phaseId and deliverable.id= :deliverableId and project.id= :projectId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phaseID); createQuery.setParameter("deliverableId", deliverableID); createQuery.setParameter("projectId", projectID); @@ -108,7 +108,7 @@ public List getDeliverableClusterParticipantByPro String query = "select dp from DeliverableClusterParticipant dp " + "where phase.id = :phaseId and project.id= :projectId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phaseID); createQuery.setParameter("projectId", projectID); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableCrpMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableCrpMySQLDAO.java index 72ad89343a..0c651ea91d 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableCrpMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableCrpMySQLDAO.java @@ -28,8 +28,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableCrpMySQLDAO extends AbstractMarloDAO implements DeliverableCrpDAO { @@ -89,7 +89,7 @@ public DeliverableCrp findDeliverableCrpByPhaseAndDeliverable(Phase phase, Deliv } else { query += "and crpProgram.id IS NULL "; } - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); if (globalUnit != null) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableDisseminationMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableDisseminationMySQLDAO.java index d980cc9d78..2a4c84fab7 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableDisseminationMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableDisseminationMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableDisseminationMySQLDAO extends AbstractMarloDAO @@ -76,7 +76,7 @@ public List findAll() { public DeliverableDissemination findDisseminationByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct dd from DeliverableDissemination dd " + " where phase.id = :phaseId and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableIntellectualAssetMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableIntellectualAssetMySQLDAO.java index 72d4f5249a..847e18b68a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableIntellectualAssetMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableIntellectualAssetMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableIntellectualAssetMySQLDAO extends AbstractMarloDAO @@ -76,7 +76,7 @@ public List findAll() { public DeliverableIntellectualAsset findIntellectualAssetByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct di from DeliverableIntellectualAsset di " + " where phase.id = :phaseId and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataElementMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataElementMySQLDAO.java index c19dc7d613..bbaff3c8de 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataElementMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataElementMySQLDAO.java @@ -27,8 +27,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableMetadataElementMySQLDAO extends AbstractMarloDAO @@ -79,7 +79,7 @@ public DeliverableMetadataElement findMetadataElementByPhaseAndDeliverable(Phase MetadataElement metadataElement) { String query = "select distinct dm from DeliverableMetadataElement dm where phase.id = :phaseId " + "and deliverable.id= :deliverableId and metadataElement.id = :metadataElementId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); createQuery.setParameter("metadataElementId", metadataElement.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataExternalSourcesMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataExternalSourcesMySQLDAO.java index 98632fa46f..d10dcd7e3a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataExternalSourcesMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMetadataExternalSourcesMySQLDAO.java @@ -25,8 +25,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; /************** * @author German C. Martinez - CIAT/CCAFS @@ -81,7 +81,8 @@ public List findAll() { public DeliverableMetadataExternalSources findByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct dm from DeliverableMetadataExternalSources dm where phase.id = :phaseId " + "and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = + this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java index 5eca0294c7..66e0694efe 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java @@ -32,8 +32,8 @@ import javax.inject.Named; import org.hibernate.FlushMode; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableMySQLDAO extends AbstractMarloDAO implements DeliverableDAO { @@ -307,7 +307,7 @@ public List getDeliverablesByProjectAndPhase(long phaseId, long pro + "join d.project pr with pr.id = :projectId and pr.active = true join di.phase ph with ph.id = :phaseId " + "where di.deliverable = d and d.active = true and coalesce(nullif(di.newExpectedYear, -1),di.year) = ph.year"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phaseId); createQuery.setParameter("projectId", projectId); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableParticipantMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableParticipantMySQLDAO.java index cd0cc55a96..6b7c321311 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableParticipantMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableParticipantMySQLDAO.java @@ -29,8 +29,9 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; + @Named public class DeliverableParticipantMySQLDAO extends AbstractMarloDAO @@ -92,7 +93,7 @@ public List findDeliverableParticipantByDeliverableAndPh public DeliverableParticipant findDeliverableParticipantByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct dp from DeliverableParticipant dp " + " where phase.id = :phaseId and deliverable.id= :deliverableId and dp.active = 1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverablePublicationMetadataMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverablePublicationMetadataMySQLDAO.java index 4a8aa67f42..5cef857653 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverablePublicationMetadataMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverablePublicationMetadataMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverablePublicationMetadataMySQLDAO extends AbstractMarloDAO @@ -77,7 +77,7 @@ public DeliverablePublicationMetadata findPublicationMetadataByPhaseAndDeliverab Deliverable deliverable) { String query = "select distinct dp from DeliverablePublicationMetadata dp " + " where phase.id = :phaseId and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableQualityCheckMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableQualityCheckMySQLDAO.java index 32150ab280..40f2374ba1 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableQualityCheckMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableQualityCheckMySQLDAO.java @@ -26,8 +26,9 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; + @Named public class DeliverableQualityCheckMySQLDAO extends AbstractMarloDAO @@ -88,7 +89,7 @@ public DeliverableQualityCheck findByDeliverable(long id, long phaseID) { public DeliverableQualityCheck findQualityByPhaseAndDeliverable(Phase phase, Deliverable deliverable) { String query = "select distinct dq from DeliverableQualityCheck dq " + " where phase.id = :phaseId and deliverable.id= :deliverableId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverable.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableUserMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableUserMySQLDAO.java index a5d7c735aa..739e79815e 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableUserMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableUserMySQLDAO.java @@ -25,8 +25,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class DeliverableUserMySQLDAO extends AbstractMarloDAO implements DeliverableUserDAO { @@ -75,7 +75,7 @@ public DeliverableUser findDeliverableUserByPhaseAndDeliverableUser(Phase phase, String query = "select distinct du from DeliverableUser du " + "where phase.id = :phaseId and deliverable.id= :deliverableId " + "and du.firstName = :duFirstName and du.lastName = :duLastName and du.elementId = :duElementId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverableUser.getDeliverable().getId()); createQuery.setParameter("duFirstName", deliverableUser.getFirstName()); @@ -92,7 +92,7 @@ public List findDeliverableUserByPhases(Phase phase, Deliverabl String query = "select distinct du from DeliverableUser du " + "where phase.id = :phaseId and deliverable.id= :deliverableId " + "and du.firstName = :duFirstName and du.lastName = :duLastName and du.elementId = :duElementId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("deliverableId", deliverableUser.getDeliverable().getId()); createQuery.setParameter("duFirstName", deliverableUser.getFirstName()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExpectedStudyProjectMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExpectedStudyProjectMySQLDAO.java index c42d418a82..9bc631ec78 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExpectedStudyProjectMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExpectedStudyProjectMySQLDAO.java @@ -24,8 +24,9 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; + @Named public class ExpectedStudyProjectMySQLDAO extends AbstractMarloDAO @@ -74,7 +75,7 @@ public List findAll() { public List getByProjectAndPhase(long projectId, long phaseId) { String query = "select distinct esp from ExpectedStudyProject esp " + "where project.id = :projectId and phase.id = :phaseId and is_active = 1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("projectId", projectId); createQuery.setParameter("phaseId", phaseId); List result = super.findAll(createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExternalSourceAuthorMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExternalSourceAuthorMySQLDAO.java index b9e97a8dad..717243fb9f 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExternalSourceAuthorMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ExternalSourceAuthorMySQLDAO.java @@ -23,8 +23,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; /************** * @author German C. Martinez - CIAT/CCAFS @@ -78,7 +78,7 @@ public List findAll() { findExternalSourceAuthorFromExternalSource(long deliverableMetadataExternalSourceId) { String query = "select distinct esa from ExternalSourceAuthor esa " + "where deliverableMetadataExternalSources.id = :deliverableMetadataExternalSourceId"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("deliverableMetadataExternalSourceId", deliverableMetadataExternalSourceId); List result = super.findAll(createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/GlobalUnitMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/GlobalUnitMySQLDAO.java index 24dabffdaa..8a2d725b72 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/GlobalUnitMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/GlobalUnitMySQLDAO.java @@ -23,91 +23,91 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class GlobalUnitMySQLDAO extends AbstractMarloDAO implements GlobalUnitDAO { - @Inject - public GlobalUnitMySQLDAO(SessionFactory sessionFactory) { - super(sessionFactory); - } - - @Override - public List crpUsers(String emai) { - - String query = "select distinct cp from GlobalUnit cp inner join fetch cp.crpUsers cpUser " - + "where (cpUser.user.email = :emai or cpUser.user.username =:emai ) and cpUser.active=1 "; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); - createQuery.setParameter("emai", emai); - List crps = super.findAll(createQuery); - return crps; - } - - @Override - public void deleteGlobalUnit(long globalUnitId) { - GlobalUnit globalUnit = this.find(globalUnitId); - globalUnit.setActive(false); - this.save(globalUnit); - } - - @Override - public boolean existGlobalUnit(long globalUnitID) { - GlobalUnit globalUnit = this.find(globalUnitID); - if (globalUnit == null) { - return false; - } - return true; - - } - - @Override - public GlobalUnit find(long id) { - return super.find(GlobalUnit.class, id); - - } - - @Override - public List findAll() { - String query = "from " + GlobalUnit.class.getName() + " where is_active=1"; - List list = super.findAll(query); - if (list.size() > 0) { - return list; - } - return null; - - } - - @Override - public GlobalUnit findGlobalUnitByAcronym(String acronym) { - String query = "from " + GlobalUnit.class.getName() + " where acronym='" + acronym + "'"; - List list = super.findAll(query); - if (list.size() > 0) { - return list.get(0); - } - return null; - } - - @Override - public GlobalUnit findGlobalUnitBySMOCode(String smoCode) { - String query = "from " + GlobalUnit.class.getName() + " where smo_code='" + smoCode + "'"; - List list = super.findAll(query); - if (list.size() > 0) { - return list.get(0); - } - return null; - } - - @Override - public GlobalUnit save(GlobalUnit globalUnit) { - if (globalUnit.getId() == null) { - super.saveEntity(globalUnit); - } else { - globalUnit = super.update(globalUnit); - } - - return globalUnit; - } + @Inject + public GlobalUnitMySQLDAO(SessionFactory sessionFactory) { + super(sessionFactory); + } + + @Override + public List crpUsers(String emai) { + + String query = "select distinct cp from GlobalUnit cp inner join fetch cp.crpUsers cpUser " + + "where (cpUser.user.email = :emai or cpUser.user.username =:emai ) and cpUser.active=1 "; + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + createQuery.setParameter("emai", emai); + List crps = super.findAll(createQuery); + return crps; + } + + @Override + public void deleteGlobalUnit(long globalUnitId) { + GlobalUnit globalUnit = this.find(globalUnitId); + globalUnit.setActive(false); + this.save(globalUnit); + } + + @Override + public boolean existGlobalUnit(long globalUnitID) { + GlobalUnit globalUnit = this.find(globalUnitID); + if (globalUnit == null) { + return false; + } + return true; + + } + + @Override + public GlobalUnit find(long id) { + return super.find(GlobalUnit.class, id); + + } + + @Override + public List findAll() { + String query = "from " + GlobalUnit.class.getName() + " where is_active=1"; + List list = super.findAll(query); + if (list.size() > 0) { + return list; + } + return null; + + } + + @Override + public GlobalUnit findGlobalUnitByAcronym(String acronym) { + String query = "from " + GlobalUnit.class.getName() + " where acronym='" + acronym + "'"; + List list = super.findAll(query); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + public GlobalUnit findGlobalUnitBySMOCode(String smoCode) { + String query = "from " + GlobalUnit.class.getName() + " where smo_code='" + smoCode + "'"; + List list = super.findAll(query); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + public GlobalUnit save(GlobalUnit globalUnit) { + if (globalUnit.getId() == null) { + super.saveEntity(globalUnit); + } else { + globalUnit = super.update(globalUnit); + } + + return globalUnit; + } } \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java index 7ddf5eecc2..0652703a3b 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; /** @@ -131,7 +131,7 @@ public List searchInstitution(String searchValue, int ppaPartner, i + "when i.acronym like concat('%', :institutionName) then 7 when i.websiteLink like concat(:institutionName, '%') then 2 " + "when i.websiteLink like concat('% %', :institutionName, '% %') then 5 when i.websiteLink like concat('%', :institutionName) then 8 " + "else 12 end), i.name, i.acronym, i.websiteLink"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("institutionName", searchValue); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectDeliverableSharedMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectDeliverableSharedMySQLDAO.java index b91cdfa94d..b68f68014f 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectDeliverableSharedMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectDeliverableSharedMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ProjectDeliverableSharedMySQLDAO extends AbstractMarloDAO @@ -75,7 +75,7 @@ public List findAll() { public List getByDeliverable(long deliverableId, long phaseId) { String query = "select distinct esp from ProjectDeliverableShared esp " + "where deliverable.id = :deliverableId and phase.id = :phaseId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("deliverableId", deliverableId); createQuery.setParameter("phaseId", phaseId); List result = super.findAll(createQuery); @@ -91,7 +91,7 @@ public List getByDeliverable(long deliverableId, long public List getByPhase(long phaseId) { String query = "select distinct esp from ProjectDeliverableShared esp " + "where phase.id = :phaseId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phaseId); List result = super.findAll(createQuery); @@ -106,7 +106,7 @@ public List getByPhase(long phaseId) { public List getByProjectAndPhase(long projectId, long phaseId) { String query = "select distinct esp from ProjectDeliverableShared esp " + "where project.id = :projectId and phase.id = :phaseId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("projectId", projectId); createQuery.setParameter("phaseId", phaseId); List result = super.findAll(createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyLinkMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyLinkMySQLDAO.java index 4896ff1f1e..601f511e83 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyLinkMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyLinkMySQLDAO.java @@ -25,8 +25,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ProjectExpectedStudyLinkMySQLDAO extends AbstractMarloDAO @@ -77,7 +77,7 @@ public ProjectExpectedStudyLink findProjectExpectedStudyLinkByPhase(Phase phase, ProjectExpectedStudyLink projectExpectedStudyLink) { String query = "select distinct du from ProjectExpectedStudyLink du " + "where phase.id = :phaseId and projectExpectedStudy.id= :expectedId " + "and du.link = :duLink"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("phaseId", phase.getId()); createQuery.setParameter("expectedId", projectExpectedStudyLink.getProjectExpectedStudy().getId()); createQuery.setParameter("duLink", projectExpectedStudyLink.getLink()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyReferenceMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyReferenceMySQLDAO.java index 04dabce400..8ee3b82558 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyReferenceMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectExpectedStudyReferenceMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ProjectExpectedStudyReferenceMySQLDAO extends AbstractMarloDAO @@ -76,7 +76,7 @@ public List getAllStudyReferencesByStudy(long stu String query = "select peslink from ProjectExpectedStudyReference peslink where peslink.projectExpectedStudy.id = :studyId " + "order by peslink.phase.id"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("studyId", studyId); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectInnovationSharedMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectInnovationSharedMySQLDAO.java index b5f0b31423..c405edee64 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectInnovationSharedMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectInnovationSharedMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ProjectInnovationSharedMySQLDAO extends AbstractMarloDAO @@ -75,7 +75,7 @@ public List findAll() { public List getByProjectAndPhase(long projectId, long phaseId) { String query = "select distinct esp from ProjectInnovationShared esp " + "where project.id = :projectId and phase.id = :phaseId and is_active=1"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("projectId", projectId); createQuery.setParameter("phaseId", phaseId); List result = super.findAll(createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectPartnerMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectPartnerMySQLDAO.java index 8fda41db5d..a1ec4532dc 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectPartnerMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ProjectPartnerMySQLDAO.java @@ -30,8 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ProjectPartnerMySQLDAO extends AbstractMarloDAO implements ProjectPartnerDAO { @@ -130,7 +130,7 @@ public ProjectPartner getPartnerPhase(Phase phase, Project project, Institution public ProjectPartner getProjectPartnerByIdAndEagerFetchLocations(long projectPartnerID) { String query = "select distinct pp from ProjectPartner pp left join fetch pp.projectPartnerLocations ppl " + "where pp.id = :projectPartnerID"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("projectPartnerID", projectPartnerID); Object findSingleResult = super.findSingleResult(ProjectPartner.class, createQuery); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ReportSynthesisFlagshipProgressDeliverableMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ReportSynthesisFlagshipProgressDeliverableMySQLDAO.java index efb43ba1d4..e4e1cd2210 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ReportSynthesisFlagshipProgressDeliverableMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ReportSynthesisFlagshipProgressDeliverableMySQLDAO.java @@ -24,8 +24,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; @Named public class ReportSynthesisFlagshipProgressDeliverableMySQLDAO @@ -79,7 +79,8 @@ public ReportSynthesisFlagshipProgressDeliverable getByFlagshipProgressAndDelive long progressId) { String query = "select distinct rsfpd from ReportSynthesisFlagshipProgressDeliverable rsfpd " + "where reportSynthesisFlagshipProgress.id = :progressId and deliverable.id = :deliverableId order by activeSince desc"; - Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + Query createQuery = + this.getSessionFactory().getCurrentSession().createQuery(query); createQuery.setParameter("progressId", progressId); createQuery.setParameter("deliverableId", deliverableId); // equivalent to LIMIT 1 diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/UserMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/UserMySQLDAO.java index 4c2e158a93..44cec74015 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/UserMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/UserMySQLDAO.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Named; -import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.hibernate.query.Query; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,8 +56,8 @@ public List> getCenterPermission(int userId, String centerId @Override public String getEmailByUsername(String username) { String queryString = "select email from " + User.class.getName() + " where username = '" + username + "'"; - Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString); - String email = (String) query.uniqueResult(); + Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString, String.class); + String email = query.uniqueResult(); return email; } diff --git a/marlo-parent/pom.xml b/marlo-parent/pom.xml index 28ed08b227..02870a3aad 100644 --- a/marlo-parent/pom.xml +++ b/marlo-parent/pom.xml @@ -12,7 +12,7 @@ UTF-8 5.5 - 5.6.14.Final + 5.4.10.Final 4.3.24.RELEASE 4.13.2 1.2.13 diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/web/filter/MARLOCustomPersistFilter.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/web/filter/MARLOCustomPersistFilter.java index ef5f66ab42..fc83450912 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/web/filter/MARLOCustomPersistFilter.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/web/filter/MARLOCustomPersistFilter.java @@ -91,6 +91,7 @@ protected void doFilterInternal(HttpServletRequest httpRequest, HttpServletRespo if (cache != null) { cache.evictAllRegions(); // Evict data from all query regions. } + System.out.println("Cache cleared for request: " + requestUrl); sessionFactory.getCurrentSession().beginTransaction(); // Continue filter chain chain.doFilter(httpRequest, response); From d1567bca131238aa489cd7025f117cfcdb699164 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Wed, 24 Jul 2024 11:50:58 -0500 Subject: [PATCH 3/9] :sparkles: feat(Project): Modify classes of the marlo-data component, to adapt it to the new version of hibernate.aiccra-feature-A2-749-hibernate-new-version --- .../data/dao/mysql/AbstractMarloDAO.java | 118 +++++++++++++----- 1 file changed, 90 insertions(+), 28 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 455ac40dd8..f74ae6aac5 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -26,6 +26,7 @@ import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.hibernate.Transaction; import org.hibernate.query.NativeQuery; import org.hibernate.query.Query; // import org.hibernate.Transaction; @@ -74,6 +75,7 @@ private void addAuditLogFieldsToThreadStorage(Object entity, String actionName, * @param obj is a persistence instance from the database model. */ protected void delete(Object obj) { + System.out.println(" linea 78"); this.sessionFactory.getCurrentSession().delete(obj); } @@ -83,15 +85,29 @@ protected void delete(Object obj) { * @param sqlQuery is a string representing an SQL query. */ public List> excuteStoreProcedure(String storeProcedure, String sqlQuery) { - NativeQuery> queryProcd = - this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); - queryProcd.setFlushMode(FlushMode.COMMIT); + System.out.println(" linea 87 excuteStoreProcedure "); + Session sesion = sessionFactory.openSession(); + System.out.println(" linea 89 excuteStoreProcedure "); + System.out.println(" linea 90 excuteStoreProcedure " + storeProcedure); + Transaction transaction = sesion.beginTransaction(); + NativeQuery> queryProcd = sesion.createSQLQuery(storeProcedure); + System.out.println(" linea 92 excuteStoreProcedure "); + // queryProcd.setFlushMode(FlushMode.COMMIT); + System.out.println(" linea 95 excuteStoreProcedure "); queryProcd.executeUpdate(); - NativeQuery> query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + NativeQuery> query = sesion.createSQLQuery(sqlQuery); + System.out.println(" linea 98 excuteStoreProcedure "); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); - query.setFlushMode(FlushMode.COMMIT); + System.out.println(" linea 100 excuteStoreProcedure "); + // query.setFlushMode(FlushMode.COMMIT); + System.out.println(" linea 102 excuteStoreProcedure "); List> result = query.list(); + System.out.println(" linea 105 excuteStoreProcedure "); + transaction.commit(); + System.out.println(" linea 107 excuteStoreProcedure "); + sesion.close(); + System.out.println(" linea 109 excuteStoreProcedure "); return result; } @@ -111,7 +127,7 @@ public Object executeFunction(String function) { * @param sqlQuery */ public void executeUpdateQuery(String sqlQuery) { - + System.out.println(" linea 130"); NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setFlushMode(FlushMode.COMMIT); query.executeUpdate(); @@ -143,13 +159,24 @@ public void executeUpdateQuery(String sqlQuery) { * @return the object populated. */ public T find(Class clazz, ID id) { + System.out.println(" linea 162"); + Session sesion = sessionFactory.openSession(); + Transaction transaction = sesion.beginTransaction(); + System.out.println(" linea 165"); + T obj = sesion.get(clazz, id); + + // committing the transaction + transaction.commit(); // Transaction is committed - T obj = sessionFactory.getCurrentSession().get(clazz, id); + // closing the session + // sesion.close(); + System.out.println(" linea 173"); return obj; } protected List findAll(Query hibernateQuery) { + System.out.println(" linea 177"); hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") List list = hibernateQuery.list(); @@ -170,7 +197,11 @@ protected List findAll(Query hibernateQuery) { * @return a list of objects. */ protected List findAll(String hibernateQuery) { - Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); + System.out.println(" linea 196"); + Session sesion = sessionFactory.openSession(); + Transaction transaction = sesion.beginTransaction(); + Query query = sesion.createQuery(hibernateQuery); + transaction.commit(); return this.findAll(query); } @@ -180,21 +211,33 @@ protected List findAll(String hibernateQuery) { * @param sqlQuery is a string representing an HQL query. */ public List> findCustomQuery(String sqlQuery) { - NativeQuery> query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + System.out.println(" linea 207"); + Session sesion = sessionFactory.openSession(); + Transaction transaction = sesion.beginTransaction(); + NativeQuery> query = sesion.createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); query.setFlushMode(FlushMode.COMMIT); List> result = query.list(); - + transaction.commit(); + System.out.println(" linea 218"); return result; } protected List findEveryone(Class clazz) { - Query query = sessionFactory.getCurrentSession().createQuery("from " + clazz.getName()); + System.out.println(" linea 224"); + Session sesion = sessionFactory.openSession(); + Transaction transaction = sesion.beginTransaction(); + System.out.println(" linea 227"); + Query query = sesion.createQuery("from " + clazz.getName()); + System.out.println(" linea 229"); query.setHibernateFlushMode(FlushMode.COMMIT); - + System.out.println(" linea 231"); @SuppressWarnings("unchecked") List list = query.list(); + System.out.println(" linea 234"); + transaction.commit(); + System.out.println(" linea 236"); return list; } @@ -207,12 +250,12 @@ protected List findEveryone(Class clazz) { * @return */ protected T findSingleResult(Class clazz, Query hibernateQuery) { + System.out.println(" linea 251"); hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); T object = clazz.cast(hibernateQuery.uniqueResult()); return object; } - /** * This method make a query that returns a single object result from the model. * This method was implemented in a generic way, so, the object to be returned will depend on how the method @@ -222,12 +265,15 @@ protected T findSingleResult(Class clazz, Query hibernateQuery) { * @return a Object of */ protected T findSingleResult(Class clazz, String hibernateQuery) { + System.out.println(" linea 266"); Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); query.setHibernateFlushMode(FlushMode.COMMIT); return this.findSingleResult(clazz, query); } + public Session getCurrentSession() { + System.out.println(" linea 274"); Session session = sessionFactory.getCurrentSession(); if (session == null || !session.isOpen()) { @@ -237,7 +283,6 @@ public Session getCurrentSession() { return session; } - /** * Return the sessionFactory. DAOs are free to get this and use it to perform custom queries. * @@ -248,20 +293,6 @@ SessionFactory getSessionFactory() { } - // /** - // * Return the ID for the entity or null - // * - // * @param entity - // * @return - // */ - // private ID getId(T entity) { - // ClassMetadata metadata = this.sessionFactory.getClassMetadata(entity.getClass()); - // if (metadata.hasIdentifierProperty()) { - // return (ID) metadata.getIdentifier(entity, (SessionImplementor) this.sessionFactory.getCurrentSession()); - // } - // return null; - // } - /** * Get the user id that is in the temporally table (permissions) * @@ -282,6 +313,31 @@ public long getTemTableUserId() { return idT; } + + // /** + // * Return the ID for the entity or null + // * + // * @param entity + // * @return + // */ + // private ID getId(T entity) { + // ClassMetadata metadata = this.sessionFactory.getClassMetadata(entity.getClass()); + // if (metadata.hasIdentifierProperty()) { + // return (ID) metadata.getIdentifier(entity, (SessionImplementor) this.sessionFactory.getCurrentSession()); + // } + // return null; + // } + + public Session openSessionIfNeeded() { + Session currentSession = sessionFactory.getCurrentSession(); + + if (currentSession == null || !currentSession.getTransaction().isActive()) { + return sessionFactory.openSession(); + } + + return currentSession; + } + /** * This method return a object result from the function. * @@ -304,6 +360,7 @@ private Object resultFunction(List> result) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity) { + System.out.println(" linea 335"); sessionFactory.getCurrentSession().persist(entity); return entity; } @@ -316,6 +373,7 @@ protected T saveEntity(T entity) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity, String actionName, List relationsName) { + System.out.println(" linea 348"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName); sessionFactory.getCurrentSession().persist(entity); return entity; @@ -329,6 +387,7 @@ protected T saveEntity(T entity, String actionName, List relationsName) * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity, String actionName, List relationsName, Phase phase) { + System.out.println(" linea 354"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName, phase); sessionFactory.getCurrentSession().persist(entity); return entity; @@ -341,6 +400,7 @@ protected T saveEntity(T entity, String actionName, List relationsName, * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity) { + System.out.println(" linea 367"); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; } @@ -353,6 +413,7 @@ protected T update(T entity) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity, String actionName, List relationsName) { + System.out.println(" linea 380"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; @@ -366,6 +427,7 @@ protected T update(T entity, String actionName, List relationsName) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity, String actionName, List relationsName, Phase phase) { + System.out.println(" linea 394"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName, phase); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; From 5026f266310ed2f68566a9ec96e8547ddbde71dd Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Fri, 26 Jul 2024 12:03:13 -0500 Subject: [PATCH 4/9] :sparkles: feat(Project): Modify classes of the marlo-data component, to adapt it to the new version of hibernate.aiccra-feature-A2-749-hibernate-new-version --- .../marlo/MarloDatabaseConfiguration.java | 6 +- .../data/dao/mysql/AbstractMarloDAO.java | 140 +++++------------- marlo-parent/pom.xml | 2 +- 3 files changed, 43 insertions(+), 105 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java index 888c4e356e..f4d5d03665 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/MarloDatabaseConfiguration.java @@ -31,15 +31,17 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; -import org.springframework.orm.hibernate4.HibernateTransactionManager; +import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; /** * Configuration for Database and Flyway beans. */ @Configuration +@EnableTransactionManagement public class MarloDatabaseConfiguration { /** @@ -100,7 +102,7 @@ public DataSource getDataSource() { private Properties hibernateProperties() { Properties props = new Properties(); - props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); + props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect"); if (Boolean.TRUE.equals(showSql)) { props.setProperty(AvailableSettings.SHOW_SQL, "true"); } diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index f74ae6aac5..396c445538 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -24,21 +24,23 @@ import java.util.Map; import org.hibernate.FlushMode; -import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.hibernate.Transaction; import org.hibernate.query.NativeQuery; import org.hibernate.query.Query; // import org.hibernate.Transaction; import org.hibernate.transform.AliasToEntityMapResultTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; /** * @author Christian David García O. - CIAT/CCAFS * @author Héctor F. Tobón R. - CIAT/CCAFS * @author Hermes Jimenez - CIAT/CCAFS */ +@Repository +@Transactional public abstract class AbstractMarloDAO { private static final Logger LOG = LoggerFactory.getLogger(AbstractMarloDAO.class); @@ -75,7 +77,6 @@ private void addAuditLogFieldsToThreadStorage(Object entity, String actionName, * @param obj is a persistence instance from the database model. */ protected void delete(Object obj) { - System.out.println(" linea 78"); this.sessionFactory.getCurrentSession().delete(obj); } @@ -84,30 +85,20 @@ protected void delete(Object obj) { * * @param sqlQuery is a string representing an SQL query. */ + + @Transactional public List> excuteStoreProcedure(String storeProcedure, String sqlQuery) { - System.out.println(" linea 87 excuteStoreProcedure "); - Session sesion = sessionFactory.openSession(); - System.out.println(" linea 89 excuteStoreProcedure "); - System.out.println(" linea 90 excuteStoreProcedure " + storeProcedure); - Transaction transaction = sesion.beginTransaction(); - NativeQuery> queryProcd = sesion.createSQLQuery(storeProcedure); - System.out.println(" linea 92 excuteStoreProcedure "); - // queryProcd.setFlushMode(FlushMode.COMMIT); - System.out.println(" linea 95 excuteStoreProcedure "); + System.out.println(" linea 91 " + storeProcedure); + System.out.println(" linea 92 " + sqlQuery); + NativeQuery> queryProcd = + this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); + queryProcd.setFlushMode(FlushMode.COMMIT); queryProcd.executeUpdate(); - NativeQuery> query = sesion.createSQLQuery(sqlQuery); - System.out.println(" linea 98 excuteStoreProcedure "); + NativeQuery> query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); - System.out.println(" linea 100 excuteStoreProcedure "); - // query.setFlushMode(FlushMode.COMMIT); - System.out.println(" linea 102 excuteStoreProcedure "); + query.setFlushMode(FlushMode.COMMIT); List> result = query.list(); - System.out.println(" linea 105 excuteStoreProcedure "); - transaction.commit(); - System.out.println(" linea 107 excuteStoreProcedure "); - sesion.close(); - System.out.println(" linea 109 excuteStoreProcedure "); return result; } @@ -127,7 +118,7 @@ public Object executeFunction(String function) { * @param sqlQuery */ public void executeUpdateQuery(String sqlQuery) { - System.out.println(" linea 130"); + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setFlushMode(FlushMode.COMMIT); query.executeUpdate(); @@ -159,31 +150,19 @@ public void executeUpdateQuery(String sqlQuery) { * @return the object populated. */ public T find(Class clazz, ID id) { - System.out.println(" linea 162"); - Session sesion = sessionFactory.openSession(); - Transaction transaction = sesion.beginTransaction(); - System.out.println(" linea 165"); - T obj = sesion.get(clazz, id); - - // committing the transaction - transaction.commit(); // Transaction is committed + T obj = sessionFactory.getCurrentSession().get(clazz, id); - - // closing the session - // sesion.close(); - System.out.println(" linea 173"); return obj; } + protected List findAll(Query hibernateQuery) { - System.out.println(" linea 177"); hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") List list = hibernateQuery.list(); return list; } - /** * This method make a query that returns a list of objects from the model. * This method was implemented in a generic way, so, the list of objects to be returned will depend on how the method @@ -197,11 +176,7 @@ protected List findAll(Query hibernateQuery) { * @return a list of objects. */ protected List findAll(String hibernateQuery) { - System.out.println(" linea 196"); - Session sesion = sessionFactory.openSession(); - Transaction transaction = sesion.beginTransaction(); - Query query = sesion.createQuery(hibernateQuery); - transaction.commit(); + Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); return this.findAll(query); } @@ -211,37 +186,28 @@ protected List findAll(String hibernateQuery) { * @param sqlQuery is a string representing an HQL query. */ public List> findCustomQuery(String sqlQuery) { - System.out.println(" linea 207"); - Session sesion = sessionFactory.openSession(); - Transaction transaction = sesion.beginTransaction(); - NativeQuery> query = sesion.createSQLQuery(sqlQuery); + + + NativeQuery> query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); query.setFlushMode(FlushMode.COMMIT); List> result = query.list(); - transaction.commit(); - System.out.println(" linea 218"); + return result; } protected List findEveryone(Class clazz) { - System.out.println(" linea 224"); - Session sesion = sessionFactory.openSession(); - Transaction transaction = sesion.beginTransaction(); - System.out.println(" linea 227"); - Query query = sesion.createQuery("from " + clazz.getName()); - System.out.println(" linea 229"); + Query query = sessionFactory.getCurrentSession().createQuery("from " + clazz.getName()); query.setHibernateFlushMode(FlushMode.COMMIT); - System.out.println(" linea 231"); + @SuppressWarnings("unchecked") List list = query.list(); - System.out.println(" linea 234"); - transaction.commit(); - System.out.println(" linea 236"); return list; } + /** * Allows clients to create the HibernateQuery and set parameters on it. * @@ -250,7 +216,6 @@ protected List findEveryone(Class clazz) { * @return */ protected T findSingleResult(Class clazz, Query hibernateQuery) { - System.out.println(" linea 251"); hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); T object = clazz.cast(hibernateQuery.uniqueResult()); return object; @@ -265,24 +230,12 @@ protected T findSingleResult(Class clazz, Query hibernateQuery) { * @return a Object of */ protected T findSingleResult(Class clazz, String hibernateQuery) { - System.out.println(" linea 266"); Query query = sessionFactory.getCurrentSession().createQuery(hibernateQuery); query.setHibernateFlushMode(FlushMode.COMMIT); return this.findSingleResult(clazz, query); } - public Session getCurrentSession() { - System.out.println(" linea 274"); - Session session = sessionFactory.getCurrentSession(); - - if (session == null || !session.isOpen()) { - session = sessionFactory.openSession(); - } - - return session; - } - /** * Return the sessionFactory. DAOs are free to get this and use it to perform custom queries. * @@ -293,6 +246,20 @@ SessionFactory getSessionFactory() { } + // /** + // * Return the ID for the entity or null + // * + // * @param entity + // * @return + // */ + // private ID getId(T entity) { + // ClassMetadata metadata = this.sessionFactory.getClassMetadata(entity.getClass()); + // if (metadata.hasIdentifierProperty()) { + // return (ID) metadata.getIdentifier(entity, (SessionImplementor) this.sessionFactory.getCurrentSession()); + // } + // return null; + // } + /** * Get the user id that is in the temporally table (permissions) * @@ -313,31 +280,6 @@ public long getTemTableUserId() { return idT; } - - // /** - // * Return the ID for the entity or null - // * - // * @param entity - // * @return - // */ - // private ID getId(T entity) { - // ClassMetadata metadata = this.sessionFactory.getClassMetadata(entity.getClass()); - // if (metadata.hasIdentifierProperty()) { - // return (ID) metadata.getIdentifier(entity, (SessionImplementor) this.sessionFactory.getCurrentSession()); - // } - // return null; - // } - - public Session openSessionIfNeeded() { - Session currentSession = sessionFactory.getCurrentSession(); - - if (currentSession == null || !currentSession.getTransaction().isActive()) { - return sessionFactory.openSession(); - } - - return currentSession; - } - /** * This method return a object result from the function. * @@ -360,7 +302,6 @@ private Object resultFunction(List> result) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity) { - System.out.println(" linea 335"); sessionFactory.getCurrentSession().persist(entity); return entity; } @@ -373,7 +314,6 @@ protected T saveEntity(T entity) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity, String actionName, List relationsName) { - System.out.println(" linea 348"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName); sessionFactory.getCurrentSession().persist(entity); return entity; @@ -387,7 +327,6 @@ protected T saveEntity(T entity, String actionName, List relationsName) * @return true if the the save/updated was successfully made, false otherwhise. */ protected T saveEntity(T entity, String actionName, List relationsName, Phase phase) { - System.out.println(" linea 354"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName, phase); sessionFactory.getCurrentSession().persist(entity); return entity; @@ -400,7 +339,6 @@ protected T saveEntity(T entity, String actionName, List relationsName, * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity) { - System.out.println(" linea 367"); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; } @@ -413,7 +351,6 @@ protected T update(T entity) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity, String actionName, List relationsName) { - System.out.println(" linea 380"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; @@ -427,7 +364,6 @@ protected T update(T entity, String actionName, List relationsName) { * @return true if the the save/updated was successfully made, false otherwhise. */ protected T update(T entity, String actionName, List relationsName, Phase phase) { - System.out.println(" linea 394"); this.addAuditLogFieldsToThreadStorage(entity, actionName, relationsName, phase); entity = (T) sessionFactory.getCurrentSession().merge(entity); return entity; diff --git a/marlo-parent/pom.xml b/marlo-parent/pom.xml index 718b9373da..cfafd752eb 100644 --- a/marlo-parent/pom.xml +++ b/marlo-parent/pom.xml @@ -12,7 +12,7 @@ UTF-8 5.5 - 5.4.10.Final + 5.4.30.Final 4.3.24.RELEASE 4.13.2 1.2.13 From e0bedca49a6b4af809d7a406c36b0f810fd1ba55 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Mon, 29 Jul 2024 10:17:14 -0500 Subject: [PATCH 5/9] :sparkles: feat(AbstractMarloDAO): Add control to validate the existence of the user permission table, before querying.aiccra-feature-A2-749-hibernate-new-version --- .../data/dao/mysql/AbstractMarloDAO.java | 106 ++++++++++++------ 1 file changed, 69 insertions(+), 37 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 396c445538..4f4765765a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -80,6 +80,30 @@ protected void delete(Object obj) { this.sessionFactory.getCurrentSession().delete(obj); } + /** + * Validate the existence of a given table + * + * @return validation result + */ + private boolean doesTableExist(String tableName) { + boolean exists = false; + String sql = ""; + + sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = :tableName"; + + try { + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql); + query.setParameter("tableName", tableName); + Long count = ((Number) query.uniqueResult()).longValue(); + + exists = count > 0; + } catch (Exception e) { + e.printStackTrace(); + } + + return exists; + } + /** * This method make a query that returns a not mapped object result from the model. * @@ -88,18 +112,20 @@ protected void delete(Object obj) { @Transactional public List> excuteStoreProcedure(String storeProcedure, String sqlQuery) { - System.out.println(" linea 91 " + storeProcedure); - System.out.println(" linea 92 " + sqlQuery); - NativeQuery> queryProcd = - this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); - queryProcd.setFlushMode(FlushMode.COMMIT); - queryProcd.executeUpdate(); - NativeQuery> query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); - query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); - query.setFlushMode(FlushMode.COMMIT); - - List> result = query.list(); - return result; + try { + NativeQuery> queryProcd = + this.sessionFactory.getCurrentSession().createSQLQuery(storeProcedure); + queryProcd.setFlushMode(FlushMode.COMMIT); + queryProcd.executeUpdate(); + NativeQuery> query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); + query.setFlushMode(FlushMode.COMMIT); + List> result = query.list(); + return result; + } catch (Exception e) { + System.out.println(" error " + e.getMessage()); + return null; + } } @@ -112,18 +138,6 @@ public Object executeFunction(String function) { return this.resultFunction(this.findCustomQuery(function)); } - /** - * Pass String based hibernate query. - * - * @param sqlQuery - */ - public void executeUpdateQuery(String sqlQuery) { - - NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); - query.setFlushMode(FlushMode.COMMIT); - query.executeUpdate(); - } - // // /** @@ -142,6 +156,19 @@ public void executeUpdateQuery(String sqlQuery) { // } + /** + * Pass String based hibernate query. + * + * @param sqlQuery + */ + public void executeUpdateQuery(String sqlQuery) { + + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); + query.setFlushMode(FlushMode.COMMIT); + query.executeUpdate(); + } + + /** * This method finds a specific record from the database and transform it to a database model object. * @@ -149,13 +176,13 @@ public void executeUpdateQuery(String sqlQuery) { * @param id is the record identifier. * @return the object populated. */ + @Transactional public T find(Class clazz, ID id) { T obj = sessionFactory.getCurrentSession().get(clazz, id); return obj; } - protected List findAll(Query hibernateQuery) { hibernateQuery.setHibernateFlushMode(FlushMode.COMMIT); @SuppressWarnings("unchecked") @@ -185,8 +212,8 @@ protected List findAll(String hibernateQuery) { * * @param sqlQuery is a string representing an HQL query. */ - public List> findCustomQuery(String sqlQuery) { + public List> findCustomQuery(String sqlQuery) { NativeQuery> query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); @@ -197,6 +224,7 @@ public List> findCustomQuery(String sqlQuery) { } + protected List findEveryone(Class clazz) { Query query = sessionFactory.getCurrentSession().createQuery("from " + clazz.getName()); query.setHibernateFlushMode(FlushMode.COMMIT); @@ -207,7 +235,6 @@ protected List findEveryone(Class clazz) { } - /** * Allows clients to create the HibernateQuery and set parameters on it. * @@ -221,6 +248,7 @@ protected T findSingleResult(Class clazz, Query hibernateQuery) { return object; } + /** * This method make a query that returns a single object result from the model. * This method was implemented in a generic way, so, the object to be returned will depend on how the method @@ -236,16 +264,6 @@ protected T findSingleResult(Class clazz, String hibernateQuery) { } - /** - * Return the sessionFactory. DAOs are free to get this and use it to perform custom queries. - * - * @return - */ - SessionFactory getSessionFactory() { - return this.sessionFactory; - } - - // /** // * Return the ID for the entity or null // * @@ -260,6 +278,15 @@ SessionFactory getSessionFactory() { // return null; // } + /** + * Return the sessionFactory. DAOs are free to get this and use it to perform custom queries. + * + * @return + */ + SessionFactory getSessionFactory() { + return this.sessionFactory; + } + /** * Get the user id that is in the temporally table (permissions) * @@ -267,6 +294,11 @@ SessionFactory getSessionFactory() { */ public long getTemTableUserId() { long idT = -1; + + if (!this.doesTableExist("user_permission")) { + return idT; + } + StringBuilder builder = new StringBuilder(); builder.append("select DISTINCT id as idT from user_permission"); try { From 7d9a9079c4203a8e90c2b83cb8203046cf107be1 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Mon, 29 Jul 2024 15:44:39 -0500 Subject: [PATCH 6/9] :sparkles: feat(AbstractMarloDAO): Add control to validate if table auditlog has errors.aiccra-feature-A2-749-hibernate-new-version" --- .../data/dao/mysql/AbstractMarloDAO.java | 44 +++++++++++++++++-- .../data/dao/mysql/AuditLogMySQLDao.java | 32 +++++++++----- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 4f4765765a..6b52928143 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -123,7 +123,7 @@ public List> excuteStoreProcedure(String storeProcedure, Str List> result = query.list(); return result; } catch (Exception e) { - System.out.println(" error " + e.getMessage()); + LOG.error(" error " + e.getMessage()); return null; } @@ -296,6 +296,7 @@ public long getTemTableUserId() { long idT = -1; if (!this.doesTableExist("user_permission")) { + LOG.info(" the table user_permission does not exist yet"); return idT; } @@ -312,6 +313,44 @@ public long getTemTableUserId() { return idT; } + /** + * Validates if the table presents an error in its integrity + * + * @return validation result + */ + public boolean isTableInGoodCondition(String tableName) { + String sql = "CHECK TABLE " + tableName; + + try { + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql); + List results = (List) query.list(); + + for (Object[] row : results) { + String table = (String) row[0]; + String operation = (String) row[1]; + String messageType = (String) row[2]; + String messageText = (String) row[3]; + + LOG.info("Table: " + table); + LOG.info("Operation: " + operation); + LOG.info("Message Type: " + messageType); + LOG.info("Message Text: " + messageText); + + if ("status".equals(messageType) && "OK".equals(messageText)) { + return true; + } else if ("error".equals(messageType)) { + LOG.error("Error with table: " + messageText); + return false; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + + /** * This method return a object result from the function. * @@ -326,7 +365,6 @@ private Object resultFunction(List> result) { return null; } - /** * This method saves or update a record into the database. * @@ -388,6 +426,7 @@ protected T update(T entity, String actionName, List relationsName) { return entity; } + /** * This method saves or update a record into the database. * @@ -401,5 +440,4 @@ protected T update(T entity, String actionName, List relationsName, Phas return entity; } - } \ No newline at end of file diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java index ca15fd4ed2..2927008d31 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java @@ -196,19 +196,31 @@ public List getHistoryBeforeList(String transactionID, String classNam @Override public List listLogs(Class classAudit, long id, String actionName, Long phaseId) { + try { + + + if (!super.isTableInGoodCondition("auditlog")) { + System.out.println("The table is not in good condition"); + return null; + } - List auditLogs = super.findAll("from " + Auditlog.class.getName() + " where ENTITY_NAME='class " - + classAudit.getName() + "' and ENTITY_ID=" + id + " and main=1 and id_phase=" + phaseId - + " and DETAIL like 'Action: " + actionName + "%' order by CREATED_DATE desc "); - // " and principal=1 order by CREATED_DATE desc LIMIT 10"); - for (Auditlog auditlog : auditLogs) { - auditlog.setUser(userDao.getUser(auditlog.getUserId())); - } - if (auditLogs.size() > 11) { - return auditLogs.subList(0, 11); + List auditLogs = super.findAll("from " + Auditlog.class.getName() + " where ENTITY_NAME='class " + + classAudit.getName() + "' and ENTITY_ID=" + id + " and main=1 and id_phase=" + phaseId + + " and DETAIL like 'Action: " + actionName + "%' order by CREATED_DATE desc "); + // " and principal=1 order by CREATED_DATE desc LIMIT 10"); + for (Auditlog auditlog : auditLogs) { + auditlog.setUser(userDao.getUser(auditlog.getUserId())); + } + + if (auditLogs.size() > 11) { + return auditLogs.subList(0, 11); + } + return auditLogs; + } catch (Exception e) { + System.out.println("Error in listLogs function " + e.getMessage()); + return null; } - return auditLogs; } From 59f6a9e7c59c691bd2f64d7bc6307a6249591a71 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Mon, 29 Jul 2024 16:32:53 -0500 Subject: [PATCH 7/9] :sparkles: feat(AbstractMarloDAO): Improve query used to validate auditlog table status.aiccra-feature-A2-749-hibernate-new-version\ --- .../ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java | 11 +++++------ .../ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 6b52928143..075177a890 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -85,18 +85,17 @@ protected void delete(Object obj) { * * @return validation result */ - private boolean doesTableExist(String tableName) { + public boolean doesTableExist(String tableName) { boolean exists = false; String sql = ""; - sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = :tableName"; + sql = "SELECT 1 FROM information_schema.tables WHERE table_name = :tableName LIMIT 1"; try { - NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql); + NativeQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("tableName", tableName); - Long count = ((Number) query.uniqueResult()).longValue(); - - exists = count > 0; + Object result = query.uniqueResult(); + exists = result != null; } catch (Exception e) { e.printStackTrace(); } diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java index 2927008d31..f5042a2312 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AuditLogMySQLDao.java @@ -199,7 +199,7 @@ public List listLogs(Class classAudit, long id, String actionName, try { - if (!super.isTableInGoodCondition("auditlog")) { + if (!super.doesTableExist("auditlog")) { System.out.println("The table is not in good condition"); return null; } From 8626a3b21178b52dfe8f64256352b0ed4e7d0d56 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Wed, 31 Jul 2024 09:16:21 -0500 Subject: [PATCH 8/9] :recycle: refactor(AbstractMarloDAO): Remove Hibernate related transactional annotations.aiccra-feature-A2-749-hibernate-new-version --- .../cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java | 6 ------ marlo-parent/pom.xml | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java index 075177a890..4f44190010 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/AbstractMarloDAO.java @@ -31,16 +31,12 @@ import org.hibernate.transform.AliasToEntityMapResultTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; /** * @author Christian David García O. - CIAT/CCAFS * @author Héctor F. Tobón R. - CIAT/CCAFS * @author Hermes Jimenez - CIAT/CCAFS */ -@Repository -@Transactional public abstract class AbstractMarloDAO { private static final Logger LOG = LoggerFactory.getLogger(AbstractMarloDAO.class); @@ -109,7 +105,6 @@ public boolean doesTableExist(String tableName) { * @param sqlQuery is a string representing an SQL query. */ - @Transactional public List> excuteStoreProcedure(String storeProcedure, String sqlQuery) { try { NativeQuery> queryProcd = @@ -175,7 +170,6 @@ public void executeUpdateQuery(String sqlQuery) { * @param id is the record identifier. * @return the object populated. */ - @Transactional public T find(Class clazz, ID id) { T obj = sessionFactory.getCurrentSession().get(clazz, id); diff --git a/marlo-parent/pom.xml b/marlo-parent/pom.xml index cfafd752eb..597461eda1 100644 --- a/marlo-parent/pom.xml +++ b/marlo-parent/pom.xml @@ -12,7 +12,7 @@ UTF-8 5.5 - 5.4.30.Final + 5.4.33.Final 4.3.24.RELEASE 4.13.2 1.2.13 From 2f7619c02d0c41f4def26b738cb4ad82c44429c5 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Wed, 31 Jul 2024 11:16:09 -0500 Subject: [PATCH 9/9] :recycle: refactor(DeliverableAction): Improve the performance of the function to obtain duplicates.aiccra-feature-A2-749-hibernate-new-version --- .../ccafs/marlo/data/dao/DeliverableDAO.java | 20 ++++++++ .../data/dao/mysql/DeliverableMySQLDAO.java | 48 +++++++++++++++++++ .../data/manager/DeliverableManager.java | 21 ++++++++ .../manager/impl/DeliverableManagerImpl.java | 7 +++ .../action/projects/DeliverableAction.java | 8 ++-- 5 files changed, 101 insertions(+), 3 deletions(-) diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java index 1c3a7590ee..ef86b8b000 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java @@ -144,8 +144,28 @@ List getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String List getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId, long projectId); + /** + * Get listing to validate duplicate information (dissemination_URL,DIO, handle) + * + * @author IBD + * @param phase phase of the project + * @return deliverable list with the data to validate duplicates (dissemination_URL,DIO, handle) + */ List getDuplicatesDeliverablesByPhase(long phase); + /** + * Get listing to validate duplicate information (dissemination_URL,DIO, handle) + * + * @author IBD + * @param phase phase of the project + * @param DOI DOI + * @param handle + * @param disseminationURL url of dissemination + * @return deliverable list with the data to validate duplicates (dissemination_URL,DIO, handle) + */ + List getDuplicatesDeliverablesByPhaseWithDissemination(long phase, String DOI, String handle, + String disseminationURL); + public List getPublicationsByPhase(long phase); /** diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java index 704a65e70d..44d9877719 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java @@ -633,6 +633,54 @@ public List getDuplicatesDeliverablesByPhase(long phase) { return deliverables; } + @Override + public List getDuplicatesDeliverablesByPhaseWithDissemination(long phase, String DOI, String handle, + String disseminationURL) { + StringBuilder query = new StringBuilder(); + query.append("select id, dissemination_URL from ( SELECT DISTINCT "); + query.append("d.id as id,"); + query.append("dv.dissemination_URL as dissemination_URL "); + query.append("FROM "); + query.append("deliverables AS d "); + query.append("INNER JOIN deliverable_dissemination AS dv ON d.id = dv.deliverable_id "); + query.append("INNER JOIN deliverables_info AS di ON d.id = di.deliverable_id "); + query.append(" WHERE di.is_active =1 "); + query.append(" and d.is_active = di.is_active "); + query.append(" and di.id_phase=" + phase); + query.append(" and dv.dissemination_URL is not null"); + query.append(" and length(dissemination_URL)>0"); + query.append(" UNION "); + query.append("SELECT DISTINCT "); + query.append("d.id as id,"); + query.append("dme.element_value as dissemination_URL "); + query.append("FROM "); + query.append("deliverables AS d "); + query.append("INNER JOIN deliverable_metadata_elements AS dme ON d.id = dme.deliverable_id "); + query.append("INNER JOIN deliverables_info AS di ON d.id = di.deliverable_id "); + query.append(" where dme.element_id in(35,36) "); + query.append(" and di.is_active =1 "); + query.append(" and d.is_active = di.is_active "); + query.append(" and di.id_phase=" + phase); + query.append(" and element_value is not null"); + query.append(" and length(element_value)>0 )t "); + query.append(" where ( dissemination_URL ='" + DOI + "'"); + query.append(" or dissemination_URL ='" + handle + "'"); + query.append(" or dissemination_URL ='" + disseminationURL + "')"); + + + List> rList = super.findCustomQuery(query.toString()); + List deliverables = new ArrayList<>(); + + if (rList != null) { + for (Map map : rList) { + String tmp = map.get("id").toString() + "|" + map.get("dissemination_URL").toString(); + deliverables.add(tmp); + } + } + + return deliverables; + } + @Override public List getPublicationsByPhase(long phase) { StringBuilder query = new StringBuilder(); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java index 00c2956242..4002817c4f 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java @@ -158,9 +158,30 @@ List getDeliverablesLeadByUserAndProjectWithSimpleConditions(lon public List getDeliverablesList(LiaisonInstitution liaisonInstitution, Phase phase); + /** + * Get listing to validate duplicate information (dissemination_URL,DIO, handle) + * + * @author IBD + * @param phase phase of the project + * @return deliverable list with the data to validate duplicates (dissemination_URL,DIO, handle) + */ List getDuplicatesDeliverablesByPhase(long phase); + /** + * Get listing to validate duplicate information (dissemination_URL,DIO, handle) + * + * @author IBD + * @param phase phase of the project + * @param DOI DOI + * @param handle + * @param disseminationURL url of dissemination + * @return deliverable list with the data to validate duplicates (dissemination_URL,DIO, handle) + */ + List getDuplicatesDeliverablesByPhaseWithDissemination(long phase, String DOI, String handle, + String disseminationURL); + + public List getNotPublicationsList(LiaisonInstitution liaisonInstitution, Phase phase); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java index 3ec09d8afb..0a42697b74 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java @@ -342,6 +342,13 @@ public List getDuplicatesDeliverablesByPhase(long phase) { return deliverableDAO.getDuplicatesDeliverablesByPhase(phase); } + + @Override + public List getDuplicatesDeliverablesByPhaseWithDissemination(long phase, String DOI, String handle, + String disseminationURL) { + return deliverableDAO.getDuplicatesDeliverablesByPhaseWithDissemination(phase, DOI, handle, disseminationURL); + } + /** * Method to fill the list of deliverables (only publications or only Grey literature, depending on the * getPublications parameter), selected by flagships. diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java index a3950e9cb6..1169a0565f 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java @@ -2304,7 +2304,8 @@ public void prepare() throws Exception { List deliverables = null; try { // cgamboa change is made to obtain deliverables only for the phase 08/04/2024 - deliverables = deliverableManager.getDuplicatesDeliverablesByPhase(this.getActualPhase().getId()); + deliverables = deliverableManager.getDuplicatesDeliverablesByPhaseWithDissemination( + this.getActualPhase().getId(), DOI, handle, disseminationURL); // deliverableDTOs = this.getDuplicatedDeliverableInformation(DOI, handle, disseminationURL, deliverableID); deliverableDTOs = this.getDuplicatedDeliverableInformationNew(DOI, handle, disseminationURL, deliverableID, deliverables); @@ -3701,7 +3702,8 @@ public void saveDuplicated() { try { List deliverables = null; // cgamboa change is made to obtain deliverables only for the phase 08/04/2024 - deliverables = deliverableManager.getDuplicatesDeliverablesByPhase(this.getActualPhase().getId()); + deliverables = deliverableManager.getDuplicatesDeliverablesByPhaseWithDissemination( + this.getActualPhase().getId(), DOI, handle, disseminationURL); // deliverableDTOs = this.getDuplicatedDeliverableInformation(DOI, handle, disseminationURL, deliverableID); deliverableDTOs = this.getDuplicatedDeliverableInformationNew(DOI, handle, disseminationURL, deliverableID, deliverables); @@ -3718,7 +3720,7 @@ public void saveDuplicated() { deliverableInfoManager.saveDeliverableInfo(deliverableBase.getDeliverableInfo()); } } catch (Exception e) { - logger.error("unable to get duplivated deliverables", e); + logger.error("unable to get duplicated deliverables", e); }