[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; const hasUploadWidget = (<any> this.form).hasUpload;
if (hasUploadWidget) { if (hasUploadWidget) {
try { try {
await this.getFolderTask(appName, taskId); const processStorageCloudModel = await this.formCloudService.getProcessStorageFolderTask(appName, taskId).toPromise();
this.form.nodeId = this.nodeId; this.form.nodeId = processStorageCloudModel.nodeId;
this.form.contentHost = processStorageCloudModel.path;
} catch (error) { } catch (error) {
this.notificationService.openSnackMessage('The content repo is not configured'); 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() { saveTaskForm() {
if (this.form && this.appName && this.taskId) { if (this.form && this.appName && this.taskId) {
this.formCloudService this.formCloudService

View File

@@ -94,7 +94,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
} }
private uploadRawContent(file): Observable<any> { 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( .pipe(
map((response: any) => { map((response: any) => {
this.logService.info(response); this.logService.info(response);

View File

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

View File

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