pinarodrigo
I'm new here

Get AdminService in Template code

Jump to solution

Hello,

Inside one section template code I am trying to get a hold of one of my project's scheduled tasks and following the FS5.1 Documentation I am trying it like this:

{code}

    $-- get current connection (at this point the setProject variable has been correctly set)--$

    $CMS_SET(connection, setProject.getUserService().getConnection())$

   

    $-- get specialist broker and the admin service --$

    $CMS_SET(specialistBroker, connection.getBroker())$

    $CMS_SET(adminService, specialistBroker.requireSpecialist(ServicesBroker.TYPE).getService(AdminService.class))$

   

    $-- get Scheduled entry --$

    $CMS_SET(scheduleEntry, adminService.getScheduleStorage().getScheduleEntry(5779891))$

{code}

For which I get the following generation error:

ERROR ($CMS_SET(adminService, specialistBroker.requireSpecialist(ServicesBroker.TYPE).getService(AdminService.class))$ at 15, 2): No specialist found for 'null'! [source: de.espirit.firstspirit.agency.ConnectionDelegatingSpecialistsBroker@14fd02da]

I believe my error is that I am fetching the "specialistBroker" out of the ProjectConnection class returned by "connection.getBroker" but unfortunately I have not found any hint in the documentation (or in this community) on how fetch the AdminService from within the generation context.

Any help will be greatly appreciated.

Saludos!

1 Solution

Accepted Solutions

Hello Rodrigo,

you simply cannot use classes "directly" like in pure Java. You have also to use class("...") in the first part inside requireSpecialist: .requireSpecialist(class("de.espirit....ServicesBroker").TYPE)...

The reason for the error message is that FirstSpirit tries to access a VARIABLE named ServicesBroker (which of course does not exist and therefore is null).

Michael

View solution in original post

0 Kudos
9 Replies
a_reg
I'm new here

Hola Rodrigo,

i think it's just a syntax problem. In templates you can go like this (the bold part):

$CMS_SET(setProject, #global.project)$

$-- get current connection (at this point the setProject variable has been correctly set)--$

$CMS_SET(connection, setProject.getUserService().getConnection())$ 

$-- get specialist broker and the admin service --$

$CMS_SET(adminService, connection.getService(class("de.espirit.firstspirit.access.AdminService")))$ 

$-- get Scheduled entry --$

$CMS_SET(scheduleEntry, adminService.getScheduleStorage().getScheduleEntry(5779891))$

0 Kudos

Hola Andreas,

thank you for your answer.

I kindda had already tried that (although not with the call to the "class()" function), but the result is the same, the "$CMS_SET(adminService, connection.getService(class("de.espirit.firstspirit.access.AdminService")))$" function evaluates to :

de.espirit.firstspirit.parser.eval.Undefined

And the generation error is the same:

ERROR ($CMS_SET(setAdminService, setBroker.requireSpecialist(ServicesBroker.TYPE).getService(class("de.espirit.firstspirit.access.AdminService")))$ at 14, 2): No specialist found for 'null'!

Any Ideas?

0 Kudos

Hallo Rodrigo.

Simply use getAdminService() on the connection object.

It works fine for me.

Greetings,

Daniel

0 Kudos

Hola Daniel,

are you under FS51, also?, I believe that function is deprecated now.

I was actually using "getAdminService" before but that implementation doesn't work anymore.

Saludos"

0 Kudos

Holla Rodrigo.

You are right, it's deprecated. We used it in a scheduler script and there you can do an import, so this one works:

import de.espirit.firstspirit.access.AdminService;

AdminService as = connection.getService(AdminService.class));

If I try the solution the .getService(class("de.espirit.firstspirit.access.AdminService")) in a template it's also not working for me.

Daniel

0 Kudos

Hello Rodrigo,

you simply cannot use classes "directly" like in pure Java. You have also to use class("...") in the first part inside requireSpecialist: .requireSpecialist(class("de.espirit....ServicesBroker").TYPE)...

The reason for the error message is that FirstSpirit tries to access a VARIABLE named ServicesBroker (which of course does not exist and therefore is null).

Michael

0 Kudos
a_reg
I'm new here

Hola Rodrigo,

like Daniel said, working directly on the connection object works fine (for me), just use the

'.getService(class("de.espirit.firstspirit.access.AdminService"))' instead of 'getAdminService()'.

If you go wtih requireSpecialist(..), then you have to use the class('..') syntax there as well, like Michael said.

Andreas

Hello Michael,

Thank you for your helpful reply, using the (operator?) class() on both methods gives us the expected results.

One last question, could you point me to the place where this operator is documented?

Thank you.

0 Kudos

Thank you, Andreas.

Michael's suggestion works, I was just wondering where is this class() operator documented; do you by any chance, know where?

Saludos!

0 Kudos