Changeset 2432
- Timestamp:
- 11/12/09 13:32:00 (2 years ago)
- Location:
- molgenis4animaldb
- Files:
-
- 3 added
- 5 edited
-
handwritten/java/fillanimaldb (added)
-
handwritten/java/fillanimaldb/FillAnimalDB.java (added)
-
handwritten/java/plugin/eventman/ManageEventsPlugin.ftl (modified) (2 diffs)
-
handwritten/java/plugin/eventman/ManageEventsPlugin.java (modified) (8 diffs)
-
handwritten/java/plugin/reports/MakeReportPlugin.ftl (modified) (1 diff)
-
handwritten/java/plugin/reports/MakeReportPlugin.java (modified) (3 diffs)
-
logger.out (added)
-
molgenis4animal_db.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
molgenis4animaldb/handwritten/java/plugin/eventman/ManageEventsPlugin.ftl
r2421 r2432 35 35 <table> 36 36 <tr> 37 <td> Concerning animal:</td>37 <td>Apply to animal(s):</td> 38 38 <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=">>" onclick="__action.value='remIndividual'" /> 77 </td> 78 </tr> 79 </table> 44 80 </td> 45 81 </tr><tr> … … 75 111 </tr> 76 112 </table> 77 <#if screen.success?exists && screen.success == 1> 113 <#if screen.success?exists> 114 <#if screen.success == 1> 78 115 Event successfully added! 79 <#elseif screen.success?exists &&screen.success == -1>116 <#elseif screen.success == -1> 80 117 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> 81 123 </#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;"/-->87 124 88 125 <#--end of your plugin--> -
molgenis4animaldb/handwritten/java/plugin/eventman/ManageEventsPlugin.java
r2421 r2432 8 8 package plugin.eventman; 9 9 10 import java. sql.Date;10 import java.util.Date; 11 11 import java.text.SimpleDateFormat; 12 12 import java.util.ArrayList; 13 import java.util.Calendar; 14 import java.util.Iterator; 13 15 import java.util.List; 14 16 15 17 import org.molgenis.framework.db.Database; 16 18 import org.molgenis.framework.db.Query; 19 import org.molgenis.framework.db.QueryRule; 20 import org.molgenis.framework.db.QueryRule.Operator; 17 21 import org.molgenis.framework.ui.ScreenModel; 18 22 import org.molgenis.framework.ui.PluginModel; … … 23 27 import animaldb.Event_type; 24 28 import animaldb.Location; 25 26 public class ManageEventsPlugin extends PluginModel 27 {29 import animaldb.Animal_group; 30 31 public class ManageEventsPlugin extends PluginModel { 28 32 private List<Animal> animalList; 33 private List<Animal> selectedAnimalList = new ArrayList<Animal>(); 29 34 private List<Event_type> eventTypeList; 30 35 private List<Location> locationList; 31 private int selectedAnimal;36 private List<Animal_group> groupList; 32 37 private int selectedLocation; 33 38 private int selectedEventType; 34 39 private Date date; 35 private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 40 private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat( 41 "yyyy-MM-dd"); 36 42 private String comment; 37 43 private int success; 38 39 public ManageEventsPlugin(String name, ScreenModel parent) 40 { 44 45 public ManageEventsPlugin(String name, ScreenModel parent) { 41 46 super(name, parent); 42 } 43 47 this.setSuccess(0); 48 } 49 44 50 public List<Location> getLocationList() { 45 51 return locationList; … … 73 79 return date; 74 80 } 75 81 76 82 public String getDateAsString() { 77 83 return mySimpleDateFormat.format(date); 78 84 } 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 80 94 public List<Animal> getAnimalList() { 81 95 return animalList; … … 85 99 this.animalList = animalList; 86 100 } 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; 94 108 } 95 109 … … 101 115 this.eventTypeList = eventTypeList; 102 116 } 103 117 104 118 public void setComment(String comment) { 105 119 this.comment = comment; … … 113 127 return success; 114 128 } 115 116 public void setSucces (int success) {129 130 public void setSuccess(int success) { 117 131 this.success = success; 118 132 } 119 133 120 134 @Override 121 public String getViewName() 122 { 135 public String getViewName() { 123 136 return "plugin_eventman_ManageEventsPlugin"; 124 137 } 125 138 126 139 @Override 127 public String getViewTemplate() 128 { 140 public String getViewTemplate() { 129 141 return "plugin/eventman/ManageEventsPlugin.ftl"; 130 142 } 131 143 132 144 @Override 133 public void handleRequest(Database db, Tuple request) 134 { 145 public void handleRequest(Database db, Tuple request) { 135 146 try { 136 147 String action = request.getString("__action"); 137 148 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 145 149 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 } 156 169 db.add(entities); 157 158 this.success = 1; 170 this.setSuccess(1); 159 171 } 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) { 169 220 Query q = db.query(Location.class); 170 221 try { … … 180 231 e.printStackTrace(); 181 232 } 182 233 183 234 q = db.query(Animal.class); 184 235 try { … … 187 238 e.printStackTrace(); 188 239 } 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; 199 257 return true; 200 258 } -
molgenis4animaldb/handwritten/java/plugin/reports/MakeReportPlugin.ftl
r2421 r2432 72 72 <br /> 73 73 <#list screen.eventList as a> 74 Event ${a.id}: ${a. name} on ${a.date}74 Event ${a.id}: ${a.comment} on ${a.date} 75 75 <br /> 76 76 </#list> -
molgenis4animaldb/handwritten/java/plugin/reports/MakeReportPlugin.java
r2421 r2432 8 8 package plugin.reports; 9 9 10 import java.sql.Date; 11 import java.text.ParseException; 10 import java.util.Date; 12 11 import java.text.SimpleDateFormat; 13 import java.util. ArrayList;12 import java.util.Calendar; 14 13 import java.util.List; 15 14 … … 41 40 private SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 42 41 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 43 49 public List<Location> getLocationList() { 44 50 return locationList; … … 112 118 public void setEventTypeList(List<Event_type> eventTypeList) { 113 119 this.eventTypeList = eventTypeList; 114 }115 116 public MakeReportPlugin(String name, ScreenModel parent) {117 super(name, parent);118 120 } 119 121 -
molgenis4animaldb/molgenis4animal_db.xml
r2413 r2432 20 20 </description> 21 21 <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"/> 23 24 </entity> 24 25
Note: See TracChangeset
for help on using the changeset viewer.