sivaprasad9394
Occasional Collector

getReferencedElement as Listable<IDProvider>??

Jump to solution

Hello Team,

Is it possible to change or get reference.getReferencedElement(); as Listable<IDProvider> as per below code.?? Is there any option available in fs-acccess api?

if (deploymentType !=null && deploymentType.equals("hotdeployment")) {

for(IDProvider node:generationTask.getStartNodes()){         

_context.logInfo(node.getUid());

Listable<IDProvider> pageRef = getChildElements(node);

for (IDProvider idProvider : pageRef) {

ReferenceEntry[] references =  idProvider.getIncomingReferences();

for (ReferenceEntry reference : references) {

if(reference.getType() == ReferenceEntry.MEDIA_STORE_REFERENCE) {

IDProvider _mediaRef = reference.getReferencedElement();  ------- Is it possible to get it as Listable<IDProvider> ------

IDProviderList.add(_mediaRef);                                    

}

}                       

   

}

}

}

I would like to get the referenceElement as Listable<IDProvider> ??

Thank you.

0 Kudos
1 Solution

Accepted Solutions
bIT_sosswald
Returning Responder

Hi Siva,

why would you like to get a single element as listable?

The API reference says:

getReferencedElement

Returns:
The referenced node or null.
Since:
4.0

So for each reference entry there is always exactly one referenced element. (Or null will be returned in the case of a broken reference etc. See API documentation.)

From my point of view it does not make any sense to hold a single value in a listable. Also i cannot find the data type IDProviderList as part of the public API. (At least I cannot find it in the API documentation.)
So the only thing you want to do is, to put all referenced elements into a list, just use a standard java list.

List<IDProvider> idProviderList = new ArrayList<>();


idProviderList.add(_mediaRef )

Greetings

Sandro

View solution in original post

0 Kudos
3 Replies
bIT_sosswald
Returning Responder

Hi Siva,

why would you like to get a single element as listable?

The API reference says:

getReferencedElement

Returns:
The referenced node or null.
Since:
4.0

So for each reference entry there is always exactly one referenced element. (Or null will be returned in the case of a broken reference etc. See API documentation.)

From my point of view it does not make any sense to hold a single value in a listable. Also i cannot find the data type IDProviderList as part of the public API. (At least I cannot find it in the API documentation.)
So the only thing you want to do is, to put all referenced elements into a list, just use a standard java list.

List<IDProvider> idProviderList = new ArrayList<>();


idProviderList.add(_mediaRef )

Greetings

Sandro

0 Kudos

Hi @all,

thanks for your helpful answer Sandro. We tend to ask the same question - why should a single object be returned as a list? The usage of an abstraction over our API (like you already did) seems to be the right tool here.

Greetings,

Hannes

0 Kudos

Hello Sandro,

Thank you for your time and reply for my post.

Finally i have modified my code like below to get the things,

for (ReferenceEntry entry : outgoingReferences) {

                     Object referenceElement = entry.getReferencedElement();

                     //_context.logInfo(referenceElement.getClass().getName());

                     if (referenceElement instanceof Media && ((Media) referenceElement).isInReleaseStore() && ((Media) referenceElement).isReleased()) {

                         IDProvider _mediaRef = (IDProvider)referenceElement;

                         _context.logInfo("_mediaRef Name:"+_mediaRef.getName());

                         IDProviderList.add(_mediaRef);

                         _context.logInfo("IDProviderList add..."+_mediaRef);

               }

             }

I am getting the media and page reference names while doing the Hotdeployment via Project file menu selection.

Thank you

0 Kudos