Hello everyone, I am new to Alfresco and I am working on a project in which I have to create a folder where all the stored files are going to be of the same format (word or pdf) and each file must have the same name only differentiated by a number. This number represents the document number and must also be included in the content of the document. Users will create these documents from a template and the document number must be assigned automatically. If you could give me a hand to know where to start or which way to go, will help me a lot. Thanks in advance
First, automatically generating a document number. To do that, consider writing a "service" class that is responsible for handing out document numbers. It's up to you whether you store the number in a database or somewhere in the repository. Many people prefer to just write a little JSON document in the Data Dictionary that tracks document numbers.
Next, you want to insert the number into the content of a file. This is tricky because if you are dealing with a variety of binary file formats, you'll potentially need an API for each one. You also need a way to specify where in the file the document number will be placed.
If you could simplify your requirement to a specific file type that would help. For example, if you were to only need to insert the doc number into Word documents, you could use docx4j. I like docx4j because it is easy to do simple things like create a document template that has a placeholder, then send key-values to the API to replace the placeholders with the values. You can place this logic in a general "doc generation" service class.
Last, how you actually trigger the generation and insertion. As Jose mentioned, a rule is probably the best approach here. The rule should probably invoke a Java-based rule action class that leverages the autonumber service and the "doc generation" service mentioned above.
Sure, you'll create a project using the Alfresco SDK. That will give you a Maven-based source code structure that will allow you to compile an AMP (Alfresco Module Package) that you will deploy to your WAR.
A service is just a class that is responsible for some specific operation. There are many many examples of this pattern, but here is a simple one that is easy to get your head around:
So you'd create an AutoNumberService.java class where your autonumbering logic would reside. It might have a method called getNextNumber() or something like that.
Then you'd also create a DocumentGenerationService.java class where your doc generation logic would reside. It might have a document called resolvePlaceholders(Map<String, Object> placeholderMap, NodeRef nodeRef) or something like that.
Of course each of these might be worthy of being in completely separate projects/separate AMP files, but that's up to you.
Finally, you'll create something like DocumentNumberActionExecuter.java that will be your custom rule action. It will leverage both of these services to actually perform the action on a document when it is added to a folder.
If this is new to you I'd recommend working through my tutorials. If you have problems, create a new post with the specifics and someone will help.