Package com.opengamma.core.region

Examples of com.opengamma.core.region.Region


          security = position.getSecurityLink().resolve(_secSource);
        }
        ExternalId id = FinancialSecurityUtils.getRegion(security);
        if (_regionSource != null) {
          if (id != null) {
            Region highestLevelRegion = _regionSource.getHighestLevelRegion(id);
            if (highestLevelRegion != null) {
              return highestLevelRegion.getName();
            } else {
              return id.getValue();
            }
          } else if (_exchangeSource != null) {
            ExternalId exchangeId = FinancialSecurityUtils.getExchange(security);
            if (exchangeId != null) {
              Exchange exchange = _exchangeSource.getSingle(exchangeId);
              if (exchange == null) {
                s_logger.info("No exchange could be found with ID {}", exchangeId);
                return NO_REGION;
              }
              if (exchange.getRegionIdBundle() == null) {
                s_logger.info("Exchange " + exchange.getName() + " region bundle was null");
                return NO_REGION;
              }
              Region highestLevelRegion = _regionSource.getHighestLevelRegion(exchange.getRegionIdBundle());
              if (s_specialCountriesRegions.contains(highestLevelRegion.getName())) {
                return highestLevelRegion.getName();
              } else {
                Set<UniqueId> parentRegionIds = highestLevelRegion.getParentRegionIds();
                s_logger.info("got " + highestLevelRegion + ", looking for parent");
                String parent = findTopLevelRegion(parentRegionIds);
                s_logger.info("parent was " + parent);
                return parent;
              }
View Full Code Here


    }
  }
 
  private String findTopLevelRegion(Set<?> parentRegions) {
    for (Object parentRegion : parentRegions) {
      Region region;
      if (parentRegion instanceof String) {
        region = _regionSource.get(UniqueId.parse((String) parentRegion));
      } else {
        region = _regionSource.get((UniqueId) parentRegion);
      }
      if (region != null) {
        if (s_topLevelRegions.contains(region.getName())) {
          return region.getName();
        }
      }
    }
    return OTHER;
  }
View Full Code Here

      for (final String region : regions) {
        resultRegions.add(regionSource.getHighestLevelRegion(ExternalSchemes.financialRegionId(region)));
      }
      return new HolidaySourceCalendarAdapter(holidaySource, resultRegions.toArray(new Region[] {}));
    }
    final Region region = regionSource.getHighestLevelRegion(regionId); // we've checked that they are the same.
    return new HolidaySourceCalendarAdapter(holidaySource, region);
  }
View Full Code Here

      @QueryParam("version") String version,
      @QueryParam("versionAsOf") String versionAsOf,
      @QueryParam("correctedTo") String correctedTo) {
    final ObjectId objectId = ObjectId.parse(idStr);
    if (version != null) {
      final Region result = getRegionSource().get(objectId.atVersion(version));
      return responseOkFudge(result);
    } else {
      final VersionCorrection vc = VersionCorrection.parse(versionAsOf, correctedTo);
      Region result = getRegionSource().get(objectId, vc);
      return responseOkFudge(result);
    }
  }
View Full Code Here

  //-------------------------------------------------------------------------
  @GET
  @Path("regionSearches/highest")
  public Response searchHighest(@QueryParam("id") List<String> externalIdStrs) {
    final ExternalIdBundle bundle = ExternalIdBundle.parse(externalIdStrs);
    Region result = getRegionSource().getHighestLevelRegion(bundle);
    return responseOkFudge(result);
  }
View Full Code Here

    return getHighestLevelRegion(ExternalIdBundle.of(externalId));
  }

  @Override
  public Region getHighestLevelRegion(ExternalIdBundle bundle) {
    Region result = null;
    Element element = _cache.get(bundle);
    if (element != null) {
      s_logger.debug("Cache hit on {}", bundle);
      result = (Region) element.getObjectValue();
    } else {
      s_logger.debug("Cache miss on {}", bundle);
      result = getUnderlying().getHighestLevelRegion(bundle);
      s_logger.debug("Caching regions {}", result);
      element = new Element(bundle, result);
      _cache.put(element);
      if (result != null) {
        _cache.put(new Element(result.getUniqueId(), result));
      }
    }
    return result;
  }
View Full Code Here

  private Region getRef() {
    return getRegionSource().getHighestLevelRegion(ExternalSchemes.countryRegionId(Country.GB));
  }

  public void testCycle() {
    final Region ref = getRef();
    final Region cycledRef = cycleObject(Region.class, ref);
    s_logger.info("pre = " + ref);
    s_logger.info("post=" + cycledRef);
    assertEquals(ref, cycledRef);
  }
View Full Code Here

    }

    @Override
    public Region get(final ObjectId objectId, final VersionCorrection versionCorrection) {
      _count.getAndIncrement();
      Region result = null;
      if (_testRegion.getUniqueId().getObjectId().equals(objectId) && versionCorrection.equals(VersionCorrection.LATEST)) {
        result = _testRegion;
      }
      return result;
    }
View Full Code Here

    }

    @Override
    public Region get(final UniqueId uniqueId) {
      _count.getAndIncrement();
      Region result = null;
      if (_testRegion.getUniqueId().equals(uniqueId)) {
        result = _testRegion;
      }
      return result;
    }
View Full Code Here

    }

    @Override
    public Region getHighestLevelRegion(final ExternalIdBundle bundle) {
      _count.getAndIncrement();
      Region result = null;
      if (_testRegion.getExternalIdBundle().equals(bundle)) {
        result = _testRegion;
      }
      return result;
    }
View Full Code Here

TOP

Related Classes of com.opengamma.core.region.Region

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.