When updating user or broker products by groovy scripts, the changes are shown in the system, but the users don't get the granted permissions. After I restart the cyclos app container the permissions are active.
How can I activate the new settings inside of the groovy script? Is there a call to initialize a cache refresh oder rebuild?
[SOLVED] How to update products configuration cache
Moderators: alexandre, hugo, rmvanarkel
-
erich.manser
- Posts: 24
- Joined: Tue Nov 08, 2022 10:40 am
[SOLVED] How to update products configuration cache
Last edited by erich.manser on Thu Aug 28, 2025 4:53 am, edited 1 time in total.
Re: How to update products configuration cache
The correct way of updating products (and any entity in general) is not to find the entity and modify its fields directly, because the entire service layer is bypassed (which handles validation, cache, other related updates, indexing, etc). The below example works for products, but the concept can be adjusted to configurations, groups, account types, etc:
As always, an IDE is recommended to setup an IDE to work with scripts: https://documentation.cyclos.org/curren ... ting-debug
Also note that the models (DTOs, VOs, Data) is distinct than the entities directly, so adjust the script as needed.
Code: Select all
import org.cyclos.entities.users.MemberProduct
import org.cyclos.impl.users.ProductServiceLocal
import org.cyclos.impl.utils.persistence.EntityManagerHandler
import org.cyclos.model.users.products.MemberProductDTO
import org.cyclos.model.users.products.MemberProductData
ProductServiceLocal productService = binding.productServiceLocal
EntityManagerHandler entityManagerHandler = binding.entityManagerHandler
// The service methods use id. But we can find by internal name
def product = entityManagerHandler.find(MemberProduct, 'internalName')
// If you need some configuration from the data, call the getData and use its DTO
MemberProductData data = productService.getData(product.id)
MemberProductDTO dto = data.dto
// Otherwise, load the DTO directly
// MemberProductDTO dto = productService.load(product.id)
// Update the DTO
dto.adsRequireAuthorization = true
// Save the product
productService.save(dto)
Also note that the models (DTOs, VOs, Data) is distinct than the entities directly, so adjust the script as needed.
Luis Fernando Planella Gonzalez
Cyclos development team
Cyclos development team
-
erich.manser
- Posts: 24
- Joined: Tue Nov 08, 2022 10:40 am
Re: How to update products configuration cache
Great Information.
Thank you very much!!
Thank you very much!!