use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class DictionaryBasedImport method handleDataRow.
private void handleDataRow(int index, Values row) {
if (row.length() == 0) {
return;
}
Context context = filterEmptyValues(dictionary.load(row, false));
if (!isEmptyContext(context)) {
Watch watch = Watch.start();
errorContext.handle(() -> {
try {
rowHandler.invoke(Tuple.create(index, context));
} catch (Exception exception) {
process.incCounter("LineBasedJob.erroneousRow");
throw exception;
}
});
process.addTiming(NLS.smartGet(rowCounterName), watch.elapsedMillis());
}
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class EntityImportJob method handleRow.
@Override
protected final void handleRow(int index, Context context) {
Watch watch = Watch.start();
if (contextExtender != null) {
contextExtender.accept(context);
}
E entity = findAndLoad(context);
errorContext.performImport(entity::toString, () -> {
if (shouldSkip(entity)) {
process.incCounter("EntityImportJob.rowIgnored");
return;
}
fillAndVerify(entity, context);
boolean isNew = entity.isNew();
if (mode == ImportMode.CHECK_ONLY) {
enforceSaveConstraints(entity, context);
} else {
createOrUpdate(entity, context);
}
if (isNew) {
process.addTiming(NLS.get("EntityImportJob.entityCreated"), watch.elapsedMillis());
} else {
process.addTiming("EntityImportJob.entityUpdated", watch.elapsedMillis());
}
});
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class JupiterSync method executeDataProvider.
private void executeDataProvider(ProcessContext processContext, JupiterDataProvider provider) {
Watch watch = Watch.start();
processContext.log(ProcessLog.info().withFormattedMessage("Executing data provider: %s", provider.getName()));
Blob blob = blobStorage.getSpace(localRepoSpaceName).findOrCreateByPath(tenants.getTenantUserManager().getSystemTenantId(), provider.getFilename());
try (OutputStream out = blob.createOutputStream(Files.getFilenameAndExtension(provider.getFilename()))) {
provider.execute(out);
processContext.log(ProcessLog.info().withFormattedMessage("Creating '%s' took %s...", provider.getFilename(), watch.duration()));
} catch (Exception e) {
processContext.log(ProcessLog.error().withMessage(Exceptions.handle().to(Jupiter.LOG).error(e).withSystemErrorMessage("Failed to execute data provider %s: %s (%s)", provider.getName()).handle().getMessage()));
}
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class RelationalEntityImportJob method handleRow.
@Override
protected final void handleRow(int index, Context context) {
Watch watch = Watch.start();
if (contextExtender != null) {
contextExtender.accept(context);
}
E entity = findAndLoad(context);
if (mode == SyncMode.DELETE_EXISTING) {
if (!entity.isNew()) {
importer.deleteNow(entity);
process.addTiming(NLS.get("EntityImportJob.entityDeleted"), watch.elapsedMillis());
}
} else {
createOrUpdateEntity(entity, context, watch);
}
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class FileImportJob method handleAuxiliaryFile.
/**
* Gets invoked for every entry in a given ZIP archive which cannot be processed by this job itself.
* <p>
* This might be used e.g. if an XML file is being processed which is accompanied with some media files to
* move them into the proper directory in the {@link sirius.biz.storage.layer3.VirtualFileSystem}.
* <p>
* By default this is attempted if the {@link #determineAuxiliaryFilesDirectory()} returns a non-null result.
* Otherwise these files are simply ignored.
*
* @param extractedFile the extracted file which cannot be handled by the job itself
*/
protected boolean handleAuxiliaryFile(ExtractedFile extractedFile) {
try {
Watch watch = Watch.start();
VirtualFile basePath = determineAuxiliaryFilesBasePath();
if (basePath == null) {
return false;
}
VirtualFile targetFile = basePath.resolve(getTargetPath(extractedFile));
if (extractor.updateFile(extractedFile, targetFile, auxiliaryFileMode.overrideMode) != ArchiveExtractor.UpdateResult.SKIPPED) {
process.addTiming(NLS.get("FileImportJob.auxiliaryFileCopied"), watch.elapsedMillis());
} else {
process.addTiming(NLS.get("FileImportJob.auxiliaryFileSkipped"), watch.elapsedMillis());
}
return true;
} catch (Exception e) {
process.handle(Exceptions.handle().error(e).to(Log.BACKGROUND).withNLSKey("FileImportJob.copyAuxiliaryFileFailed").set("file", extractedFile.getFilePath()).set("message", e.getMessage()).handle());
return false;
}
}
Aggregations