Saturday, 26 November 2016

Files not deleted by system

Whenever you face issues like you are trying to delete some files or folders either manually with windows explorer or via code, then the files may not get deleted.
Situations should be like:

  • Files already in use (opened in the system) not allowing you to delete it. Resolution - Close the file and try to delete or execute the delete code
  • Your code or maven build trying to delete the target folder but not able to. Resolution - Close the target folder or the sub directories of it. Also it can be opened in the command prompt or through some other editor in Git Bash or Git hub OR may be some files inside the target folder might be opened in notepad or Notepad++. Close all and then try to delete. If nothing works, close all applications and try deleting. Last option would be restarting the system.
  • Sometimes, java code like Files.deleteQuietly or Files.delete or Files.forceDelete may not work OR may delete some files but a few files may remain undeleted. Resolution - The code through which you are reading the file, the inputstream of it might be remaining open. Close the inputstream after you finish reading or working with the file. This occurs when you are opening so many files in bulk using your code and inputstream might be remaining opened. Close the inputstream. That is, if you are inside a loop and opening/reading new file everytime, just close the inputstream object once you finish working with it in each iteration if you don't need it. This should resolve the problem of few files not getting deleted
  • In Alfresco, in document details page, the preview of the document might not be loaded inspite of the document getting previewed correctly after downloading or viewing in browser. Resolution - You might be writing this file in alfresco through ContentWriter and the code to write the file might be improper or incomplete. You can try the following in such situations:
    • Put the code sequence like : 
      • Creating node
      • Setting aspects/properties on it (if any)
      • writer.guessMimeType()
      • writer.guessEncoding()
      • writer.putContent(...)
    •  Instead of writing writer.setMimetype and writer.setEncoding try using above options like writer.guessMimetype() and writer.guessEncoding(). This should fix your problem of content not getting previewed
  • If the content in alfresco is not previewed and also even after downloading or viewing it in browser doesnot show the document, then the document itself might be corrupted. Resolution: 
    • Check the document on your local system itself (from windows explorer) that are you able to open it correctly. The document itself might be corrupted and not able to open.
    • If you are able to open doc in windows, but not able to preview after downloading from alfresco then the document should be corrupted after arriving in alfresco itself. Check the code for upload or code of creating content in alfresco. If its your custom code, follow above steps of writing or refer docs.alfresco.com for using ContentWriter and ContentReader object in alfresco for reading/writing content.

Thursday, 10 November 2016

Importing individual maven alfresco 5 SDK 2.2.0 / 2.2.1 projects in eclipse as all-in-one project

While importing some existing projects or applications (which are created / built previously as individual repo or share amp projects) can cause problems setting up and running into your eclipse as we might be using local SDK (all-in-one) and the existing project might be built with repo/share individually and having local Alfresco installed (with alfresco installer/setup).

These projects have been setup using individual Repo and Share SDKs. We would need those projects to run as AIO into our local, to overcome individual servers start up issues.

So, here are the steps you need to follow if you come across such projects.

1.
Uncomment all required modules defined in main project's pom.xml file. Uncomment repo, share, solr-config, runner, etc modules.
E.g.

<modules>
    <module>projectone-repo-amp</module>
    <module>projectone-share-amp</module>
    <module>repo</module>
    <module>solr-config</module>
    <module>share</module>
    <module>runner</module> 
</modules>

2. Now, Import all these modules again into your eclipse.
File -> Import -> Maven Project -> (Select same project which you have imported)

3. Navigate to repo project's pom.xml file and change artifactId in dependency and overlay tag having 'repo-amp' value. Change this value to artifactId defined into your repo-amp project's pom.xml file.
E.g.
 <dependency>
           
<groupId>${project.groupId}</groupId>
           
<artifactId>projectone-repo-amp</artifactId>
           
<version>${project.version}</version>
           
<type>amp</type>
       
</dependency>

<overlay>
<groupId>${project.groupId}</groupId>
<artifactId>projectone-repo-amp</artifactId>
<type>amp</type>
</overlay>

4. Perform above step #3 for share project's pom.xml file.

5. Clean and build your whole project, remove dependency related errors if any.

6. Execute below command by selecting main project and monitor logs.
$ mvn clean install -Prun -D skipTests=true

Your application should be up and running after performing these steps.

Content Replication in alfresco

Replicating content from one server to another in alfresco 5.0
Steps:

a.      Identify two machines (IP address/host names with port numbers on which alfresco is running).
b.      On source machine:
                                                    i.     Create a folder or select a folder/file you want to replicate on target repository
                                                   ii.     Enable replication service (checkbox) from http://localhost:8080/alfresco/s/enterprise/admin/admin-replicationservice and click Save OR in alfresco-global.properties add property replication.enabled=true but it doesnot work when tried. So do it from share ui.
                                                  iii.     Here, the checkbox ‘Read Only Replication’ will be enabled (checked) by default. Uncheck it if you want that the content/folders can be edited/deleted by the target repository. Otherwise by default the content replicated on target will be read only. Click Save.
                                                  iv.     Go to Data Dictionary > Transfers > Transfer Target Groups > Default Group. This folder ‘Default Group’ has a rule to specialize the incoming type of folder to trx:transferTarget. So create a new folder here (any name for ex: oct5).
                                                   v.     Edit properties of folder oct5, specify the endpoint host (ip address/asset id of target), endpoint port (8080 if target alf running on 8080), username and pwd (admin/admin mostly for target alf). Click Enabled checkbox. Save.
                                                  vi.     Go to Admin tools > Replication jobs > Create Job. Specify name, Payload (folder you want to choose for replicating on target repository), Trasfer target as ‘oct5’, click Enabled.
                                                vii.     Now, make the target repository ready to accept the data. (i.e before starting the replication ensure that target repository is ready by following the step c mentioned below)
                                               viii.     Click Run
c.      On target machine:
                                                    i.     In alfresco-global.properties, add the property transferservice.receiver.enabled=true
                                                   ii.     In share-config-custom.xml, add the following entry:
<config evaluator="string-compare" condition="Replication">
      <share-urls>
              <share-url repositoryId="622f9533-2a1e-48fe-af4eee9e41667ea4">http://localhost:8080/share/</share-url>
</share-urls>
</config>
                                                  iii.     The repositoryId above should be taken from source repository, the source repository can give it to target by hitting the following url and getting the current repository id: http://localhost:8080/alfresco/s/enterprise/admin/admin-repositoryinfo
                                                  iv.     And for <share-url> value, keep localhost itself, don’t point it to source repository ip address or asset id.
                                                   v.     Start alfresco.

d.      Findings after the replication job is run:
                                                    i.     The nodeRefs of the source and target repository remains the same.
                                                   ii.     The folders/files created on target repo will have a replication symbol besides it with label ‘Transferred from another repository’.
                                                  iii.     The bpm package/workflow won’t be replicated to target repo.
                                                  iv.     All metadata/content along with permissions will be replicated to target repo. But for permissions to be replicated the same users/groups should exist on target repo as they are on source repo