forked from adempiere/backend
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Process
Import File Loader
form with file name (#865)
- Loading branch information
1 parent
e5994df
commit b7e4d84
Showing
3 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 | ||
|
@@ -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(); | ||
|
@@ -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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters