package custom.app.inventory.virtual; import java.rmi.RemoteException; import psdi.app.asset.AssetRemote; import psdi.app.asset.SparePartRemote; import psdi.app.inventory.Inventory; import psdi.app.inventory.virtual.WhereUsed; import psdi.app.inventory.virtual.WhereUsedSet; import psdi.app.item.Item; import psdi.app.item.ItemRemote; import psdi.mbo.Mbo; import psdi.mbo.MboRemote; import psdi.mbo.MboServerInterface; import psdi.mbo.MboSet; import psdi.mbo.MboSetRemote; import psdi.mbo.SqlFormat; import psdi.util.MXApplicationException; import psdi.util.MXException; public class WhereUsedSetExt extends WhereUsedSet { public WhereUsedSetExt(MboServerInterface ms) throws MXException, RemoteException { super(ms); // TODO Auto-generated constructor stub } @Override protected Mbo getMboInstance(MboSet ms) throws MXException, RemoteException { // TODO Auto-generated method stub return new WhereUsedExt(ms); } @Override public MboRemote setup() throws MXException, RemoteException { // TODO Auto-generated method stub MboRemote owner = this.getOwner(); ItemRemote itemMbo = null; MboSetRemote tempSetRemote = null; MboRemote returnMbo = null; String status = this.getTranslator().toExternalList("LOCASSETSTATUS", "DECOMMISSIONED"); if(owner instanceof Item) { Item owningItem = (Item)this.getOwner(); if (owningItem.isRotating()) { SqlFormat sqf = new SqlFormat(owningItem, "itemnum=:1 and parent is not null and :sitefiltering and assetnum in (select assetnum from asset where moved = :no or status not in (" + status + ") )"); sqf.setObject(1, "ASSET", "ITEMNUM", owningItem.getString("itemnum")); tempSetRemote = owningItem.getMboSet("$asset", "asset", sqf.format()); } else { tempSetRemote = owningItem.getMboSet("SPAREPART_NOSITE"); } this.createWhereUsedSet(tempSetRemote); returnMbo = this.getMbo(0); } else if (owner instanceof Inventory) { Inventory owningInventory = (Inventory)this.getOwner(); itemMbo = (ItemRemote)owningInventory.getMboSet("ITEM").getMbo(0); if (itemMbo.isRotating()) { SqlFormat sqf = new SqlFormat(owningInventory, "itemnum=:1 and parent is not null and :sitefiltering and assetnum in (select assetnum from asset where moved = :no or status not in (" + status + ") )"); sqf.setObject(1, "ASSET", "ITEMNUM", itemMbo.getString("itemnum")); tempSetRemote = owningInventory.getMboSet("$asset", "asset", sqf.format()); } else { tempSetRemote = owningInventory.getMboSet("SPAREPART_NOSITE"); } this.createWhereUsedSet(tempSetRemote); returnMbo = this.getMbo(0); } return returnMbo; } @Override public void canAdd() throws MXException { // TODO Auto-generated method stub MboRemote owner = this.getOwner(); ItemRemote itemMbo = null; if(owner instanceof Item) { try { itemMbo = (Item)this.getOwner(); if (itemMbo.isRotating()) { throw new MXApplicationException("inventory", "cannotAddRotating"); } } catch (RemoteException var3) { ;} } else if (owner instanceof Inventory) { try { itemMbo = (ItemRemote)owner.getMboSet("ITEM").getMbo(0); if (itemMbo.isRotating()) { throw new MXApplicationException("inventory", "cannotAddRotating"); } } catch (RemoteException var3) { ;} } } @Override public void createWhereUsedSet(MboSetRemote tempSetRemote) throws MXException, RemoteException { // TODO Auto-generated method stub MboRemote tempRemote = null; MboRemote owner = this.getOwner(); Inventory owningInventory = null; Item owningItem = null; MboSetRemote mborSet = null; String[] readOnlyFields = new String[]{"assetnum", "siteid", "description"}; int i = 0; while(true) { tempRemote = tempSetRemote.getMbo(i); if (tempRemote == null) { return; } MboRemote newRemote = this.add(2L); if(owner instanceof Item) { newRemote.setValue("assetnum", tempRemote.getString("assetnum"), 11L); newRemote.setValue("description", tempRemote.getString("description"), 11L); newRemote.setValue("newrow", "N", 11L); newRemote.setValue("siteid", tempRemote.getString("siteid"), 11L); //ItemRemote item = (ItemRemote)newRemote.getThisMboSet().getMbo(0); if (newRemote != null && ((ItemRemote) owner).isRotating()) { newRemote.setValue("quantity", 1, 3L); } ++i; } if(owner instanceof Inventory) { newRemote.setValue("assetnum", tempRemote.getString("assetnum"), 11L); newRemote.setValue("description", tempRemote.getString("description"), 11L); newRemote.setValue("newrow", "N", 11L); newRemote.setValue("siteid", tempRemote.getString("siteid"), 11L); ItemRemote item = (ItemRemote)tempRemote.getMboSet("ITEM").getMbo(0); if (item != null && item.isRotating()) { newRemote.setValue("quantity", 1, 3L); } ++i; } if (tempRemote instanceof SparePartRemote) { newRemote.setValue("quantity", tempRemote.getDouble("quantity"), 11L); newRemote.setValue("remarks", tempRemote.getString("description"), 11L); newRemote.setValue("sparepartid", tempRemote.getString("sparepartid"), 11L); ++i; } else if (tempRemote instanceof AssetRemote) { if(owner instanceof Item) { owningItem = (Item)this.getOwner(); mborSet = tempRemote.getMboSet("SPAREPARTITEM"); MboRemote mbor = mborSet.getMbo(0); if (mbor != null) { newRemote.setValue("remarks", mbor.getString("description"), 11L); } else { newRemote.setFieldFlag("remarks", 7L, true); } newRemote.setFieldFlag(readOnlyFields, 7L, true); newRemote.setModified(false); newRemote.setNewMbo(false); ++i; } if (owner instanceof Inventory) { owningInventory = (Inventory)this.getOwner(); mborSet = tempRemote.getMboSet("SPAREPARTITEM"); MboRemote mbor = mborSet.getMbo(0); if (mbor != null) { newRemote.setValue("remarks", mbor.getString("description"), 11L); } else { newRemote.setFieldFlag("remarks", 7L, true); } newRemote.setFieldFlag(readOnlyFields, 7L, true); newRemote.setModified(false); newRemote.setNewMbo(false); ++i; } } } } @Override public void execute() throws MXException, RemoteException { // TODO Auto-generated method stub MboRemote owner = this.getOwner(); Inventory owningInventory = null; Item owningItem = null; MboSetRemote addSparePartSetRemote = null; MboRemote whereUsed = null; MboRemote addSparePart = null; int i = 0; if(owner instanceof Inventory) { owningInventory = (Inventory)this.getOwner(); addSparePartSetRemote = owningInventory.getMboSet("SPAREPART_NOSITE"); while(true) { whereUsed = this.getMbo(i); if (whereUsed == null) { i = 0; while(true) { whereUsed = this.getMbo(i); if (whereUsed == null) { return; } if (whereUsed.getString("newrow").equals("A")) { addSparePart = addSparePartSetRemote.add(2L); addSparePart.setValue("itemnum", owningInventory.getString("itemnum"), 11L); addSparePart.setValue("itemsetid", owningInventory.getString("itemsetid"), 11L); addSparePart.setValue("assetnum", whereUsed.getString("assetnum"), 11L); addSparePart.setValue("siteid", whereUsed.getString("siteid"), 11L); addSparePart.setValue("quantity", whereUsed.getDouble("quantity"), 11L); addSparePart.setValue("description", whereUsed.getString("remarks"), 11L); } else if (whereUsed.getString("newrow").equalsIgnoreCase("D")) { ((WhereUsed)whereUsed).deleteAssociatedSparePart(); } else if (((Mbo)whereUsed).getMboValue("quantity").isModified() && owningInventory != null && !whereUsed.getString("newrow").equals("D")) { SqlFormat sqf = new SqlFormat(this.getUserInfo(), "sparepartid=:1"); sqf.setLong(1, whereUsed.getLong("sparepartid")); MboSetRemote sparePartSet = whereUsed.getMboSet("$sparePartForWhereUse", "SPAREPART", sqf.format()); MboRemote sparePart = sparePartSet.getMbo(0); if (sparePart != null) { sparePart.setValue("quantity", whereUsed.getDouble("quantity"), 11L); sparePart.setValue("description", whereUsed.getString("remarks"), 11L); } } ++i; } } if (whereUsed.getString("newrow").equals("A") && whereUsed.isNull("assetnum")) { Object[] params = new Object[]{"ASSETNUM", whereUsed.getName()}; throw new MXApplicationException("system", "null", params); } ++i; } } if(owner instanceof Item) { owningItem = (Item)this.getOwner(); addSparePartSetRemote = owningItem.getMboSet("SPAREPART_NOSITE"); while(true) { whereUsed = this.getMbo(i); if (whereUsed == null) { i = 0; while(true) { whereUsed = this.getMbo(i); if (whereUsed == null) { return; } if (whereUsed.getString("newrow").equals("A")) { addSparePart = addSparePartSetRemote.add(2L); addSparePart.setValue("itemnum", owningItem.getString("itemnum"), 11L); addSparePart.setValue("itemsetid", owningItem.getString("itemsetid"), 11L); addSparePart.setValue("assetnum", whereUsed.getString("assetnum"), 11L); addSparePart.setValue("siteid", whereUsed.getString("siteid"), 11L); addSparePart.setValue("quantity", whereUsed.getDouble("quantity"), 11L); addSparePart.setValue("description", whereUsed.getString("remarks"), 11L); } else if (whereUsed.getString("newrow").equalsIgnoreCase("D")) { ((WhereUsed)whereUsed).deleteAssociatedSparePart(); } else if (((Mbo)whereUsed).getMboValue("quantity").isModified() && owningInventory != null && !whereUsed.getString("newrow").equals("D")) { SqlFormat sqf = new SqlFormat(this.getUserInfo(), "sparepartid=:1"); sqf.setLong(1, whereUsed.getLong("sparepartid")); MboSetRemote sparePartSet = whereUsed.getMboSet("$sparePartForWhereUse", "SPAREPART", sqf.format()); MboRemote sparePart = sparePartSet.getMbo(0); if (sparePart != null) { sparePart.setValue("quantity", whereUsed.getDouble("quantity"), 11L); sparePart.setValue("description", whereUsed.getString("remarks"), 11L); } } ++i; } } if (whereUsed.getString("newrow").equals("A") && whereUsed.isNull("assetnum")) { Object[] params = new Object[]{"ASSETNUM", whereUsed.getName()}; throw new MXApplicationException("system", "null", params); } ++i; } } } @Override public void save() throws MXException, RemoteException { // TODO Auto-generated method stub System.out.println("inside save"); super.save(); } }