Skip to content

Commit

Permalink
merged with translations
Browse files Browse the repository at this point in the history
  • Loading branch information
srenberg committed Jan 16, 2012
2 parents 2218898 + 22c2367 commit 787b3b3
Show file tree
Hide file tree
Showing 72 changed files with 3,812 additions and 678 deletions.
95 changes: 51 additions & 44 deletions src/classes/Milestone1_Clone_Project_Controller.cls
Expand Up @@ -88,51 +88,58 @@ public with sharing class Milestone1_Clone_Project_Controller {
}

public PageReference createClone(){
//create new project record
rec.Name = dummyProj.Name;
Milestone1_Project__c newProj = Milestone1_Clone_Utility.cloneProject(rec);
insert newProj;

//separate milestone records into parents and subs
List<Milestone1_Milestone__c> topMilestones = new List<Milestone1_Milestone__c>();
List<Milestone1_Milestone__c> bottomMilestones = new List<Milestone1_Milestone__c>();
for(Milestone1_Milestone__c oldMS : milestones){
if(oldMS.Parent_Milestone__c == null){
topMilestones.add(oldMS);
} else {
bottomMilestones.add(oldMS);
}
}

//clone and insert top milestone records
Map<String, Milestone1_Milestone__c> newTopMilestoneMap = Milestone1_Clone_Utility.cloneMilestonesIntoMap(topMilestones);
for(Milestone1_Milestone__c newMS : newTopMilestoneMap.values()){
newMS.Project__c = newProj.Id;
}
insert newTopMilestoneMap.values();

//clone and insert sub milestone records
Map<String, Milestone1_Milestone__c> newBottomMilestoneMap = Milestone1_Clone_Utility.cloneMilestonesIntoMap(bottomMilestones);
for(Milestone1_Milestone__c newMS : newBottomMilestoneMap.values()){
newMS.Project__c = newProj.Id;
newMS.Parent_Milestone__c = newTopMilestoneMap.get(newMS.Parent_Milestone__c).Id;
Savepoint preSave = Database.setSavepoint(); //set savepoint so we can rollback the whole save if there are errors
try{
//create new project record
rec.Name = dummyProj.Name;
Milestone1_Project__c newProj = Milestone1_Clone_Utility.cloneProject(rec);
insert newProj;

//separate milestone records into parents and subs
List<Milestone1_Milestone__c> topMilestones = new List<Milestone1_Milestone__c>();
List<Milestone1_Milestone__c> bottomMilestones = new List<Milestone1_Milestone__c>();
for(Milestone1_Milestone__c oldMS : milestones){
if(oldMS.Parent_Milestone__c == null){
topMilestones.add(oldMS);
} else {
bottomMilestones.add(oldMS);
}
}

//clone and insert top milestone records
Map<String, Milestone1_Milestone__c> newTopMilestoneMap = Milestone1_Clone_Utility.cloneMilestonesIntoMap(topMilestones);
for(Milestone1_Milestone__c newMS : newTopMilestoneMap.values()){
newMS.Project__c = newProj.Id;
}
insert newTopMilestoneMap.values();

//clone and insert sub milestone records
Map<String, Milestone1_Milestone__c> newBottomMilestoneMap = Milestone1_Clone_Utility.cloneMilestonesIntoMap(bottomMilestones);
for(Milestone1_Milestone__c newMS : newBottomMilestoneMap.values()){
newMS.Project__c = newProj.Id;
newMS.Parent_Milestone__c = newTopMilestoneMap.get(newMS.Parent_Milestone__c).Id;
}
insert newBottomMilestoneMap.values();

//collect all milestones into one map
Map<String, Milestone1_Milestone__c> allNewMilestoneMap = new Map<String, Milestone1_Milestone__c>();
allNewMilestoneMap.putAll(newTopMilestoneMap);
allNewMilestoneMap.putAll(newBottomMilestoneMap);

//clone and insert task records
List<Milestone1_Task__c> newTasks = Milestone1_Clone_Utility.cloneTasksIntoList(tasks);
for(Milestone1_Task__c newTask : newTasks){
newTask.Project_Milestone__c = allNewMilestoneMap.get(newTask.Project_Milestone__c).Id;
}
insert newTasks;

//direct user to cloned project's detail page
return new ApexPages.StandardController(newProj).view();
}catch(System.DMLException e){
ApexPages.addMessages(e); //show save error(s) on the visualforce page
Database.rollback(preSave); //rollback any completed saves if the transaction has errors
}
insert newBottomMilestoneMap.values();

//collect all milestones into one map
Map<String, Milestone1_Milestone__c> allNewMilestoneMap = new Map<String, Milestone1_Milestone__c>();
allNewMilestoneMap.putAll(newTopMilestoneMap);
allNewMilestoneMap.putAll(newBottomMilestoneMap);

//clone and insert task records
List<Milestone1_Task__c> newTasks = Milestone1_Clone_Utility.cloneTasksIntoList(tasks);
for(Milestone1_Task__c newTask : newTasks){
newTask.Project_Milestone__c = allNewMilestoneMap.get(newTask.Project_Milestone__c).Id;
}
insert newTasks;

//direct user to cloned project's detail page
return new ApexPages.StandardController(newProj).view();
return null;
}

}
10 changes: 5 additions & 5 deletions src/classes/Milestone1_Clone_Utility.cls
Expand Up @@ -26,15 +26,15 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Clone_Utility {
global with sharing class Milestone1_Clone_Utility {

public static Milestone1_Project__c cloneProject(Milestone1_Project__c rec){
global static Milestone1_Project__c cloneProject(Milestone1_Project__c rec){
Milestone1_Project__c newRec = rec.clone(false);
newRec.ImportID__c = rec.Id;
return newRec;
}

public static Map<String, Milestone1_Milestone__c> cloneMilestonesIntoMap(List<Milestone1_Milestone__c> recs){
global static Map<String, Milestone1_Milestone__c> cloneMilestonesIntoMap(List<Milestone1_Milestone__c> recs){
Map<String, Milestone1_Milestone__c> recMap = new Map<String, Milestone1_Milestone__c>();
for(Milestone1_Milestone__c rec : recs){
Milestone1_Milestone__c newRec = rec.clone(false);
Expand All @@ -44,7 +44,7 @@ public with sharing class Milestone1_Clone_Utility {
return recMap;
}

public static List<Milestone1_Task__c> cloneTasksIntoList(List<Milestone1_Task__c> recs){
global static List<Milestone1_Task__c> cloneTasksIntoList(List<Milestone1_Task__c> recs){
List<Milestone1_Task__c> newRecs = new List<Milestone1_Task__c>();
for(Milestone1_Task__c rec : recs){
Milestone1_Task__c newRec = rec.clone(false);
Expand All @@ -53,7 +53,7 @@ public with sharing class Milestone1_Clone_Utility {
return newRecs;
}

public static Map<String, Milestone1_Task__c> cloneTasksIntoMap(List<Milestone1_Task__c> recs){
global static Map<String, Milestone1_Task__c> cloneTasksIntoMap(List<Milestone1_Task__c> recs){
Map<String, Milestone1_Task__c> recMap = new Map<String, Milestone1_Task__c>();
for(Milestone1_Task__c rec : recs){
Milestone1_Task__c newRec = rec.clone(false);
Expand Down
18 changes: 9 additions & 9 deletions src/classes/Milestone1_Email_Handler.cls
Expand Up @@ -38,15 +38,15 @@ global class Milestone1_Email_Handler implements Messaging.InboundEmailHandler
Parent Milestone is looked up based on Milestone Alias provided in Subject.
*/

public static final String REGEX_FWD_RE = '^[ ]*((([Ff][Ww][Dd])|([Rr][Ee]))[ ]*:[ ]*)*';
public static String ERROR_USERS_NOT_FOUND = 'The User seaches for Assignment (To Address) and/or Ownership (From Address) did not find matches to users in Salesforce.';
public static String ERROR_SUBJECT_MISSING_ALIAS = 'The subject line did not contain a milestone alias.';
public static String ERROR_ALIAS_NOT_FOUND = 'The alias provided in subject line did not match a milestone alias in Salesforce.';
public static String ERROR_FROM_USER_NOT_FOUND = 'The email sender did not match a user in Salesforce.';
public static String ERROR_TO_USER_NOT_FOUND = 'The list of recipients did not have any matches to a user in Salesforce.';
public static String ERROR_TASK_NOT_FOUND = 'A matching task was not found for this Email thread in Salesforce. Salesforce was unable to attach this email to the notes for a task.';
public static String ERROR_SUBJECT_MISSING_TASK = 'The subject line did not contain a task.';
public static String ERROR_SUBJECT_MISSING = 'The subject line did is empty.';
public static final String REGEX_FWD_RE = system.label.RegexFwdRe;
public static String ERROR_USERS_NOT_FOUND = system.label.UsersNotFound;
public static String ERROR_SUBJECT_MISSING_ALIAS = system.label.SubjectMissingAlias;
public static String ERROR_ALIAS_NOT_FOUND = system.label.ALiasNotFound;
public static String ERROR_FROM_USER_NOT_FOUND = system.label.FromUsersNotFound;
public static String ERROR_TO_USER_NOT_FOUND = system.label.ToUsersNotFound;
public static String ERROR_TASK_NOT_FOUND = system.label.TaskNotFound;
public static String ERROR_SUBJECT_MISSING_TASK = system.label.SubjectMissingTask;
public static String ERROR_SUBJECT_MISSING = system.label.SubjectMissing;

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
{
Expand Down
6 changes: 3 additions & 3 deletions src/classes/Milestone1_Email_Utility.cls
Expand Up @@ -28,9 +28,9 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Email_Utility
{
public static final String EMAIL_SENDER_NAME = 'Project Milestone Nag Engine';
public static final String EMAIL_SUBJECT = 'Project Milestone Notification - Items require attention.';
public static final String EMAIL_BODY_START = 'The following Salesforce Project Milestone items are nagging you for attention: \n';
public static final String EMAIL_SENDER_NAME = system.label.ProjectMilestoneNagEngine;
public static final String EMAIL_SUBJECT = system.label.ProjectMilestoneNotification;
public static final String EMAIL_BODY_START = system.label.TheFollowingSalesforceProjectMilestoneItems;

public static Messaging.SingleEmailMessage buildEmail(List<Milestone1_Nag__c> nags, User recipient)
{
Expand Down
26 changes: 13 additions & 13 deletions src/classes/Milestone1_Export_Project_Controller.cls
Expand Up @@ -26,18 +26,18 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Export_Project_Controller {
global with sharing class Milestone1_Export_Project_Controller {

private final String ERROR_STRING_FILE_TOO_LONG =
'Project is too large to export. Total characters must be less than ' + Milestone1_Import_Project_Controller.MAX_FILE_SIZE +
'. Current export would be $1 characters long. Please edit your project and try again';
system.label.ProjectIsTooLarge + Milestone1_Import_Project_Controller.MAX_FILE_SIZE +
system.label.CurrentExport;

public Milestone1_Project__c rec {get; set;}
public Boolean exportSuccess{get;set;}
public Document doc{get;set;}
public String errorMessage {get; private set;}
global Milestone1_Project__c rec {get; set;}
global Boolean exportSuccess{get;set;}
global Document doc{get;set;}
global String errorMessage {get; private set;}

public Milestone1_Export_Project_Controller(ApexPages.StandardController stc)
global Milestone1_Export_Project_Controller(ApexPages.StandardController stc)
{
errorMessage = null;

Expand All @@ -49,7 +49,7 @@ public with sharing class Milestone1_Export_Project_Controller {
];
}

public void createExportXML()
global void createExportXML()
{
Milestone1_XML_Export_Utility xmlUtil = new Milestone1_XML_Export_Utility();
String xmlString = xmlUtil.buildProjectXmlString(rec.Id);
Expand All @@ -74,21 +74,21 @@ public with sharing class Milestone1_Export_Project_Controller {
*
* @result Boolean True if any error has been flagged
*/
public Boolean hasError(){
global Boolean hasError(){
return this.errorMessage != null;
}

public PageReference returnToProject()
global PageReference returnToProject()
{
return new ApexPages.StandardController(rec).view();
}

public PageReference returnToDocument()
global PageReference returnToDocument()
{
return new ApexPages.StandardController(doc).view();
}

public Document saveToDocument(String name, String xml, String description) {
global Document saveToDocument(String name, String xml, String description) {
Document d = new Document();
d.body = Blob.valueOf(xml);
d.ContentType = 'text/xml';
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Milestone1_GettingStartedController.cls
Expand Up @@ -43,7 +43,7 @@ public with sharing class Milestone1_GettingStartedController {
Milestone1_Settings__c settings = Milestone1_Settings__c.getOrgDefaults();

if (settings != null) {
lastResult = 'Settings already exist. No changes made.';
lastResult = system.label.SettingsAlreadyExistNoChanges;
} else {
settings = getInitialSettingsWithoutSave();

Expand Down
8 changes: 4 additions & 4 deletions src/classes/Milestone1_Import_Exception.cls
Expand Up @@ -28,9 +28,9 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Import_Exception extends Exception {

public static final String ERROR_NO_FILE_SELECTED = 'No import XML files selected. Please select an XML file to import.';
public static final String ERROR_EMPTY_XML = 'The Project cannot be null. This is a critical error during import of XML. Please try exporting and re-importing.';
public static final String ERROR_INVALID_XML = 'Import Failed -- Milestone was unable to import your file.';
public static final String ERROR_FILESIZE_TOO_LARGE = 'The XML file is too large.';
public static final String ERROR_NO_FILE_SELECTED = system.label.NoImportXMLFilesSelected;
public static final String ERROR_EMPTY_XML = system.label.TheProjectCannotBeNull;
public static final String ERROR_INVALID_XML = system.label.ImportFailed;
public static final String ERROR_FILESIZE_TOO_LARGE = system.label.TheXMLFileIsTooLarge;

}
30 changes: 15 additions & 15 deletions src/classes/Milestone1_Import_Project_Controller.cls
Expand Up @@ -26,21 +26,21 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Import_Project_Controller {
public Milestone1_Project__c project {get; set;}
public List<Document> docs {get;set;}
public List<SelectOption> docOptions {get;set;}
public String contentType {get;set;}
public String docId{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
public Integer docsSize {get;set;}
public Integer maxFileSize {get; set;}
public static Integer MAX_FILE_SIZE = 500000;
global with sharing class Milestone1_Import_Project_Controller {
global Milestone1_Project__c project {get; set;}
global List<Document> docs {get;set;}
global List<SelectOption> docOptions {get;set;}
global String contentType {get;set;}
global String docId{get;set;}
global string fileName{get;set;}
global Blob fileBody{get;set;}
global Integer docsSize {get;set;}
global Integer maxFileSize {get; set;}
global static Integer MAX_FILE_SIZE = 500000;

private static String CONTENT_ERROR = 'Content is not allowed in prolog.';
private static String CONTENT_ERROR = system.label.ContentIsNotAllowedInProlog;

public Milestone1_Import_Project_Controller(ApexPages.StandardSetController ssc)
global Milestone1_Import_Project_Controller(ApexPages.StandardSetController ssc)
{
docOptions = new List<SelectOption>();
docs = [Select Id, Name from Document where Name like: 'EXPORT %' ];
Expand All @@ -52,7 +52,7 @@ public with sharing class Milestone1_Import_Project_Controller {
docsSize = docs.size();
}

public PageReference importTemplateXML() {
global PageReference importTemplateXML() {

try {

Expand Down Expand Up @@ -92,7 +92,7 @@ public with sharing class Milestone1_Import_Project_Controller {
}


public String getDocumentXMLString()
global String getDocumentXMLString()
{
List<Document> docs = [Select Id, Body, ContentType From Document Where Id = :docId limit 1];
if(docs.size() != 0)
Expand Down
8 changes: 4 additions & 4 deletions src/classes/Milestone1_Milestone_Trigger_Utility.cls
Expand Up @@ -28,8 +28,8 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Milestone_Trigger_Utility {

public static final String INSUFFICIENT_PRIVILEGES_TO_ACCESS_PARENT_MILESTONE = 'Insufficient privileges to access parent milestone.';
public static final String INSUFFICIENT_PRIVILEGES_TO_ACCESS_PROJECT = 'Insufficient privileges to access project.';
public static final String INSUFFICIENT_PRIVILEGES_TO_ACCESS_PARENT_MILESTONE = system.label.InsufficientPrivilegesToAccessParentMilestone;
public static final String INSUFFICIENT_PRIVILEGES_TO_ACCESS_PROJECT = system.label.InsufficientPrivileges;

public static Boolean alreadyMadeParent = false;

Expand Down Expand Up @@ -66,7 +66,7 @@ public with sharing class Milestone1_Milestone_Trigger_Utility {
if(oldRec.Project__c != newRec.Project__c && newRec.Okay_to_Reparent__c == false){
//don't want to reparent if not OK to reparent.
allPassed = false;
newRec.Project__c.addError('Milestones should not be moved to different Projects, except through the "Move to New Project" button in Milestone list view.');
newRec.Project__c.addError(system.label.MilestonesShouldNotBeMoved);
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ public with sharing class Milestone1_Milestone_Trigger_Utility {
if(rec.Parent_Milestone__c != null){
// Parent milestone not accessible
if(parentMilestonesMap.get(rec.Parent_Milestone__c).Parent_Milestone__c != null){
rec.Parent_Milestone__c.addError('Sub-milestones can only go one level deep. Please select a top-level milestone as this record\'s parent milestone.');
rec.Parent_Milestone__c.addError(system.label.SubMilestonesCanOnlyGoOneLevelDeep);
} else {
rec.Project__c = parentMilestonesMap.get(rec.Parent_Milestone__c).Project__c;
}
Expand Down
10 changes: 5 additions & 5 deletions src/classes/Milestone1_Move_Exception.cls
Expand Up @@ -28,11 +28,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public with sharing class Milestone1_Move_Exception extends Exception{

public static final String ERROR_MILESTONE_ALREADY_ASSIGNED_PROJECT = 'A milestone you are attempting to move is already assigned to this project. Please review your selection and try again.';
public static final String ERROR_TASK_ALREADY_ASSIGNED_MILESTONE = 'A task you are attempting to move is already assigned to this milestone. Please review your selection and try again.';
public static final String ERROR_MILESTONE_COMPLETE = 'Milestone is Complete, the Task can not be moved';
public static final String ERROR_MILESTONE_HAS_SUCCESSORS = 'Top Level Milestone has successors and cannot be moved. Redirect those successors and try again.';
public static final String ERROR_MILESTONE_HAS_PREDECESSOR = 'Top Level Milestone has predecessor and cannot be moved. Remove that predecessor and try again.';
public static final String ERROR_MILESTONE_ALREADY_ASSIGNED_PROJECT = system.label.MilestoneYouAreAttempting;
public static final String ERROR_TASK_ALREADY_ASSIGNED_MILESTONE = system.label.TaskYouAreAttempting;
public static final String ERROR_MILESTONE_COMPLETE = system.label.MilestoneIsComplete;
public static final String ERROR_MILESTONE_HAS_SUCCESSORS = system.label.TopLevelMilestoneHasSuccessors;
public static final String ERROR_MILESTONE_HAS_PREDECESSOR = system.label.TopLevelMilestoneHasPredecessor;

static testMethod void testConstants()
{
Expand Down

0 comments on commit 787b3b3

Please sign in to comment.