Changeset 2432


Ignore:
Timestamp:
11/12/09 13:32:00 (2 years ago)
Author:
erikroos
Message:

Got Event Manager working. It is now possible to add events and apply these to one or more animals.
Added select boxes to Event Manager interface for adding individual animals or groups.

Identifiable: made field 'name' optional and added field 'comment'.

Made class (FillAnimalDB) to re-populate Animal DB when it's been emptied after an update.

Location:
molgenis4animaldb
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • molgenis4animaldb/handwritten/java/plugin/eventman/ManageEventsPlugin.ftl

    r2421 r2432  
    3535<table> 
    3636<tr> 
    37 <td>Concerning animal:</td> 
     37<td>Apply to animal(s):</td> 
    3838<td> 
    39 <select name="animal"> 
    40         <#list screen.animalList as a> 
    41                 <option <#if screen.selectedAnimal?exists && screen.selectedAnimal == a.id>SELECTED</#if> value="${a.id}">${a.name}</option> 
    42         </#list> 
    43 </select> 
     39 
     40<table> 
     41  <tr> 
     42    <td rowspan=3> 
     43      <select name="animal" size=10> 
     44      <#if screen.selectedAnimalList?exists> 
     45        <#list screen.selectedAnimalList as sa> 
     46                  <option value="${sa.id}">${sa.name}</option> 
     47            </#list> 
     48          </#if> 
     49      </select> 
     50    </td> 
     51    <td> 
     52      <input type="submit" value="<<" onclick="__action.value='addIndividual'" /> 
     53    </td> 
     54    <td> 
     55      Add individual...<br /> 
     56      <select name="ind_animal"> 
     57      <#list screen.animalList as a> 
     58                <option value="${a.id}">${a.name}</option> 
     59          </#list> 
     60          </select> 
     61        </td> 
     62  </tr><tr> 
     63        <td> 
     64      <input type="submit" value="<<" onclick="__action.value='addGroup'" /> 
     65    </td> 
     66    <td> 
     67      Add group...<br /> 
     68      <select name="group_animal"> 
     69      <#list screen.groupList as g> 
     70                <option value="${g.id}">${g.name}</option> 
     71          </#list> 
     72          </select> 
     73        </td> 
     74  </tr><tr> 
     75    <td> 
     76      <input type="submit" value="&gt;&gt;" onclick="__action.value='remIndividual'" /> 
     77    </td> 
     78  </tr> 
     79</table> 
    4480</td> 
    4581</tr><tr> 
     
    75111</tr> 
    76112</table> 
    77 <#if screen.success?exists && screen.success == 1> 
     113<#if screen.success?exists> 
     114  <#if screen.success == 1> 
    78115        Event successfully added! 
    79 <#elseif screen.success?exists && screen.success == -1> 
     116  <#elseif screen.success == -1> 
    80117        Oops... something went wrong! Event has not been recorded. 
     118  <#elseif screen.success == 2> 
     119        Added individual(s). 
     120  <#elseif screen.success == 3> 
     121        Removed individual. 
     122  </#if> 
    81123</#if> 
    82  
    83  
    84  
    85 <#--<input name="myinput" value="${screen.getMyValue()}"> 
    86 <input type="submit" value="Change name" onclick="__action.value='do_myaction';return true;"/--> 
    87124         
    88125<#--end of your plugin-->        
  • molgenis4animaldb/handwritten/java/plugin/eventman/ManageEventsPlugin.java

    r2421 r2432  
    88package plugin.eventman; 
    99 
    10 import java.sql.Date; 
     10import java.util.Date; 
    1111import java.text.SimpleDateFormat; 
    1212import java.util.ArrayList; 
     13import java.util.Calendar; 
     14import java.util.Iterator; 
    1315import java.util.List; 
    1416 
    1517import org.molgenis.framework.db.Database; 
    1618import org.molgenis.framework.db.Query; 
     19import org.molgenis.framework.db.QueryRule; 
     20import org.molgenis.framework.db.QueryRule.Operator; 
    1721import org.molgenis.framework.ui.ScreenModel; 
    1822import org.molgenis.framework.ui.PluginModel; 
     
    2327import animaldb.Event_type; 
    2428import animaldb.Location; 
    25  
    26 public class ManageEventsPlugin extends PluginModel 
    27 { 
     29import animaldb.Animal_group; 
     30 
     31public class ManageEventsPlugin extends PluginModel { 
    2832        private List<Animal> animalList; 
     33        private List<Animal> selectedAnimalList = new ArrayList<Animal>(); 
    2934        private List<Event_type> eventTypeList; 
    3035        private List<Location> locationList; 
    31         private int selectedAnimal; 
     36        private List<Animal_group> groupList; 
    3237        private int selectedLocation; 
    3338        private int selectedEventType; 
    3439        private Date date; 
    35         private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     40        private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat( 
     41                        "yyyy-MM-dd"); 
    3642        private String comment; 
    3743        private int success; 
    38          
    39         public ManageEventsPlugin(String name, ScreenModel parent) 
    40         { 
     44 
     45        public ManageEventsPlugin(String name, ScreenModel parent) { 
    4146                super(name, parent); 
    42         } 
    43          
     47                this.setSuccess(0); 
     48        } 
     49 
    4450        public List<Location> getLocationList() { 
    4551                return locationList; 
     
    7379                return date; 
    7480        } 
    75          
     81 
    7682        public String getDateAsString() { 
    7783                return mySimpleDateFormat.format(date); 
    7884        } 
    79          
     85 
     86        public List<Animal_group> getGroupList() { 
     87                return groupList; 
     88        } 
     89 
     90        public void setGroupList(List<Animal_group> groupList) { 
     91                this.groupList = groupList; 
     92        } 
     93 
    8094        public List<Animal> getAnimalList() { 
    8195                return animalList; 
     
    8599                this.animalList = animalList; 
    86100        } 
    87          
    88         public int getSelectedAnimal() { 
    89                 return selectedAnimal; 
    90         } 
    91  
    92         public void setSelectedAnimal(int selectedAnimal) { 
    93                 this.selectedAnimal = selectedAnimal; 
     101 
     102        public List<Animal> getSelectedAnimalList() { 
     103                return selectedAnimalList; 
     104        } 
     105 
     106        public void setSelectedAnimalList(List<Animal> selectedAnimalList) { 
     107                this.selectedAnimalList = selectedAnimalList; 
    94108        } 
    95109 
     
    101115                this.eventTypeList = eventTypeList; 
    102116        } 
    103          
     117 
    104118        public void setComment(String comment) { 
    105119                this.comment = comment; 
     
    113127                return success; 
    114128        } 
    115          
    116         public void setSucces(int success) { 
     129 
     130        public void setSuccess(int success) { 
    117131                this.success = success; 
    118132        } 
    119133 
    120134        @Override 
    121         public String getViewName() 
    122         { 
     135        public String getViewName() { 
    123136                return "plugin_eventman_ManageEventsPlugin"; 
    124137        } 
    125138 
    126139        @Override 
    127         public String getViewTemplate() 
    128         { 
     140        public String getViewTemplate() { 
    129141                return "plugin/eventman/ManageEventsPlugin.ftl"; 
    130142        } 
    131143 
    132144        @Override 
    133         public void handleRequest(Database db, Tuple request) 
    134         { 
     145        public void handleRequest(Database db, Tuple request) { 
    135146                try { 
    136147                        String action = request.getString("__action"); 
    137148                        if (action.equals("addEvent")) { 
    138  
    139                                 this.setSelectedLocation(request.getInt("location")); 
    140                                 this.setSelectedEventType(request.getInt("eventtype")); 
    141                                 this.setDate(request.getDate("date")); 
    142                                 this.setSelectedAnimal(request.getInt("animal")); 
    143                                 this.setComment(request.getString("comment")); 
    144  
    145149                                List<Event> entities = new ArrayList<Event>(); 
    146                                  
    147                                 Event tmpEvent = new Event(); 
    148                                 tmpEvent.setLocationid(this.getSelectedLocation()); 
    149                                 tmpEvent.setEventtypeid(this.getSelectedEventType()); 
    150                                 tmpEvent.setDate(this.getDate()); 
    151                                 tmpEvent.setAnimalid(this.getSelectedAnimal()); 
    152                                 tmpEvent.setName(this.getComment()); 
    153                                  
    154                                 entities.add(tmpEvent); 
    155                                  
     150 
     151                                Iterator<Animal> iterator = selectedAnimalList.iterator(); 
     152                                while (iterator.hasNext()) { 
     153 
     154                                        Event tmpEvent = new Event(); 
     155                                         
     156                                        this.setSelectedLocation(request.getInt("location")); 
     157                                        this.setSelectedEventType(request.getInt("eventtype")); 
     158                                        this.setDate(request.getDate("date")); 
     159                                        this.setComment(request.getString("comment")); 
     160         
     161                                        tmpEvent.setAnimalid(iterator.next()); 
     162                                        tmpEvent.setLocationid(this.getSelectedLocation()); 
     163                                        tmpEvent.setEventtypeid(this.getSelectedEventType()); 
     164                                        tmpEvent.setDate(this.getDate()); 
     165                                        tmpEvent.setComment(this.getComment()); 
     166         
     167                                        entities.add(tmpEvent); 
     168                                } 
    156169                                db.add(entities); 
    157                                  
    158                                 this.success = 1; 
     170                                this.setSuccess(1); 
    159171                        } 
    160                 } catch (Exception e) { 
    161                         this.success = -1; 
    162                         e.printStackTrace(); 
    163                 } 
    164         } 
    165  
    166         @Override 
    167         public void reload(Database db) 
    168         { 
     172 
     173                        if (action.equals("addIndividual") || action.equals("addGroup")) { 
     174                                Query q = db.query(Animal.class); 
     175                                if (action.equals("addIndividual")) { 
     176                                        q.addRules(new QueryRule("id", Operator.EQUALS, request 
     177                                                        .getInt("ind_animal"))); 
     178                                } 
     179                                if (action.equals("addGroup")) { 
     180                                        q.addRules(new QueryRule("animalgroupid", Operator.EQUALS, 
     181                                                        request.getInt("group_animal"))); 
     182                                } 
     183                                try { 
     184                                        List<Animal> tmpAnimalList = q.find(); 
     185                                        Iterator<Animal> iterator = tmpAnimalList.iterator(); 
     186                                        while (iterator.hasNext()) { 
     187                                                if (selectedAnimalList.contains(iterator.next())) { 
     188                                                        iterator.remove(); 
     189                                                } 
     190                                        } 
     191                                        this.selectedAnimalList.addAll(tmpAnimalList); 
     192                                        this.setSuccess(2); 
     193                                } catch (Exception e) { 
     194                                        this.setSuccess(-1); 
     195                                        e.printStackTrace(); 
     196                                } 
     197                        } 
     198 
     199                        if (action.equals("remIndividual")) { 
     200                                Query q = db.query(Animal.class); 
     201                                q.addRules(new QueryRule("id", Operator.EQUALS, request 
     202                                                .getInt("animal"))); 
     203                                try { 
     204                                        this.selectedAnimalList.removeAll(q.find()); 
     205                                        this.setSuccess(3); 
     206                                } catch (Exception e) { 
     207                                        this.setSuccess(-1); 
     208                                        e.printStackTrace(); 
     209                                } 
     210                        } 
     211 
     212                } catch (Exception e) { 
     213                        this.setSuccess(-1); 
     214                        e.printStackTrace(); 
     215                } 
     216        } 
     217 
     218        @Override 
     219        public void reload(Database db) { 
    169220                Query q = db.query(Location.class); 
    170221                try { 
     
    180231                        e.printStackTrace(); 
    181232                } 
    182                  
     233 
    183234                q = db.query(Animal.class); 
    184235                try { 
     
    187238                        e.printStackTrace(); 
    188239                } 
    189                  
    190                 this.success = 0; 
    191         } 
    192          
    193         @Override 
    194         public boolean isVisible() 
    195         { 
    196                 //you can use this to hide this plugin, e.g. based on user rights. 
    197                 //e.g. 
    198                 //if(!this.getLogin().hasEditPermission(myEntity)) return false; 
     240 
     241                q = db.query(Animal_group.class); 
     242                try { 
     243                        this.setGroupList(q.find()); 
     244                } catch (Exception e) { 
     245                        e.printStackTrace(); 
     246                } 
     247 
     248                Calendar dateTime = Calendar.getInstance(); 
     249                setDate(dateTime.getTime()); 
     250        } 
     251 
     252        @Override 
     253        public boolean isVisible() { 
     254                // you can use this to hide this plugin, e.g. based on user rights. 
     255                // e.g. 
     256                // if(!this.getLogin().hasEditPermission(myEntity)) return false; 
    199257                return true; 
    200258        } 
  • molgenis4animaldb/handwritten/java/plugin/reports/MakeReportPlugin.ftl

    r2421 r2432  
    7272        <br /> 
    7373        <#list screen.eventList as a> 
    74                 Event ${a.id}: ${a.name} on ${a.date} 
     74                Event ${a.id}: ${a.comment} on ${a.date} 
    7575                <br /> 
    7676        </#list> 
  • molgenis4animaldb/handwritten/java/plugin/reports/MakeReportPlugin.java

    r2421 r2432  
    88package plugin.reports; 
    99 
    10 import java.sql.Date; 
    11 import java.text.ParseException; 
     10import java.util.Date; 
    1211import java.text.SimpleDateFormat; 
    13 import java.util.ArrayList; 
     12import java.util.Calendar; 
    1413import java.util.List; 
    1514 
     
    4140        private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    4241 
     42        public MakeReportPlugin(String name, ScreenModel parent) { 
     43                super(name, parent); 
     44                Calendar dateTime = Calendar.getInstance(); 
     45                setFromdate(dateTime.getTime()); 
     46                setTodate(dateTime.getTime()); 
     47        } 
     48         
    4349        public List<Location> getLocationList() { 
    4450                return locationList; 
     
    112118        public void setEventTypeList(List<Event_type> eventTypeList) { 
    113119                this.eventTypeList = eventTypeList; 
    114         } 
    115  
    116         public MakeReportPlugin(String name, ScreenModel parent) { 
    117                 super(name, parent); 
    118120        } 
    119121 
  • molgenis4animaldb/molgenis4animal_db.xml

    r2413 r2432  
    2020                </description> 
    2121                <field name="id" type="autoid" description="autogenerated id number (autoid)" /> 
    22                 <field name="name" unique="true" description="unique, user provided name string" label="Name"/> 
     22                <field name="name" unique="true" nillable="true" description="unique, optional, user provided name string" label="Name"/> 
     23                <field name="comment" nillable="true" description="optional comment string" label="Comment"/> 
    2324        </entity> 
    2425 
Note: See TracChangeset for help on using the changeset viewer.