List<Event> newEvents = m_repository.getAuditEvents(newDescriptors);
boolean foundDeploymentEvent = false;
boolean foundPropertiesEvent = false;
for (int position = newEvents.size() - 1; position >= 0; position--) {
Event event = newEvents.get(position);
if (!foundDeploymentEvent) {
// TODO we need to check here if the deployment package is actually the right one
String currentVersion = (String) event.getProperties().get(AuditEvent.KEY_VERSION);
if (event.getType() == AuditEvent.DEPLOYMENTCONTROL_INSTALL) {
addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
setProvisioningState(ProvisioningState.InProgress);
sendNewAuditlog(newDescriptors);
m_processedAuditEvents = allDescriptors;
foundDeploymentEvent = true;
}
if (event.getType() == AuditEvent.DEPLOYMENTADMIN_COMPLETE) {
addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
if ((currentVersion != null) && currentVersion.equals(getStatusAttribute(KEY_ACKNOWLEDGED_INSTALL_VERSION))) {
setProvisioningState(ProvisioningState.Idle);
sendNewAuditlog(newDescriptors);
m_processedAuditEvents = allDescriptors;
foundDeploymentEvent = true;
}
else {
String value = (String) event.getProperties().get(AuditEvent.KEY_SUCCESS);
addStatusAttribute(KEY_LAST_INSTALL_SUCCESS, value);
if (Boolean.parseBoolean(value)) {
setProvisioningState(ProvisioningState.OK);
sendNewAuditlog(newDescriptors);
m_processedAuditEvents = allDescriptors;
foundDeploymentEvent = true;
}
else {
setProvisioningState(ProvisioningState.Failed);
sendNewAuditlog(newDescriptors);
m_processedAuditEvents = allDescriptors;
foundDeploymentEvent = true;
}
}
}
}
if (!foundPropertiesEvent) {
if (event.getType() == AuditEvent.TARGETPROPERTIES_SET) {
m_processedTargetProperties = event.getProperties();
foundPropertiesEvent = true;
determineTargetPropertiesState();
}
}
// as soon as we've found the latest of both types of events, we're done