Connectors : Consolidation Server : Appendix - Groovy Processors : Discard Processor Code Samples
 
Discard Processor Code Samples
 
DiscardAggregationProcessor.java
DiscardAggregationProcessorConfig.java
DiscardAggregationProcessorConfigCheck.java
DiscardAggregationProcessor.java
package com.exalead.samples.consolidation;

import com.exalead.cloudview.consolidationapi.processors.IAggregationDocument;
import com.exalead.cloudview.consolidationapi.processors.java.IJavaAllUpdatesAggregationHandler;
import com.exalead.cloudview.consolidationapi.processors.java.IJavaAllUpdatesAggregationProcessor;
import com.exalead.mercury.component.config.CVComponentConfigClass;

@CVComponentConfigClass(configClass = DiscardAggregationProcessorConfig.class, configCheckClass =
DiscardAggregationProcessorConfigCheck.class)
public class DiscardAggregationProcessor implements IJavaAllUpdatesAggregationProcessor {

private final String[] discardedDocumentTypes;

public DiscardAggregationProcessor(final DiscardAggregationProcessorConfig config) {
final String[] configDocumentTypes = config.getDocumentTypes();
if (configDocumentTypes != null) {
this.discardedDocumentTypes = new String[configDocumentTypes.length];
for (int i = 0; i < configDocumentTypes.length; i++) {
this.discardedDocumentTypes[i] = configDocumentTypes[i].trim();
}
} else {
this.discardedDocumentTypes = null;
}
}

@Override
public String getAggregationDocumentType() {
return null;
}

@Override
public void process(IJavaAllUpdatesAggregationHandler handler, IAggregationDocument document) throws
Exception {
if (this.discardedDocumentTypes != null) {
for (int i = 0; i < this.discardedDocumentTypes.length; i++) {
if (document.getTypeInheritance().contains(this.discardedDocumentTypes[i])) {
handler.discard();
}
}
}
}
}
DiscardAggregationProcessorConfig.java
package com.exalead.samples.consolidation;

import com.exalead.config.bean.IsMandatory;
import com.exalead.config.bean.PropertyDescription;
import com.exalead.config.bean.PropertyLabel;
import com.exalead.mercury.component.config.CVComponentConfig;

public class DiscardAggregationProcessorConfig implements CVComponentConfig {
public final static String[] METHODS = {
"DocumentTypes"
};

public static final String[] getMethods() {
return METHODS;
}

private String[] documentTypes;
public DiscardAggregationProcessorConfig() {
}

@IsMandatory(true)
@PropertyLabel("Discard document types")
@PropertyDescription("Specifies types of documents to be discarded")
public void setDocumentTypes(String[] documentTypes) {
this.documentTypes = documentTypes;
}

public String[] getDocumentTypes() {
return this.documentTypes;
}
}
DiscardAggregationProcessorConfigCheck.java
package com.exalead.samples.consolidation;

import com.exalead.config.bean.ConfigurationException;
import com.exalead.mercury.component.config.CVComponentConfigCheck;

public class DiscardAggregationProcessorConfigCheck implements
CVComponentConfigCheck<DiscardAggregationProcessorConfig> {
@Override
public void check(final DiscardAggregationProcessorConfig config, final boolean useNow) throws
ConfigurationException, Exception {
if (config != null) {
final String[] documentTypes = config.getDocumentTypes();
if (documentTypes != null && documentTypes.length == 0) {
final ConfigurationException error = new ConfigurationException
("Discard aggregation processor: 'documentTypes' property can't be empty.");
error.setConfigKey("documentTypes");
throw error;
}
for (String documentType : documentTypes) {
final String trimmedDocumentType = documentType.trim();
if (trimmedDocumentType.isEmpty()) {
final ConfigurationException error = new ConfigurationException
("Discard aggregation processor: empty 'documentTypes' entry");
error.setConfigKey("documentTypes");
throw error;
}
}
}
}
}