/** * Returns a bare document model suitable for directory implementations. * <p> * Allow setting the readonly entry flag to {@code Boolean.TRUE}. See {@code Session#isReadOnlyEntry(DocumentModel)} * * @since 5.3.1 */ public static DocumentModel createEntryModel(String sessionId, String schema, String id, Map<String, Object> values, boolean readOnly) throws PropertyException { DocumentModel entry = createEntryModel(sessionId, schema, id, values); if (readOnly) { setReadOnlyEntry(entry); } return entry; }
@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; }
BaseSession.setReadOnlyEntry(clone);