Esempio n. 1
0
  private long _getCompanyIdByVirtualHosts(HttpServletRequest request) {
    String host = PortalUtil.getHost(request);

    if (_log.isDebugEnabled()) {
      _log.debug("Host " + host);
    }

    if (Validator.isNull(host) || _isVirtualHostsIgnoreHost(host)) {
      return 0;
    }

    try {
      VirtualHost virtualHost = VirtualHostLocalServiceUtil.fetchVirtualHost(host);

      if (virtualHost == null) {
        return 0;
      }

      if (virtualHost.getLayoutSetId() != 0) {
        LayoutSet layoutSet = null;

        try {
          ShardUtil.pushCompanyService(virtualHost.getCompanyId());

          layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(virtualHost.getLayoutSetId());
        } finally {
          ShardUtil.popCompanyService();
        }

        if (_log.isDebugEnabled()) {
          _log.debug(
              "Company "
                  + virtualHost.getCompanyId()
                  + " is associated with layout set "
                  + virtualHost.getLayoutSetId());
        }

        request.setAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET, layoutSet);
      }

      return virtualHost.getCompanyId();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return 0;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    VirtualHost newVirtualHost = _persistence.create(pk);

    newVirtualHost.setMvccVersion(ServiceTestUtil.nextLong());

    newVirtualHost.setCompanyId(ServiceTestUtil.nextLong());

    newVirtualHost.setLayoutSetId(ServiceTestUtil.nextLong());

    newVirtualHost.setHostname(ServiceTestUtil.randomString());

    _persistence.update(newVirtualHost);

    VirtualHost existingVirtualHost = _persistence.findByPrimaryKey(newVirtualHost.getPrimaryKey());

    Assert.assertEquals(existingVirtualHost.getMvccVersion(), newVirtualHost.getMvccVersion());
    Assert.assertEquals(existingVirtualHost.getVirtualHostId(), newVirtualHost.getVirtualHostId());
    Assert.assertEquals(existingVirtualHost.getCompanyId(), newVirtualHost.getCompanyId());
    Assert.assertEquals(existingVirtualHost.getLayoutSetId(), newVirtualHost.getLayoutSetId());
    Assert.assertEquals(existingVirtualHost.getHostname(), newVirtualHost.getHostname());
  }