[elvystrac] r1862 - BL for elvys updated:

  • From: elvys@xxxxxxxxxxxxxxxxxxxxxx
  • To: elvystrac@xxxxxxxxxxxxx
  • Date: Thu, 25 Feb 2010 06:55:44 +0100

Author: DavidK
Date: 2010-02-25 06:55:43 +0100 (Thu, 25 Feb 2010)
New Revision: 1862

Modified:
   trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBL.java
   trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImpl.java
   trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImplTest.java
Log:
BL for elvys updated:
1) loading elvyses having assigned the selected CatDef
2) loading elvyses having planned the selected file on

Modified: trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBL.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBL.java 
2010-02-24 23:33:58 UTC (rev 1861)
+++ trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBL.java 
2010-02-25 05:55:43 UTC (rev 1862)
@@ -72,6 +72,7 @@
        public List<Elvys> listAllElvyses()  throws ExecuteException;
        
        
+       
        /**
         * Loads list of <b>company related</b> Elvyses from DB. <br/>
         * Method for admin and user role. <br/>
@@ -97,7 +98,41 @@
         */
        public List<Elvys> listElvysesByCategoryPlanning(Integer catPlanId, 
Session sess) throws ExecuteException;
        
+       
        /**
+        * Loads elvyses that is given category assigned to. <br/>
+        * Fetches: ElvysGroup, Company, ElvysSetting, Resolution <br/>
+        * Restriction: elvys.disabled = 0, category.disabled = 0, 
group.disabled = 0
+        * @param catDefId id of category definition 
+        * @return List of elvyses
+        * @throws Exception when error
+        */
+       public List<Elvys> listElvysesByCatDefMakeSession(Integer catDefId) 
throws Exception;
+       
+       /**
+        * @see ElvysBL#listElvysesByCatDefMakeSession(Integer)
+        */
+       public List<Elvys> listElvysesByCatDef(Integer catDefId, Session sess) 
throws Exception;
+       
+       
+       
+       /**
+        * Loads elvyses that contain planning of given file. <br/>
+        * Fetches: ElvysGroup, Company, ElvysSetting, Resolution <br/>
+        * Restriction: elvys.disabled = 0, category.disabled = 0, 
group.disabled = 0
+        * @param fileId id of category definition 
+        * @return List of elvyses
+        * @throws Exception when error
+        */
+       public List<Elvys> listElvysesByFileMakeSession(Integer fileId) throws 
Exception;
+       
+       /**
+        * @see ElvysBL#listElvysesByFileMakeSession(Integer)
+        */
+       public List<Elvys> listElvysesByFile(Integer fileId, Session sess) 
throws Exception;
+       
+       
+       /**
         * @param elvysId
         * Deletes selected elvys.
         * Not supported yet.

Modified: 
trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImpl.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImpl.java     
2010-02-24 23:33:58 UTC (rev 1861)
+++ trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImpl.java     
2010-02-25 05:55:43 UTC (rev 1862)
@@ -232,9 +232,100 @@
                return elvyses;
        }
 
+       @Override
+       public List<Elvys> listElvysesByCatDefMakeSession(Integer catDefId)
+                       throws Exception {
+               Session sess = 
InitSessionFactory.getInstance().getCurrentSession();
+               Transaction tx = HibUtils.startTx(sess);
+               List<Elvys> elvyses = null;
+               try {
+                       elvyses = listElvysesByCatDef(catDefId, sess);
+                       tx.commit();
+               } catch(Exception e) {
+                       tx.rollback();
+                       throw new ExecuteException(e);
+               }
+               return elvyses;
+       }
+
        
-
        @Override
+       public List<Elvys> listElvysesByCatDef(Integer catDefId, Session sess)
+                       throws Exception {
+               List<Elvys> elvyses = null;
+               try {
+                       Query q = sess.createQuery("select elvys from Elvys as 
elvys, " +
+                                       "Category cat, " +
+                                       "CategoryDefinition cd " +
+                                       "inner join fetch elvys.elvysGroup eg " 
+
+                                       "inner join fetch elvys.company " +
+                                       "inner join fetch elvys.elvysSetting " +
+                                       "inner join fetch elvys.resolution " +
+                                       "where elvys.disabled = false " +
+                                       "  and eg.disabled = false " +
+                                       "  and cat.disabled = false " +
+                                       "   and elvys.elvysGroup = eg.id " +
+                                       "   and eg.id = cat.elvysGroup " +
+                                       "   and cat.categoryDefinition = cd.id 
" +
+                                       "   and cd.id = :cdId");
+                       q.setInteger("cdId", catDefId);
+                       elvyses = q.list();
+               } catch(Exception e) {
+                       String message = 
CommonUtils.prepareErrorMessage(ERROR_LOAD_ELVYSES
+                                       ,"catDefId", catDefId);
+                       throw new ExecuteException(message, e);
+               }
+               return elvyses;
+       }
+       
+       @Override
+       public List<Elvys> listElvysesByFileMakeSession(Integer fileId)
+                       throws Exception {
+               Session sess = 
InitSessionFactory.getInstance().getCurrentSession();
+               Transaction tx = HibUtils.startTx(sess);
+               List<Elvys> elvyses = null;
+               try {
+                       elvyses = listElvysesByFile(fileId, sess);
+                       tx.commit();
+               } catch(Exception e) {
+                       tx.rollback();
+                       throw new ExecuteException(e);
+               }
+               return elvyses;
+       }
+       
+       
+       @Override
+       public List<Elvys> listElvysesByFile(Integer fileId, Session sess)
+                       throws Exception {
+               List<Elvys> elvyses = null;
+               try {
+                       Query q = sess.createQuery("select elvys from Elvys as 
elvys, " +
+                                       "Category cat, " +
+                                       "Timeline tl, " +
+                                       "FileFrameContent ffc " +
+                                       "inner join fetch elvys.elvysGroup eg " 
+
+                                       "inner join fetch elvys.company " +
+                                       "inner join fetch elvys.elvysSetting " +
+                                       "inner join fetch elvys.resolution " +
+                                       "where elvys.disabled = false " +
+                                       "  and eg.disabled = false " +
+                                       "  and cat.disabled = false " +
+                                       "   and elvys.elvysGroup = 
cat.elvysGroup " +
+                                       "   and cat.categoryPlanning = 
tl.panel.id.planning " +
+                                       "   and tl.frameContent = ffc.id " +
+                                       "   and ffc.file = :fileId ");
+                       q.setInteger("fileId", fileId);
+                       elvyses = q.list();
+               } catch(Exception e) {
+                       String message = 
CommonUtils.prepareErrorMessage(ERROR_LOAD_ELVYSES
+                                       ,"fileId", fileId);
+                       throw new ExecuteException(message, e);
+               }
+               return elvyses;
+       }
+       
+       @Override
        public void setActiveState(Integer elvysId, boolean boolValue) throws 
ExecuteException {
                if(elvysId == null) {
                        throw new NullPointerException("elvysId");

Modified: 
trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImplTest.java
===================================================================
--- trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImplTest.java 
2010-02-24 23:33:58 UTC (rev 1861)
+++ trunk/server/elvysCommons/src/elvys/server/bl/elvysrel/ElvysBLImplTest.java 
2010-02-25 05:55:43 UTC (rev 1862)
@@ -1,24 +1,22 @@
 package elvys.server.bl.elvysrel;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.util.List;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 import cz.elvys.webServer.HIBgen.Category;
-import cz.elvys.webServer.HIBgen.Company;
+import cz.elvys.webServer.HIBgen.CategoryDefinition;
 import cz.elvys.webServer.HIBgen.Elvys;
 import cz.elvys.webServer.HIBgen.ElvysGroup;
-import cz.elvys.webServer.HIBgen.ElvysSetting;
-import cz.elvys.webServer.HIBgen.Resolution;
-import cz.elvys.webServer.db.InitSessionFactory;
+import cz.elvys.webServer.HIBgen.File;
+import cz.elvys.webServer.HIBgen.FileType;
 import elvys.server.bl.Fact;
 import elvys.server.bl.categrel.CategoryBL;
+import elvys.server.bl.file.FileManagerBL;
 
 public class ElvysBLImplTest {
        
@@ -31,11 +29,13 @@
        // static fields
        private static ElvysBL ebl;
        private static CategoryBL cbl;
+       private static FileManagerBL fbl;
        
        @BeforeClass
        public static void init() {
                ebl = Fact.getElvysBL();
                cbl = Fact.getCategoryBL();
+               fbl = Fact.getFileManagerBL();
        }
        
        @Test
@@ -104,12 +104,53 @@
                                found+= elvyses.size();
                        }
                }
+               assertTrue(found >0);
+       }
+       
+       
+       @Test
+       public void testListElvysesByCatDef() throws Exception {
+               // count of found elvyses (by catdef id)
+               int found = 0;
                
+               List<CategoryDefinition> cds = 
cbl.listCatDefinitionsOfCompanyMakeSession(companyId);
+               
+               for(CategoryDefinition cd: cds) {
+                       Integer cdid = cd.getId();
+                       
+                       // elvyses
+                       List<Elvys> elvyses = 
ebl.listElvysesByCatDefMakeSession(cdid);
+                       assertElvysesEmtyable(elvyses);
+                       found+= elvyses.size();
+               }
                assertTrue(found >0);
+       }
+       
+       @Test
+       public void testListElvysesByFile() throws Exception {
+               // count of found elvyses (by fileId)
+               int found = 0;
                
+               // file types
+               List<FileType> types = 
fbl.listCompanyAllowedFileTypesMakeSession(companyId);
+               // files
+               List<File> files = fbl.listFilesOfCompany(companyId, types);
+               
+               
+               for(File file: files) {
+                       Integer fileId = file.getId();
+                       
+                       // elvyses
+                       List<Elvys> elvyses = 
ebl.listElvysesByFileMakeSession(fileId);
+                       assertElvysesEmtyable(elvyses);
+                       found+= elvyses.size();
+               }
+               assertTrue(found >0);
+               
+               
+               
        }
        
-       
        @Test
        public void testGetElvysById() throws Exception{
                // list of all elvyses
@@ -220,6 +261,14 @@
                        assertElvys(elv);
                }
        }
+       
+       private void assertElvysesEmtyable(List<Elvys> elvyses) {
+               assertTrue(elvyses != null);
+               for (Elvys elv: elvyses) {
+                       assertElvys(elv);
+               }
+       }
+       
        private void assertElvys(Elvys elv) {
                assertTrue(elv != null);
                assertFalse(elv.isDisabled());


Other related posts:

  • » [elvystrac] r1862 - BL for elvys updated: - elvys