-
1. Re: Content mirroring into federation
vasilievip Aug 5, 2013 4:54 AM (in response to vasilievip)Use of sequencers section to plug custom code (not listeners so far, but I assume with listeners there will be no issues):
Example:
{code:json}
"sequencers" : {
"extension1" :
{ "classname" : "", "extensionClass" : "com.acme.IdHandlerExtension", "isExtension" : "true", "targetType" : "", "targetProperty" : "" }
,
"extension2" :
{ "classname" : "", "extensionClass" : "com.acme.IdHandlerExtension", "isExtension" : "true", "targetType" : "", "targetProperty" : "" }
}
{code}
And java to extract config:
{code:java}
/** Extract all extension configurations
*
* @return boolean true if configuration was changed
*/
private boolean getExtensionConfiguration(RepositoryConfiguration configuration) {
extensionConfigurationParams.clear();
RepositoryConfiguration.Sequencing sequencing = configuration.getSequencing();
if (sequencing == null) {
return false;
}
List<RepositoryConfiguration.Component> sequencersList = sequencing.getSequencers();
if (sequencersList == null ) {
return false;
}
boolean result = false;
int listSize = sequencersList.size();
for (int i = 0; listSize > i; i++) {
RepositoryConfiguration.Component component = sequencersList.get(i);
if (component == null) {
continue;
}
Document document = component.getDocument();
if (document == null) {
continue;
}
// if don't have extension flag => skip
if (! document.containsField(CONFIGURATION_EXTENSION_FLAG_NAME)) {
continue;
}
// if extension flag is NOT TRUE (flag == false) => skip
if (!document.getString(CONFIGURATION_EXTENSION_FLAG_NAME).equalsIgnoreCase("true")) {
continue;
}
// if unknown extension (extension class name not defined) => skip
if (! document.containsField(CONFIGURATION_EXTENSION_CLASSNAME)) {
continue;
}
// if empty extension class name => skip
if (document.getString(CONFIGURATION_EXTENSION_CLASSNAME).trim().equals("")) {
continue;
}
String extensionName = component.getName();
// if empty extension name => skip
if (extensionName.trim().equals("")) {
continue;
}
// if this extension name already exists in configuration => skip
if (extensionConfigurationParams.containsKey(extensionName)) {
continue;
}
Map<String, String> extensionProperties = new HashMap<String, String>();
Iterator<Document.Field> fieldsIterator = document.fields().iterator();
while(fieldsIterator.hasNext()) {
Document.Field field = fieldsIterator.next();
String fieldName = field.getName();
if (extensionProperties.containsKey(fieldName)) {
LOG.warn("Duplicated configuration value in: ' " + extensionName + " value name: '" + fieldName +"'" );
continue;
}
try {
extensionProperties.put(fieldName, field.getValueAsString());
} catch (IllegalFormatConversionException e) {
LOG.debug("Conversion error during configuration reading: " + e.getMessage());
}
}
// Save extension configuration
extensionConfigurationParams.put(extensionName, extensionProperties);
result = true;
}
return result;
}
{code}