private void writeEntries() { if(logger.isDebugEnabled()) { logger.debug("Catalog must be modified - writing new data"); } for(URI webLocation : webLocationToFileLocationMap.keySet()) { Collection<URI> physicalLocations = webLocationToFileLocationMap.get(webLocation); if(physicalLocations.size() > 1 && !isIgnored(webLocation)) { writeEntries(appendScheme(webLocation, CatalogEntryManager.DUPLICATE_SCHEME), physicalLocations); } else { writeEntries(webLocation, physicalLocations); } } }
public boolean update(Entry entry) { this.ge = (GroupEntry) entry; reset(); ensureLatestVersion(); try { if (logger.isDebugEnabled()) { logger.debug("********************************* Starting Catalog Update ************************************************"); logger.debug("Update of group entry " + ge.getId() + " started at " + new Date(timeOfCurrentUpdate)); } retainEntries(); examineDiskEntries(folder, new HashSet<URI>()); if (modified) { clearEntries(); writeEntries(); } if (logger.isDebugEnabled()) { logger.debug("********************************* Catalog Update Complete ************************************************"); } return modified; } finally { this.ge = null; reset(); } }
public boolean initializeCatalog(File folder, XMLCatalog catalog) throws IOException { URI relativeFolderUri = CatalogUtilities.relativize(folder.toURI(), catalog); ge = FolderGroupManager.createGroupEntry(relativeFolderUri, true, autoUpdate, catalog); catalog.addEntry(ge); update(ge); return true; }
private void recordEntries(Collection<URI> webLocations, URI physicalLocation, Set<URI> webLocationsFoundInParentDirectory, Set<URI> newWebLocations) { for (URI webLocation : webLocations) { if (!webLocationsFoundInParentDirectory.contains(webLocation)) { newWebLocations.add(webLocation); recordEntry(webLocation, physicalLocation); } else { recordEntry(appendScheme(webLocation, CatalogEntryManager.SHADOWED_SCHEME), physicalLocation); } } }
public boolean update(Entry entry) { this.ge = (GroupEntry) entry; reset(); ensureLatestVersion(); try { logger.debug("********************************* Starting Catalog Update ************************************************"); logger.debug("Update of group entry {} started at {}.", ge.getId(), new Date(timeOfCurrentUpdate)); retainEntries(); examineDirectoryContents(folder, new HashSet<>()); if (modified) { clearEntries(); writeEntries(); } logger.debug("********************************* Catalog Update Complete ************************************************"); return modified; } finally { this.ge = null; reset(); } }
private void ensureLatestVersion() { int version = LibraryUtilities.getVersion(ge); if (version < CURRENT_VERSION) { boolean autoUpdate = LibraryUtilities.getBooleanProperty(ge, LibraryUtilities.AUTO_UPDATE_PROP, this.autoUpdate); ge.setId(getIdString(getIdPrefix(), folder.toURI(), recursive, autoUpdate)); clearEntries(); } }
&& isValidOWLFile(physicalLocation)) { if (logger.isDebugEnabled()) { logger.debug("Applying algorithms to " + physicalLocation); logger.debug("Adding mappings retained from previous version of the catalog"); recordEntries(retainedSuggestions, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); Set<URI> webLocations = algorithm.getSuggestions(physicalLocation); modified = modified || !webLocations.isEmpty(); recordEntries(webLocations, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); examineDiskEntries(physicalLocation, webLocationsFoundInParentDirectory);
public String getDescription(Entry ge) { StringBuilder sb = new StringBuilder("<html><body><b>Folder "); sb.append(getDirectory((GroupEntry) ge)); sb.append("</b>"); if(LibraryUtilities.getBooleanProperty(ge, RECURSIVE_PROP, true)) { sb.append(" <font color=\"gray\">(includes sub-folders)</font>"); } sb.append("</body></html>"); return sb.toString(); }
public boolean isSuitable(Entry entry) { if(!(entry instanceof GroupEntry)) { return false; } GroupEntry ge = (GroupEntry) entry; File dir = getDirectory(ge); boolean enabled = LibraryUtilities.getBooleanProperty(ge, LibraryUtilities.AUTO_UPDATE_PROP, false); boolean hasRightType = ge.getId() != null && ge.getId().startsWith(getIdPrefix()) && enabled && dir != null; if(hasRightType && (!dir.exists() || !dir.isDirectory())) { logger.warn("Folder repository probably came from another system"); logger.warn("Could not be updated because directory " + dir + " does not exist"); if(!warnedUserOfBadRepositoryDeclaration) { logger.error("Bad ontology library declaration - check logs. Warnings now disabled for this session."); warnedUserOfBadRepositoryDeclaration = true; } return false; } return hasRightType; }
private void ensureLatestVersion() { int version = LibraryUtilities.getVersion(ge); if (version < CURRENT_VERSION) { boolean autoUpdate = LibraryUtilities.getBooleanProperty(ge, LibraryUtilities.AUTO_UPDATE_PROP, this.autoUpdate); ge.setId(getIdString(folder.toURI(), recursive, autoUpdate)); clearEntries(); } }
return; logger.info("{} Examining: {}", pad(depth), directory.getAbsolutePath()); Set<URI> newWebLocations = new HashSet<>(); if(algorithms == null || algorithms.isEmpty()) { if(isValidOWLFile(physicalLocation)) { examineSingleFile(physicalLocation, webLocationsFoundInParentDirectory, newWebLocations); examineDirectoryContents(physicalLocation, webLocationsFoundInParentDirectory, nonOwlFiles, depth + 1);
protected static String getIdString(String idPrefix, URI folderUri, boolean recursive, boolean autoUpdate) { return getIdString(idPrefix, folderUri.toString(), recursive, autoUpdate); }
private void examineDirectoryContents(File directory, Set<URI> webLocationsFoundInParentDirectory) { Set<URI> newWebLocations = new HashSet<>(); if (algorithms == null || algorithms.isEmpty() || directory == null) { return; } Set<File> subFolders = new HashSet<>(); File[] directoryEntries = directory.listFiles(); if (directoryEntries == null) { // I think that this means that there was an I/O error return; } for (File physicalLocation : directoryEntries) { if (!physicalLocation.isHidden()) { if (recursive && physicalLocation.exists() && physicalLocation.isDirectory()) { subFolders.add(physicalLocation); } else if (physicalLocation.exists() && physicalLocation.isFile() && isValidOWLFile(physicalLocation)) { examineSingleFile(physicalLocation, webLocationsFoundInParentDirectory, newWebLocations); } } } webLocationsFoundInParentDirectory.addAll(newWebLocations); for (File physicalLocation : subFolders) { examineDirectoryContents(physicalLocation, webLocationsFoundInParentDirectory); } }
public GroupEntry getEntry() { String text = physicalLocationField.getText(); if (text == null || text.length() == 0) { return null; } File dir = new File(text); if (!dir.exists() || !dir.isDirectory()) { return null; } try { // There seems to be a bug in relativize and resolve so don't relativize here URI folderUri = new File(physicalLocationField.getText()).toURI(); if (importByName.isSelected()) { return ImportByNameManager.createGroupEntry(folderUri, recursive.isSelected(), true, catalog); } else { return FolderGroupManager.createGroupEntry(folderUri, recursive.isSelected(), true, catalog); } } catch (IOException ioe) { LoggerFactory.getLogger(FolderGroupPanel.class) .error("An error occurred whilst creating a group entry: {}", ioe); return null; } } }
private void examineSingleFile(File physicalLocation, Set<URI> webLocationsFoundInParentDirectory, Set<URI> newWebLocations) { if (logger.isDebugEnabled()) { logger.debug("Applying algorithms to " + physicalLocation); } URI shortLocation = folder.toURI().relativize(physicalLocation.toURI()); Collection<URI> retainedSuggestions = null; try { retainedSuggestions = retainedFileToWebLocationMap.get(physicalLocation.getCanonicalFile()); } catch (IOException e) { logger.warn("IO Exception caught processing file " + physicalLocation + " for repository library update", e); } if (retainedSuggestions != null) { if (logger.isDebugEnabled()) { logger.debug("Adding mappings retained from previous version of the catalog"); } recordEntries(retainedSuggestions, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); } else { if (logger.isDebugEnabled()) { logger.debug("Adding new mappings not found in the previous version of the catalog"); } for (Algorithm algorithm : algorithms) { Set<URI> webLocations = algorithm.getSuggestions(physicalLocation); modified = modified || !webLocations.isEmpty(); recordEntries(webLocations, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); } } }
public boolean update(Entry entry) { this.ge = (GroupEntry) entry; reset(); ensureLatestVersion(); try { logger.info(LogBanner.start("Starting Catalog Update")); logger.info("Update of group entry {} started at {}.", ge.getId(), new Date(timeOfCurrentUpdate)); retainEntries(); if(folder != null) { HashSet<File> nonOwlFiles = new HashSet<>(); examineDirectoryContents(folder, new HashSet<>(), nonOwlFiles, 0); if(nonOwlFiles.size() > NON_ONTOLOGY_DOCUMENT_TERMINATION_LIMIT) { logger.warn("Search for ontology documents in {} and sub-folders has been terminated as over {} non-ontology documents have been found.", folder.getAbsolutePath(), NON_ONTOLOGY_DOCUMENT_TERMINATION_LIMIT); } } if(modified) { clearEntries(); writeEntries(); } logger.info("Catalog Update Complete"); logger.info(LogBanner.end()); return modified; } finally { this.ge = null; reset(); } }
private void ensureLatestVersion() { int version = LibraryUtilities.getVersion(ge); if(version < CURRENT_VERSION) { boolean autoUpdate = LibraryUtilities.getBooleanProperty(ge, LibraryUtilities.AUTO_UPDATE_PROP, this.autoUpdate); ge.setId(getIdString(getIdPrefix(), folder.toURI(), recursive, autoUpdate)); clearEntries(); } }
private void recordEntries(Collection<URI> webLocations, URI physicalLocation, Set<URI> webLocationsFoundInParentDirectory, Set<URI> newWebLocations) { for (URI webLocation : webLocations) { if (!webLocationsFoundInParentDirectory.contains(webLocation)) { newWebLocations.add(webLocation); recordEntry(webLocation, physicalLocation); } else { recordEntry(appendScheme(webLocation, CatalogEntryManager.SHADOWED_SCHEME), physicalLocation); } } }
&& isValidOWLFile(physicalLocation)) { if (logger.isDebugEnabled()) { logger.debug("Applying algorithms to " + physicalLocation); logger.debug("Adding mappings retained from previous version of the catalog"); recordEntries(retainedSuggestions, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); Set<URI> webLocations = algorithm.getSuggestions(physicalLocation); modified = modified || !webLocations.isEmpty(); recordEntries(webLocations, shortLocation, webLocationsFoundInParentDirectory, newWebLocations); examineDiskEntries(physicalLocation, webLocationsFoundInParentDirectory);
public String getDescription(Entry ge) { StringBuffer sb = new StringBuffer("<html><body><b>Folder Repository for "); sb.append(getDirectory((GroupEntry) ge)); sb.append("</b>"); if (LibraryUtilities.getBooleanProperty(ge, RECURSIVE_PROP, true)) { sb.append(" <font color=\"gray\">(Recursive)</font>"); } sb.append("</body></html>"); return sb.toString(); }