Skip to content

Commit

Permalink
Fixed: Process Import File Loader form with file name (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsiosanchez authored Aug 26, 2024
1 parent e5994df commit b7e4d84
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
Binary file modified resources/adempiere-grpc-server.pb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

/**
* @author Edwin Betancourt, [email protected], https://github.com/EdwinBetanc0urt
* @author Elsio Sanchez, [email protected], https://github.com/ElsioSanchez
* Service logic of Import File Loader form
*/
public class ImportFileLoaderServiceLogic {
Expand Down Expand Up @@ -246,10 +247,10 @@ public static ImportFormat.Builder getImportFromat(GetImportFromatRequest reques
public static SaveRecordsResponse.Builder saveRecords(SaveRecordsRequest request) throws Exception {
MImpFormat importFormat = validateAndGetImportFormat(request.getImportFormatId());

// validate attachment reference
int attachmentReferenceId = request.getResourceId();
if (attachmentReferenceId <= 0) {
throw new AdempiereException("@FillMandatory@ @AD_AttachmentReference_ID@");
// validate Get File Name reference
String attachmentFileName = request.getResourceName();
if (Util.isEmpty(attachmentFileName, true) ) {
throw new AdempiereException("@FileName@ @NotFound@");
}

// Get class from parent
Expand All @@ -264,12 +265,39 @@ public static SaveRecordsResponse.Builder saveRecords(SaveRecordsRequest request
// return;
}

byte[] file = AttachmentUtil.getInstance()
.withClientId(Env.getAD_Client_ID(Env.getCtx()))
.withAttachmentReferenceId(attachmentReferenceId)
.getAttachment();
if (file == null) {
throw new AdempiereException("@AD_AttachmentReference_ID@ @NotFound@");
MClientInfo clientInfo = MClientInfo.get(Env.getCtx());
if (clientInfo == null) {
throw new AdempiereException("@ClientInfo@");
}
if (clientInfo.getFileHandler_ID() <= 0) {
throw new AdempiereException("@FileHandler_ID@ @NotFound@");
}
// Connector S3
MADAppRegistration genericConnector = MADAppRegistration.getById(
Env.getCtx(),
clientInfo.getFileHandler_ID(),
null
);
if (genericConnector == null || genericConnector.getAD_AppRegistration_ID() <= 0) {
throw new AdempiereException("@AD_AppSupport_ID@ @NotFound@");
}
// Load
IAppSupport supportedApi = AppSupportHandler.getInstance().getAppSupport(genericConnector);
if (supportedApi == null) {
throw new AdempiereException("@AD_AppSupport_ID@ @NotFound@");
}
if (!IS3.class.isAssignableFrom(supportedApi.getClass())) {
throw new AdempiereException("@AD_AppSupport_ID@ @Unsupported@");
}
// Get it
IS3 fileHandler = (IS3) supportedApi;

// Resource
ResourceMetadata resourceMetadata = ResourceMetadata.newInstance()
.withResourceName(attachmentFileName);
InputStream inputStream = fileHandler.getResource(resourceMetadata);
if (inputStream == null) {
throw new AdempiereException("@InputStream@ @NotFound@");
}

String charsetValue = request.getCharset();
Expand All @@ -278,7 +306,7 @@ public static SaveRecordsResponse.Builder saveRecords(SaveRecordsRequest request
}
Charset charset = Charset.forName(charsetValue);

InputStream inputStream = new ByteArrayInputStream(file);
// InputStream inputStream = new ByteArrayInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, charset);
BufferedReader in = new BufferedReader(inputStreamReader, 10240);

Expand Down
4 changes: 2 additions & 2 deletions src/main/proto/import_file_loader.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ service ImportFileLoader {
// Manage File
rpc SaveRecords(SaveRecordsRequest) returns (SaveRecordsResponse) {
option (google.api.http) = {
post: "/import-loader/imports/{import_format_id}/{resource_id}",
post: "/import-loader/imports/{import_format_id}",
body: "*"
};
}
Expand Down Expand Up @@ -184,7 +184,7 @@ message ListFilePreviewRequest {
// Save Record
message SaveRecordsRequest {
int32 import_format_id = 1;
int32 resource_id = 2;
string resource_name = 2;
string charset = 3;
// process before save changes
bool is_process = 4;
Expand Down

0 comments on commit b7e4d84

Please sign in to comment.