WS_CUSTOM_HANDLER

Description: Limited to custom code extensions. Add a custom code extension of this type and provide the extension name as the Handler ID in the argoserviceTester view to send a CUSTOM web service request. Use this option in preference to sending groovy scripts as requests using argoservice Tester.

Abstract Base Class: AbstractCustomWSHandler

Interface: ECustomWSHandler

Module: Argo

Version Added: 2.5

Requires Code Extension Name or Name Pattern: No

Code Extension Name or Name Pattern: N/A

Where to Specify Code Extensions of this Type: In the Handler ID in the argoserviceTester view.

System-Seeded Code Extensions Using this Type: None

 

Code example

The following code implements a WS_CUSTOM_HANDLER code extension.

import org.jdom.Element;

import java.util.List;

import com.navis.argo.ArgoPropertyKeys;

import com.navis.argo.ContextHelper;

import com.navis.argo.business.api.ArgoUtils;

import com.navis.argo.business.reference.Container;

import com.navis.argo.util.XmlUtil;

import com.navis.external.argo.AbstractArgoCustomWSHandler;

import com.navis.framework.business.Roastery;

import com.navis.framework.portal.UserContext;

import com.navis.framework.util.internationalization.UserMessage;

import com.navis.framework.util.message.MessageCollector;

import com.navis.framework.util.message.MessageLevel;

import com.navis.inventory.InventoryField;

import com.navis.inventory.business.api.UnitFinder;

import com.navis.inventory.business.units.Unit;

 

public class SampleArgoCustomXmlHandler extends AbstractArgoCustomWSHandler {

    /**

     * Entry point to the argo custom webservice handler

     * @param inUserContext the authenticated user from the webservice call

     * @param inOutMessageCollector the message collector of the webservice call

     * @param inECustom the xml request message

     * @param inOutEResponse the xml response message

     * @param inWslogGkey the key of the entry in the webservice logs for this call

     * @return the response message

     */

    public void execute(

            final UserContext inUserContext,

            final MessageCollector inOutMessageCollector,

            final Element inECustom,

            final Element inOutEResponse,

            final Long inWslogGkey

    ) {

        UnitFinder uf = (UnitFinder) Roastery.getBean(UnitFinder.BEAN_ID);

        Element eUnits = new Element("units");

        inOutEResponse.addContent(eUnits);

        for (Element eContainer : (List<Element>)inECustom.getChildren("container")) {

            String ctrId = eContainer.getAttributeValue("eqid");

            Container ctr = Container.findContainer(ctrId);

            if (ctr == null) {

                String[] params = new String[1];

                params[0] = ctrId;

                inOutMessageCollector.appendMessage(MessageLevel.SEVERE, ArgoPropertyKeys.EQUIPMENT_NOT_FOUND, null, params);

            }

            else {

                Unit unit = uf.findActiveUnit(ContextHelper.getThreadComplex(), ctr);

                if (unit != null) {

                    // do some update to the unit

                    unit.setFieldValue(InventoryField.UNIT_FLEX_STRING01, "DMG");

                    Element eUnit = new Element("unit");

                    eUnits.addContent(eUnit);

                    eUnit.setAttribute("id", unit.getUnitId());

                    eUnit.setAttribute("dmg-indicator", unit.getUnitFlexString01());

                }

 

            }

        }

    }

 

    public String getVersionId() {

        return "1.01";

    }

 

    /**

      Indicates if the code extension will be called within a database transaction

      false is correct for this script as written

      it is also the default if this method is not defined

      It is therefore redundant in this case and just included for illustration

     */

    public boolean isSelfManagedTransactionHandler() {

        return false;

    }

 

}

 

-->