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:
027: package org.cougaar.mlm.plugin.ldm;
028:
029: import java.util.Calendar;
030: import java.util.Date;
031:
032: import org.cougaar.planning.ldm.PlanningFactory;
033: import org.cougaar.planning.ldm.asset.Asset;
034: import org.cougaar.planning.ldm.plan.NewRoleSchedule;
035: import org.cougaar.planning.ldm.plan.NewSchedule;
036:
037: /** AssetCreator is a subclass of AggregateAssetCreator which creates sql queries
038: * (through its superclass) and processes the query results by creating assets with bumpernumbers.
039: */
040:
041: public class SQLAssetCreator extends PeriodicQuery {
042:
043: public SQLAssetCreator() {
044: }
045:
046: public void processRow(Object[] data) {
047: //System.out.println("I see "+data[1]+" of "+data[2]);
048:
049: String nsn = (String) data[0];
050: Number count = (Number) data[1];
051: String nomenclature = (String) data[2];
052:
053: //System.out.println(myMessageAddress.getAddress() + ": " +
054: // "Creating " + count + " instances of NSN/" + nsn + " " + nomenclature);
055:
056: for (int i = 1; i <= count.intValue(); i++) {
057: String bumper = createUniqueID(myMessageAddress
058: .getAddress(), nsn, i);
059: Asset newasset = createAsset("NSN/" + nsn, bumper,
060: nomenclature);
061: setupAvailableSchedule(newasset);
062:
063: publishAdd(newasset);
064: }
065:
066: }
067:
068: public String getQuery() {
069: return (String) getParameter("query");
070: }
071:
072: private String createUniqueID(String cluster, String nsn, int id) {
073: return cluster + "-" + nsn + "-" + id;
074: }
075:
076: protected Asset createAsset(String prototype, String uniqueid,
077: String nomenclature) {
078: PlanningFactory ldmfactory = getLDM().getFactory();
079:
080: // System.out.println("Creating asset : " + prototype + " " +
081: // uniqueid + " " + nomenclature);
082:
083: return ldmfactory.createInstance(prototype, uniqueid);
084:
085: }
086:
087: private void setupAvailableSchedule(Asset asset) {
088: PlanningFactory ldmfactory = getLDM().getFactory();
089: Calendar mycalendar = Calendar.getInstance();
090: // set the start date of the available schedule to 01/01/1990
091: mycalendar.set(1990, 0, 1, 0, 0, 0);
092: Date start = mycalendar.getTime();
093: // set the end date of the available schedule to 01/01/2010
094: mycalendar.set(2010, 0, 1, 0, 0, 0);
095: Date end = mycalendar.getTime();
096: NewSchedule availsched = ldmfactory.newSimpleSchedule(start,
097: end);
098: // set the available schedule
099: ((NewRoleSchedule) asset.getRoleSchedule())
100: .setAvailableSchedule(availsched);
101: }
102:
103: }
|