/** * Immediately change and apply the specified field in the current repository configuration to the * new value. * * @param defn the attribute definition for the value; may not be null * @param newValue the new string value * @throws RepositoryException if there is a problem obtaining the repository configuration or * applying the change * @throws OperationFailedException if there is a problem obtaining the raw value from the * supplied model node */ public void changeField(MappedAttributeDefinition defn, ModelNode newValue) throws RepositoryException, OperationFailedException { ModeShapeEngine engine = getEngine(); String repositoryName = repositoryName(); // Get a snapshot of the current configuration ... RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName); // Now start to make changes ... Editor editor = config.edit(); // Find the Document containing the field ... EditableDocument fieldContainer = editor; for (String fieldName : defn.getPathToContainerOfField()) { fieldContainer = editor.getOrCreateDocument(fieldName); } // Get the raw value from the model node ... Object rawValue = defn.getTypedValue(newValue); // Change the field ... String fieldName = defn.getFieldName(); fieldContainer.set(fieldName, rawValue); // Apply the changes to the current configuration ... Changes changes = editor.getChanges(); engine.update(repositoryName, changes); }
/** * Immediately change and apply the specified sequencer field in the current repository * configuration to the new value. * * @param defn the attribute definition for the value; may not be null * @param newValue the new string value * @param sequencerName the name of the sequencer * @throws RepositoryException if there is a problem obtaining the repository configuration or * applying the change * @throws OperationFailedException if there is a problem obtaining the raw value from the * supplied model node */ public void changeSequencerField( MappedAttributeDefinition defn, ModelNode newValue, String sequencerName) throws RepositoryException, OperationFailedException { ModeShapeEngine engine = getEngine(); String repositoryName = repositoryName(); // Get a snapshot of the current configuration ... RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName); // Now start to make changes ... Editor editor = config.edit(); // Find the array of sequencer documents ... List<String> pathToContainer = defn.getPathToContainerOfField(); EditableDocument sequencing = editor.getOrCreateDocument(pathToContainer.get(0)); EditableDocument sequencers = sequencing.getOrCreateArray(pathToContainer.get(1)); // The container should be an array ... for (String configuredSequencerName : sequencers.keySet()) { // Look for the entry with a name that matches our sequencer name ... if (sequencerName.equals(configuredSequencerName)) { // All these entries should be nested documents ... EditableDocument sequencer = (EditableDocument) sequencers.get(configuredSequencerName); // Change the field ... String fieldName = defn.getFieldName(); // Get the raw value from the model node ... Object rawValue = defn.getTypedValue(newValue); // And update the field ... sequencer.set(fieldName, rawValue); break; } } // Get and apply the changes to the current configuration. Note that the 'update' call // asynchronously // updates the configuration, and returns a Future<JcrRepository> that we could use if we wanted // to // wait for the changes to take place. But we don't want/need to wait, so we'll not use the // Future ... Changes changes = editor.getChanges(); engine.update(repositoryName, changes); }
/** * Immediately change and apply the specified extractor field in the current repository * configuration to the new value. * * @param defn the attribute definition for the value; may not be null * @param newValue the new string value * @param extractorName the name of the sequencer * @throws RepositoryException if there is a problem obtaining the repository configuration or * applying the change * @throws OperationFailedException if there is a problem obtaining the raw value from the * supplied model node */ public void changeTextExtractorField( MappedAttributeDefinition defn, ModelNode newValue, String extractorName) throws RepositoryException, OperationFailedException { ModeShapeEngine engine = getEngine(); String repositoryName = repositoryName(); // Get a snapshot of the current configuration ... RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName); // Now start to make changes ... Editor editor = config.edit(); // Find the array of sequencer documents ... List<String> pathToContainer = defn.getPathToContainerOfField(); EditableDocument textExtracting = editor.getOrCreateDocument(pathToContainer.get(1)); EditableDocument extractors = textExtracting.getOrCreateDocument(pathToContainer.get(2)); // The container should be an array ... for (String configuredExtractorName : extractors.keySet()) { // Look for the entry with a name that matches our extractor name ... if (extractorName.equals(configuredExtractorName)) { // All these entries should be nested documents ... EditableDocument extractor = (EditableDocument) extractors.get(configuredExtractorName); // Change the field ... String fieldName = defn.getFieldName(); // Get the raw value from the model node ... Object rawValue = defn.getTypedValue(newValue); // And update the field ... extractor.set(fieldName, rawValue); break; } } Changes changes = editor.getChanges(); engine.update(repositoryName, changes); }
@Override public void start(StartContext arg0) throws StartException { JcrEngine jcr = getEngine(); try { final String repositoryName = repositoryConfiguration.getName(); // Get the index storage configuration ... IndexStorage indexStorageConfig = indexStorageConfigInjector.getValue(); Document queryConfig = null; if (indexStorageConfig != null) { queryConfig = indexStorageConfig.getQueryConfiguration(); } else { // We'll use the default index storage, but this will be overwritten by the *IndexStorageAdd // operation // (that we're dependent upon). The default for non-AS7 ModeShape repositories is to use // RAM index storage, but in AS7 we want to by default store the indexes on the filesystem // in the // AS7 data directory. // We'll do this by setting a path relative to the data directory, and then injecting // the "${jboss.server.data.dir}/modeshape" path into the repository service // (which will then update the configuration prior to deployment) ... EditableDocument query = Schematic.newDocument(); EditableDocument indexing = query.getOrCreateDocument(FieldName.INDEXING); EditableDocument indexStorage = query.getOrCreateDocument(FieldName.INDEX_STORAGE); EditableDocument backend = indexing.getOrCreateDocument(FieldName.INDEXING_BACKEND); query.set(FieldName.REBUILD_UPON_STARTUP, "if_needed"); backend.set(FieldName.TYPE, FieldValue.INDEXING_BACKEND_TYPE_LUCENE); indexStorage.set(FieldName.TYPE, FieldValue.INDEX_STORAGE_FILESYSTEM); String dataDirPath = dataDirectoryPathInjector.getValue(); indexStorage.set( FieldName.INDEX_STORAGE_LOCATION, dataDirPath + "/" + repositoryName + "/indexes"); queryConfig = query; } assert queryConfig != null; // Get the binary storage configuration ... Document binaryConfig = null; BinaryStorage binaryStorageConfig = binaryStorageInjector.getValue(); if (binaryStorageConfig != null) { binaryConfig = binaryStorageConfig.getBinaryConfiguration(); } else { // By default, store the binaries in the data directory ... EditableDocument binaries = Schematic.newDocument(); binaries.set(FieldName.TYPE, FieldValue.BINARY_STORAGE_TYPE_FILE); String dataDirPath = dataDirectoryPathInjector.getValue(); binaries.set(FieldName.DIRECTORY, dataDirPath + "/" + repositoryName + "/binaries"); binaryConfig = binaries; } // Now update the configuration ... Editor editor = repositoryConfiguration.edit(); editor.setDocument(FieldName.QUERY, queryConfig); editor .getOrCreateDocument(FieldName.STORAGE) .setDocument(FieldName.BINARY_STORAGE, binaryConfig); // Apply the changes to the configuration ... editor.apply(editor.getChanges()); // Deploy the repository and use this as the environment ... jcr.deploy(repositoryConfiguration.with(this)); } catch (ConfigurationException e) { throw new StartException(e); } catch (RepositoryException e) { throw new StartException(e); } }