From 7d6175abd8dc5ee15d83e240b3ab430c4024bcda Mon Sep 17 00:00:00 2001 From: Brent Gossett Date: Mon, 3 Jun 2013 13:33:07 -0500 Subject: [PATCH 1/5] PM Calendar - Custom Setting Added a custom setting to parameterize the Milestones PM Calendar tab. Addressed another issue with users that do not have profiles in the General Utility. Updated the Milestones and Project trigger helper utilities to API version 27.0. --- src/classes/Milestone1_General_Utility.cls | 140 +- .../Milestone1_General_Utility.cls-meta.xml | 7 +- ...ne1_Milestone_Trigger_Utility.cls-meta.xml | 7 +- ...tone1_Milestone_Values_Helper.cls-meta.xml | 7 +- ...tone1_Project_Trigger_Utility.cls-meta.xml | 7 +- src/classes/Milestone1_repeatCon.cls | 1396 +++++++++-------- src/classes/Milestone1_repeatCon.cls-meta.xml | 7 +- src/objects/Milestone1_Settings__c.object | 9 + 8 files changed, 820 insertions(+), 760 deletions(-) diff --git a/src/classes/Milestone1_General_Utility.cls b/src/classes/Milestone1_General_Utility.cls index f3f08ae..79070d1 100644 --- a/src/classes/Milestone1_General_Utility.cls +++ b/src/classes/Milestone1_General_Utility.cls @@ -1,71 +1,71 @@ -/* -Copyright (c) 2011, salesforce.com, Inc. -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 salesforce.com, Inc. 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 HOLDER 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. - -*/ -public with sharing class Milestone1_General_Utility -{ - public static String processTaskName(String name) - { - String nameString = name; - if(nameString.length() >= 80) - { - nameString = nameString.subString(0,76); - Integer lastSpaceLocation = Milestone1_General_Utility.truncateStringAtSpace(nameString); - if(lastSpaceLocation > -1) - { - nameString = nameString.subString(0,lastSpaceLocation); - } - nameString = namesTring + '...'; - } - - return nameString; - } - - /** - * Checks if the current User have Permissions like System Admin - * @return boolean - * @author Sebastian Muñoz - * @createDate January 19, 2011 - */ - public static Boolean isSysAdmin() { - Profile pObj = [SELECT PermissionsModifyAllData, Id FROM Profile WHERE Id=:Userinfo.getProfileId() limit 1]; - return pObj.PermissionsModifyAllData; - } - - public static Integer truncateStringAtSpace(String inputString) - { - Integer location = inputString.lastIndexOf(' '); - return location; - } - - static testMethod void testTruncateString() - { - String example = 'NEW DESCRIPTION 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ THIS IS LONG DESCRIPTION GREATER THAN 80 CHARACTER LIMIT FOR NAME TEST TRUNCATING'; - String nameString = Milestone1_General_Utility.processTaskName(example); - system.AssertEquals('NEW DESCRIPTION 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ THIS IS LONG...',nameString); - } +/* +Copyright (c) 2011, salesforce.com, Inc. +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 salesforce.com, Inc. 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 HOLDER 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. + +*/ +public with sharing class Milestone1_General_Utility +{ + public static String processTaskName(String name) + { + String nameString = name; + if(nameString.length() >= 80) + { + nameString = nameString.subString(0,76); + Integer lastSpaceLocation = Milestone1_General_Utility.truncateStringAtSpace(nameString); + if(lastSpaceLocation > -1) + { + nameString = nameString.subString(0,lastSpaceLocation); + } + nameString = namesTring + '...'; + } + + return nameString; + } + + /** + * Checks if the current User have Permissions like System Admin + * @return boolean + * @author Sebastian Muñoz + * @createDate January 19, 2011 + */ + public static Boolean isSysAdmin() { + Profile pObj = [SELECT PermissionsModifyAllData, Id FROM Profile WHERE Id=:Userinfo.getProfileId() limit 1]; + return pObj.PermissionsModifyAllData; + } + + public static Integer truncateStringAtSpace(String inputString) + { + Integer location = inputString.lastIndexOf(' '); + return location; + } + + static testMethod void testTruncateString() + { + String example = 'NEW DESCRIPTION 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ THIS IS LONG DESCRIPTION GREATER THAN 80 CHARACTER LIMIT FOR NAME TEST TRUNCATING'; + String nameString = Milestone1_General_Utility.processTaskName(example); + system.AssertEquals('NEW DESCRIPTION 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ THIS IS LONG...',nameString); + } } \ No newline at end of file diff --git a/src/classes/Milestone1_General_Utility.cls-meta.xml b/src/classes/Milestone1_General_Utility.cls-meta.xml index b6a4861..391832e 100644 --- a/src/classes/Milestone1_General_Utility.cls-meta.xml +++ b/src/classes/Milestone1_General_Utility.cls-meta.xml @@ -1,5 +1,10 @@ - 20.0 + 27.0 + + 1 + 816 + SDOC + Active diff --git a/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml b/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml index b6a4861..391832e 100644 --- a/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml +++ b/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml @@ -1,5 +1,10 @@ - 20.0 + 27.0 + + 1 + 816 + SDOC + Active diff --git a/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml b/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml index b6a4861..391832e 100644 --- a/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml +++ b/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml @@ -1,5 +1,10 @@ - 20.0 + 27.0 + + 1 + 816 + SDOC + Active diff --git a/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml b/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml index b6a4861..391832e 100644 --- a/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml +++ b/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml @@ -1,5 +1,10 @@ - 20.0 + 27.0 + + 1 + 816 + SDOC + Active diff --git a/src/classes/Milestone1_repeatCon.cls b/src/classes/Milestone1_repeatCon.cls index 942f581..bb9a17e 100644 --- a/src/classes/Milestone1_repeatCon.cls +++ b/src/classes/Milestone1_repeatCon.cls @@ -1,686 +1,712 @@ -/* -Copyright (c) 2011, salesforce.com, Inc. -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 salesforce.com, Inc. 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 HOLDER 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. - -*/ -public with sharing class Milestone1_repeatCon { - - public List filterList {get;set;} - public String filterItem {get;set;} - private final String ALL_ITEMS = system.label.Milestone1_AllItems; - private final String MY_TASKS = system.label.Milestone1_MyTasksOnly; - private final String MY_MILESTONES_ONLY = system.label.Milestone1_MyMilestonesOnly; - private final String MY_PROJECTS_AND_ITEMS = system.label.Milestone1_MyProjectsAndSubProjectItems; - private Date currentDay; - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - private List projectIds{get;set;} - private List milestoneIds{get;set;} - public List activeProjectList {get;set;} - public String selectedProject {get;set;} - - public List getAllProjectItems(){ - return [Select Id,Name from Milestone1_Project__c where Status__c ='Active' limit 500]; - } - - private Map getSelectedProject(){ - projectIds.clear(); - Map projMap=new Map(); - if(selectedProject == 'AllProjects' || selectedProject == null ) - { - List projList = getAllProjectItems(); - for(Milestone1_Project__c projObj : projList){ - projMap.put(projObj.id,projObj); - } - } - else{ - Milestone1_Project__c project=[Select id from Milestone1_Project__c where id =: selectedProject]; - projMap.put(project.id,project); - } - for(Id setId:projMap.keySet()) - projectIds.add(setId); - - return projMap; - } - - private Map getProjectSpecificMilestone(){ - milestoneIds.clear(); - Map milestonesMap=new Map(); - for(Milestone1_Milestone__c m:[Select Id from Milestone1_Milestone__c where Project__c in : projectIds limit 500]) - { - milestonesMap.put(m.Id,m); - // milestoneIds.add(m.Id); - } - for(Id setId:milestonesMap.keySet()) - milestoneIds.add(setId); - return milestonesMap; - } - - public void next() { - addMonth(1); - } - - public void prev() { - addMonth(-1); - } - - public void fiveDayView() - { - setMonth(currentDay); - month.getCurrentWeek(currentDay); - month.fiveDayView = true; - - } - - public void monthView() - { - month = new Milestone1_Month(currentDay); - filter(); - } - - public Milestone1_repeatCon() { - - currentDay = system.today(); // default to today - integer mo = currentDay.month(); - projectIds=new List(); - milestoneIds=new List(); - String m_param = System.currentPageReference().getParameters().get('mo'); - String y_param = System.currentPageReference().getParameters().get('yr'); - - // allow a month to be passed in on the url as mo=10 - if (m_param != null) { - integer mi = integer.valueOf(m_param); - if (mi > 0 && mi <= 12) { - currentDay = Date.newinstance(currentDay.year(),mi,currentDay.day()); - } - } - // and year as yr=2008 - if (y_param != null) { - integer yr = integer.valueOf(y_param); - currentDay = Date.newinstance(yr, currentDay.month(), currentDay.day()); - } - - filterList = new List{new SelectOption(ALL_ITEMS,ALL_ITEMS),new SelectOption(MY_PROJECTS_AND_ITEMS,MY_PROJECTS_AND_ITEMS),new SelectOption(MY_TASKS,MY_TASKS),new SelectOption(MY_MILESTONES_ONLY,MY_MILESTONES_ONLY)}; - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - activeProjectList=new List(); - activeProjectList.add(new SelectOption('AllProjects',' ')); - for(Milestone1_Project__c project:getAllProjectItems()){ - activeProjectList.add(new SelectOption(project.id,project.name)); - } - filterItem = ALL_ITEMS; - setMonth(currentDay); - fiveDayView(); - } - - public List getWeeks() { - system.assert(month!=null,'month is null'); - return month.getWeeks(); - } - - public Milestone1_Month getMonth() { return month; } - - - public void filter() - { - List filteredItems = new List(); - month.clearEvents(); - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - - - if(filterItem == ALL_ITEMS) - { - filteredItems = getAllItems(month.getValidDateRange()); - }else if(filterItem == MY_TASKS) - { - filteredItems = getMyTasksOnly(month.getValidDateRange()); - }else if(filterItem == MY_MILESTONES_ONLY) - { - filteredItems = getMyMilestonesOnly(month.getValidDateRange()); - }else if(filterItem == MY_PROJECTS_AND_ITEMS) - { - filteredItems = getMyProjectsAndItems(month.getValidDateRange()); - } - month.setEvents(filteredItems); - } - - private void setMonth(Date d) { - month = new Milestone1_Month(d); - - // system.assert(month != null); - // Date[] da = month.getValidDateRange(); // gather events that fall in this month - // month.setEvents(getAllItems(da)); // merge those events into the month class - filter(); - } - - private List getAllItems(Date[] da) - { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - getSelectedProject(); - getProjectSpecificMilestone(); - List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and id in :projectIds limit 500]; - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds LIMIT 500]; - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in :milestoneIds LIMIT 500]; - List events = new List(); - for(Milestone1_Project__c proj : projects) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); - events.add(calItem); - } - for(Milestone1_Milestone__c milestone : milestones) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); - events.add(calItem); - } - for(Milestone1_Task__c currTask : tasks) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); - events.add(calItem); - } - return events; - } - - private List getMyProjectsAndItems(Date[] da) - { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - getSelectedProject(); - getProjectSpecificMilestone(); - List events = new List(); - List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and id in :projectIds limit 500]; - List projectIds = new List(); - for(Milestone1_Project__c proj : projects) - { - projectIds.add(proj.Id); - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); - events.add(calItem); - } - - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds limit 500]; - List milestoneIds = new List(); - for(Milestone1_Milestone__c milestone : milestones) - { - milestoneIds.add(milestone.Id); - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); - events.add(calItem); - } - - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in:milestoneIds limit 500]; - for(Milestone1_Task__c currTask : tasks) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); - events.add(calItem); - } - - return events; - } - - - private List getMyMilestonesOnly(Date[] da) - { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - getSelectedProject(); - getProjectSpecificMilestone(); - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and Project__c in : projectIds LIMIT 500 ]; - List events = new List(); - for(Milestone1_Milestone__c milestone : milestones) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); - events.add(calItem); - } - return events; - } - - private List getMyTasksOnly(Date[] da) - { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - getSelectedProject(); - getProjectSpecificMilestone(); - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Assigned_To__c =:Userinfo.getUserId() and Project_Milestone__c in : milestoneIds LIMIT 500 ]; - List events = new List(); - for(Milestone1_Task__c currTask : tasks) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); - events.add(calItem); - } - return events; - } - - - private void addMonth(integer val) { - Date d = month.getFirstDate(); - d = d.addMonths(val); - setMonth(d); - } - - private Milestone1_Month month; - - - static testMethod void testController() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - } - - static testMethod void testControllerFilterTasks() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = testProject.id; - controller.filterItem = 'My Tasks Only'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - List mIds=new List(); - mIds.add(testMilestone.id); - List tasksList=[Select Id from Milestone1_Task__c where Assigned_To__c =:Userinfo.getUserId() and Project_Milestone__c in : mIds ]; - for(Milestone1_Task__c task:tasksList) - { - if(testTask.id==task.id) - system.assertEquals(task.id,testTask.id); - } - } - - static testMethod void testControllerFilterMilestones() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = testProject.id; - controller.filterItem = 'My Milestones Only'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - //system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - } - - static testMethod void testControllerFilterMyProjects() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = testProject.id; - controller.filterItem = 'My Projects And Sub-Project Items'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - } - - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ - static testMethod void testControllerFilterAllItems() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = testProject.id; - controller.filterItem = 'All Items'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - - } - - static testMethod void testControllerFilterAllItemsWithBlankProject() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - system.debug(testProject.name); - insert testProject; - - Milestone1_Project__c testProject1 = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject1.Status__c = 'Active'; - testProject1.Deadline__c = Date.today(); - insert testProject1; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Milestone__c testMilestone1 = Milestone1_Test_Utility.sampleMilestone(testProject1.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone1.Deadline__c = Date.today(); - testMilestone1.Complete__c = false; - insert testMilestone1; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - - Milestone1_Task__c testTask1 = Milestone1_Test_Utility.sampleTask(testMilestone1.Id); - testTask1.Complete__c = false; - testTask1.Start_Date__c = Date.today(); - testTask1.Due_Date__c = Date.today(); - insert testTask1; - - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = null; - controller.filterItem = 'All Items'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(projMap.containsKey(testProject1.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone1.id),true); - Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; - system.assertEquals(testTask.id,task.id); - - } - - -static testMethod void testControllerFilterMyProjectsWithBlankProject() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - system.debug(testProject.name); - insert testProject; - - Milestone1_Project__c testProject1 = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); - testProject1.Status__c = 'Active'; - testProject1.Deadline__c = Date.today(); - insert testProject1; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = 'AllProjects'; - controller.filterItem = 'My Projects And Sub-Project Items'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(projMap.containsKey(testProject.id),true); - system.assertEquals(projMap.containsKey(testProject1.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; - system.assertEquals(testTask.id,task.id); - } - - static testMethod void testControllerFilterMilestonesWithBlankProject() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - system.debug(testProject.name); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Milestone__c testMilestone1 = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone1.Deadline__c = Date.today(); - testMilestone1.Complete__c = false; - insert testMilestone1; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = null; - controller.filterItem = 'My Milestones Only'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); - system.assertEquals(milestonesMap.containsKey(testMilestone1.id),true); - - - } - - static testMethod void testControllerFilterTasksWithBlankProject() - { - Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); - testProject.Status__c = 'Active'; - testProject.Deadline__c = Date.today(); - system.debug(testProject.name); - insert testProject; - - Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); - testMilestone.Deadline__c = Date.today(); - testMilestone.Complete__c = false; - insert testMilestone; - - Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask.Complete__c = false; - testTask.Start_Date__c = Date.today(); - testTask.Due_Date__c = Date.today(); - insert testTask; - - Milestone1_Task__c testTask1 = Milestone1_Test_Utility.sampleTask(testMilestone.Id); - testTask1.Complete__c = false; - testTask1.Start_Date__c = Date.today(); - testTask1.Due_Date__c = Date.today(); - insert testTask1; - - test.startTest(); - Milestone1_repeatCon controller = new Milestone1_repeatCon(); - controller.next(); - controller.prev(); - controller.selectedProject = 'AllProjects'; - controller.filterItem = 'My Tasks Only'; - controller.filter(); - List weeksList = controller.getWeeks(); - test.stopTest(); - Map projMap= controller.getSelectedProject(); - Map milestonesMap=controller.getProjectSpecificMilestone(); - Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; - system.assertEquals(testTask.id,task.id); - task=[Select id,name from Milestone1_Task__c where id =: testTask1.id]; - system.assertEquals(testTask1.id,task.id); - } - - - +/* +Copyright (c) 2011, salesforce.com, Inc. +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 salesforce.com, Inc. 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 HOLDER 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. + +*/ +public with sharing class Milestone1_repeatCon { + + public List filterList {get;set;} + public String filterItem {get;set;} + private final String ALL_ITEMS = system.label.Milestone1_AllItems; + private final String MY_TASKS = system.label.Milestone1_MyTasksOnly; + private final String MY_MILESTONES_ONLY = system.label.Milestone1_MyMilestonesOnly; + private final String MY_PROJECTS_AND_ITEMS = system.label.Milestone1_MyProjectsAndSubProjectItems; + private Date currentDay; + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + private List projectIds{get;set;} + private List milestoneIds{get;set;} + public List activeProjectList {get;set;} + public String selectedProject {get;set;} + + public List getAllProjectItems(){ + /**************************************************************************************** + /* Author: Passage Technology (www.passagetech.com) * + /* Issue: https://github.com/ForceDotComLabs/Milestones-PM/issues/97 * + /* Comment: Added custom setting to enable configuration of project data to exclude.* + /****************************************************************************************/ + + string activeProjectQry; + List inactivePrjStatuses; + string inactivePrjQry = ''; + + if (Milestone1_Settings__c.getInstance().Calendar_Project_Statuses_To_Filter_Out__c == null ) { + activeProjectQry = 'Select Id, Name from Milestone1_Project__c'; + } else { + inactivePrjStatuses = Milestone1_Settings__c.getInstance().Calendar_Project_Statuses_To_Filter_Out__c.split(','); + + for(Integer i = 0 ; i < inactivePrjStatuses.size() ; i++) { + if (i == (inactivePrjStatuses.size() - 1)){ + inactivePrjQry += '\'' + inactivePrjStatuses[i].trim() + '\''; + } else { + inactivePrjQry += '\'' + inactivePrjStatuses[i].trim() + '\','; + } + } + + activeProjectQry = 'Select Id, Name from Milestone1_Project__c where Status__c NOT IN (' + inactivePrjQry + ')'; + + } + return Database.Query(activeProjectQry); + } + + private Map getSelectedProject(){ + projectIds.clear(); + Map projMap=new Map(); + if(selectedProject == 'AllProjects' || selectedProject == null ) + { + List projList = getAllProjectItems(); + for(Milestone1_Project__c projObj : projList){ + projMap.put(projObj.id,projObj); + } + } + else{ + Milestone1_Project__c project=[Select id from Milestone1_Project__c where id =: selectedProject]; + projMap.put(project.id,project); + } + for(Id setId:projMap.keySet()) + projectIds.add(setId); + + return projMap; + } + + private Map getProjectSpecificMilestone(){ + milestoneIds.clear(); + Map milestonesMap=new Map(); + for(Milestone1_Milestone__c m:[Select Id from Milestone1_Milestone__c where Project__c in : projectIds limit 500]) + { + milestonesMap.put(m.Id,m); + // milestoneIds.add(m.Id); + } + for(Id setId:milestonesMap.keySet()) + milestoneIds.add(setId); + return milestonesMap; + } + + public void next() { + addMonth(1); + } + + public void prev() { + addMonth(-1); + } + + public void fiveDayView() + { + setMonth(currentDay); + month.getCurrentWeek(currentDay); + month.fiveDayView = true; + + } + + public void monthView() + { + month = new Milestone1_Month(currentDay); + filter(); + } + + public Milestone1_repeatCon() { + + currentDay = system.today(); // default to today + integer mo = currentDay.month(); + projectIds=new List(); + milestoneIds=new List(); + String m_param = System.currentPageReference().getParameters().get('mo'); + String y_param = System.currentPageReference().getParameters().get('yr'); + + // allow a month to be passed in on the url as mo=10 + if (m_param != null) { + integer mi = integer.valueOf(m_param); + if (mi > 0 && mi <= 12) { + currentDay = Date.newinstance(currentDay.year(),mi,currentDay.day()); + } + } + // and year as yr=2008 + if (y_param != null) { + integer yr = integer.valueOf(y_param); + currentDay = Date.newinstance(yr, currentDay.month(), currentDay.day()); + } + + filterList = new List{new SelectOption(ALL_ITEMS,ALL_ITEMS),new SelectOption(MY_PROJECTS_AND_ITEMS,MY_PROJECTS_AND_ITEMS),new SelectOption(MY_TASKS,MY_TASKS),new SelectOption(MY_MILESTONES_ONLY,MY_MILESTONES_ONLY)}; + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + activeProjectList=new List(); + activeProjectList.add(new SelectOption('AllProjects',' ')); + for(Milestone1_Project__c project:getAllProjectItems()){ + activeProjectList.add(new SelectOption(project.id,project.name)); + } + filterItem = ALL_ITEMS; + setMonth(currentDay); + fiveDayView(); + } + + public List getWeeks() { + system.assert(month!=null,'month is null'); + return month.getWeeks(); + } + + public Milestone1_Month getMonth() { return month; } + + + public void filter() + { + List filteredItems = new List(); + month.clearEvents(); + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + + + if(filterItem == ALL_ITEMS) + { + filteredItems = getAllItems(month.getValidDateRange()); + }else if(filterItem == MY_TASKS) + { + filteredItems = getMyTasksOnly(month.getValidDateRange()); + }else if(filterItem == MY_MILESTONES_ONLY) + { + filteredItems = getMyMilestonesOnly(month.getValidDateRange()); + }else if(filterItem == MY_PROJECTS_AND_ITEMS) + { + filteredItems = getMyProjectsAndItems(month.getValidDateRange()); + } + month.setEvents(filteredItems); + } + + private void setMonth(Date d) { + month = new Milestone1_Month(d); + + // system.assert(month != null); + // Date[] da = month.getValidDateRange(); // gather events that fall in this month + // month.setEvents(getAllItems(da)); // merge those events into the month class + filter(); + } + + private List getAllItems(Date[] da) + { + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + getSelectedProject(); + getProjectSpecificMilestone(); + List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and id in :projectIds limit 500]; + List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds LIMIT 500]; + List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in :milestoneIds LIMIT 500]; + List events = new List(); + for(Milestone1_Project__c proj : projects) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); + events.add(calItem); + } + for(Milestone1_Milestone__c milestone : milestones) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); + events.add(calItem); + } + for(Milestone1_Task__c currTask : tasks) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); + events.add(calItem); + } + return events; + } + + private List getMyProjectsAndItems(Date[] da) + { + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + getSelectedProject(); + getProjectSpecificMilestone(); + List events = new List(); + List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and id in :projectIds limit 500]; + List projectIds = new List(); + for(Milestone1_Project__c proj : projects) + { + projectIds.add(proj.Id); + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); + events.add(calItem); + } + + List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds limit 500]; + List milestoneIds = new List(); + for(Milestone1_Milestone__c milestone : milestones) + { + milestoneIds.add(milestone.Id); + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); + events.add(calItem); + } + + List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in:milestoneIds limit 500]; + for(Milestone1_Task__c currTask : tasks) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); + events.add(calItem); + } + + return events; + } + + + private List getMyMilestonesOnly(Date[] da) + { + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + getSelectedProject(); + getProjectSpecificMilestone(); + List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and Project__c in : projectIds LIMIT 500 ]; + List events = new List(); + for(Milestone1_Milestone__c milestone : milestones) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); + events.add(calItem); + } + return events; + } + + private List getMyTasksOnly(Date[] da) + { + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + getSelectedProject(); + getProjectSpecificMilestone(); + List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Assigned_To__c =:Userinfo.getUserId() and Project_Milestone__c in : milestoneIds LIMIT 500 ]; + List events = new List(); + for(Milestone1_Task__c currTask : tasks) + { + Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); + events.add(calItem); + } + return events; + } + + + private void addMonth(integer val) { + Date d = month.getFirstDate(); + d = d.addMonths(val); + setMonth(d); + } + + private Milestone1_Month month; + + + static testMethod void testController() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + } + + static testMethod void testControllerFilterTasks() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = testProject.id; + controller.filterItem = 'My Tasks Only'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + List mIds=new List(); + mIds.add(testMilestone.id); + List tasksList=[Select Id from Milestone1_Task__c where Assigned_To__c =:Userinfo.getUserId() and Project_Milestone__c in : mIds ]; + for(Milestone1_Task__c task:tasksList) + { + if(testTask.id==task.id) + system.assertEquals(task.id,testTask.id); + } + } + + static testMethod void testControllerFilterMilestones() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = testProject.id; + controller.filterItem = 'My Milestones Only'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + //system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + } + + static testMethod void testControllerFilterMyProjects() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = testProject.id; + controller.filterItem = 'My Projects And Sub-Project Items'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + } + + /** + *Modified Date:04-20-2012. + *Owner:Persistent. + *Comment: To add an additional project filter. + *Bug #: 66. + */ + static testMethod void testControllerFilterAllItems() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = testProject.id; + controller.filterItem = 'All Items'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + + } + + static testMethod void testControllerFilterAllItemsWithBlankProject() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + system.debug(testProject.name); + insert testProject; + + Milestone1_Project__c testProject1 = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject1.Status__c = 'Active'; + testProject1.Deadline__c = Date.today(); + insert testProject1; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Milestone__c testMilestone1 = Milestone1_Test_Utility.sampleMilestone(testProject1.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone1.Deadline__c = Date.today(); + testMilestone1.Complete__c = false; + insert testMilestone1; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + + Milestone1_Task__c testTask1 = Milestone1_Test_Utility.sampleTask(testMilestone1.Id); + testTask1.Complete__c = false; + testTask1.Start_Date__c = Date.today(); + testTask1.Due_Date__c = Date.today(); + insert testTask1; + + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = null; + controller.filterItem = 'All Items'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(projMap.containsKey(testProject1.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone1.id),true); + Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; + system.assertEquals(testTask.id,task.id); + + } + + +static testMethod void testControllerFilterMyProjectsWithBlankProject() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + system.debug(testProject.name); + insert testProject; + + Milestone1_Project__c testProject1 = Milestone1_Test_Utility.sampleProject('UNIT TEST PROJECT NAME ABC123XYZ UNIQUE' + System.now()); + testProject1.Status__c = 'Active'; + testProject1.Deadline__c = Date.today(); + insert testProject1; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = 'AllProjects'; + controller.filterItem = 'My Projects And Sub-Project Items'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(projMap.containsKey(testProject.id),true); + system.assertEquals(projMap.containsKey(testProject1.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; + system.assertEquals(testTask.id,task.id); + } + + static testMethod void testControllerFilterMilestonesWithBlankProject() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + system.debug(testProject.name); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Milestone__c testMilestone1 = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone1.Deadline__c = Date.today(); + testMilestone1.Complete__c = false; + insert testMilestone1; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = null; + controller.filterItem = 'My Milestones Only'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + system.assertEquals(milestonesMap.containsKey(testMilestone.id),true); + system.assertEquals(milestonesMap.containsKey(testMilestone1.id),true); + + + } + + static testMethod void testControllerFilterTasksWithBlankProject() + { + Milestone1_Project__c testProject = Milestone1_Test_Utility.sampleProject('Trial Project ABCXYZ' + System.now()); + testProject.Status__c = 'Active'; + testProject.Deadline__c = Date.today(); + system.debug(testProject.name); + insert testProject; + + Milestone1_Milestone__c testMilestone = Milestone1_Test_Utility.sampleMilestone(testProject.Id,null,'UNIT TEST MILESTONE NAME ACB123XYZ UNIQUE' + System.now()); + testMilestone.Deadline__c = Date.today(); + testMilestone.Complete__c = false; + insert testMilestone; + + Milestone1_Task__c testTask = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask.Complete__c = false; + testTask.Start_Date__c = Date.today(); + testTask.Due_Date__c = Date.today(); + insert testTask; + + Milestone1_Task__c testTask1 = Milestone1_Test_Utility.sampleTask(testMilestone.Id); + testTask1.Complete__c = false; + testTask1.Start_Date__c = Date.today(); + testTask1.Due_Date__c = Date.today(); + insert testTask1; + + test.startTest(); + Milestone1_repeatCon controller = new Milestone1_repeatCon(); + controller.next(); + controller.prev(); + controller.selectedProject = 'AllProjects'; + controller.filterItem = 'My Tasks Only'; + controller.filter(); + List weeksList = controller.getWeeks(); + test.stopTest(); + Map projMap= controller.getSelectedProject(); + Map milestonesMap=controller.getProjectSpecificMilestone(); + Milestone1_Task__c task=[Select id,name from Milestone1_Task__c where id =: testTask.id]; + system.assertEquals(testTask.id,task.id); + task=[Select id,name from Milestone1_Task__c where id =: testTask1.id]; + system.assertEquals(testTask1.id,task.id); + } + + + } \ No newline at end of file diff --git a/src/classes/Milestone1_repeatCon.cls-meta.xml b/src/classes/Milestone1_repeatCon.cls-meta.xml index b6a4861..391832e 100644 --- a/src/classes/Milestone1_repeatCon.cls-meta.xml +++ b/src/classes/Milestone1_repeatCon.cls-meta.xml @@ -1,5 +1,10 @@ - 20.0 + 27.0 + + 1 + 816 + SDOC + Active diff --git a/src/objects/Milestone1_Settings__c.object b/src/objects/Milestone1_Settings__c.object index 697802a..64a7064 100644 --- a/src/objects/Milestone1_Settings__c.object +++ b/src/objects/Milestone1_Settings__c.object @@ -31,6 +31,15 @@ Checkbox + + Calendar_Project_Statuses_To_Filter_Out__c + false + + 255 + false + Text + false + Default_Milestone_Alias__c Default milestone for email to task. From 9be1becf237784753de20f2f24eed1b9dc07709f Mon Sep 17 00:00:00 2001 From: Brent Gossett Date: Mon, 3 Jun 2013 13:36:56 -0500 Subject: [PATCH 2/5] Milestone1_General_Utility.isSysAdmin Update --- src/classes/Milestone1_General_Utility.cls | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/classes/Milestone1_General_Utility.cls b/src/classes/Milestone1_General_Utility.cls index 79070d1..7019dc2 100644 --- a/src/classes/Milestone1_General_Utility.cls +++ b/src/classes/Milestone1_General_Utility.cls @@ -52,8 +52,23 @@ public with sharing class Milestone1_General_Utility * @createDate January 19, 2011 */ public static Boolean isSysAdmin() { - Profile pObj = [SELECT PermissionsModifyAllData, Id FROM Profile WHERE Id=:Userinfo.getProfileId() limit 1]; - return pObj.PermissionsModifyAllData; + /**************************************************************************************************** + /* Author: Passage Technology (www.passagetech.com) * + /* Issue: It is possible to have a user without a profile Id. * + /* http://www.salesforce.com/us/developer/docs/packagingGuide/Content/apex_post_install_script.htm * + /* Comment: This fix resolves an error on no rows to assign to SObject. * + /****************************************************************************************************/ + + Profile pObj; + + for(Profile p : [SELECT PermissionsModifyAllData, Id FROM Profile WHERE Id=:Userinfo.getProfileId()]) { + pObj = p; + } + if(pObj == null) { + return true; + } else { + return pObj.PermissionsModifyAllData; + } } public static Integer truncateStringAtSpace(String inputString) From 5ca9b9ae881b0eb7c60622879f58ff864c6eb7c2 Mon Sep 17 00:00:00 2001 From: Brent Gossett Date: Mon, 3 Jun 2013 13:44:51 -0500 Subject: [PATCH 3/5] Salesforce API v27.0 --- .../Milestone1_Milestone_Trigger_Utility.cls-meta.xml | 5 ----- src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml | 5 ----- src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml | 5 ----- src/classes/Milestone1_repeatCon.cls-meta.xml | 5 ----- 4 files changed, 20 deletions(-) diff --git a/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml b/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml index 391832e..6dc8b22 100644 --- a/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml +++ b/src/classes/Milestone1_Milestone_Trigger_Utility.cls-meta.xml @@ -1,10 +1,5 @@ 27.0 - - 1 - 816 - SDOC - Active diff --git a/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml b/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml index 391832e..6dc8b22 100644 --- a/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml +++ b/src/classes/Milestone1_Milestone_Values_Helper.cls-meta.xml @@ -1,10 +1,5 @@ 27.0 - - 1 - 816 - SDOC - Active diff --git a/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml b/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml index 391832e..6dc8b22 100644 --- a/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml +++ b/src/classes/Milestone1_Project_Trigger_Utility.cls-meta.xml @@ -1,10 +1,5 @@ 27.0 - - 1 - 816 - SDOC - Active diff --git a/src/classes/Milestone1_repeatCon.cls-meta.xml b/src/classes/Milestone1_repeatCon.cls-meta.xml index 391832e..6dc8b22 100644 --- a/src/classes/Milestone1_repeatCon.cls-meta.xml +++ b/src/classes/Milestone1_repeatCon.cls-meta.xml @@ -1,10 +1,5 @@ 27.0 - - 1 - 816 - SDOC - Active From 89ea42eadbec1dcffed97b8a71cb5f57198e7ccc Mon Sep 17 00:00:00 2001 From: Brent Gossett Date: Mon, 3 Jun 2013 13:46:36 -0500 Subject: [PATCH 4/5] Milestone1_General_Utility API version 27.0 --- src/classes/Milestone1_General_Utility.cls-meta.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/classes/Milestone1_General_Utility.cls-meta.xml b/src/classes/Milestone1_General_Utility.cls-meta.xml index 391832e..6dc8b22 100644 --- a/src/classes/Milestone1_General_Utility.cls-meta.xml +++ b/src/classes/Milestone1_General_Utility.cls-meta.xml @@ -1,10 +1,5 @@ 27.0 - - 1 - 816 - SDOC - Active From 580e907b718417ea890ee56234a935f67480245e Mon Sep 17 00:00:00 2001 From: Brent Gossett Date: Thu, 13 Jun 2013 12:43:18 -0500 Subject: [PATCH 5/5] Calendar Limits Revised hard coded limit statements to stay within the Visualforce collection size limit. --- src/classes/Milestone1_repeatCon.cls | 245 +++++++++++++++++++-------- 1 file changed, 176 insertions(+), 69 deletions(-) diff --git a/src/classes/Milestone1_repeatCon.cls b/src/classes/Milestone1_repeatCon.cls index bb9a17e..5e8fe2b 100644 --- a/src/classes/Milestone1_repeatCon.cls +++ b/src/classes/Milestone1_repeatCon.cls @@ -28,12 +28,23 @@ OF THE POSSIBILITY OF SUCH DAMAGE. */ public with sharing class Milestone1_repeatCon { +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Issue: https://github.com/ForceDotComLabs/Milestones-PM/issues/97 * +/* Comment: Added custom setting to enable configuration of project data to exclude.* +/* Revised hard coded limit statements to stay within the Visualforce * +/* collection size limit. * +/****************************************************************************************/ + public List filterList {get;set;} public String filterItem {get;set;} private final String ALL_ITEMS = system.label.Milestone1_AllItems; private final String MY_TASKS = system.label.Milestone1_MyTasksOnly; private final String MY_MILESTONES_ONLY = system.label.Milestone1_MyMilestonesOnly; private final String MY_PROJECTS_AND_ITEMS = system.label.Milestone1_MyProjectsAndSubProjectItems; + + //As of Winter 2013, maxiumum records displayed on a Visualforce page is 1,000. + private final Integer MAX_RECORD_DISPLAY = 1000; private Date currentDay; /** *Modified Date:04-20-2012. @@ -46,12 +57,13 @@ public with sharing class Milestone1_repeatCon { public List activeProjectList {get;set;} public String selectedProject {get;set;} +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Method: getAllProjectItems() * +/* Comment: Added custom setting to enable configuration of project data to exclude.* +/****************************************************************************************/ + public List getAllProjectItems(){ - /**************************************************************************************** - /* Author: Passage Technology (www.passagetech.com) * - /* Issue: https://github.com/ForceDotComLabs/Milestones-PM/issues/97 * - /* Comment: Added custom setting to enable configuration of project data to exclude.* - /****************************************************************************************/ string activeProjectQry; List inactivePrjStatuses; @@ -70,7 +82,9 @@ public with sharing class Milestone1_repeatCon { } } - activeProjectQry = 'Select Id, Name from Milestone1_Project__c where Status__c NOT IN (' + inactivePrjQry + ')'; + activeProjectQry = 'Select Id, Name' + + ' FROM Milestone1_Project__c' + + ' WHERE Status__c NOT IN (' + inactivePrjQry + ')'; } return Database.Query(activeProjectQry); @@ -99,7 +113,9 @@ public with sharing class Milestone1_repeatCon { private Map getProjectSpecificMilestone(){ milestoneIds.clear(); Map milestonesMap=new Map(); - for(Milestone1_Milestone__c m:[Select Id from Milestone1_Milestone__c where Project__c in : projectIds limit 500]) + for(Milestone1_Milestone__c m:[Select Id + from Milestone1_Milestone__c + where Project__c in : projectIds]) { milestonesMap.put(m.Id,m); // milestoneIds.add(m.Id); @@ -214,90 +230,173 @@ public with sharing class Milestone1_repeatCon { // month.setEvents(getAllItems(da)); // merge those events into the month class filter(); } - + +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Method: getAllItems(Date[]) * +/* Comment: Revised hard coded limit statements to stay within the Visualforce * +/* collection size limit. * +/****************************************************************************************/ private List getAllItems(Date[] da) { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ + List events = new List(); + Integer remainingItems = MAX_RECORD_DISPLAY; + getSelectedProject(); getProjectSpecificMilestone(); - List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and id in :projectIds limit 500]; - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds LIMIT 500]; - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in :milestoneIds LIMIT 500]; - List events = new List(); - for(Milestone1_Project__c proj : projects) + + for(Milestone1_Task__c currTask : [Select Id, Due_Date__c, Name + from Milestone1_Task__c + where Due_Date__c >=:da[0] + and Due_Date__c <= :da[1] + and Project_Milestone__c in :milestoneIds]) { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); - events.add(calItem); + events.add(new Milestone1_Calendar_Item( + currTask.Id, + currTask.Name, + currTask.Due_Date__c, + Milestone1_Calendar_Item.TASK_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; } - for(Milestone1_Milestone__c milestone : milestones) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); - events.add(calItem); + if(remainingItems > 0) { + for(Milestone1_Milestone__c milestone : [Select Id, Deadline__c, Name + from Milestone1_Milestone__c + where Deadline__c >=:da[0] + and Deadline__c <= :da[1] + and Project__c in :projectIds]) + { + events.add(new Milestone1_Calendar_Item( + milestone.Id, + milestone.Name, + milestone.Deadline__c, + Milestone1_Calendar_Item.MILESTONE_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; + } } - for(Milestone1_Task__c currTask : tasks) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); - events.add(calItem); + if(remainingItems > 0) { + for(Milestone1_Project__c proj : [Select Id, Deadline__c, Name + from Milestone1_Project__c + where Deadline__c >=:da[0] + and Deadline__c <= :da[1] + and id in :projectIds]) + { + events.add(new Milestone1_Calendar_Item( + proj.Id, + proj.Name, + proj.Deadline__c, + Milestone1_Calendar_Item.PROJECT_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; + } } return events; } +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Method: getMyProjectsAndItems(Date[]) * +/* Comment: Revised hard coded limit statements to stay within the Visualforce * +/* collection size limit. * +/****************************************************************************************/ private List getMyProjectsAndItems(Date[] da) { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ + Integer remainingItems = MAX_RECORD_DISPLAY; + List projectIds = new List(), + milestoneIds = new List(); + List events = new List(); + getSelectedProject(); getProjectSpecificMilestone(); - List events = new List(); - List projects = [Select Id, Deadline__c, Name from Milestone1_Project__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and id in :projectIds limit 500]; - List projectIds = new List(); - for(Milestone1_Project__c proj : projects) + + for(Milestone1_Project__c proj : [Select Id, Deadline__c, Name + from Milestone1_Project__c + where Deadline__c >=:da[0] + and Deadline__c <= :da[1] + and OwnerId =:Userinfo.getUserId() + and id in :projectIds]) { projectIds.add(proj.Id); - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(proj.Id,proj.Name,proj.Deadline__c,Milestone1_Calendar_Item.PROJECT_TYPE); - events.add(calItem); + events.add(new Milestone1_Calendar_Item( + proj.Id, + proj.Name, + proj.Deadline__c, + Milestone1_Calendar_Item.PROJECT_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; } - - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and Project__c in :projectIds limit 500]; - List milestoneIds = new List(); - for(Milestone1_Milestone__c milestone : milestones) - { - milestoneIds.add(milestone.Id); - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(milestone.Id,milestone.Name,milestone.Deadline__c,Milestone1_Calendar_Item.MILESTONE_TYPE); - events.add(calItem); + if(remainingItems > 0) { + for(Milestone1_Milestone__c milestone : [Select Id, Deadline__c, Name + from Milestone1_Milestone__c + where Deadline__c >=:da[0] + and Deadline__c <= :da[1] + and Project__c in :projectIds]) + { + milestoneIds.add(milestone.Id); + events.add(new Milestone1_Calendar_Item( + milestone.Id, + milestone.Name, + milestone.Deadline__c, + Milestone1_Calendar_Item.MILESTONE_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; + } } - - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Project_Milestone__c in:milestoneIds limit 500]; - for(Milestone1_Task__c currTask : tasks) - { - Milestone1_Calendar_Item calItem = new Milestone1_Calendar_Item(currTask.Id,currTask.Name,currTask.Due_Date__c,Milestone1_Calendar_Item.TASK_TYPE); - events.add(calItem); + if(remainingItems > 0) { + for(Milestone1_Task__c currTask : [Select Id, Due_Date__c, Name + from Milestone1_Task__c + where Due_Date__c >=:da[0] + and Due_Date__c <= :da[1] + and Project_Milestone__c in :milestoneIds]) + { + events.add(new Milestone1_Calendar_Item( + currTask.Id, + currTask.Name, + currTask.Due_Date__c, + Milestone1_Calendar_Item.TASK_TYPE + )); + remainingItems--; + if(remainingItems == 0) + break; + } + } return events; } +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Method: getMyMilestonesOnly(Date[]) * +/* Comment: Revised hard coded limit statements to stay within the Visualforce * +/* collection size limit. * +/****************************************************************************************/ private List getMyMilestonesOnly(Date[] da) { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ + getSelectedProject(); getProjectSpecificMilestone(); - List milestones = [Select Id, Deadline__c, Name from Milestone1_Milestone__c where Deadline__c >=:da[0] and Deadline__c <= :da[1] and OwnerId =:Userinfo.getUserId() and Project__c in : projectIds LIMIT 500 ]; + List milestones = [ + Select Id, Deadline__c, Name + from Milestone1_Milestone__c + where Deadline__c >=:da[0] + and Deadline__c <= :da[1] + and OwnerId =:Userinfo.getUserId() + and Project__c in : projectIds + LIMIT :MAX_RECORD_DISPLAY + ]; List events = new List(); for(Milestone1_Milestone__c milestone : milestones) { @@ -307,17 +406,25 @@ public with sharing class Milestone1_repeatCon { return events; } +/**************************************************************************************** +/* Author: Passage Technology (www.passagetech.com) * +/* Method: getMyTasksOnly(Date[]) * +/* Comment: Revised hard coded limit statements to stay within the Visualforce * +/* collection size limit. * +/****************************************************************************************/ private List getMyTasksOnly(Date[] da) { - /** - *Modified Date:04-20-2012. - *Owner:Persistent. - *Comment: To add an additional project filter. - *Bug #: 66. - */ getSelectedProject(); getProjectSpecificMilestone(); - List tasks = [Select Id, Due_Date__c, Name from Milestone1_Task__c where Due_Date__c >=:da[0] and Due_Date__c <= :da[1] and Assigned_To__c =:Userinfo.getUserId() and Project_Milestone__c in : milestoneIds LIMIT 500 ]; + List tasks = [ + Select Id, Due_Date__c, Name + from Milestone1_Task__c + where Due_Date__c >=:da[0] + and Due_Date__c <= :da[1] + and Assigned_To__c =:Userinfo.getUserId() + and Project_Milestone__c in : milestoneIds + LIMIT :MAX_RECORD_DISPLAY + ]; List events = new List(); for(Milestone1_Task__c currTask : tasks) {