Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.91 KB | None | 0 0
  1. public with sharing class G_FilesService {
  2.     public Boolean modeService {get; set;}
  3.     public G_FilesService(){
  4.         modeService = true;
  5.     }
  6.     /**
  7.      * @description This method allow us to switch over the implementation
  8.      *
  9.      * @author      Christofer Flores, cristofer@softwareallies.com
  10.      * @date        2016-12-12
  11.      * @return      void
  12.     */
  13.     public void switchToDummyImplementation(){
  14.         modeService = false;
  15.     }
  16.    
  17.    
  18.     /**
  19.      * @description This method retrieve a list of the current files stored on box associated to a record
  20.      *
  21.      * @author      Christofer Flores, cristofer@softwareallies.com
  22.      * @date        2016-11-29
  23.      * @param   idPage The id of the current object
  24.      * @param   itemBegin The integer that tell the method the start point to get the files
  25.      * @param   itemLimit The integer that tell the method how many records to show from the itemBegin
  26.      * @param   hierarchy Boolean to check if is a root folder
  27.      * @param   NameOfClass The string that contains the name of the class of the current object
  28.      * @param   IdPrivateFolder String for the private or public folder
  29.      * @return      List of itemDetails
  30.     */
  31.     public List<itemDetails> getItems(Id idObject,Integer itemBegin, Integer itemLimit,boolean hierarchy, String NameOfClass, String IdPrivateFolder){
  32.         return service(modeService, idObject, hierarchy,NameOfClass).getItems(Integer.valueOf(itemBegin), Integer.valueOf(itemLimit), IdPrivateFolder );
  33.     }
  34.    
  35.     /**
  36.      * @description This method retrieve the link to preview the file
  37.      *
  38.      * @author      Christofer Flores, cristofer@softwareallies.com
  39.      * @date        2016-11-29
  40.      * @param   idFile The id of the file we want to preview
  41.      * @param   IdObject The Id of the object that the file belongs to
  42.      * @param   hierarchy Boolean to check if is a root folder
  43.      * @param   NameOfClass The string that contains the name of the class of the current object
  44.      * @return      String as route to preview the file
  45.     */
  46.     public String PreviewLink(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
  47.         return service(modeService, idObject, hierarchy,NameOfClass).getPreviewLink(idFile);
  48.     }
  49.    
  50.     /**
  51.      * @description This method retrieve the link to delete the file
  52.      *
  53.      * @author      Christofer Flores, cristofer@softwareallies.com
  54.      * @date        2016-11-29
  55.      * @param   idFile The id of the file we want to delete
  56.      * @param   IdObject The Id of the object that the file belongs to
  57.      * @param   hierarchy Boolean to check if is a root folder
  58.      * @param   NameOfClass The string that contains the name of the class of the current object
  59.      * @return      Boolean to indicate if the delete was successfully or not
  60.     */
  61.     public boolean deleteFile(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
  62.         return service(modeService, idObject, hierarchy,NameOfClass).deleteFile(idFile);
  63.     }
  64.    
  65.     /**
  66.      * @description This method retrieve the link to download the file
  67.      *
  68.      * @author      Christofer Flores, cristofer@softwareallies.com
  69.      * @date        2016-11-29
  70.      * @param   idFile The id of the file we want to download
  71.      * @param   IdObject The Id of the object that the file belongs to
  72.      * @param   hierarchy Boolean to check if is a root folder
  73.      * @param   NameOfClass The string that contains the name of the class of the current object
  74.      * @return      String as route to donwload the file
  75.     */
  76.     public String downloadLink(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
  77.         return service(modeService, idObject, hierarchy,NameOfClass).getDownloadLink(idFile);
  78.     }
  79.    
  80.     /**
  81.      * @description This method retrieve the information about the files on the box
  82.      *
  83.      * @author      Christofer Flores, cristofer@softwareallies.com
  84.      * @date        2016-11-29
  85.      * @param   idFolder The id of the folder we are going to check
  86.      * @param   IdObject The Id of the object that the folder belongs to
  87.      * @param   hierarchy Boolean to check if is a root folder
  88.      * @param   NameOfClass The string that contains the name of the class of the current object
  89.      * @return      String with format 'x-y' where x = Total items on the folder, y = start point of the files
  90.     */
  91.     public String getTotalItems(String idFolder, Id IdObject, boolean hierarchy,String NameOfClass){
  92.  
  93.         return service(modeService, idObject, hierarchy,NameOfClass).getTotalItemsValues(idFolder);
  94.     }
  95.    
  96.     /**
  97.      * @description This method create a folder of the current object in box
  98.      *
  99.      * @author      Christofer Flores, cristofer@softwareallies.com
  100.      * @date        2016-11-30
  101.      * @param   herarchyPetition the boolean that represents if the current object its a root or a child
  102.      * @param   IdObject The Id of the object that the folder belongs to
  103.      * @param   NameOfClass The string that contains the name of the class of the current object
  104.      * @return      String that tell us if the folder was created
  105.     */
  106.     public String createTheFolder(boolean herarchyPetition, Id IdObject,String NameOfClass){
  107.         service(modeService, idObject, herarchyPetition,NameOfClass).createFolderInBox();
  108.         return 'Folder Successfully created';
  109.     }
  110.    
  111.     /**
  112.      * @description This method upload the file to box
  113.      *
  114.      * @author      Christofer Flores, cristofer@softwareallies.com
  115.      * @date        2016-11-30
  116.      * @param   idFolder the string that represents the current box folder where the file is going to be uploaded
  117.      * @param   idNewFile The string of the file that just upload
  118.      * @param   IdObject The Id of the object that the folder belongs to
  119.      * @param   hierarchy Boolean to check if is a root folder
  120.      * @param   NameOfClass The string that contains the name of the class of the current object
  121.      * @return      String that notice us if it works
  122.     */
  123.     public String uploadFile(String idFolder, String idNewFile, Id IdObject, boolean hierarchy,String NameOfClass){
  124.         service(modeService, idObject, hierarchy,NameOfClass).uploadFile(idFolder, idNewFile);
  125.         return 'Succesfully';
  126.     }
  127.    
  128.     /**
  129.      * @description This method consult if the current object has a folder assoicated in box
  130.      *
  131.      * @author      Christofer Flores, cristofer@softwareallies.com
  132.      * @date        2016-11-30
  133.      * @param   IdObject The Id of the object that the folder belongs to
  134.      * @param   NameOfClass String that contains the name of the class that belongs to
  135.      * @return      String with the box folder id
  136.     */
  137.     public String thisObjectHasFolder(Id IdObject, String NameOfClass){
  138.         return service(modeService, idObject, false, NameOfClass).thisObjectHasFolder(IdObject);
  139.     }
  140.    
  141.     /**
  142.      * @description This method consult the permission set of the current user
  143.      *
  144.      * @author      Christofer Flores, cristofer@softwareallies.com
  145.      * @date        2016-11-30
  146.      * @param   IdObject The Id of the object that the folder belongs to
  147.      * @param   NameOfClass String that contains the name of the class that belongs to
  148.      * @return      boolean true if is allow to delete a file, false otherwise
  149.     */
  150.     public boolean thisUserCanDelete(Id IdObject, String NameOfClass){
  151.         return service(modeService, idObject, false, NameOfClass).thisUserCanDelete();
  152.     }
  153.    
  154.     /**
  155.      * @description This method consult the permission set of the current user
  156.      *
  157.      * @author      Christofer Flores, cristofer@softwareallies.com
  158.      * @date        2016-11-30
  159.      * @param   IdObject The Id of the object that the folder belongs to
  160.      * @param   NameOfClass String that contains the name of the class that belongs to
  161.      * @return      boolean true if is allow to see, false otherwise
  162.     */
  163.     public boolean thisUserCanUseFilesComponent(Id IdObject, String NameOfClass){
  164.         return service(modeService, idObject, false, NameOfClass).thisUserCanUseFilesComponent();
  165.     }
  166.    
  167.     /**
  168.      * @description This method check is exists a private folder related to the current object
  169.      *
  170.      * @author      Christofer Flores, cristofer@softwareallies.com
  171.      * @date        2016-11-30
  172.      * @param   IdObject The Id of the object that the folder belongs to
  173.      * @param   NameOfClass String that contains the name of the class that belongs to
  174.      * @return      String with the id of the private folder
  175.     */
  176.     public String existPrivateFolder(Id IdObject, String NameOfClass){
  177.         return service(modeService, idObject, false, NameOfClass).existPrivateFolder();
  178.     }
  179.    
  180.     /**
  181.      * @description This method create a private folder
  182.      *
  183.      * @author      Christofer Flores, cristofer@softwareallies.com
  184.      * @date        2016-11-30
  185.      * @param   IdObject The Id of the object that the folder belongs to
  186.      * @param   NameOfClass String that contains the name of the class that belongs to
  187.      * @return      String with the id of the private folder we just create
  188.     */
  189.     public String createPrivateFilesFolder(Id IdObject, String NameOfClass){
  190.         return service(modeService, idObject, false, NameOfClass).createPrivateFilesFolder();
  191.     }
  192.    
  193.    
  194.     private interface IFilesService{
  195.         boolean deleteFile(String IdFile);
  196.         List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String val);
  197.         String getPreviewLink(String idFile);
  198.         String getDownloadLink(String idFile);
  199.         String getTotalItemsValues(String idFolder);
  200.         void createFolderInBox();
  201.         void uploadFile(String idFolder, String idNewFile);
  202.         String thisObjectHasFolder(Id idObject);
  203.         boolean thisUserCanDelete();
  204.         boolean thisUserCanUseFilesComponent();
  205.         String existPrivateFolder();
  206.         String createPrivateFilesFolder();
  207.     }
  208.    
  209. /**
  210. * @author Christofer Flores
  211. * @date 11/11/2016
  212. * @description Frontend-Side Methods
  213. *
  214. */
  215.   public class DummyImplementation implements IFilesService{
  216.        
  217.         /**
  218.          * @description This method retrieve a list of the current files stored on box associated to a record
  219.          *
  220.          * @author      Christofer Flores, cristofer@softwareallies.com
  221.          * @date        2016-11-29
  222.          * @param   itemBegin The integer that tell the method the start point to get the files
  223.          * @param   itemLimit The integer that tell the method how many records to show from the itemBegin
  224.          * @param   val String to tell the method if is private or public folder
  225.          * @return      List of itemDetails
  226.         */
  227.         public List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String val){
  228.             itemDetails file_1       = new itemDetails();
  229.             file_1.Id                        = '00l41000gfebh31';
  230.             file_1.FileName              = 'services.pdf';
  231.             file_1.CreatedDate       = '20/12/16';
  232.             file_1.ModifiedDate      = '21//12/16';
  233.             file_1.PreviewLink       = 'https://www.google.com';
  234.             itemDetails file_2       = new itemDetails();
  235.             file_2.Id                        = '10e4p00efebh31';
  236.             file_2.FileName              = 'libros.txt';
  237.             file_2.CreatedDate       = '23/04/18';
  238.             file_2.ModifiedDate      = '25/04/19';
  239.             file_2.PreviewLink       = 'http://www.online-image-editor.com/';
  240.             itemDetails file_3       = new itemDetails();
  241.             file_3.Id                        = '10e4k0fefe2h31';
  242.             file_3.FileName              = 'charts_2015.jpg';
  243.             file_3.CreatedDate       = '11/10/15';
  244.             file_3.ModifiedDate      = '15/07/18';
  245.             file_3.PreviewLink       = 'http://www.online-image-editor.com/';
  246.             List<itemDetails> files_data = new List<itemDetails> {  file_1, file_2, file_3 };
  247.             return files_data;
  248.         }
  249.        
  250.         /**
  251.          * @description This method retrieve the link to preview the file
  252.          *
  253.          * @author      Christofer Flores, cristofer@softwareallies.com
  254.          * @date        2016-11-29
  255.          * @param   idFile The id of the file we want to preview
  256.          * @return      String as route to preview the file
  257.         */
  258.         public String getPreviewLink(String idFile){
  259.             if(IdFile == null){
  260.                 return null;   
  261.             }
  262.             return 'UrlToPreviewTheFile';
  263.         }
  264.        
  265.         /**
  266.          * @description This method retrieve the link to delete the file
  267.          *
  268.          * @author      Christofer Flores, cristofer@softwareallies.com
  269.          * @date        2016-11-29
  270.          * @param   idFile The id of the file we want to delete
  271.          * @return      Boolean to indicate if the delete was successfully or not
  272.         */
  273.         public boolean deleteFile(String IdFile){
  274.             if(IdFile == null){
  275.                 return false;  
  276.             }
  277.             return true;
  278.         }
  279.  
  280.         /**
  281.          * @description This method retrieve the link to download the file
  282.          *
  283.          * @author      Christofer Flores, cristofer@softwareallies.com
  284.          * @date        2016-11-29
  285.          * @param   idFile The id of the file we want to download
  286.          * @return      String as route to donwload the file
  287.         */
  288.         public String getDownloadLink(String idFile){
  289.             if(IdFile == null){
  290.                 return null;   
  291.             }
  292.             return 'UrlToDownloadTheFile';
  293.         }
  294.        
  295.        
  296.         /**
  297.          * @description This method retrieve the information about the files on the box
  298.          *
  299.          * @author      Christofer Flores, cristofer@softwareallies.com
  300.          * @date        2016-11-29
  301.          * @param   idFolder The id of the folder we are going to check
  302.          * @return      String with format 'x-y' where x = Total items on the folder, y = start point of the files
  303.         */
  304.         public String getTotalItemsValues(String idFolder){
  305.             if(idFolder == null){
  306.                 return null;   
  307.             }
  308.             return '3-1';
  309.         }
  310.        
  311.         /**
  312.          * @description This method create a folder of the current object in box
  313.          *
  314.          * @author      Christofer Flores, cristofer@softwareallies.com
  315.          * @date        2016-11-30
  316.          * @return      void
  317.         */
  318.         public void createFolderInBox(){
  319.             String hello = 'Hi everyone';
  320.         }
  321.        
  322.        
  323.         /**
  324.          * @description This method upload the file to box
  325.          *
  326.          * @author      Christofer Flores, cristofer@softwareallies.com
  327.          * @date        2016-11-30
  328.          * @param   idFolder the string that represents the current box folder where the file is going to be uploaded
  329.          * @param   idNewFile The string of the file that just upload
  330.          * @return      void
  331.         */
  332.         public void uploadFile(String idFolder, String idNewFile){
  333.             String response = 'Should be uploading to Box.com';
  334.         }
  335.        
  336.         /**
  337.          * @description This method consult if the current object has a folder assoicated in box
  338.          *
  339.          * @author      Christofer Flores, cristofer@softwareallies.com
  340.          * @date        2016-12-14
  341.          * @param   IdObject The Id of the object that the folder belongs to
  342.          * @return      String with the box folder id
  343.         */
  344.         public String thisObjectHasFolder(String idObject){
  345.             return 'It Has Box Folder';
  346.         }
  347.        
  348.         /**
  349.          * @description This method check the permission set of the current user to check if is allow to delete files
  350.          *
  351.          * @author      Christofer Flores, cristofer@softwareallies.com
  352.          * @date        2016-12-14
  353.          * @return      boolean true if is allow, false otherwise
  354.         */
  355.         public boolean thisUserCanDelete(){
  356.             return true;
  357.         }
  358.        
  359.         /**
  360.          * @description This method check if the user can use de component
  361.          *
  362.          * @author      Christofer Flores, cristofer@softwareallies.com
  363.          * @date        2016-12-14
  364.          * @return      boolean true if the user can use it, false otherwise
  365.         */
  366.         public boolean thisUserCanUseFilesComponent(){
  367.             return true;
  368.         }
  369.        
  370.         /**
  371.          * @description This method consult if the current object has a private folder assoicated in box
  372.          *
  373.          * @author      Christofer Flores, cristofer@softwareallies.com
  374.          * @date        2016-12-14
  375.          * @return      String with the private box folder id
  376.         */
  377.         public string existPrivateFolder(){
  378.             return '11506645590';
  379.         }
  380.        
  381.         /**
  382.          * @description This method create the private folder in box of the current object
  383.          *
  384.          * @author      Christofer Flores, cristofer@softwareallies.com
  385.          * @date        2016-12-14
  386.          * @return      String with the private box folder id that we just create
  387.         */
  388.         public string createPrivateFilesFolder(){
  389.             return '11506645590';
  390.         }
  391.        
  392.   }
  393.  
  394. /**
  395. * @author Cristian Venegas
  396. * @date 11/11/2016
  397. * @description Production Box API Methods
  398. *
  399. */
  400.   public class ProductionImplementation implements IFilesService{
  401.    
  402.     G_ObjectsUsingBoxInterface gobyObject;
  403.     /**
  404.      * @description This constructor initialize the related class of the current object
  405.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  406.      * @date    8/12/2016
  407.      * @param   IdObject; id of current object sales force to instance the match class
  408.      * @param   hierarchy: Boolean value to know if the cration folder has a parent folder
  409.     */  
  410.         public ProductionImplementation(Id IdObject, boolean hierarchy, String NameOfClass){
  411.             gobyObject = (G_ObjectsUsingBoxInterface)Type.forName(NameOfClass).newInstance();
  412.             gobyObject.constructor(IdObject, hierarchy);
  413.         }
  414.    
  415.     /**
  416.      * @description This method delete a file in box.com
  417.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  418.      * @date    8/12/2016
  419.      * @param   IdFile; id of file stored in box
  420.      * @return  Boolean value to know if the box file are deleted
  421.     */  
  422.         public boolean deleteFile(String IdFile){
  423.             return gobyObject.deleteFile(IdFile);
  424.         }
  425.     /**
  426.      * @description This method get a list of items from box.com
  427.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  428.      * @date    8/12/2016
  429.      * @param   itemBegin; integer value of the list item going to start when get a list items
  430.      * @param   itemLimit; integer value about limit of items to get
  431.      * @param   idPrivateFolder; id folder box where the items is gonna get it
  432.      * @return  Boolean value to know if the box file are deleted
  433.     */
  434.         public List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String idPrivateFolder){
  435.             return gobyObject.getRecordsItem(itemBegin, itemLimit, idPrivateFolder);
  436.         }
  437.     /**
  438.      * @description This method get a preview link of a file stored in box
  439.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  440.      * @date    8/12/2016
  441.      * @param   idFile; id of a file stored in box
  442.      * @return  String URL to can see the file on new tab
  443.     */  
  444.         public String getPreviewLink(String idFile){
  445.             return gobyObject.generatepreviewLink(idFile);
  446.         }
  447.     /**
  448.      * @description This method get a termporal download link
  449.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  450.      * @date    8/12/2016
  451.      * @param   idFile; id of a file stored in box
  452.      * @return  String URL to download the currently file
  453.     */         
  454.         public String getDownloadLink(String idFile){
  455.             return gobyObject.getDownloadLink(idFile);
  456.         }
  457.      /**
  458.      * @description This method get the total items stored an folder box.com
  459.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  460.      * @date    8/12/2016
  461.      * @param   idFolder; id of a folder stored in box
  462.      * @return  String value of a total items that this folder contains
  463.      */    
  464.         public String getTotalItemsValues(String idFolder){
  465.             return gobyObject.getTotalItems(idFolder);
  466.         }
  467.     /**
  468.      * @description This method run the create folder in box making match with the current object from salesforce
  469.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  470.      * @date    8/12/2016
  471.      */        
  472.         public void createFolderInBox(){
  473.             gobyObject.createFolders();
  474.         }
  475.     /**
  476.      * @description This method make a callout to webservice when the file is uploaded
  477.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  478.      * @date    8/12/2016
  479.      * @param   idFolder; id of a folder where the new file is gonna stored in box
  480.      */    
  481.         public void uploadFile(String idFolder, String idNewFile){
  482.             gobyObject.saveFileObject(idFolder, idNewFile);
  483.         }
  484.     /**
  485.      * @description This method return a id of box folder
  486.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  487.      * @date    9/12/2016
  488.      * @param   idFolder; id of a current object
  489.      */
  490.         public String thisObjectHasFolder(String idObject){
  491.             return gobyObject.thisObjectHasBoxId(idObject);
  492.         }
  493.     /**
  494.      * @description This method return a boolean value to know if the current user have permissions to delete a file
  495.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  496.      * @date    9/12/2016
  497.      */
  498.         public boolean thisUserCanDelete(){
  499.             return gobyObject.thisUserCanDelete();
  500.         }
  501.     /**
  502.      * @description This method return a boolean value to know if the current user can use the files component
  503.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  504.      * @date    9/12/2016
  505.      */    
  506.         public boolean thisUserCanUseFilesComponent(){
  507.             return gobyObject.thisUserCanUseFilesComponent();
  508.         }
  509.     /**
  510.      * @description This method return a boolean value to know if the current folder of a goby object have a private folder
  511.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  512.      * @date    9/12/2016
  513.      */
  514.         public string existPrivateFolder(){
  515.             return gobyObject.existPrivateFolder();
  516.         }
  517.     /**
  518.      * @description This method return a boolean value to know if the current folder of a goby object have a private folder
  519.      * @author  Cristian Venegas, cristian.venegas@softwareallies.com
  520.      * @date    9/12/2016
  521.      */
  522.         public string createPrivateFilesFolder(){
  523.             return gobyObject.createPrivateFilesFolder();
  524.         }
  525.   }
  526.    
  527.   private static IFilesService service(boolean Production, Id idObject, boolean hierarchy, String NameOfClass){
  528.     return (Production ? (IFilesService) new ProductionImplementation(idObject, hierarchy,NameOfClass) : (IFilesService) new DummyImplementation());
  529.   }
  530.  
  531.    
  532.   /**
  533.     * @author Christofer Flores
  534.     * @date 11/11/2016
  535.     * @description Inner Class
  536.     *
  537.  */
  538.   public class itemDetails{
  539.         @AuraEnabled
  540.         public String Id { get; set; }
  541.         @AuraEnabled
  542.         public String PreviewLink { get; set; }
  543.         @AuraEnabled
  544.         public String FileName { get; set; }
  545.         @AuraEnabled
  546.         public String CreatedDate { get; set; }
  547.         @AuraEnabled
  548.         public String ModifiedDate { get; set; }
  549.     }
  550. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement