Source Code Cross Referenced for InventoryServlet.java in  » Science » Cougaar12_4 » org » cougaar » mlm » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.mlm.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * <copyright>
0003:         *  
0004:         *  Copyright 1997-2004 BBNT Solutions, LLC
0005:         *  under sponsorship of the Defense Advanced Research Projects
0006:         *  Agency (DARPA).
0007:         * 
0008:         *  You can redistribute this software and/or modify it under the
0009:         *  terms of the Cougaar Open Source License as published on the
0010:         *  Cougaar Open Source Website (www.cougaar.org).
0011:         * 
0012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0023:         *  
0024:         * </copyright>
0025:         */
0026:
0027:        package org.cougaar.mlm.servlet;
0028:
0029:        import java.io.BufferedReader;
0030:        import java.io.IOException;
0031:        import java.io.InputStream;
0032:        import java.io.InputStreamReader;
0033:        import java.io.ObjectOutputStream;
0034:        import java.util.Collection;
0035:        import java.util.Date;
0036:        import java.util.HashSet;
0037:        import java.util.Iterator;
0038:        import java.util.Vector;
0039:
0040:        import javax.servlet.ServletException;
0041:        import javax.servlet.ServletOutputStream;
0042:        import javax.servlet.http.HttpServlet;
0043:        import javax.servlet.http.HttpServletRequest;
0044:        import javax.servlet.http.HttpServletResponse;
0045:
0046:        import org.cougaar.core.blackboard.Subscription;
0047:        import org.cougaar.core.mts.MessageAddress;
0048:        import org.cougaar.core.service.AlarmService;
0049:        import org.cougaar.core.service.LoggingService;
0050:        import org.cougaar.core.servlet.SimpleServletSupport;
0051:        import org.cougaar.glm.ldm.Constants;
0052:        import org.cougaar.glm.ldm.asset.GLMAsset;
0053:        import org.cougaar.glm.ldm.asset.Organization;
0054:        import org.cougaar.glm.ldm.asset.ScheduledContentPG;
0055:        import org.cougaar.glm.ldm.asset.SupplyClassPG;
0056:        import org.cougaar.glm.ldm.oplan.Oplan;
0057:        import org.cougaar.glm.ldm.plan.PlanScheduleType;
0058:        import org.cougaar.mlm.ui.data.UIInventoryImpl;
0059:        import org.cougaar.mlm.ui.data.UISimpleInventory;
0060:        import org.cougaar.mlm.ui.data.UISimpleNamedScheduleNames;
0061:        import org.cougaar.planning.ldm.asset.Asset;
0062:        import org.cougaar.planning.ldm.asset.TypeIdentificationPG;
0063:        import org.cougaar.planning.ldm.plan.Allocation;
0064:        import org.cougaar.planning.ldm.plan.Role;
0065:        import org.cougaar.planning.ldm.plan.ScheduleType;
0066:        import org.cougaar.planning.ldm.plan.Task;
0067:        import org.cougaar.util.UnaryPredicate;
0068:
0069:        public class InventoryServlet extends HttpServlet {
0070:
0071:            private SimpleServletSupport support;
0072:            private AlarmService alarmService;
0073:            private LoggingService logger;
0074:
0075:            public void setSimpleServletSupport(SimpleServletSupport support) {
0076:                this .support = support;
0077:            }
0078:
0079:            public void setLoggingService(LoggingService loggingService) {
0080:                this .logger = loggingService;
0081:            }
0082:
0083:            public void setAlarmService(AlarmService anAlarmService) {
0084:                this .alarmService = anAlarmService;
0085:            }
0086:
0087:            public void doGet(HttpServletRequest request,
0088:                    HttpServletResponse response) throws IOException,
0089:                    ServletException {
0090:                // create a new "InventoryGetter" context per request
0091:                InventoryGetter ig = new InventoryGetter(support, alarmService,
0092:                        logger);
0093:                ig.execute(request, response);
0094:            }
0095:
0096:            public void doPut(HttpServletRequest request,
0097:                    HttpServletResponse response) throws IOException,
0098:                    ServletException {
0099:                // create a new "InventoryGetter" context per request
0100:                InventoryGetter ig = new InventoryGetter(support, alarmService,
0101:                        logger);
0102:                try {
0103:                    //System.out.println("\n\n\n\n\n\n********* BEGIN PUT");
0104:                    ig.execute(request, response);
0105:                    //System.out.println("\n\n\n\n\n\n\n****** DID PUT");
0106:                } catch (Exception e) {
0107:                    //System.out.println("\n\n\n\n\n********* FAILED PUT!!  Exception: "+e);
0108:                    e.printStackTrace();
0109:                }
0110:            }
0111:
0112:            /**
0113:             * This inner class does all the work.
0114:             * <p>
0115:             * A new class is created per request, to keep all the
0116:             * instance fields separate.  If there was only one
0117:             * instance then multiple simultaneous requests would
0118:             * corrupt the instance fields (e.g. the "out" stream).
0119:             * <p>
0120:             * This acts as a <b>context</b> per request.
0121:             */
0122:            private static class InventoryGetter {
0123:
0124:                private String myID;
0125:                public String desiredAssetName = "";
0126:                ServletOutputStream out;
0127:
0128:                /* since "InventoryGetter" is a static inner class, here
0129:                 * we hold onto the support API.
0130:                 *
0131:                 * this makes it clear that InventoryGetter only uses
0132:                 * the "support" from the outer class.
0133:                 */
0134:                SimpleServletSupport support;
0135:                AlarmService alarmService;
0136:                LoggingService logger;
0137:
0138:                final public static String ASSET = "ASSET";
0139:                final public static String ASSET_AND_CLASSTYPE = ASSET + ":"
0140:                        + "CLASS_TYPE:";
0141:
0142:                public InventoryGetter(SimpleServletSupport aSupport,
0143:                        AlarmService anAlarmService,
0144:                        LoggingService aLoggingService) {
0145:                    this .support = aSupport;
0146:                    this .alarmService = anAlarmService;
0147:                    this .logger = aLoggingService;
0148:                }
0149:
0150:                /*
0151:                  Called when a request is received from a client.
0152:                  Either gets the command ASSET to return the names of all the assets
0153:                  that contain a ScheduledContentPG or
0154:                  gets the name of the asset to plot from the client request.
0155:                 */
0156:                public void execute(HttpServletRequest req,
0157:                        HttpServletResponse res) throws IOException {
0158:
0159:                    this .out = res.getOutputStream();
0160:
0161:                    //this.out = response.getWriter();
0162:                    /** The query data is one of:
0163:                    ASSET -- meaning return list of assets
0164:                    nomenclature:type id -- return asset matching nomenclature & type id
0165:                    UID: -- return asset with matching UID
0166:                    
0167:                    desiredAssetName = "";
0168:                    
0169:                    if (query_parameters.hasBody()) {
0170:                    desiredAssetName = query_parameters.getBodyAsString();
0171:                    desiredAssetName = desiredAssetName.trim();
0172:                    System.out.println("POST DATA: " + desiredAssetName);
0173:                    } else {
0174:                    System.out.println("WARNING: No asset to plot");
0175:                    return;
0176:                    }
0177:                     */
0178:
0179:                    int len = req.getContentLength();
0180:                    if (len > 0) {
0181:                        System.out.println("READ from content-length[" + len
0182:                                + "]");
0183:                        InputStream in = req.getInputStream();
0184:                        BufferedReader bin = new BufferedReader(
0185:                                new InputStreamReader(in));
0186:                        desiredAssetName = bin.readLine();
0187:                        bin.close();
0188:                        desiredAssetName = desiredAssetName.trim();
0189:                        System.out.println("POST DATA: " + desiredAssetName);
0190:                    } else {
0191:                        System.out.println("WARNING: No asset to plot");
0192:                        return;
0193:                    }
0194:
0195:                    // return list of asset names
0196:                    if (desiredAssetName.equals(ASSET)
0197:                            || desiredAssetName.startsWith(ASSET_AND_CLASSTYPE)) {
0198:
0199:                        DemandObjectPredicate assetNamePredicate;
0200:                        //AssetPredicate assetNamePredicate;
0201:
0202:                        if (desiredAssetName.startsWith(ASSET_AND_CLASSTYPE)) {
0203:                            String desiredClassType = desiredAssetName
0204:                                    .substring(ASSET_AND_CLASSTYPE.length());
0205:                            assetNamePredicate = new DemandObjectPredicate(
0206:                                    desiredClassType);
0207:                            //assetNamePredicate = new AssetPredicate(desiredClassType);
0208:                        } else {
0209:                            assetNamePredicate = new DemandObjectPredicate();
0210:                            //assetNamePredicate = new AssetPredicate();
0211:                        }
0212:
0213:                        // Asset no demand type handling
0214:                        /***
0215:                         **
0216:                         *
0217:                         
0218:                         Vector assetNames = new Vector();
0219:                         Subscription subscription = 
0220:                         psc.getServerPluginSupport().subscribe(this, assetNamePredicate);
0221:                         
0222:                         Collection container = 
0223:                         ((CollectionSubscription)subscription).getCollection();
0224:                         for (Iterator i = container.iterator(); i.hasNext(); ) {
0225:                         GLMAsset asset = (GLMAsset)(i.next());
0226:                         TypeIdentificationPG typeIdPG = 
0227:                         asset.getScheduledContentPG().getAsset().getTypeIdentificationPG();
0228:                         String nomenclature = typeIdPG.getNomenclature();
0229:                         String typeId = typeIdPG.getTypeIdentification();
0230:                         if (nomenclature != null)
0231:                         nomenclature = nomenclature + ":" + typeId;
0232:                         else
0233:                         nomenclature = typeId;
0234:                         assetNames.addElement(nomenclature);
0235:                         }
0236:                         
0237:                         ***
0238:                         * MWD fix and try this out -below
0239:                         * MWD get rid of old commented out above replaced by below
0240:                         * to get demand even where no inventories.
0241:                         ****/
0242:
0243:                        HashSet assetNamesSet = new HashSet();
0244:                        Collection container = support
0245:                                .queryBlackboard(assetNamePredicate);
0246:
0247:                        /*	Subscription subscription = 
0248:                        	psc.getServerPluginSupport().subscribe(this, assetNamePredicate);
0249:                        	
0250:                        	Collection container = 
0251:                        	((CollectionSubscription)subscription).getCollection();
0252:                         */
0253:
0254:                        for (Iterator i = container.iterator(); i.hasNext();) {
0255:                            Asset asset = ((Task) (i.next())).getDirectObject();
0256:                            TypeIdentificationPG typeIdPG = asset
0257:                                    .getTypeIdentificationPG();
0258:                            String nomenclature = typeIdPG.getNomenclature();
0259:                            String typeId = typeIdPG.getTypeIdentification();
0260:                            if (nomenclature != null)
0261:                                nomenclature = nomenclature + ":" + typeId;
0262:                            else
0263:                                nomenclature = typeId;
0264:                            assetNamesSet.add(nomenclature);
0265:                        }
0266:
0267:                        Vector assetNames = new Vector(assetNamesSet);
0268:
0269:                        // unsubscribe, don't need this subscription any more
0270:                        //psc.getServerPluginSupport().unsubscribeForSubscriber(subscription);
0271:                        // send the results
0272:                        ObjectOutputStream p = new ObjectOutputStream(out);
0273:                        p.writeObject(assetNames);
0274:                        System.out.println("Sent asset names");
0275:                        return;
0276:                    } // end returning list of asset names
0277:
0278:                    if (desiredAssetName.startsWith("UID:")) {
0279:                        String desiredAssetUID = desiredAssetName.substring(4);
0280:                        Collection collection = support
0281:                                .queryBlackboard(new AssetUIDPredicate(
0282:                                        desiredAssetUID));
0283:
0284:                        /*Subscription subscription = 
0285:                          psc.getServerPluginSupport().subscribe(this, new AssetUIDPredicate(desiredAssetUID));
0286:                          Collection collection = 
0287:                          ((CollectionSubscription)subscription).getCollection();
0288:                         */
0289:
0290:                        for (Iterator i = collection.iterator(); i.hasNext();) {
0291:                            GLMAsset asset = (GLMAsset) (i.next());
0292:                            TypeIdentificationPG typeIdPG = asset
0293:                                    .getScheduledContentPG().getAsset()
0294:                                    .getTypeIdentificationPG();
0295:                            String nomenclature = typeIdPG.getNomenclature();
0296:                            String typeId = typeIdPG.getTypeIdentification();
0297:                            if (nomenclature == null)
0298:                                return;
0299:                            desiredAssetName = nomenclature + ":" + typeId;
0300:                        }
0301:                        // unsubscribe, don't need this subscription any more
0302:                        //psc.getServerPluginSupport().unsubscribeForSubscriber(subscription);
0303:                    } // end getting asset name from UID
0304:
0305:                    Date startDay = getStartDate();
0306:
0307:                    // get roles and determine if this cluster is a provider (or consumer)
0308:                    //System.out.println("\n****** look for roles for agent \""+support.getEncodedAgentName()+"\"");
0309:                    RolePredicate rolePred = new RolePredicate(support
0310:                            .getEncodedAgentName());
0311:                    Collection roleCollection = support
0312:                            .queryBlackboard(rolePred);
0313:
0314:                    /*Subscription roleSubscription =
0315:                    psc.getServerPluginSupport().subscribe(this, 
0316:                    new RolePredicate(psc.getServerPluginSupport().getClusterIDAsString()));
0317:                    Collection roleCollection =
0318:                    ((CollectionSubscription)roleSubscription).getCollection();
0319:                     */
0320:                    boolean provider = false;
0321:                    if (!roleCollection.isEmpty()) {
0322:
0323:                        //Organization asset = (Organization) ((CollectionSubscription)roleSubscription).first();
0324:                        //CollectionSubscription collectsub = new CollectionSubscription(rolePred);
0325:                        //Organization asset = (Organization) collectsub.first();
0326:                        Organization asset = (Organization) roleCollection
0327:                                .iterator().next();
0328:
0329:                        Collection roles = asset.getOrganizationPG().getRoles();
0330:                        if (roles != null) {
0331:                            Iterator i = roles.iterator();
0332:                            while (i.hasNext()) {
0333:                                Role role = (Role) i.next();
0334:                                if (role.getName().endsWith("Provider")) {
0335:                                    provider = true;
0336:                                    break;
0337:                                }
0338:                            }
0339:                        }
0340:                    }
0341:
0342:                    //psc.getServerPluginSupport().unsubscribeForSubscriber(roleSubscription);
0343:
0344:                    // get asset and tasks we need to create the inventory
0345:
0346:                    InventoryPredicate inventoryPredicate = new InventoryPredicate(
0347:                            desiredAssetName, support.getEncodedAgentName());
0348:                    Collection collection = support
0349:                            .queryBlackboard(inventoryPredicate);
0350:
0351:                    /*
0352:                    InventoryPredicate inventoryPredicate = 
0353:                    new InventoryPredicate(desiredAssetName, 
0354:                    psc.getServerPluginSupport().getClusterIDAsString());
0355:                    Subscription subscription = 
0356:                    psc.getServerPluginSupport().subscribe(this, inventoryPredicate);
0357:                    Collection collection = 
0358:                    ((CollectionSubscription)subscription).getCollection();
0359:                     */
0360:
0361:                    if (collection.isEmpty()) {
0362:                        //System.out.println("\n\n\n\n\n\n\n ************* collection is empty; return no response!");
0363:                        return;
0364:                    }
0365:
0366:                    // create UIInventory data object from the log plan objects
0367:                    UIInventoryImpl inventory = getInventoryFromLogPlan(collection);
0368:
0369:                    // unsubscribe, don't need this subscription any more
0370:                    //psc.getServerPluginSupport().unsubscribeForSubscriber(subscription);
0371:
0372:                    // set values in UISimpleInventory, a serializable object
0373:                    UISimpleInventory simpleInventory = getInventoryForClient(
0374:                            inventory, provider, startDay);
0375:
0376:                    // send the UISimpleInventory object
0377:                    if (simpleInventory != null) {
0378:                        ObjectOutputStream p = new ObjectOutputStream(out);
0379:                        //System.out.println("\n\n\n\n sending back a non-null inventory:\n"+simpleInventory);
0380:                        p.writeObject(simpleInventory);
0381:                        System.out.println("Sent XML document");
0382:                    } else {
0383:                        //System.out.println("\n\n\n\n  simple-inventory is null!!!  return no response");
0384:                    }
0385:                }
0386:
0387:                /** Called after submitting a subscription; the container
0388:                contains the asset and tasks we need to compute the inventory
0389:                object that we'll return to the client.
0390:                 */
0391:
0392:                private UIInventoryImpl getInventoryFromLogPlan(
0393:                        Collection container) {
0394:                    UIInventoryImpl inventory = new UIInventoryImpl();
0395:                    Allocation lastAllocation = null;
0396:                    Object o = null;
0397:                    Iterator i = null;
0398:
0399:                    //first set the asset
0400:                    for (i = container.iterator(); i.hasNext();) {
0401:                        o = i.next();
0402:                        if (o instanceof  Asset) {
0403:                            inventory.setAsset((Asset) o);
0404:                        }
0405:                    }
0406:                    //next do the allocation
0407:                    for (i = container.iterator(); i.hasNext();) {
0408:                        o = i.next();
0409:                        if (o instanceof  Allocation) {
0410:                            lastAllocation = (Allocation) o;
0411:                            inventory.addDueInSchedule((Allocation) o);
0412:                            inventory.addRequestedDueInSchedule((Allocation) o);
0413:                        }
0414:                    }
0415:                    //MWD new code if there are no GLMAsset Inventories it's likely
0416:                    //the Asset has not been set on this UIInventoryImpl.
0417:                    //There are just allocations in this InventoryPredicate returned
0418:                    //collection and hence if (o instanceof Asset) has been used.
0419:                    if ((lastAllocation != null)
0420:                            && (inventory.getAsset() == null)) {
0421:                        Asset directAsset = lastAllocation.getTask()
0422:                                .getDirectObject();
0423:                        inventory.setAsset(directAsset);
0424:                    }
0425:
0426:                    return inventory;
0427:                }
0428:
0429:                /** Called to make a UISimpleInventory object which gets serialized
0430:                and sent to the client.  Note that at the client end, the schedule
0431:                type must be in org.cougaar.planning.ldm.plan.ScheduleType, so we fix any bogus
0432:                schedules here and issue warnings.
0433:                 */
0434:
0435:                private UISimpleInventory getInventoryForClient(
0436:                        UIInventoryImpl inventory, boolean provider,
0437:                        Date startingCDay) {
0438:                    UISimpleInventory inv = new UISimpleInventory();
0439:
0440:                    inv.setAssetName(inventory.getAssetName());
0441:                    inv.setUnitType(inventory.getUnitType());
0442:                    inv.setProvider(provider); // ui uses this to determine chart labels
0443:                    String scheduleType = inventory.getScheduleType();
0444:                    if (scheduleType.equals(ScheduleType.OTHER)) {
0445:                        scheduleType = PlanScheduleType.TOTAL_INVENTORY;
0446:                        System.out
0447:                                .println("WARNING: Treating Other schedule as total inventory");
0448:                    }
0449:                    inv.setScheduleType(scheduleType);
0450:                    inv.setBaseCDay(startingCDay);
0451:
0452:                    Date alpNow = new Date(alarmService.currentTimeMillis());
0453:
0454:                    logger.debug("Setting Alp now to " + alpNow);
0455:
0456:                    inv.setAlpNow(alarmService.currentTimeMillis());
0457:
0458:                    if (scheduleType.equals(PlanScheduleType.TOTAL_CAPACITY)) {
0459:                        inv.addNamedSchedule(
0460:                                UISimpleNamedScheduleNames.ALLOCATED, inventory
0461:                                        .getDueOutLaborSchedule());
0462:                        inv.addNamedSchedule(
0463:                                UISimpleNamedScheduleNames.TOTAL_LABOR,
0464:                                inventory.getLaborSchedule());
0465:                    } else if (scheduleType
0466:                            .equals(PlanScheduleType.ACTUAL_CAPACITY)) {
0467:                        inv.addNamedSchedule(
0468:                                UISimpleNamedScheduleNames.ALLOCATED, inventory
0469:                                        .getDueOutLaborSchedule());
0470:                        inv.addNamedSchedule(
0471:                                UISimpleNamedScheduleNames.ON_HAND, inventory
0472:                                        .getOnHandDailySchedule());
0473:                    } else if (scheduleType
0474:                            .equals(PlanScheduleType.TOTAL_INVENTORY)) {
0475:
0476:                        inv.addNamedSchedule(
0477:                                UISimpleNamedScheduleNames.ON_HAND, inventory
0478:                                        .getOnHandDailySchedule());
0479:                        inv.addNamedSchedule(
0480:                                UISimpleNamedScheduleNames.ON_HAND_DETAILED,
0481:                                inventory.getOnHandDetailedSchedule());
0482:
0483:                        /*** MWD Remove
0484:                         **  Generate a false detailed schedule
0485:                         *
0486:                         
0487:                         if(inventory.getOnHandDetailedSchedule() != null) {
0488:                         Vector lotsODetails = new Vector();
0489:                         int divElement=5;
0490:                         Vector onHand = inventory.getOnHandDailySchedule();
0491:                         for(int i=0; i < onHand.size() ; i++) {
0492:                         UIQuantityScheduleElement orig = (UIQuantityScheduleElement) onHand.elementAt(i);
0493:                         long  myStart = orig.getStartTime();
0494:                         long  myEnd = orig.getEndTime();
0495:                         divElement = (int) i%7;
0496:                         if(divElement==0) divElement=1;
0497:                         long  addTime = (long) (myEnd - myStart)/divElement;
0498:                         double  changeQty = 10;
0499:                         for (int j=0; j < divElement; j++) {
0500:                         changeQty = ((changeQty) * j);
0501:                         double elQty = orig.getQuantity() + changeQty;
0502:                         if(elQty != orig.getQuantity()) {
0503:                         System.out.println("Different! I'd say orig: " + orig.getQuantity() + " elQty: " + elQty);
0504:                         }
0505:                         lotsODetails.add(new UIQuantityScheduleElement(myStart, myStart + addTime, elQty));
0506:                         myStart+=addTime;
0507:                         }
0508:                         }
0509:                         inv.addNamedSchedule(ON_HAND_DETAILED,lotsODetails);
0510:                         }
0511:                        	      
0512:                         **
0513:                         ***/
0514:
0515:                        inv.addNamedSchedule(UISimpleNamedScheduleNames.DUE_IN,
0516:                                inventory.getDueInSchedule());
0517:                        inv.addNamedSchedule(
0518:                                UISimpleNamedScheduleNames.UNCONFIRMED_DUE_IN,
0519:                                inventory.getUnconfirmedDueInSchedule());
0520:                        inv.addNamedSchedule(
0521:                                UISimpleNamedScheduleNames.REQUESTED_DUE_IN,
0522:                                inventory.getRequestedDueInSchedule());
0523:                        inv.addNamedSchedule(
0524:                                UISimpleNamedScheduleNames.PROJECTED_DUE_IN,
0525:                                inventory.getProjectedDueInSchedule());
0526:                        inv
0527:                                .addNamedSchedule(
0528:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_IN,
0529:                                        inventory
0530:                                                .getProjectedRequestedDueInSchedule());
0531:
0532:                        inv.addNamedSchedule(UISimpleNamedScheduleNames.DUE_IN
0533:                                + UISimpleNamedScheduleNames.INACTIVE,
0534:                                inventory.getInactiveDueInSchedule());
0535:                        inv
0536:                                .addNamedSchedule(
0537:                                        UISimpleNamedScheduleNames.UNCONFIRMED_DUE_IN
0538:                                                + UISimpleNamedScheduleNames.INACTIVE,
0539:                                        inventory
0540:                                                .getInactiveUnconfirmedDueInSchedule());
0541:                        inv.addNamedSchedule(
0542:                                UISimpleNamedScheduleNames.REQUESTED_DUE_IN
0543:                                        + UISimpleNamedScheduleNames.INACTIVE,
0544:                                inventory.getInactiveRequestedDueInSchedule());
0545:                        inv.addNamedSchedule(
0546:                                UISimpleNamedScheduleNames.PROJECTED_DUE_IN
0547:                                        + UISimpleNamedScheduleNames.INACTIVE,
0548:                                inventory.getInactiveProjectedDueInSchedule());
0549:                        inv
0550:                                .addNamedSchedule(
0551:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_IN
0552:                                                + UISimpleNamedScheduleNames.INACTIVE,
0553:                                        inventory
0554:                                                .getInactiveProjectedRequestedDueInSchedule());
0555:
0556:                        inv.addNamedSchedule(
0557:                                UISimpleNamedScheduleNames.DUE_OUT, inventory
0558:                                        .getDueOutSchedule());
0559:                        inv.addNamedSchedule(
0560:                                UISimpleNamedScheduleNames.REQUESTED_DUE_OUT,
0561:                                inventory.getRequestedDueOutSchedule());
0562:                        inv.addNamedSchedule(
0563:                                UISimpleNamedScheduleNames.PROJECTED_DUE_OUT,
0564:                                inventory.getProjectedDueOutSchedule());
0565:                        inv
0566:                                .addNamedSchedule(
0567:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_OUT,
0568:                                        inventory
0569:                                                .getProjectedRequestedDueOutSchedule());
0570:
0571:                        inv.addNamedSchedule(UISimpleNamedScheduleNames.DUE_OUT
0572:                                + UISimpleNamedScheduleNames.INACTIVE,
0573:                                inventory.getInactiveDueOutSchedule());
0574:                        inv.addNamedSchedule(
0575:                                UISimpleNamedScheduleNames.PROJECTED_DUE_OUT
0576:                                        + UISimpleNamedScheduleNames.INACTIVE,
0577:                                inventory.getInactiveProjectedDueOutSchedule());
0578:                        inv.addNamedSchedule(
0579:                                UISimpleNamedScheduleNames.REQUESTED_DUE_OUT
0580:                                        + UISimpleNamedScheduleNames.INACTIVE,
0581:                                inventory.getInactiveRequestedDueOutSchedule());
0582:                        inv
0583:                                .addNamedSchedule(
0584:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_OUT
0585:                                                + UISimpleNamedScheduleNames.INACTIVE,
0586:                                        inventory
0587:                                                .getInactiveProjectedRequestedDueOutSchedule());
0588:
0589:                        inventory.computeSimulatedProjectionSchedules();
0590:
0591:                        //inv.addNamedSchedule(ON_HAND,                               inventory.getOnHandMockSchedule());
0592:                        //inv.addNamedSchedule(PROJECTED_DUE_IN,                      inventory.getProjectedMockDueInSchedule());
0593:                        //inv.addNamedSchedule(PROJECTED_REQUESTED_DUE_IN,            inventory.getProjectedRequestedMockDueInSchedule());
0594:                        //inv.addNamedSchedule(PROJECTED_DUE_OUT,                     inventory.getProjectedMockDueOutSchedule());
0595:                        //inv.addNamedSchedule(PROJECTED_REQUESTED_DUE_OUT,           inventory.getProjectedRequestedMockDueOutSchedule());
0596:
0597:                        inv.addNamedSchedule(
0598:                                UISimpleNamedScheduleNames.ON_HAND_MOCK_PERIOD,
0599:                                inventory.getOnHandMockSchedule());
0600:                        inv
0601:                                .addNamedSchedule(
0602:                                        UISimpleNamedScheduleNames.PROJECTED_DUE_IN_MOCK_PERIOD,
0603:                                        inventory
0604:                                                .getProjectedMockDueInSchedule());
0605:                        inv
0606:                                .addNamedSchedule(
0607:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_IN_MOCK_PERIOD,
0608:                                        inventory
0609:                                                .getProjectedRequestedMockDueInSchedule());
0610:                        inv
0611:                                .addNamedSchedule(
0612:                                        UISimpleNamedScheduleNames.PROJECTED_DUE_OUT_MOCK_PERIOD,
0613:                                        inventory
0614:                                                .getProjectedMockDueOutSchedule());
0615:                        inv
0616:                                .addNamedSchedule(
0617:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_OUT_MOCK_PERIOD,
0618:                                        inventory
0619:                                                .getProjectedRequestedMockDueOutSchedule());
0620:
0621:                        //inv.addNamedSchedule(ON_HAND_MOCK_PERIOD,                    inventory.getOnHandDailySchedule());
0622:                        //inv.addNamedSchedule(PROJECTED_DUE_IN_MOCK_PERIOD,           inventory.getProjectedDueInSchedule());
0623:                        //inv.addNamedSchedule(PROJECTED_REQUESTED_DUE_IN_MOCK_PERIOD, inventory.getProjectedRequestedDueInSchedule());
0624:                        //inv.addNamedSchedule(PROJECTED_DUE_OUT_MOCK_PERIOD,          inventory.getProjectedDueOutSchedule());
0625:                        //inv.addNamedSchedule(PROJECTED_REQUESTED_DUE_OUT_MOCK_PERIOD,inventory.getProjectedRequestedDueOutSchedule());
0626:
0627:                        inv.addNamedSchedule(
0628:                                UISimpleNamedScheduleNames.GOAL_LEVEL,
0629:                                inventory.getGoalLevelSchedule());
0630:                        inv.addNamedSchedule(
0631:                                UISimpleNamedScheduleNames.REORDER_LEVEL,
0632:                                inventory.getReorderLevelSchedule());
0633:                        inv
0634:                                .addNamedSchedule(
0635:                                        UISimpleNamedScheduleNames.AVERAGE_DEMAND_LEVEL,
0636:                                        inventory.getAverageDemandSchedule());
0637:                    } else if (scheduleType
0638:                            .equals(inventory.NO_INVENTORY_SCHEDULE_JUST_CONSUME)) {
0639:                        inv.addNamedSchedule(UISimpleNamedScheduleNames.DUE_IN,
0640:                                inventory.getDueInSchedule());
0641:                        inv.addNamedSchedule(
0642:                                UISimpleNamedScheduleNames.UNCONFIRMED_DUE_IN,
0643:                                inventory.getUnconfirmedDueInSchedule());
0644:                        inv.addNamedSchedule(
0645:                                UISimpleNamedScheduleNames.REQUESTED_DUE_IN,
0646:                                inventory.getRequestedDueInSchedule());
0647:                        inv.addNamedSchedule(
0648:                                UISimpleNamedScheduleNames.PROJECTED_DUE_IN,
0649:                                inventory.getProjectedDueInSchedule());
0650:                        inv
0651:                                .addNamedSchedule(
0652:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_IN,
0653:                                        inventory
0654:                                                .getProjectedRequestedDueInSchedule());
0655:                        inv.addNamedSchedule(UISimpleNamedScheduleNames.DUE_IN
0656:                                + UISimpleNamedScheduleNames.INACTIVE,
0657:                                inventory.getInactiveDueInSchedule());
0658:                        inv.addNamedSchedule(
0659:                                UISimpleNamedScheduleNames.PROJECTED_DUE_IN
0660:                                        + UISimpleNamedScheduleNames.INACTIVE,
0661:                                inventory.getInactiveProjectedDueInSchedule());
0662:                        inv
0663:                                .addNamedSchedule(
0664:                                        UISimpleNamedScheduleNames.UNCONFIRMED_DUE_IN
0665:                                                + UISimpleNamedScheduleNames.INACTIVE,
0666:                                        inventory
0667:                                                .getInactiveUnconfirmedDueInSchedule());
0668:                        inv.addNamedSchedule(
0669:                                UISimpleNamedScheduleNames.REQUESTED_DUE_IN
0670:                                        + UISimpleNamedScheduleNames.INACTIVE,
0671:                                inventory.getInactiveRequestedDueInSchedule());
0672:                        inv
0673:                                .addNamedSchedule(
0674:                                        UISimpleNamedScheduleNames.PROJECTED_REQUESTED_DUE_IN
0675:                                                + UISimpleNamedScheduleNames.INACTIVE,
0676:                                        inventory
0677:                                                .getInactiveProjectedRequestedDueInSchedule());
0678:
0679:                        System.out
0680:                                .println("getInventoryForClient: returning schedule type: "
0681:                                        + scheduleType);
0682:
0683:                    } else {
0684:                        System.out
0685:                                .println("WARNING: Unsupportd schedule type: "
0686:                                        + scheduleType);
0687:                        return null;
0688:                    }
0689:                    return inv;
0690:                }
0691:
0692:                protected Date getStartDate() {
0693:                    Date startingCDay = null;
0694:
0695:                    // get oplan
0696:
0697:                    Collection oplanCollection = support
0698:                            .queryBlackboard(oplanPredicate());
0699:
0700:                    /*Subscription oplanSubscription =
0701:                    psc.getServerPluginSupport().subscribe(this, oplanPredicate());
0702:                    Collection oplanCollection =
0703:                    ((CollectionSubscription)oplanSubscription).getCollection();
0704:                     */
0705:
0706:                    if (!(oplanCollection.isEmpty())) {
0707:                        Iterator iter = oplanCollection.iterator();
0708:                        Oplan plan = (Oplan) iter.next();
0709:                        //CollectionSubscription collectsub = new CollectionSubscription(oplanPredicate());
0710:                        //Oplan plan = (Oplan) collectsub.first();
0711:                        //Oplan plan = (Oplan) ((CollectionSubscription)oplanSubscription).first();
0712:                        startingCDay = plan.getCday();
0713:                        //psc.getServerPluginSupport().unsubscribeForSubscriber(oplanSubscription);     
0714:                    }
0715:                    return startingCDay;
0716:                }
0717:
0718:                public boolean returnsXML() {
0719:                    return true;
0720:                }
0721:
0722:                public boolean returnsHTML() {
0723:                    return false;
0724:                }
0725:
0726:                public String getDTD() {
0727:                    return "myDTD";
0728:                }
0729:
0730:                /* The UISubscriber interface.
0731:                   This PSP doesn't care if subscriptions change
0732:                   because it treats each request as a new request.
0733:                 */
0734:
0735:                public void subscriptionChanged(Subscription subscription) {
0736:                }
0737:
0738:                private static UnaryPredicate oplanPredicate() {
0739:                    return new UnaryPredicate() {
0740:                        public boolean execute(Object o) {
0741:                            return (o instanceof  Oplan);
0742:                        }
0743:                    };
0744:                }
0745:            }
0746:        }
0747:
0748:        /** Get asset which represents this cluster.
0749:         */
0750:
0751:        class RolePredicate implements  UnaryPredicate {
0752:            String myCluster;
0753:
0754:            public RolePredicate(String myCluster) {
0755:                this .myCluster = myCluster;
0756:            }
0757:
0758:            public boolean execute(Object o) {
0759:                if (o instanceof  Organization) {
0760:                    Organization asset = (Organization) o;
0761:                    String s = asset.getItemIdentificationPG()
0762:                            .getNomenclature();
0763:                    if (s != null)
0764:                        if (s.equals(myCluster))
0765:                            return true;
0766:                }
0767:                return false;
0768:            }
0769:
0770:        }
0771:
0772:        /** Subscribes to objects that provide quantity on hand, due-ins, & due-outs
0773:         for the specified asset.
0774:         For quantity on hand, get assets with a ScheduledContentPG in which
0775:         the asset.typeIdentificationPG.nomenclature matches the specified asset.
0776:         The ScheduledContentPG schedule indicates the start and end dates and
0777:         quantities.
0778:        
0779:         For due-outs, get allocations with assets with a ScheduledContentPG in which
0780:         the asset.typeIdentificationPG.nomenclature matches the specified asset.
0781:         The allocation's reportedResult aspectTypes and results encode
0782:         the quantity and start date.
0783:         PAS - get these from the inventory role schedule?
0784:        
0785:         For due-ins, get tasks with direct objects in which the
0786:         asset.typeIdentificationPG.nomenclature is the desired asset.
0787:         Get the allocations for these tasks, 
0788:         the allocation's reportedResult encodes
0789:         the quantity, and the start and end dates.
0790:         (Actually obtained by getting the allocations and then checking
0791:         the task in the allocation.)
0792:         */
0793:
0794:        class InventoryPredicate implements  UnaryPredicate {
0795:            String desiredAssetName; // nomenclature:type id
0796:            MessageAddress myClusterId;
0797:
0798:            public InventoryPredicate(String desiredAssetName, String myCluster) {
0799:                this .desiredAssetName = desiredAssetName;
0800:                myClusterId = MessageAddress.getMessageAddress(myCluster);
0801:            }
0802:
0803:            private boolean assetMatch(Asset asset) {
0804:                TypeIdentificationPG typeIdPG = asset.getTypeIdentificationPG();
0805:                if (typeIdPG == null) {
0806:                    System.out
0807:                            .println("WARNING: No typeIdentificationPG for asset");
0808:                    return false;
0809:                }
0810:                String nomenclature = typeIdPG.getNomenclature();
0811:                String typeId = typeIdPG.getTypeIdentification();
0812:                if (nomenclature == null)
0813:                    return false;
0814:                nomenclature = nomenclature + ":" + typeId;
0815:                return nomenclature.equals(desiredAssetName);
0816:            }
0817:
0818:            /** Get assets with scheduledContentPG such that
0819:                scheduledContentPG.getAsset().getTypeIdentificationPG().getNomenclature 
0820:                equals desiredAssetName and get Tasks from Allocations such that
0821:                Task.getDirectObject.getTypeIdentificationPG().getNomenclature
0822:                equals desiredAssetName and task.getVerb is SUPPLY and
0823:                Allocation.getAsset is an organization asset.
0824:                Also matches if asset uid is equal to desiredAssetName -- i.e.
0825:                the client can pass in a UID instead of the asset name.
0826:             */
0827:
0828:            public boolean execute(Object o) {
0829:                if (o instanceof  GLMAsset) {
0830:                    // looking for Inventory Assets
0831:                    GLMAsset asset = (GLMAsset) o;
0832:                    ScheduledContentPG scheduledContentPG = asset
0833:                            .getScheduledContentPG();
0834:                    if (scheduledContentPG == null)
0835:                        return false;
0836:                    Asset a1 = scheduledContentPG.getAsset();
0837:                    if (a1 == null) {
0838:                        System.out
0839:                                .println("WARNING: no asset in scheduledContentPG");
0840:                        return false;
0841:                    }
0842:                    return assetMatch(a1);
0843:                } else if (o instanceof  Allocation) {
0844:                    // looking for due ins
0845:                    Allocation allocation = (Allocation) o;
0846:                    if (!(allocation.getAsset() instanceof  Organization))
0847:                        return false;
0848:                    Task task = allocation.getTask();
0849:                    if (!((task.getVerb().equals(Constants.Verb.SUPPLY)) || (task
0850:                            .getVerb().equals(Constants.Verb.PROJECTSUPPLY))))
0851:                        return false;
0852:                    Object directObject = task.getDirectObject();
0853:                    if (directObject == null)
0854:                        return false;
0855:                    if (!(directObject instanceof  Asset))
0856:                        return false;
0857:                    boolean aMatch = assetMatch((Asset) directObject);
0858:                    /** MWD Debug
0859:                    if(aMatch) {
0860:                    System.out.println("PSP_Inventory::InventoryPredicate:Matching allocations task is with Verb: " + task.getVerb());
0861:                    }
0862:                     */
0863:                    return aMatch;
0864:                }
0865:                return false;
0866:            }
0867:        }
0868:
0869:        class AssetPredicate implements  UnaryPredicate {
0870:
0871:            private String supplyType;
0872:
0873:            public AssetPredicate() {
0874:                super ();
0875:                supplyType = null;
0876:            }
0877:
0878:            public AssetPredicate(String theSupplyType) {
0879:                super ();
0880:                supplyType = theSupplyType;
0881:            }
0882:
0883:            public boolean execute(Object o) {
0884:                if (!(o instanceof  GLMAsset))
0885:                    return false;
0886:                GLMAsset asset = (GLMAsset) o;
0887:                ScheduledContentPG scheduledContentPG = asset
0888:                        .getScheduledContentPG();
0889:                if (scheduledContentPG == null)
0890:                    return false;
0891:                Asset a1 = scheduledContentPG.getAsset();
0892:                if (a1 == null) {
0893:                    System.out
0894:                            .println("WARNING: no asset in scheduledContentPG");
0895:                    return false;
0896:                }
0897:                TypeIdentificationPG typeIdPG = a1.getTypeIdentificationPG();
0898:                if (typeIdPG == null) {
0899:                    System.out
0900:                            .println("WARNING: No typeIdentificationPG for asset");
0901:                    return false;
0902:                }
0903:                //If we care about supply type make sure direct object matches supply type
0904:                if (supplyType != null) {
0905:                    SupplyClassPG pg = (SupplyClassPG) a1
0906:                            .searchForPropertyGroup(SupplyClassPG.class);
0907:                    if ((pg == null)
0908:                            || (!(supplyType.equals(pg.getSupplyType())))) {
0909:                        return false;
0910:                    }
0911:                    /***
0912:                    if (pg == null) {
0913:                    System.out.println("WARNING: Null Supply type");
0914:                    return false;
0915:                    }
0916:                    else if (!(supplyType.equals(pg.getSupplyType()))){
0917:                    System.out.println("WARNING: The Supply type is: " + pg.getSupplyType());
0918:                    return false;
0919:                    }
0920:                    System.out.println("NO WARNING: SUCCESS got Asset of right type");
0921:                     ***/
0922:                }
0923:                return true;
0924:            }
0925:        }
0926:
0927:        class DemandObjectPredicate implements  UnaryPredicate {
0928:
0929:            private String supplyType;
0930:
0931:            public DemandObjectPredicate() {
0932:                super ();
0933:                supplyType = null;
0934:            }
0935:
0936:            public DemandObjectPredicate(String theSupplyType) {
0937:                super ();
0938:                supplyType = theSupplyType;
0939:            }
0940:
0941:            public boolean execute(Object o) {
0942:                if (!(o instanceof  Task))
0943:                    return false;
0944:                Task task = (Task) o;
0945:                if (!((task.getVerb().equals(Constants.Verb.PROJECTSUPPLY)) || (task
0946:                        .getVerb().equals(Constants.Verb.SUPPLY))))
0947:                    return false;
0948:                Asset asset = task.getDirectObject();
0949:                if (asset == null)
0950:                    return false;
0951:                TypeIdentificationPG typeIdPG = asset.getTypeIdentificationPG();
0952:                if (typeIdPG == null) {
0953:                    System.out
0954:                            .println("WARNING: No typeIdentificationPG for asset");
0955:                    return false;
0956:                }
0957:                //If we care about supply type make sure direct object matches supply type
0958:                if (supplyType != null) {
0959:                    SupplyClassPG pg = (SupplyClassPG) asset
0960:                            .searchForPropertyGroup(SupplyClassPG.class);
0961:                    if ((pg == null)
0962:                            || (!(supplyType.equals(pg.getSupplyType())))) {
0963:                        return false;
0964:                    }
0965:                }
0966:                return true;
0967:            }
0968:        }
0969:
0970:        class AssetUIDPredicate implements  UnaryPredicate {
0971:            String desiredAssetUID;
0972:
0973:            public AssetUIDPredicate(String desiredAssetUID) {
0974:                this .desiredAssetUID = desiredAssetUID;
0975:            }
0976:
0977:            public boolean execute(Object o) {
0978:                if (!(o instanceof  GLMAsset))
0979:                    return false;
0980:                GLMAsset asset = (GLMAsset) o;
0981:                if (asset.getUID() == null)
0982:                    return false;
0983:                if (!asset.getUID().toString().equals(desiredAssetUID))
0984:                    return false;
0985:                ScheduledContentPG scheduledContentPG = asset
0986:                        .getScheduledContentPG();
0987:                if (scheduledContentPG == null)
0988:                    return false;
0989:                Asset a1 = scheduledContentPG.getAsset();
0990:                if (a1 == null) {
0991:                    System.out
0992:                            .println("WARNING: no asset in scheduledContentPG");
0993:                    return false;
0994:                }
0995:                TypeIdentificationPG typeIdPG = a1.getTypeIdentificationPG();
0996:                if (typeIdPG == null) {
0997:                    System.out
0998:                            .println("WARNING: No typeIdentificationPG for asset");
0999:                    return false;
1000:                }
1001:                return true;
1002:            }
1003:
1004:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.