Upload document with multiple custom property

cancel
Showing results for 
Search instead for 
Did you mean: 
Soprasteria
Customer

Upload document with multiple custom property

Jump to solution

Hello,

Here is my configuration Alfresco 5.2.4 with ADF 3.4
I'm facing a problem while importing document with a custom property that can take multiple string values.

Here is the content-model.xml

<constraints>
	<constraint name="multiplePropertylist" type="this.is.my.constraints.CustomConstraint">
		<parameter name="allowedValues">
			<list></list>
		</parameter>
		<parameter name="constraintName">
			<value>MultipleProperty</value>
		</parameter>
	</constraint>
</constraints>
<types>
<type name="document">
		<parent>cm:content</parent>
		<mandatory-aspects>
			<aspect>custom:data</aspect>
		</mandatory-aspects>
	</type>
</types>
<aspects>
	<aspect name="custom:data">
		...
		<properties>
			...
			<property name="multipleProperty">
				<type>d:text</type>
				<mandatory>true</mandatory>
				<multiple>true</multiple>
				<index enabled="true">
					<facetable>true</facetable>
				</index>
				<constraints>
					<constraint ref="multiplePropertylist"/>
				</constraints>
			</property>
		</properties>
		...
	</aspect>
</aspects>

When I upload a document, the event is stopped and a popup is opened allowing me to modify the properties :

onBeginUpload(event: UploadFilesEvent) {

    event.pauseUpload();

    let listFiles: FileModel[];
    listFiles = event.files || [];

    if (listFiles.length > 0) {

      const dialogUpload = this.dialog.open(DialogUploadComponent, {
        width: '1000px',
        autoFocus: false,
        data: {
          files: listFiles,
          type: 'document',
          mode: this.mode
        }
      });

      dialogUpload.afterClosed().subscribe(result => {

        if (result === 'OK') {
          event.resumeUpload();
        }

      });
    }
  }

Before closing the DialogUploadComponent popup, properties are setted to all files passed to the popup in listFiles :

uploadFiles() {
      const values = this.customForm.form.values;
      this.listFiles.forEach((file: FileModel)  => {
        file.options.nodeType = this.type;
        const properties = {};

        for (const key in values) {
          if (key !== AppConstants._PROPERTY_CM_NAME) {
            properties[key] = this.setValue(values[key]);
          }
        }
        file.options['properties'] = properties;
      });
		this.closeDialog('OK');
}

At that point, I can debug the process and see that multiple values are well passed to all files like this :

FileModel {status: 0, file: File, id: undefined, …}
	data: null
	errorCode: null
	extension: (...)
	file: File {…}
	id: undefined
	name: "toto.pdf"
	options:
		comment: undefined
		majorVersion: false
		newVersion: false
		nodeType: "document"
		parentId: "0f208ce6-bf7c-4e7d-8097-2f79d5a6abf8"
		path: ""
		properties:
			...
			multipleProperty: (2) ["4", "1"]
			...
	progress: {loaded: 0, total: 0, percent: 0}
	size: 15659
	status: 0


Then the UploadFilesEvent.resumeUpload() is emitted, and the next call is made to the backend :
POST http://localhost:4200/alfresco/api/-default-/public/alfresco/versions/1/nodes/0f208ce6-bf7c-4e7d-8097-2f79dAAAAAaa/children?autoRename=true&include=allowableOperations
Body :

------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="cm:title"

toto.pdf
------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="multipleProperty"

4
------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="multipleProperty"

1
------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="include"

allowableOperations
...
------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="autoRename"

true
------WebKitFormBoundarybVmxBA5ta4P5neSD
Content-Disposition: form-data; name="nodeType"

document
------WebKitFormBoundarybVmxBA5ta4P5neSD--

As a result, the document is saved with only one of the two value for the property "multipleProperty".

 

After that creation, it is possible to modify this property from the UI and add another value successfully, herre is the successful call :
PUT http://localhost:4200/alfresco/api/-default-/public/alfresco/versions/1/nodes/38b883ee-d5d4-4708-a797-3eb12BBBBbbb
Body :

{"name":"toto.pdf","properties":{"cm:title":"toto.pdf","multipleProperty":["8","1"]}}

Is it possible to pass multiple value while uploading a document ?

Thanks for your answers !
Charles REY

2 Solutions

Accepted Solutions
sufo
Established Member II

Re: Upload document with multiple custom property

Jump to solution

Seems that it works only on newer (6.2) version: https://issues.alfresco.com/jira/browse/MNT-21834

View solution in original post

Soprasteria
Customer

Re: Upload document with multiple custom property

Jump to solution

Here is the complete answer :

I understand that you're wondering why you're unable to set a multi-valued property on creating/uploading a node when using the createNode Rest API endpoint. This functionality is not supported in ACS 5.2, it is only available in ACS 6.2 onward (see here and here for information on how this can be done in 6.2).

In 5.2, you can use the updateNode call to add the multiple-values to the property of the new node like you already mentioned (https://api-explorer.alfresco.com/api-explorer/#!/nodes/updateNode).

View solution in original post

4 Replies
sufo
Established Member II

Re: Upload document with multiple custom property

Jump to solution

Seems that it works only on newer (6.2) version: https://issues.alfresco.com/jira/browse/MNT-21834

View solution in original post

Soprasteria
Customer

Re: Upload document with multiple custom property

Jump to solution

Thanks, I had the confirmation from Alfresco support team. This is only supported on 6.2.

I asked for a workaround and will post it back when I get the answer.

Soprasteria
Customer

Re: Upload document with multiple custom property

Jump to solution

Here is the complete answer :

I understand that you're wondering why you're unable to set a multi-valued property on creating/uploading a node when using the createNode Rest API endpoint. This functionality is not supported in ACS 5.2, it is only available in ACS 6.2 onward (see here and here for information on how this can be done in 6.2).

In 5.2, you can use the updateNode call to add the multiple-values to the property of the new node like you already mentioned (https://api-explorer.alfresco.com/api-explorer/#!/nodes/updateNode).

View solution in original post

EddieMay
Community Manager
Community Manager

Re: Upload document with multiple custom property

Jump to solution

Hi @Soprasteria 

Thanks for updating us on the workaround.

Best wishes,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!