@Override public CatalogAccessor getCatalogAccessor() { final List<BrokerServiceAccessor> serviceAccessors = new ArrayList<>(); final String[] serviceBrokers = context.getBeanNamesForAnnotation(ServiceBroker.class); for (String serviceBrokerName : serviceBrokers) { final Object serviceBroker = context.getBean(serviceBrokerName); final Class<?> clazz = getBeanClass(serviceBrokerName); final Method method = findMethodWithAnnotation(clazz, DynamicCatalog.class); if (method != null) { validateReturnType(method, DynamicCatalog.class, Catalog.class); try { final Catalog catalog = (Catalog) invokeMethod(serviceBroker, method); for (CatalogService catalogService : catalog.getServices()) { serviceAccessors.add(getMethodAccessor(serviceBrokerName, catalogService)); } } catch (Throwable e) { LOGGER.warn("The broker (" + serviceBrokerName + ") fails to return its catalog", e); } } } return new CatalogAccessor(serviceAccessors); }
@Override public String toString() { StringBuilder res = new StringBuilder(); res.append("ReverseEngineering: ").append("\n"); if (!isBlank(catalogs)) { for (Catalog catalog : catalogs) { catalog.toString(res, " "); } } if (!isBlank(schemas)) { for (Schema schema : schemas) { schema.toString(res, " "); } } if (skipRelationshipsLoading != null && skipRelationshipsLoading) { res.append("\n").append(" Skip Relationships Loading"); } if (skipPrimaryKeyLoading != null && skipPrimaryKeyLoading) { res.append("\n").append(" Skip PrimaryKey Loading"); } return super.toString(res, " ").toString(); }
@Override public boolean execute(PlugInContext context) throws Exception { String[] res = getPlugInContext().getSelectedSources(); final Catalog geocatalog = context.getWorkbenchContext().getWorkbench().getFrame().getGeocatalog(); for (int i = 0; i < res.length; i++) { final String name = res[i]; final EditableSource s = geocatalog.getEditingSource(name); if (s.isModified()) { try { s.getDataSource().commit(); } catch (DriverException e) { ErrorMessages.error(ErrorMessages.CannotSaveSource, e); } catch (NonEditableDataSourceException e) { ErrorMessages.error(ErrorMessages.CannotSaveSource, e); } } JOptionPane.showMessageDialog( geocatalog, I18N.getString("orbisgis.org.orbisgis.core.geocatalog.sourceSaved")); } // DO NOT REMOVE // this call is needed to work around a strange Swing painting problem // when using for the first time our custom SourceListRender // to display a change in the font of a listed source geocatalog.repaint(); return true; }
/** * Add the given catalog to the catalog list if it is not already there. If a separate catalog * with the same name is in the list, the user is asked if it should be removed. */ public void addCatalog(int index, Catalog cat) { // check for duplicates int i = _catalogs.indexOf(cat); if (i != -1) { return; } // check if it is a catalog with the same name (maybe from a different config file) String name = cat.getName(); Catalog oldCat = getCatalog(name); int size = _catalogs.size(); if (oldCat != null) { int ans = DialogUtil.confirm(name + " already exists. Do you want to replace it?"); if (ans != JOptionPane.YES_OPTION) return; removeCatalog(oldCat); size--; } if (index < 0 || index >= size) _catalogs.add(cat); else _catalogs.add(index, cat); cat.setParent(this); CatalogFactory.registerCatalog(cat, isLocal()); _fireTreeNodesInserted(_getTreeModelEvent(cat)); }
public String getAbsolutePath(String path) { try { URI uri = new URI(path); if (uri.isAbsolute()) { return path; } } catch (URISyntaxException e) { } if (this.base != null && !this.base.equals("")) // $NON-NLS-1$ { return makeAbsolute(base, path); } String result = path; Catalog catalog = (Catalog) getOwnerCatalog(); if (catalog != null) { String base = catalog.getBase(); if (base == null || base.equals("")) // $NON-NLS-1$ { base = catalog.getLocation(); } result = makeAbsolute(base, path); } return result; }
public void visit(LayerInfo layer) { // first update the groups, remove the layer, and if no // other layers remained, remove the group as well for (LayerGroupInfo group : catalog.getLayerGroups()) { if (group.getLayers().contains(layer)) { // parallel remove of layer and styles int index = group.getLayers().indexOf(layer); group.getLayers().remove(index); group.getStyles().remove(index); // either update or remove the group if (group.getLayers().size() == 0) { catalog.remove(group); } else { catalog.save(group); } } } // remove the layer and (for the moment) its resource as well // TODO: change this to just remove the resource once the // resource/publish split is done ResourceInfo resource = layer.getResource(); catalog.remove(layer); catalog.remove(resource); }
public static void main(String[] args) { Catalog catalog = new Catalog(); catalog.add(new Book("Author1", "Title1", 14.55, new Date())); catalog.add(new Book("Author2", "Title2", 66, new Date())); try { File file = new File("src\\res\\output.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Catalog.class); Marshaller marshaller = jaxbContext.createMarshaller(); // читабельное форматирование marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // пишем в файл marshaller.marshal(catalog, file); marshaller.marshal(catalog, System.out); // читаем из файла Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); catalog = (Catalog) unmarshaller.unmarshal(file); System.out.println(catalog); } catch (JAXBException e) { e.printStackTrace(); } }
@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
@Test public void testDropCoverageStore() throws Exception { // build the store Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); CoverageStoreInfo store = cb.buildCoverageStore("dem"); store.setURL(MockData.class.getResource("tazdem.tiff").toExternalForm()); store.setType("GeoTIFF"); cat.add(store); // build the coverage cb.setStore(store); CoverageInfo ci = cb.buildCoverage(); cat.add(ci); // build the layer LayerInfo layer = cb.buildLayer(ci); cat.add(layer); // grab a reader just to inizialize the code ci.getGridCoverage(null, null); ci.getGridCoverageReader(null, GeoTools.getDefaultHints()); // now drop the store CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(cat); visitor.visit(store); // and reload (GEOS-4782 -> BOOM!) getGeoServer().reload(); }
@Test public void testReprojectLayerGroup() throws NoSuchAuthorityCodeException, FactoryException, Exception { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); lg.getLayers().add(l); lg.setName("test-reproject"); // Give our layer a CRS without the EPSG code defined CoordinateReferenceSystem lCrs = DefaultGeographicCRS.WGS84; ((FeatureTypeInfo) l.getResource()).setSRS(null); ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs); assertNull(CRS.lookupEpsgCode(lCrs, false)); // EPSG:4326 should have an EPSG code CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4326"); assertNotNull(CRS.lookupEpsgCode(lgCrs, false)); // Reproject our layer group to EPSG:4326. We expect it to have an EPSG code. cb.calculateLayerGroupBounds(lg, lgCrs); assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false)); }
/** Return the named catalog, if found in this directory */ public Catalog getCatalog(String catalogName) { int n = getNumCatalogs(); for (int i = 0; i < n; i++) { Catalog cat = getCatalog(i); if (catalogName.equals(cat.getName()) || catalogName.equals(cat.getId())) return cat; } return null; }
/** Set the list of catalogs in this catalog directory. */ public void setCatalogs(List catalogs) { _catalogs = catalogs; int n = _catalogs.size(); for (int i = 0; i < n; i++) { Catalog cat = (Catalog) _catalogs.get(i); cat.setParent(this); CatalogFactory.registerCatalog(cat, isLocal()); } _fireTreeStructureChanged(_getTreeModelEvent(this)); }
/** * Removes the named item from the cart * * @param itemName Name of item to remove */ public void removeItems(String itemCode) { Catalog catalog = new Catalog(); // Check for item in catalog based on item code if (catalog.containsItem(itemCode)) { // Check if item is already in the cart if (contents.containsKey(itemCode)) { // remove the subscribed feed contents.remove(itemCode); } } }
void visitStore(StoreInfo store) { // drill down into layers (into resources since we cannot scan layers) List<ResourceInfo> resources = catalog.getResourcesByStore(store, ResourceInfo.class); for (ResourceInfo ri : resources) { List<LayerInfo> layers = catalog.getLayers(ri); for (LayerInfo li : layers) { li.accept(this); } } catalog.remove(store); }
public MockCatalogBuilder coverageStore(String name, String filename, String format) { String csId = newId(); WorkspaceInfo ws = workspaces.peekLast(); NamespaceInfo ns = namespaces.peekLast(); final CoverageStoreInfo cs = createNiceMock(CoverageStoreInfo.class); coverageStores.add(cs); initStore(cs, CoverageStoreInfo.class, csId, name, ws); File covDir = new File(dataDirRoot, name); final File covFile = new File(covDir, filename); expect(cs.getURL()).andReturn(DataUtilities.fileToURL(covFile).toString()).anyTimes(); expect(cs.getType()) .andAnswer( new IAnswer<String>() { @Override public String answer() throws Throwable { return lookupGridFormat(covFile).getName(); } }) .anyTimes(); expect(cs.getFormat()) .andAnswer( new IAnswer<AbstractGridFormat>() { @Override public AbstractGridFormat answer() throws Throwable { return lookupGridFormat(covFile); } }) .anyTimes(); expect(cs.getConnectionParameters()).andReturn(new HashMap()).anyTimes(); expect(catalog.getCoverageStore(csId)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(name)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(ws.getName(), name)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(ws, name)).andReturn(cs).anyTimes(); cs.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(cs); } }) .anyTimes(); callback.onStore(name, cs, ws, this); replay(cs); return this; }
/** * Adds a named item to the cart * * @param itemName The name of the item to add to the cart */ public void addItem(String itemCode) { Catalog catalog = new Catalog(); // Check for item in catalog based on item code if (catalog.containsItem(itemCode)) { Item item = catalog.getItem(itemCode); // Add the item code and item to the contents map if (!contents.containsKey(itemCode)) { contents.put(itemCode, item); } } }
public MockCatalogBuilder workspace(String name, String uri) { String wsId = newId(); String nsId = newId(); final WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); workspaces.add(ws); expect(ws.getId()).andReturn(wsId).anyTimes(); expect(ws.getName()).andReturn(name).anyTimes(); expect(ws.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getWorkspace(wsId)).andReturn(ws).anyTimes(); expect(catalog.getWorkspaceByName(name)).andReturn(ws).anyTimes(); final NamespaceInfo ns = createNiceMock(NamespaceInfo.class); namespaces.add(ns); expect(ns.getId()).andReturn(nsId).anyTimes(); expect(ns.getName()).andReturn(name).anyTimes(); expect(ns.getPrefix()).andReturn(name).anyTimes(); expect(ns.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getNamespace(nsId)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByPrefix(name)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByURI(uri)).andReturn(ns).anyTimes(); ws.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ws); } }) .anyTimes(); ns.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ns); } }) .anyTimes(); callback.onWorkspace(name, ws, this); replay(ws, ns); return this; }
public MockCatalogBuilder dataStore(String name) { String dsId = newId(); final WorkspaceInfo ws = workspaces.peekLast(); final NamespaceInfo ns = namespaces.peekLast(); final DataStoreInfo ds = createNiceMock(DataStoreInfo.class); dataStores.add(ds); initStore(ds, DataStoreInfo.class, dsId, name, ws); // setup the property data store final File propDir = new File(dataDirRoot, name); HashMap cxParams = new HashMap(); cxParams.put(PropertyDataStoreFactory.DIRECTORY.key, propDir); cxParams.put(PropertyDataStoreFactory.NAMESPACE.key, ns.getURI()); expect(ds.getConnectionParameters()).andReturn(cxParams).anyTimes(); try { expect(ds.getDataStore(null)) .andAnswer( (IAnswer) new IAnswer<DataAccess>() { @Override public DataAccess answer() throws Throwable { return new PropertyDataStore(propDir, ns.getURI()); } }) .anyTimes(); } catch (IOException e) { } expect(catalog.getDataStore(dsId)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws.getName(), name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws, name)).andReturn(ds).anyTimes(); ds.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ds); } }) .anyTimes(); callback.onStore(name, ds, ws, this); replay(ds); return this; }
/* *@param itemcode *@returns feed url associated with itemcode */ public String fetchURL(String itemCode) { Catalog catalog = new Catalog(); // Check for item in catalog based on item code if (catalog.containsItem(itemCode)) { // Check if item is already in the cart if (contents.containsKey(itemCode)) { // remove the subscribed feed Item item = contents.get(itemCode); return item.getUrl(); } } return null; }
public void visit(WorkspaceInfo workspace) { // remove owned stores for (StoreInfo s : catalog.getStoresByWorkspace(workspace, StoreInfo.class)) { s.accept(this); } // remove any linked namespaces NamespaceInfo ns = catalog.getNamespaceByPrefix(workspace.getName()); if (ns != null) { ns.accept(this); } catalog.remove(workspace); }
/** * Utility method for getting or creating a format as appropriate for bindings and key creators. */ static Format getOrCreateFormat(Catalog useCatalog, String clsName, boolean rawAccess) throws RefreshException { if (rawAccess) { Format format = useCatalog.getFormat(clsName); if (format == null) { throw new IllegalArgumentException("Not a persistent class: " + clsName); } return format; } else { Class cls = useCatalog.resolveKeyClass(clsName); return useCatalog.getFormat(cls, true /*checkEntitySubclassIndexes*/); } }
@Test public void testConfigureFeatureTypeCacheSize() { GeoServer gs = getGeoServer(); GeoServerInfo global = gs.getGlobal(); global.setFeatureTypeCacheSize(200); gs.save(global); Catalog catalog = getCatalog(); // we actually keep two versions of the feature type in the cache, so we need it // twice as big assertEquals( 400, ((SoftValueHashMap) catalog.getResourcePool().getFeatureTypeCache()) .getHardReferencesCount()); }
static Format checkRawType(Catalog catalog, Object o, Format declaredFormat) { assert declaredFormat != null; Format format; if (o instanceof RawObject) { format = (Format) ((RawObject) o).getType(); } else { format = catalog.getFormat(o.getClass()); if (!format.isSimple() || format.isEnum()) { throw new IllegalArgumentException( "Not a RawObject or a non-enum simple type: " + format.getClassName()); } } if (!format.isAssignableTo(declaredFormat)) { throw new IllegalArgumentException( "Not a subtype of the field's declared class " + declaredFormat.getClassName() + ": " + format.getClassName()); } if (!format.isCurrentVersion()) { throw new IllegalArgumentException( "Raw type version is not current. Class: " + format.getClassName() + " Version: " + format.getVersion()); } Format proxiedFormat = format.getProxiedFormat(); if (proxiedFormat != null) { format = proxiedFormat; } return format; }
private void removeStyleInLayer(LayerInfo layer, StyleInfo style) { boolean dirty = false; // remove it from the associated styles if (layer.getStyles().remove(style)) { dirty = true; } // if it's the default style, choose an associated style or reset it to the default one StyleInfo ds = layer.getDefaultStyle(); if (ds != null && ds.equals(style)) { dirty = true; StyleInfo newDefaultStyle; if (layer.getStyles().size() > 0) { newDefaultStyle = layer.getStyles().iterator().next(); layer.getStyles().remove(newDefaultStyle); } else { newDefaultStyle = getResourceDefaultStyle(layer.getResource(), style); } layer.setDefaultStyle(newDefaultStyle); } if (dirty) { catalog.save(layer); } }
public MockCatalogBuilder layerGroup( String name, List<String> layerNames, List<String> styleNames) { final LayerGroupInfo lg = createMock(LayerGroupInfo.class); layerGroups.add(lg); expect(lg.getId()).andReturn(newId()).anyTimes(); expect(lg.getName()).andReturn(name).anyTimes(); List<PublishedInfo> grpLayers = new ArrayList<PublishedInfo>(); List<StyleInfo> grpStyles = new ArrayList<StyleInfo>(); for (int i = 0; i < layerNames.size(); i++) { String layerName = layerNames.get(i); LayerInfo l = null; for (LayerInfo layer : layers) { if (layerName.equals(layer.getName())) { l = layer; break; } } if (l == null) { throw new RuntimeException("No such layer: " + layerName); } grpLayers.add(l); StyleInfo s = null; if (styleNames != null) { String styleName = styleNames.get(i); for (StyleInfo style : styles) { if (styleName.equals(style.getName())) { s = style; break; } } } grpStyles.add(s); } expect(lg.getLayers()).andReturn(grpLayers).anyTimes(); expect(lg.getStyles()).andReturn(grpStyles).anyTimes(); lg.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(lg); } }) .anyTimes(); expect(catalog.getLayerGroupByName(name)).andReturn(lg).anyTimes(); callback.onLayerGroup(name, lg, this); replay(lg); return this; }
private void removeStyleInLayerGroup(LayerGroupInfo group, StyleInfo style) { boolean dirty = false; // root layer style if (style.equals(group.getRootLayerStyle())) { group.setRootLayerStyle(getResourceDefaultStyle(group.getRootLayer().getResource(), style)); dirty = true; } // layer styles List<StyleInfo> styles = group.getStyles(); for (int i = 0; i < styles.size(); i++) { StyleInfo publishedStyle = styles.get(i); if (publishedStyle != null && publishedStyle.equals(style)) { // if publishedStyle is not null, we have a layer LayerInfo layer = (LayerInfo) group.getLayers().get(i); if (!layer.getDefaultStyle().equals(style)) { // use default style styles.set(i, layer.getDefaultStyle()); } else { styles.set(i, getResourceDefaultStyle(layer.getResource(), style)); } dirty = true; } } if (dirty) { catalog.save(group); } }
public void visit(StyleInfo style) { // remove style references in layers List<LayerInfo> layers = catalog.getLayers(); for (LayerInfo layer : layers) { removeStyleInLayer(layer, style); } // groups can also refer to style, reset each reference to the // associated layer default style List<LayerGroupInfo> groups = catalog.getLayerGroups(); for (LayerGroupInfo group : groups) { removeStyleInLayerGroup(group, style); } // finally remove the style catalog.remove(style); }
public void visit(LayerGroupInfo layerGroupToRemove) { // remove layerGroupToRemove references from other groups List<LayerGroupInfo> groups = catalog.getLayerGroups(); for (LayerGroupInfo group : groups) { if (group.getLayers().remove(layerGroupToRemove)) { if (group.getLayers().size() == 0) { // if group is empty, delete it visit(group); } else { catalog.save(group); } } } // finally remove the group catalog.remove(layerGroupToRemove); }
void visitStore(StoreInfo store) { // drill down into layers (into resources since we cannot scan layers) List<ResourceInfo> resources = catalog.getResourcesByStore(store, ResourceInfo.class); for (ResourceInfo ri : resources) { List<LayerInfo> layers = catalog.getLayers(ri); if (!layers.isEmpty()) { for (LayerInfo li : layers) { li.accept(this); } } else { // no layers for the resource, delete directly ri.accept(this); } } catalog.remove(store); }
private void handleScanOfValidBarcode(final String barcode) { try { Product catalogProduct = catalog.get(barcode); displayPrice(catalogProduct); } catch (InvalidProductException e) { displayPriceNotFound(String.format(PRODUCT_NOT_FOUND_MESSAGE, barcode)); } }