use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class MidpointUtil method getApprovalStageDefinition.
public static ApprovalStageDefinitionType getApprovalStageDefinition(String taskOid) {
RepositoryService cacheRepositoryService = getCacheRepositoryService();
OperationResult result = new OperationResult(MidpointUtil.class.getName() + ".getApprovalStageDefinition");
try {
PrismObject<TaskType> task = cacheRepositoryService.getObject(TaskType.class, taskOid, null, result);
return WfContextUtil.getCurrentStageDefinition(task.asObjectable().getWorkflowContext());
} catch (Exception e) {
throw new SystemException("Couldn't retrieve approval stage for task " + taskOid + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class TaskManagerQuartzImpl method persist.
private void persist(Task task, OperationResult parentResult) {
if (task.getPersistenceStatus() == TaskPersistenceStatus.PERSISTENT) {
// Task already persistent. Nothing to do.
return;
}
TaskQuartzImpl taskImpl = (TaskQuartzImpl) task;
if (task.getName() == null) {
PolyStringType polyStringName = new PolyStringType("Task " + task.getTaskIdentifier());
taskImpl.setNameTransient(polyStringName);
}
if (taskImpl.getOid() != null) {
// We don't support user-specified OIDs
throw new IllegalArgumentException("Transient task must not have OID (task:" + task + ")");
}
// hack: set Category if it is not set yet
if (taskImpl.getCategory() == null) {
taskImpl.setCategoryTransient(taskImpl.getCategoryFromHandler());
}
// Make sure that the task has repository service instance, so it can fully work as "persistent"
if (taskImpl.getRepositoryService() == null) {
RepositoryService repoService = (RepositoryService) this.beanFactory.getBean("repositoryService");
taskImpl.setRepositoryService(repoService);
}
try {
addTaskToRepositoryAndQuartz(taskImpl, parentResult);
} catch (ObjectAlreadyExistsException ex) {
// This should not happen. If it does, it is a bug. It is OK to convert to a runtime exception
throw new IllegalStateException("Got ObjectAlreadyExistsException while not expecting it (task:" + task + ")", ex);
} catch (SchemaException ex) {
// This should not happen. If it does, it is a bug. It is OK to convert to a runtime exception
throw new IllegalStateException("Got SchemaException while not expecting it (task:" + task + ")", ex);
}
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ExportObjects method execute.
public boolean execute() throws UnsupportedEncodingException, FileNotFoundException {
System.out.println("Starting objects export.");
File file = new File(filePath);
if (file.exists() || file.canRead()) {
System.out.println("XML file already exists, export won't be done.");
return false;
}
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONTEXTS);
final OutputStreamWriter stream = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
try {
System.out.println("Loading spring contexts.");
System.out.println("Set repository.");
RepositoryService repository = context.getBean("repositoryService", RepositoryService.class);
ResultHandler<ObjectType> handler = new ResultHandler<ObjectType>() {
PrismContext prismContext = context.getBean(PrismContext.class);
@Override
public boolean handle(PrismObject<ObjectType> object, OperationResult parentResult) {
String displayName = getDisplayName(object);
System.out.println("Exporting object " + displayName);
OperationResult resultExport = new OperationResult("Export " + displayName);
try {
String stringObject = prismContext.serializeObjectToString(object, PrismContext.LANG_XML);
stream.write("\t" + stringObject + "\n");
} catch (Exception ex) {
System.out.println("Failed to parse objects to string for xml. Reason: " + ex);
resultExport.recordFatalError("Failed to parse objects to string for xml. Reason: ", ex);
}
return true;
}
};
stream.write(createHeaderForXml());
OperationResult result = new OperationResult("search set");
System.out.println("Creating xml file " + file.getName());
repository.searchObjectsIterative(ObjectType.class, null, handler, null, false, result);
stream.write("</objects>");
System.out.println("Created xml file " + file.getName());
} catch (Exception ex) {
System.out.println("Exception occurred during context loading, reason: " + ex.getMessage());
ex.printStackTrace();
} finally {
destroyContext(context);
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
System.out.println("Objects export finished.");
return true;
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class OptimizingTriggerCreatorImpl method addTrigger.
private void addTrigger(TriggerHolderSpecification key, long triggerTimestamp, OperationResult result, String oid) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
RepositoryService repositoryService = midpointFunctions.getRepositoryService();
PrismContext prismContext = midpointFunctions.getPrismContext();
TriggerType trigger = new TriggerType(prismContext).handlerUri(RecomputeTriggerHandler.HANDLER_URI).timestamp(XmlTypeConverter.createXMLGregorianCalendar(triggerTimestamp));
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(key.getType()).item(ObjectType.F_TRIGGER).add(trigger).asItemDeltas();
repositoryService.modifyObject(key.getType(), oid, itemDeltas, result);
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class OptimizingTriggerCreatorImpl method determineObjectOid.
private String determineObjectOid(TriggerHolderSpecification key, OperationResult result) throws SchemaException {
RepositoryService repositoryService = midpointFunctions.getRepositoryService();
PrismContext prismContext = midpointFunctions.getPrismContext();
String keyOid = key.getOid();
if (keyOid != null) {
return keyOid;
} else {
ObjectQuery query = key.createQuery(prismContext);
if (query == null) {
throw new IllegalStateException("No OID nor query for " + key);
}
SearchResultList<? extends PrismObject<? extends ObjectType>> objects = repositoryService.searchObjects(key.getType(), query, createReadOnlyCollection(), result);
if (objects.isEmpty()) {
LOGGER.warn("No object found for {}; no trigger will be set", key);
return null;
} else if (objects.size() > 1) {
LOGGER.warn("More than one object found for {}; trigger will be set only for the first one: {}", key, objects);
}
return objects.get(0).getOid();
}
}
Aggregations