Search in sources :

Example 1 with RepositoryService

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);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) SpringApplicationContextHolder.getCacheRepositoryService(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getCacheRepositoryService) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 2 with RepositoryService

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);
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 3 with RepositoryService

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;
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 4 with RepositoryService

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);
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) PrismContext(com.evolveum.midpoint.prism.PrismContext) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 5 with RepositoryService

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();
    }
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Aggregations

RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)27 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 Test (org.testng.annotations.Test)8 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)7 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 List (java.util.List)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3