Magnolia CMS Modules
by Devexperts
...
Code Block |
---|
@Node(jcrType = BaseOCM.MGNL_CONTENT_NODE_TYPE) public class FinancePlan extends BaseOCM { public enum PricingModel { FREE, PAID } @Field private String name; @Field private PricingModel pricingModel; @Field(jcrDefaultValue = "false") private boolean active; @Bean private Money price; public FinancePlan() {} public PricingModel getPricingModel() { return pricingModel; } public void setPricingModel(PricingModel pricingModel) { this.pricingModel = pricingModel; } public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } public boolean getName() { return name; } public void setName(String name) { this.name = name; } public Money getPrice() { return price; } public void setPrice(Money price) { this.price = price; } } |
Note the following:
To perform operations with OCM beans, you need com.devexperts.ocm.OCM object.
To create OCM object you need javax.jcr.Session.
In Magnolia, it can be constructed in the following way:
Code Block |
---|
Session session = MgnlContext.getHierarchyManager("data").getWorkspace().getSession(); OCM ocm = new OCM(session); |
Specify the workspace you need when calling getHierarchyManager method.
When you have an instance of OCM object you may perform operations on bean objects.
Code Block |
---|
FinancePlan plan = new FinancePlan(); plan.setName("My plan"); plan.setMoney(new Money("10.00$")); plan.setPricingModel(FinancePlan.PricingModel.PAID); plan.setPath("/plans/myplan"); // Path in Jackrabbit repository ocm.insert(plan); ocm.save(); |
Code Block |
---|
FinancePlan plan = ocm.getObject(FinancePlan.class, "/plans/myplan"); plan.setActive(true); ocm.update(plan); ocm.save(); |
Code Block |
---|
String objectPath = "/plans/myplan"; ocm.lock(objectPath, false, 5000); try { FinancePlan plan = ocm.getObject(FinancePlan.class, objectPath); plan.setActive(true); ocm.update(plan); ocm.save(); } finally { ocm.discardPendingChangesAndUnlock(objectPath); } |
Code Block |
---|
List<FinancePlan> activePlans = ocm.filter(FinancePlan.class)
.setScopeFolder("/plans")
.addEqualTo("active", true).getObjects(); |
The library is released under GPL license. Contact us if you need this module under different license.