Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 17, 2014
2 parents fe16a5a + 94185a4 commit 45df280
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
Expand Up @@ -69,7 +69,9 @@

public class XNodeProcessor {

private PrismContext prismContext;
public static final String ARTIFICIAL_OBJECT_NAME = "anObject";

private PrismContext prismContext;

public XNodeProcessor() { }

Expand Down Expand Up @@ -135,7 +137,13 @@ public <O extends Objectable> PrismObject<O> parseObject(MapXNode xmap) throws S
}

private <O extends Objectable> PrismObject<O> parseObject(MapXNode xnode, PrismObjectDefinition<O> objectDefinition) throws SchemaException {
return parseObject(xnode, new QName(null, "object"), objectDefinition);
QName elementName;
if (objectDefinition != null) {
elementName = objectDefinition.getName();
} else {
elementName = new QName(null, ARTIFICIAL_OBJECT_NAME);
}
return parseObject(xnode, elementName, objectDefinition);
}

private <O extends Objectable> PrismObject<O> parseObject(XNode xnode, QName elementName, PrismObjectDefinition<O> objectDefinition) throws SchemaException {
Expand Down Expand Up @@ -978,7 +986,7 @@ private QName getElementName(XNode node, ItemDefinition itemDefinition) {
} else if (itemDefinition != null) {
return itemDefinition.getName();
} else {
return new QName(null, "object");
throw new IllegalStateException("Couldn't determine element name - neither from XNode nor from itemDefinition");
}
}

Expand Down
Expand Up @@ -998,7 +998,7 @@ public PrismObjectDefinition determineDefinitionFromClass(Class type) {
* in the known schemas.
*/
public boolean hasImplicitTypeDefinition(QName elementName, QName typeName) {
elementName = resolveElementNameIfNeeded(elementName);
elementName = resolveElementNameIfNeeded(elementName, false);
if (elementName == null) {
return false;
}
Expand All @@ -1014,10 +1014,14 @@ public boolean hasImplicitTypeDefinition(QName elementName, QName typeName) {
}

private QName resolveElementNameIfNeeded(QName elementName) {
return resolveElementNameIfNeeded(elementName, true);
}

private QName resolveElementNameIfNeeded(QName elementName, boolean exceptionIfAmbiguous) {
if (StringUtils.isNotEmpty(elementName.getNamespaceURI())) {
return elementName;
}
ItemDefinition itemDef = resolveGlobalItemDefinitionWithoutNamespace(elementName.getLocalPart(), ItemDefinition.class);
ItemDefinition itemDef = resolveGlobalItemDefinitionWithoutNamespace(elementName.getLocalPart(), ItemDefinition.class, exceptionIfAmbiguous);
if (itemDef != null) {
return itemDef.getName();
} else {
Expand Down Expand Up @@ -1053,6 +1057,10 @@ public ItemDefinition resolveGlobalItemDefinition(QName elementQName) throws Sch
}

private <T extends ItemDefinition> T resolveGlobalItemDefinitionWithoutNamespace(String localPart, Class<T> definitionClass) {
return resolveGlobalItemDefinitionWithoutNamespace(localPart, definitionClass, true);
}

private <T extends ItemDefinition> T resolveGlobalItemDefinitionWithoutNamespace(String localPart, Class<T> definitionClass, boolean exceptionIfAmbiguous) {
ItemDefinition found = null;
for (SchemaDescription schemaDescription : parsedSchemas.values()) {
PrismSchema schema = schemaDescription.getSchema();
Expand All @@ -1063,8 +1071,12 @@ private <T extends ItemDefinition> T resolveGlobalItemDefinitionWithoutNamespace
if (def != null) {
if (found != null) {
// todo change to SchemaException
throw new IllegalArgumentException("Multiple possible resolutions for unqualified element name " + localPart + " (e.g. in " +
if (exceptionIfAmbiguous) {
throw new IllegalArgumentException("Multiple possible resolutions for unqualified element name " + localPart + " (e.g. in " +
def.getNamespace() + " and " + found.getNamespace());
} else {
return null;
}
}
found = def;
}
Expand Down
Expand Up @@ -131,7 +131,10 @@ public void processEvent(Event event, Task task, OperationResult result) {
LOGGER.trace("NotificationManager processing event " + event);
}

SystemConfigurationType systemConfigurationType = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, result).asObjectable();
SystemConfigurationType systemConfigurationType = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, result);
if (systemConfigurationType == null) { // something really wrong happened (or we are doing initial import of objects)
return;
}
if (systemConfigurationType.getNotificationConfiguration() == null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("No notification configuration in repository, exiting the change listener.");
Expand Down
Expand Up @@ -51,22 +51,15 @@ public class NotificationsUtil {
@Qualifier("cacheRepositoryService")
private RepositoryService cacheRepositoryService;

public static PrismObject<SystemConfigurationType> getSystemConfiguration(RepositoryService repositoryService, OperationResult result) {
PrismObject<SystemConfigurationType> systemConfiguration;
// beware, may return null if there's any problem getting sysconfig (e.g. during initial import)
public static SystemConfigurationType getSystemConfiguration(RepositoryService repositoryService, OperationResult result) {
try {
systemConfiguration = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(),
null, result);
} catch (ObjectNotFoundException e) {
LoggingUtils.logException(LOGGER, "Couldn't get system configuration", e);
throw new SystemException("Couldn't get system configuration", e);
} catch (SchemaException e) {
LoggingUtils.logException(LOGGER, "Couldn't get system configuration", e);
throw new SystemException("Couldn't get system configuration", e);
}
if (systemConfiguration == null) {
throw new SystemException("Couldn't get system configuration");
return repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(),
null, result).asObjectable();
} catch (ObjectNotFoundException|SchemaException e) {
LoggingUtils.logException(LOGGER, "Notification(s) couldn't be processed, because the system configuration couldn't be retrieved", e);
return null;
}
return systemConfiguration;
}

public static String getResourceNameFromRepo(RepositoryService repositoryService, String oid, OperationResult result) {
Expand Down
Expand Up @@ -85,16 +85,16 @@ public void send(Message mailMessage, String transportName, Task task, Operation
result.addCollectionOfSerializablesAsParam("mailMessage recipient(s)", mailMessage.getTo());
result.addParam("mailMessage subject", mailMessage.getSubject());

PrismObject<SystemConfigurationType> systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.asObjectable().getNotificationConfiguration() == null
|| systemConfiguration.asObjectable().getNotificationConfiguration().getMail() == null) {
SystemConfigurationType systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null
|| systemConfiguration.getNotificationConfiguration().getMail() == null) {
String msg = "No notifications are configured. Mail notification to " + mailMessage.getTo() + " will not be sent.";
LOGGER.warn(msg) ;
result.recordWarning(msg);
return;
}

MailConfigurationType mailConfigurationType = systemConfiguration.asObjectable().getNotificationConfiguration().getMail();
MailConfigurationType mailConfigurationType = systemConfiguration.getNotificationConfiguration().getMail();
if (mailConfigurationType.getRedirectToFile() != null) {
try {
TransportUtil.appendToFile(mailConfigurationType.getRedirectToFile(), formatToFile(mailMessage));
Expand Down
Expand Up @@ -100,8 +100,8 @@ public void send(Message message, String transportName, Task task, OperationResu
result.addCollectionOfSerializablesAsParam("message recipient(s)", message.getTo());
result.addParam("message subject", message.getSubject());

PrismObject<SystemConfigurationType> systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.asObjectable().getNotificationConfiguration() == null) {
SystemConfigurationType systemConfiguration = NotificationsUtil.getSystemConfiguration(cacheRepositoryService, new OperationResult("dummy"));
if (systemConfiguration == null || systemConfiguration.getNotificationConfiguration() == null) {
String msg = "No notifications are configured. SMS notification to " + message.getTo() + " will not be sent.";
LOGGER.warn(msg) ;
result.recordWarning(msg);
Expand All @@ -110,7 +110,7 @@ public void send(Message message, String transportName, Task task, OperationResu

String smsConfigName = transportName.length() > NAME.length() ? transportName.substring(NAME.length() + 1) : null; // after "sms:"
SmsConfigurationType found = null;
for (SmsConfigurationType smsConfigurationType: systemConfiguration.asObjectable().getNotificationConfiguration().getSms()) {
for (SmsConfigurationType smsConfigurationType: systemConfiguration.getNotificationConfiguration().getSms()) {
if ((smsConfigName == null && smsConfigurationType.getName() == null) || (smsConfigName != null && smsConfigName.equals(smsConfigurationType.getName()))) {
found = smsConfigurationType;
break;
Expand Down
Expand Up @@ -72,7 +72,7 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
}

Filter nAryFilter = null;
if (filters.size() > 2) {
if (filters.size() >= 2) {
if (nAry instanceof AndFilter) {
nAryFilter = interpretAnd(filters.get(0), filters.subList(1, filters.size()));
} else if (nAry instanceof OrFilter) {
Expand Down
Expand Up @@ -390,13 +390,13 @@ public boolean suspendTasksResolved(Collection<Task> tasks, long waitForStop, Op

private String waitingInfo(long waitForStop) {
if (waitForStop == WAIT_INDEFINITELY) {
return "wait indefinitely";
return "stop tasks, and wait for their completion (if necessary)";
} else if (waitForStop == DO_NOT_WAIT) {
return "stop tasks, but do not wait";
} else if (waitForStop == DO_NOT_STOP) {
return "do not stop tasks";
} else {
return "stop tasks and wait " + waitForStop + " ms for their completion";
return "stop tasks and wait " + waitForStop + " ms for their completion (if necessary)";
}
}

Expand Down Expand Up @@ -481,6 +481,7 @@ public void resumeTask(Task task, OperationResult parentResult) throws ObjectNot
result.recordFatalError(message);
return;
}
clearTaskOperationResult(task, parentResult); // see a note on scheduleTaskNow
resumeOrUnpauseTask(task, result);
}

Expand Down Expand Up @@ -724,8 +725,17 @@ public void suspendAndDeleteTasks(Collection<String> taskOids, long suspendTimeo
}
}

List<Task> tasksToBeSuspended = new ArrayList<>();
for (Task task : tasksToBeDeleted) {
if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
tasksToBeSuspended.add(task);
}
}

// now suspend the tasks before deletion
suspendTasksResolved(tasksToBeDeleted, suspendTimeout, result);
if (!tasksToBeSuspended.isEmpty()) {
suspendTasksResolved(tasksToBeSuspended, suspendTimeout, result);
}

// delete them
for (Task task : tasksToBeDeleted) {
Expand Down Expand Up @@ -1350,9 +1360,16 @@ public void deleteNode(String nodeOid, OperationResult result) throws SchemaExce

@Override
public void scheduleTaskNow(Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
/*
* Note: we clear task operation result because this is what a user would generally expect when re-running a task
* (MID-1920). We do NOT do that on each task run e.g. to have an ability to see last task execution status
* during a next task run. (When the interval between task runs is too short, e.g. for live sync tasks.)
*/
if (task.isClosed()) {
clearTaskOperationResult(task, parentResult);
executionManager.reRunClosedTask(task, parentResult);
} else if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
clearTaskOperationResult(task, parentResult);
scheduleRunnableTaskNow(task, parentResult);
} else {
String message = "Task " + task + " cannot be run now, because it is not in RUNNABLE nor CLOSED state.";
Expand All @@ -1362,6 +1379,12 @@ public void scheduleTaskNow(Task task, OperationResult parentResult) throws Sche
}
}

private void clearTaskOperationResult(Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
OperationResult emptyTaskResult = new OperationResult("run");
emptyTaskResult.setStatus(OperationResultStatus.IN_PROGRESS);
task.setResultImmediate(emptyTaskResult, parentResult);
}

public void scheduleRunnableTaskNow(Task task, OperationResult parentResult) {
executionManager.scheduleRunnableTaskNow(task, parentResult);
}
Expand Down

0 comments on commit 45df280

Please sign in to comment.