public void execute() {
RequestContext context = RequestContext.extract(null);
boolean success = false;
long count = 0;
Result result = null;
final ExecutionUnit unit = getExecutionUnit();
LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Starting pushing through unit: {0}", unit);
if (isActive()) {
getProcessor().onStart(getExecutionUnit());
}
ExecutionUnitHelper helper = new ExecutionUnitHelper(getExecutionUnit());
// get report builder
final ReportBuilder rp = helper.getReportBuilder();
try {
Protocol protocol = getExecutionUnit().getRepository().getProtocol();
if (protocol instanceof HarvestProtocolAgp2Agp) {
HarvestProtocolAgp2Agp agp2agp = (HarvestProtocolAgp2Agp)protocol;
AgpSource source = agp2agp.getSource();
AgpDestination destination = agp2agp.getDestination();
AgpPush agpPush = new AgpPush(source, destination) {
private long counter;
@Override
protected boolean syncItem(AgpItem sourceItem) throws Exception {
counter++;
String sourceUri = sourceItem.getProperties().getValue("id");
try {
boolean result = super.syncItem(sourceItem);
if (result) {
rp.createEntry(sourceUri, result);
LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Pushed item #{0} of source URI: \"{1}\" through unit: {2}", new Object[]{counter, sourceItem.getProperties().getValue("id"), unit});
} else {
rp.createUnpublishedEntry(sourceUri, Arrays.asList(new String[]{"Ignored"}));
LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Rejected item #{0} of source URI: \"{1}\" through unit: {2}", new Object[]{counter, sourceItem.getProperties().getValue("id"), unit});
}
return result;
} catch (AgpException ex) {
if (stopOnError) {
throw ex;
}
LOGGER.log(Level.WARNING, "[SYNCHRONIZER] Failed pushing item #{0} of source URI: \"{1}\" through unit: {2}. Reason: {3}", new Object[]{counter, sourceItem.getProperties().getValue("id"), unit, ex.getMessage()});
rp.createUnpublishedEntry(sourceUri, Arrays.asList(new String[]{ex.getMessage()}));
return false;
} catch (HttpClientException ex) {
if (stopOnError) {
throw ex;
}
LOGGER.log(Level.WARNING, "[SYNCHRONIZER] Failed pushing item #{0} of source URI: \"{1}\" through unit: {2}. Reason: {3}", new Object[]{counter, sourceItem.getProperties().getValue("id"), unit, ex.getMessage()});
rp.createUnpublishedEntry(sourceUri, Arrays.asList(new String[]{ex.getMessage()}));
return false;
} catch (Exception ex) {
throw ex;
}
}
@Override
protected boolean doContinue() {
boolean doContinue = Agp2AgpExecutor.this.isActive();
if (!doContinue) {
unit.setCleanupFlag(false);
}
return doContinue;
}
};
agpPush.synchronize();
}
success = true;
if (isActive()) {
// save last sync date
getExecutionUnit().getRepository().setLastSyncDate(rp.getStartTime());
HrUpdateLastSyncDate updLastSyncDate = new HrUpdateLastSyncDate(context, unit.getRepository());
updLastSyncDate.execute();
}
} catch (Exception ex) {
rp.setException(ex);
unit.setCleanupFlag(false);
LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Failed pushing through unit: {0}. Cause: {1}", new Object[]{unit, ex.getMessage()});
getProcessor().onIterationException(getExecutionUnit(), ex);
} finally {
if (!isShutdown()) {
getProcessor().onEnd(unit, success);
context.onExecutionPhaseCompleted();
}
if (result != null) {
result.destroy();
}
LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Completed pushing through unit: {0}. Obtained {1} records.", new Object[]{unit, count});
}
}