Example #1
0
  public MockCatalogBuilder coverage(QName qName, String fileName, String srs, Class scope) {
    scope = scope != null ? scope : getClass();

    String cId = newId();
    final CoverageStoreInfo cs = coverageStores.peekLast();
    NamespaceInfo ns = namespaces.peekLast();

    final String name = qName.getLocalPart();
    File dir = new File(dataDirRoot, name);
    dir.mkdir();

    try {
      IOUtils.copy(scope.getResourceAsStream(fileName), new File(dir, fileName));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    // initialize the mock by actually building a real one first
    CatalogBuilder cb = new CatalogBuilder(new CatalogImpl());
    cb.setStore(cs);

    GridCoverage2DReader reader = cs.getFormat().getReader(cs.getURL());
    if (reader == null) {
      throw new RuntimeException("No reader for " + cs.getURL());
    }

    CoverageInfo real = null;
    try {
      real = cb.buildCoverage(reader, null);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    final CoverageInfo c = createNiceMock(CoverageInfo.class);
    coverages.add(c);
    final List<CoverageInfo> coverageList = coverages;

    if (srs == null) {
      srs = real.getSRS();
    }
    initResource(
        c,
        CoverageInfo.class,
        cId,
        name,
        cs,
        ns,
        srs,
        real.getProjectionPolicy(),
        real.getNativeBoundingBox(),
        real.getLatLonBoundingBox());

    expect(c.getDefaultInterpolationMethod())
        .andReturn(real.getDefaultInterpolationMethod())
        .anyTimes();
    expect(c.getDimensions()).andReturn(real.getDimensions()).anyTimes();
    expect(c.getGrid()).andReturn(real.getGrid()).anyTimes();

    expect(c.getInterpolationMethods()).andReturn(real.getInterpolationMethods()).anyTimes();
    expect(c.getRequestSRS()).andReturn(real.getRequestSRS()).anyTimes();
    expect(c.getResponseSRS()).andReturn(real.getResponseSRS()).anyTimes();

    try {
      expect(c.getGridCoverageReader(null, null)).andReturn(reader).anyTimes();
    } catch (IOException e) {
    }

    expect(catalog.getCoverageByName(or(eq(name), eq(ns.getPrefix() + ":" + name))))
        .andReturn(c)
        .anyTimes();
    expect(
            catalog.getCoverageByName(
                or(eq(new NameImpl(ns.getPrefix(), name)), eq(new NameImpl(ns.getURI(), name)))))
        .andReturn(c)
        .anyTimes();
    expect(catalog.getCoverageByName(ns, name)).andReturn(c).anyTimes();

    expect(catalog.getCoverageByName(ns.getPrefix(), name)).andReturn(c).anyTimes();
    // expect(catalog.getFeatureTypeByName(or(eq(ns.getPrefix()), eq(ns.getURI())), name))
    //    .andReturn(ft).anyTimes();

    // expect(catalog.getCoverageByStore(cs, name)).andReturn(c).anyTimes();
    expect(catalog.getCoveragesByStore(cs)).andReturn(coverageList).anyTimes();
    expect(catalog.getCoverageByCoverageStore(cs, name)).andReturn(c).anyTimes();

    c.accept((CatalogVisitor) anyObject());
    expectLastCall()
        .andAnswer(
            new VisitAnswer() {
              @Override
              protected void doVisit(CatalogVisitor visitor) {
                visitor.visit(c);
              }
            })
        .anyTimes();

    callback.onResource(name, c, cs, this);
    replay(c, createLayer(c, name, ns));
    return this;
  }
Example #2
0
  public WCSLayerConfig(String id, IModel model) {
    super(id, model);

    final CoverageInfo coverage = (CoverageInfo) getLayerInfo().getResource();
    add(
        new ListMultipleChoice(
            "requestSRS",
            new PropertyModel(this, "selectedRequestSRSs"),
            coverage.getRequestSRS()));

    add(new TextField("newRequestSRS", new PropertyModel(this, "newRequestSRS")));

    add(
        new Button("deleteSelectedRequestSRSs") {
          public void onSubmit() {
            coverage.getRequestSRS().removeAll(selectedRequestSRSs);
            selectedRequestSRSs.clear();
          }
        });

    add(
        new Button("addNewRequestSRS") {
          public void onSubmit() {
            coverage.getRequestSRS().add(newRequestSRS);
            newRequestSRS = "";
          }
        });

    add(
        new ListMultipleChoice(
            "responseSRS",
            new PropertyModel(this, "selectedResponseSRSs"),
            coverage.getResponseSRS()));

    add(new TextField("newResponseSRS", new PropertyModel(this, "newResponseSRS")));

    add(
        new Button("deleteSelectedResponseSRSs") {
          public void onSubmit() {
            coverage.getResponseSRS().removeAll(selectedResponseSRSs);
            selectedResponseSRSs.clear();
          }
        });

    add(
        new Button("addNewResponseSRS") {
          public void onSubmit() {
            coverage.getResponseSRS().add(newResponseSRS);
            newResponseSRS = "";
          }
        });

    add(
        new DropDownChoice(
            "defaultInterpolationMethod",
            new PropertyModel(coverage, "defaultInterpolationMethod"),
            new WCSInterpolationModel()));

    Palette interpolationMethods =
        new Palette(
            "interpolationMethods",
            LiveCollectionModel.list(new PropertyModel(coverage, "interpolationMethods")),
            new WCSInterpolationModel(),
            new SimpleChoiceRenderer(),
            7,
            false) {
          /** Override otherwise the header is not i18n'ized */
          @Override
          public Component newSelectedHeader(final String componentId) {
            return new Label(
                componentId, new ResourceModel("InterpolationMethodsPalette.selectedHeader"));
          }

          /** Override otherwise the header is not i18n'ized */
          @Override
          public Component newAvailableHeader(final String componentId) {
            return new Label(
                componentId, new ResourceModel("InterpolationMethodsPalette.availableHeader"));
          }
        };
    add(interpolationMethods);

    // don't allow editing the native format
    TextField nativeFormat =
        new TextField("nativeFormat", new PropertyModel(coverage, "nativeFormat"));
    nativeFormat.setEnabled(false);
    add(nativeFormat);

    Palette formatPalette =
        new Palette(
            "formatPalette",
            LiveCollectionModel.list(new PropertyModel(coverage, "supportedFormats")),
            new WCSFormatsModel(),
            new SimpleChoiceRenderer(),
            10,
            false) {
          /** Override otherwise the header is not i18n'ized */
          @Override
          public Component newSelectedHeader(final String componentId) {
            return new Label(componentId, new ResourceModel("FormatsPalette.selectedHeader"));
          }

          /** Override otherwise the header is not i18n'ized */
          @Override
          public Component newAvailableHeader(final String componentId) {
            return new Label(componentId, new ResourceModel("FormatsPalette.availableHeader"));
          }
        };
    add(formatPalette);
  }