AnsweredAssumed Answered

Upgrade the custom model, How?

Question asked by mastro on Mar 28, 2012
Latest reply on Mar 28, 2012 by billerby
Hi,

How do I handle custom models upgrade?

Example:

Types:
my:category
my:asset

my:asset can be associated to my:category through an association called my:assetCategory


Suppose that model is in place, being used for a while now.


Now I upgrade my AMP file adding ty my:category a property my:assetsCount which should contains the number of my:asset(s) associated to that my:category.
I create a policy behavior to increment the property when a new my:assetCategory association is created and decrement it when it is removed.

It does work fine on new my:category / my:asset

but when I install the new AMP the old my:category doesn't have the property.


Which is the proper way to upgrade?

I know how to search for every my:category in the system (lucene / cmis / other search services) and compute how many my:asset are associated to it (with nodeService).
The question is: how do I make alfresco execute it at startup? Possibly once?

Can I use a bean with initialize method? Will the nodeService/search services/indexing services/policies, etc. be already bootstrapped and ready to use when my initialize method is kicked in??

Is it possible?
I did a quick and dirty test, apparently yes: It is not executed at the end of the process and I wonder if something may go wrong, see the log below.
My beans are initialized before many others alfresco bootstrapping.
I think that if this was the first alfresco start then it would had failed because the database is apparently initialized later (domain.schema.SchemaBootstrap)


Mar 28, 2012 10:12:35 AM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
10:12:38,156 INFO  [my.custom.Init] My AMP module Init bean initialized…
10:12:38,787 INFO  [model.behavior.CategoryPolicy] Replacing the nodeService with a NodeService
10:12:39,047 INFO  [model.behavior.CategoryPolicy] updating the assets categories nodes…
10:12:39,215 INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/version.properties]
10:12:39,216 INFO  [alfresco.config.JndiPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/alfresco-shared.properties]
10:12:39,217 INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/domain/cache-strategies.properties]
10:12:40,728 INFO  [model.behavior.CategoryPolicy] Found 1 assets categories
10:12:41,119 INFO  [model.behavior.CategoryPolicy] Category workspace://SpacesStore/12af07cc-4b4b-4e3c-b895-69d8d1d128e4 has 2 assets associated
10:12:41,455 INFO  [model.behavior.CategoryPolicy] Restoring the nodeService
10:12:47,681 INFO  [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.H2Dialect.
Mar 28, 2012 10:12:48 AM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine activitiBootstrapEngine created
10:12:48,881 INFO  [domain.schema.SchemaBootstrap] No changes were made to the schema.

[…]
10:13:04,840 WARN  [repo.admin.ConfigurationChecker] The Alfresco 'dir.root' property is set to a relative path './alf_run/alf_data_jetty'.  'dir.root' should be overridden to point to a specific folder.
10:13:04,840 INFO  [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: ./alf_run/alf_data_jetty
10:13:05,287 INFO  [admin.patch.PatchExecuter] Checking for patches to apply …
10:13:07,805 INFO  [admin.patch.PatchExecuter] No patches were required.
10:13:07,973 INFO  [repo.module.ModuleServiceImpl] Found 1 module(s).
10:13:08,007 INFO  [repo.module.ModuleServiceImpl] Starting module 'my-alfresco-amp' version 0.0.1.
[…]
10:13:19,205 INFO  [service.descriptor.DescriptorService] Alfresco JVM - v1.6.0_26-b03; maximum heap size 910.250MB
10:13:19,206 INFO  [service.descriptor.DescriptorService] Alfresco started (Community). Current version: 4.0.0 (b @build-number@) schema 5,019. Originally installed version: 4.0.0 (b @build-number@) schema 5,019.
[…]
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.

Are there better methods to do it?

Will I have to manually keep the version of my AMP somewhere (say on a node in the workspace with custom, static, nodeRef) to know if I have to upgrade or does alfresco offer some other way to do it?

I've seen a PatchService that is used by alfresco for upgrades which apply SQL directly, and apparently that require a reindex…
I would prefer to do it through Java but I'm open for alternatives and would be happy to know if I can use this mechanism and how, thanks.

Outcomes