@Override public DocumentModel createEntry(DocumentModel entry) { Map<String, Object> fieldMap = entry.getProperties(directory.getSchema()); Map<String, Object> simpleNameFieldMap = new HashMap<>(); for (Map.Entry<String, Object> fieldEntry : fieldMap.entrySet()) { String fieldKey = fieldEntry.getKey(); if (fieldKey.contains(":")) { fieldKey = fieldKey.split(":")[1]; } simpleNameFieldMap.put(fieldKey, fieldEntry.getValue()); } return createEntry(simpleNameFieldMap); }
if (field == null) { String message = String.format("Invalid field name '%s' for directory '%s' with schema '%s'", fieldName, directory.getName(), directory.getSchema()); throw new DirectoryException(message);
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(); } }
if (ds.getDirectoryNames().contains(voc)) { Directory dir = ds.getDirectory(voc); String schema = dir.getSchema(); if ("vocabulary".equals(schema) || "xvocabulary".equals(schema)) { try (Session session = dir.getSession()) {
@Override public DocumentModel adapt(Directory directory, DocumentModel entry) { if (fieldName == null || pattern == null) { log.warn(getClass().getName() + " is missing configuration parameters"); return entry; } if (BaseSession.isReadOnlyEntry(entry)) { // keep already existing flag return entry; } try { Object fieldValue = entry.getProperty(directory.getSchema(), fieldName); String value = fieldValue != null ? fieldValue.toString() : ""; if (pattern.matcher(value).matches()) { BaseSession.setReadWriteEntry(entry); } else { BaseSession.setReadOnlyEntry(entry); } } catch (PropertyException e) { throw new DirectoryException( String.format( "The field '%s' of entry '%s' could not be adapt and map on directory '%s', check that the field exist in the schema", fieldName, entry.getId(), directory.getName()), e); } return entry; }
protected BaseSession(Directory directory, Class<? extends Reference> referenceClass) { this.directory = directory; schemaName = directory.getSchema(); directoryName = directory.getName(); BaseDirectoryDescriptor desc = directory.getDescriptor(); substringMatchType = desc.getSubstringMatchType(); autoincrementId = desc.isAutoincrementIdField(); permissions = desc.permissions; passwordHashAlgorithm = desc.passwordHashAlgorithm; this.referenceClass = referenceClass; computeMultiTenantId = desc.isComputeMultiTenantId(); }
protected JSONObject getSingleDirectoryEntry(final String storedReference, final String directoryName, final boolean localize, String keySeparator, final boolean dbl10n, final String labelFieldName) { if (storedReference == null || storedReference.isEmpty()) { return null; } DirectoryService directoryService = Framework.getService(DirectoryService.class); try { Directory directory = directoryService.getDirectory(directoryName); if (directory == null) { log.error("Could not find directory with name " + directoryName); return null; } try (Session session = directory.getSession()) { String schemaName = directory.getSchema(); SchemaManager schemaManager = Framework.getService(SchemaManager.class); Schema schema = schemaManager.getSchema(schemaName); final Locale locale = org.jboss.seam.core.Locale.instance(); final String label = SuggestConstants.getLabelFieldName(schema, dbl10n, labelFieldName, locale.getLanguage()); JSONObject obj = resolveDirectoryEntry(storedReference, keySeparator, session, schema, label, localize, dbl10n); return obj; } } catch (DirectoryException de) { log.error("An error occured while obtaining directory " + directoryName, de); return null; } }
String schemaName = directory.getSchema(); SchemaManager schemaManager = Framework.getService(SchemaManager.class); Schema schema = schemaManager.getSchema(schemaName);
/** * 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); } } }
String schema = directory.getSchema(); DocumentModel entry = session.getEntry(entryId);
Schema schema = schemaManager.getSchema(directory.getSchema()); if (!schema.hasField(PARENT_FIELD_ID)) { throw new DirectoryException(directoryName + "does not have the required field: "