Friday, 15 March 2019

File upload size limit issue on AWS Cloud


1) Faced upload issue on DEV/PROD envt.
2) Checked code of spring boot application.properties (multiple property names for spring 1.x, 2.x,etc), none working
3) Checked code of UI angularjs (20 MB is set)
4) Checked on another alfresco project server on-premise (qa / dev). Worked there.
5) Checked by uploading 10MB file on our aws dev/prod into OOTB Alfresco share UI > My Files. Still giving the same error.
6) Tried changing the limit from server.xml of tomcat/conf
Added maxHttpHeaderSize="20000000"  , also maxPostSize="-1"  , also packetSize="20000000".
   Restarted Alfresco tomcat, no luck.
7) Checked tomcat/webapps/manager/WEB-INF/web.xml.
Default allowed size was 50MB, changed <max-file-size> and <max-request-size> to 100MB in case if total request was high,
Still no luck
8) As the error contained '413 Request Entity Too Large' nginx (some version), tried searching for nginx settings.
   Searched for nginx files in linux: Found at only these two locations:
   /opt/alfresco5.2.3/tomcat/webapps/onguiportal/OnG_GIT/dist/nginx.conf
/opt/scalarizr/embedded/lib/python3.5/site-packages/scalarizr-7.11.5-py3.5.egg/scalarizr/api/nginx.py
Tried adding client_max_body_size 100M in those files , but no luck.
9) Checked if in case apache service is installed, checked the httpd.conf files, ssl.conf, workers.properties,
mod_jk, jk.conf files, but request is not going on apache, so no need to change in above apache files.
10) Raised ticket with Alfresco,
11) Raised ticket with AWS Cloud team.
   After investigation
Comments by cloud team:
we changed the parameter "client_max_body_size" in the alfresco-dev-<full-domain-name>.conf wild card conf file
12) So issue of file limit found from AWS Cloud team, fixed by them and started working.
13) For production envt, need to raise a change request from Change > Create New > Normal change. Fill details and create CR.
Once approved and acted upon, it will be fixed in prod too.

Ref links (to update in stackoverflow):
https://www.keycdn.com/support/413-request-entity-too-large
https://serverfault.com/questions/56691/whats-the-maximum-url-length-in-tomcat
https://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat

Issue of Access denied on alf_data/...../CachedContent folders when starting alfresco server.

This can happen when you normally start alf with a functional user login on linux.
And by mistake, sometime you start alfresco with other user or root user, perform some operations in alf and stop it.

Now if u try to start alf server with that functional user or other non-root user, you'll get this error as this functional user doesnot have permission to the folders and files changed under alf_data by root user.
Fix:
chown -R <FUNC_SSO>:Domain\ Users <folder_name>

Validate date format according to the format we want

The following java code/method will return true/false based on the dateformat you pass (against which the date value will be checked):

public static boolean checkDatePattern(String padrao, String data) {
  DateFormat formatter = new SimpleDateFormat(padrao);
  formatter.setLenient(false);
  try {
      Date date= formatter.parse(data);
  } catch (ParseException e) {
      e.printStackTrace();
      return false;
  }
  return true;

 }

Characters not allowed in Alfresco

Characters not allowed in Alfresco while creation of file or folder or any content:

*
:
"
<
>
.
?
/
\
|


Java code (Regex pattern) to allow all characters except above characters:

private String escapeSpecialChars(String name){

      name = name.replaceAll("[^a-zA-Z0-9\\s~`!@#$%^&()_+=;',{}\\[\\]]", "-");

      return name;
}

Writing to excel with data validation using java apache poi

----------------------------------------------------------------
Date Validation with java code - apache poi
----------------------------------------------------------------
Cell cel= rowx.createCell(i);
cel.setCellStyle(style);
XSSFCreationHelper createHelper = workbook.getCreationHelper();
short dateFormat = createHelper.createDataFormat().getFormat("MM/dd/yyyy");
style.setDataFormat(dateFormat);
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DataValidationConstraint dvConstraint = dvHelper.createDateConstraint(
    org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType.BETWEEN,
    "Date(1900, 1, 1)",
    "Date(9999, 12, 31)",
    "MM/dd/yyyy");
CellRangeAddressList addressList = new CellRangeAddressList(
2, pendingRowCount, columnNumber, columnNumber);
DataValidation validation = dvHelper.createValidation(dvConstraint, addressList);
if (validation instanceof XSSFDataValidation) {
    validation.setSuppressDropDownArrow(true);
validation.setShowErrorBox(true);
} else {
        validation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(validation);

----------------------------------------------------------------
DropDown Validation with java code - apache poi
----------------------------------------------------------------
Cell cel= rowx.createCell(i);
cel.setCellStyle(style);
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DataValidationConstraint dvConstraint =
                  dvHelper.createExplicitListConstraint(new String[] {"Yes","No"});
//same addressList and datavalidation object and if else condition and addValidationData method as above

------------------------------------------
To lock/unlock cell
------------------------------------------
CellStyle lockedStyle = workbook.createCellStyle();
lockedStyle.setWrapText(true);
lockedStyle.setLocked(true);

CellStyle unlockedStyle = workbook.createCellStyle();
unlockedStyle.setWrapText(true);
unlockedStyle.setLocked(false);

----------------------------------------------------------------------------------------------------------------------
Restricted text (only the supplier formula values from excel will populate in dropdown)
----------------------------------------------------------------------------------------------------------------------
Cell cel= rowx.createCell(i);
cel.setCellStyle(style);
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
    dvHelper.createFormulaListConstraint("$N$3:$N$5");
//same addressList and datavalidation object and if else condition and addValidationData method as above

-------------------------------------------------------------
Alphanumeric text allowed with text length limit
-------------------------------------------------------------
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
XSSFDataValidationConstraint dvConstraint =
(XSSFDataValidationConstraint) dvHelper.createNumericConstraint(
ValidationType.TEXT_LENGTH, OperatorType.BETWEEN, "0", String.valueOf(maxLength));