Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPD-29348 Change the reference from the attachment to the Object entry from ID to ERC #153938

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"FileEntry": {
"properties": {
"externalReferenceCode": {
"readOnly": true,
"type": "string"
},
"fileBase64": {
Expand Down Expand Up @@ -343,7 +342,6 @@
"type": "string"
}
},
"readOnly": true,
"type": "object",
"xml": {
"name": "Scope"
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/object/object-api/bnd.bnd
Original file line number Diff line number Diff line change
@@ -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,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 2.0.0
version 3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void setExternalReferenceCode(
}

@GraphQLField
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_WRITE)
protected String externalReferenceCode;

@JsonIgnore
Expand Down Expand Up @@ -330,7 +330,7 @@ public void setScope(UnsafeSupplier<Scope, Exception> scopeUnsafeSupplier) {
}

@GraphQLField
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_WRITE)
protected Scope scope;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version 1.9.0
version 1.9.1
2 changes: 0 additions & 2 deletions modules/apps/object/object-rest-impl/rest-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ components:
FileEntry:
properties:
externalReferenceCode:
readOnly: true
type: string
fileBase64:
# @review
Expand All @@ -48,7 +47,6 @@ components:
type: string
scope:
$ref: "#/components/schemas/Scope"
readOnly: true
type: object
Folder:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ExternalReferenceCodeModel> _getManyToOneRelatedModel(
ObjectRelationship objectRelationship, long primaryKey,
ObjectDefinition relatedObjectDefinition)
Expand Down Expand Up @@ -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(
Expand All @@ -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)) {

Expand All @@ -1417,26 +1456,30 @@ 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);
}
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);
}

Expand Down Expand Up @@ -1771,6 +1814,9 @@ else if (value != null) {
@Reference
private AttachmentManager _attachmentManager;

@Reference
private DLAppLocalService _dlAppLocalService;

@Reference
private DTOConverterRegistry _dtoConverterRegistry;

Expand Down
Loading