Thursday, 11 April 2019

Alfresco Learning


Create site programatically in alfresco:

PostMethod createSitePost = new PostMethod("http://127.0.0...);
String shortName = "TestSiteFromCode";
JSONObject siteObject = new JSONObject();
try {
siteObject.put("shortName", shortName);
siteObject.put("Visiblity", "Public");
siteObject.put("sitePreset", "site-dashboard");
siteObject.put("title", shortName);
siteObject.put("description", shortName);
createSitePost.setRequestHeader("Content-Type", "application/json");
createSitePost.setRequestHeader("Accept", "application/json");
createSitePost.setRequestEntity(new StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
int status = client.executeMethod(createSitePost);
"alf_ticket":"TICKET_1867481b6f78a70ec5df451f37971fa87d58f1de"
http://01hw537727:8080/share/page/modules/create-s...


-----------------------------------------------------------------------------------------------------

Even on sending a flag (ex: "isContent":true) from request body of JSON from UI to service,the flag received on service side is always false:
1) Resolution: Check the POJO on service side receiving this flag. It should be ideally a wrapper class (not primitive boolean type). Also check similar primitive types in the pojo (make it wrapper) and change its getter/setters.
2) Try sending "isContent":true / "isContent":"true" / "isContent":"false" / "isContent":false
3) Check by debugging, what exact value you receive in the service when the method is called. 
4) Check what is the type set in DB column (TINYINT(1) should work). And along with that check what is the default value for this column in db (ideally default value '0' set it to false)

---------------------------------------------------------------------------------------------------

Alfresco upgrade steps:
Upgrade steps on QA:
1) Install 5.1.3.2
2) Start server. Check vanilla and common functionalities working fine.
3) stop server
4) Apply the amps (amps and amps_share)
5) Put all relevant entries in alf-global.properties
6) Copy subsystems folder from extension envt and copy it to alf5.1.3.2/extension.
7) Start node and verify operations.
8) Stop the node
9) Change the following:
Change the solr path in this file to original NAS path where solr indexes are stored: ALFRESCO_INSTALLATION_DIR/tomcat/conf/Catalina/localhost/solr4.xml
Change the solr path in ALFRESCO_INSTALLATION_DIR/solr4/workspace-SpacesStore/conf/solrcore.properties & archive-SpacesStore/conf/solrcore.properties:
Change alfresco-global.properties to point to original dir.root (contentStore) and db properties:
dir.root=/data/alf_data/XXX/XXXdb.name=xxxxdb.username=xxxxxxdb.password=xxxxxxdb.driver=org.gjt.mm.mysql.Driverdb.url=jdbc:mysql://${db.host}:${db.port}/${db.name}?useUnicode=yes&characterEncoding=UTF-8 db.host=xxxxxxxx## Note: your database must also be able to accept at least this many connections. Please see your database documentation for instructions on how to configure this.db.pool.max=575db.pool.validate.query=SELECT 1db.port=xxxx
10) Clear server cache (tomcat/temp and tomcat/work).
11) Start server.

Other case:
1) Take backup of amps, wars and DB. Stop the server
2) Alf1 node is pointing to postgres db currently; now we will point to "alf50_****test" (i.e used by alf2 node)
3) Apply amps sequentially (first RM, cornerstone, and then the other amps) to the war files
4) Start alfresco
5) In indexing errors occur, will reindex the contents.

---------------------------------------------------------------------------------------------------

content-indexing not working for few selected contents:
1) Check that in alf-global, solr node (solr host/port) is pointing to correct solr node
2) Check solrcore.properties. It should point to the same contentstore which alf node is pointing
3) Check if transformation server configured in alf-global is correct, If configured correctly verify it is up and running. Keep an eye on the logs when server starts up, transformation server should start correctly and also jodconverted should work fine (jodconverter or OOOffice).
4) Check if the content file not indexed, has correct mimetype set on it. If mimetype is not set correctly, it won't index by the solr.

--------------------------------------------------------------------------------------------

SAML configuration in alf, Upgrade steps from alf 5.0 to 5.1, aikau error, content-indexing not working for few selected contents - blog
Buzone issue
Alternatives:
1. Keep dojo enabled false in surf.xml and try building amps.
3. 

2017-11-09 06:26:49,956 ERROR [extensions.surf.DependencyAggregator] [http-apr-8080-exec-16] Could not find compressed file: /share/services/UserHomePageService.js 2017-11-09 06:26:49,957 ERROR [extensions.surf.DependencyAggregator] [http-apr-8080-exec-16] Could not find compressed file: /share/services/ServicesWarning.js------------------------------------------------------------------------------------------------------------------------- 
https://community.alfresco.com/community/ecm/blog... 
Post from ddraper: "You can include multiple versions of the Aikau JAR files in the share/WEB-INF/lib folder without any problems"

------------------------------------------------------------------------------------------------
Activiti:

http://localhost:8080/activiti-app
The default app administrator is admin@app.activiti.com with password admin.
To view the Alfresco Process Services Administrator web application, use thefollowing URL:
http://localhost:8080/activiti-admin
The default administrator user is admin with password admin.
The above information is available in the process-services-readme.txt in yourinstallation.

-----------------------------------------------------------------------------------------------









  • Problem: To use repositoryService() of alfresco, and call deleteDeploymentId(..) method or any other method from ur java class -> 










  • Solution: Inject 'ProcessEngine' interface (belongs to activiti jar) in ur class and give ref= 'ActivityProcessEngine' in ur context.xml file as bean entry.









  • Problem: For splitting pdf into multiple pdfs (page wise as well as paragraph wise), use ContentWriter API, contentWriter object.setMimeType(MimeTypeMap.PDF...); also ContentWriter.setEncoding(UTF-8);









  • Solution: If preview of doc does not work, u need to split it as pdf. For that use 
  • Itext jar – PDFWriter class and Document class


  •  CORS Filter Class:
    public class CORSFilter implements Filter{

    private static Logger logger = LoggerFactory.getLogger(CORSFilter.class);

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
    throws IOException, ServletException {
    // TODO Auto-generated method stub
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");
     
        chain.doFilter(req, res);

  • --------------------------------------------------------------------------------------------------------

    Alfresco with solr 4/6 provides an intelligent search resulting into some additional search results also being displayed along with the matching search results.
    After doing some research, I found that as a part of it's intelligent search, it identifies/assumes certain characters which are commonly used or searched. And also it assumes certain characters as extra or a part of plural string:
    For example: Searching for 'cubs' may give you search results having 'cub' in some OOTB or custom metadata or document/folder name. You might wonder how come 'cubs' got matched inside 'cub' string. But this behaviour I have observed and experienced very often.

    As a solution to this point, we have found that if we provide a validation for user to enter minimum 4 characters in search textbox, and then click search button, then it will give you accurate search results.

    So in a nutshell, keep minimum 4 chars in search text field/box. Else you will get unexpected/non-matching results in search (with solr and fts)

    Example: (Here, we are searching for results with 'customPropertyName' having value of  'elephant')

    1) Search query which can give additional results along with exact results:
    TYPE:'ab:customDocumentType' AND ab:customPropertyName:"*pha*"

    2) Search query which will give you exact results:
    TYPE:'ab:customDocumentType' AND ab:customPropertyName:"*phan*"

    --------------------------------------------------------------------------------------------------------

    'System' user of Alfresco accidentally gets deleted by someone or through some LDAP configuration:
    In this case, some of the webscripts might stop working and also the code which references the 'System' user might not function.

    Resolution: Create a new user in Alfresco (using Alfresco Share), entering the First name as 'System' and Username, Password also as 'System'. Email Address you can enter any valid email. It's done. The webscript calls will start working without any server restarts.

    --------------------------------------------------------------------------------------------------------

    PDFBox error:
    java.io.IOException: Push back buffer is full
    at java.io.PushbackInputStream.unread(PushbackInputStream.java:232)
    at org.apache.pdfbox.io.PushBackInputStream.unread(PushBackInputStream.java:143)
    at org.apache.pdfbox.io.PushBackInputStream.unread(PushBackInputStream.java:132)
            at org.apache.pdfbox.pdfparser.BaseParser.parseCOSStream(BaseParser.java:552)
     [wrapped] org.apache.pdfbox.exceptions.WrappedIOException: Could not push back 811745 bytes in order to reparse stream. Try increasing push back buffer using system property org.apache.pdfbox.baseParser.pushBackSize
    at org.apache.pdfbox.pdfparser.BaseParser.parseCOSStream(BaseParser.java:556)
    at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:652)
    java.io.IOException: expected='endstream' actual='' at offset 1395276
            at org.apache.pdfbox.pdfparser.BaseParser.parseCOSStream(BaseParser.java:607)
            at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:652)
            at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:205)

    Resolution:
    1) The PDFs which you are trying to merge or split might be having some characters or encoding which is not supported by this PDFBox API. You can check the PDF content and upload new PDFs

    2) You can try upgrading to newer version or may be latest of PDFBox API

    3) Try setting org.apache.pdfbox.baseParser.pushBackSize=2024768 or any higher value than mentioned in the error to raise the buffer size, restart the server and try.
    You can try setting this property in the envt variable OR using System.setProperty("org.apache.pdfbox.baseParser.pushBackSize", "2024768"); in your java code which is actually merging/splitting PDF files.

    4) Replace the existing parser with a non-sequential parser. That is, replace the below line with next line:
    doc = PDDocument.load(input);
    doc = PDDocument.loadNonSeq(input, null);
    Courtesy: https://stackoverflow.com/questions/22946079/pdfbox-loading-large-files/30780628

    --------------------------------------------------------------------------------------------------------
    When a document is checked out from Alfresco share, two copies - a working copy and an original copy will be created.
    Now, if someone intentionally or accidentally deletes the working copy, the original copy of the document might not be visible in Alfresco Share.

    Issue: ADF shows the document (original) as locked, but Share does not show the document itself.

    Resolution:
    1) Try to find out if it's actually deleted by someone. If yes, have screen sharing session with him/her, and ask that user to go to Alf Share > My Profile > Trashcan > Recover the deleted item

    2) If you cannot find the document in anybody's trashcan, you can search it with fts-alfresco query in archive spacesstore from node browser and verify if the document exists in archive store. From it's properties, you can come to know who deleted it and then ask him to recover.

    3) If you are unable to find it in archive store, also not able to find in someone's trashcan, it might be deleted through some REST call or script executed by a functional user OR through some other unknown mechanism : If restart of server is permitted, try to write and deploy a webscript which actually deletes or unlocks or check-in the file through it's noderef.

    4) If this issue is in production envt, and restart is not permitted, go via the javascript API way.
    Try out the following option:
    var node = search.findNode("workspace://SpacesStore/....");
    node.remove();
    If you do not want this file, you can execute the above script by putting it under Data Dictionary > Scripts folder.

    If you want to keep the file (and do not want to delete it) , then try following javascript options:
    node.checkout();
    node.checkin();
    node.cancelCheckout();
    node.unlock();
    Courtesy: https://docs.alfresco.com/6.0/references/API-JS-CheckInOut.html

     You might also get an error like : Node is already checked-out OR Access denied OR Cannot perform this operation , etc

    Then you may want to go for providing options/actions in ADF - for deleting doc, unlocking doc if you have not kept it.

    5) Last (not recommended) way would be accessing the db tables, and checking which document noderef is what you want, and then change/delete the relevant entries. But it is risky and alfresco db is wired in a complex manner and not recommended to be touched/accessed directly. Instead, it should be done via the API layer.

    6) Try manually uploading the same file name from Alf.Share in the same folder where it's shown as locked and see what message you are getting.

    7) Check if you are able to replicate this behaviour for multiple documents or only this particular document. That is, it's not a data specific issue.

    8) Try to check on other envt - DEV, QA ,etc if you can see the same error there.

    9) If it's an external service (ex: spring batch) which is pushing files to Alfresco from FTP location, then try with different modes - like try pushing file from DEV spring batch service by pointing it to prod repo server, same way QA spring batch service pointing to prod repo server; try this in case you are seeing different behaviours envt wise and you suspect it's envt specific issue OR issue with the spring batch service.
    --------------------------------------------------------------------------------------------------------

    Script to unlock nodes:
    ----------------------------

    function getNode(){
        var def = {
            query : "PATH:'/app:company_home/st:sites/cm:site-name/cm:documentLibrary/cm:foldername//*' AND EXACTTYPE:'cm:content' ",
            language: "fts-alfresco"
       };
       
       return search.query(def);
    }
    var nodes = getNode();

    if(nodes!=null){
       logger.info("Count of nodes:"+nodes.length);
       for(var i=0; i<nodes.length ; i++){
          logger.info(nodes[i].properties['cm:name']);
          nodes[i].unlock();
       }
    }


    Script to hide / unhide nodes:
    ----------------------------

    function getNode(){
        var def = {
            query : "PATH:'/app:company_home/st:sites/cm:site-name/cm:documentLibrary/cm:foldername//*' AND EXACTTYPE:'cm:content' ",
            language: "fts-alfresco"
       };
       
       return search.query(def);
    }
    var nodes = getNode();

    if(nodes!=null){
       logger.info("Count of nodes:"+nodes.length);
       for(var i=0; i<nodes.length ; i++){
          logger.info(nodes[i].properties['cm:name']);
          nodes[i].addAspect("sys:hidden");
          //nodes[i].removeAspect("sys:hidden");
       }
    }
    --------------------------------------------------------------------------------------------------------

    Issue: alfresco-pdf-renderer not working in linux (not generating thumbnails only for txt, ftl,html mimetypes) but working for other mimetypes. Working in windows for all mimes:

    Resolution: Change the owner of 'alfresco-pdf-renderer' file from ec2-user to root using command:

    sudo chown root:root alfresco-pdf-renderer

    Share console properties set:
    alfresco-pdf-renderer root -->   /app/alfresco/alfresco-pdf-renderer
    alfresco-pdf-renderer exe -->   /app/alfresco/alfresco-pdf-renderer/alfresco-pdf-renderer

    Another option: https://hub.alfresco.com/t5/alfresco-content-services-forum/how-do-i-integrate-alfresco-pdf-renderer-in-the-community/td-p/218405


    --------------------------------------------------------------------------------------------------------

    Alfresco FTS query involving "PARENT" attribute not working in combination of other attributes like TAG:
    PARENT attribute returns the children (documents) lying under the specified noderef.

    PARENT attribute is not working in combination with other attributes like TAG, cm:name for partial search.

    For example:

    PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e AND ~cm:name:"*.docx" à this is not returning any item

    PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e AND TAG:”abc" à  not working

    PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e AND =TAG:”abc" à not working

    PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e AND ~TAG:”abc" à not working

    PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e AND TAG:”ABC" à  not working

     

    The 1st part of the query (PARENT:c0ee1ecc-8a1f-467c-b6e0-eca2db5f2f3e) is not held up in memory  so that 2nd part of the query is not searched only within those contents.

    This is working fine in combination with PATH query:

    PATH:"/app:company_home/st:sites/cm:sitename/cm:documentLibrary/cm:foldername//*" AND cm:name:"*.docx"

     

    Alternate solutions can be using the PATH query instead of PARENT, so the query would be like à PATH:"/app:company_home/st:sites/cm:sitename/cm:documentLibrary/cm:foldername//*" AND cm:name:"*.docx"

    OR

    searching with type  à TYPE:"custom:csDocument" AND cm:name:"*.docx"


    --------------------------------------------------------------------------------------------------------

    Alfresco Installation / Setup:

    When alfresco is being setup of AWS or cloud, and you are bound to use S3 bucket itself for docs storage, then always follow the practice as:
    1) Installing alfresco (installer bin file or distribution zip). DO NOT start alfresco server.
    2) Install the s3-connector amp file through alfresco-mmt.jar
    3) Change the alfresco-global.properties to add the s3 bucket name and location (s3.bucketName and s3.bucketLocation). NOTE: You can use access key, secret key to connect to s3 and specify here, but recommended is that you create a role in AWS and then bind it to s3. So the role who is accessing ec2 instance will have full rights on s3 bucket. Then alfresco will automatically use this role to access (read/write) to s3 bucket.
    4) Now start alfresco.

    If you do not follow the above steps for fresh setup/installation, then you might run into the error of "Ensure that the 'dir.root' property is pointing to the correct data location". This can happen when you installed and started alfresco with normal filesystem (alf_data contentstore) and postgres db (default). And then you upload a few files in Alfresco.
    Now you decide to go with s3 connector and then stop alfresco, install s3-connector amp and then start alfresco. This might cause an issue. So better to prevent the error and save time. Follow the above four steps.

    No comments:

    Post a Comment