Professional Documents
Culture Documents
1
Configuration and Customisation Exercises
Alfresco 3.1
Contents
MODULE 1 EXERCISES ............................................................................................................................. I EXERCISE 1.01 FAMILIARISING YOURSELF WITH THE DOMAIN MODEL........................................................ I EXERCISE 1.02 USING THE NODE BROWSER ................................................................................................ I MODULE 2 EXERCISES ............................................................................................................................II EXERCISE 2.01 CREATE NEW ASPECT PROJECT PROPERTIES ................................................................... II EXERCISE 2.02 ADVANCED SEARCH .......................................................................................................... II MODULE 3 EXERCISES .......................................................................................................................... III EXERCISE 3.01 WRITE A BASIC TEMPLATE ................................................................................................ III EXERCISE 3.02 PRINTING YOUR USERNAME ............................................................................................. III EXERCISE 3.03 GETTING THE NUMBER OF CHILD NODES ........................................................................... III EXERCISE 3.04 LINKING TO CONTENT ...................................................................................................... III EXERCISE 3.05 DISPLAYING DATES AND NUMBERS.................................................................................. III EXERCISE 3.06 PERFORMING A SEARCH....................................................................................................IV MODULE 4 EXERCISES ............................................................................................................................ V EXERCISE 4.01 CREATING NEW DOCUMENTS ............................................................................................ V EXERCISE 4.02 ADDING ASPECTS .............................................................................................................. V EXERCISE 4.03 EXECUTING SEARCHES ...................................................................................................... V MODULE 5 EXERCISES .......................................................................................................................... VI EXERCISE 5.01 CREATING A BASIC WEB SCRIPT .......................................................................................VI EXERCISE 5.02 ADDING A JAVASCRIPT CONTROLLER ...............................................................................VI EXERCISE 5.03 OVERRIDING WEB SCRIPTS...............................................................................................VI MODULE 6 EXERCISES ......................................................................................................................... VII EXERCISE 6.01 CLIENT CONFIG ACTIONS ............................................................................................ VII EXERCISE 6.02 SERVER CONFIG CATEGORIES ...................................................................................... VII EXERCISE 6.03 SERVER CONFIG TRANSFORMATIONS .......................................................................... VII
Module 1 Exercises
Exercise 1.01 Familiarising yourself with the domain model
1. Find and open contentModel.xml and spend time viewing it. Make yourself familiar with the <type> and <aspect> tags. 2. Find and open applicationModel.xml and spend time viewing it. Make yourself familiar with the <type> and <aspect> tags. 3. Find and open systemModel.xml and spend time viewing it. Make yourself familiar with the <type> and <aspect> tags. 4. Find and open dictionaryModel.xml and spend time viewing it. Make yourself familiar with the <type> and <aspect> tags.
Module 2 Exercises
Exercise 2.01 Create new Aspect Project Properties
5. Create a new Aspect named Project Properties. 6. You can use the example namespace my or if you wish create a new namespace. 7. Give the aspect a logical referenceable name like my:projectproperties. 8. create properties like: my:projectname my:projectclient my:projectdeveloper my:projectteamleader my:projectmanager my:projectstartdate my:projectenddate
9. Make all the properties in the aspect mandatory. 10. Remember to add the aspect you created to the web-client-config-custom.xml in order to be able to use it in the web client. 11. Restart the alfresco server and create a space called projects. 12. Add a rule to the space that will apply the Project Properties aspect to any content added to the projects space. 13. Test the rule by adding some content to the projects space.
16. Add <metadata> element. <meta-data aspect= "cm:effectivity" property="cm:to" /> 17. Restart the Alfresco server. 18. Add effectivity aspect and dates for a document. 19. Go to Advanced Search and try to find the document.
Module 3 Exercises
Exercise 3.01 Write a basic template
Write a basic template helloworld.ftl which simply prints the following HTML code: <p>Hello World!</p>
Module 4 Exercises
Exercise 4.01 Creating New Documents
20. Write a script that creates a new JavaScript Test file within Company Home and sets its content to be the text This is a test JavaScript file with the mimetype text/plain. 21. Place the script inside the Scripts space within the Data Dictionary so it is picked up by the system 22. Navigate to Company Home and click More Actions and Select View Details. 23. Run the script by clicking the Run Action link on the right side and selecting Execute Script from the list. 24. Navigate to Company Home to check the file was created. 25. Delete the test file from Company Home. Hint 1 The mynode.createFile(name) function will create the file and return a reference to its node. Hint 2 You can use a nodes content property to read or set its content. You should also set the MIME type of the content, via the dummy mimetype property.
Module 5 Exercises
Exercise 5.01 Creating a basic Web Script
Re-use the hellouser.ftl template you built in Exercise 3.02 to create a Web Script which does the same thing. You will need to create an XML descriptor file and place this together with the Freemarker file into the Data Dictionary.
Module 6 Exercises
Exercise 6.01 Client Config Actions
29. Change the configuration for the space_details and doc_details action groups. 30. Make the create_shortcut action appear at the top of the list for both the space_details and document_details. 31. Add the Create_shortcut action to the document_browse_menu action group. 32. Restart Alfresco and test.
Alfresco 3.1
Installing and Using Alfresco Exercises
Alfresco 3.1
Contents
MODULE 1 EXERCISES ............................................................................................................................. 1 EXERCISE 1.01 - INSTALLATION .................................................................................................................... 1 EXERCISE 1.02 CONNECTING TO MYSQL DATABASE................................................................................ 1 MODULE 2 EXERCISES ............................................................................................................................. 2 EXERCISE 2.01 USER OPTIONS ................................................................................................................... 2 EXERCISE 2.02 MY ALFRESCO DASHBOARD .............................................................................................. 2 EXERCISE 2.03 WORKING WITH SPACES .................................................................................................... 2 EXERCISE 2.04 WORKING WITH THE SHELF ............................................................................................... 3 EXERCISE 2.05 WORKING WITH CONTENT ................................................................................................. 4 EXERCISE 2.06 ADDING CONTENT ............................................................................................................. 4 EXERCISE 2.07 CREATING AND EDITING CONTENT .................................................................................... 5 EXERCISE 2.09 DELETING SPACES/CONTENT ............................................................................................. 5 EXERCISE 2.10 SEARCHING ........................................................................................................................ 6 EXERCISE 2.11 ADVANCED SPACE WIZARD............................................................................................... 7 MODULE 3 EXERCISES ............................................................................................................................. 8 EXERCISE 3.01 COLLABORATING WITH USERS .......................................................................................... 8 EXERCISE 3.02 RECOVERING DELETED ITEMS ........................................................................................... 8 EXERCISE 3.03 DISCUSSIONS ATTACHED TO CONTENT ............................................................................. 8 MODULE 4 EXERCISES ............................................................................................................................. 9 EXERCISE 4.01 APPLYING VERSIONABLE ASPECT TO CONTENT................................................................. 9 EXERCISE 4.02 CHECK OUT AND CHECK IN ................................................................................................ 9 EXERCISE 4.03 CATEGORIZING AND ADVANCED SEARCHING ................................................................... 10 EXERCISE 4.04 ACCESSING CONTENT WITH FTP...................................................................................... 10 EXERCISE 4.05 ACCESSING CONTENT WITH WEBDAV ............................................................................ 11 EXERCISE 4.06 ACCESSING CONTENT WITH AS A SHARED NETWORK DRIVE (CIFS) ................................ 11 EXERCISE 4.07 MAPPING A NETWORK DRIVE (CIFS) ............................................................................... 11 MODULE 5 EXERCISES ........................................................................................................................... 12 EXERCISE 5.01 CONTENT ACTIONS TRANSFORMING CONTENT ............................................................ 12 EXERCISE 5.02 CONTENT ACTIONS APPLYING ASPECTS ....................................................................... 12 EXERCISE 5.03 CONTENT RULES AND ACTIONS ....................................................................................... 13 EXERCISE 5.04 SIMPLE WORKFLOW ........................................................................................................ 14 EXERCISE 5.05 COMPOUND WORKFLOW ................................................................................................. 14 MODULE 6 EXERCISES ........................................................................................................................... 16 EXERCISE 6.01 PRESENTATION TEMPLATES ON CONTENT AND SPACES .................................................. 16 EXERCISE 6.02 APPLYING CUSTOM VIEWS .............................................................................................. 16
Alfresco 3.1
Module 1 Exercises
Exercise 1.01 - Installation
45. If not already done, install the jdk on your machine. a. Set the standard Environment Variables (JAVA_HOME, etc). b. Set the non-standard Environment Variables (JAVA_OPTS). 46. Install OpenOffice. 47. Install Alfresco Tomcat bundle. a. Enable CIFS server and Image manipulation by adding <alfresco_home>\bin to the path Environment Variable. b. Check for port conflicts (netstat). c. Create the alfresco database. d. Start Alfresco. 48. Test your installation. a. Test Web Client. b. Test CIFS.
50. Configure alfresco to connect to the MySQL Database. 51. Test your installation.
Alfresco 3.1
Module 2 Exercises
Exercise 2.01 User Options
1. Log in as admin: username = admin password = admin 2. Modify the users properties: g. Change the users first name to your first name. h. Change the users last name to your last name. i. Change the users password to demo.
Alfresco 3.1
6. Click the Modify in the Properties menu. 7. Change the description and icon. d. Close the Properties. 8. Navigate to the Users Space inside Company Home: a. Take note of all the users home spaces. 9. Change the Icon View to Icon and Details to see the differences. a. Take note of the number of items displayed for each view. b. Change the number of spaces displayed for each view and press Enter. 10. Sort spaces and content in the Details view. a. Click the down arrow against the Name column to sort it in reverse. Click again to sort it alphabetically. b. Click the down arrow against another column to sort on it. 11. Navigating the Toolbar: c. Use The Toolbar to go to Company Home, My Home, Guest Home, My Alfresco.
4. Remove from Clipboard (or Remove All). Note Does not delete the actual item.
5. Cut the just copied Alfresco-Tutorial.pdf to the Clipboard. The content remains until pasted. You can cancel the cut by removing it from the Clipboard. The icon in the Clipboard indicates whether it was from a cut or copy. 6. Paste from Clipboard to Documents. a. Navigate into Documents and paste from the Clipboard. b. Check it is no longer in Training. c. It is automatically removed from the Clipboard.
7. In Documents, click its View Details. 8. On the Actions frame, choose Create Shortcut. It adds link to space in the Shelf. Click the shortcut to navigate to the space view. 9. On the Alfresco-Tutorial.pdf, click View Details and from the Actions frame, choose Create Shortcut. It adds link to content details. a. Click Close to return to Documents b. Click the shortcut to return to the details for Alfresco-Tutorial.pdf.
Alfresco 3.1
10. Select Remove Item in the Shortcuts to remove the shortcut, but not the item to which it is linked. Recent spaces remembers the last 6 spaces you visited for quick navigation.
4. Check default details and click Finish. 5. Check the document has been added to Alfresco by viewing it. 6. Use Add Content to upload any word document to the Training space. Notice that Alfresco extracts metadata, such as title, automatically 7. Open the word document by clicking on it. If it can not be viewed directly in the browser, it will prompt to save or open. Important Any edits made to a document through the open prompt are on a temporary file, and are not kept automatically by Alfresco, but may be saved using Save As if available
Alfresco 3.1
4. Either click Finish to complete, or Next to see a summary of changes about to be made and then click Finish. 5. Select the Edit icon for simple.html and make changes. As it is inline editable, you can use the WYSIWYG editor. 6. Save the changes. 7. Editing other content (not inline editable). 8. In Training, select the Edit for myword.doc. 9. Follow the instructions to download. a. Right-click the link and choose Save link as or Save target as. b. Choose where to save, such as the desktop. 10. Edit the file (MS Word or WordPad), make changes, and save. 11. Click the More Actions icon for myword.doc in Alfresco and choose Update. a. Browse to the Windows desktop and select the recently changed myword.doc and upload it. 12. View the document in Alfresco to see the changes have been made.
Alfresco 3.1
3. Search results returned ordered on best match. Same options for views, use Details View to reorder results
4. View the Details of one of the matched results, then use Next and Previous Item to cycle through them 5. Close the search results using the Close Search action. 6. Select Advanced Search from the Toolbar search options. 7. On the Advanced options page, search within a space. Optionally, its sub-spaces. Matches a given category, optionally sub-categories Matches properties (Title, Description, Author) Within Date Ranges (Created, Modified)
8. Try restricting the search to Documents b. Click to specify a space c. Defaults to current space d. Click Training to navigate into sub-spaces e. Navigate into Documents f. Click OK to confirm selection Click Go Up to navigate to parent spaces/ Note
9. Clear all options using Reset All Action 10. Save a search for personal use. 11. Save another search for public use. 12. Log in as another user and try to load your publicly saved search.
Alfresco 3.1
5. Based on a Space Template: g. Ensure you are in the Training space. h. Create a space using the Advanced Space Wizard action in the Create menu. i. j. k. Select Using a Template. Choose the Software Engineering Project template. Name the new space ProjectX. All content, sub-spaces and smart space information will be copied.
6. Creating space templates by hand. Copy or create space in the Company Home>Data Dictionary>Space Templates Just as if a normal space.
Alfresco 3.1
Module 3 Exercises
Exercise 3.01 Collaborating With Users
1. Log in as admin user. 2. Create a space My Shared Space. 3. Create some Inline Editable content in this new space (example.txt). 4. Within My Shared Space, select More Actions > Manage Space Users. 5. Uncheck Inherit Parent Space Permissions and invite the Guest user as a Consumer. 6. Repeat Step 5 for the Company Home space. 7. Log out and log in as guest. 8. Navigate to My Shared Space. 9. Notice what operations you can perform within this space.
Alfresco 3.1
Module 4 Exercises
Exercise 4.01 Applying Versionable Aspect to content
1. Log in as the admin user. 2. Create a space Document Management. 3. Invite user training1 to be a Coordinator on this space. 4. Create some HTML content inline my-content.html. 5. View the Properties for my-content.html. Make sure the document is inline editable.
6. Expand the Version History frame at the bottom of the page. 7. Click the link Allow Versioning. 8. Take note of the information displayed in the Version History frame. 9. Close the properties page to go back to the Document Management space. 10. Click Edit to edit the document and make some changes. 11. Go back to the documents properties and view the Version History again. What happens if two users try to edit the same document at the same time?
6. Log in as training1 user, edit the document and save changes again. 7. Click the Check In icon to check in changes made to the document and unlock it. a. You can add some Version Notes. b. Uncheck Minor Change to update the major version number. c. Can optionally check in changes and keep file checked out. d. Can upload a local copy from your desktop if you wish.
Alfresco 3.1
8. Click Check In. 9. View the document to see the changes have been made. 10. View the documents properties to see its version history.
We now need to apply a specific category to this item. 1. Click the Change Category icon on the right side of Category frame. This is to edit the categories properties. 2. Click Select to select a category. 3. Navigate down the Regions category to select United Kingdom and add to list. 4. Select another category inside the Languages category. 5. Click OK. 6. Close the Details view of my-content.html. 7. On the top right side of the browser window, click Advanced Search. 8. Select the Show me results in the categories dropdown list. 9. Use the advanced categories to search for all documents in the United Kingdom category. 10. Notice you can also select a parent category and search all categories under the parent categories by checking the Include sub-categories box. 11. When finished, close the advanced search window.
Alfresco 3.1
Alfresco 3.1
Module 5 Exercises
Exercise 5.01 Content Actions Transforming Content
1. Log in as admin user and create a space named Images. 2. Use Add Content to upload logo.jpg into your home. 3. Copy logo.jpg to the clipboard. 4. Inside Images, create a sub-space named Web Ready. 5. Paste logo.jpg from the clipboard into Web Ready. 6. View the Details page for logo.jpg and select Run Action from the Actions menu. 7. Choose Transform and copy image to a specific space and click Next. 8. Select a required format of PNG. 9. For options put -resize 200x200. 10. For destination choose the Web Ready space. 11. Click Finish to run the action. 12. Find and view the transformed image. 13. Finally, delete logo.jpg in Images and the transformed image.
Alfresco 3.1
7. Click Next to define the actions. 8. For the rule action, select Transform and copy image in a given format to a specific location. 9. Click Set Values and Add. 10. Select a required format of PNG. 11. For options, put -resize 200x200. 12. For destination, choose the Web Ready space. Remember that the rules will run again if the destination is the same space. This is not a problem in this example, as the rule will not match since it is now .png.
13. Click OK and click Next to move to the next page of the wizard. 14. Choose a rule Type of Inbound and give it a title of resize to png. 15. Click Next to view a summary of the rule. 16. Click Finish to save the rule. 17. Close the list of rules. 18. Paste logo.jpg into the Images space. It should still be in the clipboard from earlier, if not copy again from your home 19. There should now be a transformed copy. 20. Delete logo.jpg in Images and the transformed copy.
Alfresco 3.1
Alfresco 3.1
8. Step Three Enter Details: a. Choose Type=Inbound b. Set Title=Drafts Rules c. Check Apply rule to sub spaces d. Uncheck Run rule in background 9. Click Next/Finish/Close. 10. Now view the Pending Approval space details page. 11. In the Actions frame click Manage Content Rules. 12. Click Create Rule. 13. Step One Select Conditions: Choose All Items and Add to List
14. Click Next. 15. Step Two - Select Actions: a. Add simple workflow to item: Name for approve step = Publish Document Action for approve step = move to Publish space Name for reject step = Reject Document Action for reject step = move to Drafts space Click OK/Next 16. Step Three Enter Details: a. Choose Type=Inbound b. Set Title=Pending Approval Rules c. Check Apply rule to sub spaces d. Uncheck Run rule in background 17. Click Next/Finish/Close. 18. Now we must test that our work flow behaves as planed a. Add content to Drafts b. Check its details to see that the aspects have been applied Check the Workflow Check the Category Check the Version History 19. For the content items actions, click Request Approval. This kicks off the workflow rule you created. Notice the item has been removed from the Drafts space. 20. Navigate to the Pending Approval space. The content item is now in this space. 21. On the content items Actions click Reject Document. The item is copied back to Drafts. 22. Repeat steps 18 to 21, and this time Approve Document.
Alfresco 3.1
Module 6 Exercises
Exercise 6.01 Presentation Templates on Content and Spaces
1. Navigate to some content. 2. Click on the Content items Action Preview in Template. 3. Use the drop-down menu on the top right side of the page to view the document with various templates. doc_info.ftl general_example.ftl localizable.ftl my_summary.ftl recent_docs.ftl translatable.ftl
Contents
Getting Started .......................................................................................................................... Alfresco SDK ................................................................................................................5 Introduction.............................................................................................................. 6 Downloading and Unpacking the Alfresco SDK...................................................... 7 Importing the Alfresco SDK projects into Eclipse.................................................... 9 Associating Source Code and Javadocs with the Alfresco Libraries..................... 12 SDK samples......................................................................................................... 15 SVN Repository..................................................................................................... 19 SDK Reference..................................................................................................... 20 Best Practices ............................................................................................................ 23 Coding Standards.................................................................................................. 24 Alfresco Module Packages (AMP)......................................................................... 25 Alfresco Repository Architecture ............................................................................ 27 Out of the Box....................................................................................................... 28 Service & Component Architecture....................................................................... 30 Repository Foundation Services API..................................................................... 33 Repository APIs..................................................................................................... 35 Developing against the Alfresco Repository ......................................................................... Spring Framework ..................................................................................................... 39 Introduction............................................................................................................ 40 Inversion of Control (IoC)...................................................................................... 41 Foundation Services API .......................................................................................... 43 Introduction............................................................................................................ 44 Access to Repository Foundation Services........................................................... 45 FirstFoundationClientwalkthrough......................................................................... 46 Other Foundation Services.................................................................................... 55 JCR API .......................................................................................................................57 Introduction............................................................................................................ 58 Web Services API ...................................................................................................... 59 Introduction............................................................................................................ 60 Available Web Services......................................................................................... 61 Separating Concerns using AOP ............................................................................. 63 Public Services and AOP proxies.......................................................................... 64 Extending the Alfresco Repository ......................................................................................... Repository Policies ................................................................................................... 67 Introduction............................................................................................................ 68 Available Policies.................................................................................................. 69 Policy Types.......................................................................................................... 70 Custom Aspect with Behaviour Howto.................................................................. 71 Repository Actions ....................................................................................................79 Introduction............................................................................................................ 80 Content Transformers ............................................................................................... 81 Introduction............................................................................................................ 82 Metadata Extractors .................................................................................................. 83 Introduction............................................................................................................ 84 MetadataExtracterRegistry.................................................................................... 85 Extending the Alfresco Web Client ......................................................................................... JavaServer Faces ...................................................................................................... 89 Introduction............................................................................................................ 90 Actions Framework ................................................................................................... 91 Introduction............................................................................................................ 92 Dialog Framework ......................................................................................................93 Introduction............................................................................................................ 94 Wizard Framework .....................................................................................................95
Introduction............................................................................................................ 96
Section 1
Getting Started
Getting Started - 3
4 - Getting Started
Alfresco SDK
Module 1
Alfresco SDK
Alfresco SDK - 5
Alfresco SDK
Introduction
The Alfresco SDK provides support for developers who wish to extend or customise the Alfresco platform. It has been designed for the developer to get developing with minimal fuss for the following development scenarios: Developing extensions for the Alfresco Repository and Web Client. Embedding Alfresco into applications via Alfresco's Java Foundation Services API or standards-compliant JCR API. Developing applications against a remote Alfresco Repository via Alfresco's Web Services API. Typically, the SDK is used stand-alone, but an Alfresco installation is also required if performing any of the following: Customising the Alfresco Web Client Deploying a custom module to a remote Alfresco repository Testing a custom application that connects to a remote Alfresco repository Note: The SDK is not designed for re-building Alfresco since it does not provide full build scripts and artifacts. If you wish to develop bug fixes or extend the core functionality of the Alfresco platform, you should use the full Alfresco development environment provided in the Alfresco SVN Repository. For more information, see SVN Repository on page 19 .
6 - Alfresco SDK
Alfresco SDK
Alfresco SDK - 7
Alfresco SDK
For a description of the contents of the Alfresco SDK, see SDK Contents on page 20 .
8 - Alfresco SDK
Alfresco SDK
1.1) From the Eclipse main menu, select Window --> Preferences... 1.2) In the Preferences dialog, select Java --> Compiler in the tree view. 1.3) In the JDK Compliance panel, set the Compiler compliance level to 5.0 or above:
1.4) Click OK
Alfresco SDK
Note: Do not navigate to the samples sub-directory, otherwise you will not see the SDK AlfrescoEmbedded and SDK AlfrescoRemote projects in the list.
In order to run the samples or to develop your own extension modules, you must import at least the SDK AlfrescoEmbedded and SDK AlfrescoRemote projects. The other SDK projects are samples for common development scenarios that you can study and run to learn more about developing Alfresco extension modules.
10 - Alfresco SDK
Alfresco SDK
2.5) Once you have selected the projects you wish to import, click Finish.
The imported projects are displayed in the Package Explorer:
Alfresco SDK - 11
Alfresco SDK
1) Expand the SDK AlfrescoEmbedded project in the Project Explorer. 2) Right click on the alfresco-repository.jar and select Properties from the popup menu.
Note: The JAR files may not be in alphabetical order.
4) Associating Javadocs
4.1) In the Properties for alfresco-repository.jar dialog, select Javadoc Location in the tree view. 4.2) In the Javadoc Location panel, select Javadoc in archive and click Browse... 4.3) Navigate to doc/api directory within your unpacked Alfresco SDK.
12 - Alfresco SDK
Alfresco SDK
4.5) Click Validate... to validate the Javadoc location, then click either OK to view the Javadocs in a web browser or Cancel if not.
Alfresco SDK - 13
Alfresco SDK
Note: The above steps need to be repeated for the following JARs: alfresco-core.jar alfresco-remote-api.jar alfresco-web-client.jar alfresco-web-service-client.jar (only Java source code is available)
14 - Alfresco SDK
Alfresco SDK
SDK samples
FirstFoundationClient and JCR Samples
The SDK FirstFoundationClient, SDK FirstJCRClient and SDK JCRSamples sample projects demonstrate how to access an embedded Alfresco repository via the Foundation Services API and the standards-compliant JCR API. These samples can be tested directly from within Eclipse and will automatically start an Alfresco repository in embedded mode. Before starting, the embedded repository needs to be configured. By default, the sample projects are configured to use a MySQL database named alfresco and a data directory with a relative path of ./alf_data. These parameters are defined in the custom-repository.properties file in the source/alfresco/extension directory of each project. It is good practice to define an absolute path for the data directory (dir.root parameter) and to configure all of the SDK projects to share the same database and the same dir.root. Example custom-repository.properties file:
dir.root=C:/alf_data #db.username=alfresco #db.password=alfresco # # MySQL connection (This is default and requires mysql-connector-java-3.1.12-bin.jar, which ships with the Alfresco server) # #db.driver=org.gjt.mm.mysql.Driver #db.url=jdbc:mysql://localhost/alfresco
The alfresco MySQL database also needs to be created using the scripts provided in the extras/databases/mysql directory of the unpacked Alfresco SDK. To create the database from the command line:
C:\alfresco-enterprise-sdk\extras\databases\mysql>mysql -u root -p < db_setup.sql Enter password: ********
The samples can now be tested by running the main Java classes from within Eclipse. In the following example, the FirstFoundationClient class is run as a Java Application:
Alfresco SDK - 15
Alfresco SDK
The Alfresco repository is automatically started in embedded mode. Because this is the first time the repository has been started, the initial bootstrap is executed to create the database tables. As you can see from the console messages below, the embedded repository uses C:\alf_data as it's data directory (dir.root).
The other embedded repository samples (SDK FirstJCRClient and SDK JCRSamples) can be run in the same way.
16 - Alfresco SDK
Alfresco SDK
The location of the remote repository is configured in the webserviceclient.properties file in the source/alfresco/extension directory of each Web Services project. If the remote repository is installed on the same machine and configured to use the default 8080 port, you will not have to modify the default value. Example webserviceclient.properties file:
# # Set the following property to reference the Alfresco server that you would like web service client # to communicate with repository.location=http://localhost:8080/alfresco/api
Once the remote repository has been installed and started, the Web Clients samples can be tested by running the main Java classes from within Eclipse. In the following example, the FirstWebServiceClient class is run as a Java Application:
Alfresco SDK
Ant build and then re-deployed to the application server. For deployment in a production environment, a custom Web Client module should be packaged as an Alfresco Module Package (AMP). The SDK CustomDialog and SDK CustomWizard are presented in detail in the Custom Dialog Howto on page and the Custom Wizard Howto on page . The SDK TaggingSample sample is presented in detail in the Repository Action Howto on page .
18 - Alfresco SDK
Alfresco SDK
SVN Repository
The Alfresco Subversion repository gives you access to all of the Alfresco source code and build artifacts. It provides the latest work-in-progress developments. It should only be used if you wish to extend the Alfresco core framework or work on Alfresco bug fixes as it allows you to perform full re-builds of Alfresco itself. For most requirements, it is best to use the Alfresco SDK. Public read-only access to the Alfresco Subversion repository is available from the Alfresco web site. To checkout the source code, use the following procedure: 1. Install Subversion and ensure that svn is on the path. 2. Checkout the HEAD of the code stream:
svn co svn://svn.alfresco.com/alfresco/HEAD
or
svn co http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD
Alfresco SDK - 19
Alfresco SDK
SDK Reference
SDK Contents
An expanded Alfresco SDK contains the following directories and top-level files: bin Supporting dll's, exe's. doc Zipped Javadoc's for all pre-built libraries. extras Additional files - database setup and migration scripts. lib Alfresco pre-built libraries (JAR files). lib/deployment Alfresco libraries required for WCM deployment to a remote server. lib/remote Alfresco libraries required for access to a remote Alfresco repository via web services. lib/server Alfresco libraries required for embedding an Alfresco repository. licenses License files. samples Sample Eclipse projects for common development scenarios (see SDK Eclipse Projects on page 20 ). src Zipped source code for all pre-built libraries. license.txt Alfresco licence file. notice.txt Notices readme.txt Alfresco SDK readme.
Alfresco SDK
Sample project demonstrating how to develop and configure a custom JSP for the Alfresco Web Client. SDK CustomLogin Sample project demonstrating how to override the Login page of the Alfresco Web Client. SDK CustomWizard Sample project demonstrating how to develop and configure a custom Wizard for the Alfresco Web Client. SDK FirstFoundationClient Sample project demonstrating how to access an Alfresco (embedded) repository via the Foundation Services API. SDK FirstJCRClient Sample project demonstrating how to access an Alfresco (embedded) repository via the standards-compliant JCR API. SDK FirstWebServiceClient Sample project demonstrating how to access a remote Alfresco repository via the Web Services API. SDK JCRSamples More sample projects demonstrating how to access an Alfresco (embedded) repository via the standards-compliant JCR API. SDK TaggingSample Advanced sample project demonstrating how to develop a custom Action that takes parameters. SDK WebServiceSamples More sample projects demonstrating how to access a remote Alfresco repository via the Web Services API.
Alfresco SDK - 21
Alfresco SDK
22 - Alfresco SDK
Best Practices
Module 2
Best Practices
Best Practices - 23
Best Practices
Coding Standards
Coding Standards - Formatting
The core coding standards are the standard Java Code Conventions . Braces are on new lines. 4 space for tabbing, except for Web Client project that uses 3 spaces. 120 characters on a line is fine. Import declarations are managed by Eclipse's standard ordering rules (CTRL-SHIFT-O). This helps prevent code merge conflicts. XML documents use 3 space tabbing. The Eclipse plug-in, XMLBuddy, is generally used.
24 - Best Practices
Best Practices
source/java/ Contains the Java source for the Alfresco Module. source/web/ Contains any web UI resources (JSPs, images, CSS, JavaScript). config/ Contains configuration files and resources used by the module. build/ Build directory for compiled class files. build/dist/ Build directory for AMP files. build/lib/ Build directory for JAR files. The recommended package structure for Java source (source/java), configuration files and resources (config) is org.alfresco.module.<moduleid>, where moduleid is the unique
Best Practices - 25
Best Practices
module id of the module. Alfresco Module Packages are presented in more detail later on in the course. For more details, see Alfresco Module Packages on page .
26 - Best Practices
Module 3
Alfresco Repository Architecture
This is typical of a web architecture, where an application server houses the logic for both the user interface and domain. Storage of data and content is provided by persistent back-ends such as a database or file system. Any number of web browsers can connect to the application without prior client installation costs. In this particular case, the application server houses both the Alfresco Application and the Alfresco Repository. An Alfresco Application provides a complete solution tailored for a specific area of Content Management such as Document Management (DM), Web Content Management (WCM) and Records Management (RM). The Alfresco Repository provides a set of reusable cross-cutting Content Management services such as content storage, query, versioning and transformation which may be utilised by one or more applications. Although this is the default installed deployment, it is only one of many ways of utilising the capabilities and components of Alfresco. When we first set out to design Alfresco, we wanted to break away from
28 - Alfresco Repository Architecture
the mould of typical Content Management architectures which are monolithic and closed. The result is that Alfresco can neatly fit into existing environments and each of its components may be used in isolation or together to form the basis of many differing Content Management solutions. The remainder of this module explores the anatomy of the Alfresco Repository which will give a good understanding of the concepts and capabilities and how it achieves openness, scalability and flexibility.
The public interface point is the Alfresco Repository Foundation Services. Each service is exposed as a Java Interface to which a Repository client can bind and invoke without knowledge of its underlying implementation. A Service Registry lists the available services. Behind services are the implementation black boxes i.e. components. Each service and component is configured via the Spring framework in XML context files. Note: The Spring context file public-service-context.xml provides the configuration and binding of the Alfresco Repository Foundation Services. The Repository Foundation Services are the lowest level of public interface providing access to all Repository capabilities. Binding to this interface is possible via the Repository Service Registry, or via Spring dependency injection if the client is also Spring aware. Access to Foundation Services is limited to Repository clients who reside in the same process as the Repository. That is, the Foundation Services are an excellent API for clients who wish to embed the Repository. An important point to note is that the Foundation Services are where transaction and security policies are enforced. The policies themselves are declaratively specified and enforced via the injection of a transaction and security implementation into each service. Every service of Alfresco is transactional and secure. Other forms of API are provided too, however, all public entry points eventually go through this layer.
Alfresco supports a common scheme for making extensions to the Repository i.e. configuring a component, adding a new component or service, or removing capabilities. Extensions are encapsulated outside of the core Repository and plugged-in automatically. This means the core Repository can be upgraded to a newer version and extensions remain intact.
Apart from the strong Object/Relational mapping that Hibernate provides, it also brings pluggable caching support and SQL dialects. The first allows for tuning of the Alfresco meta-data store to provide optimum read and write performance in both single and clustered environments. The second allows for nearly any SQL database back-end by configuring just two properties; the Alfresco community has already confirmed working support for MySQL, Oracle, DB2, Sybase, SQL Server. By externalising the indexing of meta-data and content and using the Lucene engine as a basis, it is possible to perform complex queries which combine property, location, classification and full-text predicates in a single query against any content type. Multiple query languages are supported including Lucene's native language as well as XPath and a SQL-like language in the future. To ensure reliable operation, transactional support has been added to both Lucene and the content file store providing ACID operations across the complete store. Security is woven into each of the service layer ensuring illegal modifications are not permissible and hidden meta-data and content are not returned. Nearly all other Foundation services and clients rely upon these three core building blocks.
Repository APIs
The Alfresco Repository actually provides three APIs. We've already seen one - the Repository Foundation Services - a set of local Java Interfaces covering all capabilities which are ideal for clients who wish to embed the Repository. The two other APIs are: JCR Web Services JCR (Content Repository API for Java Technologies) is a standard Java API (as defined by JSR-170) for accessing Content Repositories. Alfresco provides support for level 1 and level 2 giving standardised read and write access. Supporting this API provides the following benefits: No risk: The Alfresco Repository can be trialled and developed against, but swapped out with another JCR Repository if it does not fit requirements. Familiarity: Developers who know JCR, know Alfresco. Tools: Tools, Clients and other 3rd Party JCR solutions are immediately available to the Alfresco community. Alfresco JCR is implemented as a light facade on top of the Repository Foundation Services. So, although a familiar API is provided, it sits upon a fully transactional, secure and scalable Repository which supports many deployment options. Alfresco will continue investment in JCR by both broadening the compliance of the full specification as well driving forward JSR-283, the next version of the JCR. Web Services is the final API provided by the Alfresco Repository. This API supports remote access and bindings to any client environment, not just Java. For example, the Alfresco community is already using PHP, Ruby and Microsoft .NET. Numerous standards and integration efforts are focused around Web Services - SOA is now recognised as a way forward for integrating disparate systems including Content Management and building new enterprise-wide solutions. BPEL plays an important role in orchestrating all of these services. Alfresco fits neatly into this way of thinking.
Once again, the Repository Foundation Services serve as the base. Both the JCR and Web Services API eventually go through this layer meaning that all encapsulated content model logic and rules are honoured.
Section 2
Developing against the Alfresco Repository
Spring Framework
Module 1
Spring Framework
Spring Framework - 39
Spring Framework
Introduction
The Spring Framework is a full-stack Java/JEE application framework. Spring's main aim is to make J2EE easier to use and promote good programming practise. It does this by enabling a POJO-based programming model remaining faithful to the fundamental ideas of Expert One-on-One J2EE Design and Development. Spring is portable between application servers.
40 - Spring Framework
Spring Framework
Dependency Injection
Dependency Injection is a form of IoC that removes explicit dependencies on container APIs. Ordinary Java methods are used to inject dependencies such as collaborating objects or configuration values into application object instances. The two major flavors of Dependency Injection are: Setter Injection (injection via JavaBean setters) Constructor Injection (injection via constructor arguments). Spring provides sophisticated support for both, and even allows you to mix the two when configuring the one object.
Spring Framework - 41
Spring Framework
42 - Spring Framework
Module 2
Foundation Services API
Introduction
The Foundation Services API is a set of services providing full access to the capabilities of the Alfresco Repository. It is an in-process API meaning that the client must run within the same process as the Repository. For example, the Alfresco Web Client uses this API and is packaged together with the Repository in a single WAR file for deployment to an application server.
FirstFoundationClient walkthrough
The following walkthrough is a practical introduction to using Foundation Services. It is based on the FirstFoundationClient sample from the Alfresco SDK. Before getting started, you should be familiar with the Spring Framework on page 40 . The sample uses several of the key foundation services, including the ServiceRegistry, TransactionService, AuthenticationService, SearchService, NodeService and ContentService. After initialising the Spring Application Context and starting the repository in embedded mode, we will use the Spring getBean() method to access the ServiceRegistry. We will then use the ServiceRegistry to access the other foundation services. After authenticating to the repository using the AuthenticationService, we will search for the Company Home node using the SearchService. We will then create a new node with properties and add an aspect using the NodeService. Finally, we will write some content to the new node using the ContentService. The sample will be wrapped in a single user transaction with the help of the TransactionService.
The FirstFoundationClient sample uses the getBean() method on the Spring Application Context to retrieve the ServiceRegistry:
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface TransactionService The TransactionService and RetryingTransactionHelper are presented in more detail in the section on Transactions .
The following example runs the example work in a user transaction via the RetryingTransactionHelper:
TransactionService transactionService = serviceRegistry.getTransactionService(); RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>() { public Object execute() throws Exception { doExample(serviceRegistry); return null; } }; transactionService. getRetryingTransactionHelper().doInTransaction(exampleWork);
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface AuthenticationService
In the example, the authenticate() method is used to authenticate as the admin user. The password must be passed as a character array.
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService(); authenticationService.authenticate("admin", "admin".toCharArray());
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface SearchService
The following example runs a Lucene query using the PATH syntax to locate the Company Home by it's absolute path. The getNodeRef(0) call is used to retrieve the first NodeRef from the ResultSet. In theory, the query should only return one result.
SearchService searchService = serviceRegistry.getSearchService(); StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); ResultSet resultSet = searchService.query( storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\""); NodeRef companyHome = resultSet.getNodeRef(0);
For more information on using the SearchService and on query string syntax, see the Search page on the Alfresco Wiki.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface NodeService
nodeRef NodeRef of the node to set the property on. qname QName of the property to set. value Value of the property. The value must be Serializable. properties Map of all the properties of the node keyed by QName. The property QNames are usually defined as a static constants on the dictionary model interfaces. For example, the cm:name property is defined by the static constant ContentModel.PROP_NAME. The following example creates a Map containing the cm:name property that will be used in the next step:
String name = "Foundation API sample (" + System.currentTimeMillis() + ")"; Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); contentProps.put(ContentModel.PROP_NAME, name);
parentRef NodeRef of the parent node. The created node will be one of it's children. assocTypeQName QName of the type of association to create. This is used for verification against the data dictionary. assocQName QName of the association. nodeTypeQName QName of the node type. properties Optional Map of properties to set keyed by QName. The association and node type QName objects are usually defined as a static constants on the dictionary model interfaces. For example, the cm:contains association type is defined by the static constant ContentModel.ASSOC_CONTAINS and the cm:content node type is defined by the static constant ContentModel.TYPE_CONTENT. If a constant does not exist, a QName can be created using the QName.createQName() static method as in the example below. The createNode() method returns a ChildAssociationRef to the newly created child association. The NodeRef of the newly created node is obtained by calling the getChildRef() on the ChildAssociationRef object.
The following example creates a new node of type cm:content, using the standard cm:contains child association. The Map created in the previous step sets the cm:name property on the newly created node.
NodeService nodeService = serviceRegistry.getNodeService(); ChildAssociationRef association = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), ContentModel.TYPE_CONTENT, contentProps); NodeRef content = association.getChildRef();
nodeRef NodeRef of the node to apply the aspect to. aspectTypeQName QName of the aspect to apply. aspectProperties Map containing a minimum of the mandatory properties required for the aspect. The aspect QNames are usually defined as a static constants on the dictionary model interfaces. For example, the cm:titled aspect is defined by the static constant ContentModel.ASPECT_TITLED.
The following example applies the cm:titled aspect and sets the cm:title and cm:description properties:
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(); titledProps.put(ContentModel.PROP_TITLE, name); titledProps.put(ContentModel.PROP_DESCRIPTION, name); nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
be supplied along with the ContentModel.PROP_CONTENT QName. The ContentService is also used for transforming content. A suitable transformer can be obtained for a given transformation (defined by a source and target mime type) using the getTransformer() and getImageTransformer() methods. The transformation can then be performed by calling transform directly on the content transformer. Otherwise, a transformation can be attempted from a source ContentReader object to target ContentWriter object by calling the transform() method on the ContentService. For more information, see Content Transformers on page 82 .
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface ContentService Interface ContentReader Interface ContentWriter Interface ContentAccessor
The following example gets a ContentWriter to the newly created node. The property to be updated is defined by the QName ContentModel.PROP_CONTENT. The boolean true value is to request that the content is updated atomically when the content write stream is closed. The content mime type and encoding are set before writing the content with the putContent() method.
Foundation Services API - 53
ContentService contentService = serviceRegistry.getContentService(); ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); String text = "The quick brown fox jumps over the lazy dog"; writer.putContent(text);
Once completed, the newly created node may be viewed via the Web client.
Note: The web client will need to be re-started after executing the sample to see the changes in effect.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface FileFolderService Interface FileInfo
JCR API
Module 3
JCR API
JCR API - 57
JCR API
Introduction
The JCR API (Java Content Repository) specifies a standard, implementation independent API to access content repositories in Java. It is defined by the Java Specification Request (JSR) 170 as part of the Java Community Process (JCP). The official JSR-170 Specification can be found on the JCP web site at the following address: http://jcp.org/en/jsr/detail?id=170 Alfresco implements the JCR API against its own scalable repository and is actively contributing to the next version of JCR defined by the Java Specification Request (JSR) 283.
58 - JCR API
Module 4
Web Services API
Introduction
The Web Services API is an easy to understand and develop against API. Accessible from many client languages, it is designed for remote repository access. Web Services are particularly suitable for composite applications and business processes.
Module 5
Separating Concerns using AOP
The ProxyFactoryBean introduces a level of indirection so that objects referencing the ContentService bean do not see the ProxyFactoryBean but the object defined by the target property, in our case, the contentService bean. The proxyInterfaces property, defines an array of interfaces implemented by the target class and the interceptorNames property a list of advisor, interceptor or other advice names to apply. Ordering is significant, the first interceptor in the list will be the first to be able to intercept the method call. The ContentService_transaction interceptor is a reference to a local bean in public-services-context.xml that manages transactions for calls to the ContentService. The ContentService_security is a reference to a bean in public-services-security-context.xml that enforces security checks for calls to the ContentService.
Section 3
Extending the Alfresco Repository
Repository Policies
Module 1
Repository Policies
Repository Policies - 67
Repository Policies
Introduction
Repository policies are similar to events. Each service defines its own set of policies. For example the Content Service defines two policies: OnContentUpdatePolicy is fired when the content is updated on a node, OnContentReadPolicy is fired when the content is read on a node. A custom method or behaviour can be registered against a policy and will be called automatically when the policy is fired. This enables tasks such as maintaining the last modified date on a node or creating a new version and incrementing the version number on a node to be automated. The event-driven processing paradigm is similar to that used in traditional user interfaces.
68 - Repository Policies
Repository Policies
Available Policies
The available policies are defined as interfaces for each service. The Node Service defines more than twenty policies, including BeforeCreateNodePolicy, OnUpdatePropertiesPolicy and OnAddAspectPolicy, the other services each define their own specific policies. The policies are usually defined on an interface named after the service. For example, the Node Service policies are defined on the NodeServicePolicies interface and the Content Service policies are defined on the ContentServicePolicies interface:
Classes interested in certain policies must implement the corresponding interfaces and methods. Each policy method (or behaviour) defines its own specific list of arguments. For example: A behaviour registered against the BeforeCreateNodePolicy is called before a node is created. The beforeCreateNode() method receives the NodeRef of the parent of the node being created, the QName of the association type (usually cm:contains), the QName of the new association and the node type of the node being created. A behaviour registered against the OnCreateNodePolicy is called when a node is created. The onCreateNode() method receives the ChildAssociationRef to the node created.
Repository Policies - 69
Repository Policies
Policy Types
Each policy extends one of three policy types: Class policy Property policy Association policy
Class policies are for events related to content types or aspects, Property policies are for events related to properties and Association policies for events related to associations. Most policies extend the Class policy interface, a few policies extend the Association policy interface and, at the time of writing, none extend the Property policy.
70 - Repository Policies
Repository Policies
The ch:countStartedDate will be set when the aspect is added to a node. The ch:updateCount and ch:readCount properties will be incremented for each content update or read respectively.
Repository Policies
When creating a new JavaBehaviour instance, you must provide the following:
public JavaBehaviour(Object instance, String method, NotificationFrequency frequency)
instance the object instance holding the method method the method name
72 - Repository Policies
Repository Policies
frequency one of three possible values defining when the behaviour should be notified: EVERY_EVENT, FIRST_EVENT or TRANSACTION_COMMIT The supplied method implements the behaviour logic and may have dependencies on Foundation Services that can be resolved using Spring dependency injection. A behaviour is bound to a policy using the bindClassBehaviour() method on the Policy Component:
bindClassBehaviour(QName policy, QName classRef, Behaviour behaviour);
policy the policy name classRef QName of type or aspect concerned by the policy behaviour a Behaviour object (instance of JavaBehaviour or ScriptBehaviour) A behaviour is bound to a specific content type or aspect using the classRef argument. The Policy Component is also used by services to register policies and to invoke policy behaviours.
In the Content Hits example, the Spring initialise() method is used to bind the behaviours to policies:
public void initialise() { this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_CONTENT_HITS, new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)); this.policyComponent.bindClassBehaviour( ContentServicePolicies.ON_CONTENT_READ, ASPECT_CONTENT_HITS, new JavaBehaviour(this, "onContentRead", NotificationFrequency.TRANSACTION_COMMIT)); this.policyComponent.bindClassBehaviour( ContentServicePolicies.ON_CONTENT_UPDATE, ASPECT_CONTENT_HITS, new JavaBehaviour(this, "onContentUpdate", NotificationFrequency.TRANSACTION_COMMIT)); }
Repository Policies
The onContentUpdate() behaviour adds the NodeRef of the node being updated to the list of nodes that require write count increments after the transaction completes:
public void onContentUpdate(NodeRef nodeRef, boolean newContent) { // Bind the listener to the transaction AlfrescoTransactionSupport.bindListener(transactionListener); // Get the set of nodes written @SuppressWarnings("unchecked") 74 - Repository Policies
Repository Policies
Set<NodeRef> writeNodeRefs = (Set<NodeRef>) AlfrescoTransactionSupport.getResource(KEY_CONTENT_HITS_WRITES); if (writeNodeRefs == null) { writeNodeRefs = new HashSet<NodeRef>(5); AlfrescoTransactionSupport.bindResource(KEY_CONTENT_HITS_WRITES, writeNodeRefs); } writeNodeRefs.add(nodeRef); }
The afterCommit() method retrieves the list of nodes stored as a resource on the transaction by the onContentRead() behaviour:
public void afterCommit() { Set<NodeRef> readNodeRefs = (Set<NodeRef>) AlfrescoTransactionSupport.getResource(KEY_CONTENT_HITS_READS); if (readNodeRefs != null) { for (NodeRef nodeRef : readNodeRefs) { Runnable runnable = new ContentHitsReadCountIncrementer(nodeRef); threadExecuter.execute(runnable); } } ... }
The Content Hits read count (ch:readCount) is incremented for each node in the list. The afterCommit() method retrieves the list of nodes stored as a resource on the transaction by the onContentUpdate() behaviour:
public void afterCommit() { .... Set<NodeRef> writeNodeRefs = (Set<NodeRef>) AlfrescoTransactionSupport.getResource(KEY_CONTENT_HITS_WRITES); if (writeNodeRefs != null) { for (NodeRef nodeRef : readNodeRefs) { Runnable runnable = new ContentHitsWriteCountIncrementer(nodeRef); threadExecuter.execute(runnable); } } }
The Content Hits update count (ch:updateCount) is incremented for each node in the list.
Repository Policies - 75
Repository Policies
public void setPolicyComponent(PolicyComponent policyComponent) { this.policyComponent = policyComponent; } public void setPolicyFilter(BehaviourFilter policyFilter) { this.policyFilter = policyFilter; } public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } public void setTransactionService(TransactionService transactionService) { this.transactionService = transactionService; } public void setThreadExecuter(ThreadPoolExecutor threadExecuter) { this.threadExecuter = threadExecuter; }
The initialise() method will be called once the bean has been instantiated and the properties set.
76 - Repository Policies
Repository Policies
In order to see the Content Hits aspect properties in the Web Client, the property sheet has to be configured as in the example web-client-config-custom.xml:
<config evaluator="aspect-name" condition="ch:contentHits"> <property-sheet> <show-property name="ch:countStartedDate" read-only="true" show-in-edit-mode="false"/> <show-property name="ch:updateCount" read-only="true" show-in-edit-mode="false"/> <show-property name="ch:readCount" read-only="true" show-in-edit-mode="false" /> </property-sheet> </config>
The compiled class needs to be exported to a JAR file. The files then need to be deployed to the following directories in the Alfresco repository: the JAR file to the WEB-INF/lib directory; all other files to the WEB-INF/classes/alfresco/extension directory. For deployment in a production environment, the files should be packaged and deployed as an Alfresco Module Package (AMP). For more details, see Alfresco Module Packages on page .
Repository Policies - 77
Repository Policies
78 - Repository Policies
Repository Actions
Module 2
Repository Actions
Repository Actions - 79
Repository Actions
Introduction
An action is a unit of work that is performed against a node. For example, moving a node, copying a node, checking a node in, transforming the contents of a node, etc. Many actions already exist, however it is possible to add you own custom actions in a few easy steps. An action has to implement the org.alfresco.repo.action.executer.ActionExecuter interface. The ActionExecuter interface can be implemented directly, however it is best to extend the abstract class ActionExecuterAbstractBase that has been written to provide basic services for action executer implementations. Only two methods need implementing when deriving from the abstract superclass.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface ActionExecuter Class ActionExecuterAbstractBase
80 - Repository Actions
Content Transformers
Module 3
Content Transformers
Content Transformers - 81
Content Transformers
Introduction
A content transformer is a Java class that can transform content from one mime type to another. Many content transformers already exist, however it is possible to add you own custom content transformer in a few easy steps. A content transformer has to implement the org.alfresco.repo.content.transform.ContentTransformer interface. ContentTransformer extends the org.alfresco.repo.content.ContentWorker interface that is a common marker interface for specific worker interfaces such as content transformers and metadata extractors. An abstract base class called AbstractContentTransformer has been written to provides basic services for ContentTransformer implementations. Only two methods need implementing when deriving from the abstract superclass.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface ContentTransformer Class AbstractContentTransformer
82 - Content Transformers
Metadata Extractors
Module 4
Metadata Extractors
Metadata Extractors - 83
Metadata Extractors
Introduction
A metadata extractor is a Java class that can extract metadata from content of a particular mime type. Many metadata extractors already exist, however it is possible to add you own custom metadata extractor in a few easy steps. A metadata extractor has to implement the org.alfresco.repo.content.metadata.MetadataExtracter interface. MetadataExtracter extends the org.alfresco.repo.content.ContentWorker interface that is a common marker interface for specific worker interfaces such as metadata extractors and content transformers. An abstract class called AbstractMappingMetadataExtracter has been written to provides basic services for MetadataExtracter implementations. Only one method needs implementing when deriving from the abstract superclass.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Interface MetadataExtracter Class AbstractMappingMetadataExtracter
84 - Metadata Extractors
Metadata Extractors
MetadataExtracterRegistry
The MetadataExtracterRegistry holds a list of available metadata extractors and provides the most appropriate extractor for a particular mime type extraction request. Upon initialisation, metadata extractors register themselves with the MetadataExtracterRegistry via the register() method.
Note: For clarity, not all of the available methods are shown. For a complete description, please consult the Javadocs: Class MetadataExtracterRegistry The getExtracter() method is used by clients to get the most appropriate metadata extractor for a particular mime type. The MetadataExtracterRegistry bean is defined in the content-service-context.xml Spring configuration file:
<!-- Metadata Extraction Regisitry --> <bean id="metadataExtracterRegistry" class="org.alfresco.repo.content.metadata.MetadataExtracterRegistry" />
Metadata Extractors - 85
Metadata Extractors
86 - Metadata Extractors
Section 4
Extending the Alfresco Web Client
JavaServer Faces
Module 1
JavaServer Faces
JavaServer Faces - 89
JavaServer Faces
Introduction
JavaServer Faces (JSF) is a user interface framework for Java web applications. JSF defines an event-driven, component-based model for web application development, similar to the model that has been used successfully for standalone GUI applications for years. JSFs core architecture is designed to be independent of specific protocols and markup. However it is also aimed directly at solving many of the common problems encountered when writing applications for HTML clients that communicate via HTTP to a Java application server that supports servlets and JavaServer Pages (JSP) based applications. JSF is a specification (JSR-252) that has been developed as part of the Java Community Process. It is a standard, vendor independent specification. Several implementations exist, including the GlassFish JavaServer Faces reference implementation and Apache MyFaces . Alfresco uses the Apache Myfaces implementation. The specification defines a set of standard user interface components and an API for extending the standard components or developing new ones. As well as UI components, JSF also defines artifacts like converters, validators, events listeners, and renderers: converters perform type conversion between server-side Java objects and their representation in the user interface. A good example is a date; validators can be associated with a JSF component to perform input validation checks on local values before they are processed; event listeners are registered against events that are triggered when a user clicks a button or a link, changes a value in a field, or makes a selection in a list. The outcome of the event processing controls which page is displayed next; renderers generate the actual markup for the user interface. JSF is not limited to HTML or any other markup language and the same JSF component can be coupled with different renderers to produce different output, for example, either HTML or WML;
90 - JavaServer Faces
Actions Framework
Module 2
Actions Framework
Actions Framework - 91
Actions Framework
Introduction
The Alfresco Web Client UI actions are configured using the Actions Framework. Actions such as Edit, View Details, Update, Copy are all examples of UI Actions. Actions are grouped into
action groups. Individual actions can be reused between groups and the action groups reused across pages. Action Groups define an ordered list of actions that are displayed together, either as a serial list (for example, as a strip of icons) or grouped together in a drop-down menu. The More Actions menu is an example of an action group.
UI actions and actions groups are configured in XML. The standard UI actions and action groups are defined in the web-client-config-actions.xml configuration file. You can define your own custom UI actions and action groups in a Web Client configuration extension file. You can also extend existing action groups to add your own custom UI actions to existing menus in the Web Client.
92 - Actions Framework
Dialog Framework
Module 3
Dialog Framework
Dialog Framework - 93
Dialog Framework
Introduction
The dialog framework manages the user interface dialogs in the Alfresco Web Client. Most of the standard Web Client dialog are managed by the framework and it is possible to create your own custom dialogs using the framework. Each dialog has three main components: A <dialog/> configuration element in a web-client-config.xml file. A dialog JSP that only contains the HTML and JSF components to define the body of the dialog. A JSF managed bean that is used as a backing bean for the dialog. At the centre of the dialog framework is the Dialog Manager. When a dialog is opened, the Alfresco Navigation Handler looks up the <dialog/> configuration then calls the Dialog Manager to initialise the dialog and instantiate the managed bean before navigating to the dialog JSP page. See Dialog Manager on page for more details.
94 - Dialog Framework
Wizard Framework
Module 4
Wizard Framework
Wizard Framework - 95
Wizard Framework
Introduction
The wizard framework manages the user interface wizards in the Alfresco Web Client. Most of the standard Web Client wizards are managed by the framework and it is possible to create your own custom wizards using the framework. Each wizard has three main components: A <wizard/> configuration element in a web-client-config.xml file.performed in exactly the same A JSP for each step in the wizard that only contains the HTML and JSF components to define the body of the step. A JSF managed bean that is used as a backing bean for the wizard. At the centre of the wizard framework is the Wizard Manager. When a wizard is opened, the Alfresco Navigation Handler looks up the <wizard/> configuration then calls the Wizard Manager to initialise the wizard and instantiate the managed bean before navigating to the JSP page for the first step. See Wizard Manager on page for more details.
96 - Wizard Framework
Alfresco 3.1
Administrator Exercises
Alfresco 2.1
Administrator Exercises
Contents
MODULE 1 EXERCISES ............................................................................................................................. 1 EXERCISE 1.01 USERS & GROUPS .............................................................................................................. 1 EXERCISE 1.02 DELETE & RECOVER .......................................................................................................... 1 MODULE 2 EXERCISES ............................................................................................................................. 2 EXERCISE 2.01 EDITING THE LIST OF LOGIN LANGUAGES........................................................................... 2 EXERCISE 2.02 CUSTOMISING THE VIEW CONFIGURATION ......................................................................... 2 MODULE 3 EXERCISES ............................................................................................................................. 3 EXERCISE 3.01 CHANGING THE NAME OF THE CIFS SERVER ..................................................................... 3 EXERCISE 3.02 CREATING A NEW FILE SYSTEM ......................................................................................... 3 EXERCISE 3.03 EDITING THE FTP ROOT DIRECTORY .................................................................................. 3 MODULE 4 EXERCISES ............................................................................................................................. 4 EXERCISE 4.01 USING THE SYSTEM INFORMATION CONSOLE .................................................................... 4 EXERCISE 4.02 MODIFYING LOG4J CONFIGURATION .................................................................................. 4 MODULE 5 EXERCISES ............................................................................................................................. 5 EXERCISE 5.01 SPACES IMPORT & EXPORT ................................................................................................ 5 EXERCISE 5.01 FULL REPOSITORY IMPORT & EXPORT .............................................................................. 5 MODULE 9 EXERCISES ............................................................................................................................. 6 EXERCISE 9.01 CONFIGURING A VERTICAL CLUSTER ................................................................................ 6 EXERCISE 9.02 CONFIGURING A REPLICATING CONTENT STORE ............................................................... 6
Administrator Exercises - i
Alfresco 2.1
Administrator Exercises
Module 1 Exercises
Exercise 1.01 Users & Groups
1. Create Groups that follow the following hierarchy: Company Management Technical Developers Solutions Engineers Human Resources Partners 2. Create some users and add them into the appropriate groups. 3. Remember a user can be in more than one group.
Administrator Exercises - 1
Alfresco 2.1
Administrator Exercises
Module 2 Exercises
Exercise 2.01 Editing the list of login languages
1. Within <ext>/web-client-config-custom.xml, edit the list of language definitions to remove all options except English and French. 2. Ensure this overrides the <config> option completely rather than adding to it (Hint: use replace=true). 3. Restart Alfresco and navigate to the login page. 4. Review the list of languages.
Administrator Exercises - 2
Alfresco 2.1
Administrator Exercises
Module 3 Exercises
Exercise 3.01 Changing the name of the CIFS Server
1. Copy the relevant CIFS Server configuration from <config>/file-servers.xml into <ext>/fileservers-custom.xml. 2. Update the name of the CIFS server to LegalAlfrescoXX where XX is a number unique to you. 3. Restart Alfresco and try to browse to \\LegalAlfrescoXX to test.
Administrator Exercises - 3
Alfresco 2.1
Administrator Exercises
Module 4 Exercises
Exercise 4.01 Using the System Information console
1. Log in as the admin user. 2. Navigate to the Administration Console and select System Information. 3. Check the current version of Alfresco. 4. Check the maximum amount of Java memory (heap) allocated to Alfresco in the System Properties.
2. Copy the definition and prepend log4j.logger. to the definition. 3. Set the log level to DEBUG. 4. Restart the server and view the logging information.
Administrator Exercises - 4
Alfresco 2.1
Administrator Exercises
Module 5 Exercises
Exercise 5.01 Spaces Import & Export
1. Login as administrator 2. Create an Exports space to save exports in 3. Export a users space 4. Restore the space and test 5. Check that user permissions and content rules have been imported correctly.
4. Restore the repository by restarting the alfresco server. 5. What happens on subsequent alfresco startups if you do leave restore-context.xml as is. 6. Which method of backup and restore is better to use and why?
Administrator Exercises - 5
Alfresco 2.1
Administrator Exercises
Module 9 Exercises
Exercise 9.01 Configuring a Vertical Cluster
7. Create a copy of your Alfresco installation directory called Alfresco2 8. Ensure that the Lucene indexes are configured in different locations for each install. The content store however should point to the same directory. 9. Configure both installations to automatically rebuild its indexes as required (Hint: Use AUTO setting). 10. Enable cache replication in both installations. 11. Restart the primary instance. 12. Start up the second instance.
Administrator Exercises - 6