Search the FirstSpirit Knowledge Base
Hello Team,
I am doing an operation script in the Section and after completing the operation via script, i have to get the page last Editor name and set the same name. So that no confusion will not occur who released the page again.
How to know the field for the Last editor which is marked as question mask?
It will be helpful for me to understand more...
Code:
FormData lastEditorvalue = setPageEditor(page);
page.setFormData(lastEditorvalue);
sectionTemplate.save();
private FormData setPageEditor(Page page) {
FormData pageFormData = null;
if(page.getEditor()!=null){
String lastEditor = page.getEditor().getName();
logInfo("lastEditor:"+lastEditor);
pageFormData = page.getFormData();
FormField<?> pageEditorFormField = pageFormData.get(masterLanguage, ?????????);
pageEditorFormField.set(lastEditor);
}
return pageFormData;
}
Thanks and Regards,
Siva
Hi Siva,
first, since there is no "setEditor()" method available in the access API I would assume that this is not official public API! It seems that this is an internal field and it has good reasons to not manipulate it manually. The public API offers only the getEditor() Method.
Nevertheless if you not operate on the Interface Page but on the implementation class PageImpl my IDE offers me a setEditor() Method.
Page page = null;
PageImpl pageImpl = (PageImpl) page;
pageImpl.getEditor();
pageImpl.setEditor(null);
The editor field is not a part of the form definition but a internal attribute of the page object itself. Also it will not take just the users name but the whole User object.
Best regards
Sandro
Hello Sosswald,
Thank you for your time and reply for the post.
I am dealing with the Page Interface and this can be cast to Class PageImpl.Thanks.
My scenario is ,
1) Executing a script in my IDE with Login username as:Scott.
2) Here in a Page i am dealing with a Content-Section which has employeelist and i would like to remove the specific picture in it in the list(5-10 employee with different images available) of employees.(This is working and verified in the Eclipse IDE with JAVA Main Program).
3) For the Section and Page Last editor is:Wolf (I have verified this with seeing the page Last editor and Sections via properties Last editor is same as:Wolf)
4) While executing my code i have to get the Last editor of the page and need to set it back before page.release.
5) While executing the below code the Section-LastEditor is changed to Scott instead of Wolf. Why this is happening? Due to this after final execution Page -Last editor name is changes as Scott instead of Wolf.
Before Execution of code:
-- After executing the code below Line No:20 then the name changes to Scott instead of Wolf.Before that Line:20 LOG was showing the name as Wolf.
Image attached below..
Scott is username login for executing the script.
Wolf is the Page and Section Last editor name until the below code executes.
Section sectionTemplateRef = (Section) refEntry.getReferencedObject();
Section sectionTemplate = (Section) psCurrent
.getStoreElement(sectionTemplateRef.getId());
for (IdProvidingFormData idProvidingFormData : formDataList) {
FormField<?> formFieldPicture = idProvidingFormData.get(masterLanguage,
employeeFormDataStPictureField);
Object formFieldValuePicture = formFieldPicture.get();
if (formFieldValuePicture instanceof TargetReference) {
TargetReferenceImpl targetData = (TargetReferenceImpl) formFieldValuePicture;
if (targetData != null && !targetData.isEmpty()) {
if (targetData.getUidType() == UidType.MEDIASTORE_LEAF) {
if(targetData.getUid().contains("ABC") || targetData.getUid().contains("abc")){
idProvidingFormData.get(masterLanguage, employeeFormDataStPictureField)
.setToDefault();
SectionImpl section = (SectionImpl) sectionTemplate;
section.getEditor();
logInfo("section.getEditor():"+section.getEditor());
logInfo("page.getEditor():"+page.getEditor());
section.setEditor(page.getEditor());
section.save();
}
}
}
}
}
After execution of the above code Section - Properties shows as like below,
I did a debugging in my IDE of the code, after save() method calls then only the name changes.(Immediately verified this with seeing the Section Properties-attached images above)
I am not sure why this is happening? Do you have any opinion on this issue.?
It will be helpful for me to understand more...
Once again thank you for your time in reading the content.
Thanks and Regards,
Siva
Hi Siva,
1. You should not use PageImpl (or more specific: methods only existing in implementation classes but not the API documentation / the API interfaces) as this is no official API and might stop working any time without notice.
2. FirstSpirit sets the last editor automatically upon save() to the user performing the save operation. It is not intended to be possible to manipulate this value.
Can you explain the use case behind your request, i.e. why you want to reset the last editor?
Michael
Hello Bergmann,
Thank you for your time and reply.
Use case:
-- Over all doing some operation in Section of the page and save it back and release the page with same Last editor not with the one executing the program script.
1) Before executing my script with main method in my Eclipse IDE, we have to login to the first-spirit system with some username or login name. Here the Username or Logging name is: Scott.
2) Before executing the script in Eclipse IDE i have verified in the Site Architect Page-store Page - footer shows as Last editor:Wolf and The specific Section which my script do some operation there i have verified the properties of the Section shows Last editor:Wolf and Released by:Wolf.
3)While executing the script completed now,what should be Page-Last editor: ???.
4)In my case Last editor for the Page is setting as:Scott , But previously it was Wolf as Page Last editor. Why this chnage is happening??
5) I have a requirement that i should save the Page with same old Last editor who was before the script operation was Wolf.
6) How to get the Page Last editor and set it back to the page again instead of changing it to Scott.
Tried many ways nothing helps here....
Code:
userService = project.getUserService();
final PageStoreRoot psCurrent = (PageStoreRoot) userService.getStore(Store.Type.PAGESTORE, false);
Section sectionTemplateRef = (Section) refEntry.getReferencedObject();
Section sectionTemplate = (Section) psCurrent.getStoreElement(sectionTemplateRef.getId());
page = (Page) sectionTemplate.getParent().getParent();
boolean isPageReleased = page.isReleased();
///
///
mycode goes here and calling the save for the Section after changing the media in it.
///
///
if (isPageReleased) {
page.setLock(true);
setPageEditor(page);
logInfo("sectionTemplate.getEditor().getName()-:"+sectionTemplate.getEditor().getName()); -- Shows name as:Scott
logInfo("getRealname:"+page.getEditor().getRealname()); -- Shows name as:Scott (Wolf T)
logInfo("getName:"+page.getEditor().getName()); -- Shows name as:Wolf
page.release();
page.refresh();
}
After executing the above code and refresh the page Last editor shows as:Scott. It should show Wolf as Last editor.
Thank you.
Thanks and Regards,
Siva
Hi Siva,
I understood your technical approach but can you please explain why you want to reset the last editor? Why is this important, what is the requirement behind it?
Technically it‘s not possible to perform an operation as another user without his/her credentials. Depending on the requirement / reason maybe there is an alternative solution.
Regards
Michael
Hello Bergmann,
Thank you for your quick reply.
1) why you want to reset the last editor?
-- Each and every Page in was Released by(Last editor) different users with different names.
-- I am displaying the Last editor name of the Page in the live system of my web application page footer section.(Different web Page different name will be displayed)
-- To do some operation in Page or Section via script code to execute it with either username or Login as Admin or some other username as ABC.
-- If i execute the script now all the Section or Page in the Page-stores, Page will be change accordingly with either Admin or ABC for a Page.
-- Now in my web application live page footer section will be displaying as either Admin or ABC in all the Pages which is modified by executing the script.
-- Now the Page owner or who is responsible for the Page will raise question like Its displaying Admin in footer instead of displaying the Last editors page.
We have a custom Field PageOwner for every page.
we will display the Page-owner name instead of the Last Editor Name in the live web page footer.
Nothing to proceed further with this issue. We can close this Issue.
Thank you for your support and time spent on this issue.
Thanks and Regards,
Siva
Hi Siva,
I already thought about this as the "origin" of your request 😉
Exactly because of such scenarios like yours, I always recommend against rendering such "technical" information to the page. The "last editor" is a purely technical information and is intendedly not changeable "manually" - reasons are traceability/security in the end. There are many reasons why you should not publish that value:
The same is by the way valid for other technical data like "last change date" which usually represents some kind of "posting date" or "when was the last relevant content change".
The solution you described would also be my recommendation - just use a custom field holding the relevant information. From my experience it's a good idea to use a datasource containing persons and an FS_DATASET on the page for this.
Regards,
Michael