Skip to Content

Extending a Java function

Mar 05 at 12:47 PM


avatar image

As far as i know i can extend a function by using @pluginAt if i used a POSITION = Before i can trigger a function just before the target function.

So what i want to do is to use this way so i can edit the bar code readed from the bar code reader before it goes to the database but, still i don't know which function or which class is responsible for fetching data from database.
TEST CASE : Bar code readed : 1234567890

Item Real Bar Code : 1234567
Quantity : 890
i just need to change the barcode from 1234567890 to 1234567 before searching in the database.


And if i am going the wrong way please tell me

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Michael Bosch
Mar 06 at 08:05 AM

The right method is "readMaterialByExternalID", which you can find in the MaterialManager.
Please use the POSITION.BEFORE posibility to inject your code, before the method will be executed.


@PluginAt(pluginClass = IMaterialManager.class, method = "readMaterialByExternalID", where = PluginAt.POSITION.BEFORE)
public void beforeReadMaterialByExternalID(Object proxy, Object[] args, StackTraceElement caller) {

Show 5 Share
10 |10000 characters needed characters left characters exceeded

and then what, its overriding the actual method and thats not what i want,
i need to do something before the method readMaterialByExternalID is executed.

Please refer to the example again and if you can help me with a more detailed example i would really appreciate it.


Using the @PluginAt Annotation you're not overriding the actual method, instead you're injecting your code before or after a method will be executed. The method "readMaterialByExternalID"has the parameter "externalID" which you can find inside your parameters: "Object[] args ". By changing the "args" array before the method will be called, you can affect on the behaviour of the the "readMaterialByExternalID" method.


okay i got everything except that the the pluginAt is not working, instead @pluginAt on method updateSalesItemTypeMaterial under class ISalesItemManager is working, are you sure that the method is readMaterialByExternalID, i'm reading barcodes not external codes


i tried @PluginAt on all the following
readMaterialByBarcode, readMaterialByGTIN, retrieveMaterialByAlternateId, readMaterialsByBarcode,
readMaterialByExternalID and updateSalesItemTypeMaterial

and when i read the barcode only the updateSalesItemTypeMaterial executes


Hi Bilal,

Currently we have a small bug inside the PluginManager, which will be fixed in the next PL.
As quick fix till the next PL, please use IMappingManager instead of IMaterialManager in the PluginAt annotation.

Please excuse this inconvenience.