1
package org.hisp.dhis.oum.action.organisationunitgroup;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.Collection;
32
import org.hisp.dhis.i18n.I18n;
33
import org.hisp.dhis.organisationunit.OrganisationUnit;
34
import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
35
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
36
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
37
import org.hisp.dhis.oust.manager.SelectionTreeManager;
39
import com.opensymphony.xwork.ActionSupport;
42
* @author Torgeir Lorange Ostby
43
* @version $Id: ValidateOrganisationUnitGroupAction.java 1898 2006-09-22 12:06:56Z torgeilo $
45
public class ValidateOrganisationUnitGroupAction
48
// -------------------------------------------------------------------------
50
// -------------------------------------------------------------------------
54
public void setI18n( I18n i18n )
59
private OrganisationUnitGroupService organisationUnitGroupService;
61
public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
63
this.organisationUnitGroupService = organisationUnitGroupService;
66
private SelectionTreeManager selectionTreeManager;
68
public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
70
this.selectionTreeManager = selectionTreeManager;
73
// -------------------------------------------------------------------------
75
// -------------------------------------------------------------------------
79
public void setId( Integer id )
86
public void setName( String name )
91
// -------------------------------------------------------------------------
93
// -------------------------------------------------------------------------
95
private String message;
97
public String getMessage()
102
// -------------------------------------------------------------------------
103
// Action implementation
104
// -------------------------------------------------------------------------
106
public String execute()
108
// ---------------------------------------------------------------------
110
// ---------------------------------------------------------------------
114
message = i18n.getString( "please_specify_a_name" );
122
if ( name.length() == 0 )
124
message = i18n.getString( "please_specify_a_name" );
129
OrganisationUnitGroup match = organisationUnitGroupService.getOrganisationUnitGroupByName( name );
131
if ( match != null && (id == null || match.getId() != id) )
133
message = i18n.getString( "name_is_already_in_use" );
139
// ---------------------------------------------------------------------
140
// When updating a group which is a member of an exclusive group set,
141
// any selected units can not be a member of another group in the
143
// ---------------------------------------------------------------------
145
// No need to check this if it's a new organisations group.
148
message = "Everything's ok";
153
OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService.getOrganisationUnitGroup( id
156
Collection<OrganisationUnitGroupSet> exclusiveGroupSets = organisationUnitGroupService
157
.getExclusiveOrganisationUnitGroupSetsContainingGroup( organisationUnitGroup );
159
if ( exclusiveGroupSets != null && exclusiveGroupSets.size() > 0 )
161
Collection<OrganisationUnit> selectedUnits = selectionTreeManager.getSelectedOrganisationUnits();
163
for ( OrganisationUnitGroupSet groupSet : exclusiveGroupSets )
165
for ( OrganisationUnitGroup group : groupSet.getOrganisationUnitGroups() )
167
for ( OrganisationUnit unit : selectedUnits )
169
if ( group.getMembers().contains( unit ) && group.getId() != id )
171
message = unit.getShortName() + " "
172
+ i18n.getString( "can_not_be_a_member_because_member_of" ) + " " + group.getName()
173
+ " " + i18n.getString( "which_is_a_member_of_the_same_exclusive_group_set" ) + " "
174
+ groupSet.getName() + " " + i18n.getString( "as_the_current_group" );
183
message = "Everything's ok";