1 package org.tigris.scarab.actions; 2 3 48 49 import java.util.ArrayList ; 50 import java.util.Calendar ; 51 import java.util.HashMap ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 import java.util.Map ; 55 56 import org.apache.commons.collections.MapIterator; 57 import org.apache.commons.collections.map.LinkedMap; 58 import org.apache.commons.lang.StringUtils; 59 import org.apache.fulcrum.intake.Intake; 60 import org.apache.fulcrum.intake.model.Group; 61 import org.apache.fulcrum.parser.ParameterParser; 62 import org.apache.torque.om.NumberKey; 63 import org.apache.turbine.RunData; 64 import org.apache.turbine.TemplateContext; 65 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 66 import org.tigris.scarab.om.AttributeValue; 67 import org.tigris.scarab.om.Report; 68 import org.tigris.scarab.om.ReportManager; 69 import org.tigris.scarab.om.ReportPeer; 70 import org.tigris.scarab.om.ScarabUser; 71 import org.tigris.scarab.reports.ReportAxis; 72 import org.tigris.scarab.reports.ReportBridge; 73 import org.tigris.scarab.reports.ReportDate; 74 import org.tigris.scarab.reports.ReportDefinition; 75 import org.tigris.scarab.reports.ReportGroup; 76 import org.tigris.scarab.reports.ReportHeading; 77 import org.tigris.scarab.reports.ReportOptionAttribute; 78 import org.tigris.scarab.reports.ReportUserAttribute; 79 import org.tigris.scarab.tools.ScarabLocalizationTool; 80 import org.tigris.scarab.tools.ScarabRequestTool; 81 import org.tigris.scarab.tools.localization.L10NKeySet; 82 import org.tigris.scarab.tools.localization.L10NMessage; 83 import org.tigris.scarab.tools.localization.LocalizationKey; 84 import org.tigris.scarab.util.ScarabConstants; 85 import org.tigris.scarab.util.ScarabUtil; 86 import org.tigris.scarab.util.export.ExportFormat; 87 import org.tigris.scarab.util.word.IssueSearch; 88 89 94 public class ConfigureReport 95 extends RequireLoginFirstAction 96 { 97 static final String NO_PERMISSION_MESSAGE = 98 "NoPermissionToEditReport"; 99 100 private static final String ADD_USER = "add_user"; 101 private static final String SELECTED_USER = "select_user"; 102 103 ScarabLocalizationTool l10n; 104 ScarabRequestTool scarabR; 105 ReportBridge report; 106 Intake intake; 107 ParameterParser params; 108 ScarabUser user; 109 110 private void setup(RunData data, TemplateContext context) throws Exception { 111 l10n = getLocalizationTool(context); 112 scarabR = getScarabRequestTool(context); 113 report = scarabR.getReport(); 114 intake = getIntakeTool(context); 115 params = data.getParameters(); 116 user = (ScarabUser)data.getUser(); 117 } 118 119 public void doSaveinfo(RunData data, TemplateContext context) 120 throws Exception 121 { 122 setup(data,context); 123 124 if (!report.isEditable((ScarabUser)data.getUser())) 125 { 126 setNoPermissionMessage(); 127 setTarget(data, "reports,ReportList.vm"); 128 } 129 else if (intake.isAllValid()) 130 { 131 Group intakeReport = getIntakeReportGroup(intake, report); 132 if (intakeReport != null) 133 { 134 intakeReport.setValidProperties(report); 135 136 if (report.isReadyForCalculation()) 137 { 138 String msg = report.isNew() ? 139 l10n.get(L10NKeySet.ReportUpdated) : 140 l10n.get(L10NKeySet.ReportUpdatedNotSaved); 141 scarabR.setConfirmMessage(msg); 142 setTarget(data, "reports,Info.vm"); 143 } 144 else 145 { 146 String msg = report.isNew() ? 147 l10n.get("ReportUpdatedPleaseAddRowAndColumnCriteria") : 148 l10n.get("ReportUpdatedNotSavedPleaseAddRowAndColumnCriteria"); 149 scarabR.setConfirmMessage(msg); 150 setTarget(data, "reports,AxisConfiguration.vm"); 151 } 152 } 153 else 154 { 155 scarabR.setAlertMessage( 158 L10NKeySet.ThisShouldNotHappenPleaseContactAdmin); 159 setTarget(data, "reports,Info.vm"); 160 } 161 } 162 else 163 { 164 scarabR.setAlertMessage( 165 L10NKeySet.InvalidData); 166 setTarget(data, "reports,Info.vm"); 167 } 168 } 169 170 public void doSelectheading(RunData data, TemplateContext context) 171 throws Exception 172 { 173 setup(data,context); 174 177 intake.removeAll(); 178 181 int level = params.getInt("heading", -1); 182 int prevLevel = params.getInt("prevheading", -2); 183 if (level == prevLevel) 184 { 185 getScarabRequestTool(context).setInfoMessage( 186 getLocalizationTool(context) 187 .format("AlreadyEditingSelectedHeading", new Integer (level+1))); 188 } 189 } 190 191 public void doSettype(RunData data, TemplateContext context) 192 throws Exception 193 { 194 setup(data,context); 195 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 197 int type = params.getInt("headingtype", 0); 198 199 if (level != -1) 201 { 202 203 ReportDefinition reportDefn = report.getReportDefinition(); 204 ReportAxis reportAxis = reportDefn.getAxis(axis); 205 ReportHeading heading = reportAxis.getHeading(level); 206 int currentType = heading.calculateType(); 207 if (type != currentType) 208 { 209 if (currentType == 2 && 210 !reportDefn.allowMoreHeadings(reportAxis)) 211 { 212 scarabR.setAlertMessage(L10NKeySet.ThisAxisMustBeDatesUnlessHeadingsAreRemoved); 213 params.setString("headingtype", "2"); 214 } 215 else 216 { 217 LocalizationKey msg; 218 if (heading.size() > 0) 219 { 220 heading.reset(); 221 msg = L10NKeySet.HeadingTypeChangedOldDataDiscarded; 222 } 223 else 224 { 225 msg = L10NKeySet.HeadingTypeChanged; 226 } 227 scarabR.setConfirmMessage(msg); 228 } 229 } 230 } 231 } 232 233 public void doAddoptions(RunData data, TemplateContext context) 234 throws Exception 235 { 236 setup(data,context); 237 if (!report.isEditable((ScarabUser)data.getUser())) 238 { 239 setNoPermissionMessage(); 240 setTarget(data, "reports,ReportList.vm"); 241 } 242 else if (intake.isAllValid()) 243 { 244 245 246 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 248 int type = params.getInt("headingtype", 0); 249 250 253 IssueSearch search = scarabR.getNewSearch(); 254 258 LinkedMap avMap = search.getCommonAttributeValuesMap(); 260 for (MapIterator i = avMap.mapIterator(); i.hasNext();) 261 { 262 i.next(); 263 AttributeValue aval = (AttributeValue)i.getValue(); 264 Group group = intake.get("AttributeValue", aval.getQueryKey()); 265 if (group != null) 266 { 267 group.setProperties(aval); 268 } 269 } 270 271 List setAttValues = removeUnsetValues(search.getAttributeValues()); 273 274 ReportHeading heading = report.getReportDefinition() 275 .getAxis(axis).getHeading(level); 276 if (type != heading.calculateType()) 277 { 278 scarabR.setAlertMessage(L10NKeySet.ChangeOfTypeMessage); 279 } 280 281 List groups = heading.getReportGroups(); 284 Map optionGroupMap = null; 285 if (groups != null && !groups.isEmpty()) 286 { 287 optionGroupMap = new HashMap (); 288 for (Iterator i = groups.iterator(); i.hasNext();) 289 { 290 ReportGroup group = (ReportGroup)i.next(); 291 List options = group.getReportOptionAttributes(); 292 if (options != null && !options.isEmpty()) 293 { 294 for (Iterator j = options.iterator(); j.hasNext();) 295 { 296 optionGroupMap.put(j.next(), group); 297 } 298 } 299 } 300 } 301 heading.reset(); 302 303 for (Iterator i = setAttValues.iterator(); i.hasNext();) 305 { 306 AttributeValue av = (AttributeValue)i.next(); 307 List chainedValues = av.getValueList(); 309 for (Iterator j = chainedValues.iterator(); j.hasNext();) 310 { 311 ReportOptionAttribute roa = new ReportOptionAttribute(); 312 Integer id = Integer.valueOf(((AttributeValue)j.next()) 313 .getOptionId().toString()); 314 roa.setOptionId(id); 315 316 if (optionGroupMap == null) 317 { 318 heading.addReportOptionAttribute(roa); 319 } 320 else 321 { 322 ReportGroup group = 323 (ReportGroup)optionGroupMap.get(roa); 324 if (group == null) 325 { 326 ((ReportGroup)groups.get(0)) 328 .addReportOptionAttribute(roa); 329 } 330 else 331 { 332 group.addReportOptionAttribute(roa); 333 } 334 } 335 } 336 } 337 if (level == -1) 338 { 339 params.setString("heading", "0"); 340 } 341 342 String msg = getLocalizedHeadingConfirmMessage(report, l10n); 343 scarabR.setConfirmMessage(msg); 344 345 354 } 355 } 356 357 358 private static String getLocalizedHeadingConfirmMessage(ReportBridge report, ScarabLocalizationTool l10n) 359 { 360 LocalizationKey key; 361 if (report.isReadyForCalculation()) 362 { 363 key = report.isNew() ? 364 L10NKeySet.ReportUpdatedDoMoreOrCalculate: 365 L10NKeySet.ReportUpdatedNotSavedDoMoreOrCalculate; 366 } 367 else 368 { 369 key = report.isNew() ? 370 L10NKeySet.ReportUpdatedDoMore: 371 L10NKeySet.ReportUpdatedNotSavedDoMore; 372 } 373 L10NMessage msg = new L10NMessage(key); 374 return msg.getMessage(l10n); 375 } 376 377 382 private List removeUnsetValues(List attValues) 383 { 384 int size = attValues.size(); 385 List setAVs = new ArrayList (size); 386 for (int i=0; i<size; i++) 387 { 388 AttributeValue attVal = (AttributeValue) attValues.get(i); 389 if (attVal.getOptionId() != null || attVal.getValue() != null 390 || attVal.getUserId() != null) 391 { 392 setAVs.add(attVal); 393 } 394 } 395 return setAVs; 396 } 397 398 401 public void doAddusers(RunData data, TemplateContext context) 402 throws Exception 403 { 404 setup(data,context); 405 if (!report.isEditable(user)) 406 { 407 setNoPermissionMessage(); 408 setTarget(data, "reports,ReportList.vm"); 409 return; 410 } 411 412 413 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 415 int type = params.getInt("headingtype", 0); 416 417 ReportHeading heading = report.getReportDefinition() 421 .getAxis(axis).getHeading(level); 422 if (type != heading.calculateType() 423 || heading.getReportGroups() != null) 424 { 425 if (heading.getReportGroups() != null) 426 { 427 scarabR.setAlertMessage(L10NKeySet.CouldNotMakeRequestedChange); 428 } 429 heading.reset(); 430 } 431 432 String [] userIds = params.getStrings(ADD_USER); 433 if (userIds != null && userIds.length > 0) 434 { 435 for (int i =0; i<userIds.length; i++) 436 { 437 String userId = userIds[i]; 438 ReportUserAttribute rua = new ReportUserAttribute(); 439 rua.setUserId(new Integer (userId)); 440 rua.setAttributeId(new Integer ( 441 params.getString("user_attr_" + userId))); 442 heading.addReportUserAttribute(rua); 443 } 444 if (level == -1) 445 { 446 params.setString("heading", "0"); 447 } 448 449 String msg = getLocalizedHeadingConfirmMessage(report, l10n); 450 scarabR.setConfirmMessage(msg); 451 } 452 else 453 { 454 scarabR.setAlertMessage(L10NKeySet.NoUsersSelected); 455 } 456 } 457 458 461 public void doRemoveusers(RunData data, TemplateContext context) 462 throws Exception 463 { 464 setup(data,context); 465 if (!report.isEditable(user)) 466 { 467 setNoPermissionMessage(); 468 setTarget(data, "reports,ReportList.vm"); 469 return; 470 } 471 472 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 474 int type = params.getInt("headingtype", 0); 475 476 ReportHeading heading = report.getReportDefinition() 480 .getAxis(axis).getHeading(level); 481 if (type != heading.calculateType() 482 || heading.getReportGroups() != null) 483 { 484 heading.reset(); 485 scarabR.setAlertMessage(L10NKeySet.CouldNotMakeRequestedChange); 486 } 487 else 488 { 489 String [] userIds = params.getStrings(SELECTED_USER); 490 if (userIds != null && userIds.length > 0) 491 { 492 for (int i =0; i<userIds.length; i++) 493 { 494 String userId = userIds[i]; 495 ReportUserAttribute rua = new ReportUserAttribute(); 496 rua.setUserId(new Integer (userId)); 497 rua.setAttributeId(new Integer ( 498 params.getString("old_attr_" + userId))); 499 500 List ruas = heading.getReportUserAttributes(); 501 if (ruas != null) 502 { 503 ruas.remove(rua); 504 } 505 } 506 scarabR.setConfirmMessage(L10NKeySet.SelectedUsersWereRemoved); 507 } 508 else 509 { 510 scarabR.setAlertMessage(L10NKeySet.NoUsersSelected); 511 } 512 } 513 } 514 515 518 public void doUpdateusers(RunData data, TemplateContext context) 519 throws Exception 520 { 521 522 setup(data,context); 523 if (!report.isEditable(user)) 524 { 525 setNoPermissionMessage(); 526 setTarget(data, "reports,ReportList.vm"); 527 return; 528 } 529 530 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 532 int type = params.getInt("headingtype", 0); 533 534 ReportHeading heading = report.getReportDefinition() 538 .getAxis(axis).getHeading(level); 539 if (type != heading.calculateType() 540 || heading.getReportGroups() != null) 541 { 542 heading.reset(); 543 scarabR.setAlertMessage(L10NKeySet.CouldNotMakeRequestedChange); 544 } 545 else 546 { 547 String [] userIds = params.getStrings(SELECTED_USER); 548 if (userIds != null && userIds.length > 0) 549 { 550 for (int i =0; i<userIds.length; i++) 551 { 552 String userId = userIds[i]; 553 ReportUserAttribute rua = new ReportUserAttribute(); 554 rua.setUserId(new Integer (userId)); 555 rua.setAttributeId(new Integer ( 556 params.getString("old_attr_" + userId))); 557 558 List ruas = heading.getReportUserAttributes(); 559 if (ruas != null) 560 { 561 571 ruas.remove(rua); 572 } 573 574 rua = new ReportUserAttribute(); 575 rua.setUserId(new Integer (userId)); 576 rua.setAttributeId(new Integer ( 577 params.getString("asso_user_{" + userId + "}"))); 578 heading.addReportUserAttribute(rua); 579 } 580 scarabR.setConfirmMessage(L10NKeySet.SelectedUsersWereModified); 581 } 582 else 583 { 584 scarabR.setAlertMessage(L10NKeySet.NoUsersSelected); 585 } 586 } 587 } 588 589 592 public void doRemoveheading(RunData data, TemplateContext context) 593 throws Exception 594 { 595 setup(data,context); 596 if (!report.isEditable(user)) 597 { 598 setNoPermissionMessage(); 599 setTarget(data, "reports,ReportList.vm"); 600 return; 601 } 602 603 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 605 607 if (level >= 0) 608 { 609 List headings = report.getReportDefinition() 610 .getAxis(axis).getReportHeadings(); 611 headings.remove(level); 612 scarabR.setConfirmMessage(L10NKeySet.HeadingRemoved); 613 } 614 else 615 { 616 scarabR.setAlertMessage(L10NKeySet.NoHeadingSelected); 617 } 618 } 619 620 624 public void doGotoeditgroups(RunData data, TemplateContext context) 625 throws Exception 626 { 627 setup(data,context); 628 629 int level = params.getInt("heading", -1); 630 631 if (level >= 0) 633 { 634 int axis = params.getInt("axis", 0); ReportHeading heading = (ReportHeading)report.getReportDefinition() 636 .getAxis(axis).getReportHeadings().get(level); 637 if (heading.calculateType() == 0) 638 { 639 setTarget(data, "reports,EditGroups.vm"); 640 } 641 else 642 { 643 scarabR.setAlertMessage(getLocalizationTool(context) 644 .get("GroupsAreForOptionsOnly")); 645 } 646 } 647 else 648 { 649 scarabR.setAlertMessage(L10NKeySet.NoHeadingSelected); 650 } 651 } 652 653 656 public void doAddheading(RunData data, TemplateContext context) 657 throws Exception 658 { 659 setup(data,context); 660 if (!report.isEditable(user)) 661 { 662 setNoPermissionMessage(); 663 setTarget(data, "reports,ReportList.vm"); 664 return; 665 } 666 667 668 int axisIndex = params.getInt("axis", 0); ReportAxis axis = report.getReportDefinition().getAxis(axisIndex); 670 axis.addReportHeading(new ReportHeading()); 671 params.setString("heading", String.valueOf(axis.getReportHeadings().size()-1)); 672 Intake intake = getIntakeTool(context); 674 intake.removeAll(); 675 scarabR.setConfirmMessage(L10NKeySet.HeadingAddedNowAddContent); 676 } 677 678 public void doAddgroup(RunData data, TemplateContext context) 679 throws Exception 680 { 681 setup(data,context); 682 if (!report.isEditable(user)) 683 { 684 setNoPermissionMessage(); 685 setTarget(data, "reports,ReportList.vm"); 686 return; 687 } 688 689 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 691 692 String name = params.getString("groupname_new"); 693 if (name != null) 694 { 695 name = name.trim(); 696 } 697 698 if (name == null || name.length() == 0) 699 { 700 scarabR.setAlertMessage(L10NKeySet.InvalidGroupName); 701 } 702 else 703 { 704 ReportHeading heading = report.getReportDefinition() 705 .getAxis(axis).getHeading(level); 706 ReportGroup group = new ReportGroup(); 707 group.setName(name); 708 List groups = heading.getReportGroups(); 710 if (groups != null && groups.contains(group)) 711 { 712 scarabR.setAlertMessage(L10NKeySet.DuplicateGroupName); 713 } 714 else 715 { 716 heading.addReportGroup(group); 717 718 params.remove("groupname_new"); 719 scarabR.setConfirmMessage(L10NKeySet.GroupAdded); 721 } 722 723 741 } 742 } 743 744 public void doDeletegroup(RunData data, TemplateContext context) 745 throws Exception 746 { 747 setup(data,context); 748 if (!report.isEditable(user)) 749 { 750 setNoPermissionMessage(); 751 setTarget(data, "reports,ReportList.vm"); 752 return; 753 } 754 755 String [] groupIndices = params.getStrings("selectgroup"); 756 if (groupIndices == null || groupIndices.length == 0) 757 { 758 scarabR.setAlertMessage(L10NKeySet.NoGroupSelected); 759 } 760 else 761 { 762 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 764 List reportGroups = report.getReportDefinition() 765 .getAxis(axis).getHeading(level).getReportGroups(); 766 767 for (int j = groupIndices.length-1; j>=0; j--) 768 { 769 reportGroups.remove(Integer.parseInt(groupIndices[j])); 770 } 771 scarabR.setConfirmMessage(L10NKeySet.SelectedGroupDeleted); 772 773 790 } 791 } 792 793 public void doEditgroupname(RunData data, TemplateContext context) 794 throws Exception 795 { 796 setup(data,context); 797 798 if (!report.isEditable(user)) 799 { 800 setNoPermissionMessage(); 801 setTarget(data, "reports,ReportList.vm"); 802 return; 803 } 804 805 Object [] keys = params.getKeys(); 806 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 808 List reportGroups = report.getReportDefinition() 809 .getAxis(axis).getHeading(level).getReportGroups(); 810 811 for (int i =0; i < keys.length; i++) 812 { 813 String key = keys[i].toString(); 814 if (key.startsWith("groupname_") && key.indexOf("new") == -1) 815 { 816 int index = Integer.parseInt(key.substring(key.indexOf("_")+1, 817 key.length())); 818 ReportGroup group = (ReportGroup)reportGroups.get(index); 819 String name = params.getString(key, "").trim(); 820 if (name.length() == 0) 821 { 822 scarabR.setAlertMessage(L10NKeySet.InvalidGroupName); 823 } 824 else 825 { 826 group.setName(name); 827 } 828 } 829 } 830 scarabR.setConfirmMessage(L10NKeySet.GroupsChanged); 831 } 832 833 834 public void doSavegroups(RunData data, TemplateContext context) 835 throws Exception 836 { 837 setup(data,context); 838 839 if (!report.isEditable(user)) 840 { 841 setNoPermissionMessage(); 842 setTarget(data, "reports,ReportList.vm"); 843 return; 844 } 845 846 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 848 ReportHeading heading = report.getReportDefinition() 849 .getAxis(axis).getHeading(level); 850 List reportGroups = heading.getReportGroups(); 851 List groupedAttributes = heading.retrieveGroupedAttributes(); 855 for (Iterator i = reportGroups.iterator(); i.hasNext();) 856 { 857 ReportGroup group = (ReportGroup)i.next(); 858 group.reset(); 859 } 860 861 boolean success = true; 862 if (heading.calculateType() == 0) 863 { 864 for (Iterator j = groupedAttributes.iterator(); j.hasNext();) 865 { 866 ReportOptionAttribute reportOption = 867 (ReportOptionAttribute)j.next(); 868 String name = params.getString("option_" + 869 reportOption.getOptionId()); 870 if (name == null || name.trim().length() == 0) 871 { 872 scarabR.setAlertMessage(L10NKeySet.InvalidGroupName); 873 success = false; 874 break; 875 } 876 else 877 { 878 for (Iterator i = reportGroups.iterator(); i.hasNext();) 879 { 880 ReportGroup group = (ReportGroup)i.next(); 881 if (name.equals(group.getName())) 882 { 883 group.addReportOptionAttribute(reportOption); 884 } 885 } 886 } 887 } 888 } 889 else 890 { 891 for (Iterator j = groupedAttributes.iterator(); j.hasNext();) 892 { 893 ReportUserAttribute reportUser = 894 (ReportUserAttribute)j.next(); 895 String name = params.getString(new StringBuffer (20) 896 .append("att_").append(reportUser.getAttributeId()) 897 .append("user_").append(reportUser.getUserId()).toString()); 898 if (name == null || name.trim().length() == 0) 899 { 900 scarabR.setAlertMessage(L10NKeySet.InvalidGroupName); 901 success = false; 902 break; 903 } 904 else 905 { 906 for (Iterator i = reportGroups.iterator(); i.hasNext();) 907 { 908 ReportGroup group = (ReportGroup)i.next(); 909 if (name.equals(group.getName())) 910 { 911 group.addReportUserAttribute(reportUser); 912 } 913 } 914 } 915 } 916 } 917 918 if (success) 919 { 920 setTarget(data, "reports,AxisConfiguration.vm"); 921 } 922 } 923 924 925 public void doAdddate(RunData data, TemplateContext context) 926 throws Exception 927 { 928 setup(data,context); 929 if (!report.isEditable(user)) 930 { 931 setNoPermissionMessage(); 932 setTarget(data, "reports,ReportList.vm"); 933 return; 934 } 935 936 937 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 939 940 ReportHeading heading = report.getReportDefinition() 941 .getAxis(axis).getHeading(level); 942 params.setString("heading", "0"); 945 946 List dates = heading.getReportDates(); 947 int index = 1; 948 if (dates == null) 949 { 950 heading.reset(); 952 } 953 else 954 { 955 index = dates.size() + 1; 956 } 957 Calendar cal = scarabR.getCalendar(); 958 cal.set(Calendar.YEAR, params.getInt("y_" + index)); 959 cal.set(Calendar.MONTH, params.getInt("m_" + index) - 1); 960 cal.set(Calendar.DAY_OF_MONTH, params.getInt("d_" + index)); 961 cal.set(Calendar.HOUR_OF_DAY, params.getInt("h_" + index)); 962 cal.set(Calendar.MINUTE, 0); 963 cal.set(Calendar.SECOND, 0); 964 ReportDate rdate = new ReportDate(); 965 rdate.setTime(cal.getTime().getTime()); 966 heading.addReportDate(rdate); 967 scarabR.setConfirmMessage(L10NKeySet.DateAdded); 968 } 969 970 public void doDeletedate(RunData data, TemplateContext context) 971 throws Exception 972 { 973 setup(data,context); 974 975 if (!report.isEditable(user)) 976 { 977 setNoPermissionMessage(); 978 setTarget(data, "reports,ReportList.vm"); 979 return; 980 } 981 982 String [] dateIndices = params.getStrings("selectdate"); 983 if (dateIndices == null || dateIndices.length == 0) 984 { 985 scarabR.setAlertMessage(L10NKeySet.NoDateSelected); 986 } 987 else 988 { 989 int axis = params.getInt("axis", 0); int level = params.getInt("heading", -1); 991 List reportDates = report.getReportDefinition() 992 .getAxis(axis).getHeading(level).getReportDates(); 993 994 for (int j = dateIndices.length-1; j>=0; j--) 995 { 996 reportDates.remove(Integer.parseInt(dateIndices[j])-1); 997 } 998 scarabR.setConfirmMessage(L10NKeySet.SelectedDateDeleted); 999 } 1000 } 1001 1002 1003 public void doRedirecttocrossmodulelist(RunData data, TemplateContext context) 1004 throws Exception 1005 { 1006 setup(data,context); 1007 user.setCurrentMITList( 1010 report.getMITList()); 1011 setTarget(data, "reports,XModuleList.vm"); 1012 } 1013 1014 public void doConfinedataset(RunData data, TemplateContext context) 1015 throws Exception 1016 { 1017 setup(data,context); 1018 1019 if (!report.isEditable(user)) 1020 { 1021 setNoPermissionMessage(); 1022 setTarget(data, "reports,ReportList.vm"); 1023 return; 1024 } 1025 1026 1027 if ("fixed".equals(params.getString("def_date"))) 1028 { 1029 Calendar cal = scarabR.getCalendar(); 1030 cal.set(Calendar.YEAR, params.getInt("def_yr")); 1031 cal.set(Calendar.MONTH, params.getInt("def_month") - 1); 1032 cal.set(Calendar.DAY_OF_MONTH, params.getInt("def_day")); 1033 cal.set(Calendar.HOUR_OF_DAY, params.getInt("def_hr")); 1034 cal.set(Calendar.MINUTE, 0); 1035 cal.set(Calendar.SECOND, 0); 1036 report.setDefaultDate(cal.getTime()); 1037 } 1038 else 1039 { 1040 report.setDefaultDate(null); 1041 } 1042 ScarabLocalizationTool l10n = getLocalizationTool(context); 1043 scarabR.setConfirmMessage(L10NKeySet.ChangesSaved); 1044 setTarget(data, "reports,ConfineDataset.vm"); 1045 } 1046 1047 1048 public void doSwaprowcol(RunData data, TemplateContext context) 1049 throws Exception 1050 { 1051 setup(data,context); 1052 1053 if (!report.isEditable(user)) 1054 { 1055 setNoPermissionMessage(); 1056 setTarget(data, "reports,ReportList.vm"); 1057 return; 1058 } 1059 1060 1061 1062 ReportDefinition reportDefn = report.getReportDefinition(); 1063 List axes = reportDefn.getReportAxisList(); 1064 if (axes != null && !axes.isEmpty()) 1065 { 1066 if (axes.size() == 1) 1067 { 1068 reportDefn.addReportAxis(new ReportAxis()); 1069 } 1070 ReportAxis row = (ReportAxis)axes.remove(0); 1071 reportDefn.addReportAxis(row); 1073 } 1074 1075 } 1077 1078 public void doVerifyreport(RunData data, TemplateContext context) 1079 throws Exception 1080 { 1081 setup(data,context); 1082 if (report.removeStaleDefinitions()) 1083 { 1084 scarabR.setInfoMessage(l10n.get("ReportDefinitionModified")); 1085 } 1086 } 1087 1088 public void doGeneratereport(RunData data, TemplateContext context) 1089 throws Exception 1090 { 1091 setup(data,context); 1092 1093 if (report.removeStaleDefinitions()) 1094 { 1095 scarabR.setInfoMessage(l10n.get("ReportDefinitionModified")); 1096 } 1097 else if (report.getReportDefinition().reportQueryIsExpensive() ) 1098 { 1099 scarabR.setAlertMessage(l10n.format("ReportIsTooExpensive", String.valueOf( 1100 report.getReportDefinition().maximumHeadings()))); 1101 } 1102 else 1103 { 1104 String format = ScarabUtil.findValue(data, ExportFormat.KEY_NAME); 1107 if (StringUtils.isEmpty(format)) 1108 { 1109 Group intakeReport = getIntakeReportGroup(getIntakeTool(context), 1112 report); 1113 if (intakeReport != null) 1116 { 1117 format = (String ) intakeReport.get("Format").getValue(); 1118 } 1119 1120 if (format == null) 1121 { 1122 format = report.getFormat(); 1124 } 1125 } 1126 1127 if (ExportFormat.EXCEL_FORMAT.equalsIgnoreCase(format) 1128 || ExportFormat.TSV_FORMAT.equalsIgnoreCase(format)) 1129 { 1130 data.getParameters().setString(ExportFormat.KEY_NAME, format); 1132 setTarget(data, "ReportExport.vm"); 1133 } 1134 else 1135 { 1136 setTarget(data, "reports,Report_1.vm"); 1137 } 1138 1139 } 1140 } 1141 1142 public void doCreatenew(RunData data, TemplateContext context) 1143 throws Exception 1144 { 1145 String key = data.getParameters() 1146 .getString(ScarabConstants.CURRENT_REPORT); 1147 data.getParameters().remove(ScarabConstants.CURRENT_REPORT); 1148 ScarabUser user = (ScarabUser)data.getUser(); 1149 if (key != null && key.length() > 0) 1150 { 1151 user.setCurrentReport(key, null); 1152 } 1153 if (user.getCurrentMITList() == null) 1154 { 1155 setTarget(data, "reports,XModuleList.vm"); 1157 } 1158 else 1159 { 1160 setTarget(data, "reports,Info.vm"); 1161 } 1162 } 1163 1164 1165 public void doSavereport(RunData data, TemplateContext context) 1166 throws Exception 1167 { 1168 setup(data,context); 1169 1170 if (!report.isSavable((ScarabUser)data.getUser())) 1171 { 1172 setNoPermissionMessage(); 1173 setTarget(data, "reports,ReportList.vm"); 1174 } 1175 else if (intake.isAllValid()) 1176 { 1177 if (report.getName() == null || report.getName().trim().length() == 0) 1179 { 1180 Group intakeReport = getIntakeReportGroup(intake, report); 1181 if (intakeReport != null) 1182 { 1183 intakeReport.setValidProperties(report); 1184 } 1185 } 1186 1187 if (report.getName() == null || report.getName().trim().length() == 0) 1188 { 1189 scarabR.setAlertMessage(L10NKeySet.SavedReportsMustHaveName); 1190 setTarget(data, "reports,Info.vm"); 1191 } 1192 else 1193 { 1194 String name = report.getName().trim(); 1196 report.setName(name); 1197 org.tigris.scarab.om.Report savedReport = ReportPeer 1201 .retrieveByName(name); 1202 if (savedReport == null 1203 || savedReport.getQueryKey().equals(report.getQueryKey())) 1204 { 1205 report.save(); 1206 scarabR.setConfirmMessage(L10NKeySet.ReportSaved); 1207 } 1208 else 1209 { 1210 scarabR.setAlertMessage(L10NKeySet.ReportNameNotUnique); 1211 setTarget(data, "reports,Info.vm"); 1212 } 1213 } 1214 } 1215 else 1216 { 1217 scarabR.setAlertMessage(L10NKeySet.ErrorPreventedSavingReport); 1218 } 1219 } 1220 1221 public void doDeletestoredreport(RunData data, TemplateContext context) 1222 throws Exception 1223 { 1224 setup(data,context); 1225 ScarabUser user = (ScarabUser)data.getUser(); 1226 String [] reportIds = data.getParameters().getStrings("report_id"); 1227 if (reportIds == null || reportIds.length == 0) 1228 { 1229 scarabR.setAlertMessage(l10n.get("MustSelectReport")); 1230 } 1231 else 1232 { 1233 for (int i=0;i<reportIds.length; i++) 1234 { 1235 String reportId = reportIds[i]; 1236 if (reportId != null && reportId.length() > 0) 1237 { 1238 Report torqueReport = ReportManager 1239 .getInstance(new NumberKey(reportId), false); 1240 if (new ReportBridge(torqueReport).isDeletable(user)) 1241 { 1242 torqueReport.setDeleted(true); 1243 torqueReport.save(); 1244 } 1245 else 1246 { 1247 setNoPermissionMessage(); 1248 } 1249 } 1250 } 1251 } 1252 } 1253 1254 private void setNoPermissionMessage() 1255 { 1256 if(scarabR==null | l10n==null){ 1257 throw new RuntimeException ("setup() method not called for action event"); 1258 } 1259 scarabR.setAlertMessage( 1260 l10n.get(NO_PERMISSION_MESSAGE)); 1261 } 1262 1263 1268 private Group getIntakeReportGroup(Intake intake, ReportBridge report) 1269 throws Exception 1270 { 1271 Group intakeReport = intake.get("Report", report.getQueryKey(), false); 1272 if (intakeReport == null) 1273 { 1274 intakeReport = intake.get("Report", "", false); 1275 } 1276 return intakeReport; 1277 } 1278} 1279 | Popular Tags |