use of eu.etaxonomy.cdm.common.monitor.SubProgressMonitor in project cdmlib by cybertaxonomy.
the class CdmApplicationAwareDefaultExport method doExport.
/**
* Executes the whole
*/
protected <CONFIG extends T> ExportResult doExport(CONFIG config) {
// validate
if (config == null) {
ExportResult result = ExportResult.NewInstance(null);
String message = "Configuration is null";
logger.error(message);
result.addError(message);
result.setAborted();
return result;
}
ExportResult result = ExportResult.NewInstance(config.getResultType());
if (!config.isValid()) {
String message = "Configuration is not valid";
logger.error(message);
result.addError(message);
result.setAborted();
return result;
}
ExportStateBase state = config.getNewState();
state.initialize(config);
state.setResult(result);
List<ICdmExport> ioList = makeIoList(state, config);
List<Integer> stepCounts = countSteps(state, ioList);
Integer totalCount = stepCounts.get(stepCounts.size() - 1);
config.getProgressMonitor().beginTask(config.getUserFriendlyIOName() != null ? config.getUserFriendlyIOName() : "Start Export", totalCount);
config.getProgressMonitor().worked(1);
IProgressMonitor parentMonitor = SubProgressMonitor.NewStarted(config.getProgressMonitor(), 99, "Process data", totalCount);
// do invoke for each class
for (int i = 0; i < ioList.size(); i++) {
ICdmExport export = ioList.get(i);
Integer counts = stepCounts.get(i);
try {
String ioName = export.getClass().getSimpleName();
SubProgressMonitor ioMonitor = SubProgressMonitor.NewStarted(parentMonitor, counts, ioName, counts);
// state.getConfig().setProgressMonitor(ioMonitor);
state.setCurrentIO(export);
export.invoke(state);
ioMonitor.done();
} catch (Exception e) {
String message = "Unexpected exception in " + export.getClass().getSimpleName() + ": " + e.getMessage();
logger.error(message);
e.printStackTrace();
result.addException(e, message);
}
}
System.out.println("End export from source '" + config.getSourceNameString() + "' to destination '" + config.getDestinationNameString() + "' " + "(" + result.toString() + ")");
return result;
}
use of eu.etaxonomy.cdm.common.monitor.SubProgressMonitor in project cdmlib by cybertaxonomy.
the class MonitoredGenericApplicationContext method finishBeanFactoryInitialization.
@Override
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
checkMonitorCancelled(currentMonitor);
String task = "Finish bean factory initialization";
currentMonitor.subTask(task);
IProgressMonitor subMonitor = new SubProgressMonitor(currentMonitor, countFinishBeanFactoryInitialization);
getMyBeanFactory().setCurrentMonitor(subMonitor);
super.finishBeanFactoryInitialization(beanFactory);
checkMonitorCancelled(currentMonitor);
}
use of eu.etaxonomy.cdm.common.monitor.SubProgressMonitor in project cdmlib by cybertaxonomy.
the class CacheUpdater method doInvoke.
public UpdateResult doInvoke(CacheUpdaterConfigurator config) {
UpdateResult result = new UpdateResult();
IProgressMonitor monitor = config.getMonitor();
monitor.beginTask("Update caches", 100);
monitor.subTask("Check start conditions");
if (config.getClassList() == null || config.getClassList().isEmpty()) {
// !! not yet implemented
logger.warn("Create class list from boolean values is not yet implemented for cache updater");
createClassListFromBoolean();
}
monitor.worked(1);
monitor.subTask("Count records");
Integer count = countAllUpdatableObjects(config.getClassList());
SubProgressMonitor subMonitor = SubProgressMonitor.NewStarted(monitor, 90, "Updating secundum for subtree", count);
// handle class list
result = handleClassList(config.getClassList(), subMonitor);
config.getMonitor().done();
return result;
}
use of eu.etaxonomy.cdm.common.monitor.SubProgressMonitor in project cdmlib by cybertaxonomy.
the class SortIndexUpdaterWrapper method update.
private UpdateResult update(SortIndexUpdater updater, IProgressMonitor monitor) {
// TODO change to long running task result
UpdateResult updateResult = new UpdateResult();
try {
TransactionStatus tx = startTransaction(true);
String query = updater.createIndexMapQuery();
List<?> data = getSqlResult(query);
int c = 2;
if (updater.getTableName().equals(TAXON_NODE)) {
c = 3;
}
monitor.beginTask("Update index", data.size() * c);
monitor.subTask("Create new index");
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, data.size());
List<Integer[]> result = new ArrayList<>();
int done = 0;
for (Object object : data) {
Object[] row = (Object[]) object;
Object oId = row[0];
if (oId != null) {
int id = Integer.valueOf(oId.toString());
Integer[] rowArray = new Integer[2];
Object oParentId = row[1];
if (oParentId != null) {
int parentId = Integer.valueOf(oParentId.toString());
rowArray[1] = parentId;
} else {
rowArray[1] = null;
}
rowArray[0] = id;
result.add(rowArray);
}
done++;
subMonitor.internalWorked(done);
}
subMonitor.done();
monitor.subTask("update indices");
Map<Integer, Set<Integer>> indexMap = updater.makeIndexMap(result);
subMonitor = new SubProgressMonitor(monitor, indexMap.size());
done = 0;
for (Map.Entry<Integer, Set<Integer>> entry : indexMap.entrySet()) {
String idSet = SortIndexUpdater.makeIdSetString(entry.getValue());
query = updater.createUpdateIndicesQuery(null, entry.getKey(), idSet);
int resultInt = executeSqlResult(query);
logger.debug("update all indice with index " + entry.getKey() + " - " + resultInt);
done++;
subMonitor.internalWorked(done);
}
subMonitor.done();
// Update childrenCount
if (updater.getTableName().equals(TAXON_NODE)) {
query = updater.getChildrenCountQuery();
data = getSqlResult(query);
subMonitor = new SubProgressMonitor(monitor, data.size());
int realCount;
int countChildren;
int work = 0;
for (Object object : data) {
Object[] row = (Object[]) object;
realCount = ((Number) row[0]).intValue();
countChildren = ((Number) row[1]).intValue();
int id = ((Number) row[2]).intValue();
if (realCount != countChildren) {
query = updater.getUpdateChildrenCount(realCount, id);
int resultInt = executeSqlResult(query);
logger.debug("update all childrenCount " + resultInt);
}
work++;
subMonitor.internalWorked(work);
subMonitor.done();
}
}
// TODO: correct handling of updateResult!
monitor.done();
commitTransaction(tx);
return updateResult;
} catch (Exception e) {
monitor.warning("Stopped sortIndex updater");
updateResult.setAbort();
updateResult.addException(e);
}
return null;
}
use of eu.etaxonomy.cdm.common.monitor.SubProgressMonitor in project cdmlib by cybertaxonomy.
the class TaxonNodeServiceImpl method setPublishForSubtree.
@Override
@Transactional(readOnly = false)
public UpdateResult setPublishForSubtree(PublishForSubtreeConfigurator config) {
UpdateResult result = new UpdateResult();
IProgressMonitor monitor = config.getMonitor();
if (monitor == null) {
monitor = DefaultProgressMonitor.NewInstance();
}
monitor.beginTask("Update publish flag for subtree", 100);
monitor.subTask("Check start conditions");
if (config.getSubtreeUuid() == null) {
result.setError();
result.addException(new NullPointerException("No subtree given"));
monitor.done();
return result;
}
monitor.worked(1);
TaxonNode subTree = find(config.getSubtreeUuid());
if (subTree == null) {
result.setError();
result.addException(new NullPointerException("Subtree does not exist"));
monitor.done();
return result;
}
monitor.worked(1);
monitor.subTask("Count records");
boolean includeAcceptedTaxa = config.isIncludeAcceptedTaxa();
boolean publish = config.isPublish();
boolean includeSynonyms = config.isIncludeSynonyms();
boolean includeSharedTaxa = config.isIncludeSharedTaxa();
boolean includeHybrids = config.isIncludeHybrids();
boolean includeRelatedTaxa = config.isIncludeProParteSynonyms() || config.isIncludeMisapplications();
try {
TreeIndex subTreeIndex = TreeIndex.NewInstance(subTree.treeIndex());
int count = includeAcceptedTaxa ? dao.countPublishForSubtreeAcceptedTaxa(subTreeIndex, publish, includeSharedTaxa, includeHybrids) : 0;
monitor.worked(3);
count += includeSynonyms ? dao.countPublishForSubtreeSynonyms(subTreeIndex, publish, includeSharedTaxa, includeHybrids) : 0;
monitor.worked(3);
count += includeRelatedTaxa ? dao.countPublishForSubtreeRelatedTaxa(subTreeIndex, publish, includeSharedTaxa, includeHybrids) : 0;
monitor.worked(2);
if (monitor.isCanceled()) {
return result;
}
SubProgressMonitor subMonitor = SubProgressMonitor.NewStarted(monitor, 90, "Updating secundum for subtree", count);
if (includeAcceptedTaxa) {
monitor.subTask("Update Accepted Taxa");
@SuppressWarnings("rawtypes") Set<TaxonBase> updatedTaxa = dao.setPublishForSubtreeAcceptedTaxa(subTreeIndex, publish, includeSharedTaxa, includeHybrids, subMonitor);
result.addUpdatedObjects(updatedTaxa);
if (monitor.isCanceled()) {
return result;
}
}
if (includeSynonyms) {
monitor.subTask("Update Synonyms");
@SuppressWarnings("rawtypes") Set<TaxonBase> updatedSynonyms = dao.setPublishForSubtreeSynonyms(subTreeIndex, publish, includeSharedTaxa, includeHybrids, subMonitor);
result.addUpdatedObjects(updatedSynonyms);
if (monitor.isCanceled()) {
return result;
}
}
if (includeRelatedTaxa) {
monitor.subTask("Update Related Taxa");
Set<UUID> relationTypes = getRelationTypesForSubtree(config);
if (config.isIncludeMisapplications()) {
relationTypes.addAll(TaxonRelationshipType.misappliedNameUuids());
}
if (config.isIncludeProParteSynonyms()) {
relationTypes.addAll(TaxonRelationshipType.proParteOrPartialSynonymUuids());
}
@SuppressWarnings("rawtypes") Set<TaxonBase> updatedTaxa = dao.setPublishForSubtreeRelatedTaxa(subTreeIndex, publish, relationTypes, includeSharedTaxa, includeHybrids, subMonitor);
result.addUpdatedObjects(updatedTaxa);
if (monitor.isCanceled()) {
return result;
}
}
} catch (Exception e) {
result.setError();
result.addException(e);
}
monitor.done();
return result;
}
Aggregations