public void selectDirectoryEntry(String entryId) { String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { selectedDirectoryEntry = dirSession.getEntry(entryId); } }
protected List<NuxeoOAuth2Token> getTokens(String nxuser) { return Framework.doPrivileged(() -> { DirectoryService ds = Framework.getService(DirectoryService.class); try (Session session = ds.open(TOKEN_DIR)) { Map<String, Serializable> filter = new HashMap<>(); if (nxuser != null) { filter.put(NuxeoOAuth2Token.KEY_NUXEO_LOGIN, nxuser); } List<DocumentModel> docs = session.query(filter, Collections.emptySet(), Collections.emptyMap(), true, 0, 0); return docs.stream().map(NuxeoOAuth2Token::new).collect(Collectors.toList()); } }); }
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); } } }
@Override public DataStore<StoredCredential> delete(String key) throws IOException { DirectoryService ds = Framework.getService(DirectoryService.class); try (Session session = ds.open(DIRECTORY_NAME)) { Map<String, Serializable> filter = new HashMap<>(); filter.put("serviceName", serviceName); filter.put(ENTRY_ID, key); DocumentModelList entries = session.query(filter); for (DocumentModel entry : entries) { session.deleteEntry(entry); } } return this; }
@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; }
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())); } }); }
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"); if (FIX_SANITY_ERROR) { dirSession.deleteEntry(id); dirSession.createEntry(fields); } catch (DirectoryException e) { log.error("Unable to create entry", e);
protected DocumentModelList getChildrenEntries() { if (childrenEntries != null) { // memorized directory lookup since directory content is not // suppose to change // XXX: use the cache manager instead of field caching strategy return childrenEntries; } try (Session session = getDirectorySession()) { if (level == 0) { String schemaName = getDirectorySchema(); SchemaManager schemaManager = Framework.getService(SchemaManager.class); Schema schema = schemaManager.getSchema(schemaName); if (schema.hasField(PARENT_FIELD_ID)) { // filter on empty parent Map<String, Serializable> filter = new HashMap<String, Serializable>(); filter.put(PARENT_FIELD_ID, ""); childrenEntries = session.query(filter); } else { childrenEntries = session.getEntries(); } } else { Map<String, Serializable> filter = new HashMap<String, Serializable>(); String[] bitsOfPath = path.split("/"); filter.put(PARENT_FIELD_ID, bitsOfPath[level - 1]); childrenEntries = session.query(filter); } return childrenEntries; } }
@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 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); } } });
directorySession = getService().open(directory); if (null != directorySession) { DocumentModel entry = directorySession.getEntry(entryKey); String schemaName = getService().getDirectorySchema(directory.toString()); if (null != directorySession) { try { directorySession.close(); } catch (DirectoryException e) { log.error("Failed to close the session to the directory '" + directory + "', error: " + e.getMessage());
public DocumentModelList getItems(String directoryName, Map<String, Serializable> filter, Set<String> fulltext, Map<String, String> orderBy) throws ToutaticeException { DocumentModelList items = null; Session session = null; try { session = getService().open(directoryName); } catch (DirectoryException e) { throw new ToutaticeException("could not open session on directory '" + directoryName + "', error: " + e.getMessage()); } if (null != session) { try { items = session.query(filter, fulltext, orderBy); } catch (Exception e) { throw new ToutaticeException("could not query on directory '" + directoryName + "', error: " + e.getMessage()); } finally { try { if (null != session) { session.close(); } } catch (DirectoryException ce) { log.error("Could not close directory session", ce); } } } else { throw new ToutaticeException("could not open session on directory: " + directoryName); } return items; }
final DocumentModel entry = dirInfo.getSession().getEntry(id, fetchReferences); boolean isOptional = dirInfo.isOptional; if (entry == null && !isOptional) { if (entry == null && isOptional && !dirInfo.getSession().isReadOnly()) { entryId = entry.getId(); String passwordField = dirInfo.getSession().getPasswordField(); for (Entry<String, String> e : dirInfo.toSource.entrySet()) { String dirProp = e.getKey();
@Override public NuxeoOAuthConsumer storeConsumer(NuxeoOAuthConsumer consumer) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.createEntry( Collections.singletonMap("consumerKey", consumer.consumerKey)); consumer.asDocumentModel(entry); session.updateEntry(entry); return NuxeoOAuthConsumer.createFromDirectoryEntry(entry, null); } }); }
public String store(String nuxeoLogin, Map<String, Object> fields) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { fields.put("nuxeoLogin", nuxeoLogin); fields.put("serviceName", serviceName); DocumentModel entry = session.createEntry(fields); Long id = (Long) entry.getProperty(NuxeoOAuth2Token.SCHEMA, ENTRY_ID); return id.toString(); } }); }
DocumentModelList l = dirInfo.getSession().query(dirFilter, dirFulltext, null, fetchReferences); for (DocumentModel entry : l) { final String id = entry.getId(); dirInfo.getSession().getProjection(Collections.emptyMap(), dirInfo.idField)); for (Entry<String, Map<String, Object>> result : maps.entrySet()) { final String id = result.getKey();
@Override DirectoryEntry run(Session session) { session.deleteEntry(entry.getDocumentModel()); return null; } });
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")); } }
public DocumentModelList getEntries(String directory) throws ToutaticeException { DocumentModelList entries = null; Session directorySession = null; try { directorySession = getService().open(directory); if (null != directorySession) { entries = directorySession.getEntries(); } else { log.error("Failed to obtain a session to the the directory '" + directory + "'"); } } catch (Exception e) { log.warn("Failed to either get a session to the directory '" + directory + "' or failed to get the entries, error: " + e.getMessage()); throw new ToutaticeException(e); } finally { if (null != directorySession) { try { directorySession.close(); } catch (DirectoryException e) { log.error("Failed to close the session to the directory '" + directory + "', error: " + e.getMessage()); } } } return entries; }
public void editSelectedDirectoryEntry() { String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { setParentColumnIfNull(selectedDirectoryEntry); dirSession.updateEntry(selectedDirectoryEntry); selectedDirectoryEntry = null; // invalidate directory entries list currentDirectoryEntries = null; Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.edited")); } }