Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class G_FilesService {
- public Boolean modeService {get; set;}
- public G_FilesService(){
- modeService = true;
- }
- /**
- * @description This method allow us to switch over the implementation
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-12
- * @return void
- */
- public void switchToDummyImplementation(){
- modeService = false;
- }
- /**
- * @description This method retrieve a list of the current files stored on box associated to a record
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idPage The id of the current object
- * @param itemBegin The integer that tell the method the start point to get the files
- * @param itemLimit The integer that tell the method how many records to show from the itemBegin
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @param IdPrivateFolder String for the private or public folder
- * @return List of itemDetails
- */
- public List<itemDetails> getItems(Id idObject,Integer itemBegin, Integer itemLimit,boolean hierarchy, String NameOfClass, String IdPrivateFolder){
- return service(modeService, idObject, hierarchy,NameOfClass).getItems(Integer.valueOf(itemBegin), Integer.valueOf(itemLimit), IdPrivateFolder );
- }
- /**
- * @description This method retrieve the link to preview the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to preview
- * @param IdObject The Id of the object that the file belongs to
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return String as route to preview the file
- */
- public String PreviewLink(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
- return service(modeService, idObject, hierarchy,NameOfClass).getPreviewLink(idFile);
- }
- /**
- * @description This method retrieve the link to delete the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to delete
- * @param IdObject The Id of the object that the file belongs to
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return Boolean to indicate if the delete was successfully or not
- */
- public boolean deleteFile(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
- return service(modeService, idObject, hierarchy,NameOfClass).deleteFile(idFile);
- }
- /**
- * @description This method retrieve the link to download the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to download
- * @param IdObject The Id of the object that the file belongs to
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return String as route to donwload the file
- */
- public String downloadLink(String idFile, Id IdObject, boolean hierarchy,String NameOfClass){
- return service(modeService, idObject, hierarchy,NameOfClass).getDownloadLink(idFile);
- }
- /**
- * @description This method retrieve the information about the files on the box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFolder The id of the folder we are going to check
- * @param IdObject The Id of the object that the folder belongs to
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return String with format 'x-y' where x = Total items on the folder, y = start point of the files
- */
- public String getTotalItems(String idFolder, Id IdObject, boolean hierarchy,String NameOfClass){
- return service(modeService, idObject, hierarchy,NameOfClass).getTotalItemsValues(idFolder);
- }
- /**
- * @description This method create a folder of the current object in box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param herarchyPetition the boolean that represents if the current object its a root or a child
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return String that tell us if the folder was created
- */
- public String createTheFolder(boolean herarchyPetition, Id IdObject,String NameOfClass){
- service(modeService, idObject, herarchyPetition,NameOfClass).createFolderInBox();
- return 'Folder Successfully created';
- }
- /**
- * @description This method upload the file to box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param idFolder the string that represents the current box folder where the file is going to be uploaded
- * @param idNewFile The string of the file that just upload
- * @param IdObject The Id of the object that the folder belongs to
- * @param hierarchy Boolean to check if is a root folder
- * @param NameOfClass The string that contains the name of the class of the current object
- * @return String that notice us if it works
- */
- public String uploadFile(String idFolder, String idNewFile, Id IdObject, boolean hierarchy,String NameOfClass){
- service(modeService, idObject, hierarchy,NameOfClass).uploadFile(idFolder, idNewFile);
- return 'Succesfully';
- }
- /**
- * @description This method consult if the current object has a folder assoicated in box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass String that contains the name of the class that belongs to
- * @return String with the box folder id
- */
- public String thisObjectHasFolder(Id IdObject, String NameOfClass){
- return service(modeService, idObject, false, NameOfClass).thisObjectHasFolder(IdObject);
- }
- /**
- * @description This method consult the permission set of the current user
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass String that contains the name of the class that belongs to
- * @return boolean true if is allow to delete a file, false otherwise
- */
- public boolean thisUserCanDelete(Id IdObject, String NameOfClass){
- return service(modeService, idObject, false, NameOfClass).thisUserCanDelete();
- }
- /**
- * @description This method consult the permission set of the current user
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass String that contains the name of the class that belongs to
- * @return boolean true if is allow to see, false otherwise
- */
- public boolean thisUserCanUseFilesComponent(Id IdObject, String NameOfClass){
- return service(modeService, idObject, false, NameOfClass).thisUserCanUseFilesComponent();
- }
- /**
- * @description This method check is exists a private folder related to the current object
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass String that contains the name of the class that belongs to
- * @return String with the id of the private folder
- */
- public String existPrivateFolder(Id IdObject, String NameOfClass){
- return service(modeService, idObject, false, NameOfClass).existPrivateFolder();
- }
- /**
- * @description This method create a private folder
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param IdObject The Id of the object that the folder belongs to
- * @param NameOfClass String that contains the name of the class that belongs to
- * @return String with the id of the private folder we just create
- */
- public String createPrivateFilesFolder(Id IdObject, String NameOfClass){
- return service(modeService, idObject, false, NameOfClass).createPrivateFilesFolder();
- }
- private interface IFilesService{
- boolean deleteFile(String IdFile);
- List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String val);
- String getPreviewLink(String idFile);
- String getDownloadLink(String idFile);
- String getTotalItemsValues(String idFolder);
- void createFolderInBox();
- void uploadFile(String idFolder, String idNewFile);
- String thisObjectHasFolder(Id idObject);
- boolean thisUserCanDelete();
- boolean thisUserCanUseFilesComponent();
- String existPrivateFolder();
- String createPrivateFilesFolder();
- }
- /**
- * @author Christofer Flores
- * @date 11/11/2016
- * @description Frontend-Side Methods
- *
- */
- public class DummyImplementation implements IFilesService{
- /**
- * @description This method retrieve a list of the current files stored on box associated to a record
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param itemBegin The integer that tell the method the start point to get the files
- * @param itemLimit The integer that tell the method how many records to show from the itemBegin
- * @param val String to tell the method if is private or public folder
- * @return List of itemDetails
- */
- public List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String val){
- itemDetails file_1 = new itemDetails();
- file_1.Id = '00l41000gfebh31';
- file_1.FileName = 'services.pdf';
- file_1.CreatedDate = '20/12/16';
- file_1.ModifiedDate = '21//12/16';
- file_1.PreviewLink = 'https://www.google.com';
- itemDetails file_2 = new itemDetails();
- file_2.Id = '10e4p00efebh31';
- file_2.FileName = 'libros.txt';
- file_2.CreatedDate = '23/04/18';
- file_2.ModifiedDate = '25/04/19';
- file_2.PreviewLink = 'http://www.online-image-editor.com/';
- itemDetails file_3 = new itemDetails();
- file_3.Id = '10e4k0fefe2h31';
- file_3.FileName = 'charts_2015.jpg';
- file_3.CreatedDate = '11/10/15';
- file_3.ModifiedDate = '15/07/18';
- file_3.PreviewLink = 'http://www.online-image-editor.com/';
- List<itemDetails> files_data = new List<itemDetails> { file_1, file_2, file_3 };
- return files_data;
- }
- /**
- * @description This method retrieve the link to preview the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to preview
- * @return String as route to preview the file
- */
- public String getPreviewLink(String idFile){
- if(IdFile == null){
- return null;
- }
- return 'UrlToPreviewTheFile';
- }
- /**
- * @description This method retrieve the link to delete the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to delete
- * @return Boolean to indicate if the delete was successfully or not
- */
- public boolean deleteFile(String IdFile){
- if(IdFile == null){
- return false;
- }
- return true;
- }
- /**
- * @description This method retrieve the link to download the file
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFile The id of the file we want to download
- * @return String as route to donwload the file
- */
- public String getDownloadLink(String idFile){
- if(IdFile == null){
- return null;
- }
- return 'UrlToDownloadTheFile';
- }
- /**
- * @description This method retrieve the information about the files on the box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-29
- * @param idFolder The id of the folder we are going to check
- * @return String with format 'x-y' where x = Total items on the folder, y = start point of the files
- */
- public String getTotalItemsValues(String idFolder){
- if(idFolder == null){
- return null;
- }
- return '3-1';
- }
- /**
- * @description This method create a folder of the current object in box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @return void
- */
- public void createFolderInBox(){
- String hello = 'Hi everyone';
- }
- /**
- * @description This method upload the file to box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-11-30
- * @param idFolder the string that represents the current box folder where the file is going to be uploaded
- * @param idNewFile The string of the file that just upload
- * @return void
- */
- public void uploadFile(String idFolder, String idNewFile){
- String response = 'Should be uploading to Box.com';
- }
- /**
- * @description This method consult if the current object has a folder assoicated in box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-14
- * @param IdObject The Id of the object that the folder belongs to
- * @return String with the box folder id
- */
- public String thisObjectHasFolder(String idObject){
- return 'It Has Box Folder';
- }
- /**
- * @description This method check the permission set of the current user to check if is allow to delete files
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-14
- * @return boolean true if is allow, false otherwise
- */
- public boolean thisUserCanDelete(){
- return true;
- }
- /**
- * @description This method check if the user can use de component
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-14
- * @return boolean true if the user can use it, false otherwise
- */
- public boolean thisUserCanUseFilesComponent(){
- return true;
- }
- /**
- * @description This method consult if the current object has a private folder assoicated in box
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-14
- * @return String with the private box folder id
- */
- public string existPrivateFolder(){
- return '11506645590';
- }
- /**
- * @description This method create the private folder in box of the current object
- *
- * @author Christofer Flores, cristofer@softwareallies.com
- * @date 2016-12-14
- * @return String with the private box folder id that we just create
- */
- public string createPrivateFilesFolder(){
- return '11506645590';
- }
- }
- /**
- * @author Cristian Venegas
- * @date 11/11/2016
- * @description Production Box API Methods
- *
- */
- public class ProductionImplementation implements IFilesService{
- G_ObjectsUsingBoxInterface gobyObject;
- /**
- * @description This constructor initialize the related class of the current object
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param IdObject; id of current object sales force to instance the match class
- * @param hierarchy: Boolean value to know if the cration folder has a parent folder
- */
- public ProductionImplementation(Id IdObject, boolean hierarchy, String NameOfClass){
- gobyObject = (G_ObjectsUsingBoxInterface)Type.forName(NameOfClass).newInstance();
- gobyObject.constructor(IdObject, hierarchy);
- }
- /**
- * @description This method delete a file in box.com
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param IdFile; id of file stored in box
- * @return Boolean value to know if the box file are deleted
- */
- public boolean deleteFile(String IdFile){
- return gobyObject.deleteFile(IdFile);
- }
- /**
- * @description This method get a list of items from box.com
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param itemBegin; integer value of the list item going to start when get a list items
- * @param itemLimit; integer value about limit of items to get
- * @param idPrivateFolder; id folder box where the items is gonna get it
- * @return Boolean value to know if the box file are deleted
- */
- public List<itemDetails> getItems(Integer itemBegin, Integer itemLimit, String idPrivateFolder){
- return gobyObject.getRecordsItem(itemBegin, itemLimit, idPrivateFolder);
- }
- /**
- * @description This method get a preview link of a file stored in box
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param idFile; id of a file stored in box
- * @return String URL to can see the file on new tab
- */
- public String getPreviewLink(String idFile){
- return gobyObject.generatepreviewLink(idFile);
- }
- /**
- * @description This method get a termporal download link
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param idFile; id of a file stored in box
- * @return String URL to download the currently file
- */
- public String getDownloadLink(String idFile){
- return gobyObject.getDownloadLink(idFile);
- }
- /**
- * @description This method get the total items stored an folder box.com
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param idFolder; id of a folder stored in box
- * @return String value of a total items that this folder contains
- */
- public String getTotalItemsValues(String idFolder){
- return gobyObject.getTotalItems(idFolder);
- }
- /**
- * @description This method run the create folder in box making match with the current object from salesforce
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- */
- public void createFolderInBox(){
- gobyObject.createFolders();
- }
- /**
- * @description This method make a callout to webservice when the file is uploaded
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 8/12/2016
- * @param idFolder; id of a folder where the new file is gonna stored in box
- */
- public void uploadFile(String idFolder, String idNewFile){
- gobyObject.saveFileObject(idFolder, idNewFile);
- }
- /**
- * @description This method return a id of box folder
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 9/12/2016
- * @param idFolder; id of a current object
- */
- public String thisObjectHasFolder(String idObject){
- return gobyObject.thisObjectHasBoxId(idObject);
- }
- /**
- * @description This method return a boolean value to know if the current user have permissions to delete a file
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 9/12/2016
- */
- public boolean thisUserCanDelete(){
- return gobyObject.thisUserCanDelete();
- }
- /**
- * @description This method return a boolean value to know if the current user can use the files component
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 9/12/2016
- */
- public boolean thisUserCanUseFilesComponent(){
- return gobyObject.thisUserCanUseFilesComponent();
- }
- /**
- * @description This method return a boolean value to know if the current folder of a goby object have a private folder
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 9/12/2016
- */
- public string existPrivateFolder(){
- return gobyObject.existPrivateFolder();
- }
- /**
- * @description This method return a boolean value to know if the current folder of a goby object have a private folder
- * @author Cristian Venegas, cristian.venegas@softwareallies.com
- * @date 9/12/2016
- */
- public string createPrivateFilesFolder(){
- return gobyObject.createPrivateFilesFolder();
- }
- }
- private static IFilesService service(boolean Production, Id idObject, boolean hierarchy, String NameOfClass){
- return (Production ? (IFilesService) new ProductionImplementation(idObject, hierarchy,NameOfClass) : (IFilesService) new DummyImplementation());
- }
- /**
- * @author Christofer Flores
- * @date 11/11/2016
- * @description Inner Class
- *
- */
- public class itemDetails{
- @AuraEnabled
- public String Id { get; set; }
- @AuraEnabled
- public String PreviewLink { get; set; }
- @AuraEnabled
- public String FileName { get; set; }
- @AuraEnabled
- public String CreatedDate { get; set; }
- @AuraEnabled
- public String ModifiedDate { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement