[ADF-4550] Form Cloud - Be able to upload a file on the content taken from the process-storage (#4807)

* * Process-storage

* * Used jsapiServcie

* Be able to upload a file on the content with the createNode api

* Fix lint

* Refactor

* * Removed needless method.

* Remove useless method

* Add properties type
This commit is contained in:
Maurizio Vitale
2019-06-05 15:46:28 +01:00
committed by Eugenio Romano
parent 0684098f60
commit 67485daece
5 changed files with 41 additions and 33 deletions

View File

@@ -222,8 +222,9 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
const hasUploadWidget = (<any> this.form).hasUpload;
if (hasUploadWidget) {
try {
await this.getFolderTask(appName, taskId);
this.form.nodeId = this.nodeId;
const processStorageCloudModel = await this.formCloudService.getProcessStorageFolderTask(appName, taskId).toPromise();
this.form.nodeId = processStorageCloudModel.nodeId;
this.form.contentHost = processStorageCloudModel.path;
} catch (error) {
this.notificationService.openSnackMessage('The content repo is not configured');
}
@@ -235,10 +236,6 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
}
async getFolderTask(appName: string, taskId: string) {
this.nodeId = await this.formCloudService.getProcessStorageFolderTask(appName, taskId).toPromise();
}
saveTaskForm() {
if (this.form && this.appName && this.taskId) {
this.formCloudService

View File

@@ -94,7 +94,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
}
private uploadRawContent(file): Observable<any> {
return this.formCloudService.createTemporaryRawRelatedContent(file, this.field.form.nodeId)
return this.formCloudService.createTemporaryRawRelatedContent(file, this.field.form.nodeId, this.field.form.contentHost)
.pipe(
map((response: any) => {
this.logService.info(response);

View File

@@ -30,6 +30,7 @@ export class FormCloud {
readonly id: string;
nodeId: string;
contentHost: string;
readonly name: string;
readonly taskId: string;
readonly taskName: string;

View File

@@ -23,3 +23,16 @@ export class TaskVariableCloud {
this.value = obj.value || null;
}
}
export class ProcessStorageCloudModel {
nodeId: string;
path: string;
type: string;
constructor(obj) {
this.nodeId = obj.nodeId || null;
this.path = obj.path || null;
this.type = obj.type || null;
}
}

View File

@@ -22,7 +22,7 @@ import { catchError, map, switchMap } from 'rxjs/operators';
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
import { SaveFormRepresentation, CompleteFormRepresentation } from '@alfresco/js-api';
import { FormCloud } from '../models/form-cloud.model';
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
import { TaskVariableCloud, ProcessStorageCloudModel } from '../models/task-variable-cloud.model';
import { BaseCloudService } from '../../services/base-cloud.service';
@Injectable({
@@ -89,18 +89,19 @@ export class FormCloudService extends BaseCloudService {
);
}
createTemporaryRawRelatedContent(file, nodeId): Observable<any> {
createTemporaryRawRelatedContent(file: any, nodeId: string, contentHost: string): Observable<any> {
const apiUrl = this.buildUploadUrl(nodeId);
return from(this.apiService
.getInstance()
.oauth2Auth.callCustomApi(apiUrl, 'POST',
null, null, null,
{ filedata: file, nodeType: 'cm:content', overwrite: true }, null,
['multipart/form-data'], this.accepts,
this.returnType, null, null)
).pipe(
const changedConfig = this.apiService.lastConfig;
changedConfig.provider = 'ALL';
changedConfig.hostEcm = contentHost.replace('/alfresco', '');
this.apiService.getInstance().setConfig(changedConfig);
return from(this.apiService.getInstance().upload.uploadFile(
file,
'',
nodeId,
'',
{ overwrite: true }
)).pipe(
map((res: any) => {
return (res.entry);
}),
@@ -162,7 +163,7 @@ export class FormCloudService extends BaseCloudService {
);
}
getProcessStorageFolderTask(appName: string, taskId: string): Observable<any> {
getProcessStorageFolderTask(appName: string, taskId: string): Observable<ProcessStorageCloudModel> {
const apiUrl = this.buildFolderTask(appName, taskId);
return from(this.apiService
.getInstance()
@@ -173,7 +174,7 @@ export class FormCloudService extends BaseCloudService {
this.returnType, null, null)
).pipe(
map((res: any) => {
return res.nodeId;
return new ProcessStorageCloudModel(res);
}),
catchError((err) => this.handleError(err))
);
@@ -220,9 +221,9 @@ export class FormCloudService extends BaseCloudService {
apiUrl, 'GET', pathParams, queryParams,
headerParams, formParams, bodyParam,
this.contentTypes, this.accepts, this.returnType, null, null)
).pipe(
catchError((err) => this.handleError(err))
);
).pipe(
catchError((err) => this.handleError(err))
);
}
/**
@@ -232,11 +233,11 @@ export class FormCloudService extends BaseCloudService {
*/
getDropDownJsonData(url: string): Observable<FormFieldOption[]> {
return from(this.apiService.getInstance()
.oauth2Auth.callCustomApi(url, 'GET',
null, null, null,
null, null,
this.contentTypes, this.accepts,
this.returnType, null, null)
.oauth2Auth.callCustomApi(url, 'GET',
null, null, null,
null, null,
this.contentTypes, this.accepts,
this.returnType, null, null)
).pipe(
map((res: any) => {
return res;
@@ -281,10 +282,6 @@ export class FormCloudService extends BaseCloudService {
return `${this.getBasePath(appName)}/form/v1/forms/${formId}/save`;
}
private buildUploadUrl(nodeId: string): string {
return `${this.appConfigService.get('ecmHost')}/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/children`;
}
private buildSubmitFormUrl(appName: string, formId: string): string {
return `${this.getBasePath(appName)}/form/v1/forms/${formId}/submit`;
}