Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cloud File Mgt/Permissions/PTECloudFileMgt.permissionset.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
permissionset 80400 PTECloudFileMgt
{
Assignable = true;
Permissions = tabledata "PTE Sharepoint Folders"=RIMD,
table "PTE Sharepoint Folders"=X,
codeunit "PTE File Mgt Sharepoint"=X,
page "PTE SH Folders List"=X;
}
39 changes: 39 additions & 0 deletions Cloud File Mgt/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"id": "2051d42a-342f-4d28-9b3e-ed86d590a40f",
"name": "Cloud File Mgt",
"publisher": "PrintVis A/S",
"version": "1.0.0.4",
"brief": "",
"description": "",
"privacyStatement": "",
"EULA": "",
"help": "",
"url": "",
"logo": "",
"dependencies": [
{
"id": "5452f323-059e-499a-9753-5d2c07eef904",
"name": "PrintVis",
"publisher": "PrintVis A/S",
"version": "26.0.0.0"
}
],
"screenshots": [],
"platform": "1.0.0.0",
"application": "26.0.0.0",
"idRanges": [
{
"from": 80400,
"to": 80419
}
],
"resourceExposurePolicy": {
"allowDebugging": true,
"allowDownloadingSource": true,
"includeSourceInSymbolFile": true
},
"runtime": "14.0",
"features": [
"NoImplicitWith"
]
}
37 changes: 37 additions & 0 deletions Cloud File Mgt/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Cloud File Mgt

PrintVisCloud File Mgt functionality makes it easy to upload and move files to and from SharePoint


## What this extension includes:

- Procedures that makes it possible to Up -/ Download files to and from SharePoint that is not connected with any PVS Cases, such as import of files that.
below is a snippte on how to use whare the only input is the folder id's from the "PTE Sharepoint Folders" table.

```
procedure DownloadFilesAndProcess(ImportFolderID: Code[50]; ArchiveFolderID: Code[50])
var
temp_CloudStorage: Record "PVS Cloud Storage" temporary;
FileMgt: Codeunit "PTE File Mgt Sharepoint";
TempBlob: Codeunit "Temp Blob";
CloudStorageManagement: Codeunit "PVS Cloud Storage Management";
ServerFileName: Text;
_InStream: InStream;
OStream: OutStream;
XMLImportProcess: Codeunit "XML Import Process" ;
begin
if not FileMgt.GetFilesList(ImportFolderID, temp_CloudStorage) then
exit;

if temp_CloudStorage.FindSet() then
repeat
TempBlob.CreateInStream(_InStream);
TempBlob.CreateOutStream(OStream);
CloudStorageManagement.DownloadServerFile(temp_CloudStorage, TempBlob, ServerFileName);

if XMLImportProcess.ProcessFileImport(_InStream) then
if ArchiveFolderID <> '' then
FileMgt.MoveFileToFolderWithID(temp_CloudStorage, ArchiveFolderID);
until temp_CloudStorage.Next() = 0;
end;
```
179 changes: 179 additions & 0 deletions Cloud File Mgt/src/Sharepoint/PTEFileMgtSharepoint.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
codeunit 80400 "PTE File Mgt Sharepoint"
{
SingleInstance = true;

procedure Helper_Upload_SingleFile(TempBlob: Codeunit "Temp Blob"; SubFolderPathId: Text; ServerFileName: Text)
var
TempCloudStorage: Record "PVS Cloud Storage" temporary;
begin
// *****************************************
// * Upload generated files using Sharepoint
// *****************************************
if SubFolderPathId = '' then
Error('No folder selected!');

if not TempCloudStorage.IsTemporary() then
Error('Not temporary!');
GlobalProvider := GlobalProvider::Graph;
CloudStorageManagement.FillBufferOnOpenPage(TempCloudStorage, AuthProviderRec, GlobalProvider, WriteAccessVisible, DeleteAccessVisible, ReadAccessVisible, SubFolderPathId, GlobalCaption);

TempCloudStorage.Reset();
TempCloudStorage.SetRange(Name, 'FolderName');

TempCloudStorage.SetRange(Type, TempCloudStorage.Type::Folder);
if TempCloudStorage.FindFirst() then
Helper_Upload_File(TempCloudStorage, TempBlob, ServerFileName)
else begin
TempCloudStorage.Reset();
TempCloudStorage.SetRange(Name, '.');
TempCloudStorage.SetRange(Type, TempCloudStorage.Type::Folder);
if TempCloudStorage.FindFirst() then
// Helper_CreateFolder(TempCloudStorage, SubFolderPath);
Helper_Upload_File(TempCloudStorage, TempBlob, ServerFileName);
end;
end;

local procedure Helper_Upload_File(var CloudStorage: Record "PVS Cloud Storage"; TempBlob: Codeunit "Temp Blob"; ServerFileName: Text): Boolean
var
NewFileID: Text;
begin
if CloudStorage.Provider = CloudStorage.Provider::Graph then
Helper_Upload_FileWithoutDialog(true, CloudStorage, NewFileID, TempBlob, ServerFileName);

exit(NewFileID <> '');
end;

local procedure Helper_Upload_FileWithoutDialog(inRefreshTree: Boolean; var outTempCloudStorageRec: Record "PVS Cloud Storage"; var outNewFileID: Text; TempBlob: Codeunit "Temp Blob"; ServerFileName: Text)
begin
if outTempCloudStorageRec.Type <> outTempCloudStorageRec.Type::Folder then
Error(SelectFolder_Lbl);

if ServerFileName <> '' then begin
MiscFct.OpenDialog(UploadStart_Lbl);
if GraphMgt.UploadFile(TempBlob, ServerFileName, outTempCloudStorageRec.ID, outNewFileID) then begin
MiscFct.CloseDialog();
if inRefreshTree then begin
outTempCloudStorageRec."Contents Count" += 1;
outTempCloudStorageRec.Modify();
GraphMgt.GetFolder(outTempCloudStorageRec.Level, outTempCloudStorageRec.ID, outTempCloudStorageRec.Name, false, outTempCloudStorageRec);
end;
end else begin
MiscFct.CloseDialog();
Error(UploadError_Lbl, NAVFileMgt.GetFileName(ServerFileName));
end;
end;

end;

procedure GetFilesList(FolderId: Text; var CloudStorage_Out: Record "PVS Cloud Storage" temporary): Boolean
var
AuthProviderRec_: Record "PVS Auth. Providers";
temp_CloudStorage_: Record "PVS Cloud Storage" temporary;
GlobalCaption_: Text;
GlobalProvider_: Option " ",Graph;
DeleteAccessVisible_: Boolean;
ReadAccessVisible_: Boolean;
WriteAccessVisible_: Boolean;
begin
GlobalProvider_ := GlobalProvider_::Graph;

CloudStorageManagement.FillBufferOnOpenPage(
temp_CloudStorage_, AuthProviderRec_, GlobalProvider_,
WriteAccessVisible_, DeleteAccessVisible_, ReadAccessVisible_,
FolderId, GlobalCaption_);

CloudStorageManagement.ExpandAll(temp_CloudStorage_, FolderId, 'Folder Expanding');
temp_CloudStorage_.SetRange(type, temp_CloudStorage_.type::File);
temp_CloudStorage_.SetFilter(Name, '<>%1|<>%2', '', '.');
temp_CloudStorage_.Reset();
temp_CloudStorage_.SetRange(type, temp_CloudStorage_.type::File);
temp_CloudStorage_.SetFilter(Name, '<>%1|<>%2', '', '.');
if not temp_CloudStorage_.FindSet() then
exit;
repeat
CloudStorage_Out := temp_CloudStorage_;
CloudStorage_Out.Insert();
until temp_CloudStorage_.Next() = 0;

exit(true);
end;

procedure FileExists(FolderId: Text; FileName: Text): Boolean //used in JDF APP
var
Temp_CloudStorage_Out: Record "PVS Cloud Storage" temporary;
begin
if not GetFilesList(FolderId, Temp_CloudStorage_Out) then
exit;

WHILE STRPOS(FileName, '\') <> 0 DO
FileName := CopyStr(FileName, 1 + STRPOS(FileName, '\'));

Temp_CloudStorage_Out.SetRange(Name, FileName);
if not Temp_CloudStorage_Out.IsEmpty then
exit(true)
end;

procedure GetFolderFromPath(Path: Text): Text[50]
var
Index: Integer;
Str: Text[50];
begin
Index := Path.LastIndexOf('/');
Str := CopyStr(Path, Index + 1, 50);
exit(Str);
end;


procedure GetFolderID(Code_in: Code[20]): Code[50];
var
Folders: Record "PTE Sharepoint Folders";
Folder_Error_Lbl: Label 'Can not find folder %1', Comment = '%1 = Folder Code';
begin
Folders.SetRange(CODE, Code_in);
if Folders.IsEmpty() then
Error(Folder_Error_Lbl, Code_in);

Folders.FindFirst();
exit(Folders."Folder Id")


end;

procedure MoveFileToFolderWithID(CloudStorage_: Record "PVS Cloud Storage" temporary; To_Folder_Id: Text)
var
FileMgtCloud: Codeunit "PTE File Mgt Sharepoint";
CloudStorageManagement_: Codeunit "PVS Cloud Storage Management";
CloudGraphManagement: Codeunit "PVS Cloud Graph Management";
TempBlob: Codeunit "Temp Blob";
_InStream: InStream;
OStream: OutStream;

ServerFileName: Text;
begin
if CloudStorage_.Type <> CloudStorage_.Type::File then
exit;

CloudStorageManagement_.DownloadServerFile(CloudStorage_, TempBlob, ServerFileName);
TempBlob.CreateInStream(_InStream);

TempBlob.CreateOutStream(OStream);
FileMgtCloud.Helper_Upload_SingleFile(TempBlob, To_Folder_Id, CloudStorage_.Name);

CloudGraphManagement.DeleteFile(CloudStorage_.ID, CloudStorage_.name, true);
end;

var
AuthProviderRec: Record "PVS Auth. Providers";
NAVFileMgt: Codeunit "File Management";
GraphMgt: Codeunit "PVS Cloud Graph Management";
CloudStorageManagement: Codeunit "PVS Cloud Storage Management";
MiscFct: Codeunit "PVS Misc. Fct.";
DeleteAccessVisible: Boolean;
ReadAccessVisible: Boolean;
WriteAccessVisible: Boolean;
SelectFolder_Lbl: Label 'Please select a folder to upload the file to';
UploadError_Lbl: Label 'Uploading of file %1 failed', Comment = '%1 = File name';
UploadStart_Lbl: Label 'Uploading file to OneDrive...';
GlobalProvider: Option " ",Graph;
GlobalCaption: Text;
}
45 changes: 45 additions & 0 deletions Cloud File Mgt/src/Sharepoint/PTESHFoldersList.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
page 80400 "PTE SH Folders List"
{
Caption = 'Sharepoint Folders List';
PageType = List;
UsageCategory = Lists;
ApplicationArea = All;
SourceTable = "PTE Sharepoint Folders";
layout
{
area(Content)
{
repeater(Group)
{
field(CODE; rec.CODE)
{
ApplicationArea = All;
}
field("Folder Name"; rec."Folder Name")
{
ApplicationArea = all;
}
field(" Folder Path"; rec."Folder Path")
{
ApplicationArea = All;
trigger OnAssistEdit()
var
Folders: Record "PTE Sharepoint Folders";
begin
Folders._Folder_Path_OnAssistEdit_PathRoot(Rec);
CurrPage.Update(false);
end;
}
field(" Folder Id"; rec."Folder Id")
{
ApplicationArea = All;
}

}
}

}



}
76 changes: 76 additions & 0 deletions Cloud File Mgt/src/Sharepoint/PTESharepointFolders.Table.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
table 80400 "PTE Sharepoint Folders"
{
DataClassification = SystemMetadata;
Caption = 'Sharepoint Folders';
fields
{
field(1; CODE; Code[20])
{
Caption = 'Code';
ToolTip = 'Code for the table';
}
field(2; "Folder Path"; Text[2048])
{
Caption = 'Folder path';
ToolTip = 'The Folder path';
}
field(3; "Folder Name"; Text[50])
{
Caption = 'Folder Name';
ToolTip = 'Name of the Folder';
Editable = false;
}
field(4; "Folder Id"; Text[50])
{
Caption = 'Folder Id';
ToolTip = 'The Folder Id';
Editable = false;
}
}

keys
{
key(Key1; CODE)
{
Clustered = true;
}
}


trigger OnInsert()
begin

end;

trigger OnModify()
begin

end;

trigger OnDelete()
begin

end;

trigger OnRename()
begin

end;

internal procedure _Folder_Path_OnAssistEdit_PathRoot(Folders_: Record "PTE Sharepoint Folders")
var
GraphMgt: Codeunit "PVS Cloud Graph Management";
FileMgtCloud: Codeunit "PTE File Mgt Sharepoint";
NewID: Text[50];
FolderPath: Text;
begin
if GraphMgt.FilePicker(1, '', '', FolderPath, NewID) then begin
Folders_."Folder Id" := NewID;
if Folders_."Folder Id" <> '' then
Folders_."Folder Path" := CopyStr(FolderPath, 1, MaxStrLen(Folders_."Folder Path"));
end;
Folders_."Folder Name" := FileMgtCloud.GetFolderFromPath(Folders_."Folder Path");

Folders_.Modify(false);
end;
}
Loading