Session getSession() { if (session == null) { session = directoryService.open(dirName); } return session; }
protected DirectoryTree(String directory) { this(Framework.getService(DirectoryService.class).getDirectory(directory)); }
public DocumentModelList getCurrentDirectoryEntries() { if (currentDirectoryEntries == null) { currentDirectoryEntries = new DocumentModelListImpl(); String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { Map<String, Serializable> emptyMap = Collections.emptyMap(); Set<String> emptySet = Collections.emptySet(); DocumentModelList entries = dirSession.query(emptyMap, emptySet, null, true); if (entries != null && !entries.isEmpty()) { currentDirectoryEntries.addAll(entries); } // sort String sortField = currentDirectoryInfo.getSortField(); if (sortField == null) { sortField = dirService.getDirectoryIdField(dirName); } // sort Map<String, String> orderBy = new HashMap<String, String>(); orderBy.put(sortField, DocumentModelComparator.ORDER_ASC); Collections.sort(currentDirectoryEntries, new DocumentModelComparator(dirService.getDirectorySchema(dirName), orderBy)); } } return currentDirectoryEntries; }
private boolean initPersistentService() { if (dirSession != null) { return true; } if (directoryService == null) { directoryService = DirectoryHelper.getDirectoryService(); if (directoryService == null) { return false; } } try { dirSession = directoryService.open(DIR_NAME); directorySchema = directoryService.getDirectorySchema(DIR_NAME); } catch (DirectoryException e) { dirSession = null; log.error("Unable to open directory " + DIR_NAME + " : " + e.getMessage()); return false; } return true; }
public static List<WidgetSelectOption> getVocabularySelectOptions(String dirName, String lang) { DirectoryService ds = Framework.getService(DirectoryService.class); try (Session session = ds.open(dirName)) { String schema = ds.getDirectory(dirName).getSchema(); DocumentModelList entries = session.getEntries(); return convertToSelectOptions(entries, schema, dirName, lang); } catch (DirectoryException e) { log.error("Error while getting content of directory " + dirName, e); return Collections.emptyList(); } }
boolean success = true; Map<String, String> infos = new HashMap<>(); for (String id : directoryService.getDirectoryNames()) { BaseDirectoryDescriptor descriptor = directoryService.getDirectoryDescriptor(id); if (!(descriptor instanceof LDAPDirectoryDescriptor)) { continue; Directory dir = directoryService.getDirectory(id); long startTime = Calendar.getInstance().getTimeInMillis(); String dirName = null;
String voc = vocs.get(i); String keyValue = keys.get(i); if (ds.getDirectoryNames().contains(voc)) { Directory dir = ds.getDirectory(voc); String schema = dir.getSchema(); if ("vocabulary".equals(schema) || "xvocabulary".equals(schema)) {
protected String getDirectorySchema() { return getDirectoryService().getDirectorySchema(vocabularyName); }
for (SubDirectoryDescriptor subDir : source.subDirectories) { final String dirName = subDir.name; final String dirSchemaName = directoryService.getDirectorySchema(dirName); final String dirIdField = directoryService.getDirectoryIdField(dirName); final boolean dirIsAuth = directoryService.getDirectoryPasswordField(dirName) != null; final Map<String, String> fromSource = new HashMap<>(); final Map<String, String> toSource = new HashMap<>();
public String getLabelFor(String vocabularyName, String path, char keySeparator) { Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); String schemaName = null; List<String> labels = new ArrayList<String>(); DirectoryService directoryService = Framework.getService(DirectoryService.class); try (Session session = directoryService.open(vocabularyName)) { schemaName = directoryService.getDirectorySchema(vocabularyName); for (String id : StringUtils.split(path, keySeparator)) { DocumentModel entry = session.getEntry(id); if (entry != null) { String computeLabel = VocabularyTreeNode.computeLabel(locale, entry, schemaName); if (computeLabel == null) { labels.add(id); } else { labels.add(computeLabel); } } else { labels.add(id); } } } catch (DirectoryException e) { log.error("Error while accessing directory " + vocabularyName, e); } if (labels.isEmpty()) { return null; } else { return StringUtils.join(labels, keySeparator); } }
DirectoryService ds = Framework.getService(DirectoryService.class); List<WidgetSelectOption> result = new ArrayList<WidgetSelectOption>(); try (Session session = ds.open(parentDirName); Session subSession = ds.open(childDirName)) { String schema = ds.getDirectory(parentDirName).getSchema(); String subSchema = ds.getDirectory(childDirName).getSchema();
/** * @param nodeId tree node * @return true if tree node is not current directory entry * we want to modify. */ public boolean nodeIsNotCurrentEntry(String vocabularyName, String nodeId){ FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot viewRoot = context.getViewRoot(); DirectoryService directoryService = Framework.getLocalService(DirectoryService.class); String vocabularySchema = directoryService.getDirectorySchema(vocabularyName); String currentEntryId = getCurrentEntryValue(viewRoot, vocabularyName, vocabularySchema); return !nodeId.equalsIgnoreCase(currentEntryId); }
protected Session getDirectorySession() { return getDirectoryService().open(vocabularyName); }
public void createDirectoryEntry() { String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { // check if entry already exists String schema = dirService.getDirectorySchema(dirName); String idField = dirService.getDirectoryIdField(dirName); Object id = creationDirectoryEntry.getProperty(schema, idField); if (id instanceof String && dirSession.hasEntry((String) id)) { facesMessages.add(StatusMessage.Severity.ERROR, messages.get("vocabulary.entry.identifier.already.exists")); return; } setParentColumnIfNull(creationDirectoryEntry); dirSession.createEntry(creationDirectoryEntry); resetCreateDirectoryEntry(); // invalidate directory entries list currentDirectoryEntries = null; Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.added")); } }
@Override protected void initialize(Object... args) { super.initialize(args); if (args.length < 1) { throw new IllegalArgumentException("Directory Object takes one parameter"); } String dirName = (String) args[0]; directory = Framework.getService(DirectoryService.class).getDirectory(dirName); if (directory == null) { throw new WebResourceNotFoundException("Directory " + dirName + " was not found"); } }
directorySession = getService().open(directory); if (null != directorySession) { DocumentModel entry = directorySession.getEntry(entryKey); String schemaName = getService().getDirectorySchema(directory.toString());
public DocumentModel getCreationDirectoryEntry() { if (creationDirectoryEntry == null) { String dirName = currentDirectoryInfo.getName(); String schema = dirService.getDirectorySchema(dirName); creationDirectoryEntry = BaseSession.createEntryModel(null, schema, null, null); } return creationDirectoryEntry; }
protected List<DocumentModel> listCategories() { DirectoryService dm = Framework.getService(DirectoryService.class); try (Session session = dm.open(DIRECTORY_NAME)) { return session.query(Collections.<String, Serializable>emptyMap(), null, Collections.singletonMap("ordering", "ASC")); } }
public void createDirectoryEntry() { DirectoryService dirService = DirectoryHelper.getDirectoryService(); String dirName = getDirectoryName(); try (Session dirSession = dirService.open(dirName)) { // check if entry already exists String schema = dirService.getDirectorySchema(dirName); String idField = dirService.getDirectoryIdField(dirName); Object id = newDirectoryEntry.getProperty(schema, idField); if (id instanceof String && dirSession.hasEntry((String) id)) { facesMessages.addToControl("suggestAddNewDirectoryEntry", StatusMessage.Severity.ERROR, messages.get("vocabulary.entry.identifier.already.exists")); return; } dirSession.createEntry(newDirectoryEntry); reset(); Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.added")); } }
public VocabularyTreeNode get(String vocabularyName, boolean displayObsoleteEntries, char keySeparator, String orderingField) { if (treeModels == null) { treeModels = new HashMap<String, VocabularyTreeNode>(); } VocabularyTreeNode treeModel = treeModels.get(vocabularyName); if (treeModel != null) { // return cached model return treeModel; } DirectoryService directoryService = Framework.getService(DirectoryService.class); try { Directory directory = Framework.getService(DirectoryService.class).getDirectory(vocabularyName); if (directory == null) { throw new DirectoryException(vocabularyName + " is not a registered directory"); } } catch (DirectoryException e) { throw new RuntimeException(e); } treeModel = new VocabularyTreeNode(0, "", "", "", vocabularyName, directoryService, displayObsoleteEntries, keySeparator, orderingField); treeModels.put(vocabularyName, treeModel); return treeModel; }