public void selectDirectoryEntry(String entryId) { String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { selectedDirectoryEntry = dirSession.getEntry(entryId); } }
/** * @since 5.9.3 */ protected String getParentAbsoluteLabel(final String entryId, final String keySeparator, final Session session, final QName labelFieldName, final boolean localize, final boolean dbl10n) throws PropertyException { String[] split = entryId.split(keySeparator); String result = ""; for (int i = 0; i < split.length; i++) { DocumentModel entry = session.getEntry(split[i]); if (entry != null) { Serializable value = entry.getPropertyValue(labelFieldName.getPrefixedName()); if (localize && !dbl10n) { value = messages.get(value); } result += (i > 0 ? "/" : "") + value; } } return result; }
public static String typeLabelOf(String type) { if (StringUtils.isBlank(type)) { return ""; } DirectoryService dm = Framework.getService(DirectoryService.class); try (Session session = dm.open(DocumentationComponent.DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(type); if (entry != null) { return (String) entry.getProperty("vocabulary", "label"); } } catch (DirectoryException | PropertyException e) { log.error("Error while resolving typeLabel", e); } return type; }
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); } }
directorySession = getService().open(directory); if (null != directorySession) { DocumentModel entry = directorySession.getEntry(entryKey); String schemaName = getService().getDirectorySchema(directory.toString());
public void editEntry(String entryId) { DirectoryService ds = Framework.getService(DirectoryService.class); Framework.doPrivileged(() -> { try (Session session = ds.open(getDirectoryName())) { editableEntry = session.getEntry(entryId); } }); }
protected NuxeoOAuthToken getTokenFromDirectory(String token) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(token); if (entry == null) { return null; } return getTokenFromDirectoryEntry(entry); } }); }
@Override Object run(Session session) { DocumentModel entry = session.getEntry(entryId); if (entry == null) { throw new WebResourceNotFoundException("Entry not found"); } return newObject("directoryEntry", new DirectoryEntry(directory.getName(), entry), entryId); } });
try { if (ENABLE_SANITY_CHECK) { DocumentModel badEntry = dirSession.getEntry(id); if (badEntry != null) { log.warn("Entry with id " + id + " is already present : please check DB integrity");
protected NuxeoOAuthConsumer getEntry(String consumerKey, String keyType) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(consumerKey); if (entry == null) { return null; } return NuxeoOAuthConsumer.createFromDirectoryEntry(entry, keyType); } }); }
private static void updateSubDirectoryEntry(SubDirectoryInfo dirInfo, Map<String, Object> fieldMap, String id, boolean canCreateIfOptional) { DocumentModel dirEntry = dirInfo.getSession().getEntry(id); if (dirInfo.getSession().isReadOnly() || (dirEntry != null && isReadOnlyEntry(dirEntry))) { return; } if (dirEntry == null && !canCreateIfOptional) { // entry to update doesn't belong to this directory return; } Map<String, Object> map = new HashMap<>(); map.put(dirInfo.idField, id); for (Entry<String, String> e : dirInfo.fromSource.entrySet()) { map.put(e.getValue(), fieldMap.get(e.getKey())); } if (map.size() > 1) { if (canCreateIfOptional && dirInfo.isOptional && dirEntry == null) { // if entry does not exist, create it dirInfo.getSession().createEntry(map); } else { final DocumentModel entry = BaseSession.createEntryModel(null, dirInfo.dirSchemaName, id, null); entry.setProperties(dirInfo.dirSchemaName, map); dirInfo.getSession().updateEntry(entry); } } }
protected NuxeoOAuthToken storeAccessTokenAsDirectoryEntry(NuxeoOAuthToken aToken) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(aToken.getToken()); if (entry == null) { entry = session.createEntry(Collections.singletonMap("token", aToken.getToken())); } aToken.updateEntry(entry); session.updateEntry(entry); return getTokenFromDirectoryEntry(session.getEntry(aToken.getToken())); } }); }
@Override public boolean authenticate(String username, String password) { init(); for (SourceInfo sourceInfo : sourceInfos) { for (SubDirectoryInfo dirInfo : sourceInfo.subDirectoryInfos) { if (!dirInfo.isAuthenticating) { continue; } if (dirInfo.getSession().authenticate(username, password)) { return true; } if (dirInfo.isOptional && dirInfo.getSession().getEntry(username) == null) { // check if given password equals to default value String passwordField = dirInfo.getSession().getPasswordField(); String defaultPassword = (String) dirInfo.defaultEntry.get(passwordField); if (defaultPassword != null && defaultPassword.equals(password)) { return true; } } } } return false; }
/** * @since 9.10 */ public boolean update(NuxeoOAuth2Token token) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(String.valueOf(token.getId())); if (entry == null) { return false; } entry.setProperties(NuxeoOAuth2Token.SCHEMA, token.toMap()); session.updateEntry(entry); return true; } }); }
@Override DirectoryEntry run(Session session) { try { DocumentModel docEntry = entry.getDocumentModel(); session.updateEntry(docEntry); return new DirectoryEntry(directory.getName(), session.getEntry(docEntry.getId())); } catch (DirectoryException e) { throw new NuxeoException(e.getMessage(), SC_BAD_REQUEST); } } });
/** * Fetches both statically and dynamically defined references and merges the results. * * @see org.nuxeo.ecm.directory.Reference#getSourceIdsForTarget(String) */ @Override // XXX: broken, use getLdapTargetIds for a proper implementation public List<String> getTargetIdsForSource(String sourceId) { String schemaName = getSourceDirectory().getSchema(); try (Session session = getSourceDirectory().getSession()) { try { return BaseSession.toStringList(session.getEntry(sourceId).getProperty(schemaName, fieldName)); } catch (PropertyException e) { throw new DirectoryException(e); } } }
Directory directory = getDirectoryService().getDirectory(directoryName); String schema = directory.getSchema(); DocumentModel entry = session.getEntry(entryId);
@Override public void deleteEntry(String id) { checkPermission(SecurityConstants.WRITE); checkDeleteConstraints(id); init(); for (SourceInfo sourceInfo : sourceInfos) { for (SubDirectoryInfo dirInfo : sourceInfo.subDirectoryInfos) { if (!dirInfo.getSession().isReadOnly()) { // Check if the platform is able to manage entry if (!sourceInfo.source.creation) { // If not check if entry exist to prevent exception that may // stop the deletion loop to other subdirectories // Do not raise exception, because creation is not managed // by the platform DocumentModel docModel = dirInfo.getSession().getEntry(id); if (docModel == null) { log.warn(String.format( "MultiDirectory '%s' : The entry id '%s' could not be deleted on subdirectory '%s' because it does not exist", getName(), id, dirInfo.dirName)); } else { dirInfo.getSession().deleteEntry(id); } } else { dirInfo.getSession().deleteEntry(id); } } } } }
@Override public void updateEntry(DocumentModel docModel) { checkPermission(SecurityConstants.WRITE); if (isReadOnlyEntry(docModel)) { return; } init(); final String id = docModel.getId(); Map<String, Object> fieldMap = docModel.getProperties(schemaName); for (SourceInfo sourceInfo : sourceInfos) { // check if entry exists in this source, in case it can be created // in optional subdirectories boolean canCreateIfOptional = false; for (SubDirectoryInfo dirInfo : sourceInfo.requiredSubDirectoryInfos) { if (!canCreateIfOptional) { canCreateIfOptional = dirInfo.getSession().getEntry(id) != null; } updateSubDirectoryEntry(dirInfo, fieldMap, id, false); } for (SubDirectoryInfo dirInfo : sourceInfo.optionalSubDirectoryInfos) { updateSubDirectoryEntry(dirInfo, fieldMap, id, canCreateIfOptional); } } }
DocumentModel docMod = session.getEntry(bitsOfPath[b]); try {