use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.
the class SearchProducerWorker method run.
@Override
public void run() {
Log log = context.getLog();
try {
GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
if (options.isRaw()) {
optionsBuilder = optionsBuilder.raw();
}
optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, type.getClassDefinition());
ResultHandler<?> handler = (object, parentResult) -> {
try {
queue.put(object.asObjectable());
} catch (InterruptedException ex) {
log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
}
return true;
};
RepositoryService repository = context.getRepository();
repository.searchObjectsIterative(type.getClassDefinition(), query, handler, optionsBuilder.build(), true, operation.getResult());
} catch (SchemaException ex) {
log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);
} finally {
markDone();
if (isWorkersDone()) {
if (!operation.isFinished()) {
operation.producerFinish();
}
}
}
}
use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.
the class CountRepositoryAction method execute.
@Override
public void execute() throws Exception {
RepositoryService repository = context.getRepository();
FileReference fileReference = options.getFilter();
if (fileReference != null && options.getFilter() == null) {
throw new NinjaException("Type must be defined");
}
List<ObjectTypes> types = NinjaUtils.getTypes(options.getType());
int total = 0;
OperationResult result = new OperationResult(OPERATION_COUNT);
for (ObjectTypes type : types) {
ObjectQuery query = NinjaUtils.createObjectQuery(options.getFilter(), context, type.getClassDefinition());
int count = repository.countObjects(type.getClassDefinition(), query, new ArrayList<>(), result);
if (count == 0 && options.getType() == null) {
continue;
}
log.info("{}:\t{}", type.name(), count);
total += count;
}
log.info("===\nTotal:\t{}", total);
}
use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.
the class ImportProducerWorker method processStream.
private void processStream(InputStream input) throws IOException {
ApplicationContext appContext = context.getApplicationContext();
PrismContext prismContext = appContext.getBean(PrismContext.class);
MatchingRuleRegistry matchingRuleRegistry = appContext.getBean(MatchingRuleRegistry.class);
EventHandler<T> handler = new EventHandler<>() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
currentOid = objectElement.getAttribute("oid");
return EventResult.cont();
}
@Override
public EventResult postMarshall(T object, Element objectElement, OperationResult objectResult) {
try {
if (filter != null) {
boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry);
if (!match) {
operation.incrementSkipped();
return EventResult.skipObject("Object doesn't match filter");
}
}
if (!matchSelectedType(object.getClass())) {
operation.incrementSkipped();
return EventResult.skipObject("Type doesn't match");
}
queue.put(object);
} catch (Exception ex) {
throw new NinjaException(getErrorMessage() + ", reason: " + ex.getMessage(), ex);
}
currentOid = null;
return stopAfterFound ? EventResult.skipObject() : EventResult.cont();
}
@Override
public void handleGlobalError(OperationResult currentResult, Exception cause) {
// This should not
// Should we log error?
operation.incrementError();
String message = getErrorMessage();
if (continueOnInputError) {
if (context.isVerbose()) {
context.getLog().error(message, cause);
} else {
context.getLog().error(message + ", reason: {}", cause.getMessage());
}
} else {
// We need to throw runtime exception in order to stop validator, otherwise validator will continue
// fill queue and this may result in deadlock
operation.finish();
throw new NinjaException(message + ", reason: " + cause.getMessage(), cause);
}
}
};
// FIXME: MID-5151: If validateSchema is false we are not validating unknown attributes on import
LegacyValidator<?> validator = new LegacyValidator<>(prismContext, handler);
validator.setValidateSchema(false);
OperationResult result = operation.getResult();
Charset charset = context.getCharset();
Reader reader = new InputStreamReader(input, charset);
validator.validate(new ReaderInputStream(reader, charset), result, result.getOperation());
}
use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.
the class ExportAuditProducerWorker method run.
@Override
public void run() {
Log log = context.getLog();
try {
GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, AuditEventRecordType.class);
AuditResultHandler handler = (object, parentResult) -> {
try {
queue.put(object);
} catch (InterruptedException ex) {
log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
}
return true;
};
AuditService auditService = context.getAuditService();
auditService.searchObjectsIterative(query, handler, optionsBuilder.build(), operation.getResult());
} catch (SchemaException ex) {
log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);
} finally {
markDone();
if (isWorkersDone()) {
if (!operation.isFinished()) {
operation.producerFinish();
}
}
}
}
use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.
the class NinjaUtils method createWriter.
public static Writer createWriter(File output, Charset charset, boolean zip, boolean overwrite) throws IOException {
OutputStream os;
if (output != null) {
if (!overwrite && output.exists()) {
throw new NinjaException("Export file '" + output.getPath() + "' already exists");
}
output.createNewFile();
os = new FileOutputStream(output);
} else {
os = System.out;
}
if (zip) {
ZipOutputStream zos = new ZipOutputStream(os);
String entryName = output.getName().replaceAll("\\.", "-") + ".xml";
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
os = zos;
}
return new OutputStreamWriter(os, charset);
}
Aggregations