Search in sources :

Example 51 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ResourceContentPanel method initLayout.

private void initLayout() {
    WebMarkupContainer totals = new WebMarkupContainer(ID_TOTALS);
    totals.setOutputMarkupId(true);
    add(totals);
    initShadowStatistics(totals);
    MainObjectListPanel<ShadowType> shadowListPanel = new MainObjectListPanel<ShadowType>(ID_TABLE, ShadowType.class, getTableId(), null, pageBase) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<InlineMenuItem> createInlineMenu() {
            return ResourceContentPanel.this.createRowMenuItems();
        }

        @Override
        protected List<IColumn<SelectableBean<ShadowType>, String>> createColumns() {
            return ResourceContentPanel.this.initColumns();
        }

        @Override
        protected IColumn<SelectableBean<ShadowType>, String> createActionsColumn() {
            return new InlineMenuHeaderColumn(createHeaderMenuItems());
        }

        @Override
        protected void objectDetailsPerformed(AjaxRequestTarget target, ShadowType object) {
            shadowDetailsPerformed(target, WebComponentUtil.getName(object), object.getOid());
        }

        @Override
        protected void newObjectPerformed(AjaxRequestTarget target) {
        // TODO Auto-generated method stub
        }

        @Override
        protected BaseSortableDataProvider<SelectableBean<ShadowType>> initProvider() {
            provider = (SelectableBeanObjectDataProvider<ShadowType>) super.initProvider();
            provider.setEmptyListOnNullQuery(true);
            provider.setSort(null);
            createSearchOptions(provider);
            return provider;
        }

        @Override
        protected ObjectQuery createContentQuery() {
            ObjectQuery parentQuery = super.createContentQuery();
            List<ObjectFilter> filters = new ArrayList<>();
            if (parentQuery != null) {
                filters.add(parentQuery.getFilter());
            }
            ObjectQuery customQuery = ResourceContentPanel.this.createQuery();
            if (customQuery != null && customQuery.getFilter() != null) {
                filters.add(customQuery.getFilter());
            }
            ObjectQuery query = new ObjectQuery();
            if (filters.size() == 1) {
                query = ObjectQuery.createObjectQuery(filters.iterator().next());
                //					setProviderAvailableDataSize(query);
                return query;
            }
            if (filters.size() == 0) {
                //					setProviderAvailableDataSize(query);
                return null;
            }
            query = ObjectQuery.createObjectQuery(AndFilter.createAnd(filters));
            //				setProviderAvailableDataSize(query);
            return query;
        }

        @Override
        protected Search createSearch() {
            return ResourceContentPanel.this.createSearch();
        }
    };
    shadowListPanel.setOutputMarkupId(true);
    shadowListPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return createQuery() != null;
        }
    });
    shadowListPanel.setAdditionalBoxCssClasses(GuiStyleConstants.CLASS_OBJECT_SHADOW_BOX_CSS_CLASSES);
    add(shadowListPanel);
    Label label = new Label(ID_LABEL, "Nothing to show. Select intent to search");
    add(label);
    label.setOutputMarkupId(true);
    label.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return createQuery() == null;
        }
    });
    OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE);
    List<PrismObject<TaskType>> tasks = WebModelServiceUtils.searchObjects(TaskType.class, QueryBuilder.queryFor(TaskType.class, getPageBase().getPrismContext()).item(TaskType.F_OBJECT_REF).ref(getResourceModel().getObject().getOid()).build(), result, getPageBase());
    List<TaskType> tasksForKind = getTasksForKind(tasks);
    List<TaskType> importTasks = new ArrayList<>();
    List<TaskType> syncTasks = new ArrayList<>();
    List<TaskType> reconTasks = new ArrayList<>();
    for (TaskType task : tasksForKind) {
        if (TaskCategory.RECONCILIATION.equals(task.getCategory())) {
            reconTasks.add(task);
        } else if (TaskCategory.LIVE_SYNCHRONIZATION.equals(task.getCategory())) {
            syncTasks.add(task);
        } else if (TaskCategory.IMPORTING_ACCOUNTS.equals(task.getCategory())) {
            importTasks.add(task);
        }
    }
    initButton(ID_IMPORT, "Import", " fa-download", TaskCategory.IMPORTING_ACCOUNTS, importTasks);
    initButton(ID_RECONCILIATION, "Reconciliation", " fa-link", TaskCategory.RECONCILIATION, reconTasks);
    initButton(ID_LIVE_SYNC, "Live Sync", " fa-refresh", TaskCategory.LIVE_SYNCHRONIZATION, syncTasks);
    initCustomLayout();
}
Also used : MainObjectListPanel(com.evolveum.midpoint.gui.api.component.MainObjectListPanel) InlineMenuHeaderColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuHeaderColumn) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 52 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ResourceContentPanel method getTasksForKind.

private List<TaskType> getTasksForKind(List<PrismObject<TaskType>> tasks) {
    List<TaskType> tasksForKind = new ArrayList<>();
    for (PrismObject<TaskType> task : tasks) {
        PrismProperty<ShadowKindType> taskKind = task.findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
        ShadowKindType taskKindValue = null;
        if (taskKind != null) {
            taskKindValue = taskKind.getRealValue();
            PrismProperty<String> taskIntent = task.findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
            String taskIntentValue = null;
            if (taskIntent != null) {
                taskIntentValue = taskIntent.getRealValue();
            }
            if (StringUtils.isNotEmpty(getIntent())) {
                if (getKind() == taskKindValue && getIntent().equals(taskIntentValue)) {
                    tasksForKind.add(task.asObjectable());
                }
            } else if (getKind() == taskKindValue) {
                tasksForKind.add(task.asObjectable());
            }
        }
    }
    return tasksForKind;
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) ArrayList(java.util.ArrayList) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 53 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class PageAdminResources method saveTask.

private void saveTask(PrismObject<TaskType> oldTask, OperationResult result) {
    Task task = createSimpleTask(OPERATION_SAVE_SYNC_TASK);
    PrismProperty property = oldTask.findProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN));
    if (property == null) {
        return;
    }
    Object value = property.getRealValue();
    ObjectDelta<TaskType> delta = ObjectDelta.createModifyDelta(oldTask.getOid(), PropertyDelta.createModificationDeleteProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN), property.getDefinition(), value), TaskType.class, getPrismContext());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(delta.debugDump());
    }
    try {
        getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result);
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save task.", e);
        result.recordFatalError("Couldn't save task.", e);
    }
    result.recomputeStatus();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) PrismObject(com.evolveum.midpoint.prism.PrismObject) RestartResponseException(org.apache.wicket.RestartResponseException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 54 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class CleanupTest method testTasksCleanup.

@Test
public void testTasksCleanup() throws Exception {
    // GIVEN
    final File file = new File(FOLDER_REPO, "tasks-for-cleanup.xml");
    List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects();
    OperationResult result = new OperationResult("tasks cleanup");
    for (PrismObject<? extends Objectable> object : elements) {
        String oid = repositoryService.addObject((PrismObject) object, null, result);
        AssertJUnit.assertTrue(StringUtils.isNotEmpty(oid));
    }
    // WHEN
    // because now we can't move system time (we're not using DI for it) we create policy
    // which should always point to 2013-05-07T12:00:00.000+02:00
    final long NOW = System.currentTimeMillis();
    Calendar when = create_2013_07_12_12_00_Calendar();
    CleanupPolicyType policy = createPolicy(when, NOW);
    taskManager.cleanupTasks(policy, taskManager.createTaskInstance(), result);
    // THEN
    List<PrismObject<TaskType>> tasks = repositoryService.searchObjects(TaskType.class, null, null, result);
    AssertJUnit.assertNotNull(tasks);
    display("tasks", tasks);
    AssertJUnit.assertEquals(1, tasks.size());
    PrismObject<TaskType> task = tasks.get(0);
    XMLGregorianCalendar timestamp = task.getPropertyRealValue(TaskType.F_COMPLETION_TIMESTAMP, XMLGregorianCalendar.class);
    Date finished = XMLGregorianCalendarType.asDate(timestamp);
    Date mark = new Date(NOW);
    Duration duration = policy.getMaxAge();
    duration.addTo(mark);
    AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) Date(java.util.Date) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Objectable(com.evolveum.midpoint.prism.Objectable) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) File(java.io.File) Test(org.testng.annotations.Test)

Example 55 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class Main method listTasks.

private static Collection<TaskType> listTasks(ModelPortType modelPort) throws SAXException, IOException, FaultMessage {
    SelectorQualifiedGetOptionsType operationOptions = new SelectorQualifiedGetOptionsType();
    // Let's say we want to retrieve tasks' next scheduled time (because this may be a costly operation if
    // JDBC based quartz scheduler is used, the fetching of this attribute has to be explicitly requested)
    SelectorQualifiedGetOptionType getNextScheduledTimeOption = new SelectorQualifiedGetOptionType();
    // prepare a selector (described by path) + options (saying to retrieve that attribute)
    OptionObjectSelectorType selector = new OptionObjectSelectorType();
    selector.setPath(ModelClientUtil.createItemPathType("nextRunStartTimestamp"));
    getNextScheduledTimeOption.setSelector(selector);
    GetOperationOptionsType selectorOptions = new GetOperationOptionsType();
    selectorOptions.setRetrieve(RetrieveOptionType.INCLUDE);
    getNextScheduledTimeOption.setOptions(selectorOptions);
    // add newly created option to the list of operation options
    operationOptions.getOption().add(getNextScheduledTimeOption);
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    modelPort.searchObjects(ModelClientUtil.getTypeQName(TaskType.class), null, operationOptions, objectListHolder, resultHolder);
    ObjectListType objectList = objectListHolder.value;
    return (Collection) objectList.getObject();
}
Also used : GetOperationOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.GetOperationOptionsType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OptionObjectSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.OptionObjectSelectorType) Holder(javax.xml.ws.Holder) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Collection(java.util.Collection) SelectorQualifiedGetOptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Aggregations

TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)88 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)63 Test (org.testng.annotations.Test)50 Task (com.evolveum.midpoint.task.api.Task)47 PrismObject (com.evolveum.midpoint.prism.PrismObject)30 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)23 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)16 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 ArrayList (java.util.ArrayList)14 QName (javax.xml.namespace.QName)13 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 Checker (com.evolveum.midpoint.test.Checker)8 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)8