001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.mlm.construction;
027:
028: import org.cougaar.glm.ldm.asset.Inventory;
029: import org.cougaar.glm.ldm.asset.InventoryBG;
030: import org.cougaar.glm.ldm.asset.NewInventoryPG;
031: import org.cougaar.glm.ldm.asset.NewReportSchedulePG;
032: import org.cougaar.glm.ldm.asset.NewScheduledContentPG;
033: import org.cougaar.glm.ldm.asset.ProjectionWeight;
034: import org.cougaar.glm.ldm.asset.PropertyGroupFactory;
035: import org.cougaar.glm.ldm.plan.Agency;
036: import org.cougaar.glm.plugins.inventory.InventoryPlugin;
037: import org.cougaar.planning.ldm.asset.Asset;
038: import org.cougaar.planning.ldm.asset.NewItemIdentificationPG;
039: import org.cougaar.planning.ldm.asset.NewTypeIdentificationPG;
040:
041: import java.util.GregorianCalendar;
042:
043: /** Plugin for Construction Inventory. Contains methods to setup and create construction
044: * inventory.
045: */
046:
047: public class ConstructionInventoryPlugin extends InventoryPlugin {
048:
049: //Hardcoded required inventory levels
050: protected double capacity = 1000000;
051: protected double init_level = 0.0;
052: protected double erq = 0.0;
053: protected double min_reorder = 0.0;
054:
055: /** Constructor */
056: public ConstructionInventoryPlugin() {
057: super ();
058: }
059:
060: /** Establishes and sets up Construction Inventory Decorator */
061: protected void decoratePlugin() {
062: ConstructionInventoryDecorator decorator = new ConstructionInventoryDecorator(
063: this , myOrganization_);
064: decorator.decoratePlugin(myOrganization_);
065: }
066:
067: /** Sets up fields needed for construction inventory.
068: * Initializes inventory.
069: */
070: public Inventory createInventory(String supplytype, Asset resource) {
071: String id = resource.getTypeIdentificationPG()
072: .getTypeIdentification();
073: if (logger.isDebugEnabled()) {
074: logger
075: .debug("*****ConstructionInventoryPlugin: createInventory()"
076: + "<"
077: + supplytype
078: + "> createInventory for " + id);
079: }
080: GregorianCalendar reportBaseDate = null;
081: int reportStepKind = 0;
082: boolean success = false;
083: InventoryBG bg = null;
084: NewInventoryPG invpg = (NewInventoryPG) PropertyGroupFactory
085: .newInventoryPG();
086: InventoryItemInfo info = null;
087: double[] levels = null;
088:
089: info = (InventoryItemInfo) inventoryInitHash_.get(id);
090:
091: invpg.setResource(resource);
092: Agency agency = myOrganization_.getOrganizationPG().getAgency();
093:
094: if (inventoryInitHash_.isEmpty()) {
095: double[] temp_levels = { capacity, init_level, erq,
096: min_reorder };
097: levels = (double[]) temp_levels;
098: }
099: if ((info != null) && (levels == null)) {
100: //GLMDebug.DEBUG(className_, clusterId_,"*****ConstructionInventoryPlugin: info not null and levels null");
101: levels = (double[]) info.levels;
102: }
103:
104: // Try to initialize the inventory behavior group, if it fails this cluster
105: // does not handle the item.
106: if (levels != null) {
107: bg = new ConstructionInventoryBG(invpg);
108: success = ((ConstructionInventoryBG) bg).initialize(levels);
109: if (info != null) {
110: if (info.reportBase != null) {
111: reportBaseDate = info.reportBase;
112: reportStepKind = info.reportStepKind;
113: }
114: }
115: }
116:
117: if (!success) {
118: if (logger.isDebugEnabled()) {
119: logger
120: .debug("createInventory(), cannot create inventory for "
121: + id);
122: }
123: return null;
124: }
125:
126: Inventory inventory = null;
127: inventory = (Inventory) theLDMF.createAsset("Inventory");
128: if (inventory == null) {
129: if (logger.isDebugEnabled()) {
130: logger
131: .debug("*****ConstructionInventoryPlugin"
132: + "<"
133: + supplytype
134: + "> createInventory - fail to create inventory for "
135: + id);
136: }
137: return null;
138: }
139: invpg.setInvBG(bg);
140: bg.setProjectionWeight(getProjectionWeight(supplytype));
141: inventory.addOtherPropertyGroup(invpg);
142: long time = getMyDelegate().currentTimeMillis();
143: invpg.resetInventory(inventory, time);
144: invpg.clearContentSchedule(inventory);
145:
146: NewTypeIdentificationPG ti = (NewTypeIdentificationPG) inventory
147: .getTypeIdentificationPG();
148: ti.setTypeIdentification("InventoryAsset");
149: ti.setNomenclature("Inventory Asset");
150:
151: ((NewItemIdentificationPG) inventory.getItemIdentificationPG())
152: .setItemIdentification("Inventory:" + id);
153:
154: NewScheduledContentPG scp;
155: scp = (NewScheduledContentPG) inventory.getScheduledContentPG();
156: scp.setAsset(resource);
157:
158: if (reportBaseDate != null) {
159: NewReportSchedulePG nrsp = PropertyGroupFactory
160: .newReportSchedulePG();
161: nrsp.setBase(info.reportBase);
162: nrsp.setStep(info.reportStepKind);
163: inventory.setReportSchedulePG(nrsp);
164: //System.out.println("setReportSchedulePG " + info.reportBase);
165: }
166: return inventory;
167: }
168:
169: /**
170: Don't call this directly. Use the base class
171: getProjectionWeight which will invoke this if necessary.
172: **/
173: protected ProjectionWeight createProjectionWeight(String supplyType) {
174: return new ConstructionProjectionWeight(2);
175: }
176:
177: }
|