diff --git a/modules/apps/headless/headless-builder/headless-builder-test/src/testIntegration/resources/com/liferay/headless/builder/resource/test/dependencies/expected_openapi.json b/modules/apps/headless/headless-builder/headless-builder-test/src/testIntegration/resources/com/liferay/headless/builder/resource/test/dependencies/expected_openapi.json index 14b011ad9a2e9c..8f9ae4ae82d6c2 100644 --- a/modules/apps/headless/headless-builder/headless-builder-test/src/testIntegration/resources/com/liferay/headless/builder/resource/test/dependencies/expected_openapi.json +++ b/modules/apps/headless/headless-builder/headless-builder-test/src/testIntegration/resources/com/liferay/headless/builder/resource/test/dependencies/expected_openapi.json @@ -30,7 +30,6 @@ "FileEntry": { "properties": { "externalReferenceCode": { - "readOnly": true, "type": "string" }, "fileBase64": { @@ -343,7 +342,6 @@ "type": "string" } }, - "readOnly": true, "type": "object", "xml": { "name": "Scope" diff --git a/modules/apps/object/object-api/bnd.bnd b/modules/apps/object/object-api/bnd.bnd index 863060d568445d..3fb6f4f6f01c09 100644 --- a/modules/apps/object/object-api/bnd.bnd +++ b/modules/apps/object/object-api/bnd.bnd @@ -1,6 +1,6 @@ Bundle-Name: Liferay Object API Bundle-SymbolicName: com.liferay.object.api -Bundle-Version: 93.0.1 +Bundle-Version: 94.0.0 Export-Package:\ com.liferay.object.action.engine,\ com.liferay.object.action.executor,\ diff --git a/modules/apps/object/object-api/src/main/java/com/liferay/object/field/attachment/AttachmentManager.java b/modules/apps/object/object-api/src/main/java/com/liferay/object/field/attachment/AttachmentManager.java index 9e393bb894cf1e..af7a11bfb207b3 100644 --- a/modules/apps/object/object-api/src/main/java/com/liferay/object/field/attachment/AttachmentManager.java +++ b/modules/apps/object/object-api/src/main/java/com/liferay/object/field/attachment/AttachmentManager.java @@ -18,17 +18,6 @@ */ public interface AttachmentManager { - public FileEntry addFileEntry( - long companyId, byte[] fileContent, String fileName, long groupId, - long objectFieldId, ServiceContext serviceContext) - throws Exception; - - public FileEntry addFileEntry( - long companyId, byte[] fileContent, String fileName, - String folderExternalReferenceCode, long groupId, - long objectFieldId, ServiceContext serviceContext) - throws Exception; - public String[] getAcceptedFileExtensions(long objectFieldId); public DLFolder getDLFolder( @@ -38,6 +27,18 @@ public DLFolder getDLFolder( public long getMaximumFileSize(long objectFieldId, boolean signedIn); + public FileEntry getOrAddFileEntry( + long companyId, String externalReferenceCode, byte[] fileContent, + String fileName, long groupId, long objectFieldId, + ServiceContext serviceContext) + throws Exception; + + public FileEntry getOrAddFileEntry( + long companyId, String externalReferenceCode, byte[] fileContent, + String fileName, String folderExternalReferenceCode, long groupId, + long objectFieldId, ServiceContext serviceContext) + throws Exception; + public void validateFileExtension(String fileName, long objectFieldId) throws FileExtensionException; diff --git a/modules/apps/object/object-api/src/main/resources/com/liferay/object/field/attachment/packageinfo b/modules/apps/object/object-api/src/main/resources/com/liferay/object/field/attachment/packageinfo index 682b435622a0aa..50447f66aecefa 100644 --- a/modules/apps/object/object-api/src/main/resources/com/liferay/object/field/attachment/packageinfo +++ b/modules/apps/object/object-api/src/main/resources/com/liferay/object/field/attachment/packageinfo @@ -1 +1 @@ -version 2.0.0 \ No newline at end of file +version 3.0.0 \ No newline at end of file diff --git a/modules/apps/object/object-rest-api/src/main/java/com/liferay/object/rest/dto/v1_0/FileEntry.java b/modules/apps/object/object-rest-api/src/main/java/com/liferay/object/rest/dto/v1_0/FileEntry.java index e38799805978ae..a61db45f528131 100644 --- a/modules/apps/object/object-rest-api/src/main/java/com/liferay/object/rest/dto/v1_0/FileEntry.java +++ b/modules/apps/object/object-rest-api/src/main/java/com/liferay/object/rest/dto/v1_0/FileEntry.java @@ -85,7 +85,7 @@ public void setExternalReferenceCode( } @GraphQLField - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String externalReferenceCode; @JsonIgnore @@ -330,7 +330,7 @@ public void setScope(UnsafeSupplier scopeUnsafeSupplier) { } @GraphQLField - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected Scope scope; @JsonIgnore diff --git a/modules/apps/object/object-rest-api/src/main/resources/com/liferay/object/rest/dto/v1_0/packageinfo b/modules/apps/object/object-rest-api/src/main/resources/com/liferay/object/rest/dto/v1_0/packageinfo index 11d305c736cf3a..4ab3d959e7b6be 100644 --- a/modules/apps/object/object-rest-api/src/main/resources/com/liferay/object/rest/dto/v1_0/packageinfo +++ b/modules/apps/object/object-rest-api/src/main/resources/com/liferay/object/rest/dto/v1_0/packageinfo @@ -1 +1 @@ -version 1.9.0 \ No newline at end of file +version 1.9.1 \ No newline at end of file diff --git a/modules/apps/object/object-rest-impl/rest-openapi.yaml b/modules/apps/object/object-rest-impl/rest-openapi.yaml index d1c67705bf60a8..df2b3d0ab24840 100644 --- a/modules/apps/object/object-rest-impl/rest-openapi.yaml +++ b/modules/apps/object/object-rest-impl/rest-openapi.yaml @@ -28,7 +28,6 @@ components: FileEntry: properties: externalReferenceCode: - readOnly: true type: string fileBase64: # @review @@ -48,7 +47,6 @@ components: type: string scope: $ref: "#/components/schemas/Scope" - readOnly: true type: object Folder: properties: diff --git a/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/dto/v1_0/converter/ObjectEntryDTOConverter.java b/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/dto/v1_0/converter/ObjectEntryDTOConverter.java index 2277f22fe36bdc..2c002a1d3a2c22 100644 --- a/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/dto/v1_0/converter/ObjectEntryDTOConverter.java +++ b/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/dto/v1_0/converter/ObjectEntryDTOConverter.java @@ -488,10 +488,39 @@ private FileEntry _getFileEntry( objectDefinition.getCompanyId(), "LPS-174455")) { fileEntry.setFileBase64( - () -> (String)NestedFieldsSupplier.supply( - objectFieldName + ".fileBase64", - fieldName -> Base64.encode( - _file.getBytes(dlFileEntry.getContentStream())))); + () -> { + if (FeatureFlagManagerUtil.isEnabled( + objectDefinition.getCompanyId(), "LPD-29347")) { + + String fileSource = String.valueOf( + ObjectFieldSettingUtil.getValue( + ObjectFieldSettingConstants.NAME_FILE_SOURCE, + objectField.getObjectFieldSettings())); + + if (fileSource.equals( + ObjectFieldSettingConstants. + VALUE_USER_COMPUTER)) { + + boolean showFilesInDocumentsAndMedia = + GetterUtil.getBoolean( + ObjectFieldSettingUtil.getValue( + ObjectFieldSettingConstants. + NAME_SHOW_FILES_IN_DOCS_AND_MEDIA, + objectField.getObjectFieldSettings())); + + if (!showFilesInDocumentsAndMedia) { + return Base64.encode( + _file.getBytes( + dlFileEntry.getContentStream())); + } + } + } + + return NestedFieldsSupplier.supply( + objectFieldName + ".fileBase64", + fieldName -> Base64.encode( + _file.getBytes(dlFileEntry.getContentStream()))); + }); fileEntry.setFolder( () -> (Folder)NestedFieldsSupplier.supply( objectFieldName + ".folder", diff --git a/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/manager/v1_0/DefaultObjectEntryManagerImpl.java b/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/manager/v1_0/DefaultObjectEntryManagerImpl.java index d08da43aa57d0e..fd1e45d14da608 100644 --- a/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/manager/v1_0/DefaultObjectEntryManagerImpl.java +++ b/modules/apps/object/object-rest-impl/src/main/java/com/liferay/object/rest/internal/manager/v1_0/DefaultObjectEntryManagerImpl.java @@ -5,6 +5,7 @@ package com.liferay.object.rest.internal.manager.v1_0; +import com.liferay.document.library.kernel.service.DLAppLocalService; import com.liferay.object.action.engine.ObjectActionEngine; import com.liferay.object.constants.ObjectActionTriggerConstants; import com.liferay.object.constants.ObjectConstants; @@ -27,6 +28,7 @@ import com.liferay.object.rest.dto.v1_0.FileEntry; import com.liferay.object.rest.dto.v1_0.Folder; import com.liferay.object.rest.dto.v1_0.ObjectEntry; +import com.liferay.object.rest.dto.v1_0.Scope; import com.liferay.object.rest.dto.v1_0.Status; import com.liferay.object.rest.filter.factory.FilterFactory; import com.liferay.object.rest.filter.parser.ObjectDefinitionFilterParser; @@ -62,6 +64,7 @@ import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.model.BaseModel; import com.liferay.portal.kernel.model.ExternalReferenceCodeModel; +import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.GroupedModel; import com.liferay.portal.kernel.model.PersistedModel; import com.liferay.portal.kernel.search.BooleanClauseOccur; @@ -1140,6 +1143,22 @@ private int _getEndPosition(Pagination pagination) { return QueryUtil.ALL_POS; } + private long _getFileEntryGroupId( + String groupExternalReferenceCode, ObjectDefinition objectDefinition, + String scopeKey) { + + if (Validator.isNotNull(groupExternalReferenceCode)) { + Group group = groupLocalService.fetchGroupByExternalReferenceCode( + groupExternalReferenceCode, objectDefinition.getCompanyId()); + + if (group != null) { + return group.getGroupId(); + } + } + + return getGroupId(objectDefinition, scopeKey, true); + } + private BaseModel _getManyToOneRelatedModel( ObjectRelationship objectRelationship, long primaryKey, ObjectDefinition relatedObjectDefinition) @@ -1384,13 +1403,19 @@ private void _processAttachment( FileEntry fileEntry = ObjectMapperUtil.readValue( FileEntry.class, propertyValue); - if ((fileEntry == null) || (fileEntry.getFileBase64() == null)) { - return; + if ((fileEntry != null) && + !FeatureFlagManagerUtil.isEnabled( + objectDefinition.getCompanyId(), "LPD-29347")) { + + fileEntry.setExternalReferenceCode(() -> null); + fileEntry.setScope(() -> null); } - if (fileEntry.getId() != null) { - throw new IllegalArgumentException( - "Expected either \"id\" or \"fileBase64\" fields"); + if ((fileEntry == null) || + ((fileEntry.getExternalReferenceCode() == null) && + (fileEntry.getFileBase64() == null))) { + + return; } String fileSource = ObjectFieldSettingUtil.getValue( @@ -1408,6 +1433,20 @@ private void _processAttachment( com.liferay.portal.kernel.repository.model.FileEntry serviceBuilderFileEntry = null; + byte[] fileContent = {}; + + if (fileEntry.getFileBase64() != null) { + fileContent = _decode(fileEntry.getFileBase64()); + } + + String groupExternalReferenceCode = null; + + Scope scope = fileEntry.getScope(); + + if (scope != null) { + groupExternalReferenceCode = scope.getExternalReferenceCode(); + } + if (StringUtil.equals( fileSource, ObjectFieldSettingConstants.VALUE_DOCS_AND_MEDIA)) { @@ -1417,15 +1456,17 @@ private void _processAttachment( long folderGroupId = 0; if ((folder == null) || Validator.isNull(folder.getSiteId())) { - folderGroupId = getGroupId(objectDefinition, scopeKey, true); + folderGroupId = _getFileEntryGroupId( + groupExternalReferenceCode, objectDefinition, scopeKey); } else { folderExternalReferenceCode = folder.getExternalReferenceCode(); folderGroupId = folder.getSiteId(); } - serviceBuilderFileEntry = _attachmentManager.addFileEntry( - objectField.getCompanyId(), _decode(fileEntry.getFileBase64()), + serviceBuilderFileEntry = _attachmentManager.getOrAddFileEntry( + objectField.getCompanyId(), + fileEntry.getExternalReferenceCode(), fileContent, fileEntry.getName(), folderExternalReferenceCode, folderGroupId, objectField.getObjectFieldId(), serviceContext); } @@ -1433,10 +1474,12 @@ else if (StringUtil.equals( fileSource, ObjectFieldSettingConstants.VALUE_USER_COMPUTER)) { - serviceBuilderFileEntry = _attachmentManager.addFileEntry( - objectField.getCompanyId(), _decode(fileEntry.getFileBase64()), + serviceBuilderFileEntry = _attachmentManager.getOrAddFileEntry( + objectField.getCompanyId(), + fileEntry.getExternalReferenceCode(), fileContent, fileEntry.getName(), - getGroupId(objectDefinition, scopeKey, true), + _getFileEntryGroupId( + groupExternalReferenceCode, objectDefinition, scopeKey), objectField.getObjectFieldId(), serviceContext); } @@ -1771,6 +1814,9 @@ else if (value != null) { @Reference private AttachmentManager _attachmentManager; + @Reference + private DLAppLocalService _dlAppLocalService; + @Reference private DTOConverterRegistry _dtoConverterRegistry; diff --git a/modules/apps/object/object-rest-test/src/testIntegration/java/com/liferay/object/rest/internal/resource/v1_0/test/ObjectEntryResourceTest.java b/modules/apps/object/object-rest-test/src/testIntegration/java/com/liferay/object/rest/internal/resource/v1_0/test/ObjectEntryResourceTest.java index ea05d0782b62ed..ab15a6bc57498a 100644 --- a/modules/apps/object/object-rest-test/src/testIntegration/java/com/liferay/object/rest/internal/resource/v1_0/test/ObjectEntryResourceTest.java +++ b/modules/apps/object/object-rest-test/src/testIntegration/java/com/liferay/object/rest/internal/resource/v1_0/test/ObjectEntryResourceTest.java @@ -147,6 +147,7 @@ import com.liferay.portlet.documentlibrary.constants.DLConstants; import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.io.Serializable; import java.lang.reflect.Method; @@ -320,6 +321,20 @@ public void setUp() throws Exception { ObjectFieldSettingConstants.NAME_MAX_FILE_SIZE ).value( String.valueOf(_MAX_FILE_SIZE_VALUE) + ).build(), + new ObjectFieldSettingBuilder( + ).name( + ObjectFieldSettingConstants. + NAME_SHOW_FILES_IN_DOCS_AND_MEDIA + ).value( + Boolean.TRUE.toString() + ).build(), + new ObjectFieldSettingBuilder( + ).name( + ObjectFieldSettingConstants. + NAME_STORAGE_DL_FOLDER_PATH + ).value( + StringPool.SLASH + objectDefinitionName ).build()), false), ObjectFieldUtil.createObjectField( @@ -352,14 +367,7 @@ public void setUp() throws Exception { ObjectFieldSettingConstants. NAME_SHOW_FILES_IN_DOCS_AND_MEDIA ).value( - Boolean.TRUE.toString() - ).build(), - new ObjectFieldSettingBuilder( - ).name( - ObjectFieldSettingConstants. - NAME_STORAGE_DL_FOLDER_PATH - ).value( - StringPool.SLASH + objectDefinitionName + StringPool.FALSE ).build()), false), ObjectFieldUtil.createObjectField( @@ -731,6 +739,20 @@ public void setUp() throws Exception { ObjectFieldSettingConstants.NAME_MAX_FILE_SIZE ).value( String.valueOf(_MAX_FILE_SIZE_VALUE) + ).build(), + new ObjectFieldSettingBuilder( + ).name( + ObjectFieldSettingConstants. + NAME_SHOW_FILES_IN_DOCS_AND_MEDIA + ).value( + StringPool.TRUE + ).build(), + new ObjectFieldSettingBuilder( + ).name( + ObjectFieldSettingConstants. + NAME_STORAGE_DL_FOLDER_PATH + ).value( + StringPool.SLASH + objectDefinitionName ).build()), false), ObjectFieldUtil.createObjectField( @@ -763,14 +785,7 @@ public void setUp() throws Exception { ObjectFieldSettingConstants. NAME_SHOW_FILES_IN_DOCS_AND_MEDIA ).value( - Boolean.TRUE.toString() - ).build(), - new ObjectFieldSettingBuilder( - ).name( - ObjectFieldSettingConstants. - NAME_STORAGE_DL_FOLDER_PATH - ).value( - StringPool.SLASH + objectDefinitionName + StringPool.FALSE ).build()), false)), ObjectDefinitionConstants.SCOPE_SITE); @@ -5877,7 +5892,7 @@ public void testGetObjectEntryUnsafeSuppliers() throws Exception { } } - @FeatureFlags("LPS-174455") + @FeatureFlags({"LPD-29347", "LPS-174455"}) @Test public void testGetObjectEntryWithAttachmentObjectField() throws Exception { String content = RandomTestUtil.randomString(); @@ -5965,9 +5980,35 @@ public void testGetObjectEntryWithAttachmentObjectField() throws Exception { _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1), scopeJSONObject); + fileEntry = _addTempFileEntry( + content, _objectDefinition1, RandomTestUtil.randomString()); + + jsonObject = HTTPTestUtil.invokeToJSONObject( + JSONUtil.put( + _OBJECT_FIELD_NAME_1, "value3" + ).put( + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, + fileEntry.getFileEntryId() + ).toString(), + _objectDefinition1.getRESTContextPath(), Http.Method.POST); + + jsonObject = HTTPTestUtil.invokeToJSONObject( + null, + _objectDefinition1.getRESTContextPath() + + "/by-external-reference-code/" + + jsonObject.getString("externalReferenceCode"), + Http.Method.GET); + + _assertAttachmentJSONObject( + null, Base64.encode(content.getBytes()), + jsonObject.getJSONObject( + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2), + scopeJSONObject); + content = RandomTestUtil.randomString(); - DLFileEntry dlFileEntry = _addDLFileEntry(content); + DLFileEntry dlFileEntry = _addDLFileEntry( + content, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID); jsonObject = HTTPTestUtil.invokeToJSONObject( JSONUtil.put( @@ -7063,7 +7104,7 @@ public void testPatchPostPutCustomObjectEntryWithPermissions() Assert.assertNull(objectEntryJSONObject.get("permissions")); } - @FeatureFlags("LPS-174455") + @FeatureFlags({"LPD-29347", "LPS-174455"}) @Test public void testPatchPutCustomObjectEntryByExternalReferenceCodeWithAttachmentObjectField() throws Exception { @@ -7096,7 +7137,7 @@ public void testPatchPutCustomObjectEntryExternalReferenceCode() Http.Method.PUT, jsonObject.getLong("id")); } - @FeatureFlags("LPS-174455") + @FeatureFlags({"LPD-29347", "LPS-174455"}) @Test public void testPatchPutCustomObjectEntryWithAttachmentObjectField() throws Exception { @@ -7146,7 +7187,7 @@ public void testPatchSiteScopedObject() throws Exception { jsonObject.getString(_OBJECT_FIELD_NAME_1), newObjectFieldValue); } - @FeatureFlags("LPS-174455") + @FeatureFlags({"LPD-29347", "LPS-174455"}) @Test public void testPostCustomObjectEntryWithAttachmentObjectField() throws Exception { @@ -11521,10 +11562,11 @@ public void testSortByUnsupportedObjectFields() throws Exception { "siteId"); } - private DLFileEntry _addDLFileEntry(String content) throws Exception { + private DLFileEntry _addDLFileEntry(String content, long folderId) + throws Exception { + FileEntry fileEntry = _dlAppLocalService.addFileEntry( - null, TestPropsValues.getUserId(), _group.getGroupId(), - DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, + null, TestPropsValues.getUserId(), _group.getGroupId(), folderId, TempFileEntryUtil.getTempFileName( RandomTestUtil.randomString() + ".txt"), ContentTypes.TEXT_PLAIN, RandomTestUtil.randomString(), @@ -12089,17 +12131,36 @@ private JSONObject _getFileEntryJSONObject( Folder folder = fileEntry.getFolder(); if (folder == null) { - if (StringUtil.equals( - objectDefinition.getScope(), - ObjectDefinitionConstants.SCOPE_SITE)) { + Scope scope = fileEntry.getScope(); + + if ((scope != null) && + (scope.getExternalReferenceCode() != null)) { - repositoryId = TestPropsValues.getGroupId(); + Group group = + _groupLocalService. + fetchGroupByExternalReferenceCode( + scope.getExternalReferenceCode(), + objectDefinition.getCompanyId()); + + if (group != null) { + repositoryId = group.getGroupId(); + } } - else { - Company company = _companyLocalService.getCompany( - objectDefinition.getCompanyId()); - repositoryId = company.getGroupId(); + if (repositoryId == 0) { + if (StringUtil.equals( + objectDefinition.getScope(), + ObjectDefinitionConstants.SCOPE_SITE)) { + + repositoryId = TestPropsValues.getGroupId(); + } + else { + Company company = + _companyLocalService.getCompany( + objectDefinition.getCompanyId()); + + repositoryId = company.getGroupId(); + } } } else { @@ -12117,9 +12178,8 @@ private JSONObject _getFileEntryJSONObject( StringBundler.concat( "/documents/", repositoryId, "/", folderId, "/", URLCodec.encodeURL(fileEntry.getName()), "/", - serviceBuilderFileEntry.getExternalReferenceCode(), - "?version=", fileVersion.getVersion(), "&t=", - modifiedDate.getTime(), + serviceBuilderFileEntry.getUuid(), "?version=", + fileVersion.getVersion(), "&t=", modifiedDate.getTime(), "&download=true&objectDefinitionExternalReferenceCode=", objectDefinition.getExternalReferenceCode(), "&objectEntryExternalReferenceCode=", @@ -12662,7 +12722,6 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( ); String randomExternalReferenceCode = RandomTestUtil.randomString(); - long randomGroupId = RandomTestUtil.randomLong(); _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( @@ -12671,13 +12730,13 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( "title", StringBundler.concat( "No DLFolder exists with the key {externalReferenceCode=", - randomExternalReferenceCode, ", groupId=", randomGroupId, - "}") + randomExternalReferenceCode, ", groupId=", + TestPropsValues.getGroupId(), "}") ), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", - randomExternalReferenceCode, randomGroupId), + randomExternalReferenceCode, TestPropsValues.getGroupId()), httpMethod, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE, useExternalReferenceCode); @@ -12754,7 +12813,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), @@ -12766,7 +12825,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), @@ -12778,9 +12837,14 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", null, null), @@ -12790,9 +12854,14 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", @@ -12837,7 +12906,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, () -> { JSONObject jsonObject = _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition); return jsonObject.put( @@ -12854,7 +12923,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, () -> { JSONObject jsonObject = _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, + _getDLFolder(objectDefinition, false), fileEntry, objectDefinition); return jsonObject.put( @@ -12877,7 +12946,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), testFileEntry, httpMethod, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, @@ -12891,7 +12960,7 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( return JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)); }, testFileEntry, httpMethod, null, objectDefinition, @@ -12905,9 +12974,14 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( _testPatchPutCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), testFileEntry, httpMethod, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, useExternalReferenceCode); @@ -12919,9 +12993,14 @@ private void _testPatchPutCustomObjectEntryWithAttachmentField( return JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)); + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }); }, testFileEntry, httpMethod, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, @@ -13164,7 +13243,6 @@ private void _testPostCustomObjectEntryWithAttachmentField( ); String randomExternalReferenceCode = RandomTestUtil.randomString(); - long randomGroupId = RandomTestUtil.randomLong(); _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( @@ -13173,16 +13251,99 @@ private void _testPostCustomObjectEntryWithAttachmentField( "title", StringBundler.concat( "No DLFolder exists with the key {externalReferenceCode=", - randomExternalReferenceCode, ", groupId=", randomGroupId, - "}") + randomExternalReferenceCode, ", groupId=", + TestPropsValues.getGroupId(), "}") ), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", - randomExternalReferenceCode, randomGroupId), + randomExternalReferenceCode, TestPropsValues.getGroupId()), null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE); + // File with a nonexistent external reference code + + com.liferay.object.rest.dto.v1_0.FileEntry testFileEntry = _toFileEntry( + content -> null, RandomTestUtil.randomString(), + RandomTestUtil.randomString() + ".txt", null, null); + + testFileEntry.setExternalReferenceCode(RandomTestUtil.randomString()); + + Group group = GroupTestUtil.addGroup(); + + Scope scope = new Scope(); + + scope.setExternalReferenceCode(group.getExternalReferenceCode()); + scope.setType(Scope.Type.SITE); + + testFileEntry.setScope(scope); + + String externalReferenceCode3 = + testFileEntry.getExternalReferenceCode(); + + _testPostCustomObjectEntryWithAttachmentField( + fileEntry -> JSONUtil.put( + _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE, + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + null, fileEntry, objectDefinition); + + jsonObject.put( + "externalReferenceCode", externalReferenceCode3); + + return jsonObject; + }), + testFileEntry, null, objectDefinition, + _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE); + + FileEntry createdFileEntry = _dlAppLocalService.getFileEntry( + _testDLFileEntryModelListener.getLastFileEntryId()); + + Assert.assertEquals( + externalReferenceCode3, + createdFileEntry.getExternalReferenceCode()); + Assert.assertEquals(group.getGroupId(), createdFileEntry.getGroupId()); + + InputStream inputStream = createdFileEntry.getContentStream(); + + Assert.assertEquals(-1, inputStream.read()); + + testFileEntry = _toFileEntry( + content -> null, RandomTestUtil.randomString(), + RandomTestUtil.randomString() + ".txt", null, null); + + testFileEntry.setExternalReferenceCode(RandomTestUtil.randomString()); + + String externalReferenceCode4 = + testFileEntry.getExternalReferenceCode(); + + _testPostCustomObjectEntryWithAttachmentField( + fileEntry -> JSONUtil.put( + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, true), fileEntry, + objectDefinition); + + jsonObject.put( + "externalReferenceCode", externalReferenceCode4); + + return jsonObject; + }), + testFileEntry, null, objectDefinition, + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1); + + createdFileEntry = _dlAppLocalService.getFileEntry( + _testDLFileEntryModelListener.getLastFileEntryId()); + + Assert.assertEquals( + externalReferenceCode4, + createdFileEntry.getExternalReferenceCode()); + + inputStream = createdFileEntry.getContentStream(); + + Assert.assertEquals(-1, inputStream.read()); + // File with a nonexistent name (documents and media source) DLFolder dlFolder1 = DLTestUtil.addDLFolder( @@ -13250,7 +13411,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), @@ -13261,7 +13422,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), @@ -13272,9 +13433,14 @@ private void _testPostCustomObjectEntryWithAttachmentField( _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", null, null), @@ -13283,9 +13449,14 @@ private void _testPostCustomObjectEntryWithAttachmentField( _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", @@ -13328,7 +13499,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, () -> { JSONObject jsonObject = _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition); return jsonObject.put( @@ -13344,7 +13515,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, () -> { JSONObject jsonObject = _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, + _getDLFolder(objectDefinition, false), fileEntry, objectDefinition); return jsonObject.put( @@ -13356,9 +13527,77 @@ private void _testPostCustomObjectEntryWithAttachmentField( "fileBase64,folder", objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2); + // File with an existing external reference code + + String fileContent = RandomTestUtil.randomString(); + + com.liferay.portal.kernel.repository.model.Folder existingFolder = + _dlAppLocalService.addFolder( + null, TestPropsValues.getUserId(), _group.getGroupId(), + DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, + RandomTestUtil.randomString(), RandomTestUtil.randomString(), + ServiceContextTestUtil.getServiceContext()); + + DLFileEntry existingFile = _addDLFileEntry( + fileContent, existingFolder.getFolderId()); + + testFileEntry = _toFileEntry( + Base64::encode, fileContent, existingFile.getFileName(), null, + TestPropsValues.getGroupId()); + + testFileEntry.setExternalReferenceCode( + existingFile.getExternalReferenceCode()); + + String externalReferenceCode1 = existingFile.getExternalReferenceCode(); + + _testPostCustomObjectEntryWithAttachmentField( + fileEntry -> JSONUtil.put( + _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE, + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + null, fileEntry, objectDefinition); + + jsonObject.put( + "externalReferenceCode", externalReferenceCode1); + + return jsonObject; + }), + testFileEntry, null, objectDefinition, + _OBJECT_FIELD_NAME_ATTACHMENT_DOCS_AND_MEDIA_SOURCE); + + fileContent = RandomTestUtil.randomString(); + + existingFile = _addDLFileEntry( + fileContent, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID); + + testFileEntry = _toFileEntry( + Base64::encode, fileContent, existingFile.getFileName(), null, + TestPropsValues.getGroupId()); + + testFileEntry.setExternalReferenceCode( + existingFile.getExternalReferenceCode()); + + String externalReferenceCode2 = existingFile.getExternalReferenceCode(); + + _testPostCustomObjectEntryWithAttachmentField( + fileEntry -> JSONUtil.put( + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, true), fileEntry, + objectDefinition); + + jsonObject.put( + "externalReferenceCode", externalReferenceCode2); + + return jsonObject; + }), + testFileEntry, null, objectDefinition, + _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1); + // File with an existing name - com.liferay.object.rest.dto.v1_0.FileEntry testFileEntry = _toFileEntry( + testFileEntry = _toFileEntry( Base64::encode, RandomTestUtil.randomString(), RandomTestUtil.randomString() + ".txt", null, null); @@ -13366,7 +13605,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)), testFileEntry, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1); @@ -13379,7 +13618,7 @@ private void _testPostCustomObjectEntryWithAttachmentField( return JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_1, _getFileEntryJSONObject( - _getDLFolder(objectDefinition, false), fileEntry, + _getDLFolder(objectDefinition, true), fileEntry, objectDefinition)); }, testFileEntry, null, objectDefinition, @@ -13392,9 +13631,14 @@ private void _testPostCustomObjectEntryWithAttachmentField( _testPostCustomObjectEntryWithAttachmentField( fileEntry -> JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)), + () -> { + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + return jsonObject.put( + "fileBase64", fileEntry.getFileBase64()); + }), testFileEntry, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2); _testPostCustomObjectEntryWithAttachmentField( @@ -13403,11 +13647,15 @@ private void _testPostCustomObjectEntryWithAttachmentField( StringUtil.replace( fileEntry.getName(), ".txt", " (1).txt")); + JSONObject jsonObject = _getFileEntryJSONObject( + _getDLFolder(objectDefinition, false), fileEntry, + objectDefinition); + + jsonObject.put("fileBase64", fileEntry.getFileBase64()); + return JSONUtil.put( _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2, - _getFileEntryJSONObject( - _getDLFolder(objectDefinition, true), fileEntry, - objectDefinition)); + jsonObject); }, testFileEntry, null, objectDefinition, _OBJECT_FIELD_NAME_ATTACHMENT_USER_COMPUTER_SOURCE_2); diff --git a/modules/apps/object/object-service/src/main/java/com/liferay/object/internal/field/attachment/AttachmentManagerImpl.java b/modules/apps/object/object-service/src/main/java/com/liferay/object/internal/field/attachment/AttachmentManagerImpl.java index 396ab5bda4eebc..034cfcdbccfa8b 100644 --- a/modules/apps/object/object-service/src/main/java/com/liferay/object/internal/field/attachment/AttachmentManagerImpl.java +++ b/modules/apps/object/object-service/src/main/java/com/liferay/object/internal/field/attachment/AttachmentManagerImpl.java @@ -64,78 +64,6 @@ ) public class AttachmentManagerImpl implements AttachmentManager { - @Override - public FileEntry addFileEntry( - long companyId, byte[] fileContent, String fileName, long groupId, - long objectFieldId, ServiceContext serviceContext) - throws Exception { - - _validateFile( - fileContent, fileName, objectFieldId, serviceContext.getUserId()); - - DLFolder dlFolder = getDLFolder( - companyId, groupId, objectFieldId, serviceContext, - serviceContext.getUserId()); - - try (InputStream inputStream = new ByteArrayInputStream(fileContent)) { - return _dlAppLocalService.addFileEntry( - null, serviceContext.getUserId(), dlFolder.getRepositoryId(), - dlFolder.getFolderId(), - DLUtil.getUniqueFileName( - groupId, dlFolder.getFolderId(), fileName, true), - _mimeTypes.getContentType(inputStream, fileName), - DLUtil.getUniqueTitle( - groupId, dlFolder.getFolderId(), - FileUtil.stripExtension(fileName)), - StringPool.BLANK, null, null, inputStream, fileContent.length, - null, null, null, serviceContext); - } - } - - @Override - public FileEntry addFileEntry( - long companyId, byte[] fileContent, String fileName, - String folderExternalReferenceCode, long groupId, - long objectFieldId, ServiceContext serviceContext) - throws Exception { - - _validateFile( - fileContent, fileName, objectFieldId, serviceContext.getUserId()); - - long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; - long repositoryId = groupId; - - if (Validator.isNotNull(folderExternalReferenceCode)) { - DLFolder dlFolder = - _dlFolderService.getDLFolderByExternalReferenceCode( - folderExternalReferenceCode, groupId); - - folderId = dlFolder.getFolderId(); - repositoryId = dlFolder.getRepositoryId(); - } - - ServiceContext cloneServiceContext = - (ServiceContext)serviceContext.clone(); - - cloneServiceContext.setCompanyId(companyId); - - try (InputStream inputStream = new ByteArrayInputStream(fileContent)) { - _dlValidator.validateFileSize( - groupId, fileName, - _mimeTypes.getContentType(inputStream, fileName), - fileContent.length); - - return _dlAppService.addFileEntry( - null, repositoryId, folderId, - DLUtil.getUniqueFileName(groupId, folderId, fileName, true), - _mimeTypes.getContentType(inputStream, fileName), - DLUtil.getUniqueTitle( - groupId, folderId, FileUtil.stripExtension(fileName)), - StringPool.BLANK, null, null, inputStream, fileContent.length, - null, null, null, cloneServiceContext); - } - } - @Override public String[] getAcceptedFileExtensions(long objectFieldId) { ObjectFieldSetting objectFieldSetting = @@ -204,6 +132,95 @@ public long getMaximumFileSize(long objectFieldId, boolean signedIn) { _FILE_LENGTH_MB; } + @Override + public FileEntry getOrAddFileEntry( + long companyId, String externalReferenceCode, byte[] fileContent, + String fileName, long groupId, long objectFieldId, + ServiceContext serviceContext) + throws Exception { + + FileEntry fileEntry = + _dlAppLocalService.fetchFileEntryByExternalReferenceCode( + groupId, externalReferenceCode); + + if (fileEntry != null) { + return fileEntry; + } + + _validateFile( + fileContent, fileName, objectFieldId, serviceContext.getUserId()); + + DLFolder dlFolder = getDLFolder( + companyId, groupId, objectFieldId, serviceContext, + serviceContext.getUserId()); + + try (InputStream inputStream = new ByteArrayInputStream(fileContent)) { + return _dlAppLocalService.addFileEntry( + externalReferenceCode, serviceContext.getUserId(), + dlFolder.getRepositoryId(), dlFolder.getFolderId(), + DLUtil.getUniqueFileName( + groupId, dlFolder.getFolderId(), fileName, true), + _mimeTypes.getContentType(inputStream, fileName), + DLUtil.getUniqueTitle( + groupId, dlFolder.getFolderId(), + FileUtil.stripExtension(fileName)), + StringPool.BLANK, null, null, inputStream, fileContent.length, + null, null, null, serviceContext); + } + } + + @Override + public FileEntry getOrAddFileEntry( + long companyId, String externalReferenceCode, byte[] fileContent, + String fileName, String folderExternalReferenceCode, long groupId, + long objectFieldId, ServiceContext serviceContext) + throws Exception { + + FileEntry fileEntry = + _dlAppLocalService.fetchFileEntryByExternalReferenceCode( + groupId, externalReferenceCode); + + if (fileEntry != null) { + return fileEntry; + } + + _validateFile( + fileContent, fileName, objectFieldId, serviceContext.getUserId()); + + long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; + long repositoryId = groupId; + + if (Validator.isNotNull(folderExternalReferenceCode)) { + DLFolder dlFolder = + _dlFolderService.getDLFolderByExternalReferenceCode( + folderExternalReferenceCode, groupId); + + folderId = dlFolder.getFolderId(); + repositoryId = dlFolder.getRepositoryId(); + } + + ServiceContext cloneServiceContext = + (ServiceContext)serviceContext.clone(); + + cloneServiceContext.setCompanyId(companyId); + + try (InputStream inputStream = new ByteArrayInputStream(fileContent)) { + _dlValidator.validateFileSize( + groupId, fileName, + _mimeTypes.getContentType(inputStream, fileName), + fileContent.length); + + return _dlAppService.addFileEntry( + externalReferenceCode, repositoryId, folderId, + DLUtil.getUniqueFileName(groupId, folderId, fileName, true), + _mimeTypes.getContentType(inputStream, fileName), + DLUtil.getUniqueTitle( + groupId, folderId, FileUtil.stripExtension(fileName)), + StringPool.BLANK, null, null, inputStream, fileContent.length, + null, null, null, cloneServiceContext); + } + } + @Override public void validateFileExtension(String fileName, long objectFieldId) throws FileExtensionException { diff --git a/portal-impl/src/portal.properties b/portal-impl/src/portal.properties index 2c25500d652231..9fca7a7056c685 100644 --- a/portal-impl/src/portal.properties +++ b/portal-impl/src/portal.properties @@ -6548,6 +6548,11 @@ # feature.flag.LPD-28830=false + # + # Env: LIFERAY_FEATURE_PERIOD_FLAG_PERIOD__UPPERCASEL__UPPERCASEP__UPPERCASED__MINUS__NUMBER2__NUMBER9__NUMBER3__NUMBER4__NUMBER7_ + # + feature.flag.LPD-29347=false + # # Env: LIFERAY_FEATURE_PERIOD_FLAG_PERIOD__UPPERCASEL__UPPERCASEP__UPPERCASED__MINUS__NUMBER2__NUMBER9__NUMBER5__NUMBER1__NUMBER6_ #