Beispiel #1
0
 // -------------------------------------------------------------------------
 @Override
 public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) {
   ToolContext context = createToolContext();
   Map<String, MetaProperty<?>> mapTarget =
       new HashMap<String, MetaProperty<?>>(context.metaBean().metaPropertyMap());
   mapTarget.keySet().retainAll(this.metaBean().metaPropertyMap().keySet());
   for (MetaProperty<?> mp : mapTarget.values()) {
     mp.set(context, property(mp.name()).get());
   }
   context.setContextManager(repo);
   repo.registerInfrastructure(ToolContext.class, getClassifier(), context);
 }
 private void validateComponentsInToolContext(ToolContext toolContext) {
   if (toolContext.getViewProcessor() == null) {
     throw new OpenGammaRuntimeException("Missing view processor in given toolcontext");
   }
   if (toolContext.getSecuritySource() == null) {
     throw new OpenGammaRuntimeException("Missing security source in given toolcontext");
   }
   if (toolContext.getConfigMaster() == null) {
     throw new OpenGammaRuntimeException("Missing config master in given toolcontext");
   }
   if (toolContext.getPositionSource() == null) {
     throw new OpenGammaRuntimeException("Missing position source in given toolcontext");
   }
 }
 // -------------------------------------------------------------------------
 @Override
 protected void doRun() {
   ToolContext toolContext = getToolContext();
   CommandLine commandLine = getCommandLine();
   boolean verbose = commandLine.hasOption("verbose");
   if ((commandLine.hasOption("today") && commandLine.hasOption("yesterday"))
       || (commandLine.hasOption("date") && commandLine.hasOption("today"))
       || (commandLine.hasOption("date") && commandLine.hasOption("yesterday"))) {
     System.err.println("Can only return today OR yesterday OR date!");
     System.exit(2);
   }
   String ccyStr = commandLine.getOptionValue("ccy");
   try {
     Currency ccy = Currency.of(ccyStr);
     LocalDate date = null;
     if (commandLine.hasOption("yesterday")) {
       date = LocalDate.now().minusDays(1);
     } else if (commandLine.hasOption("today")) {
       date = LocalDate.now();
     } else if (commandLine.hasOption("date")) {
       try {
         date =
             (LocalDate)
                 DateTimeFormatter.BASIC_ISO_DATE.parse(commandLine.getOptionValue("date"));
       } catch (Exception e) {
         System.err.println("Could not parse date, should be YYYYMMDD format");
         System.exit(2);
       }
     } else {
       System.err.println("Must specify either today or yesterday option");
       System.exit(2);
     }
     boolean isHoliday = toolContext.getHolidaySource().isHoliday(date, ccy);
     if (isHoliday) {
       if (verbose) {
         System.out.println("Day was a holiday");
       }
       System.exit(0);
     } else {
       if (verbose) {
         System.out.println("Day was not a holiday");
       }
       System.exit(1);
     }
   } catch (IllegalArgumentException iae) {
     System.err.println("Invalid currency code");
     System.exit(2);
   }
 }
  private Map<String, Collection<String>> scanValueRequirementBySecType(
      UniqueId portfolioId, ToolContext toolContext) {
    AvailableOutputsProvider availableOutputsProvider = toolContext.getAvaliableOutputsProvider();
    if (availableOutputsProvider == null) {
      throw new OpenGammaRuntimeException("AvailableOutputsProvider missing from ToolContext");
    }
    final SetMultimap<String, String> valueNamesBySecurityType = TreeMultimap.create();

    AvailableOutputs portfolioOutputs =
        availableOutputsProvider.getPortfolioOutputs(portfolioId, null);
    Set<String> securityTypes = portfolioOutputs.getSecurityTypes();
    for (String securityType : securityTypes) {
      Set<AvailableOutput> positionOutputs = portfolioOutputs.getPositionOutputs(securityType);
      for (AvailableOutput availableOutput : positionOutputs) {
        valueNamesBySecurityType.put(securityType, availableOutput.getValueName());
      }
    }
    return valueNamesBySecurityType.asMap();
  }