Exemplo n.º 1
0
  public void onPostLoad(PostLoadEvent event) {
    if (!active) return;

    Object entity = event.getEntity();

    if (entity instanceof StoreInfoImpl) {
      ((StoreInfoImpl) entity).setCatalog(catalog);
    } else if (entity instanceof ResourceInfoImpl) {
      ((ResourceInfoImpl) entity).setCatalog(catalog);
    } else if (entity instanceof StyleInfoImpl) {
      ((StyleInfoImpl) entity).setCatalog(catalog);
    } else if (entity instanceof LayerGroupInfoImpl) {
      // hack to get around default styles being represented by null
      // TODO: see if we can coax the hibernate mappings into doing this for us
      LayerGroupInfoImpl lg = (LayerGroupInfoImpl) entity;
      if (lg.getStyles().isEmpty()) {
        for (LayerInfo l : lg.getLayers()) {
          lg.getStyles().add(null);
        }
      }
    } else if (entity instanceof ServiceInfoImpl) {
      ((ServiceInfoImpl) entity).setGeoServer(geoServer);
    } else if (entity instanceof GeoServerInfoImpl) {
      // contact is mapped as a component... and hibernate assumes that all null values
      // means a null object... i don't think this is configurable but coudl be wrong
      GeoServerInfoImpl global = (GeoServerInfoImpl) entity;
      if (global.getContact() == null) {
        global.setContact(geoServer.getFactory().createContact());
      }
    }
  }
  @Test
  public void testModifyService() throws Exception {
    ServiceInfo service = geoServer.getFactory().createService();
    ((ServiceInfoImpl) service).setId("id");
    service.setName("foo");
    service.setTitle("bar");
    service.setMaintainer("quux");

    geoServer.add(service);

    ServiceInfo s1 = geoServer.getServiceByName("foo", ServiceInfo.class);
    s1.setMaintainer("quam");

    ServiceInfo s2 = geoServer.getServiceByName("foo", ServiceInfo.class);
    assertEquals("quux", s2.getMaintainer());

    geoServer.save(s1);
    s2 = geoServer.getServiceByName("foo", ServiceInfo.class);
    assertEquals("quam", s2.getMaintainer());
  }