Search the FirstSpirit Knowledge Base
Dear All
I am trying to change one field availble in page, before changing I was trying to lock the page at that time its throwing some exception.
Please find the attached code.
if( storeElement instanceof Page){
Page page = (Page)storeElement;
if(!page.isLocked())
{
page.setLock(true);
System.out.println("Expiry Date ====== "+ page.getUid() +" "+page.getFormData().get(null, "pt_expiryDate").get());
FormData formData=page.getFormData();
formData.get(null, "pt_expiryDate").setToDefault();
System.out.println("isLockSupported() "+page.isLockSupported());
page.setFormData(formData);
page.save();
page.setLock(false);
}
else{
System.out.println("Already Locked!!");
}
}
If I exceute this code I am getting some exception, shown below.
storeElement.getNamea_z_in_module_and_module_element_descriptions
Exception in thread "main" java.lang.UnsupportedOperationException: lock is not supported for release store elements
at de.espirit.firstspirit.store.access.DefaultStoreElement.setLock(DefaultStoreElement.java:446)
at de.espirit.firstspirit.store.access.DefaultStoreElement.setLock(DefaultStoreElement.java:440)
at de.espirit.firstspirit.store.access.AbstractStoreElement.setLock(AbstractStoreElement.java:1109)
at com.bosch.ExpiryDate.MyHRExpiryDateExecute.getPageCount(MyHRExpiryDateExecute.java:47)
at com.bosch.ExpiryDate.MyHRExpiryDateExecute.getData(MyHRExpiryDateExecute.java:99)
at com.bosch.ExpiryDate.MyHRExpiryDate.main(MyHRExpiryDate.java:35)
Please support me to get this.
Hi,
the error message shows you a hint to the root of the problem. "lock is not supported for release store elements"
The stores in FirstSpirit have to „states“ release and current. If you are using the release state you only get the released versions of a objects in the store and these objects are immutable so you can’t change and therefore lock it.
Your code looks fine but somewhere BEFORE that code snipped is executed there must be a point where the store is set to “release” state.
Take a look into the JavaDoc to see how you can get a store in the current/work state.
The following example show you how to obtain a page in the “current” state so you can lock and change it.
PageStoreRoot pageStore = (PageStoreRoot) userService.getStore(Type.PAGESTORE, false);
Page page = (Page) pageStore.getStoreElement("uid", Page.UID_TYPE);
So you have to ensure that the page object you want to modify is taken from a “current” and not a “release” store.
Greetings
Sandro
Hello,
do you need further help or did Sandros reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have
already found a solution by yourself, it would be very kind of you, if you posted it here.
Best regards
Martin