← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10498: Only validate duplicate names of program stage section on one program stage.

 

------------------------------------------------------------
revno: 10498
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-08 16:24:43 +0700
message:
  Only validate duplicate names of program stage section on one program stage.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageSectionStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageSectionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageSectionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageSectionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageSectionForm.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionService.java	2013-02-04 03:09:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionService.java	2013-04-08 09:24:43 +0000
@@ -28,6 +28,7 @@
 package org.hisp.dhis.program;
 
 import java.util.Collection;
+import java.util.List;
 
 /**
  * @author Chau Thu Tran
@@ -50,7 +51,9 @@
     
     ProgramStageSection getProgramStageSection( int id );
     
-    ProgramStageSection getProgramStageSectionByName( String name );
+    List<ProgramStageSection> getProgramStageSectionByName( String name );
+    
+    ProgramStageSection getProgramStageSectionByName( String name, ProgramStage programStage );
     
     Collection<ProgramStageSection> getAllProgramStageSections();
     

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageSectionStore.java	2013-04-08 09:24:43 +0000
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program;
+
+import org.hisp.dhis.common.GenericNameableObjectStore;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ ProgramStageSectionStore.java Apr 8, 2013 3:48:37 PM $
+ */
+public interface ProgramStageSectionStore
+    extends GenericNameableObjectStore<ProgramStageSection>
+{
+    ProgramStageSection getByNameAndProgramStage( String name, ProgramStage programStage );
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageSectionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageSectionService.java	2013-02-04 03:09:04 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageSectionService.java	2013-04-08 09:24:43 +0000
@@ -30,8 +30,8 @@
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.Collection;
+import java.util.List;
 
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.i18n.I18nService;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -48,10 +48,9 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private GenericIdentifiableObjectStore<ProgramStageSection> programStageSectionStore;
+    private ProgramStageSectionStore programStageSectionStore;
 
-    public void setProgramStageSectionStore(
-        GenericIdentifiableObjectStore<ProgramStageSection> programStageSectionStore )
+    public void setProgramStageSectionStore( ProgramStageSectionStore programStageSectionStore )
     {
         this.programStageSectionStore = programStageSectionStore;
     }
@@ -92,9 +91,9 @@
     }
 
     @Override
-    public ProgramStageSection getProgramStageSectionByName( String name )
+    public List<ProgramStageSection> getProgramStageSectionByName( String name )
     {
-        return i18n( i18nService, programStageSectionStore.getByName( name ) );
+        return programStageSectionStore.getAllEqName( name );
     }
 
     @Override
@@ -102,11 +101,16 @@
     {
         return i18n( i18nService, programStageSectionStore.getAll() );
     }
-    
+
     @Override
     public Collection<ProgramStageSection> getProgramStages( ProgramStage programStage )
     {
         return i18n( i18nService, programStage.getProgramStageSections() );
     }
-    
+
+    @Override
+    public ProgramStageSection getProgramStageSectionByName( String name, ProgramStage programStage )
+    {
+        return i18n( i18nService, programStageSectionStore.getByNameAndProgramStage( name, programStage ) );
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageSectionStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageSectionStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageSectionStore.java	2013-04-08 09:24:43 +0000
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.program.hibernate;
+
+import org.hibernate.Criteria;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageSection;
+import org.hisp.dhis.program.ProgramStageSectionStore;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ HibernateProgramStageStore.java Apr 8, 2013 1:30:00 PM $
+ */
+public class HibernateProgramStageSectionStore
+    extends HibernateIdentifiableObjectStore<ProgramStageSection>
+    implements ProgramStageSectionStore
+{
+    // -------------------------------------------------------------------------
+    // Dependency
+    // -------------------------------------------------------------------------
+
+    @Override
+    public ProgramStageSection getByNameAndProgramStage( String name, ProgramStage programStage )
+    {
+        Criteria criteria = getCriteria( Restrictions.eq( "name", name ) );
+        criteria.createAlias( "programStageDataElements", "programStageDataElement" );
+        criteria.add( Restrictions.eq( "programStageDataElement.programStage", programStage ) );
+        
+        return (ProgramStageSection) criteria.uniqueResult();
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 08:33:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 09:24:43 +0000
@@ -58,7 +58,7 @@
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramStageSectionStore" 
-		class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+		class="org.hisp.dhis.program.hibernate.HibernateProgramStageSectionStore">
 		<property name="clazz" value="org.hisp.dhis.program.ProgramStageSection" />
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageSectionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageSectionAction.java	2012-08-24 10:09:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/ValidateProgramStageSectionAction.java	2013-04-08 09:24:43 +0000
@@ -28,8 +28,10 @@
  */
 
 import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageSection;
 import org.hisp.dhis.program.ProgramStageSectionService;
+import org.hisp.dhis.program.ProgramStageService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -53,10 +55,24 @@
         this.programStageSectionService = programStageSectionService;
     }
 
+    private ProgramStageService programStageService;
+
+    public void setProgramStageService( ProgramStageService programStageService )
+    {
+        this.programStageService = programStageService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
 
+    private Integer programStageId;
+
+    public void setProgramStageId( Integer programStageId )
+    {
+        this.programStageId = programStageId;
+    }
+
     private Integer id;
 
     public void setId( Integer id )
@@ -92,11 +108,13 @@
     public String execute()
         throws Exception
     {
-        ProgramStageSection match = programStageSectionService.getProgramStageSectionByName( name );
+        ProgramStage progamStage = programStageService.getProgramStage( programStageId );
+        
+        ProgramStageSection match = programStageSectionService.getProgramStageSectionByName( name, progamStage );
 
         if ( match != null && (id == null || match.getId() != id.intValue()) )
         {
-            message = i18n.getString( "duplicate_names" );
+            message = i18n.getString( "name_exists" );
 
             return ERROR;
         }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 08:33:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-08 09:24:43 +0000
@@ -370,6 +370,8 @@
 		scope="prototype">
 		<property name="programStageSectionService"
 			ref="org.hisp.dhis.program.ProgramStageSectionService" />
+		<property name="programStageService"
+			ref="org.hisp.dhis.program.ProgramStageService" />
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageSectionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageSectionForm.vm	2013-02-28 07:59:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageSectionForm.vm	2013-04-08 09:24:43 +0000
@@ -9,7 +9,7 @@
 			setFieldValue('hasDataElement', 'true');
 		}
 	});
-	checkValueIsExist( "name", "validateProgramStageSection.action");
+	checkValueIsExist( "name", "validateProgramStageSection.action",{programStageId:getFieldValue('programStageId')});
 	byId('name').focus();
 });
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageSectionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageSectionForm.vm	2013-02-28 07:59:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageSectionForm.vm	2013-04-08 09:24:43 +0000
@@ -10,7 +10,7 @@
 		}
 	});
 		
-	checkValueIsExist( "name", "validateProgramStageSection.action", {id:getFieldValue('id')});	
+	checkValueIsExist( "name", "validateProgramStageSection.action", {id:getFieldValue('id'),programStageId:getFieldValue('programStageId')});	
 	byId('name').focus();
 });
 </script>